From 5b1121e2645b14142cdd28cc223ea10f37a75e64 Mon Sep 17 00:00:00 2001 From: tosmers Date: Wed, 16 Dec 2015 15:03:45 +0000 Subject: [PATCH] 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 --- .../com/arsdigita/docrepo/ui/BrowsePane.java | 35 ++++---- .../docrepo/ui/DestinationFolderForm.java | 84 ++++++++----------- .../docrepo/ui/DocRepoRequestLocal.java | 26 +++--- .../arsdigita/docrepo/ui/FileActionPane.java | 34 +++----- .../arsdigita/docrepo/ui/FileEditForm.java | 65 +++++++------- .../docrepo/ui/FilePropertiesPanel.java | 4 - .../Resources.properties | 3 + .../Resources_de.properties | 3 + .../Resources_en.properties | 3 + 9 files changed, 119 insertions(+), 138 deletions(-) diff --git a/ccm-docrepo/src/main/java/com/arsdigita/docrepo/ui/BrowsePane.java b/ccm-docrepo/src/main/java/com/arsdigita/docrepo/ui/BrowsePane.java index 04a2db25b..05af96c27 100644 --- a/ccm-docrepo/src/main/java/com/arsdigita/docrepo/ui/BrowsePane.java +++ b/ccm-docrepo/src/main/java/com/arsdigita/docrepo/ui/BrowsePane.java @@ -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 diff --git a/ccm-docrepo/src/main/java/com/arsdigita/docrepo/ui/DestinationFolderForm.java b/ccm-docrepo/src/main/java/com/arsdigita/docrepo/ui/DestinationFolderForm.java index ec581e1d3..4cfe61c94 100644 --- a/ccm-docrepo/src/main/java/com/arsdigita/docrepo/ui/DestinationFolderForm.java +++ b/ccm-docrepo/src/main/java/com/arsdigita/docrepo/ui/DestinationFolderForm.java @@ -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())); } } diff --git a/ccm-docrepo/src/main/java/com/arsdigita/docrepo/ui/DocRepoRequestLocal.java b/ccm-docrepo/src/main/java/com/arsdigita/docrepo/ui/DocRepoRequestLocal.java index 4deb20570..a46706557 100644 --- a/ccm-docrepo/src/main/java/com/arsdigita/docrepo/ui/DocRepoRequestLocal.java +++ b/ccm-docrepo/src/main/java/com/arsdigita/docrepo/ui/DocRepoRequestLocal.java @@ -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; } } diff --git a/ccm-docrepo/src/main/java/com/arsdigita/docrepo/ui/FileActionPane.java b/ccm-docrepo/src/main/java/com/arsdigita/docrepo/ui/FileActionPane.java index 2ba7a3339..14a25d9ae 100644 --- a/ccm-docrepo/src/main/java/com/arsdigita/docrepo/ui/FileActionPane.java +++ b/ccm-docrepo/src/main/java/com/arsdigita/docrepo/ui/FileActionPane.java @@ -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); diff --git a/ccm-docrepo/src/main/java/com/arsdigita/docrepo/ui/FileEditForm.java b/ccm-docrepo/src/main/java/com/arsdigita/docrepo/ui/FileEditForm.java index 8160a3b14..464401e08 100644 --- a/ccm-docrepo/src/main/java/com/arsdigita/docrepo/ui/FileEditForm.java +++ b/ccm-docrepo/src/main/java/com/arsdigita/docrepo/ui/FileEditForm.java @@ -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); } } \ No newline at end of file diff --git a/ccm-docrepo/src/main/java/com/arsdigita/docrepo/ui/FilePropertiesPanel.java b/ccm-docrepo/src/main/java/com/arsdigita/docrepo/ui/FilePropertiesPanel.java index 769b3a9fd..bbbcd67fa 100644 --- a/ccm-docrepo/src/main/java/com/arsdigita/docrepo/ui/FilePropertiesPanel.java +++ b/ccm-docrepo/src/main/java/com/arsdigita/docrepo/ui/FilePropertiesPanel.java @@ -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); diff --git a/ccm-docrepo/src/main/resources/com.arsdigita.docrepo/Resources.properties b/ccm-docrepo/src/main/resources/com.arsdigita.docrepo/Resources.properties index 72368dcc4..4010df5cd 100644 --- a/ccm-docrepo/src/main/resources/com.arsdigita.docrepo/Resources.properties +++ b/ccm-docrepo/src/main/resources/com.arsdigita.docrepo/Resources.properties @@ -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. diff --git a/ccm-docrepo/src/main/resources/com.arsdigita.docrepo/Resources_de.properties b/ccm-docrepo/src/main/resources/com.arsdigita.docrepo/Resources_de.properties index 4d342bce8..ca3381373 100644 --- a/ccm-docrepo/src/main/resources/com.arsdigita.docrepo/Resources_de.properties +++ b/ccm-docrepo/src/main/resources/com.arsdigita.docrepo/Resources_de.properties @@ -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. diff --git a/ccm-docrepo/src/main/resources/com.arsdigita.docrepo/Resources_en.properties b/ccm-docrepo/src/main/resources/com.arsdigita.docrepo/Resources_en.properties index 72368dcc4..4010df5cd 100644 --- a/ccm-docrepo/src/main/resources/com.arsdigita.docrepo/Resources_en.properties +++ b/ccm-docrepo/src/main/resources/com.arsdigita.docrepo/Resources_en.properties @@ -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.