use of org.entando.entando.aps.system.services.guifragment.GuiFragment in project entando-core by entando.
the class ApiWidgetTypeInterface method revertPreviousObject.
private void revertPreviousObject(WidgetType widgetTypeToUpdate, List<GuiFragment> addedFragments, List<GuiFragment> updatedFragments) throws Throwable {
if (null != widgetTypeToUpdate) {
this.getWidgetTypeManager().updateWidgetType(widgetTypeToUpdate.getCode(), widgetTypeToUpdate.getTitles(), widgetTypeToUpdate.getConfig(), widgetTypeToUpdate.getMainGroup(), widgetTypeToUpdate.getConfigUi(), widgetTypeToUpdate.getBundleId());
}
for (int i = 0; i < addedFragments.size(); i++) {
GuiFragment guiFragment = addedFragments.get(i);
this.getGuiFragmentManager().deleteGuiFragment(guiFragment.getCode());
}
for (int i = 0; i < updatedFragments.size(); i++) {
GuiFragment guiFragment = updatedFragments.get(i);
this.getGuiFragmentManager().updateGuiFragment(guiFragment);
}
}
use of org.entando.entando.aps.system.services.guifragment.GuiFragment in project entando-core by entando.
the class ApiWidgetTypeInterface method updateWidgetType.
public StringApiResponse updateWidgetType(JAXBWidgetType jaxbWidgetType) throws ApiException, Throwable {
StringApiResponse response = new StringApiResponse();
WidgetType widgetTypeToUpdate = null;
List<GuiFragment> addedFragments = new ArrayList<GuiFragment>();
List<GuiFragment> updatedFragments = new ArrayList<GuiFragment>();
try {
widgetTypeToUpdate = this.getWidgetTypeManager().getWidgetType(jaxbWidgetType.getCode());
if (null == widgetTypeToUpdate) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "WidgetType with code " + jaxbWidgetType.getCode() + " does not exists", Response.Status.CONFLICT);
}
WidgetType widgetType = jaxbWidgetType.getModifiedWidgetType(this.getWidgetTypeManager());
this.checkAndSaveFragment(widgetType, jaxbWidgetType, false, response, addedFragments, updatedFragments);
this.getWidgetTypeManager().updateWidgetType(widgetType.getCode(), widgetType.getTitles(), widgetType.getConfig(), widgetType.getMainGroup(), widgetType.getConfigUi(), widgetType.getBundleId());
response.setResult(IResponseBuilder.SUCCESS, null);
} catch (ApiException ae) {
this.revertPreviousObject(widgetTypeToUpdate, addedFragments, updatedFragments);
throw ae;
} catch (Throwable t) {
this.revertPreviousObject(widgetTypeToUpdate, addedFragments, updatedFragments);
_logger.error("Error updating widget type", t);
throw t;
}
return response;
}
use of org.entando.entando.aps.system.services.guifragment.GuiFragment 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.guifragment.GuiFragment in project entando-core by entando.
the class WidgetService method updateWidget.
@Override
public WidgetDto updateWidget(String widgetCode, WidgetRequest widgetRequest) {
WidgetType type = this.getWidgetManager().getWidgetType(widgetCode);
if (type == null) {
throw new ResourceNotFoundException(WidgetValidator.ERRCODE_WIDGET_DOES_NOT_EXISTS, "widget", widgetCode);
}
WidgetDto widgetDto = null;
try {
if (null == this.getGroupManager().getGroup(widgetRequest.getGroup())) {
BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(type, "widget");
bindingResult.reject(WidgetValidator.ERRCODE_WIDGET_GROUP_INVALID, new String[] { widgetRequest.getGroup() }, "widgettype.group.invalid");
throw new ValidationGenericException(bindingResult);
}
if (type.isUserType() && StringUtils.isBlank(widgetRequest.getCustomUi()) && !WidgetType.existsJsp(this.srvCtx, widgetCode, widgetCode)) {
BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(type, "widget");
bindingResult.reject(WidgetValidator.ERRCODE_NOT_BLANK, new String[] { type.getCode() }, "widgettype.customUi.notBlank");
throw new ValidationGenericException(bindingResult);
}
this.processWidgetType(type, widgetRequest);
widgetDto = dtoBuilder.convert(type);
this.getWidgetManager().updateWidgetType(widgetCode, type.getTitles(), type.getConfig(), type.getMainGroup(), type.getConfigUi(), type.getBundleId());
if (!StringUtils.isEmpty(widgetCode)) {
GuiFragment guiFragment = this.getGuiFragmentManager().getUniqueGuiFragmentByWidgetType(widgetCode);
if (null == guiFragment) {
this.createAndAddFragment(type, widgetRequest);
} else {
guiFragment.setGui(widgetRequest.getCustomUi());
this.getGuiFragmentManager().updateGuiFragment(guiFragment);
}
}
this.addFragments(widgetDto);
} catch (ValidationGenericException vge) {
logger.error("Found an error on validation, throwing original exception", vge);
throw vge;
} catch (Throwable e) {
logger.error("failed to update widget type", e);
throw new RestServerError("Failed to update widget", e);
}
return widgetDto;
}
use of org.entando.entando.aps.system.services.guifragment.GuiFragment in project entando-core by entando.
the class WidgetTypeAction method checkGui.
private boolean checkGui() throws Throwable {
if (this.getStrutsAction() == NEW_USER_WIDGET || this.getStrutsAction() == ApsAdminSystemConstants.PASTE) {
return true;
}
boolean isValuedGui = StringUtils.isNotBlank(this.getGui());
if (this.getStrutsAction() == ApsAdminSystemConstants.ADD) {
return isValuedGui;
}
if (this.getStrutsAction() != ApsAdminSystemConstants.EDIT) {
throw new RuntimeException("Invalid Struts Action " + this.getStrutsAction());
}
WidgetType type = this.getWidgetType(this.getWidgetTypeCode());
if (type.isLogic() || this.isInternalServletWidget(this.getWidgetTypeCode())) {
return true;
}
String pluginCode = type.getPluginCode();
ServletContext srvCtx = this.getRequest().getSession().getServletContext();
if (WidgetType.existsJsp(srvCtx, this.getWidgetTypeCode(), pluginCode)) {
return true;
}
GuiFragment guiFragment = this.extractUniqueGuiFragment(this.getWidgetTypeCode());
if (!isValuedGui && (guiFragment == null || StringUtils.isBlank(guiFragment.getDefaultGui()))) {
return false;
} else {
return true;
}
}
Aggregations