Package org.jibeframework.contentmanager.controller

Source Code of org.jibeframework.contentmanager.controller.SupportController

package org.jibeframework.contentmanager.controller;

import java.util.ArrayList;
import java.util.List;

import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.dictionary.TypeDefinition;
import org.alfresco.service.namespace.InvalidQNameException;
import org.alfresco.service.namespace.NamespaceException;
import org.alfresco.service.namespace.QName;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.jibeframework.alfresco.util.AlfrescoUtil;
import org.jibeframework.core.annotation.Cache;
import org.jibeframework.core.app.config.ConfigurationConfig;
import org.jibeframework.core.service.ConfigService;
import org.jibeframework.core.util.JsonModelEntry;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

@Controller
public class SupportController {
  @Autowired
  private ConfigService configService;
  private static Logger log = Logger.getLogger(SupportController.class);

  @Cache("searchRestrictions")
  public List<JsonModelEntry> cacheSearchRestrictions() {
    List<JsonModelEntry> model = new ArrayList<JsonModelEntry>();
    model.add(new JsonModelEntry("0", "All Items"));
    model.add(new JsonModelEntry("1", "File names and contents"));
    model.add(new JsonModelEntry("2", "File names only"));
    model.add(new JsonModelEntry("3", "Space names only"));
    return model;
  }

  @Cache("contentTypes")
  public List<JsonModelEntry> cacheContentsTypes() {
    return getConfiguredModel("content-types/content-type");
  }

  @Cache("folderTypes")
  public List<JsonModelEntry> cacheFolderTypes() {
    return getConfiguredModel("space-types/space-type");
  }

  @SuppressWarnings("unchecked")
  private List<JsonModelEntry> getConfiguredModel(String configKey) {
    List<String> spaceTypes = configService.getConfig(ConfigurationConfig.class).getConfiguration().getList(
        configKey);
    List<JsonModelEntry> model = new ArrayList<JsonModelEntry>();
    for (String type : spaceTypes) {
      try {
        ServiceRegistry serviceRegistry = AlfrescoUtil.getServiceRegistry();
        QName qName = QName.createQName(type, serviceRegistry.getNamespaceService());
        TypeDefinition td = serviceRegistry.getDictionaryService().getType(qName);
        if (td != null) {
          String title = td.getTitle();
          if (StringUtils.isEmpty(title)) {
            title = type;
          }
          model.add(new JsonModelEntry(type, title));
        } else {
          log.warn("The type definition is not existing : " + type);
        }
      } catch (InvalidQNameException e) {
        log.warn("Invalid QName : " + type, e);
      } catch (NamespaceException e) {
        log.warn("Invalid namespace : " + type, e);
      }
    }
    return model;
  }

}
TOP

Related Classes of org.jibeframework.contentmanager.controller.SupportController

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.