Exemplo n.º 1
0
  public static Resource getResource(
      WebDAVRequest webDAVRequest, String rootPath, String token, long classNameId)
      throws WebDAVException {

    try {
      String[] pathArray = webDAVRequest.getPathArray();

      if (pathArray.length == 2) {
        String path = rootPath + webDAVRequest.getPath();

        return new BaseResourceImpl(path, StringPool.BLANK, token);
      } else if (pathArray.length == 3) {
        String type = pathArray[2];

        return toResource(webDAVRequest, type, rootPath, false);
      } else if (pathArray.length == 4) {
        String type = pathArray[2];
        String typeId = pathArray[3];

        if (type.equals(TYPE_STRUCTURES)) {
          try {
            DDMStructure structure = null;

            try {
              structure = DDMStructureLocalServiceUtil.getStructure(GetterUtil.getLong(typeId));
            } catch (NumberFormatException nfe) {
              structure =
                  DDMStructureLocalServiceUtil.getStructure(
                      webDAVRequest.getGroupId(), classNameId, typeId);
            }

            return DDMWebDavUtil.toResource(webDAVRequest, structure, rootPath, false);
          } catch (NoSuchStructureException nsse) {
            return null;
          }
        } else if (type.equals(TYPE_TEMPLATES)) {
          try {
            DDMTemplate template = null;

            try {
              template = DDMTemplateLocalServiceUtil.getTemplate(GetterUtil.getLong(typeId));
            } catch (NumberFormatException nfe) {
              template =
                  DDMTemplateLocalServiceUtil.getTemplate(
                      webDAVRequest.getGroupId(), classNameId, typeId);
            }

            return DDMWebDavUtil.toResource(webDAVRequest, template, rootPath, false);
          } catch (NoSuchTemplateException nste) {
            return null;
          }
        }
      }

      return null;
    } catch (Exception e) {
      throw new WebDAVException(e);
    }
  }
Exemplo n.º 2
0
  @Override
  public void deleteStagedModel(String uuid, long groupId, String className, String extraData)
      throws PortalException, SystemException {

    DDMStructure ddmStructure =
        DDMStructureLocalServiceUtil.fetchDDMStructureByUuidAndGroupId(uuid, groupId);

    if (ddmStructure != null) {
      DDMStructureLocalServiceUtil.deleteStructure(ddmStructure);
    }
  }
  protected void addDDMStructures(
      long userId, long groupId, long classNameId, String fileName, ServiceContext serviceContext)
      throws DocumentException, PortalException, SystemException {

    List<Element> structureElements = getDDMStructures(fileName);

    for (Element structureElement : structureElements) {
      boolean dynamicStructure =
          GetterUtil.getBoolean(structureElement.elementText("dynamic-structure"));

      if (dynamicStructure) {
        continue;
      }

      String name = structureElement.elementText("name");

      String description = structureElement.elementText("description");

      String ddmStructureKey = name;

      DDMStructure ddmStructure =
          DDMStructureLocalServiceUtil.fetchStructure(groupId, ddmStructureKey);

      if (ddmStructure != null) {
        continue;
      }

      Element structureElementRootElement = structureElement.element("root");

      String xsd = structureElementRootElement.asXML();

      Map<Locale, String> nameMap = new HashMap<Locale, String>();

      nameMap.put(LocaleUtil.getDefault(), name);

      Map<Locale, String> descriptionMap = new HashMap<Locale, String>();

      descriptionMap.put(LocaleUtil.getDefault(), description);

      DDMStructureLocalServiceUtil.addStructure(
          userId,
          groupId,
          classNameId,
          ddmStructureKey,
          nameMap,
          descriptionMap,
          xsd,
          "xml",
          DDMStructureConstants.TYPE_DEFAULT,
          serviceContext);
    }
  }
