Exemple #1
0
 @JsonIgnore
 public ManyMap<String, Attachment> getAttachmentMap() {
   ManyMap<String, Attachment> map = new ManyMap<String, Attachment>();
   if (attachments != null && !attachments.isEmpty()) {
     for (Attachment attachment : attachments) {
       map.putOne(attachment.getName(), attachment);
     }
   }
   return map;
 }
 public SequencingAnalysis copy() {
   SequencingAnalysis dst = new SequencingAnalysis();
   dst.subject = subject == null ? null : subject.copy();
   dst.date = date == null ? null : date.copy();
   dst.name = name == null ? null : name.copy();
   dst.genome = genome == null ? null : genome.copy(dst);
   dst.file = new ArrayList<Attachment>();
   for (Attachment i : file) dst.file.add(i.copy());
   dst.inputLab = new ArrayList<ResourceReference>();
   for (ResourceReference i : inputLab) dst.inputLab.add(i.copy());
   dst.inputAnalysis = new ArrayList<ResourceReference>();
   for (ResourceReference i : inputAnalysis) dst.inputAnalysis.add(i.copy());
   return dst;
 }
 public RelatedPerson copy() {
   RelatedPerson dst = new RelatedPerson();
   dst.identifier = new ArrayList<Identifier>();
   for (Identifier i : identifier) dst.identifier.add(i.copy());
   dst.patient = patient == null ? null : patient.copy();
   dst.relationship = relationship == null ? null : relationship.copy();
   dst.name = name == null ? null : name.copy();
   dst.telecom = new ArrayList<Contact>();
   for (Contact i : telecom) dst.telecom.add(i.copy());
   dst.gender = gender == null ? null : gender.copy();
   dst.address = address == null ? null : address.copy();
   dst.photo = new ArrayList<Attachment>();
   for (Attachment i : photo) dst.photo.add(i.copy());
   return dst;
 }
Exemple #4
0
  /**
   * 사용자 정보 수정
   *
   * @return
   */
  @With(AnonymousCheckAction.class)
  @Transactional
  public static Result editUserInfo() {
    Form<User> userForm = new Form<>(User.class).bindFromRequest("name", "email");
    String newEmail = userForm.data().get("email");
    String newName = userForm.data().get("name");
    User user = UserApp.currentUser();

    if (StringUtils.isEmpty(newEmail)) {
      userForm.reject("email", "user.wrongEmail.alert");
    } else {
      if (!StringUtils.equals(user.email, newEmail) && User.isEmailExist(newEmail)) {
        userForm.reject("email", "user.email.duplicate");
      }
    }

    if (userForm.error("email") != null) {
      flash(Constants.WARNING, userForm.error("email").message());
      return badRequest(edit.render(userForm, user));
    }
    user.email = newEmail;
    user.name = newName;

    try {
      Long avatarId = Long.valueOf(userForm.data().get("avatarId"));
      if (avatarId != null) {
        Attachment attachment = Attachment.find.byId(avatarId);
        String primary = attachment.mimeType.split("/")[0].toLowerCase();

        if (attachment.size > AVATAR_FILE_LIMIT_SIZE) {
          userForm.reject("avatarId", "user.avatar.fileSizeAlert");
        }

        if (primary.equals("image")) {
          Attachment.deleteAll(currentUser().avatarAsResource());
          attachment.moveTo(currentUser().avatarAsResource());
        }
      }
    } catch (NumberFormatException ignored) {
    }

    Email.deleteOtherInvalidEmails(user.email);
    user.update();
    return redirect(
        routes.UserApp.userInfo(user.loginId, DEFAULT_GROUP, DAYS_AGO, DEFAULT_SELECTED_TAB));
  }
  // FIXME: Should also use events!
  public void deleteAttachment(Attachment att) throws ProviderException {
    if (m_provider == null) return;

    m_provider.deleteAttachment(att);

    m_engine.getSearchManager().pageRemoved(att);

    m_engine.getReferenceManager().clearPageEntries(att.getName());
  }
 public DiagnosticReport copy() {
   DiagnosticReport dst = new DiagnosticReport();
   dst.status = status == null ? null : status.copy();
   dst.issued = issued == null ? null : issued.copy();
   dst.subject = subject == null ? null : subject.copy();
   dst.performer = performer == null ? null : performer.copy();
   dst.reportId = reportId == null ? null : reportId.copy();
   dst.requestDetail = new ArrayList<DiagnosticReportRequestDetailComponent>();
   for (DiagnosticReportRequestDetailComponent i : requestDetail)
     dst.requestDetail.add(i.copy(dst));
   dst.serviceCategory = serviceCategory == null ? null : serviceCategory.copy();
   dst.diagnostic = diagnostic == null ? null : diagnostic.copy();
   dst.results = results == null ? null : results.copy(dst);
   dst.image = new ArrayList<ResourceReference>();
   for (ResourceReference i : image) dst.image.add(i.copy());
   dst.conclusion = conclusion == null ? null : conclusion.copy();
   dst.codedDiagnosis = new ArrayList<CodeableConcept>();
   for (CodeableConcept i : codedDiagnosis) dst.codedDiagnosis.add(i.copy());
   dst.representation = new ArrayList<Attachment>();
   for (Attachment i : representation) dst.representation.add(i.copy());
   return dst;
 }
