use of org.entando.entando.aps.system.services.guifragment.api.JAXBGuiFragment 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);
}
}
Aggregations