Skip to content
Snippets Groups Projects
Commit f87906fb authored by Mads Lundegaard's avatar Mads Lundegaard
Browse files

Added logger to methods for better exception handling

parent f9485c40
No related branches found
No related tags found
2 merge requests!165Weekly merge to Master,!134Added logger to methods for better exception handling
Pipeline #79268 passed
package NTNU.IDATT1002.utils; package NTNU.IDATT1002.utils;
import NTNU.IDATT1002.controllers.ExploreAlbums;
import NTNU.IDATT1002.models.GeoLocation; import NTNU.IDATT1002.models.GeoLocation;
import NTNU.IDATT1002.repository.GeoLocatioRepository; import NTNU.IDATT1002.repository.GeoLocatioRepository;
import com.drew.imaging.ImageMetadataReader; import com.drew.imaging.ImageMetadataReader;
...@@ -18,6 +19,8 @@ import com.drew.metadata.iptc.IptcDirectory; ...@@ -18,6 +19,8 @@ import com.drew.metadata.iptc.IptcDirectory;
import com.drew.metadata.jpeg.JpegDirectory; import com.drew.metadata.jpeg.JpegDirectory;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
...@@ -29,6 +32,8 @@ import java.io.IOException; ...@@ -29,6 +32,8 @@ import java.io.IOException;
public class MetaDataExtractor { public class MetaDataExtractor {
private GeoLocatioRepository geoLocationRepository; private GeoLocatioRepository geoLocationRepository;
private static Logger logger = LoggerFactory.getLogger(MetaDataExtractor.class);
public MetaDataExtractor() { public MetaDataExtractor() {
} }
...@@ -56,7 +61,7 @@ public class MetaDataExtractor { ...@@ -56,7 +61,7 @@ public class MetaDataExtractor {
geoLocation.setLongitude(longitude); geoLocation.setLongitude(longitude);
} }
catch (NullPointerException | ImageProcessingException | IOException e) { catch (NullPointerException | ImageProcessingException | IOException e) {
e.printStackTrace(); logger.error("[x] Could not find geolocation on file" ,e);
} }
return geoLocation; return geoLocation;
} }
...@@ -81,7 +86,7 @@ public class MetaDataExtractor { ...@@ -81,7 +86,7 @@ public class MetaDataExtractor {
if(!(cameraInformation.isBlank())) if(!(cameraInformation.isBlank()))
cameraInformation = cleanUpTags(cameraInformation, directory); cameraInformation = cleanUpTags(cameraInformation, directory);
} catch (IOException | ImageProcessingException | NullPointerException e) { } catch (IOException | ImageProcessingException | NullPointerException e) {
e.printStackTrace(); logger.error("[x] Could not get camera information from file", e);
} }
return cameraInformation; return cameraInformation;
} }
...@@ -107,7 +112,7 @@ public class MetaDataExtractor { ...@@ -107,7 +112,7 @@ public class MetaDataExtractor {
lensInformation = cleanUpTags(lensInformation, directory); lensInformation = cleanUpTags(lensInformation, directory);
} }
catch (IOException | ImageProcessingException | NullPointerException e) { catch (IOException | ImageProcessingException | NullPointerException e) {
e.printStackTrace(); logger.error("[x] Could not get lens information from file", e);
} }
return lensInformation; return lensInformation;
} }
...@@ -132,7 +137,7 @@ public class MetaDataExtractor { ...@@ -132,7 +137,7 @@ public class MetaDataExtractor {
if(!(apertureInformation.isBlank())) if(!(apertureInformation.isBlank()))
apertureInformation = cleanUpTags(apertureInformation, directory); apertureInformation = cleanUpTags(apertureInformation, directory);
} catch (IOException | ImageProcessingException | NullPointerException e) { } catch (IOException | ImageProcessingException | NullPointerException e) {
e.printStackTrace(); logger.error("[x] Could not get aperture information from file", e);
} }
return apertureInformation; return apertureInformation;
} }
...@@ -157,7 +162,7 @@ public class MetaDataExtractor { ...@@ -157,7 +162,7 @@ public class MetaDataExtractor {
if(!(shutterSpeedInformation.isBlank())) if(!(shutterSpeedInformation.isBlank()))
shutterSpeedInformation = cleanUpTags(shutterSpeedInformation, directory); shutterSpeedInformation = cleanUpTags(shutterSpeedInformation, directory);
} catch (IOException | ImageProcessingException | NullPointerException e) { } catch (IOException | ImageProcessingException | NullPointerException e) {
e.printStackTrace(); logger.error("[x] Could not get shutter speed information from file", e);
} }
return shutterSpeedInformation; return shutterSpeedInformation;
} }
...@@ -182,7 +187,7 @@ public class MetaDataExtractor { ...@@ -182,7 +187,7 @@ public class MetaDataExtractor {
if(!(isoInformation.isBlank())) if(!(isoInformation.isBlank()))
isoInformation = cleanUpTags(isoInformation, directory); isoInformation = cleanUpTags(isoInformation, directory);
} catch (IOException | ImageProcessingException | NullPointerException e) { } catch (IOException | ImageProcessingException | NullPointerException e) {
e.printStackTrace(); logger.error("[x] Could not get iso information from file", e);
} }
return isoInformation; return isoInformation;
} }
...@@ -208,7 +213,7 @@ public class MetaDataExtractor { ...@@ -208,7 +213,7 @@ public class MetaDataExtractor {
if(!(focalLengthInformation.isBlank())) if(!(focalLengthInformation.isBlank()))
focalLengthInformation = cleanUpTags(focalLengthInformation, directory); focalLengthInformation = cleanUpTags(focalLengthInformation, directory);
} catch (IOException | ImageProcessingException | NullPointerException e) { } catch (IOException | ImageProcessingException | NullPointerException e) {
e.printStackTrace(); logger.error("[x] Could not get focal length information from file", e);
} }
return focalLengthInformation; return focalLengthInformation;
} }
...@@ -234,7 +239,7 @@ public class MetaDataExtractor { ...@@ -234,7 +239,7 @@ public class MetaDataExtractor {
if(!(fileTypeInformation.isBlank())) if(!(fileTypeInformation.isBlank()))
fileTypeInformation = cleanUpTags(fileTypeInformation, directory); fileTypeInformation = cleanUpTags(fileTypeInformation, directory);
} catch (IOException | ImageProcessingException | NullPointerException e) { } catch (IOException | ImageProcessingException | NullPointerException e) {
e.printStackTrace(); logger.error("[x] Could not get file type from file", e);
} }
return fileTypeInformation; return fileTypeInformation;
} }
...@@ -266,7 +271,7 @@ public class MetaDataExtractor { ...@@ -266,7 +271,7 @@ public class MetaDataExtractor {
if(!(dateInformation.isBlank())) if(!(dateInformation.isBlank()))
dateInformation = cleanUpTags(dateInformation, directory); dateInformation = cleanUpTags(dateInformation, directory);
} catch (IOException | ImageProcessingException | NullPointerException e) { } catch (IOException | ImageProcessingException | NullPointerException e) {
e.printStackTrace(); logger.error("[x] Could not get photo date from file", e);
} }
return dateInformation; return dateInformation;
} }
...@@ -291,7 +296,7 @@ public class MetaDataExtractor { ...@@ -291,7 +296,7 @@ public class MetaDataExtractor {
if(!(fileSize.isBlank())) if(!(fileSize.isBlank()))
fileSize = cleanUpTags(fileSize, directory); fileSize = cleanUpTags(fileSize, directory);
} catch (IOException | ImageProcessingException | NullPointerException e) { } catch (IOException | ImageProcessingException | NullPointerException e) {
e.printStackTrace(); logger.error("[x] Could not get file size from file", e);
} }
return fileSize; return fileSize;
} }
...@@ -317,7 +322,7 @@ public class MetaDataExtractor { ...@@ -317,7 +322,7 @@ public class MetaDataExtractor {
if(!(fileDimension.isBlank())) if(!(fileDimension.isBlank()))
fileDimension = cleanUpTags(fileDimension, directory); fileDimension = cleanUpTags(fileDimension, directory);
} catch (IOException | ImageProcessingException | NullPointerException e) { } catch (IOException | ImageProcessingException | NullPointerException e) {
e.printStackTrace(); logger.error("[x] Could not get file dimension from file", e);
} }
return fileDimension; return fileDimension;
} }
......
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