use of org.entando.entando.aps.system.services.api.model.ApiError in project entando-core by entando.
the class ApiWidgetTypeInterface method checkAndSaveFragment.
protected void checkAndSaveFragment(WidgetType type, JAXBWidgetType jaxbWidgetType, boolean isAdd, StringApiResponse response, List<GuiFragment> addedFragments, List<GuiFragment> updatedFragment) throws Throwable {
try {
if (!type.isLogic() && !this.isInternalServletWidget(type.getCode())) {
GuiFragment guiFragment = this.getGuiFragmentManager().getUniqueGuiFragmentByWidgetType(type.getCode());
if (StringUtils.isNotBlank(jaxbWidgetType.getGui())) {
if (null == guiFragment) {
guiFragment = new GuiFragment();
String code = this.extractUniqueGuiFragmentCode(type.getCode());
guiFragment.setCode(code);
guiFragment.setPluginCode(type.getPluginCode());
guiFragment.setGui(jaxbWidgetType.getGui());
guiFragment.setWidgetTypeCode(type.getCode());
addedFragments.add(guiFragment);
this.getGuiFragmentManager().addGuiFragment(guiFragment);
} else if (!isAdd) {
GuiFragment clone = guiFragment.clone();
updatedFragment.add(guiFragment);
clone.setGui(jaxbWidgetType.getGui());
this.getGuiFragmentManager().updateGuiFragment(clone);
}
} else {
if (null != guiFragment && !isAdd) {
if (StringUtils.isNotBlank(guiFragment.getDefaultGui())) {
GuiFragment clone = guiFragment.clone();
updatedFragment.add(guiFragment);
clone.setGui(null);
this.getGuiFragmentManager().updateGuiFragment(clone);
} else {
// nothing to do...
// this.getGuiFragmentManager().deleteGuiFragment(guiFragment.getCode());
}
}
}
} else if (type.isLogic() && !isAdd) {
boolean isInternalServlet = this.isInternalServletWidget(type.getParentType().getCode());
if (!isInternalServlet && (null != jaxbWidgetType.getFragments() && jaxbWidgetType.getFragments().size() > 0)) {
if (null != response) {
ApiError error = new ApiError(IApiErrorCodes.API_VALIDATION_ERROR, "Fragments mustn't be updated on a 'not internal servlet' logic widget type");
response.addError(error);
}
// throw new
// ApiException(IApiErrorCodes.API_VALIDATION_ERROR,
// "Fragments mustn't be updated on a 'not internal servlet'
// logic widget type", Response.Status.CONFLICT);
} else {
List<JAXBGuiFragment> fragments = jaxbWidgetType.getFragments();
if (null != fragments && fragments.size() > 0) {
for (int i = 0; i < fragments.size(); i++) {
JAXBGuiFragment jaxbGuiFragment = fragments.get(i);
GuiFragment fragment = jaxbGuiFragment.getGuiFragment();
GuiFragment existingFragment = this.getGuiFragmentManager().getGuiFragment(fragment.getCode());
if (null != existingFragment) {
if (StringUtils.isBlank(existingFragment.getDefaultGui()) && StringUtils.isBlank(jaxbWidgetType.getGui())) {
ApiError error = new ApiError(IApiErrorCodes.API_VALIDATION_ERROR, "one between A and B must be valued on fragment '" + existingFragment.getCode() + "'");
response.addError(error);
continue;
}
GuiFragment clone = existingFragment.clone();
updatedFragment.add(existingFragment);
clone.setGui(jaxbGuiFragment.getGui());
} else {
ApiError error = new ApiError(IApiErrorCodes.API_VALIDATION_ERROR, "Fragment '" + fragment.getCode() + "' does not exists");
response.addError(error);
}
}
}
}
}
} catch (Throwable t) {
_logger.error("error checking and saving fragment", t);
throw new ApsSystemException("error checking and saving fragment", t);
}
}
use of org.entando.entando.aps.system.services.api.model.ApiError in project entando-core by entando.
the class ApiContentTypeInterface method checkContentModel.
private boolean checkContentModel(Integer modelId, Content contentType, StringApiResponse response) {
if (null == modelId) {
return true;
}
ContentModel contentModel = this.getContentModelManager().getContentModel(modelId);
if (null == contentModel) {
ApiError error = new ApiError(IApiErrorCodes.API_VALIDATION_ERROR, "Content model with id '" + modelId + "' does not exist", Response.Status.ACCEPTED);
response.addError(error);
return false;
}
if (!contentType.getTypeCode().equals(contentModel.getContentType())) {
ApiError error = new ApiError(IApiErrorCodes.API_VALIDATION_ERROR, "Content model with id '" + modelId + "' is for contents of type '" + contentModel.getContentType() + "'", Response.Status.ACCEPTED);
response.addError(error);
return false;
}
return true;
}
use of org.entando.entando.aps.system.services.api.model.ApiError in project entando-core by entando.
the class JAXBEntityType method buildEntityType.
public IApsEntity buildEntityType(Class entityClass, Map<String, AttributeInterface> attributes) throws ApiException, Throwable {
List<ApiError> errors = new ArrayList<ApiError>();
IApsEntity entityType = null;
try {
entityType = (IApsEntity) entityClass.newInstance();
entityType.setTypeCode(this.getTypeCode());
entityType.setTypeDescr(this.getTypeDescription());
List<DefaultJAXBAttributeType> jabxAttributes = this.getAttributes();
for (int i = 0; i < jabxAttributes.size(); i++) {
try {
DefaultJAXBAttributeType jaxbAttributeType = jabxAttributes.get(i);
AttributeInterface attribute = jaxbAttributeType.createAttribute(attributes);
if (null != entityType.getAttribute(attribute.getName())) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Attribute '" + attribute.getName() + "' already defined");
}
entityType.addAttribute(attribute);
} catch (ApiException e) {
errors.addAll(e.getErrors());
}
}
} catch (Throwable t) {
_logger.error("error in buildEntityType", t);
// ApsSystemUtils.logThrowable(t, this, "buildEntityType");
throw t;
}
if (!errors.isEmpty())
throw new ApiException(errors);
return entityType;
}
use of org.entando.entando.aps.system.services.api.model.ApiError 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.ApiError in project entando-core by entando.
the class ResponseBuilder method extractApiMethod.
@Override
public ApiMethod extractApiMethod(ApiMethod.HttpMethod httpMethod, String namespace, String resourceName) throws ApiException {
ApiMethod api = null;
String signature = this.buildApiSignature(httpMethod, namespace, resourceName);
try {
api = this.getApiCatalogManager().getMethod(httpMethod, namespace, resourceName);
if (null == api) {
ApiError error = new ApiError(IApiErrorCodes.API_INVALID, signature + " does not exists", Response.Status.NOT_FOUND);
throw new ApiException(error);
}
if (!api.isActive()) {
ApiError error = new ApiError(IApiErrorCodes.API_INVALID, signature + " does not exists", Response.Status.NOT_FOUND);
throw new ApiException(error);
}
} catch (ApiException ae) {
_logger.error("Error extracting api method {}", this.buildApiSignature(httpMethod, namespace, resourceName), ae);
throw ae;
} catch (Throwable t) {
_logger.error("Error extracting api method {}", this.buildApiSignature(httpMethod, namespace, resourceName), t);
throw new ApiException(IApiErrorCodes.SERVER_ERROR, signature + " is not supported", Response.Status.INTERNAL_SERVER_ERROR);
}
return api;
}
Aggregations