Exemple #7
0
 public boolean isEmpty() {
   return super.isEmpty()
       && (type == null || type.isEmpty())
       && (subtype == null || subtype.isEmpty())
       && (identifier == null || identifier.isEmpty())
       && (subject == null || subject.isEmpty())
       && (operator == null || operator.isEmpty())
       && (view == null || view.isEmpty())
       && (deviceName == null || deviceName.isEmpty())
       && (height == null || height.isEmpty())
       && (width == null || width.isEmpty())
       && (frames == null || frames.isEmpty())
       && (duration == null || duration.isEmpty())
       && (content == null || content.isEmpty());
 }
  /**
   * Stores an attachment directly from a stream. If the attachment did not exist previously, this
   * method will create it. If it did exist, it stores a new version.
   *
   * @param att Attachment to store this under.
   * @param in InputStream from which the attachment contents will be read.
   * @throws IOException If writing the attachment failed.
   * @throws ProviderException If something else went wrong.
   */
  public void storeAttachment(Attachment att, InputStream in)
      throws IOException, ProviderException {
    if (m_provider == null) {
      return;
    }

    //
    //  Checks if the actual, real page exists without any modifications
    //  or aliases.  We cannot store an attachment to a non-existant page.
    //
    if (!m_engine.getPageManager().pageExists(att.getParentName())) {
      // the caller should catch the exception and use the exception text as an i18n key
      throw new ProviderException("attach.parent.not.exist");
    }

    m_provider.putAttachmentData(att, in);

    m_engine.getReferenceManager().updateReferences(att.getName(), new java.util.Vector());

    WikiPage parent = new WikiPage(m_engine, att.getParentName());
    m_engine.updateReferences(parent);

    m_engine.getSearchManager().reindexPage(att);
  }
Exemple #9
0
 /** New attachment insertion */
 public Attachment updateAttachment(long noteId, Attachment attachment, SQLiteDatabase db) {
   ContentValues valuesAttachments = new ContentValues();
   valuesAttachments.put(
       KEY_ATTACHMENT_ID,
       attachment.getId() != null ? attachment.getId() : Calendar.getInstance().getTimeInMillis());
   valuesAttachments.put(KEY_ATTACHMENT_NOTE_ID, noteId);
   valuesAttachments.put(KEY_ATTACHMENT_URI, attachment.getUri().toString());
   valuesAttachments.put(KEY_ATTACHMENT_MIME_TYPE, attachment.getMime_type());
   valuesAttachments.put(KEY_ATTACHMENT_NAME, attachment.getName());
   valuesAttachments.put(KEY_ATTACHMENT_SIZE, attachment.getSize());
   valuesAttachments.put(KEY_ATTACHMENT_LENGTH, attachment.getLength());
   db.insertWithOnConflict(
       TABLE_ATTACHMENTS, KEY_ATTACHMENT_ID, valuesAttachments, SQLiteDatabase.CONFLICT_REPLACE);
   return attachment;
 }
