CCM_NG - docrepo

- removed the CdiLookupExceptions
- added db.notfound.file/folder/resources to the Resources.properties

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@3771 8810af33-2d31-482b-a856-94f89814c4df
pull/2/head
tosmers 2015-12-16 15:03:45 +00:00
parent 3f27e09a84
commit 5b1121e264
9 changed files with 119 additions and 138 deletions

View File

@ -46,7 +46,6 @@ import com.arsdigita.bebop.parameters.BigDecimalParameter;
import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.xml.Element;
import org.libreccm.cdi.utils.CdiLookupException;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.docrepo.File;
import org.libreccm.docrepo.Resource;
@ -161,28 +160,24 @@ public class BrowsePane extends ModalContainer implements Constants, ChangeListe
// need this only when coming from 1-file page
if (fileId != null) {
final CdiUtil cdiUtil = new CdiUtil();
final ResourceRepository resourceRepository;
try {
resourceRepository = cdiUtil.findBean(ResourceRepository.class);
File file = (File) resourceRepository.findById(fileId);
Resource parent = file.getParent();
key = Long.toString(parent.getObjectId());
final ResourceRepository resourceRepository = cdiUtil.findBean(
ResourceRepository.class);
final File file = (File) resourceRepository.findById(fileId);
while (!parent.isRoot()) {
parent = parent.getParent();
String nextKey = Long.toString(parent.getObjectId());
m_tree.expand(nextKey, state);
}
Resource parent = file.getParent();
key = Long.toString(parent.getObjectId());
// to display this file's folder in the table
m_tree.setSelectedKey(state, key);
// now wipe out file param to avoid trouble elsewhere
state.setValue(m_fileIdParam, null);
} catch (CdiLookupException e) {
throw new IllegalStateException(String.format(
"Failed to retrieve file %d from the database.", fileId));
while (!parent.isRoot()) {
parent = parent.getParent();
String nextKey = Long.toString(parent.getObjectId());
m_tree.expand(nextKey, state);
}
// to display this file's folder in the table
m_tree.setSelectedKey(state, key);
// now wipe out file param to avoid trouble elsewhere
state.setValue(m_fileIdParam, null);
}
// finally expand selected folder

View File

@ -36,7 +36,6 @@ import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.web.Web;
import com.arsdigita.xml.Element;
import org.apache.log4j.Logger;
import org.libreccm.cdi.utils.CdiLookupException;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.docrepo.Folder;
import org.libreccm.docrepo.Repository;
@ -45,6 +44,7 @@ import org.libreccm.docrepo.ResourceManager;
import org.libreccm.docrepo.ResourceRepository;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
@ -189,43 +189,37 @@ public class DestinationFolderForm extends Form implements FormInitListener,
}
final CdiUtil cdiUtil = new CdiUtil();
final ResourceRepository resourceRepository;
final ResourceManager resourceManager;
try {
resourceRepository = cdiUtil.findBean(ResourceRepository.class);
resourceManager = cdiUtil.findBean(ResourceManager.class);
final ResourceRepository resourceRepository = cdiUtil.findBean(
ResourceRepository.class);
final ResourceManager resourceManager = cdiUtil.findBean(
ResourceManager.class);
Folder folder = (Folder) resourceRepository.findById(folderId);
if (folder == null) {
isError = true;
log.error(String.format("Couldn't find folder %d in the " +
"database.", folderId));
}
String[] resourceStrings = (String[]) m_resourceList.getValue(state);
for (String resourceString : resourceStrings) {
Long resourceId = Long.valueOf(resourceString);
Resource resource = resourceRepository.findById(resourceId);
if (resource == null) {
errorList.add(resourceString);
log.debug(String.format("Couldn't find selected resource " +
"%d in the database.", resourceId));
continue;
}
// Knowledge, weather its a folder or a file is not necessary
if (isCopy) {
resourceManager.copyToFolder(resource, folder);
} else {
resource.setParent(folder);
resourceRepository.save(resource);
}
}
} catch (CdiLookupException ex) {
final Folder folder = (Folder) resourceRepository.findById(folderId);
if (folder == null) {
isError = true;
log.error("Failed to find bean for either ResourceRepository or " +
"ResourceManager.", ex);
log.error(GlobalizationUtil.globalize("db.notfound.folder",
Arrays.asList(folderId).toArray()));
}
String[] resourceStrings = (String[]) m_resourceList.getValue(state);
for (String resourceString : resourceStrings) {
Long resourceId = Long.valueOf(resourceString);
Resource resource = resourceRepository.findById(resourceId);
if (resource == null) {
errorList.add(resourceString);
log.debug(GlobalizationUtil.globalize("db.notfound.resource",
Arrays.asList(resourceId).toArray()));
continue;
}
// Knowledge, weather it's a folder or a file is not necessary
if (isCopy) {
resourceManager.copyToFolder(resource, folder);
} else {
resource.setParent(folder);
resourceRepository.save(resource);
}
}
if (isError) {
@ -280,19 +274,13 @@ public class DestinationFolderForm extends Form implements FormInitListener,
public void generateXML(PageState state, Element parent) {
Element treeElement = parent.newChildElement("bebop:tree", BEBOP_XML_NS);
// Todo: notwendig?
Folder sourceFolder = null;
Long sourceFolderId = (m_parent.getFolderID(state)).longValue();
final CdiUtil cdiUtil = new CdiUtil();
final ResourceRepository resourceRepository;
try {
resourceRepository = cdiUtil.findBean(ResourceRepository.class);
sourceFolder = (Folder) resourceRepository.findById
(sourceFolderId);
} catch (CdiLookupException ex) {
log.error("Failed to find bean for the ResourceRepository.", ex);
}
final ResourceRepository resourceRepository = cdiUtil.findBean(
ResourceRepository.class);
final Folder sourceFolder = (Folder) resourceRepository.findById(
sourceFolderId);
if (sourceFolder != null) {
HashMap map = new HashMap();
@ -319,8 +307,8 @@ public class DestinationFolderForm extends Form implements FormInitListener,
}
}
} else {
log.error(String.format("Couldn't find the source folder %d " +
"in the database.", sourceFolderId));
log.error(GlobalizationUtil.globalize("db.notfound.folder",
Arrays.asList(sourceFolderId).toArray()));
}
}

