Merge branch 'develop' of ssh://git.dsv.su.se/git/scipro/scipro into develop

This commit is contained in:
joha-asc 2011-07-28 15:38:24 +02:00
commit 11281a9423
18 changed files with 190 additions and 94 deletions

@ -186,6 +186,8 @@ public class SciProSession extends WebSession {
Project activeProject = userSettings.getActiveProject();
if(activeProject != null)
activeProjectId = activeProject.getId();
else
activeProjectId = null;
}
else {
userSettings = new UserSettings(user);

@ -33,17 +33,49 @@ public class AdminServerEnvironmentSettingsPage extends AbstractAdminSettingsPag
List<KeyValuePair<String>> list = new ArrayList<KeyValuePair<String>>();
list.add(new KeyValuePair<String>("[CALL] getRemoteUser",rawRequest.getRemoteUser()));
list.add(new KeyValuePair<String>("[CALL] getAuthType",rawRequest.getAuthType()));
@SuppressWarnings("rawtypes") Enumeration attributes = rawRequest.getAttributeNames();
while(attributes.hasMoreElements()){
final String key = (String)attributes.nextElement();
final String value = rawRequest.getAttribute(key).toString();
list.add(new KeyValuePair<String>("[ATTR] "+key,value));
addManualAttributes(rawRequest,list);
{
@SuppressWarnings("rawtypes") Enumeration attributes = rawRequest.getAttributeNames();
while(attributes.hasMoreElements()){
final String key = (String)attributes.nextElement();
final String value = rawRequest.getAttribute(key).toString();
list.add(new KeyValuePair<String>("[ATTR] "+key,value));
}
}
Map<String,String> envs = System.getenv();
for(String key : envs.keySet()){
list.add(new KeyValuePair<String>("[ENV] "+key,envs.get(key)));
{
@SuppressWarnings("rawtypes") Enumeration headers = rawRequest.getHeaderNames();
while(headers.hasMoreElements()){
final String key = (String)headers.nextElement();
final String value = rawRequest.getHeader(key);
list.add(new KeyValuePair<String>("[HEAD] "+key,value));
}
}
{
Map<String,String> envs = System.getenv();
for(String key : envs.keySet()){
list.add(new KeyValuePair<String>("[ENV] "+key,envs.get(key)));
}
}
return list;
}
private void addManualAttributes(final HttpServletRequest request, final List<KeyValuePair<String>> list){
final String[] attrs = {"Shib-Application-ID","Shib-Session-ID","Shib-Identity-Provider",
"Shib-Authentication-Instant","Shib-Authentication-Method","Shib-AuthnContext-Class",
"Shib-AuthnContext-Decl","Shib-Identity-Provider","mail","cn","eppn","gidNumber","givenName","sn","uid","memberOf"};
for(final String attr : attrs){
addPrefixedManualAttribute(request,list,"",attr);
addPrefixedManualAttribute(request,list,"AJP_",attr);
addPrefixedManualAttribute(request,list,"AJP-",attr);
}
}
private void addPrefixedManualAttribute(final HttpServletRequest request, final List<KeyValuePair<String>> list, final String prefix, final String attr){
final String scanAttr = prefix+attr;
if(request.getAttribute(scanAttr) != null)
list.add(new KeyValuePair<String>("[M-ATTR] "+scanAttr,request.getAttribute(scanAttr).toString()));
if(request.getHeader(scanAttr) != null)
list.add(new KeyValuePair<String>("[M-HEAD] "+scanAttr,request.getHeader(scanAttr)));
if(System.getenv(scanAttr) != null)
list.add(new KeyValuePair<String>("[M-ENV] "+scanAttr,System.getenv(scanAttr)));
}
}

@ -26,7 +26,7 @@
<!--<link rel="stylesheet" href="css/scipro.css" media="screen,projection" />-->
<!-- <link type="text/css" href="css/smoothness/jquery-ui-1.8.10.custom.css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery-1.5.1.min.js"></script>
<script type="text/javascript" src="js/jquery-1.5.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.10.custom.min.js"></script> -->
<script type="text/javascript">

@ -84,13 +84,15 @@ public class FinalSeminarUploadControllerImpl implements FinalSeminarUploadContr
public void deleteSeminarFilesRecursive(final FinalSeminar seminar) throws FileStorageException {
if (seminar.getDocument() != null) {
delete(getRepositorySeminarPath(seminar));
//delete(getRepositorySeminarPath(seminar)); Use of deprecated path/method
delete(seminar.getDocument().getPath());
}
}
public void deleteOpponentFiles(final FinalSeminarOpposition opp) throws FileStorageException {
if (opp.getOpponentReport() != null) {
delete(getRepositoryOppositionPath(opp));
//delete(getRepositoryOppositionPath(opp)); Use of deprecated path/method
delete(opp.getOpponentReport().getPath());
}
}
@ -139,7 +141,8 @@ public class FinalSeminarUploadControllerImpl implements FinalSeminarUploadContr
throw new RuntimeException("The file must be a PDF");
}
String path = getRepositorySeminarPath(seminar);
//String path = getRepositorySeminarPath(seminar); Deprecated method call
String path = fileRepository.getFinalSeminarPath(seminar.getId());
FileDescription fd = null;
try {
fd = store(upload, path);
@ -200,8 +203,9 @@ public class FinalSeminarUploadControllerImpl implements FinalSeminarUploadContr
throw new IllegalStateException("Non other than the opponent can upload an opposition");
}
FileDescription fd = null;
String path = getRepositoryOppositionPath(opposition);
//String path = getRepositoryOppositionPath(opposition); Deprecated method call
String path = fileRepository.getFinalSeminarOppositionPath(opposition.getId());
try {
fd = store(upload, path);
fd = fileDescriptionDao.save(fd);
@ -239,7 +243,11 @@ public class FinalSeminarUploadControllerImpl implements FinalSeminarUploadContr
throw new Exception(e);
}
}
/*
* The following two methods are deprecated and should not be used, they are left here because the
* production system has data generated using these old path-methods. //MP
*
private String getRepositorySeminarPath(FinalSeminar seminar) {
return fileRepository.getRepositoryRootPath() + FINAL_SEMINAR_DIRECTORY
+ String.valueOf(seminar.getId()) + "/";
@ -249,11 +257,8 @@ public class FinalSeminarUploadControllerImpl implements FinalSeminarUploadContr
return getRepositorySeminarPath(o.getFinalSeminar()) + FINAL_SEMINAR_OPPOSITION_DIRECTORY
+ String.valueOf(o.getId()) + "/";
}
*/
}