Exemple #10
0
 public Media copy() {
   Media dst = new Media();
   copyValues(dst);
   dst.type = type == null ? null : type.copy();
   dst.subtype = subtype == null ? null : subtype.copy();
   if (identifier != null) {
     dst.identifier = new ArrayList<Identifier>();
     for (Identifier i : identifier) dst.identifier.add(i.copy());
   }
   ;
   dst.subject = subject == null ? null : subject.copy();
   dst.operator = operator == null ? null : operator.copy();
   dst.view = view == null ? null : view.copy();
   dst.deviceName = deviceName == null ? null : deviceName.copy();
   dst.height = height == null ? null : height.copy();
   dst.width = width == null ? null : width.copy();
   dst.frames = frames == null ? null : frames.copy();
   dst.duration = duration == null ? null : duration.copy();
   dst.content = content == null ? null : content.copy();
   return dst;
 }
 public GVFVariant copy() {
   GVFVariant dst = new GVFVariant();
   dst.subject = subject == null ? null : subject.copy(dst);
   dst.meta = meta == null ? null : meta.copy();
   dst.sourceFile = sourceFile == null ? null : sourceFile.copy();
   dst.seqid = seqid == null ? null : seqid.copy();
   dst.source = source == null ? null : source.copy();
   dst.type = type == null ? null : type.copy();
   dst.start = start == null ? null : start.copy();
   dst.end = end == null ? null : end.copy();
   dst.score = score == null ? null : score.copy();
   dst.strand = strand == null ? null : strand.copy();
   dst.featureId = featureId == null ? null : featureId.copy();
   dst.alias = alias == null ? null : alias.copy();
   dst.dbxref = dbxref == null ? null : dbxref.copy(dst);
   dst.variantSeq = new ArrayList<String_>();
   for (String_ i : variantSeq) dst.variantSeq.add(i.copy());
   dst.referenceSeq = referenceSeq == null ? null : referenceSeq.copy();
   dst.variantFreq = new ArrayList<Decimal>();
   for (Decimal i : variantFreq) dst.variantFreq.add(i.copy());
   dst.variantEffect = new ArrayList<GVFVariantVariantEffectComponent>();
   for (GVFVariantVariantEffectComponent i : variantEffect) dst.variantEffect.add(i.copy(dst));
   dst.startRange = startRange == null ? null : startRange.copy(dst);
   dst.endRange = endRange == null ? null : endRange.copy(dst);
   dst.variantCodon = new ArrayList<String_>();
   for (String_ i : variantCodon) dst.variantCodon.add(i.copy());
   dst.referenceCodon = referenceCodon == null ? null : referenceCodon.copy();
   dst.variantAA = new ArrayList<String_>();
   for (String_ i : variantAA) dst.variantAA.add(i.copy());
   dst.referenceAA = new ArrayList<String_>();
   for (String_ i : referenceAA) dst.referenceAA.add(i.copy());
   dst.breakpointDetail = breakpointDetail == null ? null : breakpointDetail.copy(dst);
   dst.sequenceContext = sequenceContext == null ? null : sequenceContext.copy(dst);
   dst.individual = new ArrayList<String_>();
   for (String_ i : individual) dst.individual.add(i.copy());
   dst.sample = new ArrayList<GVFVariantSampleComponent>();
   for (GVFVariantSampleComponent i : sample) dst.sample.add(i.copy(dst));
   return dst;
 }
  public void testAddRemoveAttachment() throws Exception {
    Map vars = new HashMap();
    vars.put("users", users);
    vars.put("groups", groups);
    vars.put("now", new Date());

    String str =
        "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { createdOn = now, activationTime = now}), ";
    str += "deadlines = new Deadlines(),";
    str += "delegation = new Delegation(),";
    str += "peopleAssignments = new PeopleAssignments(),";
    str += "names = [ new I18NText( 'en-UK', 'This is my task name')] })";

    Task task = (Task) eval(new StringReader(str), vars);
    client.addTask(task, null);

    long taskId = task.getId();

    Attachment attachment = new Attachment();
    Date attachedAt = new Date(System.currentTimeMillis());
    attachment.setAttachedAt(attachedAt);
    attachment.setAttachedBy(users.get("luke"));
    attachment.setName("file1.txt");
    attachment.setAccessType(AccessType.Inline);
    attachment.setContentType("txt");

    byte[] bytes = "Ths is my attachment text1".getBytes();
    Content content = new Content();
    content.setContent(bytes);

    client.addAttachment(taskId, attachment, content);

    Task task1 = client.getTask(taskId);
    // For local clients this will be the same.. that's why is commented
    // assertNotSame(task, task1);
    // assertFalse(task.equals(task1));

    List<Attachment> attachments1 = task1.getTaskData().getAttachments();
    assertEquals(1, attachments1.size());
    Attachment returnedAttachment = attachments1.get(0);
    assertEquals(attachedAt, returnedAttachment.getAttachedAt());
    assertEquals(users.get("luke"), returnedAttachment.getAttachedBy());
    assertEquals(AccessType.Inline, returnedAttachment.getAccessType());
    assertEquals("txt", returnedAttachment.getContentType());
    assertEquals("file1.txt", returnedAttachment.getName());
    assertEquals(bytes.length, returnedAttachment.getSize());

    assertEquals((long) attachment.getId(), (long) returnedAttachment.getId());
    assertEquals((long) content.getId(), (long) returnedAttachment.getAttachmentContentId());

    // Make the same as the returned tasks, so we can test equals
    task.getTaskData().setAttachments(attachments1);
    task.getTaskData().setStatus(Status.Created);
    assertEquals(task, task1);

    content = client.getContent(returnedAttachment.getAttachmentContentId());
    assertEquals("Ths is my attachment text1", new String(content.getContent()));

    // test we can have multiple attachments

    attachment = new Attachment();
    attachedAt = new Date(System.currentTimeMillis());
    attachment.setAttachedAt(attachedAt);
    attachment.setAttachedBy(users.get("tony"));
    attachment.setName("file2.txt");
    attachment.setAccessType(AccessType.Inline);
    attachment.setContentType("txt");

    bytes = "Ths is my attachment text2".getBytes();
    content = new Content();
    content.setContent(bytes);

    client.addAttachment(taskId, attachment, content);

    task1 = client.getTask(taskId);
    // In local clients this will be the same object and we are reusing the tests
    // assertNotSame(task, task1);
    // assertFalse(task.equals(task1));

    List<Attachment> attachments2 = task1.getTaskData().getAttachments();
    assertEquals(2, attachments2.size());

    content = client.getContent(content.getId());
    assertEquals("Ths is my attachment text2", new String(content.getContent()));

    // make two collections the same and compare
    attachment.setSize(26);
    attachment.setAttachmentContentId(content.getId());
    attachments1.add(attachment);
    assertTrue(CollectionUtils.equals(attachments2, attachments1));

    client.deleteAttachment(taskId, attachment.getId(), content.getId());

    task1 = client.getTask(taskId);
    attachments2 = task1.getTaskData().getAttachments();
    assertEquals(1, attachments2.size());

    assertEquals("file1.txt", attachments2.get(0).getName());
  }
