Search in sources :

Example 16 with ApiException

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

the class ApiPageModelInterface method getPageModel.

public PageModel getPageModel(Properties properties) throws ApiException, Throwable {
    String code = properties.getProperty("code");
    PageModel pageModel = null;
    try {
        pageModel = this.getPageModelManager().getPageModel(code);
        if (null == pageModel) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "PageModel with code '" + code + "' does not exist", Response.Status.CONFLICT);
        }
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("Error creating page model - code '{}'", code, t);
        throw t;
    }
    return pageModel;
}
Also used : PageModel(com.agiletec.aps.system.services.pagemodel.PageModel) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 17 with ApiException

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

the class LocalStorageManagerInterface method deleteResource.

public void deleteResource(Properties properties) throws ApiException, Throwable {
    String pathValue = properties.getProperty(PARAM_PATH);
    String protectedValue = properties.getProperty(PARAM_IS_PROTECTED);
    boolean isProtected = StringUtils.equalsIgnoreCase(protectedValue, "true");
    try {
        if (StringUtils.isNotBlank(pathValue))
            pathValue = URLDecoder.decode(pathValue, "UTF-8");
        String path = StringUtils.removeEnd(pathValue, "/");
        String parentFolder = FilenameUtils.getFullPathNoEndSeparator(path);
        BasicFileAttributeView parentBasicFileAttributeView = this.getStorageManager().getAttributes(parentFolder, isProtected);
        if (null == parentBasicFileAttributeView || !parentBasicFileAttributeView.isDirectory()) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Invalid parent directory", Response.Status.CONFLICT);
        }
        if (!StorageManagerUtil.isValidDirName(parentFolder)) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Invalid parent directory", Response.Status.CONFLICT);
        }
        BasicFileAttributeView basicFileAttributeView = this.getStorageManager().getAttributes(pathValue, isProtected);
        if (null == basicFileAttributeView) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "The file does not exists", Response.Status.CONFLICT);
        }
        String filename = StringUtils.substringAfter(pathValue, parentFolder);
        if (basicFileAttributeView.isDirectory()) {
            if (!StorageManagerUtil.isValidDirName(filename)) {
                throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Invalid dir name", Response.Status.CONFLICT);
            }
            String recursiveDelete = properties.getProperty(PARAM_DELETE_RECURSIVE);
            boolean isRecursiveDelete = StringUtils.equalsIgnoreCase(recursiveDelete, "true");
            if (!isRecursiveDelete) {
                String[] dirContents = this.getStorageManager().list(pathValue, isProtected);
                if (null != dirContents && dirContents.length > 0) {
                    throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "The directory is not empty", Response.Status.CONFLICT);
                }
            }
            this.getStorageManager().deleteDirectory(pathValue, isProtected);
        } else {
            // it's a file
            if (!StorageManagerUtil.isValidFilename(filename)) {
                throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Invalid filename", Response.Status.CONFLICT);
            }
            this.getStorageManager().deleteFile(pathValue, isProtected);
        }
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("Error adding new storage resource", t);
        throw t;
    }
}
Also used : BasicFileAttributeView(org.entando.entando.aps.system.services.storage.BasicFileAttributeView) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 18 with ApiException

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

the class LocalStorageManagerInterface method addResource.

