Search in sources :

Example 6 with ApsSystemException

use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.

the class ProtectedResourceProvider method provideProtectedResource.

@Override
public boolean provideProtectedResource(HttpServletRequest request, HttpServletResponse response) throws ApsSystemException {
    try {
        String[] uriSegments = request.getRequestURI().split("/");
        int segments = uriSegments.length;
        // CONTROLLO ASSOCIAZIONE RISORSA A CONTENUTO
        int indexGuardian = 0;
        String checkContentAssociation = uriSegments[segments - 2];
        if (checkContentAssociation.equals(AbstractResourceAttribute.REFERENCED_RESOURCE_INDICATOR)) {
            // LA Sintassi /<RES_ID>/<SIZE>/<LANG_CODE>/<REFERENCED_RESOURCE_INDICATOR>/<CONTENT_ID>
            indexGuardian = 2;
        }
        String resId = uriSegments[segments - 3 - indexGuardian];
        UserDetails currentUser = (UserDetails) request.getSession().getAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER);
        if (currentUser == null) {
            currentUser = this.getUserManager().getGuestUser();
        }
        boolean isAuthForProtectedRes = false;
        if (indexGuardian != 0) {
            if (this.isAuthOnProtectedRes(currentUser, resId, uriSegments[segments - 1])) {
                isAuthForProtectedRes = true;
            } else {
                this.executeLoginRedirect(request, response);
                return true;
            }
        }
        ResourceInterface resource = this.getResourceManager().loadResource(resId);
        if (resource == null) {
            return false;
        }
        IAuthorizationManager authManager = this.getAuthorizationManager();
        if (isAuthForProtectedRes || authManager.isAuthOnGroup(currentUser, resource.getMainGroup()) || authManager.isAuthOnGroup(currentUser, Group.ADMINS_GROUP_NAME)) {
            ResourceInstance instance = null;
            if (resource.isMultiInstance()) {
                String sizeStr = uriSegments[segments - 2 - indexGuardian];
                if (!this.isValidNumericString(sizeStr)) {
                    return false;
                }
                int size = Integer.parseInt(sizeStr);
                String langCode = uriSegments[segments - 1 - indexGuardian];
                instance = ((AbstractMultiInstanceResource) resource).getInstance(size, langCode);
            } else {
                instance = ((AbstractMonoInstanceResource) resource).getInstance();
            }
            this.createResponse(response, resource, instance);
            return true;
        }
    } catch (Throwable t) {
        _logger.error("Error extracting protected resource", t);
        throw new ApsSystemException("Error extracting protected resource", t);
    }
    return false;
}
Also used : IAuthorizationManager(com.agiletec.aps.system.services.authorization.IAuthorizationManager) UserDetails(com.agiletec.aps.system.services.user.UserDetails) ResourceInstance(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInstance) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ResourceInterface(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface)

Example 7 with ApsSystemException

use of com.agiletec.aps.system.exception.ApsSystemException 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 8 with ApsSystemException

use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.

the class ApiContentInterface method extractContents.

protected List<String> extractContents(Properties properties) throws Throwable {
    List<String> contentsId = null;
    try {
        ApiContentListBean bean = this.buildSearchBean(properties);
        UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER);
        contentsId = this.getContentListHelper().getContentsId(bean, user);
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("error in extractContents", t);
        throw new ApsSystemException("Error into API method", t);
    }
    return contentsId;
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) ApiContentListBean(org.entando.entando.plugins.jacms.aps.system.services.api.model.ApiContentListBean) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 9 with ApsSystemException

use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.

the class ApiContentInterface method getContentToHtml.

public String getContentToHtml(Properties properties) throws ApiException, Throwable {
    String render = null;
    String id = properties.getProperty("id");
    String modelId = properties.getProperty("modelId");
    try {
        if (null == modelId || modelId.trim().length() == 0) {
            return null;
        }
        Content mainContent = this.getPublicContent(id);
        Integer modelIdInteger = this.checkModel(modelId, mainContent);
        if (null != modelIdInteger) {
            String langCode = properties.getProperty(SystemConstants.API_LANG_CODE_PARAMETER);
            render = this.getRenderedContent(id, modelIdInteger, langCode);
        }
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("error in getContentToHtml", t);
        throw new ApsSystemException("Error into API method", t);
    }
    return render;
}
Also used : 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) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 10 with ApsSystemException

use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.

the class ApiContentModelInterface method deleteModel.

public void deleteModel(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);
    }
    ContentModel model = this.getContentModelManager().getContentModel(id);
    if (null == model) {
        throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Model with id '" + idString + "' does not exist", Response.Status.CONFLICT);
    }
    try {
        this.getContentModelManager().removeContentModel(model);
    } catch (Throwable t) {
        _logger.error("Error deleting model", t);
        // ApsSystemUtils.logThrowable(t, this, "deleteModel");
        throw new ApsSystemException("Error deleting model", t);
    }
}
Also used : ContentModel(com.agiletec.plugins.jacms.aps.system.services.contentmodel.ContentModel) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Aggregations

ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)452 ArrayList (java.util.ArrayList)53 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)48 RestServerError (org.entando.entando.aps.system.exception.RestServerError)39 ApsProperties (com.agiletec.aps.util.ApsProperties)26 IApsEntity (com.agiletec.aps.system.common.entity.model.IApsEntity)23 HashMap (java.util.HashMap)23 UserDetails (com.agiletec.aps.system.services.user.UserDetails)21 StringApiResponse (org.entando.entando.aps.system.services.api.model.StringApiResponse)21 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)20 Date (java.util.Date)20 StringReader (java.io.StringReader)18 IPage (com.agiletec.aps.system.services.page.IPage)17 List (java.util.List)17 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)16 File (java.io.File)16 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)16 Widget (com.agiletec.aps.system.services.page.Widget)15 IOException (java.io.IOException)15 Cache (org.springframework.cache.Cache)15