Search in sources :

Example 11 with ApiException

use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.

the class ApiEntityTypeInterface method updateEntityType.

public StringApiResponse updateEntityType(JAXBEntityType jaxbEntityType) throws Throwable {
    StringApiResponse response = new StringApiResponse();
    try {
        String typeCode = jaxbEntityType.getTypeCode();
        IApsEntity masterUserProfileType = this.getEntityManager().getEntityPrototype(typeCode);
        if (null == masterUserProfileType) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, this.getTypeLabel() + " with code '" + typeCode + "' doesn't exist");
        }
        Map<String, AttributeInterface> attributes = this.getEntityManager().getEntityAttributePrototypes();
        IApsEntity entityTypeToUpdate = jaxbEntityType.buildEntityType(this.getEntityManager().getEntityClass(), attributes);
        this.checkEntityTypeToUpdate(jaxbEntityType, entityTypeToUpdate, response);
        ((IEntityTypesConfigurer) this.getEntityManager()).updateEntityPrototype(entityTypeToUpdate);
        response.setResult(IResponseBuilder.SUCCESS, null);
    } catch (ApiException ae) {
        response.addErrors(ae.getErrors());
        response.setResult(IResponseBuilder.FAILURE, null);
    } catch (Throwable t) {
        _logger.error("Error updating entity type", t);
        // ApsSystemUtils.logThrowable(t, this, "updateEntityType");
        throw new ApsSystemException("Error updating entity type", t);
    }
    return response;
}
Also used : IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) IEntityTypesConfigurer(com.agiletec.aps.system.common.entity.IEntityTypesConfigurer) StringApiResponse(org.entando.entando.aps.system.services.api.model.StringApiResponse) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 12 with ApiException

use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.

the class JAXBEntityType method buildEntityType.

public IApsEntity buildEntityType(Class entityClass, Map<String, AttributeInterface> attributes) throws ApiException, Throwable {
    List<ApiError> errors = new ArrayList<ApiError>();
    IApsEntity entityType = null;
    try {
        entityType = (IApsEntity) entityClass.newInstance();
        entityType.setTypeCode(this.getTypeCode());
        entityType.setTypeDescr(this.getTypeDescription());
        List<DefaultJAXBAttributeType> jabxAttributes = this.getAttributes();
        for (int i = 0; i < jabxAttributes.size(); i++) {
            try {
                DefaultJAXBAttributeType jaxbAttributeType = jabxAttributes.get(i);
                AttributeInterface attribute = jaxbAttributeType.createAttribute(attributes);
                if (null != entityType.getAttribute(attribute.getName())) {
                    throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Attribute '" + attribute.getName() + "' already defined");
                }
                entityType.addAttribute(attribute);
            } catch (ApiException e) {
                errors.addAll(e.getErrors());
            }
        }
    } catch (Throwable t) {
        _logger.error("error in buildEntityType", t);
        // ApsSystemUtils.logThrowable(t, this, "buildEntityType");
        throw t;
    }
    if (!errors.isEmpty())
        throw new ApiException(errors);
    return entityType;
}
Also used : ArrayList(java.util.ArrayList) IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity) ApiError(org.entando.entando.aps.system.services.api.model.ApiError) DefaultJAXBAttributeType(com.agiletec.aps.system.common.entity.model.attribute.DefaultJAXBAttributeType) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 13 with ApiException

use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.

the class ApiI18nLabelInterface method getLabel.

public JAXBI18nLabel getLabel(Properties properties) throws ApiException, ApsSystemException {
    JAXBI18nLabel jaxbI18nLabel = null;
    try {
        String key = properties.getProperty("key");
        ApsProperties labelGroups = this.getI18nManager().getLabelGroup(key);
        if (null == labelGroups) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Label with key '" + key + "' does not exist", Response.Status.CONFLICT);
        }
        jaxbI18nLabel = new JAXBI18nLabel(key, labelGroups);
    } catch (ApiException ae) {
        throw ae;
    } catch (ApsSystemException t) {
        _logger.error("error loading labels", t);
        throw new ApsSystemException("Error loading labels", t);
    }
    return jaxbI18nLabel;
}
Also used : JAXBI18nLabel(org.entando.entando.aps.system.services.i18n.model.JAXBI18nLabel) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ApsProperties(com.agiletec.aps.util.ApsProperties) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 14 with ApiException

