Search in sources :

Example 1 with PageModelUtilizer

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;
}
Also used : HashMap(java.util.HashMap) List(java.util.List) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) PageModelUtilizer(com.agiletec.aps.system.services.pagemodel.PageModelUtilizer)

Example 2 with PageModelUtilizer

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;
    }
}
Also used : HashMap(java.util.HashMap) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ArrayList(java.util.ArrayList) List(java.util.List) PageModel(com.agiletec.aps.system.services.pagemodel.PageModel) PageModelUtilizer(com.agiletec.aps.system.services.pagemodel.PageModelUtilizer) ListableBeanFactory(org.springframework.beans.factory.ListableBeanFactory) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Aggregations

ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)2 PageModelUtilizer (com.agiletec.aps.system.services.pagemodel.PageModelUtilizer)2 HashMap (java.util.HashMap)2 List (java.util.List)2 PageModel (com.agiletec.aps.system.services.pagemodel.PageModel)1 ArrayList (java.util.ArrayList)1 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)1 ListableBeanFactory (org.springframework.beans.factory.ListableBeanFactory)1