public void addExpando(Element element, String path, ClassedModel classedModel)
      throws PortalException, SystemException {

    Class<?> clazz = classedModel.getModelClass();

    String className = clazz.getName();

    if (!_expandoColumnsMap.containsKey(className)) {
      List<ExpandoColumn> expandoColumns =
          ExpandoColumnLocalServiceUtil.getDefaultTableColumns(_companyId, className);

      for (ExpandoColumn expandoColumn : expandoColumns) {
        addPermissions(ExpandoColumn.class, expandoColumn.getColumnId());
      }

      _expandoColumnsMap.put(className, expandoColumns);
    }

    ExpandoBridge expandoBridge = classedModel.getExpandoBridge();

    Map<String, Serializable> expandoBridgeAttributes = expandoBridge.getAttributes();

    if (!expandoBridgeAttributes.isEmpty()) {
      String expandoPath = getExpandoPath(path);

      element.addAttribute("expando-path", expandoPath);

      addZipEntry(expandoPath, expandoBridgeAttributes);
    }
  }
  protected boolean isValid(MethodInvocation methodInvocation, int phase) {
    Method method = methodInvocation.getMethod();

    Class<?>[] parameterTypes = method.getParameterTypes();

    if (parameterTypes.length == 0) {
      if (_log.isDebugEnabled() && (phase == _PHASE_BEFORE)) {
        _log.debug("The method " + methodInvocation + " must have at least one parameter");
      }

      return false;
    }

    Class<?> parameterType = parameterTypes[0];

    if (!ClassedModel.class.isAssignableFrom(parameterType)) {
      if (_log.isDebugEnabled() && (phase == _PHASE_BEFORE)) {
        _log.debug("The first parameter of " + methodInvocation + " must implement ClassedModel");
      }

      return false;
    }

    Object[] arguments = methodInvocation.getArguments();

    ClassedModel classedModel = (ClassedModel) arguments[0];

    if ((classedModel == null) || !(classedModel.getPrimaryKeyObj() instanceof Long)) {

      if (_log.isDebugEnabled() && (phase == _PHASE_BEFORE)) {
        _log.debug("The first parameter of " + methodInvocation + " must be a long");
      }

      return false;
    }

    if (phase != _PHASE_AFTER_RETURNING) {
      return true;
    }

    if (!AuditedModel.class.isAssignableFrom(parameterType)
        && !GroupedModel.class.isAssignableFrom(parameterType)
        && !StagedModel.class.isAssignableFrom(parameterType)) {

      if (_log.isDebugEnabled()) {
        StringBundler sb = new StringBundler(4);

        sb.append("If send is true, the first parameter of ");
        sb.append(methodInvocation);
        sb.append(" must implement AuditedModel, GroupedModel, or ");
        sb.append("StagedModel");

        _log.debug(sb.toString());
      }

      return false;
    }

    return true;
  }
  private static <T extends StagedModel> StagedModelDataHandler<T> _getStagedModelDataHandler(
      T stagedModel) {

    ClassedModel classedModel = stagedModel;

    StagedModelDataHandler<T> stagedModelDataHandler =
        (StagedModelDataHandler<T>)
            StagedModelDataHandlerRegistryUtil.getStagedModelDataHandler(
                classedModel.getModelClassName());

    return stagedModelDataHandler;
  }
  public void importClassedModel(
      ClassedModel classedModel, ClassedModel newClassedModel, String namespace)
      throws PortalException, SystemException {

    if (!isResourceMain(classedModel)) {
      return;
    }

    Class<?> clazz = classedModel.getModelClass();
    long classPK = getClassPK(classedModel);

    long newClassPK = getClassPK(newClassedModel);

    Map<Long, Long> newPrimaryKeysMap = (Map<Long, Long>) getNewPrimaryKeysMap(clazz);

    newPrimaryKeysMap.put(classPK, newClassPK);

    importLocks(clazz, String.valueOf(classPK), String.valueOf(newClassPK));
    importPermissions(clazz, classPK, newClassPK);

    boolean portletMetadataAll =
        getBooleanParameter(namespace, PortletDataHandlerKeys.PORTLET_METADATA_ALL);

    if (portletMetadataAll || getBooleanParameter(namespace, "comments")) {
      importComments(clazz, classPK, newClassPK, getScopeGroupId());
    }

    if (portletMetadataAll || getBooleanParameter(namespace, "ratings")) {
      importRatingsEntries(clazz, classPK, newClassPK);
    }
  }
  protected long getClassPK(ClassedModel classedModel) {
    if (classedModel instanceof ResourcedModel) {
      ResourcedModel resourcedModel = (ResourcedModel) classedModel;

      return resourcedModel.getResourcePrimKey();
    } else {
      return (Long) classedModel.getPrimaryKeyObj();
    }
  }
  protected long getClassPK(ClassedModel classedModel) {
    Serializable primaryKeyObj = classedModel.getPrimaryKeyObj();

    if (!(primaryKeyObj instanceof Long)) {
      return 0;
    }

    return (Long) primaryKeyObj;
  }
  @Override
  protected BaseModel<?> moveBaseModelFromTrash(
      ClassedModel classedModel, Group group, ServiceContext serviceContext) throws Exception {

    BaseModel<?> parentBaseModel = getParentBaseModel(group, serviceContext);

    DLAppServiceUtil.moveFileShortcutFromTrash(
        (Long) classedModel.getPrimaryKeyObj(),
        (Long) parentBaseModel.getPrimaryKeyObj(),
        serviceContext);

    return parentBaseModel;
  }
  protected String getClassName(ClassedModel classedModel) {
    String className = classedModel.getModelClassName();

    if (classedModel instanceof StagedModel) {
      StagedModel stagedModel = (StagedModel) classedModel;

      StagedModelType stagedModelType = stagedModel.getStagedModelType();

      className = stagedModelType.getClassName();
    }

    return className;
  }
  public void addClassedModel(
      Element element, String path, ClassedModel classedModel, String namespace)
      throws PortalException, SystemException {

    element.addAttribute("path", path);

    if (classedModel instanceof AuditedModel) {
      AuditedModel auditedModel = (AuditedModel) classedModel;

      auditedModel.setUserUuid(auditedModel.getUserUuid());
    }

    if (isResourceMain(classedModel)) {
      Class<?> clazz = classedModel.getModelClass();
      long classPK = getClassPK(classedModel);

      addAssetLinks(clazz, classPK);
      addExpando(element, path, classedModel);
      addLocks(clazz, String.valueOf(classPK));
      addPermissions(clazz, classPK);

      boolean portletMetadataAll =
          getBooleanParameter(namespace, PortletDataHandlerKeys.PORTLET_METADATA_ALL);

      if (portletMetadataAll || getBooleanParameter(namespace, "categories")) {

        addAssetCategories(clazz, classPK);
      }

      if (portletMetadataAll || getBooleanParameter(namespace, "comments")) {

        addComments(clazz, classPK);
      }

      if (portletMetadataAll || getBooleanParameter(namespace, "ratings")) {

        addRatingsEntries(clazz, classPK);
      }

      if (portletMetadataAll || getBooleanParameter(namespace, "tags")) {
        addAssetTags(clazz, classPK);
      }
    }

    addZipEntry(path, classedModel);
  }
  protected String getUuid(ClassedModel classedModel) throws Exception {
    if (classedModel instanceof StagedModel) {
      StagedModel stagedModel = (StagedModel) classedModel;

      return stagedModel.getUuid();
    }

    Method getUuidMethod = null;

    try {
      Class<?> modelClass = classedModel.getClass();

      getUuidMethod = modelClass.getMethod("getUuid", new Class[0]);
    } catch (Exception e) {
      return StringPool.BLANK;
    }

    return (String) getUuidMethod.invoke(classedModel, new Object[0]);
  }
