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

Random bugfixs

parent 97a37792
No related branches found
No related tags found
No related merge requests found
......@@ -12,6 +12,7 @@ import mozen.model.Model;
import mozen.model.User;
import mozen.repos.CustomLayerRepository;
import mozen.repos.ModelRepository;
import mozen.utils.Md5Utils;
import mozen.utils.UserHelper;
@Service
......@@ -41,7 +42,7 @@ public class LayerManager implements ILayerManager{
CustomLayer layer = new CustomLayer();
layer.setName(name);
layer.setChecksum(crc32.getValue());
layer.setChecksum(Md5Utils.getMD5(file));
layer.setFile(file.getBytes());
layer.setFileType(file.getContentType());
layer.setModel(model);
......
......@@ -4,8 +4,6 @@ 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;
......@@ -22,6 +20,7 @@ import mozen.model.Tag;
import mozen.model.User;
import mozen.repos.ModelRepository;
import mozen.repos.TagRepository;
import mozen.utils.Md5Utils;
import mozen.utils.UserHelper;
@Service
......@@ -62,31 +61,30 @@ public class ModelManager implements IModelManager {
model.setLastModified(new Date());
model.setAuthor(user);
try {
modelRepo.save(model);
} catch (Exception e) {
System.err.println("[MODEL MANAGER] Add model error " + e.getMessage());
}
return model.getId();
}
@Override
public void addModelFile(MultipartFile file, long id, User user) throws Exception {
System.err.println("[MODEL MANAGER] add model file 0");
Model model = modelRepo.findById(id).get();
System.err.println("[MODEL MANAGER] add model file 1");
if (model == null)
throw new Exception("Unknown model");
if (!UserHelper.isAuthor(model.getAuthor(), user))
throw new Exception("Not the author");
Checksum crc32 = new CRC32();
crc32.update(file.getBytes(), 0, file.getBytes().length);
model.setChecksum(crc32.getValue());
System.err.println("[MODEL MANAGER] add model file 2");
model.setChecksum(Md5Utils.getMD5(file));
model.setFile(file.getBytes());
model.setFileType(file.getContentType());
System.err.println("[MODEL MANAGER] add model file 3");
modelRepo.save(model);
System.err.println("[MODEL MANAGER] add model file 4");
}
@Override
......
......@@ -9,7 +9,7 @@ public class ModelMessage implements Serializable {
private static final long serialVersionUID = 1L;
@NotNull
@Size(min = 3, max = 30)
@Size(min = 3, max = 100)
private String name;
@Size(min = 0, max = 200)
......@@ -22,7 +22,7 @@ public class ModelMessage implements Serializable {
private String [] customLayers;
private int performance;
private double performance;
private String performanceUnit;
......@@ -31,7 +31,7 @@ public class ModelMessage implements Serializable {
public ModelMessage() {
}
public ModelMessage(String name, String shortDescription, String longDescription, String[] tags, String[] customLayers, int performance, String performanceUnit, int parameterCount) {
public ModelMessage(String name, String shortDescription, String longDescription, String[] tags, String[] customLayers, double performance, String performanceUnit, int parameterCount) {
this.name = name;
this.shortDescription = shortDescription;
this.longDescription = longDescription;
......@@ -83,11 +83,11 @@ public class ModelMessage implements Serializable {
this.customLayers = customLayers;
}
public int getPerformance() {
public double getPerformance() {
return this.performance;
}
public void setPerformance(int performance) {
public void setPerformance(double performance) {
this.performance = performance;
}
......
......@@ -39,7 +39,7 @@ public class CustomLayer implements Serializable{
@Basic
@Column
private Long checksum;
private String checksum;
@Basic
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
......@@ -48,7 +48,7 @@ public class CustomLayer implements Serializable{
public CustomLayer() {
}
public CustomLayer(Long id, String name, byte[] file, String fileType, Long checksum, Model model) {
public CustomLayer(Long id, String name, byte[] file, String fileType, String checksum, Model model) {
this.id = id;
this.name = name;
this.file = file;
......@@ -100,11 +100,11 @@ public class CustomLayer implements Serializable{
this.model = model;
}
public Long getChecksum() {
public String getChecksum() {
return this.checksum;
}
public void setChecksum(Long checksum) {
public void setChecksum(String checksum) {
this.checksum = checksum;
}
......
......@@ -37,7 +37,7 @@ public class Model implements Serializable{
@Basic
@Column(nullable = false, unique = true)
@NotNull
@Size(min = 3, max = 30)
@Size(min = 3, max = 100)
private String name;
@Basic
......@@ -86,7 +86,7 @@ public class Model implements Serializable{
@Basic
@Column
private Long checksum;
private String checksum;
@Basic
@Column
......@@ -113,7 +113,7 @@ public class Model implements Serializable{
public Model() {
}
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, boolean isVerified, User author, Set<Tag> tags, Set<CustomLayer> customLayers, Set<Comment> comments) {
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, String checksum, boolean isVerified, User author, Set<Tag> tags, Set<CustomLayer> customLayers, Set<Comment> comments) {
this.id = id;
this.name = name;
this.shortDescription = shortDescription;
......@@ -255,11 +255,11 @@ public class Model implements Serializable{
this.parameterCount = parameterCount;
}
public Long getChecksum() {
public String getChecksum() {
return this.checksum;
}
public void setChecksum(Long checksum) {
public void setChecksum(String checksum) {
this.checksum = checksum;
}
......
package mozen.utils;
import java.io.IOException;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import org.springframework.web.multipart.MultipartFile;
public class Md5Utils {
public static String getMD5(MultipartFile file) {
try {
byte[] uploadBytes = file.getBytes();
MessageDigest md5 = MessageDigest.getInstance("MD5");
byte[] digest = md5.digest(uploadBytes);
return new BigInteger(1, digest).toString(16);
} catch (NoSuchAlgorithmException | IOException e) {
e.printStackTrace();
return null;
}
}
}
\ No newline at end of file
......@@ -151,7 +151,7 @@ public class ModelController {
}
try {
System.err.println("[MODEL CONTROLLER] model file upload n:"+file.getName());
System.err.println("[MODEL CONTROLLER] model file upload n:"+file.getName()+" id:"+id);
modelManager.addModelFile(file, id, user);
} catch (Exception e) {
response.setError(true);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment