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;
}
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();
}
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);
}
}
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);
}
}
}
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());
}
Aggregations