Exemple #13
0
  @Override
  public String attachVolume(String instanceId, String volumeId, String deviceName) {
    IaasProvider iaasInfo = getIaasProvider();
    ComputeServiceContext context = iaasInfo.getComputeService().getContext();
    String region = ComputeServiceBuilderUtil.extractRegion(iaasInfo);
    String zone = ComputeServiceBuilderUtil.extractZone(iaasInfo);
    String device = deviceName == null ? "/dev/sdh" : deviceName;

    if (region == null || zone == null) {
      log.fatal(
          "Cannot attach the volume [id]: "
              + volumeId
              + " in the [region] : "
              + region
              + ", [zone] : "
              + zone
              + " of Iaas : "
              + iaasInfo);
      return null;
    }

    ElasticBlockStoreApi blockStoreApi =
        context.unwrapApi(AWSEC2Api.class).getElasticBlockStoreApiForRegion(region).get();
    Volume.Status volumeStatus = this.getVolumeStatus(blockStoreApi, region, volumeId);

    if (log.isDebugEnabled()) {
      log.debug("Volume " + volumeId + " is in state " + volumeStatus);
    }

    while (volumeStatus != Volume.Status.AVAILABLE) {
      try {
        // TODO Use a proper mechanism to wait till volume becomes available.
        Thread.sleep(1000);
        volumeStatus = this.getVolumeStatus(blockStoreApi, region, volumeId);
        if (log.isDebugEnabled()) {
          log.debug(
              "Volume " + volumeId + " is still NOT in AVAILABLE. Current State=" + volumeStatus);
        }
      } catch (InterruptedException e) {
        // Ignoring the exception
      }
    }
    if (log.isDebugEnabled()) {
      log.debug("Volume " + volumeId + " became  AVAILABLE");
    }

    Attachment attachment =
        blockStoreApi.attachVolumeInRegion(region, volumeId, instanceId, device);

    if (attachment == null) {
      log.fatal(
          "Volume [id]: "
              + volumeId
              + " attachment for instance [id]: "
              + instanceId
              + " was unsuccessful. [region] : "
              + region
              + ", [zone] : "
              + zone
              + " of Iaas : "
              + iaasInfo);
      return null;
    }

    log.info(
        "Volume [id]: "
            + volumeId
            + " attachment for instance [id]: "
            + instanceId
            + " was successful [status]: "
            + attachment.getStatus().value()
            + ". [region] : "
            + region
            + ", [zone] : "
            + zone
            + " of Iaas : "
            + iaasInfo);
    return attachment.getStatus().value();
  }
