use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.
the class ApiUserProfileInterface method addUserProfile.
public StringApiResponse addUserProfile(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 + "' already 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().addProfile(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 adding user profile", t);
// ApsSystemUtils.logThrowable(t, this, "addUserProfile");
throw new ApsSystemException("Error adding 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 updateUserProfileType.
public StringApiResponse updateUserProfileType(JAXBUserProfileType jaxbProfileType) throws Throwable {
StringApiResponse response = new StringApiResponse();
try {
String typeCode = jaxbProfileType.getTypeCode();
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");
}
Map<String, AttributeInterface> attributes = this.getUserProfileManager().getEntityAttributePrototypes();
IApsEntity profileType = jaxbProfileType.buildEntityType(this.getUserProfileManager().getEntityClass(), attributes);
((IEntityTypesConfigurer) this.getUserProfileManager()).updateEntityPrototype(profileType);
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 type", t);
// ApsSystemUtils.logThrowable(t, this, "updateProfileType");
throw new ApsSystemException("Error updating user profile type", t);
}
return response;
}
use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.
the class ApiUserProfileTypeInterface method addUserProfileType.
public StringApiResponse addUserProfileType(JAXBUserProfileType jaxbProfileType) throws Throwable {
StringApiResponse response = new StringApiResponse();
try {
String typeCode = jaxbProfileType.getTypeCode();
IApsEntity masterProfileType = this.getUserProfileManager().getEntityPrototype(typeCode);
if (null != masterProfileType) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "User Profile type with code '" + typeCode + "' already exists");
}
if (typeCode == null || typeCode.length() != 3) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Invalid type code - '" + typeCode + "'");
}
Map<String, AttributeInterface> attributes = this.getUserProfileManager().getEntityAttributePrototypes();
IApsEntity profileType = jaxbProfileType.buildEntityType(this.getUserProfileManager().getEntityClass(), attributes);
((IEntityTypesConfigurer) this.getUserProfileManager()).addEntityPrototype(profileType);
response.setResult(IResponseBuilder.SUCCESS, null);
} catch (ApiException ae) {
response.addErrors(ae.getErrors());
response.setResult(IResponseBuilder.FAILURE, null);
} catch (Throwable t) {
_logger.error("Error adding user profile type", t);
// ApsSystemUtils.logThrowable(t, this, "addProfileType");
throw new ApsSystemException("Error adding user profile type", t);
}
return response;
}
use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.
the class ApiRestStatusServer method getApiStatus.
@GET
@Produces({ "application/json", "application/xml", "application/javascript" })
@Path("/{namespace}/{resourceName}/{httpMethod}")
public Object getApiStatus(@PathParam("httpMethod") String httpMethodString, @PathParam("namespace") String namespace, @PathParam("resourceName") String resourceName, @Context HttpServletRequest request) {
StringApiResponse response = new StringApiResponse();
ApiMethod.HttpMethod httpMethod = Enum.valueOf(ApiMethod.HttpMethod.class, httpMethodString.toUpperCase());
try {
IResponseBuilder responseBuilder = (IResponseBuilder) ApsWebApplicationUtils.getBean(SystemConstants.API_RESPONSE_BUILDER, request);
ApiMethod apiMethod = responseBuilder.extractApiMethod(httpMethod, namespace, resourceName);
if (null != apiMethod.getRequiredPermission()) {
response.setResult(ApiStatus.AUTHORIZATION_REQUIRED.toString(), null);
} else if (apiMethod.getRequiredAuth()) {
response.setResult(ApiStatus.AUTHENTICATION_REQUIRED.toString(), null);
} else {
response.setResult(ApiStatus.FREE.toString(), null);
}
} catch (ApiException ae) {
response.addErrors(((ApiException) ae).getErrors());
response.setResult(ApiStatus.INACTIVE.toString(), null);
} catch (Throwable t) {
return this.buildErrorResponse(httpMethod, namespace, resourceName, t);
}
return response;
}
use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.
the class ResponseBuilder method buildApiResponseObject.
private AbstractApiResponse buildApiResponseObject(ApiMethod apiMethod) throws ApiException {
AbstractApiResponse apiResponse = null;
try {
Class responseClass = Class.forName(apiMethod.getResponseClassName());
apiResponse = (AbstractApiResponse) responseClass.newInstance();
} catch (Exception e) {
_logger.error("Error creating instance of response '{}'", apiMethod.getResponseClassName(), e);
}
return apiResponse;
}
Aggregations