use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.
the class DataObjectManager method addUpdateDataObject.
private void addUpdateDataObject(DataObject dataobject, boolean updateDate) throws ApsSystemException {
try {
dataobject.setLastModified(new Date());
if (updateDate) {
dataobject.incrementVersion(false);
}
String status = dataobject.getStatus();
if (null == status) {
dataobject.setStatus(DataObject.STATUS_DRAFT);
} else if (status.equals(DataObject.STATUS_PUBLIC)) {
dataobject.setStatus(DataObject.STATUS_READY);
}
if (null == dataobject.getId()) {
IKeyGeneratorManager keyGenerator = (IKeyGeneratorManager) this.getService(SystemConstants.KEY_GENERATOR_MANAGER);
int key = keyGenerator.getUniqueKeyCurrentValue();
String id = dataobject.getTypeCode() + key;
dataobject.setId(id);
this.getDataObjectDAO().addEntity(dataobject);
} else {
this.getDataObjectDAO().updateDataObject(dataobject, updateDate);
}
} catch (Throwable t) {
logger.error("Error while saving dataobject", t);
throw new ApsSystemException("Error while saving dataobject", t);
}
}
use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.
the class DataObjectManager method loadDataObject.
@Override
public DataObject loadDataObject(String id, boolean onLine, boolean cacheable) throws ApsSystemException {
DataObject dataobject = null;
try {
DataObjectRecordVO dataobjectVo = this.loadDataObjectVO(id);
dataobject = this.createDataObject(dataobjectVo, onLine);
} catch (ApsSystemException e) {
logger.error("Error while loading dataobject : id {}", id, e);
throw new ApsSystemException("Error while loading dataobject : id " + id, e);
}
return dataobject;
}
use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.
the class DataObjectService method getCategoryUtilizer.
@Override
public List getCategoryUtilizer(String categoryCode) {
try {
DataObjectManager entityManager = (DataObjectManager) this.extractEntityManager(this.getManagerName());
List<String> idList = ((CategoryUtilizer) entityManager).getCategoryUtilizers(categoryCode);
return this.buildDtoList(idList, entityManager);
} catch (ApsSystemException ex) {
logger.error("Error loading dataobject references for category {}", categoryCode, ex);
throw new RestServerError("Error loading dataobject references for category", ex);
}
}
use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.
the class ApiDataObjectInterface method addDataObject.
public StringApiResponse addDataObject(JAXBDataObject jaxbDataObject, Properties properties) throws Throwable {
StringApiResponse response = new StringApiResponse();
try {
String typeCode = jaxbDataObject.getTypeCode();
DataObject prototype = (DataObject) this.getDataObjectManager().getEntityPrototype(typeCode);
if (null == prototype) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "DataObject type with code '" + typeCode + "' does not exist", Response.Status.CONFLICT);
}
DataObject dataObject = (DataObject) jaxbDataObject.buildEntity(prototype, this.getCategoryManager());
if (null != dataObject.getId()) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "You cannot specify DataObject Id", Response.Status.CONFLICT);
}
UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER);
dataObject.setFirstEditor((null != user) ? user.getUsername() : SystemConstants.GUEST_USER_NAME);
response = this.validateAndSaveDataObject(dataObject, properties);
} catch (ApiException ae) {
response.addErrors(ae.getErrors());
response.setResult(IResponseBuilder.FAILURE, null);
} catch (Throwable t) {
_logger.error("Error adding DataObject", t);
throw new ApsSystemException("Error adding DataObject", t);
}
return response;
}
use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.
the class ApiDataObjectInterface method getDataObject.
public JAXBDataObject getDataObject(Properties properties) throws ApiException, Throwable {
JAXBDataObject jaxbDataObject = null;
String id = properties.getProperty("id");
try {
String langCode = properties.getProperty(SystemConstants.API_LANG_CODE_PARAMETER);
DataObject mainDataObject = this.getPublicDataObject(id);
jaxbDataObject = this.getJAXBDataObjectInstance(mainDataObject, langCode);
UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER);
if (null == user) {
user = this.getUserManager().getGuestUser();
}
if (!this.getDataObjectAuthorizationHelper().isAuth(user, mainDataObject)) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Required DataObject '" + id + "' does not allowed", Response.Status.FORBIDDEN);
}
} catch (ApiException ae) {
throw ae;
} catch (Throwable t) {
_logger.error("error in getDataObject", t);
throw new ApsSystemException("Error into API method", t);
}
return jaxbDataObject;
}
Aggregations