@Override protected Map<String, Mimetype> retrieveValue(final String userId, final String storeId) throws ConnectorServiceException { Map<String, Mimetype> mimetypes; // initiate a call to retrieve the dictionary from the repository final RequestContext rc = ThreadLocalRequestContext.getRequestContext(); final Connector conn = rc.getServiceRegistry() .getConnectorService() .getConnector("alfresco", userId, ServletUtil.getSession()); final Response response = conn.call("/api/mimetypes/descriptions"); if (response.getStatus().getCode() == Status.STATUS_OK) { logger.info("Successfully retrieved mimetypes information from Alfresco."); mimetypes = new HashMap<String, Mimetype>(128); try { // Extract mimetype information final JSONObject json = new JSONObject(response.getResponse()); final JSONObject data = json.getJSONObject("data"); Iterator<String> types = data.keys(); while (types.hasNext()) { // The type is the key String mimetype = types.next(); // The details come from the value Mimetype details = new Mimetype(mimetype, data.getJSONObject(mimetype)); mimetypes.put(mimetype, details); } } catch (JSONException e) { throw new AlfrescoRuntimeException(e.getMessage(), e); } } else { throw new AlfrescoRuntimeException( "Unable to retrieve mimetypes information from Alfresco: " + response.getStatus().getCode()); } return mimetypes; }
@Override protected org.springframework.extensions.webscripts.connector.Response retrieveFormDefinition( String itemKind, String itemId, List<String> visibleFields, FormConfigElement formConfig) { org.springframework.extensions.webscripts.connector.Response response = null; try { assertEquals("Parameter 'itemKind' isn't 'node' value", "node", itemKind); assertFalse("itemId is empty", itemId != null && itemId.isEmpty()); assertTrue("Visible fields are empty", visibleFields.size() > 0); assertEquals("Form config 'name' field isn't 'form' value", "form", formConfig.getName()); ByteArrayInputStream bais = generateFormDefPostBody(itemKind, itemId, visibleFields, formConfig); assertTrue("Can't read bytes from ByteArrayInputStream ", bais.available() > 0); String json = getStringFromInputStream(bais); log.info("Request 'formdefinitions' json is: " + json); PostRequest request = new PostRequest("/api/formdefinitions", json, "application/json"); org.springframework.extensions.webscripts.TestWebScriptServer.Response responseTest = server.submitRequest( request.getMethod(), request.getFullUri(), request.getHeaders(), request.getBody(), request.getEncoding(), request.getType()); if (responseTest.getStatus() == 200) { JSONObject jsonParsedObject = new JSONObject(new JSONTokener(responseTest.getContentAsString())); assertNotNull("JSON from responseTest is null", jsonParsedObject); Object dataObj = jsonParsedObject.get("data"); assertEquals(JSONObject.class, dataObj.getClass()); JSONObject rootDataObject = (JSONObject) dataObj; String item = (String) rootDataObject.get("item"); String submissionUrl = (String) rootDataObject.get("submissionUrl"); String type = (String) rootDataObject.get("type"); JSONObject definitionObject = (JSONObject) rootDataObject.get("definition"); JSONObject formDataObject = (JSONObject) rootDataObject.get("formData"); assertNotNull("Item is null ", item); assertNotNull("Submission url is null ", submissionUrl); assertNotNull("Type is null ", type); assertNotNull("Definition is null ", definitionObject); assertNotNull("Form data is null ", formDataObject); log.info("Response form 'formdefinitions' json 'data' is: " + dataObj); ResponseStatus status = new ResponseStatus(); status.setCode(responseTest.getStatus()); assertFalse("Response content is empty", responseTest.getContentAsString().isEmpty()); response = new org.springframework.extensions.webscripts.connector.Response( responseTest.getContentAsString(), status); assertNotNull("Response data is null.", response.getText()); } else { assertEquals( "Response /api/formdefinitions is not 200 status", 200, responseTest.getStatus()); } } catch (Exception e) { log.error("Response form 'formdefinitions' exception : " + e.getMessage()); } return response; }