Skip to content
Snippets Groups Projects
Commit 8e1b08db authored by Eirik Steira's avatar Eirik Steira
Browse files

Clean up single image upload

e
parent f28d3e6d
No related branches found
No related tags found
2 merge requests!104Weekly merge to Master,!75Single photo upload
......@@ -29,10 +29,7 @@ import java.util.ResourceBundle;
*/
public class UploadedSingle implements Initializable {
ImageService imageService;
NTNU.IDATT1002.models.Image image;
ApplicationState applicationState;
public ImageView tbar_logo;
public TextField tbar_search;
......@@ -59,6 +56,7 @@ public class UploadedSingle implements Initializable {
*/
public void initialize(URL location, ResourceBundle resources) {
photo_image.setImage(new Image(App.ex.getUploadedFiles().get(0).toURI().toString()));
imageService = new ImageService();
}
/**
......@@ -134,20 +132,10 @@ public class UploadedSingle implements Initializable {
*/
public void uploadSingle(ActionEvent actionEvent) throws IOException {
imageService = new ImageService();
applicationState = new ApplicationState();
List<File> list = App.ex.getUploadedFiles();
File fil = list.get(0);
ArrayList<Tag> tags = new ArrayList<>();
System.out.println("SHITFUCK");
imageService.createImage(ApplicationState.getCurrentUser(), fil, tags);
/* list.stream().forEach(x -> {
image = imageService.createImage(applicationState.getCurrentUser(), x).get();
List tags = tagStringSplit(photo_tag);
tags.stream().forEach(y -> {
imageService.addTagToImage(image, new Tag((Tag) y));
});
});*/
App.setRoot("main");
}
......
......@@ -23,7 +23,6 @@ public class Metadata {
* on image_id column in image
*/
@OneToOne(mappedBy = "metadata")
@MapsId
private Image image;
@OneToOne(cascade = CascadeType.ALL)
......
......@@ -57,10 +57,7 @@ public class ImageService {
GeoLocation geoLocation = metaDataExtractor.getGeoLocation(file);
Histogram histogram = metaDataExtractor.getHistogram(file);
// geoLocation = geoLocatioRepository.save(geoLocation).orElse(null);
// histogram = historgramRepository.save(histogram).orElse(null);
Image image = new Image();
Metadata metadata = new Metadata();
metadata.setImage(image);
image.setMetadata(metadata);
......@@ -74,11 +71,9 @@ public class ImageService {
System.out.println(metadata.getGeoLocation().getLatitude());
System.out.println(metadata.getHistogram().getData());
// metadata = metadataRepository.save(metadata).orElse(null);
byte[] bFile = ImageUtil.convertToBytes(file.getPath());
//TODO: Unsure what to do with imageAlbum
//TODO: Add image tags and add image to imageAlbum
image.setRawImage(bFile);
image.setUser(user);
image.setPath(file.getPath());
......
......@@ -2,7 +2,6 @@ package NTNU.IDATT1002.utils;
import NTNU.IDATT1002.models.GeoLocation;
import NTNU.IDATT1002.models.Histogram;
import NTNU.IDATT1002.models.Image;
import NTNU.IDATT1002.repository.GeoLocatioRepository;
import NTNU.IDATT1002.repository.HistorgramRepository;
import com.drew.imaging.ImageMetadataReader;
......@@ -18,6 +17,9 @@ import java.io.File;
import java.io.IOException;
/**
* Class MetaDataExtractor. Extracts metadata and geolocation and histogram from it.
*/
public class MetaDataExtractor {
private GeoLocatioRepository geoLocationRepository;
......@@ -63,6 +65,12 @@ public class MetaDataExtractor {
return geoLocation;
}
/**
* TODO: Decide what data to store.
*
* @param file
* @return
*/
public Histogram getHistogram(File file) {
// Metadata metadata = null;
//
......@@ -83,24 +91,9 @@ public class MetaDataExtractor {
Histogram histogram = new Histogram();
histogram.setData("Hello");
histogram.setData("INSERT DATA HERE");
return histogram;
}
public NTNU.IDATT1002.models.Metadata assembleMetaData(File file, Image image) {
NTNU.IDATT1002.models.Metadata metadata = new NTNU.IDATT1002.models.Metadata();
try {
metadata.setImage(image);
metadata.setGeoLocation(getGeoLocation(file));
metadata.setHistogram(getHistogram(file));
}
catch (Exception e) {
e.printStackTrace();
}
return metadata;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment