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