Search in sources :

Example 1 with Pager

use of eu.etaxonomy.cdm.api.service.pager.Pager in project cdmlib by cybertaxonomy.

the class ListIdentifiersView method constructResponse.

protected void constructResponse(OAIPMH oaiPmh, Map<String, Object> model) {
    oaiPmh.getRequest().setVerb(Verb.LIST_IDENTIFIERS);
    oaiPmh.getRequest().setValue((String) model.get("request"));
    oaiPmh.getRequest().setMetadataPrefix((MetadataPrefix) model.get("metadataPrefix"));
    if (model.containsKey("from")) {
        oaiPmh.getRequest().setFrom((DateTime) model.get("from"));
    }
    if (model.containsKey("until")) {
        oaiPmh.getRequest().setUntil((DateTime) model.get("until"));
    }
    if (model.containsKey("set")) {
        oaiPmh.getRequest().setSet((SetSpec) model.get("set"));
    }
    ListIdentifiers listIdentifiers = new ListIdentifiers();
    for (AuditEventRecord auditEventRecord : ((Pager<AuditEventRecord>) model.get("pager")).getRecords()) {
        Header header = (Header) mapper.map(auditEventRecord.getAuditableObject(), Header.class);
        if (auditEventRecord.getRevisionType().equals(RevisionType.DEL)) {
            header.setStatus(Status.DELETED);
        }
        listIdentifiers.getHeader().add(header);
    }
    if (model.containsKey("resumptionToken")) {
        listIdentifiers.setResumptionToken((ResumptionToken) model.get("resumptionToken"));
    }
    oaiPmh.setListIdentifiers(listIdentifiers);
}
Also used : ListIdentifiers(eu.etaxonomy.cdm.remote.dto.oaipmh.ListIdentifiers) Header(eu.etaxonomy.cdm.remote.dto.oaipmh.Header) Pager(eu.etaxonomy.cdm.api.service.pager.Pager) AuditEventRecord(eu.etaxonomy.cdm.model.view.AuditEventRecord)

Example 2 with Pager

use of eu.etaxonomy.cdm.api.service.pager.Pager in project cdmlib by cybertaxonomy.

the class ListRecordsView method constructResponse.

protected void constructResponse(OAIPMH oaiPmh, Map<String, Object> model) {
    oaiPmh.getRequest().setVerb(Verb.LIST_RECORDS);
    oaiPmh.getRequest().setValue((String) model.get("request"));
    oaiPmh.getRequest().setMetadataPrefix((MetadataPrefix) model.get("metadataPrefix"));
    if (model.containsKey("from")) {
        oaiPmh.getRequest().setFrom((DateTime) model.get("from"));
    }
    if (model.containsKey("until")) {
        oaiPmh.getRequest().setUntil((DateTime) model.get("until"));
    }
    if (model.containsKey("set")) {
        oaiPmh.getRequest().setSet((SetSpec) model.get("set"));
    }
    ListRecords listRecords = new ListRecords();
    if (model.containsKey("pager")) {
        for (AuditEventRecord auditEventRecord : ((Pager<AuditEventRecord>) model.get("pager")).getRecords()) {
            Record record = new Record();
            Header header = (Header) mapper.map(auditEventRecord.getAuditableObject(), Header.class);
            record.setHeader(header);
            if (!auditEventRecord.getRevisionType().equals(RevisionType.DEL)) {
                Metadata metadata = new Metadata();
                constructMetadata(metadata, (IdentifiableEntity) auditEventRecord.getAuditableObject());
                record.setMetadata(metadata);
            } else {
                header.setStatus(Status.DELETED);
            }
            listRecords.getRecord().add(record);
        }
        if (model.containsKey("resumptionToken")) {
            listRecords.setResumptionToken((ResumptionToken) model.get("resumptionToken"));
        }
    } else if (model.containsKey("entitylist")) {
        for (IdentifiableEntity idetifiableEntity : ((List<IdentifiableEntity>) model.get("entitylist"))) {
            Record record = new Record();
            Metadata metadata = new Metadata();
            constructMetadata(metadata, idetifiableEntity);
            record.setMetadata(metadata);
            listRecords.getRecord().add(record);
        }
    }
    oaiPmh.setListRecords(listRecords);
}
Also used : IdentifiableEntity(eu.etaxonomy.cdm.model.common.IdentifiableEntity) Header(eu.etaxonomy.cdm.remote.dto.oaipmh.Header) Pager(eu.etaxonomy.cdm.api.service.pager.Pager) Metadata(eu.etaxonomy.cdm.remote.dto.oaipmh.Metadata) Record(eu.etaxonomy.cdm.remote.dto.oaipmh.Record) AuditEventRecord(eu.etaxonomy.cdm.model.view.AuditEventRecord) List(java.util.List) AuditEventRecord(eu.etaxonomy.cdm.model.view.AuditEventRecord) ListRecords(eu.etaxonomy.cdm.remote.dto.oaipmh.ListRecords)