Exemplo n.º 4
0
  protected DDMStructure fetchExistingStructure(
      String uuid, long groupId, long classNameId, String structureKey, boolean preloaded)
      throws Exception {

    DDMStructure existingStructure = null;

    if (!preloaded) {
      existingStructure =
          DDMStructureLocalServiceUtil.fetchDDMStructureByUuidAndGroupId(uuid, groupId);
    } else {
      existingStructure =
          DDMStructureLocalServiceUtil.fetchStructure(groupId, classNameId, structureKey);
    }

    return existingStructure;
  }
  @Override
  protected void validateImport(
      Map<String, List<StagedModel>> dependentStagedModelsMap, Group group) throws Exception {

    List<StagedModel> ddmStructureDependentStagedModels =
        dependentStagedModelsMap.get(DDMStructure.class.getSimpleName());

    Assert.assertEquals(1, ddmStructureDependentStagedModels.size());

    DDMStructure ddmStructure = (DDMStructure) ddmStructureDependentStagedModels.get(0);

    DDMStructureLocalServiceUtil.getDDMStructureByUuidAndGroupId(
        ddmStructure.getUuid(), group.getGroupId());

    List<StagedModel> dlFileEntryTypesDependentStagedModels =
        dependentStagedModelsMap.get(DLFileEntryType.class.getSimpleName());

    Assert.assertEquals(1, dlFileEntryTypesDependentStagedModels.size());

    DLFileEntryType dlFileEntryType =
        (DLFileEntryType) dlFileEntryTypesDependentStagedModels.get(0);

    DLFileEntryTypeLocalServiceUtil.getDLFileEntryTypeByUuidAndGroupId(
        dlFileEntryType.getUuid(), group.getGroupId());

    List<StagedModel> folderDependentStagedModels =
        dependentStagedModelsMap.get(DLFolder.class.getSimpleName());

    Assert.assertEquals(1, folderDependentStagedModels.size());

    Folder parentFolder = (Folder) folderDependentStagedModels.get(0);

    DLFolderLocalServiceUtil.getDLFolderByUuidAndGroupId(
        parentFolder.getUuid(), group.getGroupId());
  }
  protected void validateCompanyDependenciesImport(
      Map<String, List<StagedModel>> dependentStagedModelsMap, Group group) throws Exception {

    List<StagedModel> ddmStructureDependentStagedModels =
        dependentStagedModelsMap.get(DDMStructure.class.getSimpleName());

    Assert.assertEquals(1, ddmStructureDependentStagedModels.size());

    DDMStructure ddmStructure = (DDMStructure) ddmStructureDependentStagedModels.get(0);

    Assert.assertNull(
        "Company DDM structure dependency should not be imported",
        DDMStructureLocalServiceUtil.fetchDDMStructureByUuidAndGroupId(
            ddmStructure.getUuid(), group.getGroupId()));

    List<StagedModel> dlFileEntryTypesDependentStagedModels =
        dependentStagedModelsMap.get(DLFileEntryType.class.getSimpleName());

    Assert.assertEquals(1, dlFileEntryTypesDependentStagedModels.size());

    DLFileEntryType dlFileEntryType =
        (DLFileEntryType) dlFileEntryTypesDependentStagedModels.get(0);

    Assert.assertNull(
        "Company DL file entry should not be imported",
        DLFileEntryTypeLocalServiceUtil.fetchDLFileEntryTypeByUuidAndGroupId(
            dlFileEntryType.getUuid(), group.getGroupId()));
  }
 protected DDMStructure getStructure(long structureId) {
   try {
     return DDMStructureLocalServiceUtil.getStructure(structureId);
   } catch (Exception e) {
     return null;
   }
 }
  protected String extractDDMContent(DLFileVersion dlFileVersion, Locale locale) throws Exception {

    List<DLFileEntryMetadata> dlFileEntryMetadatas =
        DLFileEntryMetadataLocalServiceUtil.getFileVersionFileEntryMetadatas(
            dlFileVersion.getFileVersionId());

    StringBundler sb = new StringBundler(dlFileEntryMetadatas.size());

    for (DLFileEntryMetadata dlFileEntryMetadata : dlFileEntryMetadatas) {
      Fields fields = null;

      try {
        fields = StorageEngineUtil.getFields(dlFileEntryMetadata.getDDMStorageId());
      } catch (Exception e) {
      }

      if (fields != null) {
        DDMStructure ddmStructure =
            DDMStructureLocalServiceUtil.getStructure(dlFileEntryMetadata.getDDMStructureId());

        sb.append(DDMIndexerUtil.extractAttributes(ddmStructure, fields, locale));
      }
    }

    return sb.toString();
  }
  public static boolean contains(
      PermissionChecker permissionChecker, long structureId, String portletId, String actionId)
      throws PortalException {

    DDMStructure structure = DDMStructureLocalServiceUtil.getStructure(structureId);

    return contains(permissionChecker, structure, portletId, actionId);
  }
  @Override
  public void postProcessSearchQuery(BooleanQuery searchQuery, SearchContext searchContext)
      throws Exception {

    Set<DDMStructure> ddmStructuresSet = new TreeSet<DDMStructure>();

    long[] groupIds = searchContext.getGroupIds();

    if ((groupIds != null) && (groupIds.length > 0)) {
      List<DLFileEntryType> dlFileEntryTypes =
          DLFileEntryTypeLocalServiceUtil.getFileEntryTypes(groupIds);

      for (DLFileEntryType dlFileEntryType : dlFileEntryTypes) {
        ddmStructuresSet.addAll(dlFileEntryType.getDDMStructures());
      }
    }

    Group group = GroupLocalServiceUtil.getCompanyGroup(searchContext.getCompanyId());

    DDMStructure tikaRawMetadataStructure =
        DDMStructureLocalServiceUtil.fetchStructure(
            group.getGroupId(),
            PortalUtil.getClassNameId(RawMetadataProcessor.class),
            "TikaRawMetadata");

    if (tikaRawMetadataStructure != null) {
      ddmStructuresSet.add(tikaRawMetadataStructure);
    }

    for (DDMStructure ddmStructure : ddmStructuresSet) {
      addSearchDDMStruture(searchQuery, searchContext, ddmStructure);
    }

    String keywords = searchContext.getKeywords();

    if (Validator.isNull(keywords)) {
      addSearchTerm(searchQuery, searchContext, Field.DESCRIPTION, false);
      addSearchTerm(searchQuery, searchContext, Field.TITLE, false);
      addSearchTerm(searchQuery, searchContext, Field.USER_NAME, false);
    }

    addSearchTerm(searchQuery, searchContext, "extension", false);
    addSearchTerm(searchQuery, searchContext, "fileEntryTypeId", false);
    addSearchTerm(searchQuery, searchContext, "path", false);

    LinkedHashMap<String, Object> params =
        (LinkedHashMap<String, Object>) searchContext.getAttribute("params");

    if (params != null) {
      String expandoAttributes = (String) params.get("expandoAttributes");

      if (Validator.isNotNull(expandoAttributes)) {
        addSearchExpando(searchQuery, searchContext, expandoAttributes);
      }
    }
  }
  @Override
  public void postProcessContextQuery(BooleanQuery contextQuery, SearchContext searchContext)
      throws Exception {

    addStatus(contextQuery, searchContext);

    if (searchContext.isIncludeAttachments()) {
      addRelatedClassNames(contextQuery, searchContext);
    }

    contextQuery.addRequiredTerm(Field.HIDDEN, searchContext.isIncludeAttachments());

    addSearchClassTypeIds(contextQuery, searchContext);

    String ddmStructureFieldName = (String) searchContext.getAttribute("ddmStructureFieldName");
    Serializable ddmStructureFieldValue = searchContext.getAttribute("ddmStructureFieldValue");

    if (Validator.isNotNull(ddmStructureFieldName) && Validator.isNotNull(ddmStructureFieldValue)) {

      String[] ddmStructureFieldNameParts =
          StringUtil.split(ddmStructureFieldName, StringPool.SLASH);

      DDMStructure structure =
          DDMStructureLocalServiceUtil.getStructure(
              GetterUtil.getLong(ddmStructureFieldNameParts[1]));

      String fieldName =
          StringUtil.replaceLast(
              ddmStructureFieldNameParts[2],
              StringPool.UNDERLINE.concat(LocaleUtil.toLanguageId(searchContext.getLocale())),
              StringPool.BLANK);

      try {
        ddmStructureFieldValue =
            DDMUtil.getIndexedFieldValue(ddmStructureFieldValue, structure.getFieldType(fieldName));
      } catch (StructureFieldException sfe) {
      }

      contextQuery.addRequiredTerm(
          ddmStructureFieldName, StringPool.QUOTE + ddmStructureFieldValue + StringPool.QUOTE);
    }

    String[] mimeTypes = (String[]) searchContext.getAttribute("mimeTypes");

    if (ArrayUtil.isNotEmpty(mimeTypes)) {
      BooleanQuery mimeTypesQuery = BooleanQueryFactoryUtil.create(searchContext);

      for (String mimeType : mimeTypes) {
        mimeTypesQuery.addTerm(
            "mimeType", StringUtil.replace(mimeType, CharPool.FORWARD_SLASH, CharPool.UNDERLINE));
      }

      contextQuery.add(mimeTypesQuery, BooleanClauseOccur.MUST);
    }
  }
