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);
}
}
}
}
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;
}
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());
}
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;
}
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);
}
}
Aggregations