Search in sources :

Example 1 with ApiError

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

the class ApiWidgetTypeInterface method checkAndSaveFragment.

protected void checkAndSaveFragment(WidgetType type, JAXBWidgetType jaxbWidgetType, boolean isAdd, StringApiResponse response, List<GuiFragment> addedFragments, List<GuiFragment> updatedFragment) throws Throwable {
    try {
        if (!type.isLogic() && !this.isInternalServletWidget(type.getCode())) {
            GuiFragment guiFragment = this.getGuiFragmentManager().getUniqueGuiFragmentByWidgetType(type.getCode());
            if (StringUtils.isNotBlank(jaxbWidgetType.getGui())) {
                if (null == guiFragment) {
                    guiFragment = new GuiFragment();
                    String code = this.extractUniqueGuiFragmentCode(type.getCode());
                    guiFragment.setCode(code);
                    guiFragment.setPluginCode(type.getPluginCode());
                    guiFragment.setGui(jaxbWidgetType.getGui());
                    guiFragment.setWidgetTypeCode(type.getCode());
                    addedFragments.add(guiFragment);
                    this.getGuiFragmentManager().addGuiFragment(guiFragment);
                } else if (!isAdd) {
                    GuiFragment clone = guiFragment.clone();
                    updatedFragment.add(guiFragment);
                    clone.setGui(jaxbWidgetType.getGui());
                    this.getGuiFragmentManager().updateGuiFragment(clone);
                }
            } else {
                if (null != guiFragment && !isAdd) {
                    if (StringUtils.isNotBlank(guiFragment.getDefaultGui())) {
                        GuiFragment clone = guiFragment.clone();
                        updatedFragment.add(guiFragment);
                        clone.setGui(null);
                        this.getGuiFragmentManager().updateGuiFragment(clone);
                    } else {
                    // nothing to do...
                    // this.getGuiFragmentManager().deleteGuiFragment(guiFragment.getCode());
                    }
                }
            }
        } else if (type.isLogic() && !isAdd) {
            boolean isInternalServlet = this.isInternalServletWidget(type.getParentType().getCode());
            if (!isInternalServlet && (null != jaxbWidgetType.getFragments() && jaxbWidgetType.getFragments().size() > 0)) {
                if (null != response) {
                    ApiError error = new ApiError(IApiErrorCodes.API_VALIDATION_ERROR, "Fragments mustn't be updated on a 'not internal servlet' logic widget type");
                    response.addError(error);
                }
            // throw new
            // ApiException(IApiErrorCodes.API_VALIDATION_ERROR,
            // "Fragments mustn't be updated on a 'not internal servlet'
            // logic widget type", Response.Status.CONFLICT);
            } else {
                List<JAXBGuiFragment> fragments = jaxbWidgetType.getFragments();
                if (null != fragments && fragments.size() > 0) {
                    for (int i = 0; i < fragments.size(); i++) {
                        JAXBGuiFragment jaxbGuiFragment = fragments.get(i);
                        GuiFragment fragment = jaxbGuiFragment.getGuiFragment();
                        GuiFragment existingFragment = this.getGuiFragmentManager().getGuiFragment(fragment.getCode());
                        if (null != existingFragment) {
                            if (StringUtils.isBlank(existingFragment.getDefaultGui()) && StringUtils.isBlank(jaxbWidgetType.getGui())) {
                                ApiError error = new ApiError(IApiErrorCodes.API_VALIDATION_ERROR, "one between A and B must be valued on fragment '" + existingFragment.getCode() + "'");
                                response.addError(error);
                                continue;
                            }
                            GuiFragment clone = existingFragment.clone();
                            updatedFragment.add(existingFragment);
                            clone.setGui(jaxbGuiFragment.getGui());
                        } else {
                            ApiError error = new ApiError(IApiErrorCodes.API_VALIDATION_ERROR, "Fragment '" + fragment.getCode() + "' does not exists");
                            response.addError(error);
                        }
                    }
                }
            }
        }
    } catch (Throwable t) {
        _logger.error("error checking and saving fragment", t);
        throw new ApsSystemException("error checking and saving fragment", t);
    }
}
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) List(java.util.List) JAXBGuiFragment(org.entando.entando.aps.system.services.guifragment.api.JAXBGuiFragment) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ApiError(org.entando.entando.aps.system.services.api.model.ApiError)

Example 2 with ApiError

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

the class ApiContentTypeInterface method checkContentModel.

private boolean checkContentModel(Integer modelId, Content contentType, StringApiResponse response) {
    if (null == modelId) {
        return true;
    }
    ContentModel contentModel = this.getContentModelManager().getContentModel(modelId);
    if (null == contentModel) {
        ApiError error = new ApiError(IApiErrorCodes.API_VALIDATION_ERROR, "Content model with id '" + modelId + "' does not exist", Response.Status.ACCEPTED);
        response.addError(error);
        return false;
    }
    if (!contentType.getTypeCode().equals(contentModel.getContentType())) {
        ApiError error = new ApiError(IApiErrorCodes.API_VALIDATION_ERROR, "Content model with id '" + modelId + "' is for contents of type '" + contentModel.getContentType() + "'", Response.Status.ACCEPTED);
        response.addError(error);
        return false;
    }
    return true;
}
Also used : ContentModel(com.agiletec.plugins.jacms.aps.system.services.contentmodel.ContentModel) ApiError(org.entando.entando.aps.system.services.api.model.ApiError)

