use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.
the class ApiI18nLabelInterface method deleteLabel.
public void deleteLabel(Properties properties) throws ApsSystemException, ApiException {
try {
String key = properties.getProperty("key");
ApsProperties labelGroups = this.getI18nManager().getLabelGroup(key);
if (null == labelGroups) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Label with key '" + key + "' does not exist", Response.Status.CONFLICT);
}
this.getI18nManager().deleteLabelGroup(key);
} catch (ApiException | ApsSystemException ae) {
_logger.error("Error deleting label", ae);
throw new ApsSystemException("Error deleting labels", ae);
}
}
use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.
the class ApiPageModelInterface method deletePageModel.
public void deletePageModel(Properties properties) throws ApiException, Throwable {
String code = properties.getProperty("code");
try {
PageModel 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);
}
Map<String, List<Object>> references = new HashMap<String, List<Object>>();
ListableBeanFactory factory = (ListableBeanFactory) this.getBeanFactory();
String[] defNames = factory.getBeanNamesForType(PageModelUtilizer.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) {
PageModelUtilizer pageModelUtilizer = (PageModelUtilizer) service;
List<Object> utilizers = pageModelUtilizer.getPageModelUtilizers(code);
if (utilizers != null && !utilizers.isEmpty()) {
references.put(pageModelUtilizer.getName(), utilizers);
}
}
}
if (!references.isEmpty()) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "PageModel with code " + code + " has references with other object", Response.Status.CONFLICT);
}
this.getPageModelManager().deletePageModel(code);
} catch (ApiException ae) {
throw ae;
} catch (Throwable t) {
_logger.error("Error deleting page model throw api", t);
throw t;
}
}
use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.
the class LocalStorageManagerInterface method getListDirectory.
public List<LinkedListItem> getListDirectory(Properties properties) throws Throwable {
List<LinkedListItem> list = new ArrayList<LinkedListItem>();
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");
if (!StorageManagerUtil.isValidDirName(pathValue)) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "The path '" + pathValue + "' does not exists", Response.Status.CONFLICT);
}
BasicFileAttributeView[] files = this.getStorageManager().listAttributes(pathValue, isProtected);
for (int i = 0; i < files.length; i++) {
BasicFileAttributeView fileAttributeView = files[i];
String url = this.getApiResourceURLWithParams(properties, fileAttributeView, pathValue, isProtected);
LinkedListItem item = new LinkedListItem();
item.setCode(this.buildResourcePath(fileAttributeView, pathValue));
item.setUrl(url);
list.add(item);
}
} catch (Throwable t) {
_logger.error("Error extracting storage resources in path: {} and protected flag: {} ", pathValue, isProtected, t);
throw t;
}
return list;
}
use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.
the class ApiUserProfileInterface method getUserProfiles.
public List<String> getUserProfiles(Properties properties) throws Throwable {
List<String> usernames = null;
try {
String userProfileType = properties.getProperty("typeCode");
IUserProfile prototype = (IUserProfile) this.getUserProfileManager().getEntityPrototype(userProfileType);
if (null == prototype) {
throw new ApiException(IApiErrorCodes.API_PARAMETER_VALIDATION_ERROR, "Profile Type '" + userProfileType + "' does not exist", Response.Status.CONFLICT);
}
String langCode = properties.getProperty(SystemConstants.API_LANG_CODE_PARAMETER);
String filtersParam = properties.getProperty("filters");
BaseFilterUtils filterUtils = new BaseFilterUtils();
EntitySearchFilter[] filters = filterUtils.getFilters(prototype, filtersParam, langCode);
usernames = this.getUserProfileManager().searchId(userProfileType, filters);
} catch (ApiException ae) {
throw ae;
} catch (Throwable t) {
_logger.error("Error searching usernames", t);
// ApsSystemUtils.logThrowable(t, this, "getUserProfiles");
throw new ApsSystemException("Error searching usernames", t);
}
return usernames;
}
use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.
the class ApiUserProfileInterface method deleteUserProfile.
public void deleteUserProfile(Properties properties) throws ApiException, Throwable {
StringApiResponse response = new StringApiResponse();
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);
}
this.getUserProfileManager().deleteProfile(username);
response.setResult(IResponseBuilder.SUCCESS, null);
} catch (ApiException ae) {
response.addErrors(ae.getErrors());
response.setResult(IResponseBuilder.FAILURE, null);
} catch (Throwable t) {
_logger.error("Error deleting user Profile", t);
// ApsSystemUtils.logThrowable(t, this, "deleteUserProfile");
throw new ApsSystemException("Error deleting user Profile", t);
}
}
Aggregations