Example 3 with Pager

use of eu.etaxonomy.cdm.api.service.pager.Pager in project cdmlib by cybertaxonomy.

the class TestAggregations method testNewConfigControler.

private void testNewConfigControler() {
    logger.debug("start");
    DbSchemaValidation schema = DbSchemaValidation.VALIDATE;
    String server;
    String database;
    String username;
    ICdmDataSource dataSource;
    // List<CdmPersistentDataSource> lsDataSources = CdmPersistentDataSource.getAllDataSources();
    // System.out.println(lsDataSources);
    // dataSource = lsDataSources.get(1);
    // DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
    server = "160.45.63.171";
    database = "cdm_production_euromed";
    username = "edit";
    dataSource = CdmDataSource.NewMySqlInstance(server, database, username, AccountStore.readOrStorePassword(server, database, username, null));
    // server = "test.e-taxonomy.eu";
    // database = "cdm_test_euromed";
    // username = "edit";
    // dataSource = CdmDataSource.NewMySqlInstance(server, database, username, AccountStore.readOrStorePassword(server, database, username, null));
    // String server = "localhost";
    // String database = "testCDM";
    // String username = "postgres";
    // dataSource = CdmDataSource.NewInstance(DatabaseTypeEnum.PostgreSQL, server, database, DatabaseTypeEnum.PostgreSQL.getDefaultPort(), username, AccountStore.readOrStorePassword(server, database, username, null));
    // //SQLServer
    // server = "BGBM-PESISQL";
    // database = "cdm36";
    // int port = 1433;
    // username = "cdmupdater";
    // dataSource = CdmDataSource.NewSqlServer2012Instance(server, database, port, username, AccountStore.readOrStorePassword(server, database, username, null));
    // 
    // //H2
    // String path = "C:\\Users\\a.mueller\\.cdmLibrary\\writableResources\\h2\\LocalH2";
    // //      String path = "C:\\Users\\a.mueller\\eclipse\\svn\\cdmlib-trunk\\cdmlib-remote-webapp\\src\\test\\resources\\h2";
    // username = "sa";
    // dataSource = CdmDataSource.NewH2EmbeddedInstance("cdm", username, "", path);
    // dataSource = CdmDataSource.NewH2EmbeddedInstance(database, username, "sa");
    // server = "160.45.63.201";
    // database = "cdm_integration_cichorieae";
    // username = "edit";
    // dataSource = CdmDataSource.NewMySqlInstance(server, database, username, AccountStore.readOrStorePassword(server, database, username, null));
    // CdmPersistentDataSource.save(dataSource.getName(), dataSource);
    CdmApplicationController appCtr;
    appCtr = CdmApplicationController.NewInstance(dataSource, schema);
    // TransactionStatus tx = appCtr.startTransaction(true);
    UUID targetAreaLevelUuid = UUID.fromString("25b563b6-6a6c-401b-b090-c9498886c50b");
    NamedAreaLevel targetAreaLevel = (NamedAreaLevel) appCtr.getTermService().load(targetAreaLevelUuid);
    Pager<NamedArea> areaPager = appCtr.getTermService().list(targetAreaLevel, (NamedAreaType) null, null, null, (List<OrderHint>) null, null);
    IProgressMonitor monitor = DefaultProgressMonitor.NewInstance();
    // Cichorieae
    UUID uuidCichorieae = UUID.fromString("2343071c-d5f4-4434-89b4-cdf7b2ff7f39");
    UUID uuidCichoriinae = UUID.fromString("2b05bf1a-950e-43ad-8367-41fe8d3e6c92");
    UUID uuidCichorium = UUID.fromString("6a7ac1ad-2fd9-4218-8132-12dd463d04b9");
    UUID uuidArnoseris = UUID.fromString("0f71555c-676b-4d66-8a0c-281787ac72f6");
    UUID uuidAlternativeClassificationRoot = UUID.fromString("9672a9e0-87bd-416a-9268-983c60debce5");
    // Asteraceae
    UUID uuidAsteracea = UUID.fromString("29e37083-5ae2-4e31-94f6-0007f78c3397");
    // E+M
    UUID uuidPlantae = UUID.fromString("d049b868-941a-4f07-8110-d506abcc2bb5");
    TaxonNodeFilter filter = TaxonNodeFilter.NewSubtreeInstance(uuidPlantae);
    filter.setRankMax(Rank.uuidGenus);
    List<AggregationMode> modes = AggregationMode.byToParent();
    List<UUID> areaList = areaPager.getRecords().stream().map(p -> p.getUuid()).collect(Collectors.toList());
    DistributionAggregationConfiguration config = DistributionAggregationConfiguration.NewInstance(modes, areaList, filter, monitor);
    config.setToParentSourceMode(AggregationSourceMode.NONE);
    config.setWithinTaxonSourceMode(AggregationSourceMode.NONE);
    try {
        config.getTaskInstance().invoke(config, appCtr);
    } catch (Exception e) {
        e.printStackTrace();
    }
    appCtr.close();
}
Also used : OrderHint(eu.etaxonomy.cdm.persistence.query.OrderHint) TaxonNodeFilter(eu.etaxonomy.cdm.filter.TaxonNodeFilter) Pager(eu.etaxonomy.cdm.api.service.pager.Pager) AccountStore(eu.etaxonomy.cdm.config.AccountStore) Rank(eu.etaxonomy.cdm.model.name.Rank) IProgressMonitor(eu.etaxonomy.cdm.common.monitor.IProgressMonitor) NamedAreaLevel(eu.etaxonomy.cdm.model.location.NamedAreaLevel) ICdmDataSource(eu.etaxonomy.cdm.database.ICdmDataSource) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) NamedArea(eu.etaxonomy.cdm.model.location.NamedArea) Logger(org.apache.log4j.Logger) AggregationSourceMode(eu.etaxonomy.cdm.api.service.description.AggregationSourceMode) List(java.util.List) CdmDataSource(eu.etaxonomy.cdm.database.CdmDataSource) DefaultProgressMonitor(eu.etaxonomy.cdm.common.monitor.DefaultProgressMonitor) DbSchemaValidation(eu.etaxonomy.cdm.database.DbSchemaValidation) AggregationMode(eu.etaxonomy.cdm.api.service.description.AggregationMode) CdmApplicationController(eu.etaxonomy.cdm.api.application.CdmApplicationController) OrderHint(eu.etaxonomy.cdm.persistence.query.OrderHint) DistributionAggregationConfiguration(eu.etaxonomy.cdm.api.service.description.DistributionAggregationConfiguration) NamedAreaType(eu.etaxonomy.cdm.model.location.NamedAreaType) TaxonNodeFilter(eu.etaxonomy.cdm.filter.TaxonNodeFilter) DbSchemaValidation(eu.etaxonomy.cdm.database.DbSchemaValidation) CdmApplicationController(eu.etaxonomy.cdm.api.application.CdmApplicationController) AggregationMode(eu.etaxonomy.cdm.api.service.description.AggregationMode) NamedArea(eu.etaxonomy.cdm.model.location.NamedArea) ICdmDataSource(eu.etaxonomy.cdm.database.ICdmDataSource) IProgressMonitor(eu.etaxonomy.cdm.common.monitor.IProgressMonitor) DistributionAggregationConfiguration(eu.etaxonomy.cdm.api.service.description.DistributionAggregationConfiguration) NamedAreaLevel(eu.etaxonomy.cdm.model.location.NamedAreaLevel) UUID(java.util.UUID)

