Search in sources :

Example 21 with ApiMethod

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

the class ApiCatalogManager method getMethods.

@Override
public List<ApiMethod> getMethods(ApiMethod.HttpMethod httpMethod) throws ApsSystemException {
    List<ApiMethod> clonedMethods = new ArrayList<>();
    try {
        List<ApiMethod> masterMethods = this.getMasterMethods(httpMethod);
        for (int i = 0; i < masterMethods.size(); i++) {
            ApiMethod apiMethod = masterMethods.get(i);
            clonedMethods.add(apiMethod.clone());
        }
    } catch (Throwable t) {
        logger.error("Error extracting methods", t);
        throw new ApsSystemException("Error extracting methods", t);
    }
    return clonedMethods;
}
Also used : ApiMethod(org.entando.entando.aps.system.services.api.model.ApiMethod) ArrayList(java.util.ArrayList) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 22 with ApiMethod

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

the class ApiCatalogManager method resetMethodConfig.

@Override
public void resetMethodConfig(ApiMethod apiMethod) throws ApsSystemException {
    try {
        ApiMethod masterMethod = this.checkMethod(apiMethod);
        String resourceCode = ApiResource.getCode(masterMethod.getNamespace(), masterMethod.getResourceName());
        this.getApiCatalogDAO().resetApiStatus(resourceCode, masterMethod.getHttpMethod());
        masterMethod.resetConfiguration();
    } catch (Throwable t) {
        logger.error("Error error resetting api status : resource '{}' method '{}'", apiMethod.getResourceName(), apiMethod.getHttpMethod(), t);
        throw new ApsSystemException("Error resetting api status", t);
    }
}
Also used : ApiMethod(org.entando.entando.aps.system.services.api.model.ApiMethod) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 23 with ApiMethod

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

the class ApiRestStatusServer method getApiStatus.

@GET
@Produces({ "application/json", "application/xml", "application/javascript" })
@Path("/{namespace}/{resourceName}/{httpMethod}")
public Object getApiStatus(@PathParam("httpMethod") String httpMethodString, @PathParam("namespace") String namespace, @PathParam("resourceName") String resourceName, @Context HttpServletRequest request) {
    StringApiResponse response = new StringApiResponse();
    ApiMethod.HttpMethod httpMethod = Enum.valueOf(ApiMethod.HttpMethod.class, httpMethodString.toUpperCase());
    try {
        IResponseBuilder responseBuilder = (IResponseBuilder) ApsWebApplicationUtils.getBean(SystemConstants.API_RESPONSE_BUILDER, request);
        ApiMethod apiMethod = responseBuilder.extractApiMethod(httpMethod, namespace, resourceName);
        if (null != apiMethod.getRequiredPermission()) {
            response.setResult(ApiStatus.AUTHORIZATION_REQUIRED.toString(), null);
        } else if (apiMethod.getRequiredAuth()) {
            response.setResult(ApiStatus.AUTHENTICATION_REQUIRED.toString(), null);
        } else {
            response.setResult(ApiStatus.FREE.toString(), null);
        }
    } catch (ApiException ae) {
        response.addErrors(((ApiException) ae).getErrors());
        response.setResult(ApiStatus.INACTIVE.toString(), null);
    } catch (Throwable t) {
        return this.buildErrorResponse(httpMethod, namespace, resourceName, t);
    }
    return response;
}
Also used : ApiMethod(org.entando.entando.aps.system.services.api.model.ApiMethod) StringApiResponse(org.entando.entando.aps.system.services.api.model.StringApiResponse) ApiException(org.entando.entando.aps.system.services.api.model.ApiException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 24 with ApiMethod

use of org.entando.entando.aps.system.services.api.model.ApiMethod 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 25 with ApiMethod

use of org.entando.entando.aps.system.services.api.model.ApiMethod 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)

Aggregations

ApiMethod (org.entando.entando.aps.system.services.api.model.ApiMethod)40 Properties (java.util.Properties)11 ApiResource (org.entando.entando.aps.system.services.api.model.ApiResource)10 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)9 ApsProperties (com.agiletec.aps.util.ApsProperties)6 StringApiResponse (org.entando.entando.aps.system.services.api.model.StringApiResponse)6 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)5 ApiService (org.entando.entando.aps.system.services.api.model.ApiService)5 Method (java.lang.reflect.Method)4 HashMap (java.util.HashMap)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 ApiMethodRelatedWidget (org.entando.entando.aps.system.services.api.model.ApiMethodRelatedWidget)3 EntitySearchFilter (com.agiletec.aps.system.common.entity.model.EntitySearchFilter)2 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2