public void addResource(JAXBStorageResource storageResource, Properties properties) throws ApiException, Throwable {
    try {
        boolean isProtected = storageResource.isProtectedResource();
        // validate parent directory;
        String path = StringUtils.removeEnd(storageResource.getName(), "/");
        String parentFolder = FilenameUtils.getFullPathNoEndSeparator(path);
        if (StringUtils.isNotBlank(parentFolder))
            parentFolder = URLDecoder.decode(parentFolder, "UTF-8");
        if (!StorageManagerUtil.isValidDirName(parentFolder)) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Invalid parent directory", Response.Status.CONFLICT);
        }
        BasicFileAttributeView parentBasicFileAttributeView = this.getStorageManager().getAttributes(parentFolder, isProtected);
        if (null == parentBasicFileAttributeView || !parentBasicFileAttributeView.isDirectory()) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Invalid parent directory", Response.Status.CONFLICT);
        }
        // validate exists
        BasicFileAttributeView basicFileAttributeView2 = this.getStorageManager().getAttributes(path, isProtected);
        if (null != basicFileAttributeView2) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "File already present", Response.Status.CONFLICT);
        }
        String filename = StringUtils.substringAfter(storageResource.getName(), parentFolder);
        if (storageResource.isDirectory()) {
            if (!StorageManagerUtil.isValidDirName(filename)) {
                throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Invalid dir name", Response.Status.CONFLICT);
            }
            this.getStorageManager().createDirectory(storageResource.getName(), isProtected);
        } else {
            // validate file content
            if (!storageResource.isDirectory() && (null == storageResource.getBase64() || storageResource.getBase64().length == 0)) {
                throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "A file cannot be empty", Response.Status.CONFLICT);
            }
            if (!StorageManagerUtil.isValidFilename(filename)) {
                throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Invalid filename name", Response.Status.CONFLICT);
            }
            this.getStorageManager().saveFile(storageResource.getName(), isProtected, new ByteArrayInputStream(storageResource.getBase64()));
        }
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("Error adding new storage resource", t);
        throw t;
    }
}
Also used : BasicFileAttributeView(org.entando.entando.aps.system.services.storage.BasicFileAttributeView) ByteArrayInputStream(java.io.ByteArrayInputStream) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 19 with ApiException

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

the class LocalStorageManagerInterface method getFile.

public JAXBBasicFileAttributeView getFile(Properties properties) throws ApiException, Throwable {
    JAXBBasicFileAttributeView apiResult;
    String pathValue = properties.getProperty(PARAM_PATH);
    String protectedValue = properties.getProperty(PARAM_IS_PROTECTED);
    boolean isProtected = StringUtils.equalsIgnoreCase(protectedValue, "true");
    try {
        if (StringUtils.isNotBlank(pathValue))
            pathValue = URLDecoder.decode(pathValue, "UTF-8");
        BasicFileAttributeView result = this.getStorageManager().getAttributes(pathValue, isProtected);
        if (null == result) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "The path '" + pathValue + "' does not exists", Response.Status.CONFLICT);
        }
        InputStream fis = null;
        if (!result.isDirectory()) {
            fis = this.getStorageManager().getStream(pathValue, isProtected);
        }
        apiResult = new JAXBBasicFileAttributeView(result, fis);
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("Error extracting storage resource in path: {} and protected flag: {} ", pathValue, isProtected, t);
        throw t;
    }
    return apiResult;
}
Also used : BasicFileAttributeView(org.entando.entando.aps.system.services.storage.BasicFileAttributeView) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 20 with ApiException

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

the class ApiUserProfileInterface method getUserProfile.

public JAXBUserProfile getUserProfile(Properties properties) throws ApiException, Throwable {
    JAXBUserProfile jaxbUserProfile = null;
    try {
        String username = properties.getProperty("username");
        IUserProfile userProfile = this.getUserProfileManager().getProfile(username);
        if (null == userProfile) {
            throw new ApiException(IApiErrorCodes.API_PARAMETER_VALIDATION_ERROR, "Profile of user '" + username + "' does not exist", Response.Status.CONFLICT);
        }
        jaxbUserProfile = new JAXBUserProfile(userProfile, null);
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("Error extracting user profile", t);
        // ApsSystemUtils.logThrowable(t, this, "getUserProfile");
        throw new ApsSystemException("Error extracting user profile", t);
    }
    return jaxbUserProfile;
}
Also used : JAXBUserProfile(org.entando.entando.aps.system.services.userprofile.api.model.JAXBUserProfile) IUserProfile(org.entando.entando.aps.system.services.userprofile.model.IUserProfile) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) 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