Exemplo n.º 12
0
  @Override
  public String getCompleteXsd() throws PortalException, SystemException {
    if (getParentStructureId() == 0) {
      return getXsd();
    }

    DDMStructure parentStructure =
        DDMStructureLocalServiceUtil.getStructure(getParentStructureId());

    return _mergeXsds(getXsd(), parentStructure.getCompleteXsd());
  }
  public static boolean contains(
      PermissionChecker permissionChecker,
      long groupId,
      long classNameId,
      String structureKey,
      String actionId)
      throws PortalException {

    DDMStructure structure =
        DDMStructureLocalServiceUtil.getStructure(groupId, classNameId, structureKey, true);

    return contains(permissionChecker, structure, actionId);
  }
  @Override
  protected void validateImport(
      Map<String, List<StagedModel>> dependentStagedModelsMap, Group group) throws Exception {

    List<StagedModel> dependentStagedModels =
        dependentStagedModelsMap.get(DDMStructure.class.getSimpleName());

    Assert.assertEquals(1, dependentStagedModels.size());

    DDMStructure ddmStructure = (DDMStructure) dependentStagedModels.get(0);

    DDMStructureLocalServiceUtil.getDDMStructureByUuidAndGroupId(
        ddmStructure.getUuid(), group.getGroupId());
  }
  protected void validateDDMStructureFields(long ddmStructureId, Fields fields)
      throws PortalException {

    DDMStructure ddmStructure = DDMStructureLocalServiceUtil.getDDMStructure(ddmStructureId);

    for (Field field : fields) {
      if (!ddmStructure.hasField(field.getName())) {
        throw new StorageFieldNameException();
      }

      if (ddmStructure.getFieldRequired(field.getName()) && Validator.isNull(field.getValue())) {

        throw new StorageFieldRequiredException();
      }
    }
  }
