Example #1
0
  public ArrayList<History> getHistory(String userId, long entryId) {
    Entry entry = dao.get(entryId);
    if (entry == null) return null;

    authorization.expectWrite(userId, entry);
    List<Audit> list = auditDAO.getAuditsForEntry(entry);
    ArrayList<History> result = new ArrayList<>();
    for (Audit audit : list) {
      History history = audit.toDataTransferObject();
      if (history.isLocalUser()) {
        history.setAccount(
            accountController.getByEmail(history.getUserId()).toDataTransferObject());
      }
      result.add(history);
    }
    return result;
  }
Example #2
0
  private Audit auditRelationshipHelper(
      Audit audit,
      AuditAction action,
      Vertex sourceVertex,
      Vertex destVertex,
      String label,
      String process,
      String comment,
      User user,
      Visibility visibility) {
    visibility = orVisibility(visibility);
    audit
        .getAuditCommon()
        .setUser(user, visibility)
        .setAction(action, visibility)
        .setType(OntologyRepository.TYPE_RELATIONSHIP, visibility)
        .setComment(comment, visibility)
        .setProcess(process, visibility)
        .setUnixBuildTime(
            versionService.getUnixBuildTime() != null ? versionService.getUnixBuildTime() : -1L,
            visibility)
        .setScmBuildNumber(
            versionService.getScmBuildNumber() != null ? versionService.getScmBuildNumber() : "",
            visibility)
        .setVersion(
            versionService.getVersion() != null ? versionService.getVersion() : "", visibility);

    audit
        .getAuditRelationship()
        .setSourceId(sourceVertex.getId(), visibility)
        .setSourceType(CONCEPT_TYPE.getPropertyValue(sourceVertex), visibility)
        .setSourceTitle(TITLE.getPropertyValue(sourceVertex), visibility)
        .setDestId(destVertex.getId(), visibility)
        .setDestTitle(TITLE.getPropertyValue(destVertex), visibility)
        .setDestType(CONCEPT_TYPE.getPropertyValue(destVertex), visibility)
        .setLabel(label, visibility);
    return audit;
  }
Example #3
0
  public Audit auditVertex(
      AuditAction auditAction,
      Object vertexId,
      String process,
      String comment,
      User user,
      FlushFlag flushFlag,
      Visibility visibility) {
    checkNotNull(vertexId, "vertexId cannot be null");
    checkNotNull(comment, "comment cannot be null");
    checkNotNull(user, "user cannot be null");
    checkNotNull(process, "process cannot be null");

    Audit audit = new Audit(AuditRowKey.build(vertexId));
    visibility = orVisibility(visibility);
    audit
        .getAuditCommon()
        .setUser(user, visibility)
        .setAction(auditAction, visibility)
        .setType(OntologyRepository.ENTITY_CONCEPT_IRI, visibility)
        .setComment(comment, visibility)
        .setUnixBuildTime(
            versionService.getUnixBuildTime() != null ? versionService.getUnixBuildTime() : -1L,
            visibility)
        .setScmBuildNumber(
            versionService.getScmBuildNumber() != null ? versionService.getScmBuildNumber() : "",
            visibility)
        .setVersion(
            versionService.getVersion() != null ? versionService.getVersion() : "", visibility);

    if (process.length() > 0) {
      audit.getAuditCommon().setProcess(process, visibility);
    }

    save(audit, flushFlag);
    return audit;
  }
