use of org.entando.entando.aps.system.services.guifragment.GuiFragmentUtilizer in project entando-core by entando.
the class GuiFragmentActionHelper method getReferencingObjects.
@SuppressWarnings("unchecked")
@Override
public Map<String, List<Object>> getReferencingObjects(GuiFragment fragment, HttpServletRequest request) throws ApsSystemException {
Map<String, List<Object>> references = new HashMap<String, List<Object>>();
try {
String[] defNames = ApsWebApplicationUtils.getWebApplicationContext(request).getBeanNamesForType(GuiFragmentUtilizer.class);
for (int i = 0; i < defNames.length; i++) {
Object service = null;
try {
service = ApsWebApplicationUtils.getWebApplicationContext(request).getBean(defNames[i]);
} catch (Throwable t) {
_logger.error("error in hasReferencingObjects", t);
service = null;
}
if (service != null) {
GuiFragmentUtilizer guiFragUtilizer = (GuiFragmentUtilizer) service;
List<Object> utilizers = guiFragUtilizer.getGuiFragmentUtilizers(fragment.getCode());
if (utilizers != null && !utilizers.isEmpty()) {
// FIXME UNIFORMARE E STUDIARE CHIAVE IDONEA
references.put(guiFragUtilizer.getName() + "Utilizers", utilizers);
}
}
}
} catch (Throwable t) {
throw new ApsSystemException("Error in getReferencingObjects", t);
}
return references;
}
use of org.entando.entando.aps.system.services.guifragment.GuiFragmentUtilizer 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.GuiFragmentUtilizer 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);
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;
}
Aggregations