Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
541 changes: 266 additions & 275 deletions app/logbook/elog/src/main/java/org/phoebus/elog/api/ElogClient.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,10 @@ private void submitLogEntry(final String title, final String body, final File im
ologLog.setDescription(body != null ? body : "");

if (image_file != null) {
try {
final Attachment attachment = AttachmentImpl.of(image_file, "image", false);
List<Attachment> attachments = new ArrayList<>();
attachments.add(attachment);
ologLog.setAttachments(attachments);
} catch (FileNotFoundException ex) {
logger.log(Level.WARNING, "Cannot attach " + image_file, ex);
}
final Attachment attachment = AttachmentImpl.of(image_file, "image", false);
List<Attachment> attachments = new ArrayList<>();
attachments.add(attachment);
ologLog.setAttachments(attachments);
}
new LogEntryEditorStage(ologLog).show();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,7 @@ else if(clazz.isAssignableFrom(AdvancedSearchViewController.class)){
}
lb.appendDescription(sb.toString());
listOfFiles.forEach(file -> {
try {
lb.attach(AttachmentImpl.of(file));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
lb.attach(AttachmentImpl.of(file));
});
logs.add(lb.build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,7 @@ public void start(Stage primaryStage) throws Exception {
.inLogbooks(new HashSet<Logbook>(Arrays.asList(LogbookImpl.of("Operations", "active"), LogbookImpl.of("Electrical", "active"))))
.owner("nsls2-user");
listOfFiles.forEach(file -> {
try {
lb.attach(AttachmentImpl.of(file));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
lb.attach(AttachmentImpl.of(file));
});
controller.setLogEntry(new TableViewListItem(lb.build(), true));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,7 @@ public void start(Stage primaryStage) throws Exception {
}
lb.appendDescription(sb.toString());
listOfFiles.forEach(file -> {
try {
lb.attach(AttachmentImpl.of(file));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
lb.attach(AttachmentImpl.of(file));
});
logs.add(lb.build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,7 @@ public void start(Stage primaryStage) throws Exception {
lb.appendDescription(sb.toString());
if (i % 2 != 0) {
listOfFiles.forEach(file -> {
try {
lb.attach(AttachmentImpl.of(file));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
lb.attach(AttachmentImpl.of(file));
});
lb.appendProperty(experimentProperty);
lb.appendProperty(track);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,8 @@ private void submitLogEntry(final Node parent, final String title, final String

if (image_file != null)
{
try
{
final Attachment attachment = AttachmentImpl.of(image_file, "image", false);
logEntryBuilder.attach(attachment);
}
catch (FileNotFoundException ex)
{
logger.log(Level.WARNING, "Cannot attach " + image_file, ex);
}
final Attachment attachment = AttachmentImpl.of(image_file, "image", false);
logEntryBuilder.attach(attachment);
}

final LogEntryModel model = new LogEntryModel(logEntryBuilder.createdDate(Instant.now()).build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,7 @@ else if(clazz.isAssignableFrom(AdvancedSearchViewController.class)){
}
lb.appendDescription(sb.toString());
listOfFiles.forEach(file -> {
try {
lb.attach(AttachmentImpl.of(file));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
lb.attach(AttachmentImpl.of(file));
});
logs.add(lb.build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,7 @@ public void start(Stage primaryStage) throws Exception {
.withTags(new HashSet<Tag>(Arrays.asList(TagImpl.of("Orbit", "active"), TagImpl.of("Studies", "active"))))
.inLogbooks(new HashSet<Logbook>(Arrays.asList(LogbookImpl.of("Operations", "active"))));
listOfFiles.forEach(file -> {
try {
lb.attach(AttachmentImpl.of(file));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
lb.attach(AttachmentImpl.of(file));
});
controller.setLogEntry(lb.build());
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,7 @@ else if(clazz.isAssignableFrom(AdvancedSearchViewController.class)){
}
lb.appendDescription(sb.toString());
listOfFiles.forEach(file -> {
try {
lb.attach(AttachmentImpl.of(file));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
lb.attach(AttachmentImpl.of(file));
});
logs.add(lb.build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,7 @@ else if(clazz.isAssignableFrom(AdvancedSearchViewController.class)){
}
lb.appendDescription(sb.toString());
listOfFiles.forEach(file -> {
try {
lb.attach(AttachmentImpl.of(file));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
lb.attach(AttachmentImpl.of(file));
});
logs.add(lb.build());

Expand Down
42 changes: 22 additions & 20 deletions core/logbook/src/main/java/org/phoebus/logbook/AttachmentImpl.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package org.phoebus.logbook;

import java.io.File;
import java.io.FileNotFoundException;
import java.net.FileNameMap;
import java.net.URLConnection;


/**
* A default implementation of {@link Attachment}
*
* @author Kunal Shroff
*
*/
Expand All @@ -17,10 +16,9 @@ public class AttachmentImpl implements Attachment {
private final Boolean thumbnail;
private String id;

private static FileNameMap fileNameMap = URLConnection.getFileNameMap();
private static final FileNameMap fileNameMap = URLConnection.getFileNameMap();

private AttachmentImpl(File file, String contentType, Boolean thumbnail) {
super();
this.file = file;
this.contentType = contentType;
this.thumbnail = thumbnail;
Expand All @@ -47,51 +45,55 @@ public String getName() {
}

@Override
public String getId(){
public String getId() {
return id;
}

@Override
public void setId(String id){
public void setId(String id) {
this.id = id;
}

@Override
public String getUniqueFilename() {
return getName();
}

/**
* Create a new instance of a default implementation of the {@link Attachment} interface using the given file
*
* @param file - the attachment file
* @return a {@link Attachment} based on the given file
* @throws FileNotFoundException
*/
public static Attachment of(File file) throws FileNotFoundException {
public static Attachment of(File file) {
String mimeType = fileNameMap.getContentTypeFor(file.getName());
return new AttachmentImpl(file, mimeType, null);
}

/**
* Create a new instance of a default implementation of the {@link Attachment} interface using the given file
* @param file - the attachment file
*
* @param file - the attachment file
* @param contentType - the type of the attached content ("image", "file", etc...)
* @param thumbnail - Whether the attachment has a thumbnail.
* @param thumbnail - Whether the attachment has a thumbnail.
* @return a {@link Attachment} based on the given file
* @throws FileNotFoundException
*/
public static Attachment of(File file, String contentType, boolean thumbnail) throws FileNotFoundException {
public static Attachment of(File file, String contentType, boolean thumbnail) {
return new AttachmentImpl(file, contentType, thumbnail);
}

/**
* Create a new instance of a default implementation of the {@link Attachment} interface using the given file
* @param id A unique id
* @param file - the attachment file
*
* @param id A unique id
* @param file - the attachment file
* @param contentType - the type of the attached content ("image", "file", etc...)
* @param thumbnail - Whether the attachment has a thumbnail.
* @param thumbnail - Whether the attachment has a thumbnail.
* @return a {@link Attachment} based on the given file
* @throws FileNotFoundException
*/
public static Attachment of(String id, File file, String contentType, boolean thumbnail) throws FileNotFoundException {
public static Attachment of(String id, File file, String contentType, boolean thumbnail) {
AttachmentImpl attachment = new AttachmentImpl(file, contentType, thumbnail);
attachment.setId(id);
return attachment;
return attachment;
}

}
Loading