Search in sources :

Example 1 with NamedMongoScript

use of org.springframework.data.mongodb.core.script.NamedMongoScript in project ocvn by devgateway.

the class MongoTemplateConfiguration method createPostImportStructures.

public void createPostImportStructures() {
    createCorruptionFlagsIndexes();
    // initialize some extra indexes
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("ocid", Direction.ASC).unique());
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("tender.procurementMethod", Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("tender.procurementMethodRationale", Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("tender.status", Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("awards.status", Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("awards.suppliers._id", Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("awards.date", Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("awards.publishedDate", Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("awards.value.amount", Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("tender.value.amount", Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("tender.contrMethod._id", Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("tender.numberOfTenderers", Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("tender.cancellationRationale", Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("tender.submissionMethod", Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("tender.publicationMethod", Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on(MongoConstants.FieldNames.TENDER_PERIOD_START_DATE, Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on(MongoConstants.FieldNames.TENDER_PERIOD_END_DATE, Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("tender.items.classification._id", Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("tender.items.deliveryLocation._id", Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("tender.items.deliveryLocation.geometry.coordinates", Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("planning.budget.projectLocation.geometry.coordinates", Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("planning.budget.projectLocation._id", Direction.ASC));
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("tender.items.deliveryLocation.geometry.coordinates", Direction.ASC));
    mongoTemplate.indexOps(Organization.class).ensureIndex(new TextIndexDefinitionBuilder().onField("name").onField("id").onField("additionalIdentifiers._id").build());
    mongoTemplate.indexOps(VNLocation.class).ensureIndex(new TextIndexDefinitionBuilder().onField("description").onField("uri").build());
    //vietnam specific indexes:
    mongoTemplate.indexOps(Release.class).ensureIndex(new Index().on("planning.bidPlanProjectDateApprove", Direction.ASC));
    createProcuringEntityIndexes();
    logger.info("Added extra Mongo indexes");
    ScriptOperations scriptOps = mongoTemplate.scriptOps();
    // add script to calculate the percentiles endpoint
    URL scriptFile = getClass().getResource("/tenderBidPeriodPercentilesMongo.js");
    try {
        String scriptText = IOUtils.toString(scriptFile);
        ExecutableMongoScript script = new ExecutableMongoScript(scriptText);
        scriptOps.register(new NamedMongoScript("tenderBidPeriodPercentiles", script));
    } catch (IOException e) {
        e.printStackTrace();
    }
    // add general mongo system helper methods
    URL systemScriptFile = getClass().getResource("/mongoSystemScripts.js");
    try {
        String systemScriptFileText = IOUtils.toString(systemScriptFile);
        ExecutableMongoScript script = new ExecutableMongoScript(systemScriptFileText);
        scriptOps.execute(script);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : TextIndexDefinitionBuilder(org.springframework.data.mongodb.core.index.TextIndexDefinition.TextIndexDefinitionBuilder) VNLocation(org.devgateway.ocvn.persistence.mongo.dao.VNLocation) Organization(org.devgateway.ocds.persistence.mongo.Organization) ScriptOperations(org.springframework.data.mongodb.core.ScriptOperations) ExecutableMongoScript(org.springframework.data.mongodb.core.script.ExecutableMongoScript) Index(org.springframework.data.mongodb.core.index.Index) IOException(java.io.IOException) NamedMongoScript(org.springframework.data.mongodb.core.script.NamedMongoScript) Release(org.devgateway.ocds.persistence.mongo.Release) URL(java.net.URL)

Example 2 with NamedMongoScript

use of org.springframework.data.mongodb.core.script.NamedMongoScript in project spring-data-mongodb by spring-projects.

the class DefaultScriptOperationsUnitTests method saveShouldGenerateScriptNameForExecutableMongoScripts.

// DATAMONGO-479
@Test
public void saveShouldGenerateScriptNameForExecutableMongoScripts() {
    scriptOps.register(new ExecutableMongoScript("function..."));
    ArgumentCaptor<NamedMongoScript> captor = ArgumentCaptor.forClass(NamedMongoScript.class);
    verify(mongoOperations, times(1)).save(captor.capture(), eq("system.js"));
    Assert.assertThat(captor.getValue().getName(), notNullValue());
}
Also used : ExecutableMongoScript(org.springframework.data.mongodb.core.script.ExecutableMongoScript) NamedMongoScript(org.springframework.data.mongodb.core.script.NamedMongoScript) Test(org.junit.Test)

Example 3 with NamedMongoScript

use of org.springframework.data.mongodb.core.script.NamedMongoScript in project spring-data-mongodb by spring-projects.

the class DefaultScriptOperationsUnitTests method saveShouldUseCorrectCollectionName.

// DATAMONGO-479
@Test
public void saveShouldUseCorrectCollectionName() {
    scriptOps.register(new NamedMongoScript("foo", "function..."));
    verify(mongoOperations, times(1)).save(any(NamedMongoScript.class), eq("system.js"));
}
Also used : NamedMongoScript(org.springframework.data.mongodb.core.script.NamedMongoScript) Test(org.junit.Test)

Example 4 with NamedMongoScript

use of org.springframework.data.mongodb.core.script.NamedMongoScript in project spring-data-mongodb by spring-projects.

the class DefaultScriptOperations method getScriptNames.

/*
	 * (non-Javadoc)
	 * @see org.springframework.data.mongodb.core.ScriptOperations#getScriptNames()
	 */
@Override
public Set<String> getScriptNames() {
    List<NamedMongoScript> scripts = mongoOperations.findAll(NamedMongoScript.class, SCRIPT_COLLECTION_NAME);
    if (CollectionUtils.isEmpty(scripts)) {
        return Collections.emptySet();
    }
    Set<String> scriptNames = new HashSet<String>();
    for (NamedMongoScript script : scripts) {
        scriptNames.add(script.getName());
    }
    return scriptNames;
}
Also used : NamedMongoScript(org.springframework.data.mongodb.core.script.NamedMongoScript) HashSet(java.util.HashSet)

Example 5 with NamedMongoScript

use of org.springframework.data.mongodb.core.script.NamedMongoScript in project oc-explorer by devgateway.

the class AbstractMongoDatabaseConfiguration method createPostImportStructures.

public void createPostImportStructures() {
    createCorruptionFlagsIndexes();
    // initialize some extra indexes
    getTemplate().indexOps(Release.class).ensureIndex(new Index().on("ocid", Direction.ASC).unique());
    getTemplate().indexOps(Release.class).ensureIndex(new Index().on(MongoConstants.FieldNames.TENDER_PROC_METHOD, Direction.ASC));
    getTemplate().indexOps(Release.class).ensureIndex(new Index().on("tender.procurementMethodRationale", Direction.ASC));
    getTemplate().indexOps(Release.class).ensureIndex(new Index().on(MongoConstants.FieldNames.TENDER_STATUS, Direction.ASC));
    getTemplate().indexOps(Release.class).ensureIndex(new Index().on(MongoConstants.FieldNames.AWARDS_STATUS, Direction.ASC));
    getTemplate().indexOps(Release.class).ensureIndex(new Index().on(MongoConstants.FieldNames.AWARDS_SUPPLIERS_ID, Direction.ASC));
    getTemplate().indexOps(Release.class).ensureIndex(new Index().on(MongoConstants.FieldNames.AWARDS_SUPPLIERS_NAME, Direction.ASC));
    getTemplate().indexOps(Release.class).ensureIndex(new Index().on(MongoConstants.FieldNames.AWARDS_DATE, Direction.ASC));
    getTemplate().indexOps(Release.class).ensureIndex(new Index().on(MongoConstants.FieldNames.AWARDS_VALUE_AMOUNT, Direction.ASC));
    getTemplate().indexOps(Release.class).ensureIndex(new Index().on(MongoConstants.FieldNames.TENDER_VALUE_AMOUNT, Direction.ASC));
    getTemplate().indexOps(Release.class).ensureIndex(new Index().on(MongoConstants.FieldNames.TENDER_NO_TENDERERS, Direction.ASC));
    getTemplate().indexOps(Release.class).ensureIndex(new Index().on(MongoConstants.FieldNames.TENDER_SUBMISSION_METHOD, Direction.ASC));
    getTemplate().indexOps(Release.class).ensureIndex(new Index().on(MongoConstants.FieldNames.TENDER_PERIOD_START_DATE, Direction.ASC));
    getTemplate().indexOps(Release.class).ensureIndex(new Index().on(MongoConstants.FieldNames.TENDER_PERIOD_END_DATE, Direction.ASC));
    getTemplate().indexOps(Release.class).ensureIndex(new Index().on("tender.items.classification._id", Direction.ASC));
    getTemplate().indexOps(Release.class).ensureIndex(new Index().on("tender.items.deliveryLocation._id", Direction.ASC));
    getTemplate().indexOps(Release.class).ensureIndex(new Index().on("tender.items.deliveryLocation.geometry.coordinates", Direction.ASC));
    getTemplate().indexOps(Release.class).ensureIndex(new Index().on(MongoConstants.FieldNames.BIDS_DETAILS_TENDERERS_ID, Direction.ASC));
    getTemplate().indexOps(Release.class).ensureIndex(new Index().on(MongoConstants.FieldNames.BIDS_DETAILS_VALUE_AMOUNT, Direction.ASC));
    getTemplate().indexOps(Organization.class).ensureIndex(new TextIndexDefinitionBuilder().withDefaultLanguage(MongoConstants.MONGO_LANGUAGE).onField("name").onField("id").onField("additionalIdentifiers._id").build());
    getTemplate().indexOps(Release.class).ensureIndex(new TextIndexDefinitionBuilder().named("text_search").withDefaultLanguage(MongoConstants.MONGO_LANGUAGE).onFields("tender.title", "tender.description", "tender.procuringEntity.name", "tender.id", "tender.procuringEntity.description", "awards.id", "awards.description", "awards.suppliers.name", "awards.suppliers.description", "ocid", "buyer.name", "buyer.id").build());
    getLogger().info("Added extra Mongo indexes");
    ScriptOperations scriptOps = getTemplate().scriptOps();
    // add script to calculate the percentiles endpoint
    URL scriptFile = getClass().getResource("/tenderBidPeriodPercentilesMongo.js");
    try {
        String scriptText = IOUtils.toString(scriptFile);
        ExecutableMongoScript script = new ExecutableMongoScript(scriptText);
        scriptOps.register(new NamedMongoScript("tenderBidPeriodPercentiles", script));
    } catch (IOException e) {
        e.printStackTrace();
    }
    // add general mongo system helper methods
    URL systemScriptFile = getClass().getResource("/mongoSystemScripts.js");
    try {
        String systemScriptFileText = IOUtils.toString(systemScriptFile);
        ExecutableMongoScript script = new ExecutableMongoScript(systemScriptFileText);
        scriptOps.execute(script);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : TextIndexDefinitionBuilder(org.springframework.data.mongodb.core.index.TextIndexDefinition.TextIndexDefinitionBuilder) Organization(org.devgateway.ocds.persistence.mongo.Organization) ScriptOperations(org.springframework.data.mongodb.core.ScriptOperations) ExecutableMongoScript(org.springframework.data.mongodb.core.script.ExecutableMongoScript) Index(org.springframework.data.mongodb.core.index.Index) IOException(java.io.IOException) NamedMongoScript(org.springframework.data.mongodb.core.script.NamedMongoScript) Release(org.devgateway.ocds.persistence.mongo.Release) URL(java.net.URL)

Aggregations

NamedMongoScript (org.springframework.data.mongodb.core.script.NamedMongoScript)6 Test (org.junit.Test)3 ExecutableMongoScript (org.springframework.data.mongodb.core.script.ExecutableMongoScript)3 IOException (java.io.IOException)2 URL (java.net.URL)2 Organization (org.devgateway.ocds.persistence.mongo.Organization)2 Release (org.devgateway.ocds.persistence.mongo.Release)2 ScriptOperations (org.springframework.data.mongodb.core.ScriptOperations)2 Index (org.springframework.data.mongodb.core.index.Index)2 TextIndexDefinitionBuilder (org.springframework.data.mongodb.core.index.TextIndexDefinition.TextIndexDefinitionBuilder)2 HashSet (java.util.HashSet)1 VNLocation (org.devgateway.ocvn.persistence.mongo.dao.VNLocation)1 Query (org.springframework.data.mongodb.core.query.Query)1