Пример #1
0
 @Override
 public LogEntry findLogEntry(Object logId) throws Exception {
   Log log = reader.getLog((Long) logId);
   if (log != null) {
     LogBuilder logBuilder = LogBuilder.log(log);
     for (edu.msu.nscl.olog.api.Attachment attachments : reader.listAttachments(log.getId())) {
       logBuilder.attach(AttachmentBuilder.attachment(attachments));
     }
     return new OlogEntry(logBuilder.build());
   }
   return new OlogEntry(log);
 }
Пример #2
0
  @Override
  public Attachment addAttachment(Object logId, InputStream attachment, String name)
      throws Exception {
    try {
      File file = new File(name);
      OutputStream out = new FileOutputStream(file);
      int read = 0;
      byte[] bytes = new byte[1024];

      while ((read = attachment.read(bytes)) != -1) {
        out.write(bytes, 0, read);
      }
      out.flush();
      out.close();
      edu.msu.nscl.olog.api.Attachment response;
      if (file != null) {
        response = writer.add(file, (Long) logId);
        file.delete();
        return new OlogAttachment(response, getAttachment(logId, response.getFileName()));
      }
    } catch (IOException e) {
      throw new Exception(e);
    }
    return null;
  }
Пример #3
0
 @Override
 public void updateLogEntries(Collection<LogEntry> logEntires) throws Exception {
   Collection<LogBuilder> logbuilders = new ArrayList<LogBuilder>();
   for (LogEntry logEntry : logEntires) {
     logbuilders.add(LogBuilder(logEntry));
   }
   writer.update(logbuilders);
 }
Пример #4
0
 @Override
 public Collection<LogEntry> findLogEntries(String search) throws Exception {
   Collection<LogEntry> logEntries = new ArrayList<LogEntry>();
   Collection<Log> logs = reader.findLogsBySearch(search);
   for (Log log : logs) {
     logEntries.add(new OlogEntry(log));
   }
   return logEntries;
 }
Пример #5
0
  @Override
  public Collection<Property> listProperties() throws Exception {
    return Collections.unmodifiableCollection(
        Collections2.transform(
            reader.listProperties(),
            new Function<edu.msu.nscl.olog.api.Property, Property>() {

              @Override
              public Property apply(edu.msu.nscl.olog.api.Property input) {
                return new OlogProperty(input);
              }
            }));
  }
Пример #6
0
  @Override
  public Collection<Tag> listTags() throws Exception {
    return Collections.unmodifiableCollection(
        Collections2.transform(
            reader.listTags(),
            new Function<edu.msu.nscl.olog.api.Tag, Tag>() {

              @Override
              public Tag apply(edu.msu.nscl.olog.api.Tag input) {
                return new OlogTag(input);
              }
            }));
  }
Пример #7
0
  @Override
  public Collection<Logbook> listLogbooks() throws Exception {
    return Collections.unmodifiableCollection(
        Collections2.transform(
            reader.listLogbooks(),
            new Function<edu.msu.nscl.olog.api.Logbook, Logbook>() {

              @Override
              public Logbook apply(edu.msu.nscl.olog.api.Logbook input) {
                return new OlogLogbook(input);
              }
            }));
  }
Пример #8
0
 @Override
 public LogEntry createLogEntry(LogEntry logEntry) throws Exception {
   OlogEntry ologEntry = new OlogEntry(writer.set(LogBuilder(logEntry)));
   // creates the log entry and then adds all the attachments
   // TODO (shroffk) multiple network calls, one for each attachment, need
   // to improve
   for (Attachment attachment : logEntry.getAttachment()) {
     InputStream inputStream = attachment.getInputStream();
     if (inputStream != null) {
       addAttachment(ologEntry.getId(), inputStream, attachment.getFileName());
       inputStream.close();
     }
   }
   return ologEntry;
 }
Пример #9
0
  @Override
  public Collection<Attachment> listAttachments(final Object logId) throws Exception {
    return Collections.unmodifiableCollection(
        Collections2.transform(
            reader.listAttachments((Long) logId),
            new Function<edu.msu.nscl.olog.api.Attachment, Attachment>() {

              @Override
              public Attachment apply(edu.msu.nscl.olog.api.Attachment input) {
                // TODO (shroffk) n/w call
                try {
                  return new OlogAttachment(input, getAttachment(logId, input.getFileName()));
                } catch (IOException e) {
                }
                return null;
              }
            }));
  }
Пример #10
0
 @Override
 public LogEntry updateLogEntry(LogEntry logEntry) throws Exception {
   return new OlogEntry(writer.update(LogBuilder(logEntry)));
 }
Пример #11
0
 @Override
 public InputStream getAttachment(Object logId, String attachmentFileName) {
   return reader.getAttachment((Long) logId, attachmentFileName);
 }