Skip to content
Snippets Groups Projects
Commit 2ce891e5 authored by Thomas's avatar Thomas
Browse files

Added model performance & checksum

parent 0ba1611f
Branches
No related tags found
No related merge requests found
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);
......
......@@ -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());
......
......@@ -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,11 +48,12 @@ 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;
}
......@@ -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
......@@ -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
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment