Search in sources :

Example 1 with RecordType

use of org.osate.aadl2.RecordType in project ddf by codice.

the class TestCswSourceBase method generateCswCollection.

protected CswRecordCollection generateCswCollection(String file) {
    InputStream stream = getClass().getResourceAsStream(file);
    GetRecordsResponseType recordsResponse = parseXml(stream);
    GetRecordsResponseType records = new GetRecordsResponseType();
    recordsResponse.copyTo(records);
    List<Metacard> cswRecords = new LinkedList<>();
    for (JAXBElement<? extends AbstractRecordType> rec : records.getSearchResults().getAbstractRecord()) {
        MetacardImpl metacard = new MetacardImpl();
        cswRecords.add(metacard);
        if (rec.getValue() instanceof BriefRecordType) {
            BriefRecordType record = (BriefRecordType) rec.getValue();
            metacard.setId(record.getIdentifier().get(0).getValue().getContent().get(0));
            if (!CollectionUtils.isEmpty(record.getType().getContent())) {
                metacard.setContentTypeName(record.getType().getContent().get(0));
            }
        } else if (rec.getValue() instanceof SummaryRecordType) {
            SummaryRecordType record = (SummaryRecordType) rec.getValue();
            metacard.setId(record.getIdentifier().get(0).getValue().getContent().get(0));
            if (!CollectionUtils.isEmpty(record.getType().getContent())) {
                metacard.setContentTypeName(record.getType().getContent().get(0));
            }
        } else if (rec.getValue() instanceof RecordType) {
            RecordType record = (RecordType) rec.getValue();
            for (JAXBElement<SimpleLiteral> jb : record.getDCElement()) {
                if ("identifier".equals(jb.getName().getLocalPart())) {
                    metacard.setId(jb.getValue().getContent().get(0));
                }
                if ("type".equals(jb.getName().getLocalPart()) && !CollectionUtils.isEmpty(jb.getValue().getContent())) {
                    metacard.setContentTypeName(jb.getValue().getContent().get(0));
                }
            }
        }
    }
    CswRecordCollection collection = new CswRecordCollection();
    collection.setCswRecords(cswRecords);
    collection.setNumberOfRecordsMatched(records.getSearchResults().getNumberOfRecordsMatched().intValue());
    collection.setNumberOfRecordsReturned(records.getSearchResults().getNumberOfRecordsReturned().intValue());
    return collection;
}
Also used : SummaryRecordType(net.opengis.cat.csw.v_2_0_2.SummaryRecordType) InputStream(java.io.InputStream) BriefRecordType(net.opengis.cat.csw.v_2_0_2.BriefRecordType) LinkedList(java.util.LinkedList) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Metacard(ddf.catalog.data.Metacard) AbstractRecordType(net.opengis.cat.csw.v_2_0_2.AbstractRecordType) RecordType(net.opengis.cat.csw.v_2_0_2.RecordType) SummaryRecordType(net.opengis.cat.csw.v_2_0_2.SummaryRecordType) BriefRecordType(net.opengis.cat.csw.v_2_0_2.BriefRecordType) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) GetRecordsResponseType(net.opengis.cat.csw.v_2_0_2.GetRecordsResponseType) SimpleLiteral(net.opengis.cat.csw.v_2_0_2.dc.elements.SimpleLiteral)

Example 2 with RecordType

use of org.osate.aadl2.RecordType in project mod-oai-pmh by folio-org.

the class AbstractGetRecordsHelper method buildRecords.

/**
 * Builds {@link Map} with storage id as key and {@link RecordType} with populated header if there is any,
 * otherwise empty map is returned
 */
private Map<String, RecordType> buildRecords(Context context, Request request, JsonArray instances) {
    final boolean suppressedRecordsProcessingEnabled = getBooleanProperty(request.getRequestId(), REPOSITORY_SUPPRESSED_RECORDS_PROCESSING);
    if (instances != null && !instances.isEmpty()) {
        Map<String, RecordType> records = new HashMap<>();
        RecordMetadataManager metadataManager = RecordMetadataManager.getInstance();
        // Using LinkedHashMap just to rely on order returned by storage service
        String identifierPrefix = request.getIdentifierPrefix();
        instances.stream().map(JsonObject.class::cast).filter(instance -> isNotEmpty(storageHelper.getIdentifierId(instance))).forEach(instance -> {
            String recordId = storageHelper.getRecordId(instance);
            String identifierId = storageHelper.getIdentifierId(instance);
            RecordType record = createRecord(request, identifierPrefix, instance, identifierId);
            // Some repositories like SRS can return record source data along with other info
            String source = storageHelper.getInstanceRecordSource(instance);
            if (source != null && record.getHeader().getStatus() == null) {
                if (suppressedRecordsProcessingEnabled) {
                    source = metadataManager.updateMetadataSourceWithDiscoverySuppressedData(source, instance);
                }
                try {
                    record.withMetadata(buildOaiMetadata(request, source));
                } catch (Exception e) {
                    logger.error("Error occurred while converting record to xml representation. {}.", e.getMessage(), e);
                    logger.debug("Skipping problematic record due the conversion error. Source record id - {}.", recordId);
                    return;
                }
            } else {
                context.put(recordId, instance);
            }
            if (filterInstance(request, instance)) {
                records.put(recordId, record);
            }
        });
        return records;
    }
    return Collections.emptyMap();
}
Also used : HttpResponse(io.vertx.ext.web.client.HttpResponse) SourceStorageSourceRecordsClientWrapper(org.folio.oaipmh.service.SourceStorageSourceRecordsClientWrapper) DecodeException(io.vertx.core.json.DecodeException) Date(java.util.Date) StatusType(org.openarchives.oai._2.StatusType) SEND_REQUEST(org.folio.oaipmh.service.MetricsCollectingService.MetricOperation.SEND_REQUEST) HashMap(java.util.HashMap) REPOSITORY_MAX_RECORDS_PER_RESPONSE(org.folio.oaipmh.Constants.REPOSITORY_MAX_RECORDS_PER_RESPONSE) GENERIC_ERROR_MESSAGE(org.folio.oaipmh.Constants.GENERIC_ERROR_MESSAGE) Context(io.vertx.core.Context) StringUtils.isNotEmpty(org.apache.commons.lang3.StringUtils.isNotEmpty) OAIPMHerrorType(org.openarchives.oai._2.OAIPMHerrorType) ResumptionTokenType(org.openarchives.oai._2.ResumptionTokenType) RepositoryConfigurationUtil.getBooleanProperty(org.folio.oaipmh.helpers.RepositoryConfigurationUtil.getBooleanProperty) Request(org.folio.oaipmh.Request) OAIPMH(org.openarchives.oai._2.OAIPMH) Map(java.util.Map) BAD_RESUMPTION_TOKEN(org.openarchives.oai._2.OAIPMHerrorcodeType.BAD_RESUMPTION_TOKEN) JsonObject(io.vertx.core.json.JsonObject) AsyncResult(io.vertx.core.AsyncResult) RESUMPTION_TOKEN_FLOW_ERROR(org.folio.oaipmh.Constants.RESUMPTION_TOKEN_FLOW_ERROR) Promise(io.vertx.core.Promise) Collection(java.util.Collection) RecordMetadataManager(org.folio.oaipmh.helpers.records.RecordMetadataManager) MetricsCollectingService(org.folio.oaipmh.service.MetricsCollectingService) Future(io.vertx.core.Future) JsonArray(io.vertx.core.json.JsonArray) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Buffer(io.vertx.core.buffer.Buffer) Response(javax.ws.rs.core.Response) WebClientProvider(org.folio.oaipmh.WebClientProvider) RecordType(org.openarchives.oai._2.RecordType) RepositoryConfigurationUtil.isDeletedRecordsEnabled(org.folio.oaipmh.helpers.RepositoryConfigurationUtil.isDeletedRecordsEnabled) REPOSITORY_SUPPRESSED_RECORDS_PROCESSING(org.folio.oaipmh.Constants.REPOSITORY_SUPPRESSED_RECORDS_PROCESSING) ListRecordsType(org.openarchives.oai._2.ListRecordsType) Handler(io.vertx.core.Handler) Response.isSuccess(org.folio.rest.tools.client.Response.isSuccess) LogManager(org.apache.logging.log4j.LogManager) Collections(java.util.Collections) RecordType(org.openarchives.oai._2.RecordType) HashMap(java.util.HashMap) RecordMetadataManager(org.folio.oaipmh.helpers.records.RecordMetadataManager) JsonObject(io.vertx.core.json.JsonObject) DecodeException(io.vertx.core.json.DecodeException)

Example 3 with RecordType

use of org.osate.aadl2.RecordType in project mod-oai-pmh by folio-org.

the class AbstractGetRecordsHelper method processRecords.

protected Response processRecords(Context ctx, Request request, JsonObject instancesResponseBody) {
    JsonArray instances = storageHelper.getItems(instancesResponseBody);
    Integer totalRecords = storageHelper.getTotalRecords(instancesResponseBody);
    logger.debug("{} entries retrieved out of {}.", instances != null ? instances.size() : 0, totalRecords);
    if (request.isRestored() && !canResumeRequestSequence(request, totalRecords, instances)) {
        OAIPMH oaipmh = getResponseHelper().buildBaseOaipmhResponse(request).withErrors(new OAIPMHerrorType().withCode(BAD_RESUMPTION_TOKEN).withValue(RESUMPTION_TOKEN_FLOW_ERROR));
        return getResponseHelper().buildFailureResponse(oaipmh, request);
    }
    ResumptionTokenType resumptionToken = buildResumptionToken(request, instances, totalRecords);
    /*
     * According to OAI-PMH guidelines: it is recommended that the responseDate reflect the time of the repository's clock at the start
     * of any database query or search function necessary to answer the list request, rather than when the output is written.
     */
    final OAIPMH oaipmh = getResponseHelper().buildBaseOaipmhResponse(request);
    final Map<String, RecordType> recordsMap = buildRecords(ctx, request, instances);
    if (recordsMap.isEmpty()) {
        return buildNoRecordsFoundOaiResponse(oaipmh, request);
    } else {
        addRecordsToOaiResponse(oaipmh, recordsMap.values());
        addResumptionTokenToOaiResponse(oaipmh, resumptionToken);
        return buildResponse(oaipmh, request);
    }
}
Also used : JsonArray(io.vertx.core.json.JsonArray) OAIPMH(org.openarchives.oai._2.OAIPMH) OAIPMHerrorType(org.openarchives.oai._2.OAIPMHerrorType) ResumptionTokenType(org.openarchives.oai._2.ResumptionTokenType) RecordType(org.openarchives.oai._2.RecordType)

Example 4 with RecordType

use of org.osate.aadl2.RecordType in project VERDICT by ge-high-assurance.

the class Agree2Vdm method resolveAADLDataImplementationType.

private void resolveAADLDataImplementationType(DataImplementation dataImplementationImpl, HashSet<String> dataTypeDecl, Model model) {
    verdict.vdm.vdm_data.DataType dtype = new verdict.vdm.vdm_data.DataType();
    // GET DETAILS OF THE DATA IMPLEMENTATION AND CREATE CORRESPONDING VDM DATATYPE
    EList<DataSubcomponent> subcomponents = dataImplementationImpl.getOwnedDataSubcomponents();
    if (!subcomponents.isEmpty()) {
        // if the dataType definition has subcomponents
        RecordType recType = new RecordType();
        for (DataSubcomponent dataSubComp : subcomponents) {
            RecordField recField = new RecordField();
            recField.setName(dataSubComp.getName());
            DataSubcomponentType dataSubCompType = dataSubComp.getDataSubcomponentType();
            if (dataSubCompType instanceof org.osate.aadl2.DataType) {
                org.osate.aadl2.DataType aadlDataType = (org.osate.aadl2.DataType) dataSubCompType;
                // the line below is just to ensure that the type's declaration is added to VDM
                resolveAADLDataType(aadlDataType, dataTypeDecl, model);
                verdict.vdm.vdm_data.DataType recFieldDtype = getVdmTypeFromAADLType(aadlDataType);
                recField.setType(recFieldDtype);
                recType.getRecordField().add(recField);
            } else if (dataSubCompType instanceof DataImplementation) {
                DataImplementation dataSubCompDataImplementation = (DataImplementation) dataSubCompType;
                // the line below is just to ensure that the type's declaration is added to VDM
                resolveAADLDataImplementationType(dataSubCompDataImplementation, dataTypeDecl, model);
                verdict.vdm.vdm_data.DataType recFieldDtype = new verdict.vdm.vdm_data.DataType();
                recFieldDtype.setUserDefinedType(dataSubCompDataImplementation.getName());
                recField.setType(recFieldDtype);
                recType.getRecordField().add(recField);
            } else {
                System.out.println("Unexpected Data Subcomponent that is not a DataTypeImpl or DataImplementatioImpl.");
            }
        }
        if (recType.getRecordField().size() != 0) {
            dtype.setRecordType(recType);
            // DEFINE DATA TYPE IN DECLARATIONS IF NOT ALREADY DEFINED
            String dataImplementationName = dataImplementationImpl.getName();
            if (!dataTypeDecl.contains(dataImplementationName)) {
                dataTypeDecl.add(dataImplementationName);
                // vdm data type declaration
                TypeDeclaration dataTypeVdm = new TypeDeclaration();
                dataTypeVdm.setName(dataImplementationName);
                dataTypeVdm.setDefinition(dtype);
                // add the typeDeclaration to the model
                model.getTypeDeclaration().add(dataTypeVdm);
            }
        }
    } else {
        // if the dataType is base type boolean or integer or char or string
        System.out.println("Unexpected data implementation type with no subcomponents");
        // DEFINE DATA TYPE IN DECLARATIONS IF NOT ALREADY DEFINED
        String dataImplementationName = dataImplementationImpl.getName();
        if (!dataTypeDecl.contains(dataImplementationName)) {
            dataTypeDecl.add(dataImplementationName);
            // vdm data type declaration
            TypeDeclaration dataTypeVdm = new TypeDeclaration();
            dataTypeVdm.setName(dataImplementationName);
            // add the typeDeclaration to the model
            model.getTypeDeclaration().add(dataTypeVdm);
        }
    }
}
Also used : RecordField(verdict.vdm.vdm_data.RecordField) DataImplementation(org.osate.aadl2.DataImplementation) DataSubcomponentType(org.osate.aadl2.DataSubcomponentType) RecordType(verdict.vdm.vdm_data.RecordType) DataSubcomponent(org.osate.aadl2.DataSubcomponent) TypeDeclaration(verdict.vdm.vdm_data.TypeDeclaration)

Example 5 with RecordType

use of org.osate.aadl2.RecordType in project AGREE by loonwerks.

the class AgreeUtils method getInitValueFromType.

public static Expr getInitValueFromType(Type type) {
    if (type instanceof NamedType) {
        return getInitValueFromType((NamedType) type);
    }
    if (type instanceof RecordType) {
        RecordType recordType = (RecordType) type;
        Map<String, Expr> fieldMap = new HashMap<>();
        for (Entry<String, Type> entry : recordType.fields.entrySet()) {
            Expr subExpr = getInitValueFromType(entry.getValue());
            fieldMap.put(entry.getKey(), subExpr);
        }
        return new RecordExpr(recordType.id, fieldMap);
    }
    throw new AgreeException("AGREE cannot figure out an initial type for Lustre type: " + type.getClass());
}
Also used : RecordType(jkind.lustre.RecordType) EnumType(jkind.lustre.EnumType) ComponentType(org.osate.aadl2.ComponentType) Type(jkind.lustre.Type) NamedType(jkind.lustre.NamedType) RecordType(jkind.lustre.RecordType) RecordAccessExpr(jkind.lustre.RecordAccessExpr) Expr(jkind.lustre.Expr) IntExpr(jkind.lustre.IntExpr) RecordExpr(jkind.lustre.RecordExpr) BoolExpr(jkind.lustre.BoolExpr) RealExpr(jkind.lustre.RealExpr) IdExpr(jkind.lustre.IdExpr) HashMap(java.util.HashMap) NamedType(jkind.lustre.NamedType) RecordExpr(jkind.lustre.RecordExpr)

Aggregations

ArrayList (java.util.ArrayList)12 List (java.util.List)8 AbstractRecordType (org.geotoolkit.csw.xml.v202.AbstractRecordType)7 BriefRecordType (org.geotoolkit.csw.xml.v202.BriefRecordType)7 RecordType (org.geotoolkit.csw.xml.v202.RecordType)7 SummaryRecordType (org.geotoolkit.csw.xml.v202.SummaryRecordType)7 SimpleLiteral (org.geotoolkit.dublincore.xml.v2.elements.SimpleLiteral)7 BoundingBoxType (org.geotoolkit.ows.xml.v100.BoundingBoxType)7 WGS84BoundingBoxType (org.geotoolkit.ows.xml.v100.WGS84BoundingBoxType)7 Test (org.junit.Test)7 NamedElement (org.osate.aadl2.NamedElement)7 Property (org.osate.aadl2.Property)7 RecordType (org.openarchives.oai._2.RecordType)6 OAIPMH (org.openarchives.oai._2.OAIPMH)5 ResumptionTokenType (org.openarchives.oai._2.ResumptionTokenType)5 AadlPackage (org.osate.aadl2.AadlPackage)5 DoubleDotRef (com.rockwellcollins.atc.agree.agree.DoubleDotRef)4 StringWriter (java.io.StringWriter)4 RecordType (org.osate.aadl2.RecordType)4 Map (java.util.Map)3