Search in sources :

Example 41 with Release

use of org.devgateway.ocds.persistence.mongo.Release in project ocvn by devgateway.

the class ProcurementPlansRowImporter method createReleaseFromReleaseRow.

@Override
public Release createReleaseFromReleaseRow(final String[] row) throws ParseException {
    String projectID = getRowCell(row, 0);
    Release oldRelease = repository.findByBudgetProjectId(projectID);
    if (oldRelease != null) {
        throw new RuntimeException("Duplicate planning.budget.projectID");
    }
    Release release = new Release();
    release.setOcid(MongoConstants.OCDS_PREFIX + "prjid-" + projectID);
    release.getTag().add(Tag.planning);
    VNPlanning planning = new VNPlanning();
    VNBudget budget = new VNBudget();
    release.setPlanning(planning);
    planning.setBudget(budget);
    // search for locations
    if (getRowCell(row, 3) != null) {
        String[] locations = getRowCell(row, 3).split(",");
        for (int i = 0; i < locations.length; i++) {
            VNLocation location = locationRepository.findByDescription(locations[i].trim());
            if (location == null) {
                location = new VNLocation();
                location.setDescription(locations[i]);
                location = locationRepository.insert(location);
            }
            budget.getProjectLocation().add(location);
        }
    }
    planning.setBidPlanProjectDateIssue(getExcelDate(getRowCell(row, 4)));
    planning.setBidPlanProjectCompanyIssue(getRowCell(row, 6));
    planning.setBidPlanProjectFund(getInteger(getRowCell(row, 8)));
    budget.getProjectClassification().setDescription(getRowCell(row, 9));
    planning.setBidPlanProjectDateApprove(getExcelDate(getRowCell(row, 10)));
    budget.getProjectClassification().setId(getRowCell(row, 12));
    planning.setBidNo(getRowCell(row, 13));
    budget.setProjectID(getRowCell(row, 0));
    budget.setBidPlanProjectStyle(getRowCell(row, 5));
    budget.setBidPlanProjectType(getRowCell(row, 7));
    budget.setProject(getRowCell(row, 1));
    budget.setDescription(getRowCell(row, 11));
    Amount value = new Amount();
    budget.setProjectAmount(value);
    value.setCurrency("VND");
    value.setAmount(getDecimal(getRowCell(row, 2)));
    return release;
}
Also used : VNLocation(org.devgateway.ocvn.persistence.mongo.dao.VNLocation) VNBudget(org.devgateway.ocvn.persistence.mongo.dao.VNBudget) Amount(org.devgateway.ocds.persistence.mongo.Amount) VNPlanning(org.devgateway.ocvn.persistence.mongo.dao.VNPlanning) Release(org.devgateway.ocds.persistence.mongo.Release)

Example 42 with Release

use of org.devgateway.ocds.persistence.mongo.Release in project ocvn by devgateway.

the class ReleaseJsonImportTest method importObject.

@Test
public void importObject() throws Exception {
    final String jsonRelease = "{\n" + "    tag: [\"tender\"],\n" + "    planning: {\n" + "        budget: {\n" + "            description: \"budget desc...\",\n" + "            amount: {\n" + "                amount: 10000,\n" + "                currency: \"USD\"\n" + "            }\n" + "        }\n" + "    }\n" + "}";
    final JsonImport releaseJsonImport = new ReleaseJsonImport(releaseRepository, jsonRelease, false);
    final Release release = (Release) releaseJsonImport.importObject();
    final Release releaseById = releaseRepository.findById(release.getId());
    Assert.assertNotNull("Check if we have something in the database", releaseById);
    Assert.assertEquals("Check if the releases are the same", release, releaseById);
}
Also used : Release(org.devgateway.ocds.persistence.mongo.Release) AbstractMongoTest(org.devgateway.toolkit.persistence.mongo.AbstractMongoTest) Test(org.junit.Test)

Example 43 with Release

use of org.devgateway.ocds.persistence.mongo.Release in project ocvn 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, false);
    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("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) Release(org.devgateway.ocds.persistence.mongo.Release) Test(org.junit.Test) AbstractMongoTest(org.devgateway.toolkit.persistence.mongo.AbstractMongoTest)

Example 44 with Release

use of org.devgateway.ocds.persistence.mongo.Release in project ocvn 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, false);
    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)

Example 45 with Release

use of org.devgateway.ocds.persistence.mongo.Release in project ocvn by devgateway.

the class ReleasePackageJsonImportTest method importObjectsContract.

@Test
public void importObjectsContract() throws Exception {
    final ClassLoader classLoader = getClass().getClassLoader();
    final File file = new File(classLoader.getResource("json/fictional-example/ocds-213czf-000-00001-05-contract.json").getFile());
    final ReleasePackageJsonImport releasePackageJsonImport = new ReleasePackageJsonImport(releaseRepository, file, false);
    final Collection<Release> releases = releasePackageJsonImport.importObjects();
    final Release importedRelease = releaseRepository.findById("ocds-213czf-000-00001-05-contract");
    Assert.assertEquals(1, releases.size());
    Assert.assertNotNull(importedRelease);
    final Set<Contract> contracts = importedRelease.getContracts();
    Assert.assertEquals(Contract.Status.active, contracts.iterator().next().getStatus());
}
Also used : File(java.io.File) Contract(org.devgateway.ocds.persistence.mongo.Contract) 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