Search in sources :

Example 11 with ApiResource

use of org.entando.entando.aps.system.services.api.model.ApiResource in project entando-core by entando.

the class TestApiI18nLabelInterface method testCreateNewLabel.

protected void testCreateNewLabel(MediaType mediaType) throws Throwable {
    String key = "TEST_LABEL_KEY";
    String label = this._i18nManager.getLabel(key, "it");
    assertNull(label);
    ApsProperties labels = new ApsProperties();
    labels.put("en", "Test label");
    labels.put("it", "Label di Test");
    JAXBI18nLabel jaxbLabel = new JAXBI18nLabel(key, labels);
    ApiResource labelResource = this.getApiCatalogManager().getResource("core", "i18nlabel");
    ApiMethod postMethod = labelResource.getPostMethod();
    Properties properties = super.createApiProperties("admin", "it", mediaType);
    try {
        Object response = this.getResponseBuilder().createResponse(postMethod, jaxbLabel, properties);
        assertNotNull(response);
        assertTrue(response instanceof StringApiResponse);
        assertEquals(IResponseBuilder.SUCCESS, ((StringApiResponse) response).getResult());
        label = this._i18nManager.getLabel(key, "it");
        assertEquals("Label di Test", label);
    } catch (Exception e) {
        throw e;
    } finally {
        this._i18nManager.deleteLabelGroup(key);
    }
}
Also used : ApiResource(org.entando.entando.aps.system.services.api.model.ApiResource) JAXBI18nLabel(org.entando.entando.aps.system.services.i18n.model.JAXBI18nLabel) ApiMethod(org.entando.entando.aps.system.services.api.model.ApiMethod) Properties(java.util.Properties) ApsProperties(com.agiletec.aps.util.ApsProperties) StringApiResponse(org.entando.entando.aps.system.services.api.model.StringApiResponse) ApsProperties(com.agiletec.aps.util.ApsProperties)

Example 12 with ApiResource

use of org.entando.entando.aps.system.services.api.model.ApiResource in project entando-core by entando.

the class TestApiContentInterface method testGetContent.

protected JAXBContent testGetContent(MediaType mediaType, String username, String contentId, String langCode) throws Throwable {
    ApiResource contentResource = this.getApiCatalogManager().getResource("jacms", "content");
    ApiMethod getMethod = contentResource.getGetMethod();
    Properties properties = super.createApiProperties(username, langCode, mediaType);
    properties.put("id", contentId);
    Object result = this.getResponseBuilder().createResponse(getMethod, properties);
    assertNotNull(result);
    ApiContentInterface apiContentInterface = (ApiContentInterface) this.getApplicationContext().getBean("jacmsApiContentInterface");
    Object singleResult = apiContentInterface.getContent(properties);
    assertNotNull(singleResult);
    String toString = this.marshall(singleResult, mediaType);
    InputStream stream = new ByteArrayInputStream(toString.getBytes());
    JAXBContent jaxbContent = (JAXBContent) UnmarshalUtils.unmarshal(super.getApplicationContext(), JAXBContent.class, stream, mediaType);
    assertNotNull(jaxbContent);
    return jaxbContent;
}
Also used : ApiResource(org.entando.entando.aps.system.services.api.model.ApiResource) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ApiMethod(org.entando.entando.aps.system.services.api.model.ApiMethod) Properties(java.util.Properties) JAXBContent(org.entando.entando.plugins.jacms.aps.system.services.api.model.JAXBContent)

Example 13 with ApiResource

use of org.entando.entando.aps.system.services.api.model.ApiResource in project entando-core by entando.

the class TestApiContentInterface method testCreateNewContent.

protected void testCreateNewContent(MediaType mediaType, String contentId) throws Throwable {
    String dateNow = DateConverter.getFormattedDate(new Date(), JacmsSystemConstants.CONTENT_METADATA_DATE_FORMAT);
    EntitySearchFilter filter = new EntitySearchFilter(IContentManager.CONTENT_CREATION_DATE_FILTER_KEY, false, dateNow, null);
    EntitySearchFilter[] filters = { filter };
    List<String> ids = this._contentManager.searchId(filters);
    assertTrue(ids.isEmpty());
    JAXBContent jaxbContent = this.testGetContent(mediaType, "admin", contentId, "it");
    ApiResource contentResource = this.getApiCatalogManager().getResource("jacms", "content");
    ApiMethod postMethod = contentResource.getPostMethod();
    Properties properties = super.createApiProperties("admin", "it", mediaType);
    try {
        jaxbContent.setId(null);
        Object response = this.getResponseBuilder().createResponse(postMethod, jaxbContent, properties);
        assertNotNull(response);
        assertTrue(response instanceof StringApiResponse);
        assertEquals(IResponseBuilder.SUCCESS, ((StringApiResponse) response).getResult());
        ids = this._contentManager.searchId(filters);
        assertEquals(1, ids.size());
        String newContentId = ids.get(0);
        Content newContent = this._contentManager.loadContent(newContentId, false);
        Content masterContent = this._contentManager.loadContent(contentId, true);
        List<AttributeInterface> attributes = masterContent.getAttributeList();
        for (int i = 0; i < attributes.size(); i++) {
            AttributeInterface attribute = attributes.get(i);
            AttributeInterface newAttribute = (AttributeInterface) newContent.getAttribute(attribute.getName());
            this.checkAttributes(attribute, newAttribute);
        }
    } catch (Exception e) {
        throw e;
    } finally {
        ids = this._contentManager.searchId(filters);
        if (!ids.isEmpty()) {
            for (int i = 0; i < ids.size(); i++) {
                String id = ids.get(i);
                Content content = this._contentManager.loadContent(id, false);
                this._contentManager.deleteContent(content);
            }
        }
    }
}
Also used : ApiResource(org.entando.entando.aps.system.services.api.model.ApiResource) ApiMethod(org.entando.entando.aps.system.services.api.model.ApiMethod) Properties(java.util.Properties) Date(java.util.Date) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) JAXBContent(org.entando.entando.plugins.jacms.aps.system.services.api.model.JAXBContent) JAXBContent(org.entando.entando.plugins.jacms.aps.system.services.api.model.JAXBContent) EntitySearchFilter(com.agiletec.aps.system.common.entity.model.EntitySearchFilter) StringApiResponse(org.entando.entando.aps.system.services.api.model.StringApiResponse) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)

