Tagit bort möjligheten att rekursivt ta bort en massa saker (av misstag) samt möjligheten att ta bort filer som länkats till
git-svn-id: svn://svn.dsv.su.se/scipro/scipro/trunk@253 73ecded7-942e-4092-bab0-0e58ef0ee984
This commit is contained in:
parent
97e7e5fa80
commit
2839b74fef
src/main/java/se/su/dsv/scipro
data
repository
@ -3,6 +3,10 @@ package se.su.dsv.scipro.data.dao.interfaces;
|
||||
import se.su.dsv.scipro.data.dataobjects.FileDescription;
|
||||
|
||||
public interface FileDescriptionDao extends Dao<FileDescription> {
|
||||
|
||||
int countFileDescriptionByIdentifier(final String identifier);
|
||||
|
||||
int countFileDescriptionByPath(final String path);
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,13 @@
|
||||
package se.su.dsv.scipro.data.dao.jpa;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceException;
|
||||
import javax.persistence.TypedQuery;
|
||||
|
||||
import org.hibernate.ejb.QueryHints;
|
||||
import org.springframework.orm.jpa.JpaCallback;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import se.su.dsv.scipro.data.dao.interfaces.FileDescriptionDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.FileDescription;
|
||||
@ -18,5 +25,29 @@ public class FileDescriptionDaoJPAImp extends AbstractDaoJPAImp<FileDescription>
|
||||
super(FileDescription.class);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public int countFileDescriptionByIdentifier(final String identifier) {
|
||||
return getJpaTemplate().execute(new JpaCallback<Integer>() {
|
||||
public Integer doInJpa(EntityManager em) throws PersistenceException {
|
||||
TypedQuery<Long> query = em.createQuery("SELECT COUNT (fd) FROM FileDescription fd WHERE fd.identifier = :identifier", Long.class);
|
||||
query.setParameter("identifier", identifier);
|
||||
query.setHint(QueryHints.HINT_CACHEABLE, "true");
|
||||
return (query.getSingleResult()).intValue();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public int countFileDescriptionByPath(final String path) {
|
||||
return getJpaTemplate().execute(new JpaCallback<Integer>() {
|
||||
public Integer doInJpa(EntityManager em) throws PersistenceException {
|
||||
TypedQuery<Long> query = em.createQuery("SELECT COUNT (fd) FROM FileDescription fd WHERE fd.path = :path", Long.class);
|
||||
query.setParameter("path", path);
|
||||
query.setHint(QueryHints.HINT_CACHEABLE, "true");
|
||||
return (query.getSingleResult()).intValue();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,7 @@ import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.annotations.Cache;
|
||||
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
||||
import org.hibernate.annotations.Index;
|
||||
|
||||
|
||||
/**
|
||||
@ -49,7 +50,9 @@ public class FileDescription extends DomainObject implements Comparable<FileDesc
|
||||
private String name;
|
||||
private Date targetLastModified;
|
||||
private String mimeType;
|
||||
@Index(name="identifier_index") //Hibernate specific, just for performance
|
||||
private String identifier;
|
||||
@Index(name="path_index") //Hibernate specific, just for performance
|
||||
private String path;
|
||||
private Long userId = null;
|
||||
private Long size;
|
||||
|
@ -77,5 +77,9 @@ public class FolderDescription implements Serializable, Comparable<FolderDescrip
|
||||
public int compareTo(FolderDescription other) {
|
||||
return this.getName().compareToIgnoreCase(other.getName());
|
||||
}
|
||||
@Override
|
||||
public String toString(){
|
||||
return name;//+" "+created.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ import org.apache.wicket.spring.injection.annot.SpringBean;
|
||||
import org.apache.wicket.util.lang.Bytes;
|
||||
import org.apache.wicket.util.resource.IResourceStream;
|
||||
|
||||
import se.su.dsv.scipro.data.dao.interfaces.FileDescriptionDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.UserDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.FileDescription;
|
||||
import se.su.dsv.scipro.data.dataobjects.User;
|
||||
@ -43,6 +44,8 @@ public abstract class AbstractFilePanel extends Panel {
|
||||
|
||||
@SpringBean
|
||||
private UserDao userDao;
|
||||
@SpringBean
|
||||
private FileDescriptionDao fileDescriptionDao;
|
||||
|
||||
/**
|
||||
* A reference to the page that holds the FilePanel, required to be able to
|
||||
@ -186,6 +189,15 @@ public abstract class AbstractFilePanel extends Panel {
|
||||
if(target != null)
|
||||
target.addComponent(listFolders);
|
||||
}
|
||||
@Override
|
||||
public boolean isEnabled(){
|
||||
//Check if folder contains either files or folders, if it does we disable the delete link
|
||||
if(fileRepository.searchFiles(absolutePath+folderDescription.getName()).size() > 0)
|
||||
return false;
|
||||
if(fileRepository.searchFolders(absolutePath+folderDescription.getName()).size() > 0)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
delete.add(new Label("deleteIcon", "X"));
|
||||
inner.add(delete);
|
||||
@ -235,7 +247,7 @@ public abstract class AbstractFilePanel extends Panel {
|
||||
}
|
||||
|
||||
}));
|
||||
//System.out.println(desc.getPath());
|
||||
|
||||
inner.add(new Label("modified", df.format(desc.getTargetLastModified())));
|
||||
inner.add(new Label("size", fileRepository.formatBytes(desc.getSize())));
|
||||
inner.add(new Label("mimeType", desc.getMimeType()));
|
||||
@ -250,7 +262,6 @@ public abstract class AbstractFilePanel extends Panel {
|
||||
}
|
||||
inner.add(new Label("userId", userId));
|
||||
AjaxFallbackLink<Void> delete = new AjaxFallbackLink<Void>("delete") {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
@ -260,8 +271,13 @@ public abstract class AbstractFilePanel extends Panel {
|
||||
if(target != null)
|
||||
target.addComponent(listFiles);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(){
|
||||
//If the file has been linked to in a persisted FileDescription object, disable remove functionality
|
||||
return fileDescriptionDao.countFileDescriptionByPath(desc.getPath()) == 0;
|
||||
}
|
||||
};
|
||||
|
||||
delete.add(new Label("deleteIcon", "X"));
|
||||
inner.add(delete);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user