Revision 45152
Added by Claudio Atzori over 7 years ago
modules/cnr-mongo-mdstore/releases/1.1.0/deploy.info | ||
---|---|---|
1 |
{"type_source": "SVN", "goal": "package -U -T 4C source:jar", "url": "http://svn-public.driver.research-infrastructures.eu/driver/dnet40/modules/cnr-mongo-mdstore/trunk/", "deploy_repository": "dnet4-snapshots", "version": "4", "mail": "sandro.labruzzo@isti.cnr.it,michele.artini@isti.cnr.it, claudio.atzori@isti.cnr.it, alessia.bardi@isti.cnr.it", "deploy_repository_url": "http://maven.research-infrastructures.eu/nexus/content/repositories/dnet4-snapshots", "name": "cnr-mongo-mdstore"} |
modules/cnr-mongo-mdstore/releases/1.1.0/src/main/java/eu/dnetlib/mongodb/MongoOptionsFactory.java | ||
---|---|---|
1 |
package eu.dnetlib.mongodb; |
|
2 |
|
|
3 |
import org.springframework.beans.BeansException; |
|
4 |
import org.springframework.beans.factory.FactoryBean; |
|
5 |
|
|
6 |
import com.mongodb.MongoOptions; |
|
7 |
|
|
8 |
public class MongoOptionsFactory implements FactoryBean { |
|
9 |
private int connectionsPerHost; |
|
10 |
|
|
11 |
@Override |
|
12 |
public Object getObject() throws BeansException { |
|
13 |
MongoOptions opts = new MongoOptions(); |
|
14 |
opts.connectionsPerHost = connectionsPerHost; |
|
15 |
return opts; |
|
16 |
} |
|
17 |
|
|
18 |
@SuppressWarnings("rawtypes") |
|
19 |
@Override |
|
20 |
public Class getObjectType() { |
|
21 |
return MongoOptions.class; |
|
22 |
} |
|
23 |
|
|
24 |
@Override |
|
25 |
public boolean isSingleton() { |
|
26 |
return false; |
|
27 |
} |
|
28 |
|
|
29 |
public int getConnectionsPerHost() { |
|
30 |
return connectionsPerHost; |
|
31 |
} |
|
32 |
|
|
33 |
public void setConnectionsPerHost(int connectionsPerHost) { |
|
34 |
this.connectionsPerHost = connectionsPerHost; |
|
35 |
} |
|
36 |
|
|
37 |
} |
|
0 | 38 |
modules/cnr-mongo-mdstore/releases/1.1.0/src/main/java/eu/dnetlib/data/mdstore/modular/mongodb/MongoResultSetListener.java | ||
---|---|---|
1 |
package eu.dnetlib.data.mdstore.modular.mongodb; |
|
2 |
|
|
3 |
import static eu.dnetlib.miscutils.collections.MappedCollection.listMap; |
|
4 |
|
|
5 |
import java.util.ArrayList; |
|
6 |
import java.util.List; |
|
7 |
import java.util.regex.Pattern; |
|
8 |
|
|
9 |
import org.apache.commons.logging.Log; |
|
10 |
import org.apache.commons.logging.LogFactory; |
|
11 |
|
|
12 |
import com.google.common.collect.Lists; |
|
13 |
import com.mongodb.BasicDBObject; |
|
14 |
import com.mongodb.DBCollection; |
|
15 |
import com.mongodb.DBCursor; |
|
16 |
import com.mongodb.DBObject; |
|
17 |
import com.mongodb.QueryBuilder; |
|
18 |
|
|
19 |
import eu.dnetlib.enabling.resultset.ResultSet; |
|
20 |
import eu.dnetlib.enabling.resultset.ResultSetAware; |
|
21 |
import eu.dnetlib.enabling.resultset.ResultSetListener; |
|
22 |
import eu.dnetlib.miscutils.functional.UnaryFunction; |
|
23 |
import eu.dnetlib.miscutils.maps.ConcurrentSizedMap; |
|
24 |
|
|
25 |
public class MongoResultSetListener implements ResultSetListener, |
|
26 |
ResultSetAware { |
|
27 |
|
|
28 |
private static final Log log = LogFactory |
|
29 |
.getLog(MongoResultSetListener.class); // NOPMD by marko on 11/24/08 |
|
30 |
// 5:02 PM |
|
31 |
|
|
32 |
private ConcurrentSizedMap<Integer, String> lastKeys = new ConcurrentSizedMap<Integer, String>(); |
|
33 |
private final DBObject byId = new BasicDBObject("id", 1); |
|
34 |
|
|
35 |
private UnaryFunction<String, DBObject> serializer; |
|
36 |
private Pattern filter; |
|
37 |
private DBCollection collection; |
|
38 |
|
|
39 |
public MongoResultSetListener(DBCollection collection, Pattern filter, |
|
40 |
UnaryFunction<String, DBObject> serializer) { |
|
41 |
this.collection = collection; |
|
42 |
this.filter = filter; |
|
43 |
this.serializer = serializer; |
|
44 |
} |
|
45 |
|
|
46 |
@Override |
|
47 |
public List<String> getResult(int fromPosition, int toPosition) { |
|
48 |
// log.info("getting mdstore resultset " + fromPosition + ", " + |
|
49 |
// toPosition); |
|
50 |
|
|
51 |
ArrayList<DBObject> page = null; |
|
52 |
|
|
53 |
String lastKey = lastKeys.get(fromPosition); |
|
54 |
if (lastKey != null) |
|
55 |
page = continueFrom(lastKey, toPosition - fromPosition + 1); |
|
56 |
else |
|
57 |
page = fetchNew(fromPosition - 1, toPosition - fromPosition + 1); |
|
58 |
|
|
59 |
if (!page.isEmpty()) { |
|
60 |
DBObject last = page.get(page.size() - 1); |
|
61 |
lastKeys.put(toPosition + 1, (String) last.get("id")); |
|
62 |
} |
|
63 |
|
|
64 |
return listMap(page, serializer); |
|
65 |
} |
|
66 |
|
|
67 |
private ArrayList<DBObject> fetchNew(int from, int size) { |
|
68 |
// StopWatch stopWatch = new CommonsLogStopWatch(log); |
|
69 |
try { |
|
70 |
DBCursor cursor = null; |
|
71 |
if (filter != null) { |
|
72 |
DBObject query = QueryBuilder.start("body").regex(filter).get(); |
|
73 |
cursor = collection.find(query).sort(byId); |
|
74 |
} else |
|
75 |
cursor = collection.find().sort(byId); |
|
76 |
|
|
77 |
return Lists.newArrayList((Iterable<DBObject>) cursor.skip(from) |
|
78 |
.limit(size)); |
|
79 |
} finally { |
|
80 |
// stopWatch.stop("mongodb.list.scan"); |
|
81 |
} |
|
82 |
} |
|
83 |
|
|
84 |
private ArrayList<DBObject> continueFrom(String lastKey, int size) { |
|
85 |
// StopWatch stopWatch = new CommonsLogStopWatch(log); |
|
86 |
try { |
|
87 |
if (log.isDebugEnabled()) |
|
88 |
log.debug("trying to continue from previous key: " + lastKey); |
|
89 |
|
|
90 |
DBObject query = null; |
|
91 |
if (filter != null) |
|
92 |
query = QueryBuilder.start("id").greaterThan(lastKey) |
|
93 |
.and("body").regex(filter).get(); |
|
94 |
else |
|
95 |
query = QueryBuilder.start("id").greaterThan(lastKey).get(); |
|
96 |
|
|
97 |
final DBCursor cursor = collection.find(query).sort(byId); |
|
98 |
return Lists.newArrayList((Iterable<DBObject>) cursor.limit(size)); |
|
99 |
} finally { |
|
100 |
// stopWatch.stop("mongodb.list.resume"); |
|
101 |
} |
|
102 |
} |
|
103 |
|
|
104 |
@Override |
|
105 |
public int getSize() { |
|
106 |
if (filter != null) { |
|
107 |
DBObject query = QueryBuilder.start("body").regex(filter).get(); |
|
108 |
return (int) collection.find(query).count(); |
|
109 |
} |
|
110 |
return (int) collection.getCount(); |
|
111 |
} |
|
112 |
|
|
113 |
@Override |
|
114 |
public void setResultSet(ResultSet resultSet) { |
|
115 |
resultSet.close(); |
|
116 |
} |
|
117 |
|
|
118 |
} |
modules/cnr-mongo-mdstore/releases/1.1.0/src/main/java/eu/dnetlib/data/mdstore/modular/mongodb/utils/EnsureIndexJob.java | ||
---|---|---|
1 |
package eu.dnetlib.data.mdstore.modular.mongodb.utils; |
|
2 |
|
|
3 |
import org.apache.commons.logging.Log; |
|
4 |
import org.apache.commons.logging.LogFactory; |
|
5 |
import org.springframework.beans.factory.annotation.Required; |
|
6 |
|
|
7 |
import eu.dnetlib.data.mdstore.modular.connector.MDStoreDao; |
|
8 |
import eu.dnetlib.data.mdstore.modular.mongodb.MongoMDStore; |
|
9 |
import eu.dnetlib.enabling.tools.AbstractSchedulable; |
|
10 |
|
|
11 |
public class EnsureIndexJob extends AbstractSchedulable { |
|
12 |
|
|
13 |
private static final Log log = LogFactory.getLog(EnsureIndexJob.class); // NOPMD by marko on 11/24/08 5:02 PM |
|
14 |
|
|
15 |
private MDStoreDao dao; |
|
16 |
|
|
17 |
@Override |
|
18 |
protected void doExecute() { |
|
19 |
log.info("performing scheduled mdstore index check"); |
|
20 |
|
|
21 |
for (String mdId : getDao().listMDStores()) { |
|
22 |
try { |
|
23 |
log.info("ensureindex for mdStoreId:" + mdId); |
|
24 |
((MongoMDStore) getDao().getMDStore(mdId)).ensureIndices(); |
|
25 |
} catch (Throwable e) { |
|
26 |
log.warn("unable to reindex mdstore: " + mdId, e); |
|
27 |
} |
|
28 |
} |
|
29 |
} |
|
30 |
|
|
31 |
@Required |
|
32 |
public void setDao(MDStoreDao dao) { |
|
33 |
this.dao = dao; |
|
34 |
} |
|
35 |
|
|
36 |
public MDStoreDao getDao() { |
|
37 |
return dao; |
|
38 |
} |
|
39 |
|
|
40 |
} |
modules/cnr-mongo-mdstore/releases/1.1.0/src/main/java/eu/dnetlib/data/mdstore/modular/mongodb/utils/MetadataCheckJob.java | ||
---|---|---|
1 |
package eu.dnetlib.data.mdstore.modular.mongodb.utils; |
|
2 |
|
|
3 |
import java.io.StringReader; |
|
4 |
import java.util.List; |
|
5 |
|
|
6 |
import javax.xml.ws.Endpoint; |
|
7 |
|
|
8 |
import org.apache.commons.logging.Log; |
|
9 |
import org.apache.commons.logging.LogFactory; |
|
10 |
import org.dom4j.Document; |
|
11 |
import org.dom4j.DocumentException; |
|
12 |
import org.dom4j.io.SAXReader; |
|
13 |
import org.springframework.beans.factory.annotation.Required; |
|
14 |
|
|
15 |
import com.mongodb.BasicDBObject; |
|
16 |
import com.mongodb.DBCollection; |
|
17 |
import com.mongodb.DBObject; |
|
18 |
|
|
19 |
import eu.dnetlib.data.mdstore.modular.connector.MDStoreDao; |
|
20 |
import eu.dnetlib.data.mdstore.modular.mongodb.MongoMDStore; |
|
21 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpException; |
|
22 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService; |
|
23 |
import eu.dnetlib.enabling.tools.ServiceLocator; |
|
24 |
import eu.dnetlib.soap.EndpointReferenceBuilder; |
|
25 |
|
|
26 |
public class MetadataCheckJob { |
|
27 |
|
|
28 |
private static final Log log = LogFactory.getLog(MetadataCheckJob.class); // NOPMD by marko on 11/24/08 5:02 PM |
|
29 |
|
|
30 |
/** |
|
31 |
* lookup locator. |
|
32 |
*/ |
|
33 |
private ServiceLocator<ISLookUpService> lookupLocator; |
|
34 |
|
|
35 |
/** |
|
36 |
* {@link Endpoint} |
|
37 |
*/ |
|
38 |
private Endpoint endpoint; |
|
39 |
|
|
40 |
/** |
|
41 |
* {@link EndpointReferenceBuilder} |
|
42 |
*/ |
|
43 |
private EndpointReferenceBuilder<Endpoint> eprBuilder; |
|
44 |
|
|
45 |
/** |
|
46 |
* MDStore dao. |
|
47 |
*/ |
|
48 |
private MDStoreDao dao; |
|
49 |
|
|
50 |
private boolean runOnStart; |
|
51 |
|
|
52 |
public void runOnStart() { |
|
53 |
if(isRunOnStart()) { |
|
54 |
log.info("running mdStore metadata check on service start"); |
|
55 |
repairMetadata(); |
|
56 |
} |
|
57 |
} |
|
58 |
|
|
59 |
/** |
|
60 |
* Job execution method. |
|
61 |
*/ |
|
62 |
public void repairMetadata() { |
|
63 |
DBCollection metadata = ((MongoMDStore) getDao().getMDStore("metadata")).getCollection(); |
|
64 |
if (metadata.findOne() != null) { |
|
65 |
log.debug("\n mdStore metadata doesn't need to be repaired"); |
|
66 |
return; |
|
67 |
} |
|
68 |
try { |
|
69 |
List<String> mdStores = getLookupLocator().getService().quickSearchProfile( |
|
70 |
"//RESOURCE_PROFILE[" + |
|
71 |
".//RESOURCE_TYPE/@value='MDStoreDSResourceType' and " + |
|
72 |
".//RESOURCE_URI/@value='" + getServiceAddress() + "']"); |
|
73 |
|
|
74 |
log.debug("\n repairing mdstore metadata"); |
|
75 |
|
|
76 |
for(String MDStoreProfile : mdStores) |
|
77 |
metadata.save(getMdInfo(MDStoreProfile)); |
|
78 |
|
|
79 |
log.debug("\n FINISHED repairing mdstore metadata"); |
|
80 |
|
|
81 |
} catch(ISLookUpException e) { |
|
82 |
throw new RuntimeException(e); |
|
83 |
} catch(DocumentException e ) { |
|
84 |
throw new RuntimeException(e); |
|
85 |
} |
|
86 |
} |
|
87 |
|
|
88 |
/** |
|
89 |
* Helper method, gets an MDStore profile and returns a DBObject. |
|
90 |
* |
|
91 |
* @param MDStoreProfile |
|
92 |
* @return a DBObject representing the metadata informations |
|
93 |
* @throws DocumentException |
|
94 |
*/ |
|
95 |
private DBObject getMdInfo(final String MDStoreProfile) throws DocumentException { |
|
96 |
Document doc = new SAXReader().read(new StringReader(MDStoreProfile)); |
|
97 |
|
|
98 |
DBObject dbo = new BasicDBObject(); |
|
99 |
dbo.put("mdId", doc.valueOf("//RESOURCE_IDENTIFIER/@value")); |
|
100 |
dbo.put("format", doc.valueOf("//METADATA_FORMAT/text()")); |
|
101 |
dbo.put("layout", doc.valueOf("//METADATA_FORMAT_LAYOUT/text()")); |
|
102 |
dbo.put("interpretation", doc.valueOf("//METADATA_FORMAT_INTERPRETATION/text()")); |
|
103 |
|
|
104 |
return dbo; |
|
105 |
} |
|
106 |
|
|
107 |
private String getServiceAddress() { |
|
108 |
return getEprBuilder().getAddress(getEndpoint()) + "?wsdl"; |
|
109 |
} |
|
110 |
|
|
111 |
@Required |
|
112 |
public void setEprBuilder(EndpointReferenceBuilder<Endpoint> eprBuilder) { |
|
113 |
this.eprBuilder = eprBuilder; |
|
114 |
} |
|
115 |
|
|
116 |
public EndpointReferenceBuilder<Endpoint> getEprBuilder() { |
|
117 |
return eprBuilder; |
|
118 |
} |
|
119 |
|
|
120 |
@Required |
|
121 |
public void setEndpoint(Endpoint endpoint) { |
|
122 |
this.endpoint = endpoint; |
|
123 |
} |
|
124 |
|
|
125 |
public Endpoint getEndpoint() { |
|
126 |
return endpoint; |
|
127 |
} |
|
128 |
|
|
129 |
@Required |
|
130 |
public void setDao(MDStoreDao dao) { |
|
131 |
this.dao = dao; |
|
132 |
} |
|
133 |
|
|
134 |
public MDStoreDao getDao() { |
|
135 |
return dao; |
|
136 |
} |
|
137 |
|
|
138 |
@Required |
|
139 |
public void setLookupLocator(ServiceLocator<ISLookUpService> lookupLocator) { |
|
140 |
this.lookupLocator = lookupLocator; |
|
141 |
} |
|
142 |
|
|
143 |
public ServiceLocator<ISLookUpService> getLookupLocator() { |
|
144 |
return lookupLocator; |
|
145 |
} |
|
146 |
|
|
147 |
@Required |
|
148 |
public void setRunOnStart(boolean runOnStart) { |
|
149 |
this.runOnStart = runOnStart; |
|
150 |
} |
|
151 |
|
|
152 |
public boolean isRunOnStart() { |
|
153 |
return runOnStart; |
|
154 |
} |
|
155 |
|
|
156 |
} |
|
157 |
|
modules/cnr-mongo-mdstore/releases/1.1.0/src/main/java/eu/dnetlib/data/mdstore/modular/mongodb/utils/MDStoreUtils.java | ||
---|---|---|
1 |
package eu.dnetlib.data.mdstore.modular.mongodb.utils; |
|
2 |
|
|
3 |
import com.google.common.base.Function; |
|
4 |
import com.mongodb.DBObject; |
|
5 |
|
|
6 |
import eu.dnetlib.miscutils.functional.UnaryFunction; |
|
7 |
|
|
8 |
public class MDStoreUtils { |
|
9 |
|
|
10 |
public static UnaryFunction<String, DBObject> mdId() { |
|
11 |
return new UnaryFunction<String, DBObject>() { |
|
12 |
@Override |
|
13 |
public String evaluate(DBObject arg) { |
|
14 |
return (String) arg.get("mdId"); |
|
15 |
} |
|
16 |
}; |
|
17 |
} |
|
18 |
|
|
19 |
public static UnaryFunction<Boolean, DBObject> dboFilter(final String format, final String layout, final String interpretation) { |
|
20 |
return new UnaryFunction<Boolean, DBObject>() { |
|
21 |
@Override |
|
22 |
public Boolean evaluate(DBObject dbo) { |
|
23 |
return dbo.get("format").toString().equals(format) && dbo.get("layout").toString().equals(layout) |
|
24 |
&& dbo.get("interpretation").toString().equals(interpretation); |
|
25 |
} |
|
26 |
}; |
|
27 |
} |
|
28 |
|
|
29 |
public static Function<DBObject, String> body() { |
|
30 |
return new Function<DBObject, String>() { |
|
31 |
|
|
32 |
@Override |
|
33 |
public String apply(DBObject dbo) { |
|
34 |
return (String) dbo.get("body"); |
|
35 |
} |
|
36 |
}; |
|
37 |
} |
|
38 |
} |
modules/cnr-mongo-mdstore/releases/1.1.0/src/main/java/eu/dnetlib/data/mdstore/modular/mongodb/MDStoreDaoImpl.java | ||
---|---|---|
1 |
package eu.dnetlib.data.mdstore.modular.mongodb; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
|
|
5 |
import org.apache.commons.lang.StringUtils; |
|
6 |
import org.apache.commons.logging.Log; |
|
7 |
import org.apache.commons.logging.LogFactory; |
|
8 |
import org.springframework.beans.factory.annotation.Required; |
|
9 |
|
|
10 |
import com.mongodb.BasicDBObject; |
|
11 |
import com.mongodb.DB; |
|
12 |
import com.mongodb.DBCollection; |
|
13 |
|
|
14 |
import eu.dnetlib.data.mdstore.modular.RecordParser; |
|
15 |
import eu.dnetlib.data.mdstore.modular.connector.MDStore; |
|
16 |
import eu.dnetlib.data.mdstore.modular.connector.MDStoreDao; |
|
17 |
import eu.dnetlib.data.mdstore.modular.mongodb.utils.MDStoreUtils; |
|
18 |
import eu.dnetlib.miscutils.collections.FilteredCollection; |
|
19 |
import eu.dnetlib.miscutils.collections.MappedCollection; |
|
20 |
|
|
21 |
/** |
|
22 |
* Factory bean for MongoMDStore instances. |
|
23 |
* |
|
24 |
* @author marko |
|
25 |
* |
|
26 |
*/ |
|
27 |
public class MDStoreDaoImpl implements MDStoreDao { |
|
28 |
|
|
29 |
private static final Log log = LogFactory.getLog(MDStoreDaoImpl.class); |
|
30 |
|
|
31 |
private DB db; |
|
32 |
|
|
33 |
private RecordParser recordParser; |
|
34 |
|
|
35 |
private boolean upsert; |
|
36 |
|
|
37 |
private boolean discardRecords = true; |
|
38 |
|
|
39 |
@Override |
|
40 |
public void createMDStore(String mdId, String format, String interpretation, String layout) { |
|
41 |
|
|
42 |
String internalId = mdId; |
|
43 |
if (internalId.contains("_")) { |
|
44 |
internalId = StringUtils.substringBefore(mdId, "_"); |
|
45 |
} |
|
46 |
|
|
47 |
db.createCollection(internalId, null); |
|
48 |
DBCollection coll = db.getCollection("metadata"); |
|
49 |
final BasicDBObject obj = new BasicDBObject(); |
|
50 |
obj.put("mdId", mdId); |
|
51 |
obj.put("format", format); |
|
52 |
obj.put("interpretation", interpretation); |
|
53 |
obj.put("layout", layout); |
|
54 |
|
|
55 |
coll.save(obj); |
|
56 |
} |
|
57 |
|
|
58 |
@Override |
|
59 |
public void deleteMDStore(String mdId) { |
|
60 |
DBCollection coll = db.getCollection("metadata"); |
|
61 |
|
|
62 |
String internalId = mdId; |
|
63 |
if (internalId.contains("_")) { |
|
64 |
internalId = StringUtils.substringBefore(mdId, "_"); |
|
65 |
} |
|
66 |
|
|
67 |
log.info("delete mdId: " + mdId); |
|
68 |
|
|
69 |
coll.remove(new BasicDBObject("mdId", mdId)); |
|
70 |
final DBCollection mdColl = db.getCollection(internalId); |
|
71 |
if (mdColl != null) { |
|
72 |
mdColl.drop(); |
|
73 |
} |
|
74 |
} |
|
75 |
|
|
76 |
@Override |
|
77 |
public MDStore getMDStore(String mdId) { |
|
78 |
String internalId = mdId; |
|
79 |
if (internalId.contains("_")) { |
|
80 |
internalId = StringUtils.substringBefore(mdId, "_"); |
|
81 |
} |
|
82 |
return new MongoMDStore(mdId, db.getCollection(internalId), recordParser, isUpsert(), isDiscardRecords()); |
|
83 |
} |
|
84 |
|
|
85 |
@Override |
|
86 |
public List<String> listMDStores() { |
|
87 |
return MappedCollection.listMap(db.getCollection("metadata").find(), MDStoreUtils.mdId()); |
|
88 |
} |
|
89 |
|
|
90 |
@Override |
|
91 |
public List<String> listMDStores(String format, String layout, String interpretation) { |
|
92 |
return MappedCollection.listMap( |
|
93 |
FilteredCollection.listFilter(getDb().getCollection("metadata").find(), MDStoreUtils.dboFilter(format, layout, interpretation)), |
|
94 |
MDStoreUtils.mdId()); |
|
95 |
} |
|
96 |
|
|
97 |
public DB getDb() { |
|
98 |
return db; |
|
99 |
} |
|
100 |
|
|
101 |
@Required |
|
102 |
public void setDb(DB db) { |
|
103 |
this.db = db; |
|
104 |
} |
|
105 |
|
|
106 |
public RecordParser getRecordParser() { |
|
107 |
return recordParser; |
|
108 |
} |
|
109 |
|
|
110 |
@Required |
|
111 |
public void setRecordParser(RecordParser recordParser) { |
|
112 |
this.recordParser = recordParser; |
|
113 |
} |
|
114 |
|
|
115 |
@Required |
|
116 |
public void setUpsert(boolean upsert) { |
|
117 |
this.upsert = upsert; |
|
118 |
} |
|
119 |
|
|
120 |
public boolean isUpsert() { |
|
121 |
return upsert; |
|
122 |
} |
|
123 |
|
|
124 |
public boolean isDiscardRecords() { |
|
125 |
return discardRecords; |
|
126 |
} |
|
127 |
|
|
128 |
public void setDiscardRecords(boolean discardRecords) { |
|
129 |
this.discardRecords = discardRecords; |
|
130 |
} |
|
131 |
|
|
132 |
} |
modules/cnr-mongo-mdstore/releases/1.1.0/src/main/java/eu/dnetlib/data/mdstore/modular/mongodb/MongoMDStore.java | ||
---|---|---|
1 |
package eu.dnetlib.data.mdstore.modular.mongodb; |
|
2 |
|
|
3 |
import java.util.Iterator; |
|
4 |
import java.util.List; |
|
5 |
import java.util.Map; |
|
6 |
import java.util.concurrent.ArrayBlockingQueue; |
|
7 |
import java.util.concurrent.BlockingQueue; |
|
8 |
import java.util.regex.Pattern; |
|
9 |
|
|
10 |
import org.apache.commons.lang.StringUtils; |
|
11 |
import org.apache.commons.logging.Log; |
|
12 |
import org.apache.commons.logging.LogFactory; |
|
13 |
import org.bson.BasicBSONObject; |
|
14 |
import org.springframework.beans.factory.annotation.Required; |
|
15 |
|
|
16 |
import com.google.common.collect.Iterators; |
|
17 |
import com.google.common.collect.Lists; |
|
18 |
import com.mongodb.BasicDBObject; |
|
19 |
import com.mongodb.DBCollection; |
|
20 |
import com.mongodb.DBCursor; |
|
21 |
import com.mongodb.DBObject; |
|
22 |
import com.mongodb.QueryBuilder; |
|
23 |
|
|
24 |
import eu.dnetlib.data.mdstore.DocumentNotFoundException; |
|
25 |
import eu.dnetlib.data.mdstore.modular.RecordParser; |
|
26 |
import eu.dnetlib.data.mdstore.modular.connector.MDStore; |
|
27 |
import eu.dnetlib.data.mdstore.modular.mongodb.utils.MDStoreUtils; |
|
28 |
import eu.dnetlib.enabling.resultset.ResultSetListener; |
|
29 |
import eu.dnetlib.miscutils.collections.MappedCollection; |
|
30 |
import eu.dnetlib.miscutils.functional.UnaryFunction; |
|
31 |
|
|
32 |
public class MongoMDStore implements MDStore { |
|
33 |
|
|
34 |
private static final class SerializeMongoRecord implements UnaryFunction<String, DBObject> { |
|
35 |
|
|
36 |
@Override |
|
37 |
public String evaluate(final DBObject arg) { |
|
38 |
return (String) arg.get("body"); |
|
39 |
} |
|
40 |
} |
|
41 |
|
|
42 |
private static final class SerializeMongoRecordId implements UnaryFunction<String, DBObject> { |
|
43 |
|
|
44 |
@Override |
|
45 |
public String evaluate(final DBObject arg) { |
|
46 |
return (String) arg.get("id"); |
|
47 |
} |
|
48 |
} |
|
49 |
|
|
50 |
private static final Log log = LogFactory.getLog(MongoMDStore.class); |
|
51 |
|
|
52 |
private String id; |
|
53 |
private DBCollection collection; |
|
54 |
private DBCollection discardedCollection; |
|
55 |
|
|
56 |
private RecordParser recordParser; |
|
57 |
|
|
58 |
private final boolean upsert; |
|
59 |
private final boolean discardRecords; |
|
60 |
|
|
61 |
private static List<String> requiredIndicies = Lists.newArrayList("{ \"id\" : 1}", "{ \"timestamp\" : 1}", "{ \"originalId\" : 1}"); |
|
62 |
|
|
63 |
public MongoMDStore(final String id, final DBCollection collection, final RecordParser recordParser, final boolean upsert, final boolean discardRecords) { |
|
64 |
this.id = id; |
|
65 |
this.collection = collection; |
|
66 |
this.discardedCollection = collection.getDB().getCollection("discarded-" + StringUtils.substringBefore(id, "_")); |
|
67 |
this.recordParser = recordParser; |
|
68 |
this.upsert = upsert; |
|
69 |
this.discardRecords = discardRecords; |
|
70 |
} |
|
71 |
|
|
72 |
@Override |
|
73 |
public int feed(final Iterable<String> records, final boolean incremental) { |
|
74 |
ensureIndices(); |
|
75 |
|
|
76 |
final BlockingQueue<Object> queue = new ArrayBlockingQueue<Object>(80); |
|
77 |
final Object sentinel = new Object(); |
|
78 |
|
|
79 |
Thread background = new Thread(new Runnable() { |
|
80 |
|
|
81 |
@Override |
|
82 |
public void run() { |
|
83 |
while (true) { |
|
84 |
try { |
|
85 |
Object record = queue.take(); |
|
86 |
if (record == sentinel) { |
|
87 |
break; |
|
88 |
} |
|
89 |
safeFeedRecord((String) record, incremental); |
|
90 |
} catch (InterruptedException e) { |
|
91 |
log.fatal("got exception in background thread", e); |
|
92 |
throw new IllegalStateException(e); |
|
93 |
} |
|
94 |
} |
|
95 |
} |
|
96 |
}); |
|
97 |
background.start(); |
|
98 |
try { |
|
99 |
|
|
100 |
log.info("feeding mdstore " + id); |
|
101 |
for (final String record : records) { |
|
102 |
queue.put(record); |
|
103 |
} |
|
104 |
queue.put(sentinel); |
|
105 |
// safeFeedRecord(record, incremental); |
|
106 |
log.info("finished feeding mdstore " + id); |
|
107 |
|
|
108 |
background.join(); |
|
109 |
} catch (InterruptedException e) { |
|
110 |
throw new IllegalStateException(e); |
|
111 |
} |
|
112 |
|
|
113 |
// double check |
|
114 |
ensureIndices(); |
|
115 |
collection.ensureIndex(new BasicDBObject("id", 1)); |
|
116 |
|
|
117 |
return getSize(); |
|
118 |
} |
|
119 |
|
|
120 |
public void ensureIndices() { |
|
121 |
collection.resetIndexCache(); |
|
122 |
for (String key : Lists.newArrayList("id", "timestamp", "originalId")) { |
|
123 |
collection.ensureIndex(new BasicDBObject(key, 1)); |
|
124 |
} |
|
125 |
} |
|
126 |
|
|
127 |
public boolean isIndexed() { |
|
128 |
return Lists.newArrayList(new MappedCollection<String, DBObject>(collection.getIndexInfo(), new UnaryFunction<String, DBObject>() { |
|
129 |
|
|
130 |
@Override |
|
131 |
public String evaluate(final DBObject dbo) { |
|
132 |
return new BasicBSONObject(dbo.toMap()).getString("key"); |
|
133 |
} |
|
134 |
})).containsAll(requiredIndicies); |
|
135 |
} |
|
136 |
|
|
137 |
private void safeFeedRecord(final String record, final boolean incremental) { |
|
138 |
try { |
|
139 |
if (record.isEmpty()) return; |
|
140 |
feedRecord(record, incremental); |
|
141 |
} catch (final Throwable e) { |
|
142 |
if (discardRecords) { |
|
143 |
log.info("Got unhandled exception while parsing record", e); |
|
144 |
discardedCollection.insert(new BasicDBObject("body", record)); |
|
145 |
} |
|
146 |
} |
|
147 |
} |
|
148 |
|
|
149 |
private void feedRecord(final String record, final boolean incremental) { |
|
150 |
final Map<String, String> recordProperties = recordParser.parseRecord(record); |
|
151 |
|
|
152 |
log.debug("found props: " + recordProperties); |
|
153 |
if (recordProperties.containsKey("id")) { |
|
154 |
DBObject obj = new BasicDBObject(); |
|
155 |
final String id = recordProperties.get("id"); |
|
156 |
final String originalId = recordProperties.get("originalId"); |
|
157 |
obj.put("id", id); |
|
158 |
obj.put("originalId", originalId); |
|
159 |
obj.put("body", record); |
|
160 |
obj.put("timestamp", System.currentTimeMillis()); |
|
161 |
|
|
162 |
collection.update(new BasicDBObject("id", id), obj, upsert, false); |
|
163 |
} else { |
|
164 |
if (discardRecords) { |
|
165 |
log.debug("parsed record seems invalid"); |
|
166 |
discardedCollection.insert(new BasicDBObject("body", record)); |
|
167 |
} |
|
168 |
} |
|
169 |
} |
|
170 |
|
|
171 |
/** |
|
172 |
* Method searches for the given string grep into this collection and replaces it with the given replacement. |
|
173 |
* |
|
174 |
* @param grep |
|
175 |
* the string to search |
|
176 |
* @param replace |
|
177 |
* the replacement |
|
178 |
*/ |
|
179 |
public void replace(final String grep, final String replace) { |
|
180 |
Pattern regex = Pattern.compile(grep, Pattern.MULTILINE); |
|
181 |
DBCursor matches = collection.find(QueryBuilder.start("body").regex(regex).get()); |
|
182 |
|
|
183 |
log.debug("FOUND: " + matches.size()); |
|
184 |
|
|
185 |
for (DBObject match : matches) { |
|
186 |
DBObject o = new BasicDBObject(match.toMap()); |
|
187 |
o.put("body", regex.matcher((String) match.get("body")).replaceAll(replace)); |
|
188 |
collection.update(match, o); |
|
189 |
} |
|
190 |
} |
|
191 |
|
|
192 |
@Override |
|
193 |
public ResultSetListener deliver(final String from, final String until, final String recordFilter) { |
|
194 |
return deliver(from, until, recordFilter, new SerializeMongoRecord()); |
|
195 |
} |
|
196 |
|
|
197 |
@Override |
|
198 |
public ResultSetListener deliverIds(final String from, final String until, final String recordFilter) { |
|
199 |
return deliver(from, until, recordFilter, new SerializeMongoRecordId()); |
|
200 |
} |
|
201 |
|
|
202 |
public ResultSetListener deliver(final String from, final String until, final String recordFilter, final UnaryFunction<String, DBObject> serializer) { |
|
203 |
ensureIndices(); |
|
204 |
|
|
205 |
final Pattern filter = ((recordFilter != null) && (recordFilter.length() > 0)) ? Pattern.compile(recordFilter, Pattern.MULTILINE) : null; |
|
206 |
|
|
207 |
return new MongoResultSetListener(collection, filter, serializer); |
|
208 |
} |
|
209 |
|
|
210 |
@Override |
|
211 |
public Iterable<String> iterate() { |
|
212 |
return new Iterable<String>() { |
|
213 |
|
|
214 |
@Override |
|
215 |
public Iterator<String> iterator() { |
|
216 |
return Iterators.transform(collection.find(), MDStoreUtils.body()); |
|
217 |
} |
|
218 |
}; |
|
219 |
} |
|
220 |
|
|
221 |
@Override |
|
222 |
public void deleteRecord(final String recordId) { |
|
223 |
collection.remove(new BasicDBObject("id", recordId)); |
|
224 |
} |
|
225 |
|
|
226 |
@Override |
|
227 |
public String getRecord(final String recordId) throws DocumentNotFoundException { |
|
228 |
DBObject obj = collection.findOne(new BasicDBObject("id", recordId)); |
|
229 |
if ((obj == null) || (obj.containsField("body") == false)) throw new DocumentNotFoundException("The document with id " + id + " does not exist"); |
|
230 |
String body = (String) obj.get("body"); |
|
231 |
if (body.trim().length() == 0) throw new DocumentNotFoundException("The document with id " + id + " does not exist"); |
|
232 |
return (new SerializeMongoRecord()).evaluate(obj); |
|
233 |
} |
|
234 |
|
|
235 |
@Override |
|
236 |
public void truncate() { |
|
237 |
collection.drop(); |
|
238 |
discardedCollection.drop(); |
|
239 |
} |
|
240 |
|
|
241 |
public DBObject getMDStoreMetadata() { |
|
242 |
return collection.getDB().getCollection("metadata").findOne(new BasicDBObject("mdId", getId())); |
|
243 |
} |
|
244 |
|
|
245 |
@Override |
|
246 |
public String getFormat() { |
|
247 |
return (String) getMDStoreMetadata().get("format"); |
|
248 |
} |
|
249 |
|
|
250 |
@Override |
|
251 |
public String getInterpretation() { |
|
252 |
return (String) getMDStoreMetadata().get("interpretation"); |
|
253 |
} |
|
254 |
|
|
255 |
@Override |
|
256 |
public String getLayout() { |
|
257 |
return (String) getMDStoreMetadata().get("layout"); |
|
258 |
} |
|
259 |
|
|
260 |
@Override |
|
261 |
public String getId() { |
|
262 |
return id; |
|
263 |
} |
|
264 |
|
|
265 |
public void setId(final String id) { |
|
266 |
this.id = id; |
|
267 |
} |
|
268 |
|
|
269 |
public DBCollection getCollection() { |
|
270 |
return collection; |
|
271 |
} |
|
272 |
|
|
273 |
public void setCollection(final DBCollection collection) { |
|
274 |
this.collection = collection; |
|
275 |
} |
|
276 |
|
|
277 |
public RecordParser getRecordParser() { |
|
278 |
return recordParser; |
|
279 |
} |
|
280 |
|
|
281 |
@Required |
|
282 |
public void setRecordParser(final RecordParser recordParser) { |
|
283 |
this.recordParser = recordParser; |
|
284 |
} |
|
285 |
|
|
286 |
@Override |
|
287 |
public int getSize() { |
|
288 |
return (int) collection.getCount(); |
|
289 |
} |
|
290 |
|
|
291 |
public DBCollection getDiscardedCollection() { |
|
292 |
return discardedCollection; |
|
293 |
} |
|
294 |
|
|
295 |
public void setDiscardedCollection(final DBCollection discardedCollection) { |
|
296 |
this.discardedCollection = discardedCollection; |
|
297 |
} |
|
298 |
|
|
299 |
} |
modules/cnr-mongo-mdstore/releases/1.1.0/src/main/java/eu/dnetlib/data/mdstore/modular/inspector/MDStoreInspector.java | ||
---|---|---|
1 |
package eu.dnetlib.data.mdstore.modular.inspector; |
|
2 |
|
|
3 |
import static eu.dnetlib.miscutils.collections.MappedCollection.listMap; |
|
4 |
|
|
5 |
import java.util.List; |
|
6 |
|
|
7 |
import javax.annotation.Resource; |
|
8 |
|
|
9 |
import org.apache.commons.logging.Log; |
|
10 |
import org.apache.commons.logging.LogFactory; |
|
11 |
import org.springframework.stereotype.Controller; |
|
12 |
import org.springframework.ui.Model; |
|
13 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
14 |
import org.springframework.web.bind.annotation.RequestMethod; |
|
15 |
import org.springframework.web.bind.annotation.RequestParam; |
|
16 |
|
|
17 |
import com.google.common.collect.Iterables; |
|
18 |
import com.google.common.collect.Lists; |
|
19 |
|
|
20 |
import eu.dnetlib.data.mdstore.modular.MDStoreFeeder; |
|
21 |
import eu.dnetlib.data.mdstore.modular.connector.MDStore; |
|
22 |
import eu.dnetlib.data.mdstore.modular.connector.MDStoreDao; |
|
23 |
import eu.dnetlib.data.mdstore.modular.mongodb.MongoMDStore; |
|
24 |
import eu.dnetlib.enabling.inspector.AbstractInspectorController; |
|
25 |
import eu.dnetlib.enabling.resultset.ResultSetListener; |
|
26 |
import eu.dnetlib.miscutils.collections.MappedCollection; |
|
27 |
import eu.dnetlib.miscutils.functional.UnaryFunction; |
|
28 |
import eu.dnetlib.miscutils.functional.string.EscapeHtml; |
|
29 |
|
|
30 |
@Controller |
|
31 |
public class MDStoreInspector extends AbstractInspectorController { |
|
32 |
private static final Log log = LogFactory.getLog(MDStoreInspector.class); // NOPMD by marko on 11/24/08 5:02 PM |
|
33 |
|
|
34 |
@Resource(name="mongodbMDStoreDao") |
|
35 |
private MDStoreDao mdstoreDao; |
|
36 |
|
|
37 |
@Resource |
|
38 |
private MDStoreFeeder feeder; |
|
39 |
|
|
40 |
class MDStoreDescription { |
|
41 |
private String id; |
|
42 |
|
|
43 |
private int size; |
|
44 |
|
|
45 |
public MDStoreDescription(String id, int size) { |
|
46 |
super(); |
|
47 |
this.id = id; |
|
48 |
this.size = size; |
|
49 |
} |
|
50 |
|
|
51 |
public String getFormat() { |
|
52 |
return mdstoreDao.getMDStore(id).getFormat(); |
|
53 |
} |
|
54 |
|
|
55 |
public String getLayout() { |
|
56 |
return mdstoreDao.getMDStore(id).getLayout(); |
|
57 |
} |
|
58 |
|
|
59 |
public String getInterpretation() { |
|
60 |
return mdstoreDao.getMDStore(id).getInterpretation(); |
|
61 |
} |
|
62 |
|
|
63 |
public boolean getIndexed() { |
|
64 |
return ((MongoMDStore) mdstoreDao.getMDStore(id)).isIndexed(); |
|
65 |
} |
|
66 |
|
|
67 |
public String getId() { |
|
68 |
return id; |
|
69 |
} |
|
70 |
|
|
71 |
public void setId(String id) { |
|
72 |
this.id = id; |
|
73 |
} |
|
74 |
|
|
75 |
public int getSize() { |
|
76 |
return size; |
|
77 |
} |
|
78 |
|
|
79 |
public void setSize(int size) { |
|
80 |
this.size = size; |
|
81 |
} |
|
82 |
} |
|
83 |
|
|
84 |
@RequestMapping(value = "/inspector/mdstores.do") |
|
85 |
public void mdstores(final Model model) { |
|
86 |
model.addAttribute("mdstores", MappedCollection.listMap(mdstoreDao.listMDStores(), new UnaryFunction<MDStoreDescription, String>() { |
|
87 |
@Override |
|
88 |
public MDStoreDescription evaluate(String arg) { |
|
89 |
MDStore mdstore = mdstoreDao.getMDStore(arg); |
|
90 |
return new MDStoreDescription(arg, mdstore.getSize()); |
|
91 |
} |
|
92 |
})); |
|
93 |
} |
|
94 |
|
|
95 |
@RequestMapping(value = "/inspector/mdstore.do", method = RequestMethod.GET) |
|
96 |
public void mdstore( |
|
97 |
final Model model, |
|
98 |
@RequestParam("id") String id, |
|
99 |
@RequestParam(value = "start", required = false) Integer startParam, |
|
100 |
@RequestParam(value = "regex", required = false) String regex) { |
|
101 |
int pageSize = 10; |
|
102 |
int start = 0; |
|
103 |
|
|
104 |
if (startParam != null) |
|
105 |
start = startParam; |
|
106 |
|
|
107 |
MDStore mdstore = mdstoreDao.getMDStore(id); |
|
108 |
|
|
109 |
ResultSetListener rs = mdstore.deliver(null, null, regex); |
|
110 |
List<String> page = rs.getResult(1 + start, start + pageSize); |
|
111 |
|
|
112 |
model.addAttribute("id", id); |
|
113 |
model.addAttribute("start", start); |
|
114 |
model.addAttribute("regex", regex); |
|
115 |
model.addAttribute("nextPage", start + pageSize); |
|
116 |
model.addAttribute("prevPage", Math.max(0, start - pageSize)); |
|
117 |
model.addAttribute("size", rs.getSize()); |
|
118 |
model.addAttribute("page", listMap(page, new EscapeHtml())); |
|
119 |
} |
|
120 |
|
|
121 |
@RequestMapping(value = "/inspector/mdstore.do", method = RequestMethod.POST) |
|
122 |
public String bulkReplace( |
|
123 |
final Model model, |
|
124 |
@RequestParam("id") String id, |
|
125 |
@RequestParam("regex") final String regex, |
|
126 |
@RequestParam("replace") final String replace, |
|
127 |
@RequestParam(value = "checkReplace", required = false) final Boolean checkReplace) { |
|
128 |
|
|
129 |
log.debug("regex: " + regex); |
|
130 |
log.debug("replace: " + replace); |
|
131 |
|
|
132 |
MongoMDStore mdstore = (MongoMDStore) mdstoreDao.getMDStore(id); |
|
133 |
|
|
134 |
boolean replaceEnable = checkReplace != null && checkReplace == true; |
|
135 |
|
|
136 |
if (replaceEnable) |
|
137 |
mdstore.replace(regex, replace); |
|
138 |
else |
|
139 |
model.addAttribute("regex", regex); |
|
140 |
|
|
141 |
return "redirect:mdstore.do?id=" + id; |
|
142 |
} |
|
143 |
|
|
144 |
@RequestMapping(value = "/inspector/mdstoreEditResult.do") |
|
145 |
public void mdstoreEditRecord(final Model model, @RequestParam("id") String id, @RequestParam("start") int start, @RequestParam("index") int index) { |
|
146 |
MDStore mdstore = mdstoreDao.getMDStore(id); |
|
147 |
|
|
148 |
ResultSetListener rs = mdstore.deliver(null, null, null); |
|
149 |
List<String> page = rs.getResult(1 + index + start, 1 + index + start); |
|
150 |
|
|
151 |
model.addAttribute("id", id); |
|
152 |
model.addAttribute("start", start); |
|
153 |
model.addAttribute("record", new EscapeHtml().evaluate(Iterables.getOnlyElement(page))); |
|
154 |
} |
|
155 |
|
|
156 |
@RequestMapping(value = "/inspector/mdstoreSaveRecord.do") |
|
157 |
public String mdstoreSaveRecord( |
|
158 |
final Model model, |
|
159 |
@RequestParam("id") String id, |
|
160 |
@RequestParam("start") int start, |
|
161 |
@RequestParam("record") String record) { |
|
162 |
MDStore mdstore = mdstoreDao.getMDStore(id); |
|
163 |
|
|
164 |
mdstore.feed(Lists.newArrayList(record), true); |
|
165 |
|
|
166 |
return "redirect:mdstore.do?id=" + id + "&start=" + start; |
|
167 |
} |
|
168 |
|
|
169 |
@RequestMapping(value = "/inspector/mdstoreDeleteRecord.do") |
|
170 |
public String mdstoreDeleteRecord(final Model model, @RequestParam("id") String id, @RequestParam("start") int start, @RequestParam("index") int index) { |
|
171 |
MDStore mdstore = mdstoreDao.getMDStore(id); |
|
172 |
|
|
173 |
ResultSetListener rs = mdstore.deliverIds(null, null, null); |
|
174 |
List<String> page = rs.getResult(1 + index + start, 1 + index + start); |
|
175 |
String recordId = Iterables.getOnlyElement(page); |
|
176 |
|
|
177 |
log.fatal("deleting record " + recordId); |
|
178 |
mdstore.deleteRecord(recordId); |
|
179 |
|
|
180 |
return "redirect:mdstore.do?id=" + id + "&start=" + start; |
|
181 |
} |
|
182 |
|
|
183 |
@RequestMapping(value = "/inspector/mdstoresRefreshSizes.do") |
|
184 |
public String mdstoresRefreshSizes(final Model model) { |
|
185 |
|
|
186 |
for (String mdId : mdstoreDao.listMDStores()) |
|
187 |
feeder.touchSize(mdId, mdstoreDao.getMDStore(mdId).getSize()); |
|
188 |
|
|
189 |
return "redirect:mdstores.do"; |
|
190 |
} |
|
191 |
|
|
192 |
@RequestMapping(value = "/inspector/ensure.do") |
|
193 |
public String mdstoreEnsureIndex(final Model model, @RequestParam("id") String id) { |
|
194 |
MongoMDStore mdStore = (MongoMDStore) mdstoreDao.getMDStore(id); |
|
195 |
|
|
196 |
log.info("manual ensureIndex for mdId: " + id); |
|
197 |
mdStore.ensureIndices(); |
|
198 |
|
|
199 |
return "redirect:mdstores.do"; |
|
200 |
} |
|
201 |
|
|
202 |
} |
modules/cnr-mongo-mdstore/releases/1.1.0/src/main/resources/eu/dnetlib/enabling/views/inspector/mdstore.st | ||
---|---|---|
1 |
$inspector/master(it={ |
|
2 |
|
|
3 |
<style type="text/css"> |
|
4 |
.mdstoreRecords li.record { |
|
5 |
display: block; |
|
6 |
border-top: 1px solid #ccc; |
|
7 |
} |
|
8 |
|
|
9 |
.mdstoreRecords ul.nav li { |
|
10 |
display: inline; |
|
11 |
} |
|
12 |
</style> |
|
13 |
|
|
14 |
<h2>MDStore details</h2> |
|
15 |
<p> |
|
16 |
|
|
17 |
<form action="mdstore.do?id=$id$" method="POST"> |
|
18 |
GREP: <input name="regex" value="$regex$"/> REPLACEMENT: <input name="replace" value="$replace$"/> |
|
19 |
Replace? <input type="checkbox" name="checkReplace" $if(checkReplace)$checked="checked"$endif$/> |
|
20 |
<input type="submit" value="grep/repl"/> |
|
21 |
</form> |
|
22 |
</p> |
|
23 |
|
|
24 |
<p>Show from: $start$ (<a href="?id=$id$&start=$prevPage$®ex=$regex$">prev</a>) out of $size$ (<a href="?id=$id$&start=$nextPage$®ex=$regex$">next</a>)</p> |
|
25 |
|
|
26 |
<ul class="mdstoreRecords"> |
|
27 |
$page:{ |
|
28 |
<li class="record"> |
|
29 |
<ul class="nav"> |
|
30 |
<li><a href="mdstoreEditResult.do?id=$id$&start=$start$&index=$i0$">edit</a></li> |
|
31 |
<li><a href="mdstoreDeleteRecord.do?id=$id$&start=$start$&index=$i0$">delete</a></li> |
|
32 |
</ul> |
|
33 |
<pre>$it$</pre> |
|
34 |
</li> |
|
35 |
}$ |
|
36 |
</ul> |
|
37 |
})$ |
modules/cnr-mongo-mdstore/releases/1.1.0/src/main/resources/eu/dnetlib/enabling/views/inspector/mdstores.st | ||
---|---|---|
1 |
$inspector/master(it={ |
|
2 |
|
|
3 |
<h2>MDStores</h2> |
|
4 |
|
|
5 |
<table> |
|
6 |
<tr> |
|
7 |
<th>Format</th> |
|
8 |
<th>Layout</th> |
|
9 |
<th>Interpretation</th> |
|
10 |
<th>Size</th> |
|
11 |
<th>ID</th> |
|
12 |
<th>Indexed?</th> |
|
13 |
<th>Ensure index</th> |
|
14 |
</tr> |
|
15 |
$mdstores:{ |
|
16 |
<tr><td>$it.format$</td><td>$it.layout$</td><td>$it.interpretation$</td><td>$it.size$</td><td><a href="mdstore.do?id=$it.id$">$it.id$</a></td><td><span class="$if(it.indexed)$enabled$else$disabled$endif$">$it.indexed$</span></td><td><a href="ensure.do?id=$it.id$">GO</a></td></tr> |
|
17 |
}$ |
|
18 |
</table> |
|
19 |
})$ |
modules/cnr-mongo-mdstore/releases/1.1.0/src/main/resources/eu/dnetlib/enabling/views/inspector/mdstoreEditResult.st | ||
---|---|---|
1 |
$inspector/master(it={ |
|
2 |
|
|
3 |
<style type="text/css"> |
|
4 |
#record { |
|
5 |
height: 60em; |
|
6 |
width: 100%; |
|
7 |
border: 1px solid #B0B0FF; |
|
8 |
padding: 4px; |
|
9 |
} |
|
10 |
</style> |
|
11 |
|
|
12 |
<h2>Low level edit mdstore record:</h2> |
|
13 |
|
|
14 |
<ul> |
|
15 |
<li><a href="javascript:document.forms[0].submit()">save</a></li> |
|
16 |
</ul> |
|
17 |
|
|
18 |
<p> It will <b>not</b> trigger a mdstore modification date. </p> |
|
19 |
|
|
20 |
<form action="mdstoreSaveRecord.do" method="POST"> |
|
21 |
<input type="hidden" name="id" value="$id$"/> |
|
22 |
<input type="hidden" name="start" value="$start$"/> |
|
23 |
|
|
24 |
<textarea id="record" name="record"> |
|
25 |
$record$ |
|
26 |
</textarea> |
|
27 |
|
|
28 |
</form> |
|
29 |
|
|
30 |
})$ |
modules/cnr-mongo-mdstore/releases/1.1.0/src/main/resources/eu/dnetlib/data/mdstore/modular/mongodb/utils/applicationContext-mongo-mdstore-scheduler.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<beans xmlns="http://www.springframework.org/schema/beans" |
|
3 |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws" |
|
4 |
xmlns:sec="http://cxf.apache.org/configuration/security" xmlns:wsa="http://cxf.apache.org/ws/addressing" |
|
5 |
xmlns:p="http://www.springframework.org/schema/p" xmlns:http="http://cxf.apache.org/transports/http/configuration" |
|
6 |
xmlns:t="http://dnetlib.eu/springbeans/t" xmlns:template="http://dnetlib.eu/springbeans/template" |
|
7 |
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd |
|
8 |
http://cxf.apache.org/ws/addressing http://cxf.apache.org/schemas/ws-addr-conf.xsd |
|
9 |
http://cxf.apache.org/configuration/security http://cxf.apache.org/schemas/configuration/security.xsd |
|
10 |
http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd |
|
11 |
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd |
|
12 |
http://dnetlib.eu/springbeans/template http://dnetlib.eu/springbeans/template.xsd"> |
|
13 |
|
|
14 |
<!-- beans --> |
|
15 |
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean" |
|
16 |
depends-on="mdStoreService"> |
|
17 |
<property name="triggers"> |
|
18 |
<list> |
|
19 |
<ref bean="mdStoreCheckTrigger"/> |
|
20 |
</list> |
|
21 |
</property> |
|
22 |
</bean> |
|
23 |
|
|
24 |
<bean id="mdStoreEnsureIndexScheduler" |
|
25 |
class="eu.dnetlib.data.mdstore.modular.mongodb.utils.EnsureIndexJob" |
|
26 |
p:cronExpression="${services.mdstore.mongodb.ensureindex.cron}" |
|
27 |
p:enabled="${services.mdstore.mongodb.ensureindex.enable}" |
|
28 |
p:dao-ref="mongodbMDStoreDao" /> |
|
29 |
|
|
30 |
<bean id="mdStoreCheckTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean" |
|
31 |
p:startDelay="${services.mdstore.mongodb.checkmetadata.startdelay}" p:repeat-count="0" p:repeatInterval="60000"> |
|
32 |
<property name="jobDetail"> |
|
33 |
<bean class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> |
|
34 |
<property name="targetObject" ref="mdStoreCheckMetadataMBean" /> |
|
35 |
<property name="targetMethod" value="runOnStart" /> |
|
36 |
<property name="concurrent" value="false" /> |
|
37 |
</bean> |
|
38 |
</property> |
|
39 |
</bean> |
|
40 |
|
|
41 |
<bean id="mdStoreCheckMetadataMBean" |
|
42 |
class="eu.dnetlib.data.mdstore.modular.mongodb.utils.MetadataCheckJob" |
|
43 |
depends-on="mdStoreService" |
|
44 |
p:runOnStart="${services.mdstore.mongodb.checkmetadata.onstart}" |
|
45 |
p:dao-ref="mongodbMDStoreDao" p:lookupLocator-ref="lookupLocator" |
|
46 |
p:endpoint-ref="mdStoreServiceEndpoint" p:eprBuilder-ref="jaxwsEndpointReferenceBuilder" /> |
|
47 |
|
|
48 |
<bean id="jmxExporter" class="org.springframework.jmx.export.MBeanExporter"> |
|
49 |
<property name="beans"> |
|
50 |
<map> |
|
51 |
<entry key="mongodbMDStore:name=metadata" value-ref="mdStoreCheckMetadataMBean" /> |
|
52 |
</map> |
|
53 |
</property> |
|
54 |
</bean> |
|
55 |
|
|
56 |
</beans> |
modules/cnr-mongo-mdstore/releases/1.1.0/src/main/resources/eu/dnetlib/data/mdstore/modular/mongodb/applicationContext-mongodb-mdstore.properties | ||
---|---|---|
1 |
services.mdstore.mongodb.host=localhost |
|
2 |
services.mdstore.mongodb.port=27017 |
|
3 |
services.mdstore.mongodb.db=mdstore |
|
4 |
services.mdstore.mongodb.connectionsPerHost=20 |
|
5 |
|
|
6 |
services.mdstore.mongodb.ensureindex.cron=0 0 23 * * ? |
|
7 |
services.mdstore.mongodb.ensureindex.enable=false |
|
8 |
services.mdstore.mongodb.checkmetadata.onstart=true |
|
9 |
services.mdstore.mongodb.checkmetadata.startdelay=30000 |
|
10 |
|
|
11 |
services.mdstore.mongodb.upsert=true |
|
12 |
|
modules/cnr-mongo-mdstore/releases/1.1.0/src/main/resources/eu/dnetlib/data/mdstore/modular/mongodb/applicationContext-mongodb-mdstore.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<beans xmlns="http://www.springframework.org/schema/beans" |
|
3 |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" |
|
4 |
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> |
|
5 |
|
|
6 |
<bean id="mongodbMDStoreDao" class="eu.dnetlib.data.mdstore.modular.mongodb.MDStoreDaoImpl" |
|
7 |
p:db-ref="mdstoreMongoDB" p:recordParser-ref="mdstoreRecordParser" |
|
8 |
p:upsert="${services.mdstore.mongodb.upsert}" |
|
9 |
p:discardRecords="${services.mdstore.discardrecords}"/> |
|
10 |
|
|
11 |
<bean id="mdstoreMongoServer" class="com.mongodb.Mongo"> |
|
12 |
<constructor-arg index="0" type="com.mongodb.ServerAddress"> |
|
13 |
<bean class="com.mongodb.ServerAddress"> |
|
14 |
<constructor-arg index="0" |
|
15 |
value="${services.mdstore.mongodb.host}" /> |
|
16 |
<constructor-arg index="1" |
|
17 |
value="${services.mdstore.mongodb.port}" /> |
|
18 |
</bean> |
|
19 |
</constructor-arg> |
|
20 |
<constructor-arg index="1" type="com.mongodb.MongoOptions"> |
|
21 |
<bean class="eu.dnetlib.mongodb.MongoOptionsFactory" |
|
22 |
p:connectionsPerHost="${services.mdstore.mongodb.connectionsPerHost}" /> |
|
23 |
</constructor-arg> |
|
24 |
</bean> |
|
25 |
|
|
26 |
<bean id="mdstoreMongoDB" factory-bean="mdstoreMongoServer" |
|
27 |
factory-method="getDB"> |
|
28 |
<constructor-arg index="0" |
|
29 |
value="${services.mdstore.mongodb.db}" /> |
|
30 |
</bean> |
|
31 |
|
|
32 |
</beans> |
modules/cnr-mongo-mdstore/releases/1.1.0/src/main/resources/eu/dnetlib/data/mdstore/modular/inspector/webContext-mdstore-inspector.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<beans xmlns="http://www.springframework.org/schema/beans" |
|
3 |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" |
|
4 |
xmlns:util="http://www.springframework.org/schema/util" |
|
5 |
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd |
|
6 |
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd"> |
|
7 |
|
|
8 |
<bean id="mdstoreInspectorGroup" |
|
9 |
class="eu.dnetlib.enabling.inspector.StaticEntryPointDescriptorGroup" |
|
10 |
p:name="mdstore"> |
|
11 |
<property name="descriptors"> |
|
12 |
<list> |
|
13 |
<bean class="eu.dnetlib.enabling.inspector.StaticEntryPointDescriptor" |
|
14 |
p:name="mdstores" p:relativeUrl="mdstores.do" /> |
|
15 |
</list> |
|
16 |
</property> |
|
17 |
</bean> |
|
18 |
|
|
19 |
</beans> |
|
20 |
|
modules/cnr-mongo-mdstore/releases/1.1.0/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|
3 |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
|
4 |
<parent> |
|
5 |
<groupId>eu.dnetlib</groupId> |
|
6 |
<artifactId>dnet-parent</artifactId> |
|
7 |
<version>1.0.0-SNAPSHOT</version> |
|
8 |
</parent> |
|
9 |
<modelVersion>4.0.0</modelVersion> |
|
10 |
<groupId>eu.dnetlib</groupId> |
|
11 |
<artifactId>cnr-mongo-mdstore</artifactId> |
|
12 |
<packaging>jar</packaging> |
|
13 |
<version>1.1.0-SNAPSHOT</version> |
|
14 |
<dependencies> |
|
15 |
<dependency> |
|
16 |
<groupId>junit</groupId> |
|
17 |
<artifactId>junit</artifactId> |
|
18 |
<version>${junit.version}</version> |
|
19 |
<scope>test</scope> |
|
20 |
</dependency> |
|
21 |
<dependency> |
|
22 |
<groupId>org.springframework</groupId> |
|
23 |
<artifactId>spring-test</artifactId> |
|
24 |
<version>${spring.version}</version> |
|
25 |
<scope>test</scope> |
|
26 |
</dependency> |
|
27 |
<dependency> |
|
28 |
<groupId>org.mockito</groupId> |
|
29 |
<artifactId>mockito-core</artifactId> |
|
30 |
<version>1.6</version> |
|
31 |
<scope>test</scope> |
|
32 |
</dependency> |
|
33 |
<dependency> |
|
34 |
<groupId>eu.dnetlib</groupId> |
|
35 |
<artifactId>cnr-test-utils</artifactId> |
|
36 |
<version>[1.0.0-SNAPSHOT]</version> |
|
37 |
<scope>test</scope> |
|
38 |
</dependency> |
|
39 |
<dependency> |
|
40 |
<groupId>eu.dnetlib</groupId> |
|
41 |
<artifactId>cnr-modular-mdstore-service</artifactId> |
|
42 |
<version>[2.0.0-SNAPSHOT]</version> |
|
43 |
</dependency> |
|
44 |
<dependency> |
|
45 |
<groupId>eu.dnetlib</groupId> |
|
46 |
<artifactId>cnr-inspector</artifactId> |
|
47 |
<version>[1.0.0-SNAPSHOT]</version> |
|
48 |
</dependency> |
|
49 |
<dependency> |
|
50 |
<groupId>org.mongodb</groupId> |
|
51 |
<artifactId>mongo-java-driver</artifactId> |
|
52 |
<version>${mongodb.driver.version}</version> |
|
53 |
</dependency> |
|
54 |
</dependencies> |
|
55 |
</project> |
modules/cnr-mongo-mdstore/trunk/deploy.info | ||
---|---|---|
1 |
{"type_source": "SVN", "goal": "package -U -T 4C source:jar", "url": "http://svn-public.driver.research-infrastructures.eu/driver/dnet40/modules/cnr-mongo-mdstore/trunk/", "deploy_repository": "dnet4-snapshots", "version": "4", "mail": "sandro.labruzzo@isti.cnr.it,michele.artini@isti.cnr.it, claudio.atzori@isti.cnr.it, alessia.bardi@isti.cnr.it", "deploy_repository_url": "http://maven.research-infrastructures.eu/nexus/content/repositories/dnet4-snapshots", "name": "cnr-mongo-mdstore"} |
modules/cnr-mongo-mdstore/trunk/src/test/java/eu/dnetlib/data/mdstore/modular/mongodb/MDStoreDaoImplTest.java | ||
---|---|---|
1 |
package eu.dnetlib.data.mdstore.modular.mongodb; |
|
2 |
|
|
3 |
import com.mongodb.BasicDBObject; |
|
4 |
import com.mongodb.DBObject; |
|
5 |
import com.mongodb.client.MongoCollection; |
|
6 |
import com.mongodb.client.MongoDatabase; |
|
7 |
import eu.dnetlib.data.mdstore.MDStoreServiceException; |
|
8 |
import eu.dnetlib.data.mdstore.modular.connector.MDStoreDBStatus; |
|
9 |
import eu.dnetlib.data.mdstore.modular.connector.MDStoreDao; |
|
10 |
import eu.dnetlib.data.mdstore.modular.connector.MDStoreTransactionManager; |
|
11 |
import org.junit.After; |
|
12 |
import org.junit.Before; |
|
13 |
import org.junit.Ignore; |
|
14 |
import org.junit.Test; |
|
15 |
import org.junit.runner.RunWith; |
|
16 |
import org.springframework.beans.factory.annotation.Autowired; |
|
17 |
import org.springframework.test.context.ContextConfiguration; |
|
18 |
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
|
19 |
|
|
20 |
import static org.junit.Assert.assertEquals; |
|
21 |
|
|
22 |
@Ignore |
|
23 |
@RunWith(SpringJUnit4ClassRunner.class) |
|
24 |
@ContextConfiguration(classes = ConfigurationTestConfig.class) |
|
25 |
public class MDStoreDaoImplTest { |
|
26 |
|
|
27 |
@Autowired |
|
28 |
private MDStoreDao dao; |
|
29 |
@Autowired |
|
30 |
private MongoDatabase db; |
|
31 |
@Autowired |
|
32 |
private MDStoreTransactionManager manager; |
|
33 |
|
|
34 |
@After |
|
35 |
public void tearDown() throws MDStoreServiceException { |
|
36 |
dao.deleteMDStore("1"); |
|
37 |
dao.deleteMDStore("2"); |
|
38 |
dao.deleteMDStore("3"); |
|
39 |
dao.deleteMDStore("4"); |
|
40 |
dao.deleteMDStore("5"); |
|
41 |
dao.deleteMDStore("6"); |
|
42 |
} |
|
43 |
|
|
44 |
@Before |
|
45 |
public void setUp() throws Exception { |
|
46 |
dao.createMDStore("1", "F", "I", "L"); |
|
47 |
dao.createMDStore("2", "F", "I", "L"); |
|
48 |
dao.createMDStore("3", "F", "I", "L"); |
|
49 |
dao.createMDStore("4", "F", "I", "L"); |
|
50 |
dao.createMDStore("5", "F1", "I", "L"); |
|
51 |
dao.createMDStore("6", "F1", "I", "L"); |
|
52 |
|
|
53 |
final MongoCollection<DBObject> metadata = db.getCollection(MDStoreDaoImpl.METADATA_NAME, DBObject.class); |
|
54 |
|
|
55 |
metadata.findOneAndUpdate(new BasicDBObject(MDStoreDaoImpl.MD_ID, "1"), new BasicDBObject("$set", new BasicDBObject(MDStoreDaoImpl.SIZE, 10))); |
|
56 |
metadata.findOneAndUpdate(new BasicDBObject(MDStoreDaoImpl.MD_ID, "2"), new BasicDBObject("$set", new BasicDBObject(MDStoreDaoImpl.SIZE, 10))); |
|
57 |
metadata.findOneAndUpdate(new BasicDBObject(MDStoreDaoImpl.MD_ID, "3"), new BasicDBObject("$set", new BasicDBObject(MDStoreDaoImpl.SIZE, 10))); |
|
58 |
metadata.findOneAndUpdate(new BasicDBObject(MDStoreDaoImpl.MD_ID, "4"), new BasicDBObject("$set", new BasicDBObject(MDStoreDaoImpl.SIZE, 10))); |
|
59 |
metadata.findOneAndUpdate(new BasicDBObject(MDStoreDaoImpl.MD_ID, "5"), new BasicDBObject("$set", new BasicDBObject(MDStoreDaoImpl.SIZE, 10))); |
|
60 |
metadata.findOneAndUpdate(new BasicDBObject(MDStoreDaoImpl.MD_ID, "6"), new BasicDBObject("$set", new BasicDBObject(MDStoreDaoImpl.SIZE, 10))); |
|
61 |
|
|
62 |
} |
|
63 |
|
|
64 |
@Test |
|
65 |
public void test() throws MDStoreServiceException { |
|
66 |
assertEquals(40, dao.getSumOfSizes("F", "L", "I")); |
|
67 |
assertEquals(20, dao.getSumOfSizes("F1", "L", "I")); |
|
68 |
assertEquals(0, dao.getSumOfSizes("F_0", "L", "I")); |
|
69 |
} |
|
70 |
|
|
71 |
@Test |
|
72 |
public void getDBStatusTest() { |
|
73 |
final MDStoreDBStatus dbStatus = dao.getDBStatus(); |
|
74 |
System.out.println(dbStatus); |
|
75 |
|
|
76 |
} |
|
77 |
|
|
78 |
} |
modules/cnr-mongo-mdstore/trunk/src/test/java/eu/dnetlib/data/mdstore/modular/mongodb/FeedSpeedTest.java | ||
---|---|---|
1 |
package eu.dnetlib.data.mdstore.modular.mongodb; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.io.FileInputStream; |
|
5 |
import java.io.IOException; |
|
6 |
import java.util.Iterator; |
|
7 |
import java.util.UUID; |
|
8 |
|
|
9 |
import com.mongodb.DBObject; |
|
10 |
import com.mongodb.client.MongoDatabase; |
|
11 |
import eu.dnetlib.data.mdstore.MDStoreServiceException; |
Also available in: Unified diff
codebase used to migrate to java8 the production system