Exemplo n.º 16
0
  @Override
  public boolean hasField(String fieldName) throws PortalException, SystemException {

    Map<String, Map<String, String>> fieldsMap = getFieldsMap();

    boolean hasField = fieldsMap.containsKey(fieldName);

    while (!hasField && (getParentStructureId() > 0)) {
      DDMStructure parentStructure =
          DDMStructureLocalServiceUtil.getStructure(getParentStructureId());

      hasField = parentStructure.hasField(fieldName);
    }

    return hasField;
  }
Exemplo n.º 17
0
  private void _indexFieldsMap(String locale) throws PortalException, SystemException {

    Map<String, Map<String, String>> fieldsMap = _localizedFieldsMap.get(locale);
    Map<String, Map<String, String>> transientFieldsMap = _localizedTransientFieldsMap.get(locale);

    if (fieldsMap != null) {
      return;
    }

    if (getParentStructureId() > 0) {
      DDMStructure parentStructure =
          DDMStructureLocalServiceUtil.getStructure(getParentStructureId());

      fieldsMap = parentStructure.getFieldsMap(locale);
      transientFieldsMap = parentStructure.getTransientFieldsMap(locale);
    } else {
      fieldsMap = new LinkedHashMap<String, Map<String, String>>();
      transientFieldsMap = new LinkedHashMap<String, Map<String, String>>();
    }

    XPath xPathSelector = SAXReaderUtil.createXPath("//dynamic-element");

    List<Node> nodes = xPathSelector.selectNodes(getDocument());

    for (Node node : nodes) {
      Element element = (Element) node;

      String name = element.attributeValue("name");

      if (Validator.isNotNull(element.attributeValue("dataType"))) {
        fieldsMap.put(name, _getField(element, locale));
      } else {
        transientFieldsMap.put(name, _getField(element, locale));
      }
    }

    String[] privateFieldNames = PropsValues.DYNAMIC_DATA_MAPPING_STRUCTURE_PRIVATE_FIELD_NAMES;

    for (String privateFieldName : privateFieldNames) {
      Map<String, String> privateField = _getPrivateField(privateFieldName);

      fieldsMap.put(privateFieldName, privateField);
    }

    _localizedFieldsMap.put(locale, fieldsMap);
    _localizedTransientFieldsMap.put(locale, transientFieldsMap);
  }
Exemplo n.º 18
0
  public static int addResource(WebDAVRequest webDavRequest, long classNameId) throws Exception {

    String[] pathArray = webDavRequest.getPathArray();

    if (pathArray.length != 4) {
      return HttpServletResponse.SC_FORBIDDEN;
    }

    String type = pathArray[2];
    String typeId = pathArray[3];

    if (type.equals(TYPE_STRUCTURES)) {
      HttpServletRequest request = webDavRequest.getHttpServletRequest();

      String xsd = StringUtil.read(request.getInputStream());

      String defaultLocale = LocalizationUtil.getDefaultLocale(xsd);

      Map<Locale, String> nameMap = new HashMap<Locale, String>();

      nameMap.put(LocaleUtil.fromLanguageId(defaultLocale), typeId);

      ServiceContext serviceContext = new ServiceContext();

      serviceContext.setAddGroupPermissions(true);
      serviceContext.setAddGuestPermissions(true);

      DDMStructureLocalServiceUtil.addStructure(
          webDavRequest.getUserId(),
          webDavRequest.getGroupId(),
          classNameId,
          nameMap,
          null,
          xsd,
          serviceContext);

      return HttpServletResponse.SC_CREATED;
    } else if (type.equals(TYPE_TEMPLATES)) {

      // DDM templates can not be added via WebDAV because there is no way
      // to know the associated class name or class PK

      return HttpServletResponse.SC_FORBIDDEN;
    }

    return HttpServletResponse.SC_FORBIDDEN;
  }
  protected List<Resource> getStructures(WebDAVRequest webDAVRequest) throws Exception {

    List<Resource> resources = new ArrayList<>();

    List<DDMStructure> ddmStructures =
        DDMStructureLocalServiceUtil.getStructures(
            webDAVRequest.getGroupId(), PortalUtil.getClassNameId(JournalArticle.class));

    for (DDMStructure ddmStructure : ddmStructures) {
      Resource resource =
          DDMWebDavUtil.toResource(webDAVRequest, ddmStructure, getRootPath(), true);

      resources.add(resource);
    }

    return resources;
  }
Exemplo n.º 20
0
  @Override
  public String getStructureId() {
    if (_ddmTemplate.getClassPK() == 0) {
      return null;
    }

    try {
      DDMStructure ddmStructure =
          DDMStructureLocalServiceUtil.getStructure(_ddmTemplate.getClassPK());

      return ddmStructure.getStructureKey();
    } catch (Exception e) {
      _log.error(e, e);
    }

    return null;
  }
Exemplo n.º 21
0
  @Override
  protected PortletPreferences doDeleteData(
      PortletDataContext portletDataContext,
      String portletId,
      PortletPreferences portletPreferences)
      throws Exception {

    if (portletDataContext.addPrimaryKey(DDMPortletDataHandler.class, "deleteData")) {

      return portletPreferences;
    }

    DDMTemplateLocalServiceUtil.deleteTemplates(portletDataContext.getScopeGroupId());

    DDMStructureLocalServiceUtil.deleteStructures(portletDataContext.getScopeGroupId());

    return portletPreferences;
  }
Exemplo n.º 22
0
  @Override
  public void setStructureId(String structureId) {
    if (Validator.isNull(structureId)) {
      _ddmTemplate.setClassPK(0);

      return;
    }

    try {
      DDMStructure ddmStructure =
          DDMStructureLocalServiceUtil.getStructure(
              getGroupId(), PortalUtil.getClassNameId(JournalArticle.class), structureId, true);

      _ddmTemplate.setClassPK(ddmStructure.getPrimaryKey());
    } catch (Exception e) {
      _log.error(e, e);
    }
  }
  protected void addFileEntryTypeAttributes(Document document, DLFileVersion dlFileVersion)
      throws PortalException {

    List<DLFileEntryMetadata> dlFileEntryMetadatas =
        DLFileEntryMetadataLocalServiceUtil.getFileVersionFileEntryMetadatas(
            dlFileVersion.getFileVersionId());

    for (DLFileEntryMetadata dlFileEntryMetadata : dlFileEntryMetadatas) {
      Fields fields = null;

      try {
        fields = StorageEngineUtil.getFields(dlFileEntryMetadata.getDDMStorageId());
      } catch (Exception e) {
      }

      if (fields != null) {
        DDMStructure ddmStructure =
            DDMStructureLocalServiceUtil.getStructure(dlFileEntryMetadata.getDDMStructureId());

        DDMIndexerUtil.addAttributes(document, ddmStructure, fields);
      }
    }
  }
