use of com.agiletec.plugins.jacms.aps.system.services.resource.model.BaseResourceDataBean in project entando-core by entando.
the class ApiResourceInterface method addResource.
public StringApiResponse addResource(JAXBResource jaxbResource, Properties properties) throws ApiException, Throwable {
StringApiResponse response = new StringApiResponse();
BaseResourceDataBean bean = null;
try {
UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER);
this.check(jaxbResource, user, response, true);
if (null != response.getErrors() && !response.getErrors().isEmpty()) {
return response;
}
bean = jaxbResource.createBataBean(this.getCategoryManager());
String id = bean.getResourceId();
if (null != id && id.trim().length() > 0) {
Pattern pattern = Pattern.compile("^[a-zA-Z]+$");
Matcher matcher = pattern.matcher(id);
if (!matcher.matches()) {
throw new ApiException(IApiErrorCodes.API_PARAMETER_VALIDATION_ERROR, "The resourceId can contain only alphabetic characters", Response.Status.CONFLICT);
}
}
this.getResourceManager().addResource(bean);
response.setResult(IResponseBuilder.SUCCESS);
} catch (ApiException ae) {
throw ae;
} catch (Throwable t) {
_logger.error("error in addResource", t);
throw new ApsSystemException("Error into API method", t);
} finally {
if (null != bean && null != bean.getFile()) {
bean.getFile().delete();
}
}
return response;
}
use of com.agiletec.plugins.jacms.aps.system.services.resource.model.BaseResourceDataBean in project entando-core by entando.
the class ApiResourceInterface method updateResource.
public StringApiResponse updateResource(JAXBResource jaxbResource, Properties properties) throws Throwable {
StringApiResponse response = new StringApiResponse();
BaseResourceDataBean bean = null;
try {
UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER);
this.check(jaxbResource, user, response, false);
if (null != response.getErrors() && !response.getErrors().isEmpty()) {
return response;
}
bean = jaxbResource.createBataBean(this.getCategoryManager());
this.getResourceManager().updateResource(bean);
response.setResult(IResponseBuilder.SUCCESS);
} catch (Throwable t) {
_logger.error("error in updateResource", t);
throw new ApsSystemException("Error into API method", t);
} finally {
if (null != bean && null != bean.getFile()) {
bean.getFile().delete();
}
}
return response;
}
use of com.agiletec.plugins.jacms.aps.system.services.resource.model.BaseResourceDataBean in project entando-core by entando.
the class JAXBResource method createBataBean.
public BaseResourceDataBean createBataBean(ICategoryManager categoryManager) throws Throwable {
BaseResourceDataBean bean = new BaseResourceDataBean();
if (null != this.getCategories()) {
List<Category> categories = new ArrayList<>();
for (int i = 0; i < this.getCategories().size(); i++) {
String categoryCode = this.getCategories().get(i);
Category category = categoryManager.getCategory(categoryCode);
if (null != category) {
categories.add(category);
}
}
bean.setCategories(categories);
}
bean.setDescr(this.getDescription());
bean.setFileName(this.getFileName());
bean.setMainGroup(this.getMainGroup());
FileNameMap fileNameMap = URLConnection.getFileNameMap();
String mimeType = fileNameMap.getContentTypeFor(this.getFileName());
bean.setMimeType(mimeType);
bean.setResourceType(this.getTypeCode());
bean.setResourceId(this.getId());
if (null != this.getBase64()) {
File file = this.byteArrayToFile();
bean.setFile(file);
}
return bean;
}
Aggregations