Revision 1331
Added by Jing Tao about 22 years ago
src/edu/ucsb/nceas/metacat/CleanupAccessTable.java | ||
---|---|---|
59 | 59 |
|
60 | 60 |
public class CleanupAccessTable |
61 | 61 |
{ |
62 |
/** |
|
63 |
* A method to add a new triple to a data set doc and update data set doc |
|
64 |
* in metacat db |
|
65 |
* |
|
66 |
* @param accessionNumber the accession number of the data set doc |
|
67 |
* @param newTripleVector the vector containing new triples need to be added |
|
68 |
* into the data set doc |
|
69 |
*/ |
|
70 | 62 |
private static final String TRIPLESTAG = "//triple"; |
71 | 63 |
private static final String IDENTIFIER = "//identifier"; |
72 | 64 |
private static final String RELATIONSHIP = "provides access control rules for"; |
... | ... | |
77 | 69 |
private static final String ALLOWPATH ="//allow"; |
78 | 70 |
private static final String DENY = "deny"; |
79 | 71 |
private static final String DENYPATH = "//deny"; |
80 |
|
|
81 |
public static void addNewTripleIntoDataset(String accessionNumber, |
|
72 |
/** |
|
73 |
* A method to add a new triple to a data set doc and update data set doc |
|
74 |
* in metacat db |
|
75 |
* |
|
76 |
* @param accessionNumber the accession number of the data set doc |
|
77 |
* @param newTripleVector the vector containing new triples need to be added |
|
78 |
* into the data set doc |
|
79 |
*/ |
|
80 |
public static void addNewTripleIntoDataset(String accessionNumber, |
|
82 | 81 |
Vector newTripleVector) |
83 | 82 |
{ |
84 | 83 |
String docidWithoutVersion = null; |
... | ... | |
1086 | 1085 |
/** |
1087 | 1086 |
* Method to delete rules which is not in xml access file |
1088 | 1087 |
*/ |
1089 |
public static void addAccessRulesToDocument(Vector aclDocList) |
|
1088 |
public static void addAccessRulesToDocument(String aclDocId, |
|
1089 |
Vector rulesFromDB, |
|
1090 |
Vector rulesFromDocument) |
|
1090 | 1091 |
{ |
1091 |
String aclDocId = null; |
|
1092 |
//checking for every acl id |
|
1093 |
for (int i= 0; i<aclDocList.size(); i++) |
|
1092 |
|
|
1093 |
try |
|
1094 | 1094 |
{ |
1095 |
try |
|
1095 |
Vector rulesAdded = new Vector(); |
|
1096 |
//check for every rules |
|
1097 |
for (int j=0; j< rulesFromDB.size(); j++) |
|
1096 | 1098 |
{ |
1097 |
aclDocId = (String)aclDocList.elementAt(i); |
|
1098 |
AccessRulesFromDocument xmlDocument = new |
|
1099 |
AccessRulesFromDocument(aclDocId); |
|
1100 |
Vector rules = xmlDocument.getAccessRuleVector(); |
|
1101 |
AccessRulesFromDB db = new AccessRulesFromDB(aclDocId); |
|
1102 |
Vector rulesFromDB = db.getAccessRuleVector(); |
|
1103 |
Vector rulesAdded = new Vector(); |
|
1104 |
//check for every rules |
|
1105 |
for (int j=0; j< rulesFromDB.size(); j++) |
|
1099 |
String oneRule = (String)rulesFromDB.elementAt(j); |
|
1100 |
// if onerules get from db not in xml_access, delete it |
|
1101 |
if (!rulesFromDocument.contains(oneRule)) |
|
1106 | 1102 |
{ |
1107 |
String oneRule = (String)rulesFromDB.elementAt(j); |
|
1108 |
// if onerules get from db not in xml_access, delete it |
|
1109 |
if (!rules.contains(oneRule)) |
|
1110 |
{ |
|
1111 |
MetaCatUtil.debugMessage("one rule: "+oneRule, 30); |
|
1112 |
rulesAdded.addElement(oneRule); |
|
1113 |
}//if |
|
1114 |
oneRule = null; |
|
1115 |
}//for |
|
1116 |
addAccessRules(aclDocId, rulesAdded); |
|
1117 |
aclDocId = null; |
|
1118 |
} |
|
1119 |
catch (Exception e) |
|
1120 |
{ |
|
1121 |
MetaCatUtil.debugMessage("error delete addAccessRulesToDocument(): "+ |
|
1103 |
MetaCatUtil.debugMessage("one rule: "+oneRule, 30); |
|
1104 |
rulesAdded.addElement(oneRule); |
|
1105 |
}//if |
|
1106 |
oneRule = null; |
|
1107 |
}//for |
|
1108 |
addAccessRules(aclDocId, rulesAdded); |
|
1109 |
} |
|
1110 |
catch (Exception e) |
|
1111 |
{ |
|
1112 |
MetaCatUtil.debugMessage("error delete addAccessRulesToDocument(): "+ |
|
1122 | 1113 |
e.getMessage(), 30); |
1123 |
} |
|
1124 |
}//for |
|
1114 |
} |
|
1125 | 1115 |
} |
1126 | 1116 |
|
1127 | 1117 |
/** |
1128 | 1118 |
* Method to updata data set files |
1129 | 1119 |
*/ |
1130 |
public static void updateDataSetFiles(Vector aclDocList) |
|
1120 |
public static void updateDataSetFilesForNewTriples(String aclDocId, |
|
1121 |
Vector docidFromAccessDB, |
|
1122 |
Vector docidFromRelationDB) |
|
1131 | 1123 |
{ |
1132 |
String aclDocId = null; |
|
1133 | 1124 |
String aclAccessionNumber = null; |
1134 | 1125 |
String revForAcl = null; |
1135 | 1126 |
String packagAccessionNumber = null; |
1136 | 1127 |
//checking for every acl id |
1137 |
for (int i= 0; i<aclDocList.size(); i++) |
|
1128 |
|
|
1129 |
try |
|
1138 | 1130 |
{ |
1139 |
try |
|
1131 |
//Get package and acl access number |
|
1132 |
packagAccessionNumber = getDataPackageAccessionNumber(aclDocId); |
|
1133 |
revForAcl = getRevNumber(aclDocId); |
|
1134 |
aclAccessionNumber = aclDocId+DOT+revForAcl; |
|
1135 |
//check for every docid in relation ship |
|
1136 |
Vector newTripleVector = new Vector(); |
|
1137 |
for (int j=0; j<docidFromAccessDB.size(); j++) |
|
1140 | 1138 |
{ |
1141 |
aclDocId = (String)aclDocList.elementAt(i); |
|
1142 |
packagAccessionNumber = getDataPackageAccessionNumber(aclDocId); |
|
1143 |
AccessRulesFromDocument xmlDocument = new |
|
1144 |
AccessRulesFromDocument(aclDocId); |
|
1145 |
Vector docid = xmlDocument.getACLObjects(); |
|
1146 |
AccessRulesFromDB db = new AccessRulesFromDB(aclDocId); |
|
1147 |
Vector docidFromDB = db.getDocidAccessRuleApplied(); |
|
1148 |
revForAcl = getRevNumber(aclDocId); |
|
1149 |
aclAccessionNumber = aclDocId+DOT+revForAcl; |
|
1150 |
//check for every docid in relation ship |
|
1151 |
Vector newTripleVector = new Vector(); |
|
1152 |
for (int j=0; j<docidFromDB.size(); j++) |
|
1139 |
String objectId = (String)docidFromAccessDB.elementAt(j); |
|
1140 |
String objectAccessionNumber = null; |
|
1141 |
String revForObject = null; |
|
1142 |
// new triple |
|
1143 |
if (!docidFromRelationDB.contains(objectId)) |
|
1153 | 1144 |
{ |
1154 |
String objectId = (String)docidFromDB.elementAt(j); |
|
1155 |
String objectAccessionNumber = null; |
|
1156 |
String revForObject = null; |
|
1157 |
// new triple |
|
1158 |
if (!docid.contains(objectId)) |
|
1159 |
{ |
|
1160 |
revForObject = getRevNumber(objectId); |
|
1161 |
objectAccessionNumber = objectId+DOT+revForObject; |
|
1162 |
Triple newTriple = new Triple(aclAccessionNumber, RELATIONSHIP, |
|
1145 |
revForObject = getRevNumber(objectId); |
|
1146 |
objectAccessionNumber = objectId+DOT+revForObject; |
|
1147 |
Triple newTriple = new Triple(aclAccessionNumber, RELATIONSHIP, |
|
1163 | 1148 |
objectAccessionNumber); |
1164 |
newTripleVector.add(newTriple);
|
|
1165 |
MetaCatUtil.debugMessage("find a new triple"+
|
|
1149 |
newTripleVector.add(newTriple); |
|
1150 |
MetaCatUtil.debugMessage("find a new triple"+ |
|
1166 | 1151 |
newTriple.toString(), 30); |
1167 | 1152 |
|
1168 |
}//if |
|
1169 |
}//for |
|
1170 |
// add new trip into data set |
|
1171 |
addNewTripleIntoDataset(packagAccessionNumber, newTripleVector); |
|
1172 |
// reset value |
|
1173 |
aclDocId = null; |
|
1174 |
aclAccessionNumber = null; |
|
1175 |
revForAcl = null; |
|
1176 |
packagAccessionNumber = null; |
|
1177 |
} |
|
1178 |
catch (Exception e) |
|
1179 |
{ |
|
1153 |
}//if |
|
1154 |
}//for |
|
1155 |
// add new trip into data set |
|
1156 |
addNewTripleIntoDataset(packagAccessionNumber, newTripleVector); |
|
1157 |
|
|
1158 |
} |
|
1159 |
catch (Exception e) |
|
1160 |
{ |
|
1180 | 1161 |
MetaCatUtil.debugMessage("error in updataDatasetFiles(): "+ |
1181 | 1162 |
e.getMessage(), 30); |
1182 |
}
|
|
1163 |
} |
|
1183 | 1164 |
|
1184 |
}//for |
|
1165 |
|
|
1185 | 1166 |
} |
1186 | 1167 |
|
1187 | 1168 |
/* |
... | ... | |
1210 | 1191 |
{ |
1211 | 1192 |
DBConnectionPool pool = DBConnectionPool.getInstance(); |
1212 | 1193 |
Vector aclVector = readAccessDocIdFromDB(); |
1213 |
//deleteRules(aclVector); |
|
1214 |
addAccessRulesToDocument(aclVector); |
|
1215 |
updateDataSetFiles(aclVector); |
|
1194 |
for (int i = 0; i < aclVector.size(); i++) |
|
1195 |
{ |
|
1196 |
try |
|
1197 |
{ |
|
1198 |
String aclDocId = (String)aclVector.elementAt(i); |
|
1199 |
AccessRulesFromDocument xmlDocument = new |
|
1200 |
AccessRulesFromDocument(aclDocId); |
|
1201 |
AccessRulesFromDB db = new AccessRulesFromDB(aclDocId); |
|
1202 |
Vector ruleFromDocument = xmlDocument.getAccessRuleVector(); |
|
1203 |
Vector ruleFromDB = db.getAccessRuleVector(); |
|
1204 |
Vector docIdFromRelation = xmlDocument.getACLObjects(); |
|
1205 |
Vector docIdFromAccess = db.getDocidAccessRuleApplied(); |
|
1206 |
// update rules in acl and triple in dataset file |
|
1207 |
addAccessRulesToDocument(aclDocId, ruleFromDB, ruleFromDocument); |
|
1208 |
//update triplse in dataset file |
|
1209 |
updateDataSetFilesForNewTriples(aclDocId, docIdFromAccess, |
|
1210 |
docIdFromRelation); |
|
1211 |
} |
|
1212 |
catch (Exception e) |
|
1213 |
{ |
|
1214 |
MetaCatUtil.debugMessage("exception in main is: " + |
|
1215 |
e.getMessage(), 30); |
|
1216 |
} |
|
1217 |
|
|
1218 |
} |
|
1216 | 1219 |
} |
1217 |
catch(Exception e) |
|
1220 |
catch(Exception ee)
|
|
1218 | 1221 |
{ |
1219 |
MetaCatUtil.debugMessage("exception is: "+e.getMessage(), 30); |
|
1222 |
MetaCatUtil.debugMessage("exception is: "+ee.getMessage(), 30);
|
|
1220 | 1223 |
} |
1221 | 1224 |
} |
1222 | 1225 |
|
Also available in: Unified diff
Fixed a bug that if new triple is a new rule in xml_access table, the new triple wouldn't be added into data set file.