use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.

the class ApiI18nLabelInterface method updateInlineLabel.

public void updateInlineLabel(JAXBI18nLabel jaxbI18nLabel) throws ApiException {
    try {
        this.checkLabels(jaxbI18nLabel);
        String key = jaxbI18nLabel.getKey();
        ApsProperties labelGroups = this.getI18nManager().getLabelGroup(key);
        _logger.info("KEY ->  {} ", key);
        boolean isEdit = (null != labelGroups);
        if (!isEdit) {
            labelGroups = new ApsProperties();
        } else {
        // 
        }
        ApsProperties labels = jaxbI18nLabel.extractLabels();
        Iterator<Object> iterator = labels.keySet().iterator();
        while (iterator.hasNext()) {
            Object langKey = iterator.next();
            labelGroups.put(langKey, labels.get(langKey));
        }
        if (isEdit) {
            this.getI18nManager().updateLabelGroup(key, labelGroups);
            _logger.info("*** EDIT DONE *** -> {}", labelGroups);
        } else {
            this.getI18nManager().addLabelGroup(key, labelGroups);
            _logger.info("*** ADD DONE *** -> {}", labelGroups);
        }
    } catch (ApiException | ApsSystemException t) {
        _logger.error("Error updating label {} ", t);
        throw new ApiException("Error updating labels", t);
    }
}
Also used : ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ApsProperties(com.agiletec.aps.util.ApsProperties) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 15 with ApiException

use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.

the class ApiI18nLabelInterface method checkLabels.

protected void checkLabels(JAXBI18nLabel jaxbI18nLabel) throws ApiException {
    try {
        String key = jaxbI18nLabel.getKey();
        if (null == key || key.trim().length() == 0) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Label key required", Response.Status.CONFLICT);
        }
        ApsProperties labels = jaxbI18nLabel.extractLabels();
        if (null == labels || labels.isEmpty()) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Label list can't be empty", Response.Status.CONFLICT);
        }
        Iterator<Object> labelCodeIter = labels.keySet().iterator();
        while (labelCodeIter.hasNext()) {
            Object langCode = labelCodeIter.next();
            Object value = labels.get(langCode);
            if (null == value || value.toString().trim().length() == 0) {
                throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Label for the language '" + langCode + "' is empty", Response.Status.CONFLICT);
            }
        }
    } catch (ApiException ae) {
        _logger.error("Error method checkLabels ", ae);
        throw new ApiException("Error method checkLabels", ae);
    }
}
Also used : ApiException(org.entando.entando.aps.system.services.api.model.ApiException) ApsProperties(com.agiletec.aps.util.ApsProperties)

Aggregations

ApiException (org.entando.entando.aps.system.services.api.model.ApiException)80 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)49 StringApiResponse (org.entando.entando.aps.system.services.api.model.StringApiResponse)23 UserDetails (com.agiletec.aps.system.services.user.UserDetails)13 ApsProperties (com.agiletec.aps.util.ApsProperties)12 IApsEntity (com.agiletec.aps.system.common.entity.model.IApsEntity)11 ApiError (org.entando.entando.aps.system.services.api.model.ApiError)10 ArrayList (java.util.ArrayList)9 GuiFragment (org.entando.entando.aps.system.services.guifragment.GuiFragment)9 WidgetType (org.entando.entando.aps.system.services.widgettype.WidgetType)9 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)7 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)7 JAXBDataObject (org.entando.entando.aps.system.services.dataobject.api.model.JAXBDataObject)7 DataObject (org.entando.entando.aps.system.services.dataobject.model.DataObject)7 JAXBContent (org.entando.entando.plugins.jacms.aps.system.services.api.model.JAXBContent)7 IEntityTypesConfigurer (com.agiletec.aps.system.common.entity.IEntityTypesConfigurer)6 EntitySearchFilter (com.agiletec.aps.system.common.entity.model.EntitySearchFilter)5 ApiMethod (org.entando.entando.aps.system.services.api.model.ApiMethod)5 IUserProfile (org.entando.entando.aps.system.services.userprofile.model.IUserProfile)5 Properties (java.util.Properties)4