Example 14 with ApiResource

use of org.entando.entando.aps.system.services.api.model.ApiResource in project entando-core by entando.

the class ApiCatalogManager method updateMethodConfig.

@Override
public void updateMethodConfig(ApiMethod apiMethod) throws ApsSystemException {
    try {
        ApiMethod masterMethod = this.checkMethod(apiMethod);
        this.getApiCatalogDAO().saveApiStatus(apiMethod);
        masterMethod.setStatus(apiMethod.getStatus());
        masterMethod.setHidden(apiMethod.getHidden());
        masterMethod.setRequiredAuth(apiMethod.getRequiredAuth());
        String requiredPermission = apiMethod.getRequiredPermission();
        if (null != requiredPermission && requiredPermission.trim().length() > 0) {
            masterMethod.setRequiredPermission(requiredPermission);
        } else {
            masterMethod.setRequiredPermission(null);
        }
        String resourceCode = ApiResource.getCode(masterMethod.getNamespace(), masterMethod.getResourceName());
        ApiResource resource = this.getResourceCacheWrapper().getMasterResource(resourceCode);
        this.getResourceCacheWrapper().updateResource(resource);
    } catch (Throwable t) {
        logger.error("Error error updating api status : resource '{}' method '{}'", apiMethod.getResourceName(), apiMethod.getHttpMethod(), t);
        throw new ApsSystemException("Error updating api status", t);
    }
}
Also used : ApiResource(org.entando.entando.aps.system.services.api.model.ApiResource) ApiMethod(org.entando.entando.aps.system.services.api.model.ApiMethod) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 15 with ApiResource

use of org.entando.entando.aps.system.services.api.model.ApiResource in project entando-core by entando.

the class ApiResourceLoader method loadApiResources.

private void loadApiResources(String locationPattern) throws Exception {
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    Resource[] resources = resolver.getResources(locationPattern);
    ApiResourcesDefDOM dom = null;
    for (int i = 0; i < resources.length; i++) {
        Resource resource = resources[i];
        InputStream is = null;
        String path = resource.getURL().getPath();
        try {
            is = resource.getInputStream();
            String xml = FileTextReader.getText(is);
            dom = new ApiResourcesDefDOM(xml, path);
            Map<String, ApiResource> extractedResources = dom.getResources();
            if (null != extractedResources) {
                Iterator<ApiResource> extractedResourcesIter = extractedResources.values().iterator();
                while (extractedResourcesIter.hasNext()) {
                    ApiResource apiResource = extractedResourcesIter.next();
                    if (null != this.getResources().get(apiResource.getCode())) {
                        _logger.info("Into definition file '{}' there is an API with namespace '{}', resource '{}' and there is just one already present - The old definition will be overrided!!!", path, apiResource.getNamespace(), apiResource.getResourceName());
                    }
                    this.getResources().put(apiResource.getCode(), apiResource);
                }
            }
            _logger.debug("Loaded Api Resources definition by file {}", path);
        } catch (Throwable t) {
            _logger.error("Error loading Api Resources definition by location Pattern '{}'", path, t);
        // ApsSystemUtils.logThrowable(t, this, "loadApiResources", "Error loading Api Resources definition by location Pattern '" + path + "'");
        } finally {
            if (null != is) {
                is.close();
            }
        }
    }
}
Also used : ApiResource(org.entando.entando.aps.system.services.api.model.ApiResource) InputStream(java.io.InputStream) ApiResource(org.entando.entando.aps.system.services.api.model.ApiResource) Resource(org.springframework.core.io.Resource) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver)

Aggregations

ApiResource (org.entando.entando.aps.system.services.api.model.ApiResource)17 ApiMethod (org.entando.entando.aps.system.services.api.model.ApiMethod)8 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)4 Properties (java.util.Properties)4 InputStream (java.io.InputStream)3 HashMap (java.util.HashMap)3 ApsProperties (com.agiletec.aps.util.ApsProperties)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ArrayList (java.util.ArrayList)2 StringApiResponse (org.entando.entando.aps.system.services.api.model.StringApiResponse)2 JAXBI18nLabel (org.entando.entando.aps.system.services.i18n.model.JAXBI18nLabel)2 JAXBContent (org.entando.entando.plugins.jacms.aps.system.services.api.model.JAXBContent)2 EntitySearchFilter (com.agiletec.aps.system.common.entity.model.EntitySearchFilter)1 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)1 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 Date (java.util.Date)1 List (java.util.List)1