Search in sources :

Example 81 with ApsSystemException

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);
    }
}
Also used : IKeyGeneratorManager(com.agiletec.aps.system.services.keygenerator.IKeyGeneratorManager) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) Date(java.util.Date)

Example 82 with ApsSystemException

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;
}
Also used : DataObject(org.entando.entando.aps.system.services.dataobject.model.DataObject) DataObjectRecordVO(org.entando.entando.aps.system.services.dataobject.model.DataObjectRecordVO) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 83 with ApsSystemException

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);
    }
}
Also used : CategoryUtilizer(com.agiletec.aps.system.services.category.CategoryUtilizer) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 84 with ApsSystemException

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;
}
Also used : JAXBDataObject(org.entando.entando.aps.system.services.dataobject.api.model.JAXBDataObject) DataObject(org.entando.entando.aps.system.services.dataobject.model.DataObject) UserDetails(com.agiletec.aps.system.services.user.UserDetails) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) StringApiResponse(org.entando.entando.aps.system.services.api.model.StringApiResponse) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 85 with ApsSystemException

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;
}
Also used : JAXBDataObject(org.entando.entando.aps.system.services.dataobject.api.model.JAXBDataObject) DataObject(org.entando.entando.aps.system.services.dataobject.model.DataObject) UserDetails(com.agiletec.aps.system.services.user.UserDetails) JAXBDataObject(org.entando.entando.aps.system.services.dataobject.api.model.JAXBDataObject) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Aggregations

ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)452 ArrayList (java.util.ArrayList)53 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)48 RestServerError (org.entando.entando.aps.system.exception.RestServerError)39 ApsProperties (com.agiletec.aps.util.ApsProperties)26 IApsEntity (com.agiletec.aps.system.common.entity.model.IApsEntity)23 HashMap (java.util.HashMap)23 UserDetails (com.agiletec.aps.system.services.user.UserDetails)21 StringApiResponse (org.entando.entando.aps.system.services.api.model.StringApiResponse)21 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)20 Date (java.util.Date)20 StringReader (java.io.StringReader)18 IPage (com.agiletec.aps.system.services.page.IPage)17 List (java.util.List)17 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)16 File (java.io.File)16 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)16 Widget (com.agiletec.aps.system.services.page.Widget)15 IOException (java.io.IOException)15 Cache (org.springframework.cache.Cache)15