Search in sources :

Example 36 with DataObject

use of org.entando.entando.aps.system.services.dataobject.model.DataObject in project entando-core by entando.

the class DataObjectUpdaterService method reloadEntityReferences.

public void reloadEntityReferences(String entityId) {
    try {
        String cacheKey = JacmsSystemConstants.CONTENT_CACHE_PREFIX + entityId;
        this.getCacheInfoManager().flushEntry(ICacheInfoManager.DEFAULT_CACHE_NAME, cacheKey);
        ApsSystemUtils.getLogger().debug("removing_from_cache " + cacheKey);
        DataObject content = this.getContentManager().loadDataObject(entityId, true);
        if (content != null) {
            this.getContentUpdaterDAO().reloadDataObjectCategoryReferences(content);
        }
        ApsSystemUtils.getLogger().debug("Reload content references for content " + entityId + "- DONE");
    } catch (Throwable t) {
        ApsSystemUtils.logThrowable(t, this, "reloadEntityReferences");
    }
}
Also used : DataObject(org.entando.entando.aps.system.services.dataobject.model.DataObject)

Example 37 with DataObject

use of org.entando.entando.aps.system.services.dataobject.model.DataObject in project entando-core by entando.

the class ApiDataObjectInterface method updateDataObjectText.

public void updateDataObjectText(JAXBDataObjectAttribute jaxbDataObjectAttribute, Properties properties) throws ApiException, Throwable {
    try {
        String dataId = jaxbDataObjectAttribute.getDataId();
        DataObject masterDataObject = this.getDataObjectManager().loadDataObject(jaxbDataObjectAttribute.getDataId(), true);
        if (null == masterDataObject) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "DataObject with code '" + dataId + "' does not exist", Response.Status.CONFLICT);
        }
        String attributeName = jaxbDataObjectAttribute.getAttributeName();
        AttributeInterface attribute = (AttributeInterface) masterDataObject.getAttribute(attributeName);
        if (null == attribute) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "DataObject Attribute with code '" + attributeName + "' does not exist into DataObject " + dataId, Response.Status.CONFLICT);
        } else if (!(attribute instanceof ITextAttribute)) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "DataObject Attribute with code '" + attributeName + "' isn't a Text Atttribute", Response.Status.CONFLICT);
        }
        String langCode = jaxbDataObjectAttribute.getLangCode();
        String value = jaxbDataObjectAttribute.getValue();
        if (StringUtils.isEmpty(langCode) || StringUtils.isEmpty(value)) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "LangCode or value is Empty", Response.Status.CONFLICT);
        }
        ((ITextAttribute) attribute).setText(value, langCode);
        this.getDataObjectManager().insertDataObject(masterDataObject);
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("Error updating DataObject attribute", t);
        throw new ApsSystemException("Error updating DataObject attribute", t);
    }
}
Also used : ITextAttribute(com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute) JAXBDataObject(org.entando.entando.aps.system.services.dataobject.api.model.JAXBDataObject) DataObject(org.entando.entando.aps.system.services.dataobject.model.DataObject) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 38 with DataObject

use of org.entando.entando.aps.system.services.dataobject.model.DataObject in project entando-core by entando.

the class ApiDataObjectInterface method getDataObjectsToHtml.

public String getDataObjectsToHtml(Properties properties) throws Throwable {
    StringBuilder render = new StringBuilder();
    try {
        String modelId = properties.getProperty("modelId");
        if (null == modelId || modelId.trim().length() == 0) {
            return null;
        }
        String dataType = properties.getProperty("dataType");
        DataObject prototype = (DataObject) this.getDataObjectManager().getEntityPrototype(dataType);
        Integer modelIdInteger = this.checkModel(modelId, prototype);
        if (null == modelIdInteger) {
            return null;
        }
        List<String> dataObjectsId = this.extractDataObjects(properties);
        String langCode = properties.getProperty(SystemConstants.API_LANG_CODE_PARAMETER);
        render.append(this.getItemsStartElement());
        for (int i = 0; i < dataObjectsId.size(); i++) {
            render.append(this.getItemStartElement());
            String renderedData = this.getRenderedDataObject(dataObjectsId.get(i), modelIdInteger, langCode);
            if (null != renderedData) {
                render.append(renderedData);
            }
            render.append(this.getItemEndElement());
        }
        render.append(this.getItemsEndElement());
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("error in getDataObjectsToHtml", t);
        throw new ApsSystemException("Error into API method", t);
    }
    return render.toString();
}
Also used : JAXBDataObject(org.entando.entando.aps.system.services.dataobject.api.model.JAXBDataObject) DataObject(org.entando.entando.aps.system.services.dataobject.model.DataObject) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 39 with DataObject