View File

@ -20,13 +20,15 @@ package com.arsdigita.docrepo.ui;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.RequestLocal;
import com.arsdigita.docrepo.util.GlobalizationUtil;
import org.apache.log4j.Logger;
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 java.util.Arrays;
/**
* Same as the {@link RequestLocal} but overrides the
* {@code initialValue} uniquely for {@code DocRepo} classes.
@ -41,18 +43,22 @@ public class DocRepoRequestLocal extends RequestLocal
DocRepoRequestLocal.class);
@Override
protected Object initialValue(PageState state) {
protected File initialValue(PageState state) {
Long id = (Long) state.getValue(FILE_ID_PARAM);
File file = null;
final CdiUtil cdiUtil = new CdiUtil();
final ResourceRepository resourceRepository;
try {
resourceRepository = cdiUtil.findBean(ResourceRepository.class);
Resource resource = resourceRepository.findById(id);
file = resource.isFile() ? (File) resource : null;
} catch(CdiLookupException ex) {
log.error("Failed to find bean for the ResourceRepository.", ex);
final ResourceRepository resourceRepository = cdiUtil.findBean(
ResourceRepository.class);
final Resource resource = resourceRepository.findById(id);
File file = resource != null && resource.isFile() ? (File) resource :
null;
if (file == null) {
log.error(GlobalizationUtil.globalize("db.notfound.file",
Arrays.asList(id).toArray()));
}
return file;
}
}

View File

@ -29,15 +29,16 @@ import com.arsdigita.bebop.event.ActionListener;
import com.arsdigita.bebop.event.PrintEvent;
import com.arsdigita.bebop.event.PrintListener;
import com.arsdigita.dispatcher.DispatcherHelper;
import com.arsdigita.docrepo.util.GlobalizationUtil;
import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.web.Web;
import org.apache.log4j.Logger;
import org.libreccm.cdi.utils.CdiLookupException;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.docrepo.File;
import org.libreccm.docrepo.ResourceRepository;
import java.io.IOException;
import java.util.Arrays;
/**
@ -69,24 +70,19 @@ public class FileActionPane extends ColumnPanel implements Constants {
m_parent = parent;
m_fileData = new RequestLocal() {
protected Object initialValue(PageState state) {
File file = null;
protected File initialValue(PageState state) {
Long fileId = (Long) state.getValue
(FILE_ID_PARAM);
final CdiUtil cdiUtil = new CdiUtil();
final ResourceRepository resourceRepository;
try {
resourceRepository = cdiUtil.findBean(ResourceRepository.class);
file = (File) resourceRepository.findById(fileId);
if (file == null) {
log.error(String.format("Couldn't find the file %d in" +
" the database.", fileId));
}
} catch(CdiLookupException ex) {
log.error("Failed to find bean for the " +
"ResourceRepository.", ex);
final ResourceRepository resourceRepository = cdiUtil
.findBean(ResourceRepository.class);
final File file = (File) resourceRepository.findById(fileId);
if (file == null) {
log.error(GlobalizationUtil.globalize("db.notfound.file",
Arrays.asList(fileId).toArray()));
}
return file;
}
};
@ -169,9 +165,8 @@ public class FileActionPane extends ColumnPanel implements Constants {
Long parentFolderId = file.getParent().getObjectId();
final CdiUtil cdiUtil = new CdiUtil();
final ResourceRepository resourceRepository;
try {
resourceRepository = cdiUtil.findBean(ResourceRepository.class);
final ResourceRepository resourceRepository = cdiUtil.findBean
(ResourceRepository.class);
// Todo: replace KernelExcursion
// KernelExcursion ex = new KernelExcursion() {
@ -182,11 +177,6 @@ public class FileActionPane extends ColumnPanel implements Constants {
// };
// ex.run();
} catch (CdiLookupException ex) {
log.error("Failed to find bean for the " +
"ResourceRepository.", ex);
}
try {
String appURI = getRedirectURI(state);

View File

@ -36,13 +36,14 @@ import com.arsdigita.bebop.parameters.NotEmptyValidationListener;
import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.docrepo.util.GlobalizationUtil;
import org.apache.log4j.Logger;
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.ResourceManager;
import org.libreccm.docrepo.ResourceRepository;
import java.util.Arrays;
//import com.arsdigita.docrepo.File;
//import com.arsdigita.docrepo.Folder;
@ -124,15 +125,17 @@ public class FileEditForm extends Form implements FormValidationListener,
Long fileId = (Long) state.getValue(FILE_ID_PARAM);
final CdiUtil cdiUtil = new CdiUtil();
final ResourceRepository resourceRepository;
try {
resourceRepository = cdiUtil.findBean(ResourceRepository.class);
File file = (File) resourceRepository.findById(fileId);
data.put(FILE_EDIT_FNAME, file.getName());
data.put(FILE_EDIT_DESCRIPTION, file.getDescription());
} catch (CdiLookupException ex) {
log.error("Failed to find bean for ResourceRepository.", ex);
final ResourceRepository resourceRepository = cdiUtil.findBean(
ResourceRepository.class);
final File file = (File) resourceRepository.findById(fileId);
if (file == null) {
log.error(GlobalizationUtil.globalize("db.notfound.file",
Arrays.asList(fileId).toArray()));
}
data.put(FILE_EDIT_FNAME, file.getName());
data.put(FILE_EDIT_DESCRIPTION, file.getDescription());
}
/**
@ -148,18 +151,15 @@ public class FileEditForm extends Form implements FormValidationListener,
FormData data = event.getFormData();
Long resourceId = (Long) state.getValue(FILE_ID_PARAM);
File file = null;
ResourceManager resourceManager = null;
final CdiUtil cdiUtil = new CdiUtil();
final ResourceRepository resourceRepository;
try {
resourceRepository = cdiUtil.findBean(ResourceRepository.class);
Resource resource = resourceRepository.findById(resourceId);
file = resource.isFile() ? (File) resource : null;
resourceManager = cdiUtil.findBean(ResourceManager.class);
} catch (CdiLookupException ex) {
log.error("Failed to find bean for the ResourceManager.", ex);
}
final ResourceRepository resourceRepository = cdiUtil.findBean(
ResourceRepository.class);
final ResourceManager resourceManager = cdiUtil.findBean(
ResourceManager.class);
final Resource resource = resourceRepository.findById(resourceId);
final File file = resource.isFile() ? (File) resource : null;
if (resourceManager != null && file != null) {
String fname = (String) data.get(FILE_EDIT_FNAME);
@ -185,21 +185,18 @@ public class FileEditForm extends Form implements FormValidationListener,
Long fileId = (Long) state.getValue(FILE_ID_PARAM);
final CdiUtil cdiUtil = new CdiUtil();
final ResourceRepository resourceRepository;
try {
resourceRepository = cdiUtil.findBean(ResourceRepository.class);
File file = (File) resourceRepository.findById(fileId);
if (file != null) {
file.setName(fname);
file.setDescription(fdesc);
resourceRepository.save(file);
} else {
log. error(String.format("Couldn't find file %d in the " +
"database.", fileId));
}
} catch (CdiLookupException ex) {
log.error("Failed to find bean for ResourceRepository.", ex);
final ResourceRepository resourceRepository = cdiUtil.findBean(
ResourceRepository.class);
File file = (File) resourceRepository.findById(fileId);
if (file != null) {
file.setName(fname);
file.setDescription(fdesc);
resourceRepository.save(file);
} else {
log. error(String.format("Couldn't find file %d in the " +
"database.", fileId));
}
m_parent.displayPropertiesAndActions(state);
}
}

View File

@ -27,7 +27,6 @@ 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;
@ -76,9 +75,6 @@ public class FilePropertiesPanel extends SimpleComponent implements Constants {
// 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);

View File

@ -80,3 +80,6 @@ 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.
db.notfound.file=Couldn't find the file %d in the database.
db.notfound.folder=Couldn't find folder %d in the database.
db.notfound.resource=Couldn't find resource %d in the database.

View File

@ -80,3 +80,6 @@ beanFinder.fail.resourceManager=Das Finden der Bean für den ResourceManager sch
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.
db.notfound.file=Die Datei %d konnte in der Datenbank nicht gefunden werden.
db.notfound.folder=Der Ordner %d konnte in der Datenbank nicht gefunden werden.
db.notfound.resource=Die Resource %d konnte in der Datenbank nicht gefunden werden.

View File

@ -80,3 +80,6 @@ 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.
db.notfound.file=Couldn't find the file %d in the database.
db.notfound.folder=Couldn't find folder %d in the database.
db.notfound.resource=Couldn't find resource %d in the database.