use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.
the class ApiUserProfileInterface method updateUserProfile.
public StringApiResponse updateUserProfile(JAXBUserProfile jaxbUserProfile) throws Throwable {
StringApiResponse response = new StringApiResponse();
try {
String username = jaxbUserProfile.getId();
if (null == this.getUserProfileManager().getProfile(username)) {
throw new ApiException(IApiErrorCodes.API_PARAMETER_VALIDATION_ERROR, "Profile of user '" + username + "' does not exist", Response.Status.CONFLICT);
}
IApsEntity profilePrototype = this.getUserProfileManager().getEntityPrototype(jaxbUserProfile.getTypeCode());
if (null == profilePrototype) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "User Profile type with code '" + jaxbUserProfile.getTypeCode() + "' does not exist", Response.Status.CONFLICT);
}
IUserProfile userProfile = (IUserProfile) jaxbUserProfile.buildEntity(profilePrototype, null);
List<ApiError> errors = this.validate(userProfile);
if (errors.size() > 0) {
response.addErrors(errors);
response.setResult(IResponseBuilder.FAILURE, null);
return response;
}
this.getUserProfileManager().updateProfile(username, userProfile);
response.setResult(IResponseBuilder.SUCCESS, null);
} catch (ApiException ae) {
response.addErrors(ae.getErrors());
response.setResult(IResponseBuilder.FAILURE, null);
} catch (Throwable t) {
_logger.error("Error updating user profile", t);
// ApsSystemUtils.logThrowable(t, this, "updateUserProfile");
throw new ApsSystemException("Error updating user profile", t);
}
return response;
}
use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.
the class ApiUserProfileTypeInterface method getUserProfileType.
public JAXBUserProfileType getUserProfileType(Properties properties) throws ApiException, Throwable {
JAXBUserProfileType jaxbProfileType = null;
try {
String typeCode = properties.getProperty("typeCode");
IApsEntity masterProfileType = this.getUserProfileManager().getEntityPrototype(typeCode);
if (null == masterProfileType) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "User Profile type with code '" + typeCode + "' does not exist");
}
jaxbProfileType = new JAXBUserProfileType(masterProfileType);
} catch (ApiException ae) {
throw ae;
} catch (Throwable t) {
_logger.error("Error extracting user profile type", t);
// ApsSystemUtils.logThrowable(t, this, "getProfileType");
throw new ApsSystemException("Error extracting user profile type", t);
}
return jaxbProfileType;
}
use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.
the class ApiUserProfileTypeInterface method deleteUserProfileType.
public void deleteUserProfileType(Properties properties) throws ApiException, Throwable {
try {
String typeCode = properties.getProperty("typeCode");
IApsEntity masterProfileType = this.getUserProfileManager().getEntityPrototype(typeCode);
if (null == masterProfileType) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "User Profile type with code '" + typeCode + "' doesn't exist");
}
EntitySearchFilter filter = new EntitySearchFilter(IEntityManager.ENTITY_TYPE_CODE_FILTER_KEY, false, typeCode, false);
List<String> profileIds = this.getUserProfileManager().searchId(new EntitySearchFilter[] { filter });
if (null != profileIds && !profileIds.isEmpty()) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "User profile type '" + typeCode + "' are used into " + profileIds.size() + " profiles");
}
((IEntityTypesConfigurer) this.getUserProfileManager()).removeEntityPrototype(typeCode);
} catch (ApiException ae) {
throw ae;
} catch (Throwable t) {
_logger.error("Error deleting user Profile type", t);
// ApsSystemUtils.logThrowable(t, this, "deleteProfileType");
throw new ApsSystemException("Error deleting user Profile type", t);
}
}
use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.
the class ApiServiceInterface method getServices.
public ArrayList<ServiceInfo> getServices(Properties properties) throws ApiException {
ArrayList<ServiceInfo> services = new ArrayList<ServiceInfo>();
try {
String defaultLangCode = this.getLangManager().getDefaultLang().getCode();
String langCode = properties.getProperty(SystemConstants.API_LANG_CODE_PARAMETER);
String tagParamValue = properties.getProperty("tag");
// String myentandoParamValue = properties.getProperty("myentando");
// Boolean myentando = (null != myentandoParamValue && myentandoParamValue.trim().length() > 0) ? Boolean.valueOf(myentandoParamValue) : null;
langCode = (null != langCode && null != this.getLangManager().getLang(langCode)) ? langCode : defaultLangCode;
Map<String, ApiService> masterServices = this.getApiCatalogManager().getServices(tagParamValue);
Iterator<ApiService> iter = masterServices.values().iterator();
while (iter.hasNext()) {
ApiService service = (ApiService) iter.next();
if (service.isActive() && !service.isHidden() && this.checkServiceAuthorization(service, properties, false)) {
ServiceInfo smallService = this.createServiceInfo(service, langCode, defaultLangCode);
services.add(smallService);
}
}
BeanComparator comparator = new BeanComparator("description");
Collections.sort(services, comparator);
} catch (Throwable t) {
_logger.error("Error extracting services", t);
throw new ApiException(IApiErrorCodes.SERVER_ERROR, "Internal error");
}
return services;
}
use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.
the class ApiEntityTypeInterface method deleteEntityType.
public void deleteEntityType(Properties properties) throws Throwable {
try {
String typeCode = properties.getProperty(this.getTypeCodeParamName());
IApsEntity masterEntityType = this.getEntityManager().getEntityPrototype(typeCode);
if (null == masterEntityType) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, this.getTypeLabel() + " with code '" + typeCode + "' doesn't exist");
}
EntitySearchFilter filter = new EntitySearchFilter(IEntityManager.ENTITY_TYPE_CODE_FILTER_KEY, false, typeCode, false);
List<String> entityIds = this.getEntityManager().searchId(new EntitySearchFilter[] { filter });
if (null != entityIds && !entityIds.isEmpty()) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, this.getTypeLabel() + " '" + typeCode + "' are used into " + entityIds.size() + " entities");
}
this.checkEntityTypeToDelete(masterEntityType);
((IEntityTypesConfigurer) this.getEntityManager()).removeEntityPrototype(typeCode);
} catch (ApiException ae) {
throw ae;
} catch (Throwable t) {
_logger.error("Error deleting Entity type", t);
// ApsSystemUtils.logThrowable(t, this, "deleteEntityType");
throw new ApsSystemException("Error deleting Entity type", t);
}
}
Aggregations