Search in sources :

Example 1 with ReleasePackage

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

the class ReleaseExportFileTest method createWorkbook.

@Test
public void createWorkbook() throws Exception {
    final ClassLoader classLoader = getClass().getClassLoader();
    final File file = new File(classLoader.getResource("json/release-excel-export.json").getFile());
    final JsonToObject releasePackageJsonToObject = new ReleasePackageJsonToObject(file, false);
    final ReleasePackage releasePackage = (ReleasePackage) releasePackageJsonToObject.toObject();
    final ExcelFile releaseExcelFile = new ReleaseExportFile(new ArrayList<>(releasePackage.getReleases()));
    final Workbook workbook = releaseExcelFile.createWorkbook();
    // try (FileOutputStream outputStream = new FileOutputStream("/Users/ionut/Downloads/ocds-export.xlsx")) {
    //     workbook.write(outputStream);
    // }
    Assert.assertEquals("Number of sheets", 6, workbook.getNumberOfSheets());
    Assert.assertNotNull("release sheet", workbook.getSheet("release"));
    Assert.assertNotNull("tender sheet", workbook.getSheet("vntender"));
    Assert.assertNotNull("award sheet", workbook.getSheet("vnaward"));
    Assert.assertNotNull("item sheet", workbook.getSheet("vnitem"));
    Assert.assertEquals("release id", "ocds-213czf-000-00001-01-planning", workbook.getSheet("release").getRow(3).getCell(0).toString());
    Assert.assertEquals("release id", "ocds-213czf-000-00001-06-implementation", workbook.getSheet("release").getRow(5).getCell(0).toString());
    Assert.assertEquals("tender parent", "release - ocds-213czf-000-00001", workbook.getSheet("vntender").getRow(1).getCell(0).toString());
    Assert.assertEquals("tender id", "ocds-213czf-000-00001-01-planning", workbook.getSheet("vntender").getRow(1).getCell(1).toString());
    Assert.assertEquals("award number of rows", 4, workbook.getSheet("vnaward").getLastRowNum());
    Assert.assertEquals("item number of rows", 7, workbook.getSheet("vnitem").getLastRowNum());
}
Also used : ReleasePackageJsonToObject(org.devgateway.ocds.persistence.mongo.spring.json2object.ReleasePackageJsonToObject) ReleasePackage(org.devgateway.ocds.persistence.mongo.ReleasePackage) ReleasePackageJsonToObject(org.devgateway.ocds.persistence.mongo.spring.json2object.ReleasePackageJsonToObject) JsonToObject(org.devgateway.ocds.persistence.mongo.spring.json2object.JsonToObject) File(java.io.File) Workbook(org.apache.poi.ss.usermodel.Workbook) Test(org.junit.Test)

Example 2 with ReleasePackage

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

the class OcdsController method ocdsPackages.

@ApiOperation(value = "Returns all available packages, filtered by the given criteria." + "This will contain the OCDS package information (metadata about publisher) plus the release itself.")
@RequestMapping(value = "/api/ocds/package/all", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
@JsonView(Views.Public.class)
public List<ReleasePackage> ocdsPackages(@ModelAttribute @Valid final YearFilterPagingRequest releaseRequest) {
    List<Release> ocdsReleases = ocdsReleases(releaseRequest);
    List<ReleasePackage> releasePackages = new ArrayList<>(ocdsReleases.size());
    for (Release release : ocdsReleases) {
        releasePackages.add(createReleasePackage(release));
    }
    return releasePackages;
}
Also used : ReleasePackage(org.devgateway.ocds.persistence.mongo.ReleasePackage) ArrayList(java.util.ArrayList) Release(org.devgateway.ocds.persistence.mongo.Release) ApiOperation(io.swagger.annotations.ApiOperation) JsonView(com.fasterxml.jackson.annotation.JsonView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with ReleasePackage

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

the class OcdsController method createReleasePackage.

public ReleasePackage createReleasePackage(final Release release) {
    ReleasePackage releasePackage = new ReleasePackage();
    releasePackage.setLicense("https://creativecommons.org/licenses/by/2.0/");
    releasePackage.setPublicationPolicy("https://github.com/open-contracting/sample-data/");
    releasePackage.setPublishedDate(release.getDate());
    releasePackage.getReleases().add(release);
    releasePackage.setUri(SERVER_DOMAIN + "/api/ocds/package/ocid/" + release.getOcid());
    Publisher publisher = new Publisher();
    publisher.setName("Government of Vietnam: Public Procurement Agency");
    publisher.setScheme("VN-PPA");
    publisher.setUid(release.getOcid());
    publisher.setUri(SERVER_DOMAIN);
    releasePackage.setPublisher(publisher);
    return releasePackage;
}
Also used : ReleasePackage(org.devgateway.ocds.persistence.mongo.ReleasePackage) Publisher(org.devgateway.ocds.persistence.mongo.Publisher)

Example 4 with ReleasePackage

use of org.devgateway.ocds.persistence.mongo.ReleasePackage in project ocvn 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 5 with ReleasePackage

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

the class OcdsControllerTest method createReleasePackage.

@Test
public void createReleasePackage() throws Exception {
    final ReleasePackage releasePackage = ocdsController.createReleasePackage(ocdsController.ocdsByOcid("ocds-endpoint-001"));
    Assert.assertNotNull(releasePackage);
    final Optional<Release> release = releasePackage.getReleases().stream().findFirst();
    Assert.assertEquals(true, release.isPresent());
    Assert.assertEquals("ocds-endpoint-001", release.get().getOcid());
}
Also used : ReleasePackage(org.devgateway.ocds.persistence.mongo.ReleasePackage) Release(org.devgateway.ocds.persistence.mongo.Release) Test(org.junit.Test)

Aggregations

ReleasePackage (org.devgateway.ocds.persistence.mongo.ReleasePackage)9 Release (org.devgateway.ocds.persistence.mongo.Release)6 Test (org.junit.Test)6 JsonView (com.fasterxml.jackson.annotation.JsonView)1 ApiOperation (io.swagger.annotations.ApiOperation)1 File (java.io.File)1 BigDecimal (java.math.BigDecimal)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1 Workbook (org.apache.poi.ss.usermodel.Workbook)1 Publisher (org.devgateway.ocds.persistence.mongo.Publisher)1 JsonToObject (org.devgateway.ocds.persistence.mongo.spring.json2object.JsonToObject)1 ReleasePackageJsonToObject (org.devgateway.ocds.persistence.mongo.spring.json2object.ReleasePackageJsonToObject)1 YearFilterPagingRequest (org.devgateway.ocds.web.rest.controller.request.YearFilterPagingRequest)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1