Пример #1
0
 /** @todo DRY! Perhaps we should merge this with the older updateContentIndexTime method. */
 public DvObject updatePermissionIndexTime(DvObject dvObject) {
   /**
    * @todo to avoid a possible OptimisticLockException, should we merge dvObject before we try to
    *     set this timestamp? See
    *     https://github.com/IQSS/dataverse/commit/6ad0ebb272c8cb46368cb76784b55dbf33eea947
    */
   DvObject dvObjectToModify = findDvObject(dvObject.getId());
   dvObjectToModify.setPermissionIndexTime(new Timestamp(new Date().getTime()));
   DvObject savedDvObject = em.merge(dvObjectToModify);
   return savedDvObject;
 }
  public Set<RoleAssignment> rolesAssignments(DvObject dv) {
    Set<RoleAssignment> ras = new HashSet<>();
    while (!dv.isEffectivelyPermissionRoot()) {
      ras.addAll(
          em.createNamedQuery("RoleAssignment.listByDefinitionPointId", RoleAssignment.class)
              .setParameter("definitionPointId", dv.getId())
              .getResultList());
      dv = dv.getOwner();
    }

    ras.addAll(
        em.createNamedQuery("RoleAssignment.listByDefinitionPointId", RoleAssignment.class)
            .setParameter("definitionPointId", dv.getId())
            .getResultList());

    return ras;
  }
 /**
  * Retrieves the roles assignments for {@code user}, directly on {@code dv}. No traversal on the
  * containment hierarchy is done.
  *
  * @param roas the user whose roles are given
  * @param dvo the object where the roles are defined.
  * @return Set of roles defined for the user in the given dataverse.
  * @see #roleAssignments(edu.harvard.iq.dataverse.DataverseUser,
  *     edu.harvard.iq.dataverse.Dataverse)
  */
 public List<RoleAssignment> directRoleAssignments(RoleAssignee roas, DvObject dvo) {
   if (roas == null) throw new IllegalArgumentException("RoleAssignee cannot be null");
   TypedQuery<RoleAssignment> query =
       em.createNamedQuery(
           "RoleAssignment.listByAssigneeIdentifier_DefinitionPointId", RoleAssignment.class);
   query.setParameter("assigneeIdentifier", roas.getIdentifier());
   query.setParameter("definitionPointId", dvo.getId());
   return query.getResultList();
 }
 public void revoke(Set<DataverseRole> roles, RoleAssignee assignee, DvObject defPoint) {
   for (DataverseRole role : roles) {
     em.createNamedQuery("RoleAssignment.deleteByAssigneeIdentifier_RoleIdDefinition_PointId")
         .setParameter("assigneeIdentifier", assignee.getIdentifier())
         .setParameter("roleId", role.getId())
         .setParameter("definitionPointId", defPoint.getId())
         .executeUpdate();
     em.refresh(role);
   }
   em.refresh(assignee);
 }
  public RoleAssignmentSet assignmentsFor(final User u, final DvObject d) {
    return d.accept(
        new DvObject.Visitor<RoleAssignmentSet>() {

          @Override
          public RoleAssignmentSet visit(Dataverse dv) {
            return roleAssignments(u, dv);
          }

          @Override
          public RoleAssignmentSet visit(Dataset ds) {
            RoleAssignmentSet asgn = ds.getOwner().accept(this);
            asgn.add(directRoleAssignments(u, ds));
            return asgn;
          }

          @Override
          public RoleAssignmentSet visit(DataFile df) {
            RoleAssignmentSet asgn = df.getOwner().accept(this);
            asgn.add(directRoleAssignments(u, df));
            return asgn;
          }
        });
  }
 /**
  * Retrieves the roles assignments for {@code user}, directly on {@code dv}. No traversal on the
  * containment hierarchy is done.
  *
  * @param dvo the object where the roles are defined.
  * @return Set of roles defined for the user in the given dataverse.
  * @see #roleAssignments(edu.harvard.iq.dataverse.DataverseUser,
  *     edu.harvard.iq.dataverse.Dataverse)
  */
 public List<RoleAssignment> directRoleAssignments(DvObject dvo) {
   TypedQuery<RoleAssignment> query =
       em.createNamedQuery("RoleAssignment.listByDefinitionPointId", RoleAssignment.class);
   query.setParameter("definitionPointId", dvo.getId());
   return query.getResultList();
 }