Aggregations

Pager (eu.etaxonomy.cdm.api.service.pager.Pager)3 AuditEventRecord (eu.etaxonomy.cdm.model.view.AuditEventRecord)2 Header (eu.etaxonomy.cdm.remote.dto.oaipmh.Header)2 List (java.util.List)2 CdmApplicationController (eu.etaxonomy.cdm.api.application.CdmApplicationController)1 AggregationMode (eu.etaxonomy.cdm.api.service.description.AggregationMode)1 AggregationSourceMode (eu.etaxonomy.cdm.api.service.description.AggregationSourceMode)1 DistributionAggregationConfiguration (eu.etaxonomy.cdm.api.service.description.DistributionAggregationConfiguration)1 DefaultProgressMonitor (eu.etaxonomy.cdm.common.monitor.DefaultProgressMonitor)1 IProgressMonitor (eu.etaxonomy.cdm.common.monitor.IProgressMonitor)1 AccountStore (eu.etaxonomy.cdm.config.AccountStore)1 CdmDataSource (eu.etaxonomy.cdm.database.CdmDataSource)1 DbSchemaValidation (eu.etaxonomy.cdm.database.DbSchemaValidation)1 ICdmDataSource (eu.etaxonomy.cdm.database.ICdmDataSource)1 TaxonNodeFilter (eu.etaxonomy.cdm.filter.TaxonNodeFilter)1 IdentifiableEntity (eu.etaxonomy.cdm.model.common.IdentifiableEntity)1 NamedArea (eu.etaxonomy.cdm.model.location.NamedArea)1 NamedAreaLevel (eu.etaxonomy.cdm.model.location.NamedAreaLevel)1 NamedAreaType (eu.etaxonomy.cdm.model.location.NamedAreaType)1 Rank (eu.etaxonomy.cdm.model.name.Rank)1