Commits

dloy  committed b474f79

Updates to support collections in fixity context

  • Participants
  • Parent commits d23d992

Comments (0)

Files changed (2)

File fixity-storeload/src/main/java/org/cdlib/mrt/fixity/tools/Store2Fixity.java

 import org.cdlib.mrt.core.Manifest;
 import org.cdlib.mrt.core.ManifestRowAbs;
 import org.cdlib.mrt.core.MessageDigest;
+import org.cdlib.mrt.utility.FileUtil;
 import org.cdlib.mrt.utility.TFileLogger;
 import org.cdlib.mrt.utility.TFrame;
 import org.cdlib.mrt.utility.URLEncoder;
     protected int maxout = 10000;
     protected FixityClient client = null;
     protected String serverLink = null;
+    protected String[] owners = null;
+    protected String[] members = null;
 
     public Store2Fixity(
             File baseFile,
             if (content == null) {
                 throw new TException.INVALID_OR_MISSING_PARM(MESSAGE + "not able to process manifest");
             }
+            extractMembership();
+            extractOwner();
 
         } catch (Exception ex) {
             throw new TException(ex);
         }
     }
-    
+
     public static Identifier getArk(String arkP)
         throws TException
     {
             }
             File manifestFile = new File(baseFile, line);
             if (!manifestFile.exists()) {
-                throw new TException.INVALID_OR_MISSING_PARM(MESSAGE + "manifest.txt file does not exist");
+                throw new TException.INVALID_OR_MISSING_PARM(MESSAGE + "manifest.txt file does not exist:" + manifestFile.getCanonicalPath());
             }
              
             Manifest manifest = Manifest.getManifest(logger, ManifestRowAbs.ManifestType.object);
                 line,
                 logger);
             System.out.println(test.dump("MAIN dump"));
+            if (false) return;
             test.run();
 
         } catch(Exception e) {
 
             String note = null;
             String formatTypeS = "XML";
-        client.add(
-            linkS,
-            timeout,
-            retry,
-            urlS,
-            source,
-            sizeS,
-            digestType,
-            digestValue,
-            context,
-            note,
-            formatTypeS);
+
+            Properties prop = client.add(
+                linkS,
+                timeout,
+                retry,
+                urlS,
+                source,
+                sizeS,
+                digestType,
+                digestValue,
+                context,
+                note,
+                formatTypeS);
+            if (isError(prop)) {
+                handleException(prop);
+            }
+
+            for (String member: members) {
+                String memberContext = "|member=" + member + "|";
+                Properties contextProp = client.update(
+                    linkS,
+                    timeout,
+                    retry,
+                    urlS,
+                    null,
+                    null,
+                    null,
+                    null,
+                    memberContext,
+                    null,
+                    formatTypeS);
+                if (isError(contextProp)) {
+                    handleException(prop);
+                }
+            }
+
+            for (String owner: owners) {
+                String ownerContext = "|owner=" + owner + "|";
+                Properties contextProp = client.update(
+                    linkS,
+                    timeout,
+                    retry,
+                    urlS,
+                    null,
+                    null,
+                    null,
+                    null,
+                    ownerContext,
+                    null,
+                    formatTypeS);
+                if (isError(contextProp)) {
+                    handleException(prop);
+                }
+            }
 
         } catch (Exception ex) {
             ex.printStackTrace();
 
     }
 
+    protected void handleException(Properties prop)
+        throws TException
+    {
+        if ((prop == null) || (prop.size() == 0)) {
+            throw new TException.INVALID_OR_MISSING_PARM("No properties returned from FixityClient");
+        }
+        String exceptionS = prop.getProperty("response.state");
+        if (StringUtil.isEmpty(exceptionS)) {
+            throw new TException.INVALID_OR_MISSING_PARM("No exception state retunred from FixityClient");
+        }
+        if (exceptionS.contains("exc:tException.REQUEST_ITEM_EXISTS")) {
+            throw new TException.REQUEST_ITEM_EXISTS(exceptionS);
+        } else {
+            throw new TException.GENERAL_EXCEPTION(exceptionS);
+        }
+    }
+
+    protected int getStatus(Properties prop)
+    {
+        int statusVal = 200;
+        String statusValS = prop.getProperty("response.status");
+        if (StringUtil.isNotEmpty(statusValS)) {
+            statusVal = Integer.parseInt(statusValS);
+        }
+        return statusVal;
+    }
+
+
+
+    protected boolean isError(Properties prop)
+    {
+        if (prop == null) return true;
+
+        String errorStatus = prop.getProperty("error.status");
+        if (StringUtil.isNotEmpty(errorStatus)) return true;
+        return false;
+    }
 
     protected void log(String msg)
     {
                     + " - baseURL=" + baseURL + NL
                     + " - serverLink=" + serverLink + NL
                     );