Example 3 with ApiError

use of org.entando.entando.aps.system.services.api.model.ApiError 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 4 with ApiError

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

the class ApiUserProfileInterface method addUserProfile.

public StringApiResponse addUserProfile(JAXBUserProfile jaxbUserProfile) throws Throwable {
    StringApiResponse response = new StringApiResponse();
    try {
        String username = jaxbUserProfile.getId();
        if (null != this.getUserProfileManager().getProfile(username)) {
            throw new ApiException(IApiErrorCodes.API_PARAMETER_VALIDATION_ERROR, "Profile of user '" + username + "' already exist", Response.Status.CONFLICT);
        }
        IApsEntity profilePrototype = this.getUserProfileManager().getEntityPrototype(jaxbUserProfile.getTypeCode());
        if (null == profilePrototype) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "User Profile type with code '" + jaxbUserProfile.getTypeCode() + "' does not exist", Response.Status.CONFLICT);
        }
        IUserProfile userProfile = (IUserProfile) jaxbUserProfile.buildEntity(profilePrototype, null);
        List<ApiError> errors = this.validate(userProfile);
        if (errors.size() > 0) {
            response.addErrors(errors);
            response.setResult(IResponseBuilder.FAILURE, null);
            return response;
        }
        this.getUserProfileManager().addProfile(username, userProfile);
        response.setResult(IResponseBuilder.SUCCESS, null);
    } catch (ApiException ae) {
        response.addErrors(ae.getErrors());
        response.setResult(IResponseBuilder.FAILURE, null);
    } catch (Throwable t) {
        _logger.error("Error adding user profile", t);
        // ApsSystemUtils.logThrowable(t, this, "addUserProfile");
        throw new ApsSystemException("Error adding user profile", t);
    }
    return response;
}
Also used : IUserProfile(org.entando.entando.aps.system.services.userprofile.model.IUserProfile) IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ApiError(org.entando.entando.aps.system.services.api.model.ApiError) StringApiResponse(org.entando.entando.aps.system.services.api.model.StringApiResponse) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 5 with ApiError

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

the class ResponseBuilder method extractApiMethod.

@Override
public ApiMethod extractApiMethod(ApiMethod.HttpMethod httpMethod, String namespace, String resourceName) throws ApiException {
    ApiMethod api = null;
    String signature = this.buildApiSignature(httpMethod, namespace, resourceName);
    try {
        api = this.getApiCatalogManager().getMethod(httpMethod, namespace, resourceName);
        if (null == api) {
            ApiError error = new ApiError(IApiErrorCodes.API_INVALID, signature + " does not exists", Response.Status.NOT_FOUND);
            throw new ApiException(error);
        }
        if (!api.isActive()) {
            ApiError error = new ApiError(IApiErrorCodes.API_INVALID, signature + " does not exists", Response.Status.NOT_FOUND);
            throw new ApiException(error);
        }
    } catch (ApiException ae) {
        _logger.error("Error extracting api method {}", this.buildApiSignature(httpMethod, namespace, resourceName), ae);
        throw ae;
    } catch (Throwable t) {
        _logger.error("Error extracting api method {}", this.buildApiSignature(httpMethod, namespace, resourceName), t);
        throw new ApiException(IApiErrorCodes.SERVER_ERROR, signature + " is not supported", Response.Status.INTERNAL_SERVER_ERROR);
    }
    return api;
}
Also used : ApiMethod(org.entando.entando.aps.system.services.api.model.ApiMethod) ApiError(org.entando.entando.aps.system.services.api.model.ApiError) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Aggregations

ApiError (org.entando.entando.aps.system.services.api.model.ApiError)21 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)13 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)10 StringApiResponse (org.entando.entando.aps.system.services.api.model.StringApiResponse)9 ArrayList (java.util.ArrayList)8 UserDetails (com.agiletec.aps.system.services.user.UserDetails)4 AttributeFieldError (com.agiletec.aps.system.common.entity.model.AttributeFieldError)3 FieldError (com.agiletec.aps.system.common.entity.model.FieldError)3 IApsEntity (com.agiletec.aps.system.common.entity.model.IApsEntity)3 ContentRecordVO (com.agiletec.plugins.jacms.aps.system.services.content.model.ContentRecordVO)2 ContentModel (com.agiletec.plugins.jacms.aps.system.services.contentmodel.ContentModel)2 AbstractApiResponse (org.entando.entando.aps.system.services.api.model.AbstractApiResponse)2 StringListApiResponse (org.entando.entando.aps.system.services.api.model.StringListApiResponse)2 DataObjectModel (org.entando.entando.aps.system.services.dataobjectmodel.DataObjectModel)2 IUserProfile (org.entando.entando.aps.system.services.userprofile.model.IUserProfile)2 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)1 DefaultJAXBAttributeType (com.agiletec.aps.system.common.entity.model.attribute.DefaultJAXBAttributeType)1 ContentUtilizer (com.agiletec.plugins.jacms.aps.system.services.content.ContentUtilizer)1 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)1 ResourceUtilizer (com.agiletec.plugins.jacms.aps.system.services.resource.ResourceUtilizer)1