use of org.entando.entando.plugins.jacms.aps.system.services.api.model.JAXBContent in project entando-core by entando.
the class ApiContentInterface method addContent.
public StringApiResponse addContent(JAXBContent jaxbContent, Properties properties) throws Throwable {
StringApiResponse response = new StringApiResponse();
try {
String typeCode = jaxbContent.getTypeCode();
Content prototype = (Content) this.getContentManager().getEntityPrototype(typeCode);
if (null == prototype) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Content type with code '" + typeCode + "' does not exist", Response.Status.CONFLICT);
}
Content content = (Content) jaxbContent.buildEntity(prototype, this.getCategoryManager());
if (null != content.getId()) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "You cannot specify Content Id", Response.Status.CONFLICT);
}
UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER);
content.setFirstEditor((null != user) ? user.getUsername() : SystemConstants.GUEST_USER_NAME);
response = this.validateAndSaveContent(content, properties);
} catch (ApiException ae) {
response.addErrors(ae.getErrors());
response.setResult(IResponseBuilder.FAILURE, null);
} catch (Throwable t) {
_logger.error("Error adding content", t);
throw new ApsSystemException("Error adding content", t);
}
return response;
}
use of org.entando.entando.plugins.jacms.aps.system.services.api.model.JAXBContent in project entando-core by entando.
the class ApiContentInterface method getContent.
public JAXBContent getContent(Properties properties) throws ApiException, Throwable {
JAXBContent jaxbContent = null;
String id = properties.getProperty("id");
try {
String langCode = properties.getProperty(SystemConstants.API_LANG_CODE_PARAMETER);
Content mainContent = this.getPublicContent(id);
jaxbContent = this.getJAXBContentInstance(mainContent, langCode);
UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER);
if (null == user) {
user = this.getUserManager().getGuestUser();
}
if (!this.getContentAuthorizationHelper().isAuth(user, mainContent)) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Required content '" + id + "' does not allowed", Response.Status.FORBIDDEN);
}
} catch (ApiException ae) {
throw ae;
} catch (Throwable t) {
_logger.error("error in getContent", t);
throw new ApsSystemException("Error into API method", t);
}
return jaxbContent;
}
use of org.entando.entando.plugins.jacms.aps.system.services.api.model.JAXBContent in project entando-core by entando.
the class ApiContentInterface method updateContent.
public StringApiResponse updateContent(JAXBContent jaxbContent, Properties properties) throws Throwable {
StringApiResponse response = new StringApiResponse();
try {
String typeCode = jaxbContent.getTypeCode();
Content prototype = (Content) this.getContentManager().getEntityPrototype(typeCode);
if (null == prototype) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Content type with code '" + typeCode + "' does not exist", Response.Status.CONFLICT);
}
Content content = (Content) jaxbContent.buildEntity(prototype, this.getCategoryManager());
Content masterContent = this.getContentManager().loadContent(content.getId(), false);
if (null == masterContent) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Content with code '" + content.getId() + "' does not exist", Response.Status.CONFLICT);
} else if (!masterContent.getMainGroup().equals(content.getMainGroup())) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Invalid main group " + content.getMainGroup() + " not equals then master " + masterContent.getMainGroup(), Response.Status.CONFLICT);
}
response = this.validateAndSaveContent(content, properties);
} catch (ApiException ae) {
response.addErrors(ae.getErrors());
response.setResult(IResponseBuilder.FAILURE, null);
} catch (Throwable t) {
_logger.error("Error updating content", t);
throw new ApsSystemException("Error updating content", t);
}
return response;
}
use of org.entando.entando.plugins.jacms.aps.system.services.api.model.JAXBContent 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.plugins.jacms.aps.system.services.api.model.JAXBContent 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