use of org.entando.entando.aps.system.services.guifragment.GuiFragment in project entando-core by entando.
the class WidgetTypeManager method deleteWidgetType.
@Override
public void deleteWidgetType(String widgetTypeCode) throws ApsSystemException {
List<GuiFragment> deletedFragments = new ArrayList<GuiFragment>();
try {
WidgetType type = this.getWidgetType(widgetTypeCode);
if (null == type) {
logger.error("Type not exists : type code {}", widgetTypeCode);
return;
}
if (type.isLocked()) {
logger.error("A locked widget can't be deleted - type {}", widgetTypeCode);
return;
}
List<String> fragmentCodes = this.getGuiFragmentManager().getGuiFragmentCodesByWidgetType(widgetTypeCode);
if (null != fragmentCodes) {
for (int i = 0; i < fragmentCodes.size(); i++) {
String fragmentCode = fragmentCodes.get(i);
GuiFragment fragmentToDelete = this.getGuiFragmentManager().getGuiFragment(fragmentCode);
deletedFragments.add(fragmentToDelete);
this.getGuiFragmentManager().deleteGuiFragment(fragmentCode);
}
}
this.getWidgetTypeDAO().deleteWidgetType(widgetTypeCode);
this.getCacheWrapper().deleteWidgetType(widgetTypeCode);
this.notifyWidgetTypeChanging(widgetTypeCode, WidgetTypeChangedEvent.REMOVE_OPERATION_CODE);
} catch (Throwable t) {
for (int i = 0; i < deletedFragments.size(); i++) {
GuiFragment guiFragment = deletedFragments.get(i);
if (null == this.getGuiFragmentManager().getGuiFragment(guiFragment.getCode())) {
this.getGuiFragmentManager().addGuiFragment(guiFragment);
}
}
logger.error("Error deleting widget type", t);
throw new ApsSystemException("Error deleting widget type", t);
}
}
use of org.entando.entando.aps.system.services.guifragment.GuiFragment in project entando-core by entando.
the class WidgetTypeManager method getGuiFragmentUtilizers.
@Override
public List getGuiFragmentUtilizers(String guiFragmentCode) throws ApsSystemException {
List<WidgetType> utilizers = new ArrayList<WidgetType>();
try {
FieldSearchFilter codeFilter = new FieldSearchFilter("code", guiFragmentCode, false);
FieldSearchFilter widgetTypeFilter = new FieldSearchFilter("widgettypecode");
FieldSearchFilter[] filters = { codeFilter, widgetTypeFilter };
List<String> widgetUtilizers = this.getGuiFragmentManager().searchGuiFragments(filters);
if (null != widgetUtilizers && !widgetUtilizers.isEmpty()) {
for (int i = 0; i < widgetUtilizers.size(); i++) {
String code = widgetUtilizers.get(i);
GuiFragment fragment = this.getGuiFragmentManager().getGuiFragment(code);
WidgetType widgetType = this.getWidgetType(fragment.getWidgetTypeCode());
if (null != widgetType) {
utilizers.add(widgetType);
}
}
}
} catch (Throwable t) {
logger.error("Error extracting utilizers", t);
throw new ApsSystemException("Error extracting utilizers", t);
}
return utilizers;
}
use of org.entando.entando.aps.system.services.guifragment.GuiFragment in project entando-core by entando.
the class ApiWidgetTypeInterface method getWidgetType.
public JAXBWidgetType getWidgetType(Properties properties) throws ApiException, Throwable {
String widgetTypeCode = properties.getProperty("code");
JAXBWidgetType jaxbWidgetType = null;
try {
WidgetType widgetType = this.getWidgetTypeManager().getWidgetType(widgetTypeCode);
if (null == widgetType) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "WidgetType with code '" + widgetTypeCode + "' does not exist", Response.Status.CONFLICT);
}
GuiFragment singleGuiFragment = null;
List<GuiFragment> fragments = new ArrayList<GuiFragment>();
if (!widgetType.isLogic()) {
singleGuiFragment = this.getGuiFragmentManager().getUniqueGuiFragmentByWidgetType(widgetTypeCode);
} else {
List<String> fragmentCodes = this.getGuiFragmentManager().getGuiFragmentCodesByWidgetType(widgetTypeCode);
if (null != fragmentCodes) {
for (int i = 0; i < fragmentCodes.size(); i++) {
String fragmentCode = fragmentCodes.get(i);
GuiFragment fragment = this.getGuiFragmentManager().getGuiFragment(fragmentCode);
if (null != fragment) {
fragments.add(fragment);
}
}
}
}
jaxbWidgetType = new JAXBWidgetType(widgetType, singleGuiFragment, fragments);
} catch (ApiException ae) {
throw ae;
} catch (Throwable t) {
_logger.error("Error creating widget type - code '{}'", widgetTypeCode, t);
throw t;
}
return jaxbWidgetType;
}
use of org.entando.entando.aps.system.services.guifragment.GuiFragment in project entando-core by entando.
the class ApiWidgetTypeInterface method addWidgetType.
public void addWidgetType(JAXBWidgetType jaxbWidgetType) throws ApiException, Throwable {
List<GuiFragment> addedFragments = new ArrayList<GuiFragment>();
List<GuiFragment> updatedFragments = new ArrayList<GuiFragment>();
try {
WidgetType widgetType = this.getWidgetTypeManager().getWidgetType(jaxbWidgetType.getCode());
if (null != widgetType) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "WidgetType with code " + jaxbWidgetType.getCode() + " already exists", Response.Status.CONFLICT);
}
widgetType = jaxbWidgetType.getNewWidgetType(this.getWidgetTypeManager());
if (!widgetType.isLogic() && StringUtils.isBlank(jaxbWidgetType.getGui())) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Gui is mandatory", Response.Status.CONFLICT);
}
if (widgetType.isLogic() && (StringUtils.isNotBlank(jaxbWidgetType.getGui()) || (null != jaxbWidgetType.getFragments() && jaxbWidgetType.getFragments().size() > 0))) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Fragment mustn't be added on the new logic widget type", Response.Status.CONFLICT);
}
if (widgetType.isLogic() && this.isInternalServletWidget(widgetType.getParentType().getCode())) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Logic type with parent 'Internal Servlet' widget mustn't be added", Response.Status.CONFLICT);
}
this.getWidgetTypeManager().addWidgetType(widgetType);
if (!widgetType.isLogic()) {
this.checkAndSaveFragment(widgetType, jaxbWidgetType, true, null, addedFragments, updatedFragments);
}
} catch (ApiException ae) {
this.revertPreviousObject(null, addedFragments, updatedFragments);
throw ae;
} catch (Throwable t) {
this.revertPreviousObject(null, addedFragments, updatedFragments);
this.getWidgetTypeManager().deleteWidgetType(jaxbWidgetType.getCode());
_logger.error("Error adding new widget type", t);
throw t;
}
}
use of org.entando.entando.aps.system.services.guifragment.GuiFragment in project entando-core by entando.
the class GuiFragmentTag method extractFragmentOutput.
protected String extractFragmentOutput(RequestContext reqCtx) throws ApsSystemException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
IGuiFragmentManager guiFragmentManager = (IGuiFragmentManager) ApsWebApplicationUtils.getBean(SystemConstants.GUI_FRAGMENT_MANAGER, this.pageContext);
GuiFragment guiFragment = guiFragmentManager.getGuiFragment(this.getCode());
if (null == guiFragment || StringUtils.isBlank(guiFragment.getCurrentGui())) {
return null;
}
ExecutorBeanContainer ebc = (ExecutorBeanContainer) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_EXECUTOR_BEAN_CONTAINER);
Writer out = new OutputStreamWriter(baos);
Template template = new Template(this.getCode(), new StringReader(guiFragment.getCurrentGui()), ebc.getConfiguration());
template.process(ebc.getTemplateModel(), out);
out.flush();
} catch (Throwable t) {
String msg = "Error creating fragment output - code '" + this.getCode() + "'";
_logger.error(msg, t);
throw new ApsSystemException(msg, t);
}
return baos.toString();
}
Aggregations