Example #4
0
  protected PartData retrieveEntryDetails(String userId, Entry entry) {
    // user must be able to read if not public entry
    if (!permissionsController.isPubliclyVisible(entry)) authorization.expectRead(userId, entry);

    PartData partData = ModelToInfoFactory.getInfo(entry);
    if (partData == null) return null;
    boolean hasSequence = sequenceDAO.hasSequence(entry.getId());

    partData.setHasSequence(hasSequence);
    boolean hasOriginalSequence = sequenceDAO.hasOriginalSequence(entry.getId());
    partData.setHasOriginalSequence(hasOriginalSequence);

    // permissions
    partData.setCanEdit(authorization.canWriteThoroughCheck(userId, entry));
    partData.setPublicRead(permissionsController.isPubliclyVisible(entry));

    // create audit event if not owner
    // todo : remote access check
    if (userId != null
        && authorization.getOwner(entry) != null
        && !authorization.getOwner(entry).equalsIgnoreCase(userId)) {
      try {
        Audit audit = new Audit();
        audit.setAction(AuditType.READ.getAbbrev());
        audit.setEntry(entry);
        audit.setUserId(userId);
        audit.setLocalUser(true);
        audit.setTime(new Date(System.currentTimeMillis()));
        auditDAO.create(audit);
      } catch (Exception e) {
        Logger.error(e);
      }
    }

    // retrieve more information about linked entries if any (default only contains id)
    if (partData.getLinkedParts() != null) {
      ArrayList<PartData> newLinks = new ArrayList<>();
      for (PartData link : partData.getLinkedParts()) {
        Entry linkedEntry = dao.get(link.getId());
        if (!authorization.canRead(userId, linkedEntry)) continue;

        link = ModelToInfoFactory.createTipView(linkedEntry);
        Sequence sequence = sequenceDAO.getByEntry(linkedEntry);
        if (sequence != null) {
          link.setBasePairCount(sequence.getSequence().length());
          link.setFeatureCount(sequence.getSequenceFeatures().size());
        }

        newLinks.add(link);
      }
      partData.getLinkedParts().clear();
      partData.getLinkedParts().addAll(newLinks);
    }

    // check if there is a parent available
    List<Entry> parents = dao.getParents(entry.getId());
    if (parents == null) return partData;

    for (Entry parent : parents) {
      if (!authorization.canRead(userId, parent)) continue;

      if (parent.getVisibility() != Visibility.OK.getValue()
          && !authorization.canWriteThoroughCheck(userId, entry)) continue;

      EntryType type = EntryType.nameToType(parent.getRecordType());
      PartData parentData = new PartData(type);
      parentData.setId(parent.getId());
      parentData.setName(parent.getName());
      parentData.setVisibility(Visibility.valueToEnum(parent.getVisibility()));
      partData.getParents().add(parentData);
    }

    return partData;
  }
  /**
   * Called by the main class to initialize defaults.
   *
   * @param projectName the project name
   * @param username the authenticated username
   * @exception PersisterException if an error occurs
   */
  public void initParams(String projectName, String username) throws PersisterException {

    audit = DomainObjectFactory.newAudit();
    audit.setCreatedBy(username);

    this.projectName = projectName;

    // !!!! TODO Use version Too
    LoaderDefault loaderDefault = loaderDAO.findByName(projectName);

    if (loaderDefault == null) {
      throw new PersisterException("Defaults not found. Please create a profile first.");
    }

    String cName = loaderDefault.getContextName();

    if (cName == null) {
      throw new PersisterException("Context Name not Set.");
    }

    context = contextDAO.findByName(cName);

    if (context == null) {
      throw new PersisterException("Context: " + cName + " not found.");
    }

    version = new Float(loaderDefault.getVersion().toString());
    projectVersion = loaderDefault.getProjectVersion().toString();

    workflowStatus = loaderDefault.getWorkflowStatus();

    if (workflowStatus == null) {
      throw new PersisterException("WorkflowStatus not Set.");
    }

    conceptualDomain = DomainObjectFactory.newConceptualDomain();
    conceptualDomain.setPreferredName(loaderDefault.getCdName());

    Context cdContext = contextDAO.findByName(loaderDefault.getCdContextName());

    if (cdContext == null) {
      throw new PersisterException("CD Context not found.");
    }

    conceptualDomain.setContext(cdContext);

    try {
      conceptualDomain = (ConceptualDomain) conceptualDomainDAO.find(conceptualDomain).get(0);
    } catch (NullPointerException e) {
      throw new PersisterException("CD: " + conceptualDomain.getPreferredName() + " not found.");
    }

    logger.info("List of packages that will be processed:");
    String[] pkgs = loaderDefault.getPackageFilter().split(",");
    for (int i = 0; i < pkgs.length; i++) {
      String s = pkgs[i].trim();
      int ind = s.indexOf(">");

      String alias = null;
      String pkg = null;
      if (ind > 0) {
        alias = s.substring(1, ind).trim();
        pkg = s.substring(ind + 1).trim();
      } else {
        alias = pkg = s;
      }

      packageFilter.put(pkg, alias);
      logger.info("Package: " + pkg + " -- Alias: " + alias);
    }
    logger.info("End of package list.");
  }
