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;
}
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;
}
}
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;
}
}
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;
}
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;
}
Aggregations