+            if (members != null) {
+                for (String item: members) {
+                    buf.append(" - member=" + item + NL);
+                }
+            }
+            if (owners != null) {
+                for (String item: owners) {
+                    buf.append(" - owner=" + item + NL);
+                }
+            }
             return buf.toString();
             
         } catch (Exception ex) {
             return ex.toString();
         }
     }
+
+    protected void extractMembership()
+        throws TException
+    {
+        try {
+            String urlS = baseURL
+                    + "/" + URLEncoder.encode(id.getValue(), "utf-8")
+                    + "/" + version
+                    + "/" + URLEncoder.encode("system/mrt-membership.txt", "utf-8");
+            members = FileUtil.getLinesFromURL(logger, urlS);
+
+        } catch (Exception ex) {
+            log("Warning - getMembership Exception:" + ex);
+        }
+
+    }
+
+    protected void extractOwner()
+        throws TException
+    {
+        try {
+            String urlS = baseURL
+                    + "/" + URLEncoder.encode(id.getValue(), "utf-8")
+                    + "/" + version
+                    + "/" + URLEncoder.encode("system/mrt-owner.txt", "utf-8");
+            owners = FileUtil.getLinesFromURL(logger, urlS);
+
+        } catch (Exception ex) {
+            log("Warning - getMembership Exception:" + ex);
+        }
+
+    }
+
+    public String[] getMembers() {
+        return members;
+    }
+
+    public String[] getOwners() {
+        return owners;
+    }
+
+
 }

File fixity-storeload/src/main/resources/resources/FixityTest.properties

+#         mrt Test properties
+#-----------------------------------------------------------------
+#-----------------------------------------------------------------
+db.url=jdbc:mysql://127.0.0.1:3306/merritt?characterEncoding=UTF-8&characterSetResults=UTF-8
+db.user=merrittrw
+db.pw=rInueot2oCxT88IZNAumMA==
+
+#db.url=jdbc:mysql://mysql-dev.cdlib.org:3333/mrt?characterEncoding=UTF-8&characterSetResults=UTF-8
+#db.user=mrtrw
+#db.pw=XhruRdVATeA=
+
+#db.url=jdbc:mysql://mysql-dev.cdlib.org:3333/mrt2?characterEncoding=UTF-8&characterSetResults=UTF-8
+#db.user=mrt2rw
+#db.pw=3rM2GDetwQM=
+
+#hsqldb
+#db.url=jdbc:hsqldb:file:C:/Documents and Settings/dloy/My Documents/MRTMaven/db
+#db.user=sa
+#db.password=
+
+SaveDirectory.path=C:/Documents and Settings/dloy/My Documents/CDL6/tomcat_base/webapps/fixity
+SaveDirectory.maxout=3000
+SaveDirectory.baseURL=http://localhost:28080/fixity/
+
+RunQueue.capacity=100
+
+FixityServiceStateManager.infoPath=C:/Documents and Settings/dloy/My Documents/MRTMaven/fixity/fixity-info.txt
+TestFixityReport.select=status,count(status) from fixity_item group by status
+TestFixityReport.mailTo=dloy@ucop.edu
+TestFixityItemReport.mailTo=dloy@ucop.edu
+TestFixityItemsReport.mailTo=dloy@ucop.edu
+
+mail.smtp.host=exchangemail.ad.ucop.edu
+mail.from=user@cdlib.org
+
+
+Store2Fixity.baseFile=C:/Documents and Settings/dloy/My Documents/MRTMaven/repository/fixity/node/store/pairtree_root/ar/k+/=1/30/30/=q/t1
+Store2Fixity.line=./k6/0c/4r/w/ark+=13030=qt1k60c4rw/v001/manifest.txt
+Store2Fixity.serverLink=http://localhost:28080/mrtfixity
+Store2Fixity.baseURL=http://localhost:28080/storage/content/10
+
+FixityPeriodicReport.frequency=60
+FixityPeriodicReport.delay=30
+FixityService=C:/Documents and Settings/dloy/My Documents/MRTMaven/fixity
+
+TestClientProcessFixity.url=http://localhost:28080/mrtfixity