Example #6
0
  public List<Audit> auditRelationshipProperty(
      AuditAction action,
      String sourceId,
      String destId,
      String propertyName,
      Object oldValue,
      Object newValue,
      Edge edge,
      String process,
      String comment,
      User user,
      Visibility visibility) {
    checkNotNull(action, "action cannot be null");
    checkNotNull(sourceId, "sourceId cannot be null");
    checkNotNull(sourceId.length() > 0, "sourceId cannot be empty");
    checkNotNull(destId, "destId cannot be null");
    checkNotNull(destId.length() > 0, "destId cannot be empty");
    checkNotNull(propertyName, "propertyName cannot be null");
    checkNotNull(propertyName.length() > 0, "propertyName cannot be empty");
    checkNotNull(edge, "edge cannot be null");
    checkNotNull(process, "process cannot be null");
    checkNotNull(comment, "comment cannot be null");
    checkNotNull(user, "user cannot be null");

    Audit auditSourceDest = new Audit(AuditRowKey.build(sourceId, destId));
    Audit auditDestSource = new Audit(AuditRowKey.build(destId, sourceId));
    Audit auditEdge = new Audit(AuditRowKey.build(edge.getId()));
    visibility = orVisibility(visibility);

    auditSourceDest
        .getAuditCommon()
        .setUser(user, visibility)
        .setAction(action, visibility)
        .setType(OntologyRepository.TYPE_PROPERTY, visibility)
        .setComment(comment, visibility)
        .setProcess(process, visibility)
        .setUnixBuildTime(
            versionService.getUnixBuildTime() != null ? versionService.getUnixBuildTime() : -1L,
            visibility)
        .setScmBuildNumber(
            versionService.getScmBuildNumber() != null ? versionService.getScmBuildNumber() : "",
            visibility)
        .setVersion(
            versionService.getVersion() != null ? versionService.getVersion() : "", visibility);

    auditDestSource
        .getAuditCommon()
        .setUser(user, visibility)
        .setAction(action, visibility)
        .setType(OntologyRepository.TYPE_PROPERTY, visibility)
        .setComment(comment, visibility)
        .setProcess(process, visibility)
        .setUnixBuildTime(
            versionService.getUnixBuildTime() != null ? versionService.getUnixBuildTime() : -1L,
            visibility)
        .setScmBuildNumber(
            versionService.getScmBuildNumber() != null ? versionService.getScmBuildNumber() : "",
            visibility)
        .setVersion(
            versionService.getVersion() != null ? versionService.getVersion() : "", visibility);

    auditEdge
        .getAuditCommon()
        .setUser(user, visibility)
        .setAction(action, visibility)
        .setType(OntologyRepository.TYPE_PROPERTY, visibility)
        .setComment(comment, visibility)
        .setProcess(process, visibility)
        .setUnixBuildTime(
            versionService.getUnixBuildTime() != null ? versionService.getUnixBuildTime() : -1L,
            visibility)
        .setScmBuildNumber(
            versionService.getScmBuildNumber() != null ? versionService.getScmBuildNumber() : "",
            visibility)
        .setVersion(
            versionService.getVersion() != null ? versionService.getVersion() : "", visibility);

    if (oldValue != null && !oldValue.equals("")) {
      auditDestSource.getAuditProperty().setPreviousValue(oldValue, visibility);
      auditSourceDest.getAuditProperty().setPreviousValue(oldValue, visibility);
      auditEdge.getAuditProperty().setPreviousValue(oldValue, visibility);
    }
    if (action == AuditAction.DELETE) {
      auditDestSource.getAuditProperty().setNewValue("", visibility);
      auditSourceDest.getAuditProperty().setNewValue("", visibility);
      auditEdge.getAuditProperty().setNewValue("", visibility);
    } else {
      // TODO handle multi-valued properties
      auditDestSource.getAuditProperty().setNewValue(newValue, visibility);
      auditSourceDest.getAuditProperty().setNewValue(newValue, visibility);
      auditEdge.getAuditProperty().setNewValue(newValue, visibility);
    }
    auditDestSource.getAuditProperty().setPropertyName(propertyName, visibility);
    auditSourceDest.getAuditProperty().setPropertyName(propertyName, visibility);
    auditEdge.getAuditProperty().setPropertyName(propertyName, visibility);

    List<Audit> audits = Lists.newArrayList(auditSourceDest, auditDestSource);
    saveMany(audits);
    return audits;
  }
Example #7
0
  public List<Audit> auditRelationship(
      AuditAction action,
      Vertex sourceVertex,
      Vertex destVertex,
      Edge edge,
      String process,
      String comment,
      User user,
      Visibility visibility) {
    checkNotNull(action, "action cannot be null");
    checkNotNull(sourceVertex, "sourceVertex cannot be null");
    checkNotNull(destVertex, "destVertex cannot be null");
    checkNotNull(edge, "edge cannot be null");
    checkNotNull(process, "process cannot be null");
    checkNotNull(comment, "comment cannot be null");
    checkNotNull(user, "user cannot be null");

    Audit auditSourceDest = new Audit(AuditRowKey.build(sourceVertex.getId(), destVertex.getId()));
    Audit auditDestSource = new Audit(AuditRowKey.build(destVertex.getId(), sourceVertex.getId()));
    Audit auditEdge = new Audit(AuditRowKey.build(edge.getId()));
    visibility = orVisibility(visibility);

    List<Audit> audits = new ArrayList<Audit>();
    String displayLabel = ontologyRepository.getDisplayNameForLabel(edge.getLabel());
    audits.add(
        auditRelationshipHelper(
            auditSourceDest,
            action,
            sourceVertex,
            destVertex,
            displayLabel,
            process,
            comment,
            user,
            visibility));
    audits.add(
        auditRelationshipHelper(
            auditDestSource,
            action,
            sourceVertex,
            destVertex,
            displayLabel,
            process,
            comment,
            user,
            visibility));
    auditEdge
        .getAuditCommon()
        .setUser(user, visibility)
        .setAction(action, visibility)
        .setType(OntologyRepository.TYPE_RELATIONSHIP, visibility)
        .setComment(comment, visibility)
        .setProcess(process, visibility)
        .setUnixBuildTime(
            versionService.getUnixBuildTime() != null ? versionService.getUnixBuildTime() : -1L,
            visibility)
        .setScmBuildNumber(
            versionService.getScmBuildNumber() != null ? versionService.getScmBuildNumber() : "",
            visibility)
        .setVersion(
            versionService.getVersion() != null ? versionService.getVersion() : "", visibility);

    auditEdge
        .getAuditRelationship()
        .setSourceId(sourceVertex.getId(), visibility)
        .setSourceType(CONCEPT_TYPE.getPropertyValue(sourceVertex), visibility)
        .setSourceTitle(TITLE.getPropertyValue(sourceVertex), visibility)
        .setDestId(destVertex.getId(), visibility)
        .setDestTitle(TITLE.getPropertyValue(destVertex), visibility)
        .setDestType(CONCEPT_TYPE.getPropertyValue(destVertex), visibility)
        .setLabel(displayLabel, visibility);

    audits.add(auditEdge);

    saveMany(audits);
    return audits;
  }
Example #8
0
  public Audit auditEntityProperty(
      AuditAction action,
      Object id,
      String propertyName,
      Object oldValue,
      Object newValue,
      String process,
      String comment,
      Map<String, Object> metadata,
      User user,
      Visibility visibility) {
    checkNotNull(action, "action cannot be null");
    checkNotNull(id, "id cannot be null");
    checkNotNull(propertyName, "propertyName cannot be null");
    checkArgument(propertyName.length() > 0, "property name cannot be empty");
    checkNotNull(process, "process cannot be null");
    checkNotNull(comment, "comment cannot be null");
    checkNotNull(user, "user cannot be null");

    Audit audit = new Audit(AuditRowKey.build(id));
    visibility = orVisibility(visibility);

    audit
        .getAuditCommon()
        .setUser(user, visibility)
        .setAction(action, visibility)
        .setType(OntologyRepository.TYPE_PROPERTY, visibility)
        .setComment(comment, visibility)
        .setProcess(process, visibility)
        .setUnixBuildTime(
            versionService.getUnixBuildTime() != null ? versionService.getUnixBuildTime() : -1L,
            visibility)
        .setScmBuildNumber(
            versionService.getScmBuildNumber() != null ? versionService.getScmBuildNumber() : "",
            visibility)
        .setVersion(
            versionService.getVersion() != null ? versionService.getVersion() : "", visibility);

    if (oldValue != null) {
      if (oldValue instanceof GeoPoint) {
        String val =
            String.format(
                "POINT(%f,%f)",
                ((GeoPoint) oldValue).getLatitude(), ((GeoPoint) oldValue).getLongitude());
        audit.getAuditProperty().setPreviousValue(val, visibility);
      } else {
        audit.getAuditProperty().setPreviousValue(oldValue.toString(), visibility);
      }
    }
    if (action == AuditAction.DELETE) {
      audit.getAuditProperty().setNewValue("", visibility);
    } else {
      if (newValue instanceof GeoPoint) {
        String val =
            String.format(
                "POINT(%f,%f)",
                ((GeoPoint) newValue).getLatitude(), ((GeoPoint) newValue).getLongitude());
        audit.getAuditProperty().setNewValue(val, visibility);
      } else {
        audit.getAuditProperty().setNewValue(newValue.toString(), visibility);
      }
    }
    audit.getAuditProperty().setPropertyName(propertyName, visibility);

    if (metadata != null || !metadata.isEmpty()) {
      audit.getAuditProperty().setPropertyMetadata(jsonMetadata(metadata).toString(), visibility);
    }

    save(audit);
    return audit;
  }