Skip to content
Browse files

added export of Arrangement to CSV file as per JD

  • Loading branch information...
1 parent 0b4a993 commit 0c74497bec8632d8be0b6dfc95217fda9d51d010 @gregjan gregjan committed Jul 25, 2012
View
59 mets.model/src/gov/loc/mets/util/METSUtils.java
@@ -51,7 +51,7 @@
/**
* @author Gregory Jansen
- *
+ *
*/
public class METSUtils {
@@ -62,7 +62,7 @@
public static String makeXMLUUID(UUID rawuuid) {
return new StringBuilder().append("uuid_").append(rawuuid.toString()).toString();
}
-
+
public static String makeXMLUUID() {
return new StringBuilder().append("uuid_").append(UUID.randomUUID().toString()).toString();
}
@@ -73,7 +73,7 @@ public static DocumentRoot createInitialMetsDocument(String label) {
MetsType m = result.getMets();
UUID uuid = UUID.randomUUID();
m.setID(makeXMLUUID(uuid));
- m.setOBJID("info:fedora/uuid:"+uuid.toString());
+ m.setOBJID("info:fedora/uuid:" + uuid.toString());
m.setLABEL(label);
m.setPROFILE(METSConstants.MetsProfile_UNC_LIBRARIES);
m.setTYPE(METSConstants.MetsType_WORKBENCH);
@@ -143,22 +143,23 @@ public static FileGrpType getBatchMetadataGroup(MetsType m) {
}
return result;
}
-
+
public static SmLinkType findLink(EObject s, String p, EObject o) {
SmLinkType result = null;
EObject testMets = s.eContainer();
- while(!MetsType.class.isInstance(testMets)) {
+ while (!MetsType.class.isInstance(testMets)) {
testMets = testMets.eContainer();
- if(testMets == null) {
+ if (testMets == null) {
return null;
}
}
- MetsType mets = (MetsType)testMets;
- if(mets.getStructLink() == null) return null;
- for(SmLinkType l : mets.getStructLink().getSmLink()) {
- if(l.getXlinkFrom().equals(s)) {
- if(l.getXlinkTo().equals(o)) {
- if(l.getArcrole().equals(p)) {
+ MetsType mets = (MetsType) testMets;
+ if (mets.getStructLink() == null)
+ return null;
+ for (SmLinkType l : mets.getStructLink().getSmLink()) {
+ if (l.getXlinkFrom().equals(s)) {
+ if (l.getXlinkTo().equals(o)) {
+ if (l.getArcrole().equals(p)) {
result = l;
break;
}
@@ -248,7 +249,7 @@ public static FileType addFile(MetsType mets, URI originalData, String xmlid, lo
public static FLocatType addStagedFileLocator(MetsType mets, String id, URI original, URI stagedUri,
LOCTYPEType locType, String otherLocType) {
// find or create the group for this object
- FileType data = (FileType)mets.eResource().getEObject(id);
+ FileType data = (FileType) mets.eResource().getEObject(id);
if (data == null) {
throw new Error("data file element does not exist");
}
@@ -286,7 +287,7 @@ public static EObject getDescription(DivType d, String status) {
* @return
*/
public static boolean isContainer(DivType d) {
- if(!d.getDiv().isEmpty()) {
+ if (!d.getDiv().isEmpty()) {
return true;
}
if (METSConstants.Div_Folder.equals(d.getTYPE()) || METSConstants.Div_Collection.equals(d.getTYPE())
@@ -300,15 +301,35 @@ public static boolean isContainer(DivType d) {
public static Collection<SmLinkType> getObjectLinks(DivType d) {
Set<SmLinkType> result = new HashSet<SmLinkType>();
try {
- DocumentRoot r = (DocumentRoot)d.eResource().getContents().get(0);
- for(SmLinkType sml : r.getMets().getStructLink().getSmLink()) {
- if(d.equals(sml.getXlinkTo())) {
+ DocumentRoot r = (DocumentRoot) d.eResource().getContents().get(0);
+ for (SmLinkType sml : r.getMets().getStructLink().getSmLink()) {
+ if (d.equals(sml.getXlinkTo())) {
result.add(sml);
}
}
- } catch(NullPointerException ignored) {
- //ignored.printStackTrace();
+ } catch (NullPointerException ignored) {
+ // ignored.printStackTrace();
}
return result;
}
+
+ public static int getDepth(DivType d) {
+ int depth = 0;
+ for (EObject eo = d.eContainer(); !(eo instanceof StructMapType); eo = eo.eContainer()) {
+ depth++;
+ }
+ return depth;
+ }
+
+ public static String getUUID(DivType d) {
+ String def = null;
+ if (d.getCONTENTIDS() != null) {
+ for (String id : d.getCONTENTIDS()) {
+ if (id.contains("uuid:")) {
+ return id;
+ }
+ }
+ }
+ return def;
+ }
}
View
1 workbench_plugin/.classpath
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
+ <classpathentry exported="true" kind="lib" path="lib/opencsv-2.2.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src/main/java/"/>
View
3 workbench_plugin/META-INF/MANIFEST.MF
@@ -28,7 +28,8 @@ Bundle-ClassPath: .,
lib/jdom-1.1.jar,
lib/saxon-8.7.jar,
lib/saxon-dom-8.7.jar,
- lib/xml-apis-1.3.04.jar
+ lib/xml-apis-1.3.04.jar,
+ lib/opencsv-2.2.jar
Export-Package: .,
edu.sdsc.grid.io,
edu.sdsc.grid.io.irods,
View
3 workbench_plugin/build.properties
@@ -18,7 +18,8 @@ bin.includes = plugin.xml,\
intro/,\
introData.xml,\
helpData.xml,\
- intro.png
+ intro.png,\
+ lib/opencsv-2.2.jar
jars.compile.order = cdr-metadata-1.1-SNAPSHOT.jar,\
commons-logging-1.0.4.jar,\
Jargon-2.3.0.jar,\
View
BIN workbench_plugin/icons/table.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN workbench_plugin/lib/opencsv-2.2.jar
Binary file not shown.
View
10 workbench_plugin/plugin.xml
@@ -867,6 +867,16 @@
id="workbench_plugin.categorySIP"
name="Submission Package">
</category>
+ <wizard
+ category="org.eclipse.ui.Basic/workbench_plugin.categorySIP"
+ class="unc.lib.cdr.workbench.project.CSVArrangementExportWizard"
+ icon="icons/table.gif"
+ id="workbench_plugin.wizardExportArrangementCSV"
+ name="Arrangement as Comma-Separated Values (CSV)">
+ <selection
+ class="org.eclipse.core.resources.IProject">
+ </selection>
+ </wizard>
</extension>
<extension
point="org.eclipse.core.runtime.adapters">
View
111 workbench_plugin/src/main/java/unc/lib/cdr/workbench/project/CSVArrangementExportJob.java
@@ -0,0 +1,111 @@
+/**
+ * Copyright 2010 The University of North Carolina at Chapel Hill
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package unc.lib.cdr.workbench.project;
+
+import gov.loc.mets.DivType;
+import gov.loc.mets.MetsType1;
+import gov.loc.mets.StructMapType;
+import gov.loc.mets.util.METSUtils;
+
+import java.io.FileWriter;
+import java.io.IOException;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.emf.common.util.TreeIterator;
+import org.eclipse.emf.ecore.EObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import unc.lib.cdr.workbench.rcp.Activator;
+import au.com.bytecode.opencsv.CSVWriter;
+
+/**
+ * @author Gregory Jansen
+ *
+ */
+public class CSVArrangementExportJob extends Job {
+ @SuppressWarnings("unused")
+ private static final Logger LOG = LoggerFactory.getLogger(CSVArrangementExportJob.class);
+
+ IProject p = null;
+ String filepath = null;
+
+ public CSVArrangementExportJob(IProject p, String filepath) {
+ super("Exporting arrangement of '" + p.getName() + "' as CSV");
+ this.p = p;
+ this.filepath = filepath;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime. IProgressMonitor)
+ */
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ if (monitor == null) {
+ monitor = new NullProgressMonitor();
+ }
+ MetsProjectNature n = null;
+ try {
+ n = (MetsProjectNature) p.getNature(MetsProjectNature.NATURE_ID);
+ } catch (CoreException e) {
+ return new Status(Status.ERROR, Activator.PLUGIN_ID, "There was a problem obtaining the METS project nature.",
+ e);
+ }
+ MetsType1 workbench = n.getMets();
+ DivType bag = METSUtils.findBagDiv(workbench);
+
+ // setup CSV file handler
+ CSVWriter writer = null;
+ try {
+ writer = new CSVWriter(new FileWriter(filepath));
+ writer.writeNext(new String[] {"order", "depth", "pid", "label"});
+ int order = 1;
+ for (TreeIterator<EObject> iter = bag.eAllContents(); iter.hasNext();) {
+ EObject eo = iter.next();
+ if (eo instanceof DivType) {
+ DivType d = (DivType) eo;
+ String uuid = METSUtils.getUUID(d);
+ int depth = METSUtils.getDepth(d);
+ writer.writeNext(new String[] { String.valueOf(order), String.valueOf(depth), uuid, d.getLABEL1() });
+ order++;
+ }
+ }
+
+ writer.flush();
+ writer.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Cannot open the export file: " + filepath);
+ }
+
+ try {
+ p.refreshLocal(IResource.DEPTH_ONE, new NullProgressMonitor());
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ return Status.OK_STATUS;
+ }
+
+}
View
89 workbench_plugin/src/main/java/unc/lib/cdr/workbench/project/CSVArrangementExportWizard.java
@@ -0,0 +1,89 @@
+package unc.lib.cdr.workbench.project;
+
+import org.eclipse.core.filesystem.EFS;
+import org.eclipse.core.filesystem.IFileStore;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.ui.IExportWizard;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.ide.IDE;
+
+public class CSVArrangementExportWizard extends Wizard implements IExportWizard {
+ IWorkbench workbench = null;
+ IStructuredSelection selection = null;
+ PickExportFilePage page = null;
+ IProject project = null;
+
+ public CSVArrangementExportWizard() {
+ this.setWindowTitle("Export");
+ }
+
+ @Override
+ public void init(IWorkbench workbench, IStructuredSelection selection) {
+ this.workbench = workbench;
+ this.selection = selection;
+ if (IProject.class.isInstance(selection.getFirstElement())) {
+ this.project = (IProject) selection.getFirstElement();
+ }
+ }
+
+ @Override
+ public boolean performFinish() {
+ CSVArrangementExportJob job = new CSVArrangementExportJob(project, this.page.getDestinationValue());
+ job.schedule();
+ try {
+ job.join();
+ } catch (InterruptedException e) {
+ }
+ if (this.page.openFile) {
+ openFile();
+ }
+ return true;
+ }
+
+ /**
+ *
+ */
+ private void openFile() {
+ IFileStore store = null;
+ try {
+ Path p = new Path(page.getDestinationValue());
+ store = EFS.getStore(p.toFile().toURI());
+ } catch (CoreException e) {
+ e.printStackTrace();
+ return;
+ }
+
+ IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ System.out.print(page);
+ try {
+ IDE.openEditorOnFileStore(page, store);
+ } catch (PartInitException e) {
+ e.printStackTrace();
+ return;
+ }
+ }
+
+ @Override
+ public void addPages() {
+ super.addPages();
+ page = new PickExportFilePage("page Name", project, "Arrangement as Comma-Separated Values (CSV)", "cdr.csv");
+ addPage(page);
+ }
+
+ @Override
+ public boolean canFinish() {
+ if (project == null)
+ return false;
+ if (!page.isPageComplete())
+ return false;
+ return super.canFinish();
+ }
+
+}
View
18 workbench_plugin/src/main/java/unc/lib/cdr/workbench/project/CdrSipExportWizard.java
@@ -11,8 +11,10 @@
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;
-import org.eclipse.ui.internal.Workbench;
+
+import unc.lib.cdr.workbench.stage.StagingUtils;
public class CdrSipExportWizard extends Wizard implements IExportWizard {
IWorkbench workbench = null;
@@ -63,7 +65,7 @@ private void openFile() {
return;
}
- IWorkbenchPage page = Workbench.getInstance().getActiveWorkbenchWindow().getActivePage();
+ IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
System.out.print(page);
try {
IDE.openEditorOnFileStore(page, store);
@@ -76,7 +78,7 @@ private void openFile() {
@Override
public void addPages() {
super.addPages();
- page = new PickExportFilePage("page Name", project);
+ page = new PickExportFilePage("page Name", project, "Carolina Digital Repository Submission (METS)", "cdr.xml");
addPage(page);
}
@@ -86,6 +88,16 @@ public boolean canFinish() {
return false;
if (!page.isPageComplete())
return false;
+ try {
+ int unstaged = StagingUtils.countUnstaged(project);
+ if(unstaged > 0) {
+ page.setErrorMessage("There are still "+unstaged+" files queued for staging. All captured files must be staged prior to export.");
+ page.setPageComplete(false);
+ return false;
+ }
+ } catch(CoreException e) {
+ e.printStackTrace();
+ }
return super.canFinish();
}
View
2 workbench_plugin/src/main/java/unc/lib/cdr/workbench/project/NewProjectStagingPage.java
@@ -113,7 +113,7 @@ public void widgetDefaultSelected(SelectionEvent e) {
// checkbox - automatically stage captured files?
autoStageButton = new Button(composite, SWT.CHECK | SWT.RIGHT);
- autoStageButton.setText("Automatically stage captured files");
+ autoStageButton.setText("Automatically stage files as you capture them.");
autoStageButton.setSelection(true);
GridData buttonData = new GridData();
buttonData.horizontalSpan = 2;
View
20 workbench_plugin/src/main/java/unc/lib/cdr/workbench/project/PickExportFilePage.java
@@ -60,19 +60,19 @@
* @param pageName
* @param project
*/
- protected PickExportFilePage(String pageName, IProject project) {
+ protected PickExportFilePage(String pageName, IProject project, String title, String extension) {
super(pageName);
- this.setTitle("Carolina Digital Repository Submission (METS)");
+ this.setTitle(title);
this.setMessage("Please select the file location and options for export.");
this.project = project;
if (project != null) {
if(project.isOpen()) {
- setDestinationValue(project.getLocation().append(project.getName() + ".cdr.xml").toString());
+ setDestinationValue(project.getLocation().append(project.getName() + "."+extension).toString());
} else {
setErrorMessage("The selected project is closed. Please open it and try again.");
}
} else {
- this.setErrorMessage("You must first select an open project to export this kind of submission package.");
+ this.setErrorMessage("You must select an open project to export.");
}
}
@@ -244,20 +244,10 @@ private void updatePageCompletion() {
return;
}
} else {
- this.setErrorMessage("You must first select an open project to export this kind of submission package.");
+ this.setErrorMessage("You must first select an open project to export.");
this.setPageComplete(false);
return;
}
- try {
- int unstaged = StagingUtils.countUnstaged(project);
- if(unstaged > 0) {
- this.setErrorMessage("There are still "+unstaged+" files queued for staging. All captured files must be staged prior to export.");
- this.setPageComplete(false);
- return;
- }
- } catch(CoreException e) {
- e.printStackTrace();
- }
if(getDestinationValue() == null || "".equals(getDestinationValue().trim())) {
this.setErrorMessage("You must select a file location for the export.");
this.setPageComplete(false);

0 comments on commit 0c74497

Please sign in to comment.
Something went wrong with that request. Please try again.