Search in sources :

Example 6 with ApiMethod

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

the class TestApiDataObjectInterface method testCreateNewDataObject.

protected void testCreateNewDataObject(MediaType mediaType, String dataObjectId) throws Throwable {
    String dateNow = DateConverter.getFormattedDate(new Date(), SystemConstants.DATA_TYPE_METADATA_DATE_FORMAT);
    EntitySearchFilter filter = new EntitySearchFilter(IDataObjectManager.DATA_OBJECT_CREATION_DATE_FILTER_KEY, false, dateNow, null);
    EntitySearchFilter[] filters = { filter };
    List<String> ids = this.dataObjectManager.searchId(filters);
    assertTrue(ids.isEmpty());
    JAXBDataObject jaxbDataObject = this.testGetDataObject(mediaType, "admin", dataObjectId, "it");
    ApiResource dataTypeResource = this.getApiCatalogManager().getResource("core", "dataObject");
    ApiMethod postMethod = dataTypeResource.getPostMethod();
    Properties properties = super.createApiProperties("admin", "it", mediaType);
    try {
        jaxbDataObject.setId(null);
        Object response = this.getResponseBuilder().createResponse(postMethod, jaxbDataObject, properties);
        assertNotNull(response);
        assertTrue(response instanceof StringApiResponse);
        assertEquals(IResponseBuilder.SUCCESS, ((StringApiResponse) response).getResult());
        ids = this.dataObjectManager.searchId(filters);
        assertEquals(1, ids.size());
        String newDataObjectId = ids.get(0);
        DataObject newDataType = this.dataObjectManager.loadDataObject(newDataObjectId, false);
        DataObject masterDataType = this.dataObjectManager.loadDataObject(dataObjectId, true);
        List<AttributeInterface> attributes = masterDataType.getAttributeList();
        for (int i = 0; i < attributes.size(); i++) {
            AttributeInterface attribute = attributes.get(i);
            AttributeInterface newAttribute = (AttributeInterface) newDataType.getAttribute(attribute.getName());
            this.checkAttributes(attribute, newAttribute);
        }
    } catch (Exception e) {
        throw e;
    } finally {
        ids = this.dataObjectManager.searchId(filters);
        if (!ids.isEmpty()) {
            for (int i = 0; i < ids.size(); i++) {
                String id = ids.get(i);
                DataObject dataObject = this.dataObjectManager.loadDataObject(id, false);
                this.dataObjectManager.deleteDataObject(dataObject);
            }
        }
    }
}
Also used : ApiResource(org.entando.entando.aps.system.services.api.model.ApiResource) ApiMethod(org.entando.entando.aps.system.services.api.model.ApiMethod) JAXBDataObject(org.entando.entando.aps.system.services.dataobject.api.model.JAXBDataObject) Properties(java.util.Properties) Date(java.util.Date) DataObject(org.entando.entando.aps.system.services.dataobject.model.DataObject) JAXBDataObject(org.entando.entando.aps.system.services.dataobject.api.model.JAXBDataObject) DataObject(org.entando.entando.aps.system.services.dataobject.model.DataObject) JAXBDataObject(org.entando.entando.aps.system.services.dataobject.api.model.JAXBDataObject) 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 7 with ApiMethod

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

the class TestApiDataObjectInterface method testGetDataObject.

protected JAXBDataObject testGetDataObject(MediaType mediaType, String username, String dataId, String langCode) throws Throwable {
    ApiResource dataResource = this.getApiCatalogManager().getResource("core", "dataObject");
    ApiMethod getMethod = dataResource.getGetMethod();
    Properties properties = super.createApiProperties(username, langCode, mediaType);
    properties.put("id", dataId);
    Object result = this.getResponseBuilder().createResponse(getMethod, properties);
    assertNotNull(result);
    ApiDataObjectInterface apiDataObjectInterface = (ApiDataObjectInterface) this.getApplicationContext().getBean("ApiDataObjectInterface");
    Object singleResult = apiDataObjectInterface.getDataObject(properties);
    assertNotNull(singleResult);
    String toString = this.marshall(singleResult, mediaType);
    InputStream stream = new ByteArrayInputStream(toString.getBytes());
    JAXBDataObject jaxbData = (JAXBDataObject) UnmarshalUtils.unmarshal(super.getApplicationContext(), JAXBDataObject.class, stream, mediaType);
    assertNotNull(jaxbData);
    return jaxbData;
}
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) JAXBDataObject(org.entando.entando.aps.system.services.dataobject.api.model.JAXBDataObject) DataObject(org.entando.entando.aps.system.services.dataobject.model.DataObject) JAXBDataObject(org.entando.entando.aps.system.services.dataobject.api.model.JAXBDataObject) Properties(java.util.Properties)

