use of org.entando.entando.aps.system.services.api.model.StringApiResponse 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.StringApiResponse in project entando-core by entando.
the class ApiUserProfileInterface method deleteUserProfile.
public void deleteUserProfile(Properties properties) throws ApiException, Throwable {
StringApiResponse response = new StringApiResponse();
try {
String username = properties.getProperty("username");
IUserProfile userProfile = this.getUserProfileManager().getProfile(username);
if (null == userProfile) {
throw new ApiException(IApiErrorCodes.API_PARAMETER_VALIDATION_ERROR, "Profile of user '" + username + "' does not exist", Response.Status.CONFLICT);
}
this.getUserProfileManager().deleteProfile(username);
response.setResult(IResponseBuilder.SUCCESS, null);
} catch (ApiException ae) {
response.addErrors(ae.getErrors());
response.setResult(IResponseBuilder.FAILURE, null);
} catch (Throwable t) {
_logger.error("Error deleting user Profile", t);
// ApsSystemUtils.logThrowable(t, this, "deleteUserProfile");
throw new ApsSystemException("Error deleting user Profile", t);
}
}
use of org.entando.entando.aps.system.services.api.model.StringApiResponse in project entando-core by entando.
the class ApiUserProfileInterface method updateUserProfile.
public StringApiResponse updateUserProfile(JAXBUserProfile jaxbUserProfile) throws Throwable {
StringApiResponse response = new StringApiResponse();
try {
String username = jaxbUserProfile.getId();
if (null == this.getUserProfileManager().getProfile(username)) {
throw new ApiException(IApiErrorCodes.API_PARAMETER_VALIDATION_ERROR, "Profile of user '" + username + "' does not exist", Response.Status.CONFLICT);
}
IApsEntity profilePrototype = this.getUserProfileManager().getEntityPrototype(jaxbUserProfile.getTypeCode());
if (null == profilePrototype) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "User Profile type with code '" + jaxbUserProfile.getTypeCode() + "' does not exist", Response.Status.CONFLICT);
}
IUserProfile userProfile = (IUserProfile) jaxbUserProfile.buildEntity(profilePrototype, null);
List<ApiError> errors = this.validate(userProfile);
if (errors.size() > 0) {
response.addErrors(errors);
response.setResult(IResponseBuilder.FAILURE, null);
return response;
}
this.getUserProfileManager().updateProfile(username, userProfile);
response.setResult(IResponseBuilder.SUCCESS, null);
} catch (ApiException ae) {
response.addErrors(ae.getErrors());
response.setResult(IResponseBuilder.FAILURE, null);
} catch (Throwable t) {
_logger.error("Error updating user profile", t);
// ApsSystemUtils.logThrowable(t, this, "updateUserProfile");
throw new ApsSystemException("Error updating user profile", t);
}
return response;
}
Aggregations