Revision 8689
Added by ben leinfelder over 10 years ago
src/edu/ucsb/nceas/metacat/replication/ReplicationService.java | ||
---|---|---|
50 | 50 |
import java.util.Arrays; |
51 | 51 |
import java.util.Calendar; |
52 | 52 |
import java.util.Date; |
53 |
import java.util.HashMap; |
|
53 | 54 |
import java.util.Hashtable; |
54 | 55 |
import java.util.List; |
56 |
import java.util.Map; |
|
55 | 57 |
import java.util.Timer; |
56 | 58 |
import java.util.Vector; |
57 | 59 |
|
... | ... | |
2010 | 2012 |
|
2011 | 2013 |
return serverCode; |
2012 | 2014 |
} |
2015 |
|
|
2016 |
/** |
|
2017 |
* Returns a Map of serverCode=serverName |
|
2018 |
* @return Map of server codes to names (URIs) |
|
2019 |
*/ |
|
2020 |
public static Map<Integer, String> getServerCodes() throws ServiceException { |
|
2021 |
DBConnection dbConn = null; |
|
2022 |
int serialNumber = -1; |
|
2023 |
PreparedStatement pstmt = null; |
|
2024 |
|
|
2025 |
Map<Integer, String> codes = new HashMap<Integer, String>(); |
|
2013 | 2026 |
|
2027 |
try { |
|
2028 |
|
|
2029 |
dbConn = DBConnectionPool.getDBConnection("MetacatReplication.getServerCodes"); |
|
2030 |
serialNumber = dbConn.getCheckOutSerialNumber(); |
|
2031 |
pstmt = dbConn.prepareStatement("SELECT serverid, server FROM xml_replication "); |
|
2032 |
pstmt.execute(); |
|
2033 |
ResultSet rs = pstmt.getResultSet(); |
|
2034 |
while (rs.next()) { |
|
2035 |
int serverCode = rs.getInt(1); |
|
2036 |
String server = rs.getString(2); |
|
2037 |
codes.put(serverCode, server); |
|
2038 |
} |
|
2039 |
pstmt.close(); |
|
2040 |
|
|
2041 |
} catch (SQLException sqle) { |
|
2042 |
throw new ServiceException("ReplicationService.getServerCodes - " |
|
2043 |
+ "SQL error when getting server map: " + sqle.getMessage()); |
|
2044 |
|
|
2045 |
} finally { |
|
2046 |
try { |
|
2047 |
pstmt.close(); |
|
2048 |
}//try |
|
2049 |
catch (Exception ee) { |
|
2050 |
logMetacat.error("ReplicationService.getServerCodes - " + ReplicationService.METACAT_REPL_ERROR_MSG); |
|
2051 |
logReplication.error("ReplicationService.getServerCodes - Error in MetacatReplicatio.getServerCodes: " |
|
2052 |
+ ee.getMessage()); |
|
2053 |
|
|
2054 |
}//catch |
|
2055 |
finally { |
|
2056 |
DBConnectionPool.returnDBConnection(dbConn, serialNumber); |
|
2057 |
}//finally |
|
2058 |
}//finally |
|
2059 |
|
|
2060 |
return codes; |
|
2061 |
} |
|
2062 |
|
|
2014 | 2063 |
/** |
2015 | 2064 |
* Method to get a host server information for given docid |
2016 | 2065 |
* @param conn a connection to the database |
src/edu/ucsb/nceas/metacat/annotation/DatapackageSummarizer.java | ||
---|---|---|
4 | 4 |
import java.sql.PreparedStatement; |
5 | 5 |
import java.sql.SQLException; |
6 | 6 |
import java.util.ArrayList; |
7 |
import java.util.Arrays; |
|
8 |
import java.util.Iterator; |
|
7 | 9 |
import java.util.List; |
10 |
import java.util.Map; |
|
8 | 11 |
import java.util.Vector; |
9 | 12 |
|
10 | 13 |
import org.apache.log4j.Logger; |
... | ... | |
26 | 29 |
import edu.ucsb.nceas.metacat.database.DBConnectionPool; |
27 | 30 |
import edu.ucsb.nceas.metacat.dataone.MNodeService; |
28 | 31 |
import edu.ucsb.nceas.metacat.properties.PropertyService; |
32 |
import edu.ucsb.nceas.metacat.replication.ReplicationService; |
|
29 | 33 |
import edu.ucsb.nceas.metacat.util.DocumentUtil; |
30 | 34 |
import edu.ucsb.nceas.utilities.SortedProperties; |
31 | 35 |
|
... | ... | |
152 | 156 |
// summarize the packages |
153 | 157 |
DatapackageSummarizer ds = new DatapackageSummarizer(); |
154 | 158 |
List<Identifier> identifiers = new ArrayList<Identifier>(); |
155 |
Vector<String> idList = DBUtil.getAllDocidsByType(DocumentImpl.EML2_0_0NAMESPACE, false, 1); |
|
156 |
Vector<String> idList1 = DBUtil.getAllDocidsByType(DocumentImpl.EML2_0_1NAMESPACE, false, 1); |
|
157 |
Vector<String> idList2 = DBUtil.getAllDocidsByType(DocumentImpl.EML2_1_0NAMESPACE, false, 1); |
|
158 |
Vector<String> idList3 = DBUtil.getAllDocidsByType(DocumentImpl.EML2_1_1NAMESPACE, false, 1); |
|
159 |
Map<Integer, String> serverCodes = ReplicationService.getServerCodes(); |
|
160 |
|
|
161 |
// select the metadata ids we want to summarize |
|
162 |
boolean includeReplicas = true; |
|
163 |
Iterator<Integer> codeIter = Arrays.asList(new Integer[] {1}).iterator(); |
|
164 |
if (includeReplicas ) { |
|
165 |
codeIter = serverCodes.keySet().iterator(); |
|
166 |
} |
|
159 | 167 |
|
160 |
idList.addAll(idList1); |
|
161 |
idList.addAll(idList2); |
|
162 |
idList.addAll(idList3); |
|
168 |
Vector<String> idList = new Vector<String>(); |
|
169 |
while (codeIter.hasNext()) { |
|
170 |
int serverLocation = codeIter.next(); |
|
171 |
Vector<String> idList0 = DBUtil.getAllDocidsByType(DocumentImpl.EML2_0_0NAMESPACE, false, serverLocation); |
|
172 |
Vector<String> idList1 = DBUtil.getAllDocidsByType(DocumentImpl.EML2_0_1NAMESPACE, false, serverLocation); |
|
173 |
Vector<String> idList2 = DBUtil.getAllDocidsByType(DocumentImpl.EML2_1_0NAMESPACE, false, serverLocation); |
|
174 |
Vector<String> idList3 = DBUtil.getAllDocidsByType(DocumentImpl.EML2_1_1NAMESPACE, false, serverLocation); |
|
175 |
|
|
176 |
idList.addAll(idList0); |
|
177 |
idList.addAll(idList1); |
|
178 |
idList.addAll(idList2); |
|
179 |
idList.addAll(idList3); |
|
163 | 180 |
|
181 |
} |
|
182 |
|
|
183 |
// go through all the identifiers now |
|
164 | 184 |
for (String localId : idList) { |
165 | 185 |
try { |
166 | 186 |
String guid = IdentifierManager.getInstance().getGUID( |
Also available in: Unified diff
support content from all serverLocations when summarizing entity info (semtools)