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