adds filePropertiesPanel to DocRepo and modifies minor stuff
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@3766 8810af33-2d31-482b-a856-94f89814c4dfpull/2/head
parent
c54956d642
commit
e1ad4b4347
|
|
@ -19,15 +19,18 @@
|
||||||
package org.libreccm.auditing;
|
package org.libreccm.auditing;
|
||||||
|
|
||||||
import org.hibernate.envers.AuditReader;
|
import org.hibernate.envers.AuditReader;
|
||||||
|
import org.hibernate.envers.exception.NotAuditedException;
|
||||||
import org.hibernate.envers.query.AuditEntity;
|
import org.hibernate.envers.query.AuditEntity;
|
||||||
import org.hibernate.envers.query.AuditQuery;
|
import org.hibernate.envers.query.AuditQuery;
|
||||||
import org.libreccm.core.AbstractEntityRepository;
|
import org.libreccm.core.AbstractEntityRepository;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a>
|
||||||
* @param <K> Primary key of the entity.
|
* @param <K> Primary key of the entity.
|
||||||
* @param <T> Type of the entity
|
* @param <T> Type of the entity
|
||||||
*/
|
*/
|
||||||
|
|
@ -58,4 +61,24 @@ public abstract class AbstractAuditedEntityRepository<K, T>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the number of revisions for a given entity.
|
||||||
|
*
|
||||||
|
* @param entity The entity
|
||||||
|
* @param objectId The primary key
|
||||||
|
*
|
||||||
|
* @return A list of revision numbers, at which the entity was modified,
|
||||||
|
* sorted in ascending order (so older revisions come first).
|
||||||
|
*
|
||||||
|
* @throws NotAuditedException When entities of the given class are not audited.
|
||||||
|
* @throws IllegalArgumentException If cls or primaryKey is null.
|
||||||
|
* @throws IllegalStateException If the associated entity manager is closed.
|
||||||
|
*/
|
||||||
|
public List<Number> retrieveRevisionNumbersOfEntity(final T entity,
|
||||||
|
Long objectId)
|
||||||
|
throws IllegalArgumentException, NotAuditedException,
|
||||||
|
IllegalStateException {
|
||||||
|
return auditReader.getRevisions(entity.getClass(), objectId);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,161 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2001-2004 Red Hat Inc. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2.1 of
|
||||||
|
* the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package com.arsdigita.docrepo.ui;
|
||||||
|
|
||||||
|
import com.arsdigita.bebop.PageState;
|
||||||
|
import com.arsdigita.bebop.SimpleComponent;
|
||||||
|
import com.arsdigita.docrepo.util.GlobalizationUtil;
|
||||||
|
import com.arsdigita.web.ParameterMap;
|
||||||
|
import com.arsdigita.web.URL;
|
||||||
|
import com.arsdigita.xml.Element;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import org.apache.shiro.authz.AuthorizationException;
|
||||||
|
import org.hibernate.envers.exception.NotAuditedException;
|
||||||
|
import org.libreccm.cdi.utils.CdiLookupException;
|
||||||
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
|
import org.libreccm.docrepo.File;
|
||||||
|
import org.libreccm.docrepo.Resource;
|
||||||
|
import org.libreccm.docrepo.ResourceRepository;
|
||||||
|
import org.libreccm.security.PermissionChecker;
|
||||||
|
import org.libreccm.security.User;
|
||||||
|
|
||||||
|
import javax.activation.MimeType;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A simple custom bebop component that summarizes the properties of a
|
||||||
|
* file in tabular form.
|
||||||
|
*
|
||||||
|
* @author StefanDeusch@computer.org, ddao@arsdigita.com
|
||||||
|
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
|
||||||
|
* @version $Id: FilePropertiesPanel.java pboy $
|
||||||
|
*/
|
||||||
|
public class FilePropertiesPanel extends SimpleComponent implements Constants {
|
||||||
|
|
||||||
|
private static final Logger log = Logger.getLogger(
|
||||||
|
FilePropertiesPanel.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates the XML for this container.
|
||||||
|
*
|
||||||
|
* @param state represents the current request
|
||||||
|
* @param parent the parent XML element
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void generateXML(PageState state, Element parent) {
|
||||||
|
// Get file id.
|
||||||
|
Long resourceId = (Long) state.getValue(FILE_ID_PARAM);
|
||||||
|
Element element = parent.newChildElement("docs:file-info", DOCS_XML_NS);
|
||||||
|
|
||||||
|
File file = null;
|
||||||
|
final CdiUtil cdiUtil = new CdiUtil();
|
||||||
|
ResourceRepository resourceRepository = null;
|
||||||
|
final PermissionChecker permissionChecker;
|
||||||
|
try {
|
||||||
|
resourceRepository = cdiUtil.findBean(ResourceRepository.class);
|
||||||
|
Resource resource = resourceRepository.findById(resourceId);
|
||||||
|
file = resource.isFile() ? (File) resource : null;
|
||||||
|
|
||||||
|
permissionChecker = cdiUtil.findBean(PermissionChecker.class);
|
||||||
|
// checks if the subject has permissions granting the privilege to
|
||||||
|
// 'read' the file
|
||||||
|
permissionChecker.checkPermission("read", file);
|
||||||
|
} catch (CdiLookupException ex) {
|
||||||
|
log.error(GlobalizationUtil.globalize("beanFinder.fail" +
|
||||||
|
".resourceRepository"), ex);
|
||||||
|
} catch (AuthorizationException authEx) {
|
||||||
|
log.error(GlobalizationUtil.globalize("ui.file.failure.privilege.read"),
|
||||||
|
authEx);
|
||||||
|
}
|
||||||
|
|
||||||
|
Element nameElement = element.newChildElement("docs:name", DOCS_XML_NS);
|
||||||
|
nameElement.setText(file.getName());
|
||||||
|
Element descriptionElement = element.newChildElement("docs:description",
|
||||||
|
DOCS_XML_NS);
|
||||||
|
String description = file.getDescription();
|
||||||
|
if (description != null) {
|
||||||
|
descriptionElement.setText(description);
|
||||||
|
}
|
||||||
|
|
||||||
|
Element sizeElement = element.newChildElement("docs:size", DOCS_XML_NS);
|
||||||
|
sizeElement.setText(Utils.FileSize.formatFileSize(file.getSize(), state));
|
||||||
|
Element typeElement = element.newChildElement("docs:type", DOCS_XML_NS);
|
||||||
|
|
||||||
|
// Retrieve pretty name for a mime type.
|
||||||
|
MimeType mimeType = file.getMimeType();
|
||||||
|
typeElement.setText(mimeType.getBaseType());
|
||||||
|
|
||||||
|
Element lastModifiedElement = element.newChildElement(
|
||||||
|
"docs:last-modified", DOCS_XML_NS);
|
||||||
|
lastModifiedElement.setText(Utils.DateFormat.format(
|
||||||
|
file.getLastModifiedDate()));
|
||||||
|
|
||||||
|
Element revisionElement = element.newChildElement("docs:revision",
|
||||||
|
DOCS_XML_NS);
|
||||||
|
|
||||||
|
long numRevs = 0; // if there aren't any revisions 0 is accurate
|
||||||
|
if (resourceRepository != null) {
|
||||||
|
try {
|
||||||
|
numRevs = resourceRepository.retrieveRevisionNumbersOfEntity(
|
||||||
|
file, file.getObjectId()).size();
|
||||||
|
} catch (IllegalArgumentException |
|
||||||
|
NotAuditedException |
|
||||||
|
IllegalStateException ex) {
|
||||||
|
log.error(GlobalizationUtil.globalize("ui.file.failure" +
|
||||||
|
".retrieve.revisionNumber"), ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//deprecated: exchanged through the above
|
||||||
|
//TransactionCollection tc = file.getTransactions();
|
||||||
|
//long numRevs = tc.size();
|
||||||
|
revisionElement.setText(numRevs + "");
|
||||||
|
|
||||||
|
// Must allow for the possibility that not author is available.
|
||||||
|
|
||||||
|
Element authorElement = element.newChildElement("docs:author",
|
||||||
|
DOCS_XML_NS);
|
||||||
|
User author = file.getCreationUser();
|
||||||
|
if (author != null) {
|
||||||
|
authorElement.setText(author.getName());
|
||||||
|
} else {
|
||||||
|
authorElement.setText("Unknown");
|
||||||
|
}
|
||||||
|
|
||||||
|
Element uriElement = element.newChildElement("docs:uri", DOCS_XML_NS);
|
||||||
|
uriElement.setText(makeFileURL(file, state));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Makes an url for a given file.
|
||||||
|
*
|
||||||
|
* @param file The file
|
||||||
|
* @param state The page state
|
||||||
|
*
|
||||||
|
* @return The url to the file
|
||||||
|
*/
|
||||||
|
private static String makeFileURL(File file, PageState state) {
|
||||||
|
final HttpServletRequest req = state.getRequest();
|
||||||
|
|
||||||
|
final ParameterMap params = new ParameterMap();
|
||||||
|
params.setParameter(FILE_ID_PARAM.getName(), file.getObjectId());
|
||||||
|
|
||||||
|
return URL.here(req, "/download/" + file.getName(), params).toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -27,8 +27,10 @@ import javax.persistence.Entity;
|
||||||
import javax.persistence.JoinColumn;
|
import javax.persistence.JoinColumn;
|
||||||
import javax.persistence.NamedQueries;
|
import javax.persistence.NamedQueries;
|
||||||
import javax.persistence.NamedQuery;
|
import javax.persistence.NamedQuery;
|
||||||
|
import javax.persistence.OneToMany;
|
||||||
import javax.persistence.OneToOne;
|
import javax.persistence.OneToOne;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Entity class of a repository for documents. Instances will be persisted into
|
* Entity class of a repository for documents. Instances will be persisted into
|
||||||
|
|
@ -70,6 +72,13 @@ public class Repository extends CcmApplication {
|
||||||
@NotBlank
|
@NotBlank
|
||||||
private User owner;
|
private User owner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All {@link Resource}s contained in this {@code Repository}.
|
||||||
|
*/
|
||||||
|
@OneToMany(mappedBy = "repository")
|
||||||
|
private List<Resource> resources;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor calls the super-class-constructor of {@link CcmApplication}.
|
* Constructor calls the super-class-constructor of {@link CcmApplication}.
|
||||||
*/
|
*/
|
||||||
|
|
@ -103,6 +112,14 @@ public class Repository extends CcmApplication {
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Resource> getResources() {
|
||||||
|
return resources;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setResources(List<Resource> resources) {
|
||||||
|
this.resources = resources;
|
||||||
|
}
|
||||||
|
|
||||||
//< End GETTER & SETTER
|
//< End GETTER & SETTER
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -72,4 +72,5 @@ public class RepositoryRepository extends
|
||||||
|
|
||||||
return query.getResultList();
|
return query.getResultList();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ import org.hibernate.validator.constraints.NotBlank;
|
||||||
import org.libreccm.core.CcmObject;
|
import org.libreccm.core.CcmObject;
|
||||||
import org.libreccm.security.User;
|
import org.libreccm.security.User;
|
||||||
|
|
||||||
|
import javax.activation.MimeType;
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.JoinColumn;
|
import javax.persistence.JoinColumn;
|
||||||
|
|
@ -33,7 +34,6 @@ import javax.persistence.OneToOne;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
import javax.persistence.Temporal;
|
import javax.persistence.Temporal;
|
||||||
import javax.persistence.TemporalType;
|
import javax.persistence.TemporalType;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
@ -98,7 +98,7 @@ public abstract class Resource extends CcmObject {
|
||||||
* Mime-type of the {@code Resource}.
|
* Mime-type of the {@code Resource}.
|
||||||
*/
|
*/
|
||||||
@Column(name = "MIME_TYPE")
|
@Column(name = "MIME_TYPE")
|
||||||
private String mimeType;
|
private MimeType mimeType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Size of the {@code Resource}.
|
* Size of the {@code Resource}.
|
||||||
|
|
@ -168,6 +168,13 @@ public abstract class Resource extends CcmObject {
|
||||||
@OneToMany(mappedBy = "parent")
|
@OneToMany(mappedBy = "parent")
|
||||||
private List<Resource> immediateChildren;
|
private List<Resource> immediateChildren;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The {@link Repository} containing this {@code Resource}.
|
||||||
|
*/
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "REPOSITORY_ID")
|
||||||
|
private Repository repository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor calls the super-class-constructor of {@link CcmObject}.
|
* Constructor calls the super-class-constructor of {@link CcmObject}.
|
||||||
*/
|
*/
|
||||||
|
|
@ -209,11 +216,11 @@ public abstract class Resource extends CcmObject {
|
||||||
this.path = path;
|
this.path = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMimeType() {
|
public MimeType getMimeType() {
|
||||||
return mimeType;
|
return mimeType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMimeType(String mimeType) {
|
public void setMimeType(MimeType mimeType) {
|
||||||
this.mimeType = mimeType;
|
this.mimeType = mimeType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -297,6 +304,14 @@ public abstract class Resource extends CcmObject {
|
||||||
this.immediateChildren = immediateChildren;
|
this.immediateChildren = immediateChildren;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Repository getRepository() {
|
||||||
|
return repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRepository(Repository repository) {
|
||||||
|
this.repository = repository;
|
||||||
|
}
|
||||||
|
|
||||||
//< End GETTER & SETTER
|
//< End GETTER & SETTER
|
||||||
|
|
||||||
public boolean isRoot() {
|
public boolean isRoot() {
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ package org.libreccm.docrepo;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.apache.oro.text.perl.Perl5Util;
|
import org.apache.oro.text.perl.Perl5Util;
|
||||||
|
|
||||||
|
import javax.activation.MimetypesFileTypeMap;
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
|
@ -95,9 +96,13 @@ public class ResourceManager {
|
||||||
boolean validName = !(perl5Util.match(INVALID_START_PATTERN, name) ||
|
boolean validName = !(perl5Util.match(INVALID_START_PATTERN, name) ||
|
||||||
perl5Util.match(INVALID_NAME_PATTERN, name));
|
perl5Util.match(INVALID_NAME_PATTERN, name));
|
||||||
|
|
||||||
// checks duplication of the name, database access (mind performance)
|
// checks duplication of the name; database access (mind performance)
|
||||||
validName &= resourceRepository.findByName(name).isEmpty();
|
validName &= resourceRepository.findByName(name).isEmpty();
|
||||||
|
|
||||||
|
// checks that the name corresponds to a compatible MIME type
|
||||||
|
validName &= new MimetypesFileTypeMap().getContentType(name).equals
|
||||||
|
(resource.getMimeType().toString());
|
||||||
|
|
||||||
return validName;
|
return validName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -77,3 +77,6 @@ ui.folder.choose_destination=Please choose a destination
|
||||||
ui.file.name.invalid=The filename is not valid.
|
ui.file.name.invalid=The filename is not valid.
|
||||||
beanFinder.fail.resourceRepository=Failed to find bean for the ResourceRepository.
|
beanFinder.fail.resourceRepository=Failed to find bean for the ResourceRepository.
|
||||||
beanFinder.fail.resourceManager=Failed to find bean for the ResourceManager.
|
beanFinder.fail.resourceManager=Failed to find bean for the ResourceManager.
|
||||||
|
ui.file.failure.privilege.read=You do not have the permission granting you the privilege to the read the chosen file.
|
||||||
|
beanFinder.fail.repositoryRepository=Failed to find bean for the RepositoryRepository.
|
||||||
|
ui.file.failure.retrieve.revisionNumber=Wasn't able to retrieve the revision numbers for the given file.
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
ui.action.edit.copy=Kopieren
|
ui.action.edit.copy=Kopieren
|
||||||
ui.action.edit.cut=Ausschneiden
|
ui.action.edit.cut=Ausschneiden
|
||||||
ui.action.edit.delete=Löschen
|
ui.action.edit.delete=Löschen
|
||||||
ui.action.error=Folgende(r) Fehler trat(en) auf:
|
ui.action.error=Folgende(r) Fehler trat(en) auf\:
|
||||||
ui.action.error.continue=Fortfahren
|
ui.action.error.continue=Fortfahren
|
||||||
ui.action.submit.delete=L\u00f6schen
|
ui.action.submit.delete=L\u00f6schen
|
||||||
ui.action.confirm.delete='Sollen die ausgew\u00e4hlten Dateien und Ordner tats\u00e4chlich gel\u00f6scht werden?'
|
ui.action.confirm.delete='Sollen die ausgew\u00e4hlten Dateien und Ordner tats\u00e4chlich gel\u00f6scht werden?'
|
||||||
|
|
@ -22,7 +22,7 @@ ui.file.name.required=Name: (*)
|
||||||
ui.file.save=Sichern
|
ui.file.save=Sichern
|
||||||
ui.file.submit=Upload
|
ui.file.submit=Upload
|
||||||
ui.file.source=Quelle:
|
ui.file.source=Quelle:
|
||||||
ui.file.version.description=Version Description: (*)
|
ui.file.version.description=Version Description\: (*)
|
||||||
ui.file.upload.header=Upload File into Folder
|
ui.file.upload.header=Upload File into Folder
|
||||||
ui.file.confirm.delete=Do you really want to delete this file?
|
ui.file.confirm.delete=Do you really want to delete this file?
|
||||||
ui.fileinfo.goback.label=Return to
|
ui.fileinfo.goback.label=Return to
|
||||||
|
|
@ -77,3 +77,6 @@ ui.folder.choose_destination=Bitte w\u00e4hle ein Ziel
|
||||||
ui.file.name.invalid=Der Dateiname ist nicht gültig.
|
ui.file.name.invalid=Der Dateiname ist nicht gültig.
|
||||||
beanFinder.fail.resourceRepository=Das Finden der Bean für das ResourceRepository schlug fehl.
|
beanFinder.fail.resourceRepository=Das Finden der Bean für das ResourceRepository schlug fehl.
|
||||||
beanFinder.fail.resourceManager=Das Finden der Bean für den ResourceManager schlug fehl.
|
beanFinder.fail.resourceManager=Das Finden der Bean für den ResourceManager schlug fehl.
|
||||||
|
ui.file.failure.privilege.read=Sie haben nicht die Erlaubnis, die ihnen das Recht gibt, die ausgewählte Datei zu lesen.
|
||||||
|
beanFinder.fail.repositoryRepository=Das Finden der Bean für das RepositoryRepository schlug fehl.
|
||||||
|
ui.file.failure.retrieve.revisionNumber=Es war nicht möglich, die Revisionsnummern für die gegebene Datei wiederzuholen.
|
||||||
|
|
|
||||||
|
|
@ -77,3 +77,6 @@ ui.folder.choose_destination=Please choose a destination
|
||||||
ui.file.name.invalid=The filename is not valid.
|
ui.file.name.invalid=The filename is not valid.
|
||||||
beanFinder.fail.resourceRepository=Failed to find bean for the ResourceRepository.
|
beanFinder.fail.resourceRepository=Failed to find bean for the ResourceRepository.
|
||||||
beanFinder.fail.resourceManager=Failed to find bean for the ResourceManager.
|
beanFinder.fail.resourceManager=Failed to find bean for the ResourceManager.
|
||||||
|
ui.file.failure.privilege.read=You do not have the permission granting you the privilege to the read the chosen file.
|
||||||
|
beanFinder.fail.repositoryRepository=Failed to find bean for the RepositoryRepository.
|
||||||
|
ui.file.failure.retrieve.revisionNumber=Wasn't able to retrieve the revision numbers for the given file.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue