Search in sources :

Example 1 with JAXBResource

use of org.entando.entando.plugins.jacms.aps.system.services.api.model.JAXBResource 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)

Aggregations

ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)1 UserDetails (com.agiletec.aps.system.services.user.UserDetails)1 ResourceInterface (com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface)1 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)1 JAXBResource (org.entando.entando.plugins.jacms.aps.system.services.api.model.JAXBResource)1