use of cn.edu.zju.acm.onlinejudge.persistence.ReferencePersistence in project zoj by licheng.
the class AddProblemAction method createReference.
private void createReference(ReferenceType type, FormFile formFile, long problemId, long user) throws Exception {
if (formFile == null) {
return;
}
ReferencePersistence referencePersistence = PersistenceManager.getInstance().getReferencePersistence();
byte[] data = formFile.getFileData();
if (data.length == 0) {
return;
}
Reference ref = new Reference();
ref.setContent(data);
ref.setReferenceType(type);
ref.setSize(data.length);
referencePersistence.createProblemReference(problemId, ref, user);
}
use of cn.edu.zju.acm.onlinejudge.persistence.ReferencePersistence in project zoj by licheng.
the class EditProblemAction method setReference.
private void setReference(String typeKey, ReferenceType type, long problemId, ContextAdapter context) throws Exception {
ReferencePersistence referencePersistence = PersistenceManager.getInstance().getReferencePersistence();
List<Reference> references = referencePersistence.getProblemReferenceInfo(problemId, type);
if (references.size() > 0) {
context.setAttribute(typeKey, references.get(0));
}
}
use of cn.edu.zju.acm.onlinejudge.persistence.ReferencePersistence in project zoj by licheng.
the class EditProblemAction method updateReference.
private void updateReference(ReferenceType type, FormFile formFile, long problemId, long user) throws Exception {
if (formFile == null || formFile.getFileName() == null || formFile.getFileName().trim().length() == 0) {
return;
}
String name = formFile.getFileName();
String contentType = null;
int p = name.lastIndexOf('.');
if (p != -1) {
contentType = name.substring(p + 1);
}
byte[] data = formFile.getFileData();
ReferencePersistence referencePersistence = PersistenceManager.getInstance().getReferencePersistence();
List<Reference> references = referencePersistence.getProblemReferenceInfo(problemId, type);
if (references.size() == 0) {
Reference ref = new Reference();
ref.setContent(data);
ref.setContentType(contentType);
ref.setReferenceType(type);
ref.setSize(data.length);
referencePersistence.createProblemReference(problemId, ref, user);
} else {
Reference ref = references.get(0);
ref.setContent(data);
ref.setContentType(contentType);
ref.setSize(data.length);
referencePersistence.updateReference(ref, user);
}
}
use of cn.edu.zju.acm.onlinejudge.persistence.ReferencePersistence in project zoj by licheng.
the class ProblemImportAction method createReference.
private static void createReference(ReferenceType type, byte[] data, long problemId, long user, String fileName, String fileType) throws Exception {
if (data == null) {
return;
}
ReferencePersistence referencePersistence = PersistenceManager.getInstance().getReferencePersistence();
if (fileType != null && fileType.trim().length() > 0) {
fileName = fileName + "." + fileType;
}
Reference ref = new Reference();
ref.setName(fileName);
ref.setContentType(fileType);
ref.setContent(data);
ref.setReferenceType(type);
ref.setSize(data.length);
referencePersistence.createProblemReference(problemId, ref, user);
}
use of cn.edu.zju.acm.onlinejudge.persistence.ReferencePersistence in project zoj by licheng.
the class ShowProblemsAction method getReferenceLength.
private long getReferenceLength(Problem p, ReferenceType type) throws Exception {
ReferencePersistence referencePersistence = PersistenceManager.getInstance().getReferencePersistence();
List<Reference> refs = referencePersistence.getProblemReferenceInfo(p.getId(), type);
if (refs.size() == 0) {
return -1;
}
Reference ref = refs.get(0);
return ref.getSize();
}
Aggregations