コード例 #1
0
  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);
    }
  }
コード例 #2
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;
  }
コード例 #3
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());
  }