diff --git a/mozen/src/main/java/mozen/business/LayerManager.java b/mozen/src/main/java/mozen/business/LayerManager.java index b31a66e2ee0ee211482f25eeb42c495fb7cecaf7..0f9d418ff51129763ab2c04a2676343c1ac16197 100644 --- a/mozen/src/main/java/mozen/business/LayerManager.java +++ b/mozen/src/main/java/mozen/business/LayerManager.java @@ -1,5 +1,8 @@ package mozen.business; +import java.util.zip.CRC32; +import java.util.zip.Checksum; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; @@ -33,8 +36,12 @@ public class LayerManager implements ILayerManager{ if (!isModelAuthor(model, user)) throw new Exception("Not the author"); + Checksum crc32 = new CRC32(); + crc32.update(file.getBytes(), 0, file.getBytes().length); + CustomLayer layer = new CustomLayer(); layer.setName(name); + layer.setChecksum(crc32.getValue()); layer.setFile(file.getBytes()); layer.setFileType(file.getContentType()); layer.setModel(model); diff --git a/mozen/src/main/java/mozen/business/ModelManager.java b/mozen/src/main/java/mozen/business/ModelManager.java index dec9495a850dbb0eaad7ff8f3a75d9cdc5385336..61a34863071f3335eb64b3ad6303bc881d8de9f0 100644 --- a/mozen/src/main/java/mozen/business/ModelManager.java +++ b/mozen/src/main/java/mozen/business/ModelManager.java @@ -4,6 +4,8 @@ import java.util.Collection; import java.util.Date; import java.util.HashSet; import java.util.Set; +import java.util.zip.CRC32; +import java.util.zip.Checksum; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; @@ -74,6 +76,9 @@ public class ModelManager implements IModelManager { if (!isModelAuthor(model, user)) throw new Exception("Not the author"); + Checksum crc32 = new CRC32(); + crc32.update(file.getBytes(), 0, file.getBytes().length); + model.setChecksum(crc32.getValue()); model.setFile(file.getBytes()); model.setFileType(file.getContentType()); diff --git a/mozen/src/main/java/mozen/model/CustomLayer.java b/mozen/src/main/java/mozen/model/CustomLayer.java index 071cb7f2d2f9082bf53bc09b4e2072b1b973597e..b2e1e218d3659ccafe47da4683400b60e1cfd480 100644 --- a/mozen/src/main/java/mozen/model/CustomLayer.java +++ b/mozen/src/main/java/mozen/model/CustomLayer.java @@ -37,6 +37,10 @@ public class CustomLayer implements Serializable{ @Column private String fileType; + @Basic + @Column + private Long checksum; + @Basic @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL) private Model model; @@ -44,14 +48,15 @@ public class CustomLayer implements Serializable{ public CustomLayer() { } - public CustomLayer(Long id, String name, byte[] file, String fileType, Model model) { + public CustomLayer(Long id, String name, byte[] file, String fileType, Long checksum, Model model) { this.id = id; this.name = name; this.file = file; this.fileType = fileType; + this.checksum = checksum; this.model = model; } - + public Long getId() { return this.id; } @@ -95,4 +100,12 @@ public class CustomLayer implements Serializable{ this.model = model; } + public Long getChecksum() { + return this.checksum; + } + + public void setChecksum(Long checksum) { + this.checksum = checksum; + } + } \ No newline at end of file diff --git a/mozen/src/main/java/mozen/model/Model.java b/mozen/src/main/java/mozen/model/Model.java index 70eab80d5fa47d69c8c0dae3da63c179434c3e44..507c82da5dacdb1121d2a9c632cc77b6334a706e 100644 --- a/mozen/src/main/java/mozen/model/Model.java +++ b/mozen/src/main/java/mozen/model/Model.java @@ -64,6 +64,18 @@ public class Model implements Serializable{ @Column private int votes; + @Basic + @Column + private double performance; + + @Basic + @Column + private String performanceUnit; + + @Basic + @Column + private int parameterCount; + @Lob @Column(columnDefinition="BLOB") private byte[] file; @@ -72,6 +84,10 @@ public class Model implements Serializable{ @Column private String fileType; + @Basic + @Column + private Long checksum; + @Basic @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.MERGE) private User author; @@ -89,7 +105,7 @@ public class Model implements Serializable{ public Model() { } - public Model(Long id, String name, String shortDescription, String longDescription, Date added, Date lastModified, int votes, byte[] file, String fileType, User author, Set<Tag> tags, Set<CustomLayer> customLayers) { + public Model(Long id, String name, String shortDescription, String longDescription, Date added, Date lastModified, int votes, double performance, String performanceUnit, int parameterCount, byte[] file, String fileType, Long checksum, User author, Set<Tag> tags, Set<CustomLayer> customLayers) { this.id = id; this.name = name; this.shortDescription = shortDescription; @@ -97,8 +113,12 @@ public class Model implements Serializable{ this.added = added; this.lastModified = lastModified; this.votes = votes; + this.performance = performance; + this.performanceUnit = performanceUnit; + this.parameterCount = parameterCount; this.file = file; this.fileType = fileType; + this.checksum = checksum; this.author = author; this.tags = tags; this.customLayers = customLayers; @@ -201,4 +221,36 @@ public class Model implements Serializable{ this.fileType = fileType; } + public double getPerformance() { + return this.performance; + } + + public void setPerformance(double performance) { + this.performance = performance; + } + + public String getPerformanceUnit() { + return this.performanceUnit; + } + + public void setPerformanceUnit(String performanceUnit) { + this.performanceUnit = performanceUnit; + } + + public int getParameterCount() { + return this.parameterCount; + } + + public void setParameterCount(int parameterCount) { + this.parameterCount = parameterCount; + } + + public Long getChecksum() { + return this.checksum; + } + + public void setChecksum(Long checksum) { + this.checksum = checksum; + } + } \ No newline at end of file diff --git a/mozen/src/main/java/mozen/utils/DatabaseFiller.java b/mozen/src/main/java/mozen/utils/DatabaseFiller.java index ac405fab0001204497075072ddba20034d57776f..3734bd0182d4aeea47da7e27c2fb46cb42c6672b 100644 --- a/mozen/src/main/java/mozen/utils/DatabaseFiller.java +++ b/mozen/src/main/java/mozen/utils/DatabaseFiller.java @@ -16,7 +16,6 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import mozen.model.CustomLayer; import mozen.model.Model; import mozen.model.Role; import mozen.model.Tag; @@ -68,21 +67,13 @@ public class DatabaseFiller { m1.setShortDescription("Short description for model testo"); m1.setLongDescription("# README \n model testo"); m1.setVotes(0); + m1.setParameterCount(10); + m1.setPerformance(98.5); + m1.setPerformanceUnit("accuracy"); m1.setAdded(new Date()); m1.setLastModified(new Date()); m1.setTags(tagLoader()); - Set<CustomLayer> m1layers = new HashSet<CustomLayer>(); - CustomLayer l1 = new CustomLayer(); - l1.setName("super layer 1"); - - CustomLayer l2 = new CustomLayer(); - l2.setName("super layer 2"); - - m1layers.add(l1); - m1layers.add(l2); - m1.setCustomLayers(m1layers); - userRepo.save(u1); userRepo.save(u2); userRepo.save(admin);