use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.
the class ProtectedResourceProvider method provideProtectedResource.
@Override
public boolean provideProtectedResource(HttpServletRequest request, HttpServletResponse response) throws ApsSystemException {
try {
String[] uriSegments = request.getRequestURI().split("/");
int segments = uriSegments.length;
// CONTROLLO ASSOCIAZIONE RISORSA A CONTENUTO
int indexGuardian = 0;
String checkContentAssociation = uriSegments[segments - 2];
if (checkContentAssociation.equals(AbstractResourceAttribute.REFERENCED_RESOURCE_INDICATOR)) {
// LA Sintassi /<RES_ID>/<SIZE>/<LANG_CODE>/<REFERENCED_RESOURCE_INDICATOR>/<CONTENT_ID>
indexGuardian = 2;
}
String resId = uriSegments[segments - 3 - indexGuardian];
UserDetails currentUser = (UserDetails) request.getSession().getAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER);
if (currentUser == null) {
currentUser = this.getUserManager().getGuestUser();
}
boolean isAuthForProtectedRes = false;
if (indexGuardian != 0) {
if (this.isAuthOnProtectedRes(currentUser, resId, uriSegments[segments - 1])) {
isAuthForProtectedRes = true;
} else {
this.executeLoginRedirect(request, response);
return true;
}
}
ResourceInterface resource = this.getResourceManager().loadResource(resId);
if (resource == null) {
return false;
}
IAuthorizationManager authManager = this.getAuthorizationManager();
if (isAuthForProtectedRes || authManager.isAuthOnGroup(currentUser, resource.getMainGroup()) || authManager.isAuthOnGroup(currentUser, Group.ADMINS_GROUP_NAME)) {
ResourceInstance instance = null;
if (resource.isMultiInstance()) {
String sizeStr = uriSegments[segments - 2 - indexGuardian];
if (!this.isValidNumericString(sizeStr)) {
return false;
}
int size = Integer.parseInt(sizeStr);
String langCode = uriSegments[segments - 1 - indexGuardian];
instance = ((AbstractMultiInstanceResource) resource).getInstance(size, langCode);
} else {
instance = ((AbstractMonoInstanceResource) resource).getInstance();
}
this.createResponse(response, resource, instance);
return true;
}
} catch (Throwable t) {
_logger.error("Error extracting protected resource", t);
throw new ApsSystemException("Error extracting protected resource", t);
}
return false;
}
use of com.agiletec.aps.system.exception.ApsSystemException 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 com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.
the class ApiContentInterface method extractContents.
protected List<String> extractContents(Properties properties) throws Throwable {
List<String> contentsId = null;
try {
ApiContentListBean bean = this.buildSearchBean(properties);
UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER);
contentsId = this.getContentListHelper().getContentsId(bean, user);
} catch (ApiException ae) {
throw ae;
} catch (Throwable t) {
_logger.error("error in extractContents", t);
throw new ApsSystemException("Error into API method", t);
}
return contentsId;
}
use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.
the class ApiContentInterface method getContentToHtml.
public String getContentToHtml(Properties properties) throws ApiException, Throwable {
String render = null;
String id = properties.getProperty("id");
String modelId = properties.getProperty("modelId");
try {
if (null == modelId || modelId.trim().length() == 0) {
return null;
}
Content mainContent = this.getPublicContent(id);
Integer modelIdInteger = this.checkModel(modelId, mainContent);
if (null != modelIdInteger) {
String langCode = properties.getProperty(SystemConstants.API_LANG_CODE_PARAMETER);
render = this.getRenderedContent(id, modelIdInteger, langCode);
}
} catch (ApiException ae) {
throw ae;
} catch (Throwable t) {
_logger.error("error in getContentToHtml", t);
throw new ApsSystemException("Error into API method", t);
}
return render;
}
use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.
the class ApiContentModelInterface method deleteModel.
public void deleteModel(Properties properties) throws ApiException, Throwable {
String idString = properties.getProperty("id");
int id = 0;
try {
id = Integer.parseInt(idString);
} catch (NumberFormatException e) {
throw new ApiException(IApiErrorCodes.API_PARAMETER_VALIDATION_ERROR, "Invalid number format for 'id' parameter - '" + idString + "'", Response.Status.CONFLICT);
}
ContentModel model = this.getContentModelManager().getContentModel(id);
if (null == model) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Model with id '" + idString + "' does not exist", Response.Status.CONFLICT);
}
try {
this.getContentModelManager().removeContentModel(model);
} catch (Throwable t) {
_logger.error("Error deleting model", t);
// ApsSystemUtils.logThrowable(t, this, "deleteModel");
throw new ApsSystemException("Error deleting model", t);
}
}
Aggregations