Exemple #14
0
  // Inserting or updating single note
  public Note updateNote(Note note, boolean updateLastModification) {
    SQLiteDatabase db = getDatabase(true);

    String content;
    if (note.isLocked()) {
      content = Security.encrypt(note.getContent(), prefs.getString(Constants.PREF_PASSWORD, ""));
    } else {
      content = note.getContent();
    }

    // To ensure note and attachments insertions are atomical and boost performances transaction are
    // used
    db.beginTransaction();

    ContentValues values = new ContentValues();
    values.put(KEY_TITLE, note.getTitle());
    values.put(KEY_CONTENT, content);
    values.put(
        KEY_CREATION,
        note.getCreation() != null ? note.getCreation() : Calendar.getInstance().getTimeInMillis());
    values.put(
        KEY_LAST_MODIFICATION,
        updateLastModification
            ? Calendar.getInstance().getTimeInMillis()
            : (note.getLastModification() != null
                ? note.getLastModification()
                : Calendar.getInstance().getTimeInMillis()));
    values.put(KEY_ARCHIVED, note.isArchived());
    values.put(KEY_TRASHED, note.isTrashed());
    values.put(KEY_REMINDER, note.getAlarm());
    values.put(KEY_REMINDER_FIRED, note.isReminderFired());
    values.put(KEY_RECURRENCE_RULE, note.getRecurrenceRule());
    values.put(KEY_LATITUDE, note.getLatitude());
    values.put(KEY_LONGITUDE, note.getLongitude());
    values.put(KEY_ADDRESS, note.getAddress());
    values.put(KEY_CATEGORY, note.getCategory() != null ? note.getCategory().getId() : null);
    boolean locked = note.isLocked() != null ? note.isLocked() : false;
    values.put(KEY_LOCKED, locked);
    boolean checklist = note.isChecklist() != null ? note.isChecklist() : false;
    values.put(KEY_CHECKLIST, checklist);

    db.insertWithOnConflict(TABLE_NOTES, KEY_ID, values, SQLiteDatabase.CONFLICT_REPLACE);
    Log.d(Constants.TAG, "Updated note titled '" + note.getTitle() + "'");

    // Updating attachments
    List<Attachment> deletedAttachments = note.getAttachmentsListOld();
    for (Attachment attachment : note.getAttachmentsList()) {
      updateAttachment(
          note.get_id() != null ? note.get_id() : values.getAsLong(KEY_CREATION), attachment, db);
      deletedAttachments.remove(attachment);
    }
    // Remove from database deleted attachments
    for (Attachment attachmentDeleted : deletedAttachments) {
      db.delete(
          TABLE_ATTACHMENTS,
          KEY_ATTACHMENT_ID + " = ?",
          new String[] {String.valueOf(attachmentDeleted.getId())});
    }

    db.setTransactionSuccessful();
    db.endTransaction();

    // Fill the note with correct data before returning it
    note.setCreation(
        note.getCreation() != null ? note.getCreation() : values.getAsLong(KEY_CREATION));
    note.setLastModification(values.getAsLong(KEY_LAST_MODIFICATION));

    return note;
  }