Exemplo n.º 24
0
  @Override
  protected void doExportStagedModel(PortletDataContext portletDataContext, DDMStructure structure)
      throws Exception {

    Element structureElement = portletDataContext.getExportDataElement(structure);

    if (structure.getParentStructureId() != DDMStructureConstants.DEFAULT_PARENT_STRUCTURE_ID) {

      DDMStructure parentStructure =
          DDMStructureLocalServiceUtil.getStructure(structure.getParentStructureId());

      StagedModelDataHandlerUtil.exportReferenceStagedModel(
          portletDataContext, structure, parentStructure, PortletDataContext.REFERENCE_TYPE_PARENT);
    }

    long defaultUserId = UserLocalServiceUtil.getDefaultUserId(structure.getCompanyId());

    if (defaultUserId == structure.getUserId()) {
      structureElement.addAttribute("preloaded", "true");
    }

    portletDataContext.addClassedModel(
        structureElement, ExportImportPathUtil.getModelPath(structure), structure);
  }
  protected void exportImportJournalArticle(boolean companyScopeDependencies) throws Exception {

    JournalArticle article = null;
    DDMStructure ddmStructure = null;
    DDMTemplate ddmTemplate = null;

    long groupId = group.getGroupId();

    Company company = CompanyLocalServiceUtil.fetchCompany(group.getCompanyId());

    Group companyGroup = company.getGroup();

    if (companyScopeDependencies) {
      groupId = companyGroup.getGroupId();
    }

    ddmStructure = DDMStructureTestUtil.addStructure(groupId, JournalArticle.class.getName());

    ddmTemplate = DDMTemplateTestUtil.addTemplate(groupId, ddmStructure.getStructureId());

    String content = DDMStructureTestUtil.getSampleStructuredContent();

    article =
        JournalTestUtil.addArticleWithXMLContent(
            group.getGroupId(),
            content,
            ddmStructure.getStructureKey(),
            ddmTemplate.getTemplateKey());

    exportImportPortlet(PortletKeys.JOURNAL);

    int articlesCount = JournalArticleLocalServiceUtil.getArticlesCount(importedGroup.getGroupId());

    Assert.assertEquals(1, articlesCount);

    JournalArticle groupArticle =
        JournalArticleLocalServiceUtil.fetchJournalArticleByUuidAndGroupId(
            article.getUuid(), importedGroup.getGroupId());

    Assert.assertNotNull(groupArticle);

    groupId = importedGroup.getGroupId();

    if (companyScopeDependencies) {
      DDMStructure importedDDMStructure =
          DDMStructureLocalServiceUtil.fetchDDMStructureByUuidAndGroupId(
              ddmStructure.getUuid(), groupId);

      Assert.assertNull(importedDDMStructure);

      DDMTemplate importedDDMTemplate =
          DDMTemplateLocalServiceUtil.fetchDDMTemplateByUuidAndGroupId(
              ddmTemplate.getUuid(), groupId);

      Assert.assertNull(importedDDMTemplate);

      groupId = companyGroup.getGroupId();
    }

    DDMStructure dependentDDMStructure =
        DDMStructureLocalServiceUtil.fetchDDMStructureByUuidAndGroupId(
            ddmStructure.getUuid(), groupId);

    Assert.assertNotNull(dependentDDMStructure);

    DDMTemplate dependentDDMTemplate =
        DDMTemplateLocalServiceUtil.fetchDDMTemplateByUuidAndGroupId(
            ddmTemplate.getUuid(), groupId);

    Assert.assertNotNull(dependentDDMTemplate);
    Assert.assertEquals(article.getDDMStructureKey(), dependentDDMStructure.getStructureKey());
    Assert.assertEquals(article.getDDMTemplateKey(), dependentDDMTemplate.getTemplateKey());
    Assert.assertEquals(dependentDDMTemplate.getClassPK(), dependentDDMStructure.getStructureId());
  }
  @Override
  public void postProcessContextBooleanFilter(
      BooleanFilter contextBooleanFilter, SearchContext searchContext) throws Exception {

    addStatus(contextBooleanFilter, searchContext);

    if (searchContext.isIncludeAttachments()) {
      addRelatedClassNames(contextBooleanFilter, searchContext);
    }

    if (ArrayUtil.contains(
        searchContext.getFolderIds(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID)) {

      contextBooleanFilter.addRequiredTerm(Field.HIDDEN, searchContext.isIncludeAttachments());
    }

    addSearchClassTypeIds(contextBooleanFilter, searchContext);

    String ddmStructureFieldName = (String) searchContext.getAttribute("ddmStructureFieldName");
    Serializable ddmStructureFieldValue = searchContext.getAttribute("ddmStructureFieldValue");

    if (Validator.isNotNull(ddmStructureFieldName) && Validator.isNotNull(ddmStructureFieldValue)) {

      String[] ddmStructureFieldNameParts =
          StringUtil.split(ddmStructureFieldName, DDMIndexer.DDM_FIELD_SEPARATOR);

      DDMStructure structure =
          DDMStructureLocalServiceUtil.getStructure(
              GetterUtil.getLong(ddmStructureFieldNameParts[1]));

      String fieldName =
          StringUtil.replaceLast(
              ddmStructureFieldNameParts[2],
              StringPool.UNDERLINE.concat(LocaleUtil.toLanguageId(searchContext.getLocale())),
              StringPool.BLANK);

      try {
        ddmStructureFieldValue =
            DDMUtil.getIndexedFieldValue(ddmStructureFieldValue, structure.getFieldType(fieldName));
      } catch (StructureFieldException sfe) {
        if (_log.isDebugEnabled()) {
          _log.debug(sfe, sfe);
        }
      }

      BooleanQuery booleanQuery = new BooleanQueryImpl();

      booleanQuery.addRequiredTerm(
          ddmStructureFieldName, StringPool.QUOTE + ddmStructureFieldValue + StringPool.QUOTE);

      contextBooleanFilter.add(new QueryFilter(booleanQuery));
    }

    String[] mimeTypes = (String[]) searchContext.getAttribute("mimeTypes");

    if (ArrayUtil.isNotEmpty(mimeTypes)) {
      BooleanFilter mimeTypesBooleanFilter = new BooleanFilter();

      for (String mimeType : mimeTypes) {
        mimeTypesBooleanFilter.addTerm(
            "mimeType", StringUtil.replace(mimeType, CharPool.FORWARD_SLASH, CharPool.UNDERLINE));
      }

      contextBooleanFilter.add(mimeTypesBooleanFilter, BooleanClauseOccur.MUST);
    }
  }
 public DDMStructure getStructure() throws PortalException, SystemException {
   return DDMStructureLocalServiceUtil.getStructure(getStructureId());
 }
  @Override
  protected void doImportStagedModel(
      PortletDataContext portletDataContext, DLFileEntryType fileEntryType) throws Exception {

    long userId = portletDataContext.getUserId(fileEntryType.getUserUuid());

    StagedModelDataHandlerUtil.importReferenceStagedModels(
        portletDataContext, fileEntryType, DDMStructure.class);

    List<Element> ddmStructureReferenceElements =
        portletDataContext.getReferenceElements(fileEntryType, DDMStructure.class);

    long[] ddmStructureIdsArray = new long[ddmStructureReferenceElements.size()];

    Map<Long, Long> ddmStructureIds =
        (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(DDMStructure.class);

    for (int i = 0; i < ddmStructureReferenceElements.size(); i++) {
      Element ddmStructureReferenceElement = ddmStructureReferenceElements.get(i);

      long ddmStructureId =
          GetterUtil.getLong(ddmStructureReferenceElement.attributeValue("class-pk"));

      ddmStructureIdsArray[i] = MapUtil.getLong(ddmStructureIds, ddmStructureId);
    }

    ServiceContext serviceContext = portletDataContext.createServiceContext(fileEntryType);

    DLFileEntryType importedDLFileEntryType = null;

    Element element = portletDataContext.getImportDataStagedModelElement(fileEntryType);

    boolean preloaded = GetterUtil.getBoolean(element.attributeValue("preloaded"));

    if (portletDataContext.isDataStrategyMirror()) {
      DLFileEntryType existingDLFileEntryType =
          fetchExistingFileEntryType(
              fileEntryType.getUuid(),
              portletDataContext.getScopeGroupId(),
              fileEntryType.getFileEntryTypeKey(),
              preloaded);

      if (existingDLFileEntryType == null) {
        serviceContext.setUuid(fileEntryType.getUuid());

        importedDLFileEntryType =
            DLFileEntryTypeLocalServiceUtil.addFileEntryType(
                userId,
                portletDataContext.getScopeGroupId(),
                fileEntryType.getFileEntryTypeKey(),
                fileEntryType.getNameMap(),
                fileEntryType.getDescriptionMap(),
                ddmStructureIdsArray,
                serviceContext);
      } else {
        DLFileEntryTypeLocalServiceUtil.updateFileEntryType(
            userId,
            existingDLFileEntryType.getFileEntryTypeId(),
            fileEntryType.getNameMap(),
            fileEntryType.getDescriptionMap(),
            ddmStructureIdsArray,
            serviceContext);

        importedDLFileEntryType =
            DLFileEntryTypeLocalServiceUtil.fetchDLFileEntryType(
                existingDLFileEntryType.getFileEntryTypeId());
      }
    } else {
      importedDLFileEntryType =
          DLFileEntryTypeLocalServiceUtil.addFileEntryType(
              userId,
              portletDataContext.getScopeGroupId(),
              fileEntryType.getFileEntryTypeKey(),
              fileEntryType.getNameMap(),
              fileEntryType.getDescriptionMap(),
              ddmStructureIdsArray,
              serviceContext);
    }

    portletDataContext.importClassedModel(fileEntryType, importedDLFileEntryType);

    if (preloaded) {
      return;
    }

    String importedDLFileEntryDDMStructureKey = DLUtil.getDDMStructureKey(importedDLFileEntryType);

    List<DDMStructure> importedDDMStructures = importedDLFileEntryType.getDDMStructures();

    for (DDMStructure importedDDMStructure : importedDDMStructures) {
      String ddmStructureKey = importedDDMStructure.getStructureKey();

      if (!DLUtil.isAutoGeneratedDLFileEntryTypeDDMStructureKey(ddmStructureKey)) {

        continue;
      }

      if (ddmStructureKey.equals(importedDLFileEntryDDMStructureKey)) {
        continue;
      }

      importedDDMStructure.setStructureKey(importedDLFileEntryDDMStructureKey);

      DDMStructureLocalServiceUtil.updateDDMStructure(importedDDMStructure);
    }
  }
Exemplo n.º 29
0
  @Override
  protected void doImportStagedModel(PortletDataContext portletDataContext, DDMStructure structure)
      throws Exception {

    prepareLanguagesForImport(structure);

    long userId = portletDataContext.getUserId(structure.getUserUuid());

    if (structure.getParentStructureId() != DDMStructureConstants.DEFAULT_PARENT_STRUCTURE_ID) {

      StagedModelDataHandlerUtil.importReferenceStagedModel(
          portletDataContext, structure, DDMStructure.class, structure.getParentStructureId());
    }

    Map<Long, Long> structureIds =
        (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(DDMStructure.class);

    long parentStructureId =
        MapUtil.getLong(
            structureIds, structure.getParentStructureId(), structure.getParentStructureId());

    Map<String, String> structureKeys =
        (Map<String, String>)
            portletDataContext.getNewPrimaryKeysMap(DDMStructure.class + ".ddmStructureKey");

    ServiceContext serviceContext = portletDataContext.createServiceContext(structure);

    DDMStructure importedStructure = null;

    if (portletDataContext.isDataStrategyMirror()) {
      Element element = portletDataContext.getImportDataStagedModelElement(structure);

      boolean preloaded = GetterUtil.getBoolean(element.attributeValue("preloaded"));

      DDMStructure existingStructure =
          fetchExistingStructure(
              structure.getUuid(),
              portletDataContext.getScopeGroupId(),
              structure.getClassNameId(),
              structure.getStructureKey(),
              preloaded);

      if (existingStructure == null) {
        serviceContext.setUuid(structure.getUuid());

        importedStructure =
            DDMStructureLocalServiceUtil.addStructure(
                userId,
                portletDataContext.getScopeGroupId(),
                parentStructureId,
                structure.getClassNameId(),
                structure.getStructureKey(),
                structure.getNameMap(),
                structure.getDescriptionMap(),
                structure.getXsd(),
                structure.getStorageType(),
                structure.getType(),
                serviceContext);
      } else {
        importedStructure =
            DDMStructureLocalServiceUtil.updateStructure(
                existingStructure.getStructureId(), parentStructureId,
                structure.getNameMap(), structure.getDescriptionMap(),
                structure.getXsd(), serviceContext);
      }
    } else {
      importedStructure =
          DDMStructureLocalServiceUtil.addStructure(
              userId,
              portletDataContext.getScopeGroupId(),
              parentStructureId,
              structure.getClassNameId(),
              structure.getStructureKey(),
              structure.getNameMap(),
              structure.getDescriptionMap(),
              structure.getXsd(),
              structure.getStorageType(),
              structure.getType(),
              serviceContext);
    }

    portletDataContext.importClassedModel(structure, importedStructure);

    structureKeys.put(structure.getStructureKey(), importedStructure.getStructureKey());
  }
  public void postProcessContextQuery(BooleanQuery contextQuery, SearchContext searchContext)
      throws Exception {

    if (_log.isDebugEnabled()) {
      _log.debug(" postProcessContextQuery()");
    }

    Map<String, Object> params = (Map<String, Object>) searchContext.getAttribute("params");

    if (params == null) {
      return;
    }

    Map<String, Serializable> searchByFields =
        (Map<String, Serializable>) params.get(SampleConstants.STRUCTURE_FIELDS);

    String structureKey = (String) params.get(SampleConstants.STRUCTURE_KEY);

    Long groupId = (Long) params.get(SampleConstants.STRUCTURE_GROUP_ID);

    Locale locale = searchContext.getLocale();

    DDMStructure structure =
        DDMStructureLocalServiceUtil.fetchStructure(
            groupId, PortalUtil.getClassNameId(JournalArticle.class), structureKey, true);

    if (!isCustomSearch(structure, groupId, searchByFields)) {
      return;
    }

    for (String fieldName : searchByFields.keySet()) {
      try {
        Serializable value = searchByFields.get(fieldName);

        String indexType = structure.getFieldProperty(fieldName, "indexType");

        if (Validator.isNull(indexType)) {
          if (_log.isDebugEnabled()) {
            _log.debug("fieldName " + fieldName + " is not indexable");
          }

          continue;
        }

        // some types are stored in a special way

        try {
          value = DDMUtil.getIndexedFieldValue(value, structure.getFieldType(fieldName));
        } catch (StructureFieldException sfe) {
          _log.error(sfe);

          continue;
        }

        contextQuery.addRequiredTerm(
            DDMIndexerUtil.encodeName(structure.getStructureId(), fieldName, locale),
            StringPool.QUOTE + value + StringPool.QUOTE);
      } catch (Exception e) {
        _log.error("Error processing custom search", e);
      }
    }

    _log.debug(contextQuery);
  }