Пример #11
0
 protected Long getBaseModelClassPK(ClassedModel classedModel) {
   return (Long) classedModel.getPrimaryKeyObj();
 }
  protected ServiceContext createServiceContext(
      Element element, String path, ClassedModel classedModel, String namespace) {

    Class<?> clazz = classedModel.getModelClass();
    long classPK = getClassPK(classedModel);

    ServiceContext serviceContext = new ServiceContext();

    // Theme display

    serviceContext.setCompanyId(getCompanyId());
    serviceContext.setScopeGroupId(getScopeGroupId());

    // Dates

    if (classedModel instanceof AuditedModel) {
      AuditedModel auditedModel = (AuditedModel) classedModel;

      serviceContext.setCreateDate(auditedModel.getCreateDate());
      serviceContext.setModifiedDate(auditedModel.getModifiedDate());
    }

    // Permissions

    if (!MapUtil.getBoolean(_parameterMap, PortletDataHandlerKeys.PERMISSIONS)) {

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

    // Asset

    boolean portletMetadataAll =
        getBooleanParameter(namespace, PortletDataHandlerKeys.PORTLET_METADATA_ALL);

    if (isResourceMain(classedModel)) {
      if (portletMetadataAll || getBooleanParameter(namespace, "categories")) {

        long[] assetCategoryIds = getAssetCategoryIds(clazz, classPK);

        serviceContext.setAssetCategoryIds(assetCategoryIds);
      }

      if (portletMetadataAll || getBooleanParameter(namespace, "tags")) {
        String[] assetTagNames = getAssetTagNames(clazz, classPK);

        serviceContext.setAssetTagNames(assetTagNames);
      }
    }

    // Expando

    String expandoPath = null;

    if (element != null) {
      expandoPath = element.attributeValue("expando-path");
    } else {
      expandoPath = getExpandoPath(path);
    }

    if (Validator.isNotNull(expandoPath)) {
      try {
        Map<String, Serializable> expandoBridgeAttributes =
            (Map<String, Serializable>) getZipEntryAsObject(expandoPath);

        serviceContext.setExpandoBridgeAttributes(expandoBridgeAttributes);
      } catch (Exception e) {
        if (_log.isDebugEnabled()) {
          _log.debug(e, e);
        }
      }
    }

    return serviceContext;
  }