1 | main { |
---|
2 | # A few checks to get meaningful error messages |
---|
3 | dataObjExists(*geniXmlObjPath); |
---|
4 | dataObjExists(*xsltObjPath); |
---|
5 | hasExtension(*geniXmlObjPath,"xml"); |
---|
6 | hasExtension(*xsltObjPath,"xsl"); |
---|
7 | |
---|
8 | # Apply stylesheet |
---|
9 | msiXsltApply(*xsltObjPath, *geniXmlObjPath, *buffer); |
---|
10 | |
---|
11 | # Generate path of formatted metadata object |
---|
12 | msiSplitPath(*geniXmlObjPath, *collection, *filename); |
---|
13 | *metadataObjPath=*collection++"/"++trimr(*filename,".")++"_formatted.xml"; |
---|
14 | |
---|
15 | # Create and write to metadata object |
---|
16 | msiDataObjCreate(*metadataObjPath, "forceFlag=", *D_FD); |
---|
17 | msiDataObjWrite(*D_FD, *buffer, *W_len); |
---|
18 | msiDataObjClose(*D_FD, *status); |
---|
19 | |
---|
20 | # Load metadata from formatted object |
---|
21 | msiLoadMetadataFromXml(*geniXmlObjPath, *metadataObjPath); |
---|
22 | |
---|
23 | # Remove formatted metadata object |
---|
24 | msiDataObjUnlink(*metadataObjPath, *status); |
---|
25 | |
---|
26 | # Done |
---|
27 | writeLine("stdout", "Added metadata to "++*geniXmlObjPath); |
---|
28 | } |
---|
29 | |
---|
30 | |
---|
31 | dataObjExists(*objPath) { |
---|
32 | # Split path to get obj and coll names |
---|
33 | msiSplitPath(*objPath, *collection, *object); |
---|
34 | |
---|
35 | # Make query |
---|
36 | msiAddSelectFieldToGenQuery("DATA_ID", "count", *genQInp); |
---|
37 | msiAddConditionToGenQuery("DATA_NAME", "=", *object, *genQInp); |
---|
38 | msiAddConditionToGenQuery("COLL_NAME", "=", *collection, *genQInp); |
---|
39 | |
---|
40 | # Run query |
---|
41 | msiExecGenQuery(*genQInp, *genQOut); |
---|
42 | |
---|
43 | # Extract path from query result |
---|
44 | foreach (*genQOut) { |
---|
45 | msiGetValByKey(*genQOut, "DATA_ID", *count); |
---|
46 | } |
---|
47 | |
---|
48 | # Success? |
---|
49 | if (int(*count) > 0) { |
---|
50 | succeed; |
---|
51 | } |
---|
52 | else { |
---|
53 | fail(-310000); #USER_FILE_DOES_NOT_EXIST |
---|
54 | } |
---|
55 | } |
---|
56 | |
---|
57 | |
---|
58 | hasExtension(*object,*extension) { |
---|
59 | # Get object extension |
---|
60 | *ext = triml(*object, "."); |
---|
61 | |
---|
62 | # Match? |
---|
63 | if (*ext == *extension) { |
---|
64 | succeed; |
---|
65 | } |
---|
66 | else { |
---|
67 | fail(-815000); #CAT_INVALID_DATA_TYPE |
---|
68 | } |
---|
69 | } |
---|
70 | |
---|
71 | |
---|
72 | INPUT *geniXmlObjPath=$1, *xsltObjPath="/pluto/home/rods/geni/geniObject.xsl" |
---|
73 | OUTPUT ruleExecOut |
---|