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

View File

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

View File

@ -20,13 +20,15 @@ package com.arsdigita.docrepo.ui;
import com.arsdigita.bebop.PageState; import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.RequestLocal; import com.arsdigita.bebop.RequestLocal;
import com.arsdigita.docrepo.util.GlobalizationUtil;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.libreccm.cdi.utils.CdiLookupException;
import org.libreccm.cdi.utils.CdiUtil; import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.docrepo.File; import org.libreccm.docrepo.File;
import org.libreccm.docrepo.Resource; import org.libreccm.docrepo.Resource;
import org.libreccm.docrepo.ResourceRepository; import org.libreccm.docrepo.ResourceRepository;
import java.util.Arrays;
/** /**
* Same as the {@link RequestLocal} but overrides the * Same as the {@link RequestLocal} but overrides the
* {@code initialValue} uniquely for {@code DocRepo} classes. * {@code initialValue} uniquely for {@code DocRepo} classes.
@ -41,18 +43,22 @@ public class DocRepoRequestLocal extends RequestLocal
DocRepoRequestLocal.class); DocRepoRequestLocal.class);
@Override @Override
protected Object initialValue(PageState state) { protected File initialValue(PageState state) {
Long id = (Long) state.getValue(FILE_ID_PARAM); Long id = (Long) state.getValue(FILE_ID_PARAM);
File file = null;
final CdiUtil cdiUtil = new CdiUtil(); final CdiUtil cdiUtil = new CdiUtil();
final ResourceRepository resourceRepository; final ResourceRepository resourceRepository = cdiUtil.findBean(
try { ResourceRepository.class);
resourceRepository = cdiUtil.findBean(ResourceRepository.class); final Resource resource = resourceRepository.findById(id);
Resource resource = resourceRepository.findById(id);
file = resource.isFile() ? (File) resource : null; File file = resource != null && resource.isFile() ? (File) resource :
} catch(CdiLookupException ex) { null;
log.error("Failed to find bean for the ResourceRepository.", ex);
if (file == null) {
log.error(GlobalizationUtil.globalize("db.notfound.file",
Arrays.asList(id).toArray()));
} }
return file; 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.PrintEvent;
import com.arsdigita.bebop.event.PrintListener; import com.arsdigita.bebop.event.PrintListener;
import com.arsdigita.dispatcher.DispatcherHelper; import com.arsdigita.dispatcher.DispatcherHelper;
import com.arsdigita.docrepo.util.GlobalizationUtil;
import com.arsdigita.globalization.GlobalizedMessage; import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.web.Web; import com.arsdigita.web.Web;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.libreccm.cdi.utils.CdiLookupException;
import org.libreccm.cdi.utils.CdiUtil; import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.docrepo.File; import org.libreccm.docrepo.File;
import org.libreccm.docrepo.ResourceRepository; import org.libreccm.docrepo.ResourceRepository;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays;
/** /**
@ -69,24 +70,19 @@ public class FileActionPane extends ColumnPanel implements Constants {
m_parent = parent; m_parent = parent;
m_fileData = new RequestLocal() { m_fileData = new RequestLocal() {
protected Object initialValue(PageState state) { protected File initialValue(PageState state) {
File file = null;
Long fileId = (Long) state.getValue Long fileId = (Long) state.getValue
(FILE_ID_PARAM); (FILE_ID_PARAM);
final CdiUtil cdiUtil = new CdiUtil(); final CdiUtil cdiUtil = new CdiUtil();
final ResourceRepository resourceRepository; final ResourceRepository resourceRepository = cdiUtil
try { .findBean(ResourceRepository.class);
resourceRepository = cdiUtil.findBean(ResourceRepository.class); final File file = (File) resourceRepository.findById(fileId);
file = (File) resourceRepository.findById(fileId);
if (file == null) { if (file == null) {
log.error(String.format("Couldn't find the file %d in" + log.error(GlobalizationUtil.globalize("db.notfound.file",
" the database.", fileId)); Arrays.asList(fileId).toArray()));
}
} catch(CdiLookupException ex) {
log.error("Failed to find bean for the " +
"ResourceRepository.", ex);
} }
return file; return file;
} }
}; };
@ -169,9 +165,8 @@ public class FileActionPane extends ColumnPanel implements Constants {
Long parentFolderId = file.getParent().getObjectId(); Long parentFolderId = file.getParent().getObjectId();
final CdiUtil cdiUtil = new CdiUtil(); final CdiUtil cdiUtil = new CdiUtil();
final ResourceRepository resourceRepository; final ResourceRepository resourceRepository = cdiUtil.findBean
try { (ResourceRepository.class);
resourceRepository = cdiUtil.findBean(ResourceRepository.class);
// Todo: replace KernelExcursion // Todo: replace KernelExcursion
// KernelExcursion ex = new KernelExcursion() { // KernelExcursion ex = new KernelExcursion() {
@ -182,11 +177,6 @@ public class FileActionPane extends ColumnPanel implements Constants {
// }; // };
// ex.run(); // ex.run();
} catch (CdiLookupException ex) {
log.error("Failed to find bean for the " +
"ResourceRepository.", ex);
}
try { try {
String appURI = getRedirectURI(state); 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.bebop.parameters.StringParameter;
import com.arsdigita.docrepo.util.GlobalizationUtil; import com.arsdigita.docrepo.util.GlobalizationUtil;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.libreccm.cdi.utils.CdiLookupException;
import org.libreccm.cdi.utils.CdiUtil; import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.docrepo.File; import org.libreccm.docrepo.File;
import org.libreccm.docrepo.Resource; import org.libreccm.docrepo.Resource;
import org.libreccm.docrepo.ResourceManager; import org.libreccm.docrepo.ResourceManager;
import org.libreccm.docrepo.ResourceRepository; import org.libreccm.docrepo.ResourceRepository;
import java.util.Arrays;
//import com.arsdigita.docrepo.File; //import com.arsdigita.docrepo.File;
//import com.arsdigita.docrepo.Folder; //import com.arsdigita.docrepo.Folder;
@ -124,15 +125,17 @@ public class FileEditForm extends Form implements FormValidationListener,
Long fileId = (Long) state.getValue(FILE_ID_PARAM); Long fileId = (Long) state.getValue(FILE_ID_PARAM);
final CdiUtil cdiUtil = new CdiUtil(); final CdiUtil cdiUtil = new CdiUtil();
final ResourceRepository resourceRepository; final ResourceRepository resourceRepository = cdiUtil.findBean(
try { ResourceRepository.class);
resourceRepository = cdiUtil.findBean(ResourceRepository.class); final File file = (File) resourceRepository.findById(fileId);
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_FNAME, file.getName());
data.put(FILE_EDIT_DESCRIPTION, file.getDescription()); data.put(FILE_EDIT_DESCRIPTION, file.getDescription());
} catch (CdiLookupException ex) {
log.error("Failed to find bean for ResourceRepository.", ex);
}
} }
/** /**
@ -148,18 +151,15 @@ public class FileEditForm extends Form implements FormValidationListener,
FormData data = event.getFormData(); FormData data = event.getFormData();
Long resourceId = (Long) state.getValue(FILE_ID_PARAM); Long resourceId = (Long) state.getValue(FILE_ID_PARAM);
File file = null;
ResourceManager resourceManager = null;
final CdiUtil cdiUtil = new CdiUtil(); final CdiUtil cdiUtil = new CdiUtil();
final ResourceRepository resourceRepository; final ResourceRepository resourceRepository = cdiUtil.findBean(
try { ResourceRepository.class);
resourceRepository = cdiUtil.findBean(ResourceRepository.class); final ResourceManager resourceManager = cdiUtil.findBean(
Resource resource = resourceRepository.findById(resourceId); ResourceManager.class);
file = resource.isFile() ? (File) resource : null;
resourceManager = cdiUtil.findBean(ResourceManager.class); final Resource resource = resourceRepository.findById(resourceId);
} catch (CdiLookupException ex) { final File file = resource.isFile() ? (File) resource : null;
log.error("Failed to find bean for the ResourceManager.", ex);
}
if (resourceManager != null && file != null) { if (resourceManager != null && file != null) {
String fname = (String) data.get(FILE_EDIT_FNAME); String fname = (String) data.get(FILE_EDIT_FNAME);
@ -185,9 +185,8 @@ public class FileEditForm extends Form implements FormValidationListener,
Long fileId = (Long) state.getValue(FILE_ID_PARAM); Long fileId = (Long) state.getValue(FILE_ID_PARAM);
final CdiUtil cdiUtil = new CdiUtil(); final CdiUtil cdiUtil = new CdiUtil();
final ResourceRepository resourceRepository; final ResourceRepository resourceRepository = cdiUtil.findBean(
try { ResourceRepository.class);
resourceRepository = cdiUtil.findBean(ResourceRepository.class);
File file = (File) resourceRepository.findById(fileId); File file = (File) resourceRepository.findById(fileId);
if (file != null) { if (file != null) {
file.setName(fname); file.setName(fname);
@ -197,9 +196,7 @@ public class FileEditForm extends Form implements FormValidationListener,
log. error(String.format("Couldn't find file %d in the " + log. error(String.format("Couldn't find file %d in the " +
"database.", fileId)); "database.", fileId));
} }
} catch (CdiLookupException ex) {
log.error("Failed to find bean for ResourceRepository.", ex);
}
m_parent.displayPropertiesAndActions(state); m_parent.displayPropertiesAndActions(state);
} }
} }

View File

@ -27,7 +27,6 @@ import com.arsdigita.xml.Element;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.apache.shiro.authz.AuthorizationException; import org.apache.shiro.authz.AuthorizationException;
import org.hibernate.envers.exception.NotAuditedException; import org.hibernate.envers.exception.NotAuditedException;
import org.libreccm.cdi.utils.CdiLookupException;
import org.libreccm.cdi.utils.CdiUtil; import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.docrepo.File; import org.libreccm.docrepo.File;
import org.libreccm.docrepo.Resource; 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 // checks if the subject has permissions granting the privilege to
// 'read' the file // 'read' the file
permissionChecker.checkPermission("read", file); permissionChecker.checkPermission("read", file);
} catch (CdiLookupException ex) {
log.error(GlobalizationUtil.globalize("beanFinder.fail" +
".resourceRepository"), ex);
} catch (AuthorizationException authEx) { } catch (AuthorizationException authEx) {
log.error(GlobalizationUtil.globalize("ui.file.failure.privilege.read"), log.error(GlobalizationUtil.globalize("ui.file.failure.privilege.read"),
authEx); 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. 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. 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. 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. 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. 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. 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. 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. 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. 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.