Search in sources :

Example 61 with Release

use of org.devgateway.ocds.persistence.mongo.Release in project oc-explorer by devgateway.

the class ReleaseCompilerService method createCompiledRelease.

protected Release createCompiledRelease(final Record record) {
    // empty records produce null compiled release
    if (record.getReleases().isEmpty()) {
        return null;
    }
    // records with just one release produce a compiled release identical to
    // the one release
    Release left = record.getReleases().get(0);
    if (record.getReleases().size() > 1) {
        // we merge each element of the list to its left partner
        List<Release> subList = record.getReleases().subList(1, record.getReleases().size());
        for (Release right : subList) {
            Release compiled = mergeOcdsBeans(left, right);
            left = compiled;
        }
    }
    // this was purposefully nullified by ocdsOmit
    left.setTag(new ArrayList<Tag>());
    left.getTag().add(Tag.compiled);
    return left;
}
Also used : Tag(org.devgateway.ocds.persistence.mongo.Tag) Release(org.devgateway.ocds.persistence.mongo.Release)

Example 62 with Release

use of org.devgateway.ocds.persistence.mongo.Release in project oc-explorer by devgateway.

the class ReleasePackageJsonImport method importObjects.

@Override
public Collection<Release> importObjects() throws IOException {
    final ReleasePackage releasePackage = (ReleasePackage) releasePackageJsonToObject.toObject();
    final Collection<Release> savedReleases = new LinkedHashSet<>();
    if (!releasePackage.getReleases().isEmpty()) {
        Set<Release> releases = releasePackage.getReleases();
        for (Release release : releases) {
            Release savedRelease = releaseRepository.save(release);
            savedReleases.add(savedRelease);
        }
    }
    return savedReleases;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ReleasePackage(org.devgateway.ocds.persistence.mongo.ReleasePackage) Release(org.devgateway.ocds.persistence.mongo.Release)

Example 63 with Release

use of org.devgateway.ocds.persistence.mongo.Release in project oc-explorer by devgateway.

the class ReleasePackageJsonImportTest method importObjectsTender.

@Test
public void importObjectsTender() throws Exception {
    final ClassLoader classLoader = getClass().getClassLoader();
    final File file = new File(classLoader.getResource("json/fictional-example/ocds-213czf-000-00001-02-tender.json").getFile());
    final ReleasePackageJsonImport releasePackageJsonImport = new ReleasePackageJsonImport(releaseRepository, file);
    final Collection<Release> releases = releasePackageJsonImport.importObjects();
    final Release importedRelease = releaseRepository.findById("ocds-213czf-000-00001-02-tender");
    Assert.assertEquals(1, releases.size());
    Assert.assertNotNull(importedRelease);
    Assert.assertEquals(Tender.ProcurementMethod.open, importedRelease.getTender().getProcurementMethod());
}
Also used : File(java.io.File) Release(org.devgateway.ocds.persistence.mongo.Release) Test(org.junit.Test) AbstractMongoTest(org.devgateway.toolkit.persistence.mongo.AbstractMongoTest)

Example 64 with Release

use of org.devgateway.ocds.persistence.mongo.Release in project oc-explorer by devgateway.

the class ReleasePackageJsonImportTest method importObjectsImplementation.

@Test
public void importObjectsImplementation() throws Exception {
    final ClassLoader classLoader = getClass().getClassLoader();
    final File file = new File(classLoader.getResource("json/fictional-example/ocds-213czf-000-00001-06-implementation.json").getFile());
    final ReleasePackageJsonImport releasePackageJsonImport = new ReleasePackageJsonImport(releaseRepository, file);
    final Collection<Release> releases = releasePackageJsonImport.importObjects();
    final Release importedRelease = releaseRepository.findById("ocds-213czf-000-00001-06-implementation");
    Assert.assertEquals(1, releases.size());
    Assert.assertNotNull(importedRelease);
    Assert.assertArrayEquals(new Tag[] { Tag.implementation }, importedRelease.getTag().toArray());
    final Set<Contract> contracts = importedRelease.getContracts();
    final Set<Transaction> transactions = contracts.iterator().next().getImplementation().getTransactions();
    Assert.assertEquals(new URI("https://openspending.org/uk-barnet-spending/"), transactions.iterator().next().getSource());
}
Also used : Transaction(org.devgateway.ocds.persistence.mongo.Transaction) File(java.io.File) Contract(org.devgateway.ocds.persistence.mongo.Contract) URI(java.net.URI) Release(org.devgateway.ocds.persistence.mongo.Release) Test(org.junit.Test) AbstractMongoTest(org.devgateway.toolkit.persistence.mongo.AbstractMongoTest)

Example 65 with Release

use of org.devgateway.ocds.persistence.mongo.Release in project oc-explorer by devgateway.

the class ReleasePackageJsonImportTest method importObjectsAward.

@Test
public void importObjectsAward() throws Exception {
    final ClassLoader classLoader = getClass().getClassLoader();
    final File file = new File(classLoader.getResource("json/fictional-example/ocds-213czf-000-00001-04-award.json").getFile());
    final ReleasePackageJsonImport releasePackageJsonImport = new ReleasePackageJsonImport(releaseRepository, file);
    final Collection<Release> releases = releasePackageJsonImport.importObjects();
    final Release importedRelease = releaseRepository.findById("ocds-213czf-000-00001-04-award");
    Assert.assertEquals(1, releases.size());
    Assert.assertNotNull(importedRelease);
    final Set<Award> awards = importedRelease.getAwards();
    Assert.assertEquals(Award.Status.pending, awards.iterator().next().getStatus());
}
Also used : Award(org.devgateway.ocds.persistence.mongo.Award) File(java.io.File) Release(org.devgateway.ocds.persistence.mongo.Release) Test(org.junit.Test) AbstractMongoTest(org.devgateway.toolkit.persistence.mongo.AbstractMongoTest)

Aggregations

Release (org.devgateway.ocds.persistence.mongo.Release)68 Test (org.junit.Test)44 File (java.io.File)22 AbstractMongoTest (org.devgateway.toolkit.persistence.mongo.AbstractMongoTest)20 ReleasePackage (org.devgateway.ocds.persistence.mongo.ReleasePackage)12 Amount (org.devgateway.ocds.persistence.mongo.Amount)9 JsonNode (com.fasterxml.jackson.databind.JsonNode)6 ProcessingMessage (com.github.fge.jsonschema.core.report.ProcessingMessage)6 BigDecimal (java.math.BigDecimal)6 Award (org.devgateway.ocds.persistence.mongo.Award)6 OcdsSchemaValidatorService (org.devgateway.ocds.persistence.mongo.spring.OcdsSchemaValidatorService)6 JsonImport (org.devgateway.ocds.persistence.mongo.spring.json.JsonImport)6 ReleaseJsonImport (org.devgateway.ocds.persistence.mongo.spring.json.ReleaseJsonImport)6 AbstractWebTest (org.devgateway.toolkit.web.AbstractWebTest)6 MvcResult (org.springframework.test.web.servlet.MvcResult)6 Budget (org.devgateway.ocds.persistence.mongo.Budget)5 Contract (org.devgateway.ocds.persistence.mongo.Contract)4 Planning (org.devgateway.ocds.persistence.mongo.Planning)4 VNPlanning (org.devgateway.ocvn.persistence.mongo.dao.VNPlanning)4 VNTender (org.devgateway.ocvn.persistence.mongo.dao.VNTender)4