void performCancel(Action action) { String key = action.getKey(); BitmapHunter hunter = hunterMap.get(key); if (hunter != null) { hunter.detach(action); if (hunter.cancel()) { hunterMap.remove(key); if (action.getPicasso().loggingEnabled) { Utils.log(Utils.OWNER_DISPATCHER, Utils.VERB_CANCELED, action.getRequest().logId()); } } } if (pausedTags.contains(action.getTag())) { pausedActions.remove(action.getTarget()); if (action.getPicasso().loggingEnabled) { Utils.log( Utils.OWNER_DISPATCHER, Utils.VERB_CANCELED, action.getRequest().logId(), "because paused request got canceled"); } } Action remove = failedActions.remove(action.getTarget()); if (remove != null && remove.getPicasso().loggingEnabled) { Utils.log( Utils.OWNER_DISPATCHER, Utils.VERB_CANCELED, remove.getRequest().logId(), "from replaying"); } }
private void addHeaderParams(DetailedLink link, Action action) { // Add the parameters that are specified in the metadata: if (action.getRequest().getHeaders() != null && !action.getRequest().getHeaders().isEmpty()) { link.getRequest().setHeaders(new Headers()); for (Object key : action.getRequest().getHeaders().keySet()) { Header header = new Header(); header.setName(key.toString()); Object value = action.getRequest().getHeaders().get(key); if (value != null) { ParamData paramData = (ParamData) value; header.setValue(paramData.getValue()); header.setRequired( paramData.getRequired() == null ? Boolean.FALSE : paramData.getRequired()); header.setDeprecated(paramData.getDeprecated()); } link.getRequest().getHeaders().getHeaders().add(header); } } // All the operations that potentially modify the state of the system accept the // "Correlation-Id" header, so // instead of adding it explicitly in the metadata file it is better to add it implicitly: if (!GET.equals(link.getRel())) { addCorrelationIdHeader(link); } // All the operations that potentially send a body (everything except GET) should also specify // the "Content-Type" header, so instead of explicitly adding it in the metadata file it is // better to add it // implicity: if (!GET.equals(link.getRel())) { addContentTypeHeader(link); } // All the operations that create a new entity (those whose rel is "add") support the "Expect" // header with the // "201-created" value, so instead of explicitly adding it in the metadata file it is better to // add it // implicitly: if (ADD.equals(link.getRel())) { addExpectHeader(link, "201-created"); } // All the operations that update entities (those whose rel is "update") support the "Expect" // header with the // "202-accepted" value, so instead of explicitly adding it in the metadata file it is better to // add it // implicitly: if (UPDATE.equals(link.getRel())) { addExpectHeader(link, "202-accepted"); } }
private void addBodyParams(DetailedLink link, Action action) { if (action.getRequest().getBody() != null) { link.getRequest().getBody().setRequired(action.getRequest().getBody().isRequired()); if (action.getRequest().getBody().getSignatures() != null) { for (Signature signature : action.getRequest().getBody().getSignatures()) { ParametersSet ps = new ParametersSet(); if (signature.getDeprecated() != null) { ps.setDeprecated(signature.getDeprecated()); } if (signature.getDescription() != null) { ps.setDescription(signature.getDescription()); } addBodyParams(ps, signature.getMandatoryArguments().entrySet(), true); addBodyParams(ps, signature.getOptionalArguments().entrySet(), false); link.getRequest().getBody().getParametersSets().add(ps); } } } }
private void flushFailedActions() { if (!failedActions.isEmpty()) { Iterator<Action> iterator = failedActions.values().iterator(); while (iterator.hasNext()) { Action action = iterator.next(); iterator.remove(); if (action.getPicasso().loggingEnabled) { Utils.log(Utils.OWNER_DISPATCHER, Utils.VERB_REPLAYING, action.getRequest().logId()); } performSubmit(action, false); } } }
private void addUrlParams(DetailedLink link, Action action) { if (action.getRequest().getUrlparams() != null && !action.getRequest().getUrlparams().isEmpty()) { link.getRequest().setUrl(new Url()); ParametersSet ps = new ParametersSet(); for (Object key : action.getRequest().getUrlparams().keySet()) { Parameter param = new Parameter(); param.setName(key.toString()); Object value = action.getRequest().getUrlparams().get(key); if (value != null) { ParamData urlParamData = (ParamData) value; param.setType(urlParamData.getType()); param.setContext(urlParamData.getContext()); param.setValue(urlParamData.getValue()); param.setRequired( urlParamData.getRequired() == null ? Boolean.FALSE : urlParamData.getRequired()); param.setDeprecated(urlParamData.getDeprecated()); } ps.getParameters().add(param); } link.getRequest().getUrl().getParametersSets().add(ps); } }
private DetailedLink addParametersMetadata(DetailedLink link) { String link_name = link.getHref() + "|rel=" + link.getRel(); if (this.parametersMetaData.containsKey(link_name)) { Action action = this.parametersMetaData.get(link_name); if (action.getDescription() != null) { link.setDescription(action.getDescription()); } if (action.getRequest() != null) { addUrlParams(link, action); addHeaderParams(link, action); addBodyParams(link, action); } } return link; }
@Test public void onGlobalLayoutSubmitsRequestAndCleansUp() throws Exception { Picasso picasso = mock(Picasso.class); when(picasso.transformRequest(any(Request.class))).thenAnswer(TRANSFORM_REQUEST_ANSWER); RequestCreator creator = new RequestCreator(picasso, URI_1, 0); ImageView target = mockFitImageViewTarget(true); when(target.getWidth()).thenReturn(100); when(target.getHeight()).thenReturn(100); ViewTreeObserver observer = target.getViewTreeObserver(); DeferredRequestCreator request = new DeferredRequestCreator(creator, target); request.onPreDraw(); verify(observer).removeOnPreDrawListener(request); verify(picasso).enqueueAndSubmit(actionCaptor.capture()); Action value = actionCaptor.getValue(); assertThat(value).isInstanceOf(ImageViewAction.class); assertThat(value.getRequest().targetWidth).isEqualTo(100); assertThat(value.getRequest().targetHeight).isEqualTo(100); }