Search in sources :

Example 61 with ApiException

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

the class ApiResourceInterface method deleteResource.

private StringApiResponse deleteResource(Properties properties, String expectedTypeCode) throws ApiException, Throwable {
    StringApiResponse response = null;
    try {
        String id = properties.getProperty("id");
        ResourceInterface resource = this.getResourceManager().loadResource(id);
        if (null != resource && !resource.getType().equals(expectedTypeCode)) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Invalid resource type - '" + resource.getType() + "'", Response.Status.CONFLICT);
        }
        properties.setProperty(RESOURCE_TYPE_CODE_PARAM, expectedTypeCode);
        response = this.deleteResource(properties, resource);
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("Error deleting resource", t);
        // ApsSystemUtils.logThrowable(t, this, "deleteResource");
        throw new ApsSystemException("Error deleting resource", t);
    }
    return response;
}
Also used : ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ResourceInterface(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface) StringApiResponse(org.entando.entando.aps.system.services.api.model.StringApiResponse) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 62 with ApiException

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

the class ApiResourceInterface method getResource.

public JAXBResource getResource(Properties properties) throws Throwable {
    JAXBResource jaxbResource = null;
    String id = properties.getProperty("id");
    String resourceTypeCode = properties.getProperty(RESOURCE_TYPE_CODE_PARAM);
    try {
        ResourceInterface resource = this.getResourceManager().loadResource(id);
        if (null == resource || !resource.getType().equalsIgnoreCase(resourceTypeCode)) {
            throw new ApiException(IApiErrorCodes.API_PARAMETER_VALIDATION_ERROR, "Null resource by id '" + id + "'", Response.Status.CONFLICT);
        }
        UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER);
        if (null == user) {
            user = this.getUserManager().getGuestUser();
        }
        String groupName = resource.getMainGroup();
        if (!Group.FREE_GROUP_NAME.equals(groupName) && !this.getAuthorizationManager().isAuthOnGroup(user, groupName)) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Required resource '" + id + "' does not allowed", Response.Status.FORBIDDEN);
        }
        jaxbResource = new JAXBResource(resource);
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("error in getResource", t);
        throw new ApsSystemException("Error into API method", t);
    }
    return jaxbResource;
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) JAXBResource(org.entando.entando.plugins.jacms.aps.system.services.api.model.JAXBResource) ResourceInterface(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 63 with ApiException

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

the class ApiDataObjectModelInterface method getModel.

public DataObjectModel getModel(Properties properties) throws ApiException, Throwable {
    String idString = properties.getProperty("id");
    int id = 0;
    try {
        id = Integer.parseInt(idString);
    } catch (NumberFormatException e) {
        throw new ApiException(IApiErrorCodes.API_PARAMETER_VALIDATION_ERROR, "Invalid number format for 'id' parameter - '" + idString + "'", Response.Status.CONFLICT);
    }
    DataObjectModel model = this.getDataObjectModelManager().getDataObjectModel(id);
    if (null == model) {
        throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Model with id '" + idString + "' does not exist", Response.Status.CONFLICT);
    }
    return model;
}
Also used : DataObjectModel(org.entando.entando.aps.system.services.dataobjectmodel.DataObjectModel) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 64 with ApiException

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

the class ApiGuiFragmentInterface method deleteGuiFragment.

public void deleteGuiFragment(Properties properties) throws ApiException, Throwable {
    String code = properties.getProperty("code");
    try {
        GuiFragment guiFragment = this.getGuiFragmentManager().getGuiFragment(code);
        if (null == guiFragment) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "GuiFragment with code '" + code + "' does not exist", Response.Status.CONFLICT);
        }
        if (guiFragment.isLocked()) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "GuiFragment with code '" + code + "' are locked", Response.Status.CONFLICT);
        }
        Map<String, List<Object>> references = new HashMap<String, List<Object>>();
        ListableBeanFactory factory = (ListableBeanFactory) this.getBeanFactory();
        String[] defNames = factory.getBeanNamesForType(GuiFragmentUtilizer.class);
        for (int i = 0; i < defNames.length; i++) {
            Object service = null;
            try {
                service = this.getBeanFactory().getBean(defNames[i]);
            } catch (Throwable t) {
                _logger.error("error extracting bean with name '{}'", defNames[i], t);
                throw new ApsSystemException("error extracting bean with name '" + defNames[i] + "'", t);
            }
            if (service != null) {
                GuiFragmentUtilizer guiFragUtilizer = (GuiFragmentUtilizer) service;
                List<Object> utilizers = guiFragUtilizer.getGuiFragmentUtilizers(code);
                if (utilizers != null && !utilizers.isEmpty()) {
                    references.put(guiFragUtilizer.getName(), utilizers);
                }
            }
        }
        if (!references.isEmpty()) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "GuiFragment with code " + code + " has references with other object", Response.Status.CONFLICT);
        }
        this.getGuiFragmentManager().deleteGuiFragment(code);
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("Error deleting fragment throw api", t);
        throw t;
    }
}
Also used : GuiFragmentUtilizer(org.entando.entando.aps.system.services.guifragment.GuiFragmentUtilizer) HashMap(java.util.HashMap) GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ArrayList(java.util.ArrayList) List(java.util.List) ListableBeanFactory(org.springframework.beans.factory.ListableBeanFactory) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 65 with ApiException

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

the class ApiGuiFragmentInterface method updateGuiFragment.

public void updateGuiFragment(JAXBGuiFragment jaxbGuiFragment) throws ApiException, Throwable {
    try {
        if (null == this.getGuiFragmentManager().getGuiFragment(jaxbGuiFragment.getCode())) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "GuiFragment with code '" + jaxbGuiFragment.getCode() + "' does not exist", Response.Status.CONFLICT);
        }
        GuiFragment guiFragment = jaxbGuiFragment.getGuiFragment();
        if (StringUtils.isBlank(guiFragment.getCurrentGui())) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "one between A and B must be valued", Response.Status.CONFLICT);
        }
        this.getGuiFragmentManager().updateGuiFragment(guiFragment);
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("Error updating fragment", t);
        throw t;
    }
}
Also used : GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

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