use of org.entando.entando.aps.system.services.dataobject.model.DataObject in project entando-core by entando.

the class ApiDataObjectInterface method deleteDataObject.

public StringApiResponse deleteDataObject(Properties properties) throws Throwable {
    StringApiResponse response = new StringApiResponse();
    try {
        String id = properties.getProperty("id");
        DataObject masterDataObject = this.getDataObjectManager().loadDataObject(id, false);
        if (null == masterDataObject) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "DataObject with code '" + id + "' does not exist", Response.Status.CONFLICT);
        }
        UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER);
        if (null == user) {
            user = this.getUserManager().getGuestUser();
        }
        if (!this.getDataObjectAuthorizationHelper().isAuth(user, masterDataObject)) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "DataObject groups makes the new dataObject not allowed for user " + user.getUsername(), Response.Status.FORBIDDEN);
        }
        if (masterDataObject.isOnLine()) {
            this.getDataObjectManager().removeDataObject(masterDataObject);
        }
        response.setResult(IResponseBuilder.SUCCESS, null);
    } catch (ApiException ae) {
        response.addErrors(ae.getErrors());
        response.setResult(IResponseBuilder.FAILURE, null);
    } catch (Throwable t) {
        _logger.error("Error deleting DataObject", t);
        throw new ApsSystemException("Error deleting 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 40 with DataObject

use of org.entando.entando.aps.system.services.dataobject.model.DataObject in project entando-core by entando.

the class ApiDataObjectTypeInterface method createJAXBEntityType.

@Override
protected JAXBEntityType createJAXBEntityType(IApsEntity masterEntityType) {
    DataObject masterDataObjectType = (DataObject) masterEntityType;
    JAXBDataObjectType jaxbDataObjectType = new JAXBDataObjectType(masterDataObjectType);
    jaxbDataObjectType.setDefaultModelId(this.extractModelId(masterDataObjectType.getDefaultModel()));
    jaxbDataObjectType.setListModelId(this.extractModelId(masterDataObjectType.getListModel()));
    return jaxbDataObjectType;
}
Also used : DataObject(org.entando.entando.aps.system.services.dataobject.model.DataObject) JAXBDataObjectType(org.entando.entando.aps.system.services.dataobject.api.model.JAXBDataObjectType)

Aggregations

DataObject (org.entando.entando.aps.system.services.dataobject.model.DataObject)72 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)10 UserDetails (com.agiletec.aps.system.services.user.UserDetails)9 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)7 JAXBDataObject (org.entando.entando.aps.system.services.dataobject.api.model.JAXBDataObject)7 Test (org.junit.Test)7 TextAttribute (com.agiletec.aps.system.common.entity.model.attribute.TextAttribute)6 ArrayList (java.util.ArrayList)5 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)4 ITextAttribute (com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute)4 MonoTextAttribute (com.agiletec.aps.system.common.entity.model.attribute.MonoTextAttribute)4 Category (com.agiletec.aps.system.services.category.Category)4 Date (java.util.Date)4 EntitySearchFilter (com.agiletec.aps.system.common.entity.model.EntitySearchFilter)3 FieldError (com.agiletec.aps.system.common.entity.model.FieldError)3 DateAttribute (com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)3 MonoListAttribute (com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute)3 Group (com.agiletec.aps.system.services.group.Group)3 StringApiResponse (org.entando.entando.aps.system.services.api.model.StringApiResponse)3 IDataObjectManager (org.entando.entando.aps.system.services.dataobject.IDataObjectManager)3