Exemplo n.º 1
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 definition = StringUtil.read(request.getInputStream());

      DDMForm ddmForm = getDDMForm(definition);

      DDMFormLayout ddmFormLayout = DDMUtil.getDefaultDDMFormLayout(ddmForm);

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

      Locale defaultLocale = ddmForm.getDefaultLocale();

      nameMap.put(defaultLocale, typeId);

      ServiceContext serviceContext = new ServiceContext();

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

      DDMStructureLocalServiceUtil.addStructure(
          webDavRequest.getUserId(),
          webDavRequest.getGroupId(),
          classNameId,
          nameMap,
          null,
          ddmForm,
          ddmFormLayout,
          StorageType.JSON.toString(),
          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;
  }
  @Override
  protected void updateDDMStructure(ServiceContext serviceContext) throws Exception {

    DDMForm ddmForm = DDMStructureTestUtil.getSampleDDMForm("title");

    DDMFormLayout ddmFormLayout = DDMUtil.getDefaultDDMFormLayout(ddmForm);

    DDMStructureLocalServiceUtil.updateStructure(
        _ddmStructure.getUserId(),
        _ddmStructure.getStructureId(),
        _ddmStructure.getParentStructureId(),
        _ddmStructure.getNameMap(),
        _ddmStructure.getDescriptionMap(),
        ddmForm,
        ddmFormLayout,
        serviceContext);
  }
Exemplo n.º 3
0
  public static int putResource(
      WebDAVRequest webDAVRequest, String rootPath, String token, long classNameId)
      throws WebDAVException {

    try {
      Resource resource = getResource(webDAVRequest, rootPath, token, classNameId);

      if (resource == null) {
        return addResource(webDAVRequest, classNameId);
      }

      Object model = resource.getModel();

      if (model instanceof DDMStructure) {
        DDMStructure structure = (DDMStructure) model;

        HttpServletRequest request = webDAVRequest.getHttpServletRequest();

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

        DDMForm ddmForm = getDDMForm(definition);

        DDMFormLayout ddmFormLayout = DDMUtil.getDefaultDDMFormLayout(ddmForm);

        DDMStructureServiceUtil.updateStructure(
            structure.getGroupId(),
            structure.getParentStructureId(),
            structure.getClassNameId(),
            structure.getStructureKey(),
            structure.getNameMap(),
            structure.getDescriptionMap(),
            ddmForm,
            ddmFormLayout,
            new ServiceContext());

        return HttpServletResponse.SC_CREATED;
      } else if (model instanceof DDMTemplate) {
        DDMTemplate template = (DDMTemplate) model;

        HttpServletRequest request = webDAVRequest.getHttpServletRequest();

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

        DDMTemplateServiceUtil.updateTemplate(
            template.getTemplateId(),
            template.getClassPK(),
            template.getNameMap(),
            template.getDescriptionMap(),
            template.getType(),
            template.getMode(),
            template.getLanguage(),
            script,
            template.isCacheable(),
            template.isSmallImage(),
            template.getSmallImageURL(),
            null,
            new ServiceContext());

        return HttpServletResponse.SC_CREATED;
      } else {
        return HttpServletResponse.SC_FORBIDDEN;
      }
    } catch (PortalException pe) {
      if (_log.isDebugEnabled()) {
        _log.debug(pe, pe);
      }

      return HttpServletResponse.SC_FORBIDDEN;
    } catch (Exception e) {
      throw new WebDAVException(e);
    }
  }