Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Team 14 - IDATT1002
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Eirik Steira
Team 14 - IDATT1002
Commits
4bb69fef
Commit
4bb69fef
authored
5 years ago
by
Mads Lundegaard
Committed by
Eirik Steira
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Dunno anymore
parent
bb37258d
No related branches found
Branches containing commit
No related tags found
2 merge requests
!104
Weekly merge to Master
,
!75
Single photo upload
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/NTNU/IDATT1002/service/ImageService.java
+9
-3
9 additions, 3 deletions
src/main/java/NTNU/IDATT1002/service/ImageService.java
src/main/java/NTNU/IDATT1002/utils/MetaDataExtractor.java
+24
-5
24 additions, 5 deletions
src/main/java/NTNU/IDATT1002/utils/MetaDataExtractor.java
with
33 additions
and
8 deletions
src/main/java/NTNU/IDATT1002/service/ImageService.java
+
9
−
3
View file @
4bb69fef
...
...
@@ -30,6 +30,7 @@ public class ImageService {
private
ImageRepository
imageRepository
;
private
MetadataRepository
metadataRepository
;
private
TagRepository
tagRepository
;
private
MetaDataExtractor
metaDataExtractor
;
/**
* Inject entity manager instance to the repositories.
...
...
@@ -41,6 +42,8 @@ public class ImageService {
this
.
imageRepository
=
new
ImageRepository
(
entityManager
);
this
.
metadataRepository
=
new
MetadataRepository
(
entityManager
);
this
.
tagRepository
=
new
TagRepository
(
entityManager
);
this
.
metaDataExtractor
=
new
MetaDataExtractor
();
}
/**
...
...
@@ -52,14 +55,17 @@ public class ImageService {
*/
public
Optional
<
Image
>
createImage
(
User
user
,
File
file
,
ArrayList
<
Tag
>
tags
)
{
Image
image
=
new
Image
();
Metadata
metadata
=
metaDataExtractor
.
assembleMetaData
(
file
,
image
);
System
.
out
.
println
(
metadata
.
getGeoLocation
().
getLatitude
());
System
.
out
.
println
(
metadata
.
getHistogram
().
getData
());
byte
[]
bFile
=
ImageUtil
.
convertToBytes
(
file
.
getPath
());
Metadata
metadata
=
MetaDataExtractor
.
assembleMetaData
(
file
,
image
);
metadata
=
metadataRepository
.
save
(
metadata
).
orElse
(
null
);
metadata
=
metadataRepository
.
save
(
metadata
).
get
();
//TODO: Unsure what to do with imageAlbum
image
.
setRawImage
(
bFile
);
image
.
setUser
(
user
);
image
.
setUser
(
null
);
image
.
setMetadata
(
metadata
);
image
.
setPath
(
file
.
getPath
());
//image.addTags(tags);
...
...
This diff is collapsed.
Click to expand it.
src/main/java/NTNU/IDATT1002/utils/MetaDataExtractor.java
+
24
−
5
View file @
4bb69fef
...
...
@@ -3,6 +3,9 @@ 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
NTNU.IDATT1002.repository.MetadataRepository
;
import
com.drew.imaging.ImageMetadataReader
;
import
com.drew.imaging.ImageProcessingException
;
import
com.drew.metadata.Directory
;
...
...
@@ -12,6 +15,9 @@ import com.drew.metadata.Tag;
import
com.drew.metadata.exif.*
;
import
com.drew.metadata.jpeg.JpegDirectory
;
import
javax.persistence.EntityManager
;
import
javax.persistence.EntityManagerFactory
;
import
javax.persistence.Persistence
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
...
...
@@ -22,6 +28,17 @@ import java.util.Arrays;
public
class
MetaDataExtractor
{
private
GeoLocatioRepository
geoLocationRepository
;
private
HistorgramRepository
historgramRepository
;
public
MetaDataExtractor
()
{
EntityManagerFactory
entityManagerFactory
=
Persistence
.
createEntityManagerFactory
(
"ImageApplication"
);
EntityManager
entityManager
=
entityManagerFactory
.
createEntityManager
();
this
.
historgramRepository
=
new
HistorgramRepository
(
entityManager
);
this
.
geoLocationRepository
=
new
GeoLocatioRepository
(
entityManager
);
}
/**
* Returns a string with the GPS position
*
...
...
@@ -30,7 +47,7 @@ public class MetaDataExtractor {
* @throws IOException
* @throws MetadataException
*/
private
static
GeoLocation
getGPS
(
File
file
)
throws
ImageProcessingException
,
IOException
,
MetadataException
{
private
GeoLocation
getGPS
(
File
file
)
throws
ImageProcessingException
,
IOException
,
MetadataException
{
String
gps
=
""
;
String
latitude
=
""
;
String
longitude
=
""
;
...
...
@@ -47,14 +64,15 @@ public class MetaDataExtractor {
geoLocation
.
setLatitude
(
latitude
);
geoLocation
.
setLongitude
(
longitude
);
}
catch
(
NullPointerException
e
)
{
geoLocationRepository
.
save
(
geoLocation
);
}
catch
(
NullPointerException
e
)
{
e
.
printStackTrace
();
}
return
geoLocation
;
}
public
static
Histogram
getHistorgram
(
File
file
)
throws
ImageProcessingException
,
IOException
{
public
Histogram
getHistorgram
(
File
file
)
throws
ImageProcessingException
,
IOException
{
String
text
=
""
;
Metadata
metadata
=
ImageMetadataReader
.
readMetadata
(
file
);
Histogram
histogram
=
new
Histogram
();
...
...
@@ -65,10 +83,11 @@ public class MetaDataExtractor {
}
}
histogram
.
setData
(
text
);
historgramRepository
.
save
(
histogram
);
return
histogram
;
}
public
static
NTNU
.
IDATT1002
.
models
.
Metadata
assembleMetaData
(
File
file
,
Image
image
)
{
public
NTNU
.
IDATT1002
.
models
.
Metadata
assembleMetaData
(
File
file
,
Image
image
)
{
NTNU
.
IDATT1002
.
models
.
Metadata
metadata
=
new
NTNU
.
IDATT1002
.
models
.
Metadata
();
try
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment