use of org.entando.entando.aps.system.services.guifragment.GuiFragment in project entando-core by entando.
the class GuiFragmentDtoBuilder method toDto.
@Override
protected GuiFragmentDto toDto(GuiFragment src) {
if (null == src) {
return null;
}
WidgetType type = null;
if (StringUtils.isNotEmpty(src.getWidgetTypeCode())) {
type = this.getWidgetTypeManager().getWidgetType(src.getWidgetTypeCode());
}
GuiFragmentDto dest = new GuiFragmentDto(src, type, langManager);
ListableBeanFactory factory = (ListableBeanFactory) this.beanFactory;
String[] defNames = factory.getBeanNamesForType(GuiFragmentUtilizer.class);
for (String defName : defNames) {
GuiFragmentUtilizer utilizers = null;
try {
utilizers = this.beanFactory.getBean(defName, GuiFragmentUtilizer.class);
List<Object> references = utilizers.getGuiFragmentUtilizers(src.getCode());
if (null != references) {
for (Object reference : references) {
if (reference instanceof GuiFragment) {
dest.addFragmentRef((GuiFragment) reference);
} else if (reference instanceof PageModel) {
dest.addPageModelRef((PageModel) reference);
} else {
logger.info("unexpected reference - type {}", reference.getClass());
}
}
}
} catch (Throwable t) {
logger.error("Error extracting reference from bean '{}'", defName);
utilizers = null;
}
}
return dest;
}
use of org.entando.entando.aps.system.services.guifragment.GuiFragment in project entando-core by entando.
the class ApiGuiFragmentInterface method updateGuiFragment.
public void updateGuiFragment(JAXBGuiFragment jaxbGuiFragment) throws ApiException, Throwable {
try {
if (null == this.getGuiFragmentManager().getGuiFragment(jaxbGuiFragment.getCode())) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "GuiFragment with code '" + jaxbGuiFragment.getCode() + "' does not exist", Response.Status.CONFLICT);
}
GuiFragment guiFragment = jaxbGuiFragment.getGuiFragment();
if (StringUtils.isBlank(guiFragment.getCurrentGui())) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "one between A and B must be valued", Response.Status.CONFLICT);
}
this.getGuiFragmentManager().updateGuiFragment(guiFragment);
} catch (ApiException ae) {
throw ae;
} catch (Throwable t) {
_logger.error("Error updating fragment", t);
throw t;
}
}
use of org.entando.entando.aps.system.services.guifragment.GuiFragment in project entando-core by entando.
the class ApiGuiFragmentInterface method deleteGuiFragment.
public void deleteGuiFragment(Properties properties) throws ApiException, Throwable {
String code = properties.getProperty("code");
try {
GuiFragment guiFragment = this.getGuiFragmentManager().getGuiFragment(code);
if (null == guiFragment) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "GuiFragment with code '" + code + "' does not exist", Response.Status.CONFLICT);
}
if (guiFragment.isLocked()) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "GuiFragment with code '" + code + "' are locked", Response.Status.CONFLICT);
}
Map<String, List<Object>> references = new HashMap<String, List<Object>>();
ListableBeanFactory factory = (ListableBeanFactory) this.getBeanFactory();
String[] defNames = factory.getBeanNamesForType(GuiFragmentUtilizer.class);
for (int i = 0; i < defNames.length; i++) {
Object service = null;
try {
service = this.getBeanFactory().getBean(defNames[i]);
} catch (Throwable t) {
_logger.error("error extracting bean with name '{}'", defNames[i], t);
throw new ApsSystemException("error extracting bean with name '" + defNames[i] + "'", t);
}
if (service != null) {
GuiFragmentUtilizer guiFragUtilizer = (GuiFragmentUtilizer) service;
List<Object> utilizers = guiFragUtilizer.getGuiFragmentUtilizers(code);
if (utilizers != null && !utilizers.isEmpty()) {
references.put(guiFragUtilizer.getName(), utilizers);
}
}
}
if (!references.isEmpty()) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "GuiFragment with code " + code + " has references with other object", Response.Status.CONFLICT);
}
this.getGuiFragmentManager().deleteGuiFragment(code);
} catch (ApiException ae) {
throw ae;
} catch (Throwable t) {
_logger.error("Error deleting fragment throw api", t);
throw t;
}
}
use of org.entando.entando.aps.system.services.guifragment.GuiFragment in project entando-core by entando.
the class WidgetService method addFragments.
private void addFragments(WidgetDto widgetDto) throws Exception {
List<String> fragmentCodes = this.getGuiFragmentManager().getGuiFragmentCodesByWidgetType(widgetDto.getCode());
if (fragmentCodes != null) {
for (String fragmentCode : fragmentCodes) {
GuiFragment fragment = this.getGuiFragmentManager().getGuiFragment(fragmentCode);
widgetDto.addGuiFragmentRef(fragment.getCode(), fragment.getCurrentGui(), fragment.getDefaultGui());
}
}
}
use of org.entando.entando.aps.system.services.guifragment.GuiFragment in project entando-core by entando.
the class WidgetService method createAndAddFragment.
private void createAndAddFragment(WidgetType widgetType, WidgetRequest widgetRequest) throws Exception {
GuiFragment guiFragment = new GuiFragment();
String code = this.extractUniqueGuiFragmentCode(widgetType.getCode());
guiFragment.setCode(code);
guiFragment.setPluginCode(widgetType.getPluginCode());
guiFragment.setGui(widgetRequest.getCustomUi());
guiFragment.setWidgetTypeCode(widgetType.getCode());
this.getGuiFragmentManager().addGuiFragment(guiFragment);
}
Aggregations