Search in sources :

Example 1 with StringApiResponse

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

the class ApiWidgetTypeInterface method updateWidgetType.

public StringApiResponse updateWidgetType(JAXBWidgetType jaxbWidgetType) throws ApiException, Throwable {
    StringApiResponse response = new StringApiResponse();
    WidgetType widgetTypeToUpdate = null;
    List<GuiFragment> addedFragments = new ArrayList<GuiFragment>();
    List<GuiFragment> updatedFragments = new ArrayList<GuiFragment>();
    try {
        widgetTypeToUpdate = this.getWidgetTypeManager().getWidgetType(jaxbWidgetType.getCode());
        if (null == widgetTypeToUpdate) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "WidgetType with code " + jaxbWidgetType.getCode() + " does not exists", Response.Status.CONFLICT);
        }
        WidgetType widgetType = jaxbWidgetType.getModifiedWidgetType(this.getWidgetTypeManager());
        this.checkAndSaveFragment(widgetType, jaxbWidgetType, false, response, addedFragments, updatedFragments);
        this.getWidgetTypeManager().updateWidgetType(widgetType.getCode(), widgetType.getTitles(), widgetType.getConfig(), widgetType.getMainGroup());
        response.setResult(IResponseBuilder.SUCCESS, null);
    } catch (ApiException ae) {
        this.revertPreviousObject(widgetTypeToUpdate, addedFragments, updatedFragments);
        throw ae;
    } catch (Throwable t) {
        this.revertPreviousObject(widgetTypeToUpdate, addedFragments, updatedFragments);
        _logger.error("Error updating widget type", t);
        throw t;
    }
    return response;
}
Also used : GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) JAXBGuiFragment(org.entando.entando.aps.system.services.guifragment.api.JAXBGuiFragment) ArrayList(java.util.ArrayList) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType) StringApiResponse(org.entando.entando.aps.system.services.api.model.StringApiResponse) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 2 with StringApiResponse

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

the class ApiContentInterface method addContent.

public StringApiResponse addContent(JAXBContent jaxbContent, Properties properties) throws Throwable {
    StringApiResponse response = new StringApiResponse();
    try {
        String typeCode = jaxbContent.getTypeCode();
        Content prototype = (Content) this.getContentManager().getEntityPrototype(typeCode);
        if (null == prototype) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Content type with code '" + typeCode + "' does not exist", Response.Status.CONFLICT);
        }
        Content content = (Content) jaxbContent.buildEntity(prototype, this.getCategoryManager());
        if (null != content.getId()) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "You cannot specify Content Id", Response.Status.CONFLICT);
        }
        UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER);
        content.setFirstEditor((null != user) ? user.getUsername() : SystemConstants.GUEST_USER_NAME);
        response = this.validateAndSaveContent(content, properties);
    } catch (ApiException ae) {
        response.addErrors(ae.getErrors());
        response.setResult(IResponseBuilder.FAILURE, null);
    } catch (Throwable t) {
        _logger.error("Error adding content", t);
        throw new ApsSystemException("Error adding content", t);
    }
    return response;
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) JAXBContent(org.entando.entando.plugins.jacms.aps.system.services.api.model.JAXBContent) 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 3 with StringApiResponse

use of org.entando.entando.aps.system.services.api.model.StringApiResponse 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;
}
Also used : Pattern(java.util.regex.Pattern) UserDetails(com.agiletec.aps.system.services.user.UserDetails) Matcher(java.util.regex.Matcher) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) BaseResourceDataBean(com.agiletec.plugins.jacms.aps.system.services.resource.model.BaseResourceDataBean) StringApiResponse(org.entando.entando.aps.system.services.api.model.StringApiResponse) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 4 with StringApiResponse

use of org.entando.entando.aps.system.services.api.model.StringApiResponse 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;
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) BaseResourceDataBean(com.agiletec.plugins.jacms.aps.system.services.resource.model.BaseResourceDataBean) StringApiResponse(org.entando.entando.aps.system.services.api.model.StringApiResponse)

Example 5 with StringApiResponse

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

the class ApiEntityTypeInterface method addEntityType.

public StringApiResponse addEntityType(JAXBEntityType jaxbEntityType) throws Throwable {
    StringApiResponse response = new StringApiResponse();
    try {
        IEntityManager manager = this.getEntityManager();
        String typeCode = jaxbEntityType.getTypeCode();
        IApsEntity masterEntityType = manager.getEntityPrototype(typeCode);
        if (null != masterEntityType) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, this.getTypeLabel() + " with code '" + typeCode + "' already exists");
        }
        if (typeCode == null || typeCode.length() != 3) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Invalid type code - '" + typeCode + "'");
        }
        Map<String, AttributeInterface> attributes = manager.getEntityAttributePrototypes();
        IApsEntity newEntityType = jaxbEntityType.buildEntityType(manager.getEntityClass(), attributes);
        this.checkNewEntityType(jaxbEntityType, newEntityType, response);
        ((IEntityTypesConfigurer) manager).addEntityPrototype(newEntityType);
        response.setResult(IResponseBuilder.SUCCESS, null);
    } catch (ApiException ae) {
        response.addErrors(ae.getErrors());
        response.setResult(IResponseBuilder.FAILURE, null);
    } catch (Throwable t) {
        _logger.error("Error extracting entity type", t);
        // ApsSystemUtils.logThrowable(t, this, "getEntityType");
        throw new ApsSystemException("Error extracting entity type", t);
    }
    return response;
}
Also used : IEntityManager(com.agiletec.aps.system.common.entity.IEntityManager) 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)

Aggregations

StringApiResponse (org.entando.entando.aps.system.services.api.model.StringApiResponse)28 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)23 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)20 UserDetails (com.agiletec.aps.system.services.user.UserDetails)9 ApiError (org.entando.entando.aps.system.services.api.model.ApiError)8 IApsEntity (com.agiletec.aps.system.common.entity.model.IApsEntity)6 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)5 IEntityTypesConfigurer (com.agiletec.aps.system.common.entity.IEntityTypesConfigurer)4 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)4 ApiMethod (org.entando.entando.aps.system.services.api.model.ApiMethod)4 JAXBContent (org.entando.entando.plugins.jacms.aps.system.services.api.model.JAXBContent)4 JAXBDataObject (org.entando.entando.aps.system.services.dataobject.api.model.JAXBDataObject)3 DataObject (org.entando.entando.aps.system.services.dataobject.model.DataObject)3 IUserProfile (org.entando.entando.aps.system.services.userprofile.model.IUserProfile)3 ContentRecordVO (com.agiletec.plugins.jacms.aps.system.services.content.model.ContentRecordVO)2 BaseResourceDataBean (com.agiletec.plugins.jacms.aps.system.services.resource.model.BaseResourceDataBean)2 ResourceInterface (com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface)2 Properties (java.util.Properties)2 ApiResource (org.entando.entando.aps.system.services.api.model.ApiResource)2 IEntityManager (com.agiletec.aps.system.common.entity.IEntityManager)1