use of com.agiletec.aps.system.services.pagemodel.PageModelUtilizer in project entando-core by entando.
the class PageModelActionHelper method getReferencingObjects.
@Override
public Map<String, List<Object>> getReferencingObjects(PageModel pageModel, HttpServletRequest request) throws ApsSystemException {
Map<String, List<Object>> references = new HashMap<String, List<Object>>();
try {
String[] defNames = ApsWebApplicationUtils.getWebApplicationContext(request).getBeanNamesForType(PageModelUtilizer.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) {
PageModelUtilizer pageModelUtilizer = (PageModelUtilizer) service;
List<Object> utilizers = pageModelUtilizer.getPageModelUtilizers(pageModel.getCode());
if (utilizers != null && !utilizers.isEmpty()) {
references.put(pageModelUtilizer.getName() + "Utilizers", utilizers);
}
}
}
} catch (Throwable t) {
throw new ApsSystemException("Error on getReferencingObjects methods", t);
}
return references;
}
use of com.agiletec.aps.system.services.pagemodel.PageModelUtilizer in project entando-core by entando.
the class ApiPageModelInterface method deletePageModel.
public void deletePageModel(Properties properties) throws ApiException, Throwable {
String code = properties.getProperty("code");
try {
PageModel pageModel = this.getPageModelManager().getPageModel(code);
if (null == pageModel) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "PageModel with code '" + code + "' does not exist", Response.Status.CONFLICT);
}
Map<String, List<Object>> references = new HashMap<String, List<Object>>();
ListableBeanFactory factory = (ListableBeanFactory) this.getBeanFactory();
String[] defNames = factory.getBeanNamesForType(PageModelUtilizer.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) {
PageModelUtilizer pageModelUtilizer = (PageModelUtilizer) service;
List<Object> utilizers = pageModelUtilizer.getPageModelUtilizers(code);
if (utilizers != null && !utilizers.isEmpty()) {
references.put(pageModelUtilizer.getName(), utilizers);
}
}
}
if (!references.isEmpty()) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "PageModel with code " + code + " has references with other object", Response.Status.CONFLICT);
}
this.getPageModelManager().deletePageModel(code);
} catch (ApiException ae) {
throw ae;
} catch (Throwable t) {
_logger.error("Error deleting page template throw api", t);
throw t;
}
}
Aggregations