Example 8 with ApiMethod

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

the class ApiCatalogManagerTest method testUpdateMethodStatus.

@Test
public void testUpdateMethodStatus() throws Throwable {
    when(resourceCacheWrapper.getMasterResource("getService")).thenReturn(createResource(null, "getService"));
    ApiMethod method = this.apiCatalogManager.getMethod(ApiMethod.HttpMethod.GET, "getService");
    method.setStatus(false);
    this.apiCatalogManager.updateMethodConfig(method);
    method = this.apiCatalogManager.getMethod(ApiMethod.HttpMethod.GET, "getService");
    assertFalse(method.isActive());
}
Also used : ApiMethod(org.entando.entando.aps.system.services.api.model.ApiMethod) Test(org.junit.Test)

Example 9 with ApiMethod

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

the class ApiServiceAction method newService.

/**
 * Create of new api service.
 *
 * @return The result code.
 */
public String newService() {
    try {
        if (null != this.getResourceCode()) {
            String[] sections = this.getResourceCode().split(":");
            if (sections.length == 2) {
                this.setNamespace(sections[0]);
                this.setResourceName(sections[1]);
            } else {
                this.setResourceName(sections[0]);
            }
        }
        String check = this.checkMasterMethod(this.getNamespace(), this.getResourceName());
        if (null != check) {
            return check;
        }
        ApiMethod masterMethod = this.getMethod(this.getNamespace(), this.getResourceName());
        if (null != this.getWidgetTypeCode() && null != masterMethod.getRelatedWidget()) {
            WidgetType type = this.getWidgetTypeManager().getWidgetType(this.getWidgetTypeCode());
            if (null != type && type.isLogic()) {
                ApsProperties parameters = this.extractParametersFromWidgetProperties(masterMethod.getRelatedWidget(), type.getConfig());
                this.setApiParameterValues(parameters);
            }
        }
        this.setApiParameters(masterMethod.getParameters());
        this.setStrutsAction(ApsAdminSystemConstants.ADD);
        this.setServiceKey(this.buildTempKey(masterMethod.getResourceName()));
    } catch (Throwable t) {
        _logger.error("error in newService", t);
        return FAILURE;
    }
    return SUCCESS;
}
Also used : ApiMethod(org.entando.entando.aps.system.services.api.model.ApiMethod) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType) ApsProperties(com.agiletec.aps.util.ApsProperties)

Example 10 with ApiMethod

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

the class ApiServiceAction method checkParameters.

private void checkParameters() {
    try {
        this.setApiParameterValues(new ApsProperties());
        ApiMethod masterMethod = this.getMethod(this.getNamespace(), this.getResourceName());
        List<ApiMethodParameter> apiParameters = masterMethod.getParameters();
        if (null == apiParameters) {
            return;
        }
        this.extractFreeParameters(apiParameters);
        this.setApiParameters(apiParameters);
        for (int i = 0; i < apiParameters.size(); i++) {
            ApiMethodParameter apiParameter = apiParameters.get(i);
            String fieldName = apiParameter.getKey() + "_apiParam";
            String value = this.getRequest().getParameter(fieldName);
            if (null != value && value.trim().length() > 0) {
                this.getApiParameterValues().put(apiParameter.getKey(), value);
            }
            boolean isFreeParameter = (null != this.getFreeParameters()) ? this.getFreeParameters().contains(apiParameter.getKey()) : false;
            if (apiParameter.isRequired() && (null == value || value.trim().length() == 0) && !isFreeParameter) {
                this.addFieldError(fieldName, this.getText("error.service.parameter.invalidSetting", new String[] { apiParameter.getKey(), apiParameter.getDescription() }));
            }
        }
    } catch (Throwable t) {
        _logger.error("Error checking parameters", t);
        throw new RuntimeException("Error checking parameters", t);
    }
}
Also used : ApiMethod(org.entando.entando.aps.system.services.api.model.ApiMethod) ApiMethodParameter(org.entando.entando.aps.system.services.api.model.ApiMethodParameter) ApsProperties(com.agiletec.aps.util.ApsProperties)

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