Exemple #15
0
  /** Retrieves statistics data based on app usage */
  public Stats getStats() {
    Stats mStats = new Stats();

    // Categories
    mStats.setCategories(getCategories().size());

    // Everything about notes and their text stats
    int notesActive = 0,
        notesArchived = 0,
        notesTrashed = 0,
        reminders = 0,
        remindersFuture = 0,
        checklists = 0,
        notesMasked = 0,
        tags = 0,
        locations = 0;
    int totalWords = 0, totalChars = 0, maxWords = 0, maxChars = 0, avgWords = 0, avgChars = 0;
    int words, chars;
    List<Note> notes = getAllNotes(false);
    for (Note note : notes) {
      if (note.isTrashed()) {
        notesTrashed++;
      } else if (note.isArchived()) {
        notesArchived++;
      } else {
        notesActive++;
      }
      if (note.getAlarm() != null && Long.parseLong(note.getAlarm()) > 0) {
        if (Long.parseLong(note.getAlarm()) > Calendar.getInstance().getTimeInMillis()) {
          remindersFuture++;
        } else {
          reminders++;
        }
      }
      if (note.isChecklist()) {
        checklists++;
      }
      if (note.isLocked()) {
        notesMasked++;
      }
      tags += TagsHelper.retrieveTags(note).size();
      if (note.getLongitude() != null && note.getLongitude() != 0) {
        locations++;
      }
      words = getWords(note);
      chars = getChars(note);
      if (words > maxWords) {
        maxWords = words;
      }
      if (chars > maxChars) {
        maxChars = chars;
      }
      totalWords += words;
      totalChars += chars;
    }
    mStats.setNotesActive(notesActive);
    mStats.setNotesArchived(notesArchived);
    mStats.setNotesTrashed(notesTrashed);
    mStats.setReminders(reminders);
    mStats.setRemindersFutures(remindersFuture);
    mStats.setNotesChecklist(checklists);
    mStats.setNotesMasked(notesMasked);
    mStats.setTags(tags);
    mStats.setLocation(locations);
    avgWords = totalWords / (notes.size() != 0 ? notes.size() : 1);
    avgChars = totalChars / (notes.size() != 0 ? notes.size() : 1);

    mStats.setWords(totalWords);
    mStats.setWordsMax(maxWords);
    mStats.setWordsAvg(avgWords);
    mStats.setChars(totalChars);
    mStats.setCharsMax(maxChars);
    mStats.setCharsAvg(avgChars);

    // Everything about attachments
    int attachmentsAll = 0, images = 0, videos = 0, audioRecordings = 0, sketches = 0, files = 0;
    List<Attachment> attachments = getAllAttachments();
    for (Attachment attachment : attachments) {
      if (Constants.MIME_TYPE_IMAGE.equals(attachment.getMime_type())) {
        images++;
      } else if (Constants.MIME_TYPE_VIDEO.equals(attachment.getMime_type())) {
        videos++;
      } else if (Constants.MIME_TYPE_AUDIO.equals(attachment.getMime_type())) {
        audioRecordings++;
      } else if (Constants.MIME_TYPE_SKETCH.equals(attachment.getMime_type())) {
        sketches++;
      } else if (Constants.MIME_TYPE_FILES.equals(attachment.getMime_type())) {
        files++;
      }
    }
    mStats.setAttachments(attachmentsAll);
    mStats.setImages(images);
    mStats.setVideos(videos);
    mStats.setAudioRecordings(audioRecordings);
    mStats.setSketches(sketches);
    mStats.setFiles(files);

    return mStats;
  }