@ -154,11 +154,7 @@ public abstract class Event extends LazyDeletableDomainObject
@Override
public int compareTo(Event other) {
int dcomp = dueDate.compareTo(other.dueDate);
if(dcomp == 0)
return id.compareTo(other.id);
else
return dcomp;
return (int) (dueDate.getTime() - other.dueDate.getTime());
}
public Panel getDisplayPanel(String id){

@ -3,6 +3,7 @@ package se.su.dsv.scipro.data.dataobjects;
import java.util.Date;
import javax.persistence.Cacheable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@ -24,17 +25,22 @@ import org.hibernate.annotations.Index;
public class FileDescription extends DomainObject implements Comparable<FileDescription>{
private static final long serialVersionUID = 1L;
public static final int PATH_MAX_LENGTH = 255;
@Id
@GeneratedValue
private Long id;
@Column(length=255)
private String name;
private Date targetLastModified;
@Column(length=255)
private String mimeType;
@Index(name="file_description_identifier_index") //Hibernate specific, just for performance
@Column(length=255)
private String identifier;
@Index(name="file_description_path_index") //Hibernate specific, just for performance
@Column(length=PATH_MAX_LENGTH)
private String path;
private Long userId = null;
private Long size;

@ -38,6 +38,9 @@ public class ProjectEventTemplate extends DomainObject implements Comparable<Pro
@Column(nullable=false)
private long estimatedTimeConsumption = 0;
@Column(nullable=false)
private int daysOffset;
@Column(nullable=false)
private boolean requireHandIn = false;
@ -46,6 +49,10 @@ public class ProjectEventTemplate extends DomainObject implements Comparable<Pro
public ProjectEventTemplate(){}
public ProjectEventTemplate(int daysOffset){
this.daysOffset = daysOffset;
}
public Long getId() {
return id;
}
@ -53,6 +60,14 @@ public class ProjectEventTemplate extends DomainObject implements Comparable<Pro
public void setId(Long id) {
this.id = id;
}
public void setdaysOffset(int daysOffset){
this.daysOffset = daysOffset;
}
public int getDaysOffset(){
return daysOffset;
}
public String getTitle() {
return title;

@ -21,9 +21,9 @@ public abstract class AbstractSupervisorPeerPage extends AbstractSupervisorPage
@Override
protected List<MenuItem> getItemList() {
final List<MenuItem> items = new ArrayList<MenuItem>();
items.add(new MenuItem("My projects", SupervisorPeerStatsPage.class, MenuHighlightReviewPage.class, ImageIcon.ICON_STATISTICS));
final List<MenuItem> items = new ArrayList<MenuItem>();
items.add(new MenuItem("Peer portal", SupervisorPeerPortalPage.class, ImageIcon.ICON_FIND));
items.add(new MenuItem("My projects", SupervisorPeerStatsPage.class, MenuHighlightReviewPage.class, ImageIcon.ICON_STATISTICS));
items.add(new MenuItem("How to write a good review", SupervisorPeerReviewGuidePage.class, ImageIcon.ICON_HELP));
return items;
}

@ -2,6 +2,10 @@ package se.su.dsv.scipro.peer.pages;
import org.apache.wicket.PageParameters;
import se.su.dsv.scipro.security.auth.Authorization;
import se.su.dsv.scipro.security.auth.roles.Roles;
@Authorization(authorizedRoles={Roles.SYSADMIN})
public class ProjectPeerReviewGuidePage extends AbstractProjectPeerPage {
public ProjectPeerReviewGuidePage(PageParameters pp) {

@ -2,6 +2,10 @@ package se.su.dsv.scipro.peer.pages;
import org.apache.wicket.PageParameters;
import se.su.dsv.scipro.security.auth.Authorization;
import se.su.dsv.scipro.security.auth.roles.Roles;
@Authorization(authorizedRoles={Roles.SYSADMIN})
public class SupervisorPeerReviewGuidePage extends AbstractSupervisorPeerPage {
public SupervisorPeerReviewGuidePage(PageParameters pp) {

@ -161,6 +161,18 @@ public interface FileRepository {
* @return
*/
String getResourcePath(Long fileResourceId);
/**
* Get the repository path associated with a certain FinalSeminar
* @param finalSeminarId
* @return
*/
String getFinalSeminarPath(Long finalSeminarId);
/**
* Get the repository path associated with a certain FinalSeminarOpposition
* @param finalSeminarOppositionId
* @return
*/
String getFinalSeminarOppositionPath(Long finalSeminarOppositionId);
/**
* Convenience method to sort folders according to the input parameters
* @param list

@ -62,14 +62,19 @@ import eu.medsea.mimeutil.detector.ExtensionMimeDetector;
@Repository
public class FileRepositoryImpl implements FileRepository {
protected static final int STANDARD_INTERVAL_LENGTH = 100;
protected static final String ROOT_PATH = "root/";
protected static final String PROJECTS_PATH = "projects/";
protected static final String RESOURCES_PATH = "resources/";
protected static final String FINAL_SEMINAR_ROOT_PATH = "final_seminars/";
protected static final String FINAL_SEMINARS_PATH = "final_seminar_reports/";
protected static final String FINAL_SEMINAR_OPPOSITION_REPORT_PATH = "opposition_reports/";
@Autowired(required=false)
private RepositoryManager repositoryManager;
public String storeFile(String name, String mimeType, InputStream fileStream) {
if (StringUtils.isEmpty(name)) {
return null;
}
@ -89,6 +94,9 @@ public class FileRepositoryImpl implements FileRepository {
Node folder = RepositoryHelper.findOrCreateFolder(session, splitWithoutFile, rootNode);
Node file = folder.addNode(itemName, "nt:file");
if( file.getPath().length() > FileDescription.PATH_MAX_LENGTH ){
throw new IllegalStateException("Trying to store a node with a path length that is too long");
}
file.addMixin("sp:fileMixin");
Node fileContent = file.addNode ("jcr:content", "nt:resource");
fileContent.addMixin("mix:referenceable");
@ -384,35 +392,37 @@ public class FileRepositoryImpl implements FileRepository {
}
public String getProjectRootPath(Long projectId){
return ROOT_PATH+PROJECTS_PATH+getProjectSubFolder(projectId);
return ROOT_PATH+PROJECTS_PATH+getIntervalSubFolder(projectId, STANDARD_INTERVAL_LENGTH);
}
public String getFinalSeminarPath(Long finalSeminarId){
return ROOT_PATH+FINAL_SEMINAR_ROOT_PATH+FINAL_SEMINARS_PATH+getIntervalSubFolder(finalSeminarId, STANDARD_INTERVAL_LENGTH);
}
public String getFinalSeminarOppositionPath(Long finalSeminarOppositionId){
return ROOT_PATH+FINAL_SEMINAR_ROOT_PATH+FINAL_SEMINAR_OPPOSITION_REPORT_PATH+getIntervalSubFolder(finalSeminarOppositionId, STANDARD_INTERVAL_LENGTH);
}
/**
* Method used to split the projects folder into subfolders containing projects. Precaution because jackrabbit can
* Method used to split the folders into subfolders containing for example projects. Precaution because jackrabbit can
* get slow when faced with huge number of subnodes in one node (10.000+).
* @param projectId id of the project, for example 54
* @param id id of the domain object used as key, for example projectId, for example 54
* @param intervalLength, should be a CONSTANT for any given uses
* @return result looking like for example: "0-99/54
*/
protected String getProjectSubFolder(Long projectId){
int intervalLength = 100;
Long startId = ( projectId / intervalLength ) * intervalLength;
protected String getIntervalSubFolder(final Long id, final int intervalLength){
if(id == null)
throw new IllegalStateException("Attempting to calculate a repository path using a null-id, that's not allowed!");
Long startId = ( id / intervalLength ) * intervalLength;
Long endId = startId + intervalLength - 1;
String result = startId.toString() + "-" + endId.toString() + "/" + projectId.toString() +"/";
String result = startId.toString() + "-" + endId.toString() + "/" + id.toString() +"/";
return result;
}
public String getResourcePath(Long fileResourceId){
if(fileResourceId == null)
throw new NullPointerException("Null value for FileResource-id cannot generate a valid path to store a file resource!");
return ROOT_PATH+RESOURCES_PATH+getResourceSubFolder(fileResourceId);
}
protected String getResourceSubFolder(Long fileResourceId){
int intervalLength = 1000;
Long startId = ( fileResourceId / intervalLength ) * intervalLength;
Long endId = startId + intervalLength - 1;
String result = startId.toString() + "-" + endId.toString() + "/" + fileResourceId.toString() +"/";
return result;
return ROOT_PATH+RESOURCES_PATH+getIntervalSubFolder(fileResourceId, 1000); //TODO If resources are ever used with files, make this a static constant
}
@Override

@ -416,13 +416,21 @@ public abstract class AbstractFilePanel extends Panel {
protected void onSubmit() {
final FileUpload upload = fileUploadField.getFileUpload();
fileRepository.storeFile(upload, absolutePath);
setRedirect(true);
pp.put("i", relativePath.replaceAll("/", "."));
setResponsePage(fpc.getSurroundingPageClass(), pp);
try{
fileRepository.storeFile(upload, absolutePath);
setRedirect(true);
pp.put("i", relativePath.replaceAll("/", "."));
setResponsePage(fpc.getSurroundingPageClass(), pp);
} catch (FileStorageException fse){
if(fse.getCause().getClass().equals(IllegalStateException.class)){
error("Cannot save file into this directory, the resulting path is to long/deep. Try a shorter name or a different directory.");
}
else{
error(fse.getMessage());
}
}
}
}
}

@ -11,7 +11,10 @@ import org.joda.time.DateMidnight;
import org.joda.time.DateTimeConstants;
import org.joda.time.Days;
import se.su.dsv.scipro.SciProSession;
import se.su.dsv.scipro.data.dao.interfaces.EventDao;
import se.su.dsv.scipro.data.dao.interfaces.ProjectDao;
import se.su.dsv.scipro.data.dao.interfaces.ProjectEventDao;
import se.su.dsv.scipro.data.dao.interfaces.ScheduleTemplateDao;
import se.su.dsv.scipro.data.dataobjects.Project;
import se.su.dsv.scipro.data.dataobjects.ProjectEvent;
@ -27,6 +30,9 @@ public class ScheduleGenerator {
@SpringBean
private ProjectDao projectDao;
@SpringBean
private ProjectEventDao projectEventDao;
private Project project;
private ScheduleTemplate template;
private List<ProjectEventTemplate> eventTemplates;
@ -72,14 +78,17 @@ public class ScheduleGenerator {
List<ProjectEvent> events = new ArrayList<ProjectEvent>();
DateMidnight datePointer = new DateMidnight(startDate);
DateMidnight tempPointer;
int totalDuration = 0;
for(ProjectEventTemplate e : eventTemplates){
tempPointer = new DateMidnight(datePointer);
ProjectEvent event = e.createEventFromTemplate();
event.setParticipants(project.getProjectParticipants());
event.setParticipants(project.getProjectParticipants());//might have to remove this
if(e.getEstimatedTimeConsumption() <= 1){
datePointer = new DateMidnight(startDate).plusDays(e.getDaysOffset());
}
double duration = (double) e.getEstimatedTimeConsumption() * ratio;
if(duration < 1.0)
duration = 1.0;
datePointer = datePointer.plusDays((int) duration);
totalDuration += (int)duration;
@ -94,6 +103,9 @@ public class ScheduleGenerator {
}
event.setDueDate(datePointer.toDate());
events.add(event);
if(e.getEstimatedTimeConsumption() <= 1){
datePointer = tempPointer;
}
}
return new ScheduleGeneratorResult(template, events, totalDuration, templateEstimatedDays, startDate.toDate(), endDate.toDate());
}

@ -38,6 +38,7 @@ public class TemplateGenerator { //based on ScheduleGenerator
private int templateEstimatedDays = 0;
private int durationInDays = 0;
private int daysOffset;
private DateMidnight startDate;
@ -56,12 +57,9 @@ public class TemplateGenerator { //based on ScheduleGenerator
if(schedule.getStartDate() != null){
this.startDate = new DateMidnight(schedule.getStartDate());
}else{
this.startDate = new DateMidnight(projectEvents.first().getDueDate());
int days = (new DateMidnight(projectEvents.first().getDueDate()).getDayOfYear() - new DateMidnight(schedule.getStartDate()).getDayOfYear());
this.startDate = new DateMidnight(projectEvents.first().getDueDate()).minusDays(days);
}
}
public ScheduleTemplate generate(){
@ -94,9 +92,12 @@ public class TemplateGenerator { //based on ScheduleGenerator
pet.setRequireHandIn(pe.isRequireHandIn());
pet.setScheduleTemplate(template);
int daysOffset = (new DateMidnight(pe.getDueDate()).getDayOfYear() - startDate.getDayOfYear());
pet.setdaysOffset(daysOffset);
datePointer = datePointer.plusDays(durationInDays);
templateEstimatedDays += durationInDays;
setTemplateEstimatedDays(getTemplateEstimatedDays() + durationInDays);
projectEventTemplate.add(pet);
}
@ -158,5 +159,21 @@ public class TemplateGenerator { //based on ScheduleGenerator
this.startDate = new DateMidnight(startDate);
}
public int getTemplateEstimatedDays() {
return templateEstimatedDays;
}
public void setTemplateEstimatedDays(int templateEstimatedDays) {
this.templateEstimatedDays = templateEstimatedDays;
}
public int getDaysOffset() {
return daysOffset;
}
public void setDaysOffset(int daysOffset) {
this.daysOffset = daysOffset;
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -64,7 +64,7 @@ import se.su.dsv.scipro.repository.util.RepositoryManager;
*
*/
@Ignore
public class BaseWicketTest {
public abstract class BaseWicketTest {
protected WicketTester tester;
@ -112,7 +112,9 @@ public class BaseWicketTest {
@Mock EntityManagerFactoryInfo entityManagerFactory = Mockito.mock(LocalEntityManagerFactoryBean.class);
//@Before
/**
* Call this method within as the first call in @Before annotated method in an overriding test case class, see example in {@link TestWicketPages}
*/
public void setup() {
/*
* Setup a new mock applicationContext
@ -174,7 +176,10 @@ public class BaseWicketTest {
});
}
/*
* The following methods are added for convenience
*/
protected void setLoggedIn(boolean loggedIn){
MockSciProSession.currentSession.setLoggedIn(loggedIn);
}