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

Fix single image upload

parent f1891d57
No related branches found
No related tags found
2 merge requests!104Weekly merge to Master,!75Single photo upload
...@@ -18,7 +18,6 @@ public class DataExchange { ...@@ -18,7 +18,6 @@ public class DataExchange {
searchField = ""; searchField = "";
} }
public List<File> getUploadedFiles() { public List<File> getUploadedFiles() {
System.out.println("SHITFUCK111");
return uploadedFiles; return uploadedFiles;
} }
......
...@@ -23,8 +23,7 @@ public class GeoLocation { ...@@ -23,8 +23,7 @@ public class GeoLocation {
* One to one relation between geolocationId in table Geolocation * One to one relation between geolocationId in table Geolocation
* Joins column geolocation_id in metadata * Joins column geolocation_id in metadata
*/ */
@OneToOne @OneToOne(mappedBy = "geolocation")
@JoinColumn(name = "metadata_id")
private Metadata metadata; private Metadata metadata;
@NotBlank (message = "Altitude may not be blank") @NotBlank (message = "Altitude may not be blank")
...@@ -70,4 +69,8 @@ public class GeoLocation { ...@@ -70,4 +69,8 @@ public class GeoLocation {
public void setLongitude(String longitude) { public void setLongitude(String longitude) {
this.longitude = longitude; this.longitude = longitude;
} }
public void setMetadata(Metadata metadata) {
this.metadata = metadata;
}
} }
...@@ -2,6 +2,7 @@ package NTNU.IDATT1002.models; ...@@ -2,6 +2,7 @@ package NTNU.IDATT1002.models;
import javax.persistence.*; import javax.persistence.*;
import javax.validation.constraints.NotBlank;
/** /**
* Creates histogram table * Creates histogram table
...@@ -22,13 +23,11 @@ public class Histogram { ...@@ -22,13 +23,11 @@ public class Histogram {
* One to one relations, joins histogramId * One to one relations, joins histogramId
* On columns histogramId in metadata * On columns histogramId in metadata
*/ */
@OneToOne @OneToOne(mappedBy = "histogram")
@JoinColumn(name = "metadata_id")
private Metadata metadata; private Metadata metadata;
// @Column(name="data", length=294967295)
// @NotBlank (message = "Data may not be blank")
@Lob @Lob
@NotBlank(message = "Data may not be blank")
private String data; private String data;
public Histogram() { public Histogram() {
...@@ -50,4 +49,7 @@ public class Histogram { ...@@ -50,4 +49,7 @@ public class Histogram {
this.data = data; this.data = data;
} }
public void setMetadata(Metadata metadata) {
this.metadata = metadata;
}
} }
...@@ -38,7 +38,7 @@ public class Image { ...@@ -38,7 +38,7 @@ public class Image {
@NotEmpty @NotEmpty
private byte[] rawImage; private byte[] rawImage;
@OneToOne @OneToOne(cascade = CascadeType.ALL)
private Metadata metadata; private Metadata metadata;
@NotBlank @NotBlank
......
...@@ -22,14 +22,14 @@ public class Metadata { ...@@ -22,14 +22,14 @@ public class Metadata {
* One to one relation joining imageId * One to one relation joining imageId
* on image_id column in image * on image_id column in image
*/ */
@OneToOne @OneToOne(mappedBy = "metadata")
@JoinColumn(name = "image_id") @MapsId
private Image image; private Image image;
@OneToOne @OneToOne(cascade = CascadeType.ALL)
private GeoLocation geoLocation; private GeoLocation geolocation;
@OneToOne @OneToOne(cascade = CascadeType.ALL)
private Histogram histogram; private Histogram histogram;
public Metadata() { public Metadata() {
...@@ -37,7 +37,7 @@ public class Metadata { ...@@ -37,7 +37,7 @@ public class Metadata {
public Metadata(Image image, GeoLocation geoLocation, Histogram histogram) { public Metadata(Image image, GeoLocation geoLocation, Histogram histogram) {
this.image = image; this.image = image;
this.geoLocation = geoLocation; this.geolocation = geolocation;
this.histogram = histogram; this.histogram = histogram;
} }
...@@ -50,7 +50,7 @@ public class Metadata { ...@@ -50,7 +50,7 @@ public class Metadata {
} }
public GeoLocation getGeoLocation() { public GeoLocation getGeoLocation() {
return geoLocation; return geolocation;
} }
public Histogram getHistogram() { public Histogram getHistogram() {
...@@ -61,8 +61,8 @@ public class Metadata { ...@@ -61,8 +61,8 @@ public class Metadata {
this.image = image; this.image = image;
} }
public void setGeoLocation(GeoLocation geoLocation) { public void setGeoLocation(GeoLocation geolocation) {
this.geoLocation = geoLocation; this.geolocation = geolocation;
} }
public void setHistogram(Histogram histogram) { public void setHistogram(Histogram histogram) {
......
...@@ -57,26 +57,30 @@ public class ImageService { ...@@ -57,26 +57,30 @@ public class ImageService {
GeoLocation geoLocation = metaDataExtractor.getGeoLocation(file); GeoLocation geoLocation = metaDataExtractor.getGeoLocation(file);
Histogram histogram = metaDataExtractor.getHistogram(file); Histogram histogram = metaDataExtractor.getHistogram(file);
geoLocation = geoLocatioRepository.save(geoLocation).orElse(null); // geoLocation = geoLocatioRepository.save(geoLocation).orElse(null);
histogram = historgramRepository.save(histogram).orElse(null); // histogram = historgramRepository.save(histogram).orElse(null);
Image image = new Image(); Image image = new Image();
Metadata metadata = new Metadata(); Metadata metadata = new Metadata();
metadata.setImage(image); metadata.setImage(image);
image.setMetadata(metadata);
metadata.setGeoLocation(geoLocation); metadata.setGeoLocation(geoLocation);
geoLocation.setMetadata(metadata);
metadata.setHistogram(histogram); metadata.setHistogram(histogram);
histogram.setMetadata(metadata);
System.out.println(metadata.getGeoLocation().getLatitude()); System.out.println(metadata.getGeoLocation().getLatitude());
System.out.println(metadata.getHistogram().getData()); System.out.println(metadata.getHistogram().getData());
metadata = metadataRepository.save(metadata).orElse(null); // metadata = metadataRepository.save(metadata).orElse(null);
byte[] bFile = ImageUtil.convertToBytes(file.getPath()); byte[] bFile = ImageUtil.convertToBytes(file.getPath());
//TODO: Unsure what to do with imageAlbum //TODO: Unsure what to do with imageAlbum
image.setRawImage(bFile); image.setRawImage(bFile);
image.setUser(user); image.setUser(user);
image.setMetadata(metadata);
image.setPath(file.getPath()); image.setPath(file.getPath());
// image.addTags(tags); // image.addTags(tags);
return imageRepository.save(image); return imageRepository.save(image);
......
...@@ -7,10 +7,8 @@ import NTNU.IDATT1002.repository.GeoLocatioRepository; ...@@ -7,10 +7,8 @@ import NTNU.IDATT1002.repository.GeoLocatioRepository;
import NTNU.IDATT1002.repository.HistorgramRepository; import NTNU.IDATT1002.repository.HistorgramRepository;
import com.drew.imaging.ImageMetadataReader; import com.drew.imaging.ImageMetadataReader;
import com.drew.imaging.ImageProcessingException; import com.drew.imaging.ImageProcessingException;
import com.drew.metadata.Directory;
import com.drew.metadata.Metadata; import com.drew.metadata.Metadata;
import com.drew.metadata.MetadataException; import com.drew.metadata.MetadataException;
import com.drew.metadata.Tag;
import com.drew.metadata.exif.GpsDirectory; import com.drew.metadata.exif.GpsDirectory;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
...@@ -66,23 +64,26 @@ public class MetaDataExtractor { ...@@ -66,23 +64,26 @@ public class MetaDataExtractor {
} }
public Histogram getHistogram(File file) { public Histogram getHistogram(File file) {
Metadata metadata = null; // Metadata metadata = null;
//
// try {
// metadata = ImageMetadataReader.readMetadata(file);
// } catch (IOException | ImageProcessingException e) {
// e.printStackTrace();
// }
//
// StringBuilder data = new StringBuilder();
// assert metadata != null;
// for(Directory d : metadata.getDirectories()) {
// for (Tag t : d.getTags()) {
// data.append(t.toString()).append(" | ");
// }
// }
// histogram.setData(data.toString());
try {
metadata = ImageMetadataReader.readMetadata(file);
} catch (IOException | ImageProcessingException e) {
e.printStackTrace();
}
StringBuilder data = new StringBuilder();
assert metadata != null;
for(Directory d : metadata.getDirectories()) {
for (Tag t : d.getTags()) {
data.append(t.toString()).append(" | ");
}
}
Histogram histogram = new Histogram(); Histogram histogram = new Histogram();
histogram.setData(data.toString()); histogram.setData("Hello");
return histogram; return histogram;
} }
......
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