Search in sources :

Example 1 with SimpleLiteral

use of org.purl.dc.elements._1.SimpleLiteral in project fix-orchestra by FIXTradingCommunity.

the class RepositoryCompressor method compress.

private boolean compress(InputStream is, OutputStream os, Predicate<? super MessageType> messagePredicate) {
    try {
        final Repository inRepository = unmarshal(is);
        final Categories categories = inRepository.getCategories();
        isCategoryInSection.setCategories(categories.getCategory());
        final Repository outRepository = new Repository();
        inRepository.copyTo(null, outRepository, AttributeCopyStrategy.INSTANCE);
        final ElementOrRefinementContainer metadata = (ElementOrRefinementContainer) inRepository.getMetadata().clone();
        final List<JAXBElement<SimpleLiteral>> literals = metadata.getAny();
        final ObjectFactory objectFactory = new ObjectFactory();
        final SimpleLiteral contributor = new SimpleLiteral();
        contributor.getContent().add("RepositoryCompressor");
        literals.add(objectFactory.createContributor(contributor));
        outRepository.setMetadata(metadata);
        if (categories != null) {
            outRepository.setCategories((Categories) categories.clone());
        }
        final Sections sections = inRepository.getSections();
        if (sections != null) {
            outRepository.setSections((Sections) sections.clone());
        }
        final Datatypes datatypes = inRepository.getDatatypes();
        if (datatypes != null) {
            outRepository.setDatatypes((Datatypes) datatypes.clone());
        }
        final Actors actors = inRepository.getActors();
        if (actors != null) {
            outRepository.setActors((Actors) actors.clone());
        }
        final Components components = inRepository.getComponents();
        if (components != null) {
            final Components inComponents = (Components) components.clone();
            componentList = inComponents.getComponent();
        }
        final Groups groups = inRepository.getGroups();
        if (groups != null) {
            final Groups inGroups = (Groups) groups.clone();
            groupList = inGroups.getGroup();
        }
        final Messages messages = inRepository.getMessages();
        final List<MessageType> messageList;
        if (messages != null) {
            final Messages inMessages = (Messages) messages.clone();
            messageList = inMessages.getMessage();
        } else {
            messageList = Collections.emptyList();
        }
        final List<MessageType> filteredMessages = messageList.stream().filter(messagePredicate).collect(Collectors.toList());
        filteredMessages.forEach(m -> walk(m.getStructure().getComponentRefOrGroupRefOrFieldRef()));
        final List<BigInteger> distinctFieldIds = fieldIdList.stream().distinct().collect(Collectors.toList());
        final Fields inFields = (Fields) inRepository.getFields().clone();
        final List<FieldType> fieldsWithFlow = inFields.getField().stream().filter(f -> distinctFieldIds.contains(f.getId())).collect(Collectors.toList());
        final Fields outFields = new Fields();
        outFields.getField().addAll(fieldsWithFlow);
        outRepository.setFields(outFields);
        final List<String> typeList = fieldsWithFlow.stream().map(FieldType::getType).distinct().collect(Collectors.toList());
        final CodeSets inCodeSets = (CodeSets) inRepository.getCodeSets().clone();
        final List<CodeSetType> codeSetsWithFlow = inCodeSets.getCodeSet().stream().filter(cs -> typeList.contains(cs.getName())).collect(Collectors.toList());
        final CodeSets outCodeSets = new CodeSets();
        outCodeSets.getCodeSet().addAll(codeSetsWithFlow);
        outRepository.setCodeSets(outCodeSets);
        final List<BigInteger> distinctComponentsIds = componentIdList.stream().distinct().collect(Collectors.toList());
        final List<ComponentType> componentsWithFlow = componentList.stream().filter(c -> distinctComponentsIds.contains(c.getId())).collect(Collectors.toList());
        final Components outComponents = new Components();
        outComponents.getComponent().addAll(componentsWithFlow);
        outRepository.setComponents(outComponents);
        final List<BigInteger> distinctGroupIds = groupIdList.stream().distinct().collect(Collectors.toList());
        final List<GroupType> groupWithFlow = groupList.stream().filter(c -> distinctGroupIds.contains(c.getId())).collect(Collectors.toList());
        final Groups outGroups = new Groups();
        outGroups.getGroup().addAll(groupWithFlow);
        outRepository.setGroups(outGroups);
        final Messages outMessages = new Messages();
        outMessages.getMessage().addAll(filteredMessages);
        outRepository.setMessages(outMessages);
        marshal(outRepository, os);
        return true;
    } catch (JAXBException e) {
        logger.fatal("RepositoryCompressor failed", e);
        return false;
    }
}
Also used : ComponentType(io.fixprotocol._2020.orchestra.repository.ComponentType) ElementOrRefinementContainer(org.purl.dc.terms.ElementOrRefinementContainer) Sections(io.fixprotocol._2020.orchestra.repository.Sections) Marshaller(javax.xml.bind.Marshaller) Components(io.fixprotocol._2020.orchestra.repository.Components) Options(org.apache.commons.cli.Options) CategoryType(io.fixprotocol._2020.orchestra.repository.CategoryType) GroupRefType(io.fixprotocol._2020.orchestra.repository.GroupRefType) HelpFormatter(org.apache.commons.cli.HelpFormatter) ArrayList(java.util.ArrayList) DefaultParser(org.apache.commons.cli.DefaultParser) BiPredicate(java.util.function.BiPredicate) CodeSets(io.fixprotocol._2020.orchestra.repository.CodeSets) MessageType(io.fixprotocol._2020.orchestra.repository.MessageType) Groups(io.fixprotocol._2020.orchestra.repository.Groups) Fields(io.fixprotocol._2020.orchestra.repository.Fields) CommandLine(org.apache.commons.cli.CommandLine) BigInteger(java.math.BigInteger) ObjectFactory(org.purl.dc.elements._1.ObjectFactory) Datatypes(io.fixprotocol._2020.orchestra.repository.Datatypes) Repository(io.fixprotocol._2020.orchestra.repository.Repository) JAXBContext(javax.xml.bind.JAXBContext) Option(org.apache.commons.cli.Option) SimpleLiteral(org.purl.dc.elements._1.SimpleLiteral) ComponentRefType(io.fixprotocol._2020.orchestra.repository.ComponentRefType) OutputStream(java.io.OutputStream) Unmarshaller(javax.xml.bind.Unmarshaller) Actors(io.fixprotocol._2020.orchestra.repository.Actors) Predicate(java.util.function.Predicate) JAXBElement(javax.xml.bind.JAXBElement) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Collectors(java.util.stream.Collectors) JAXBException(javax.xml.bind.JAXBException) File(java.io.File) Categories(io.fixprotocol._2020.orchestra.repository.Categories) List(java.util.List) Logger(org.apache.logging.log4j.Logger) FieldRefType(io.fixprotocol._2020.orchestra.repository.FieldRefType) CodeSetType(io.fixprotocol._2020.orchestra.repository.CodeSetType) ParseException(org.apache.commons.cli.ParseException) FieldType(io.fixprotocol._2020.orchestra.repository.FieldType) Messages(io.fixprotocol._2020.orchestra.repository.Messages) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) InputStream(java.io.InputStream) GroupType(io.fixprotocol._2020.orchestra.repository.GroupType) Components(io.fixprotocol._2020.orchestra.repository.Components) ObjectFactory(org.purl.dc.elements._1.ObjectFactory) Sections(io.fixprotocol._2020.orchestra.repository.Sections) Groups(io.fixprotocol._2020.orchestra.repository.Groups) SimpleLiteral(org.purl.dc.elements._1.SimpleLiteral) Datatypes(io.fixprotocol._2020.orchestra.repository.Datatypes) MessageType(io.fixprotocol._2020.orchestra.repository.MessageType) CodeSetType(io.fixprotocol._2020.orchestra.repository.CodeSetType) ComponentType(io.fixprotocol._2020.orchestra.repository.ComponentType) Messages(io.fixprotocol._2020.orchestra.repository.Messages) CodeSets(io.fixprotocol._2020.orchestra.repository.CodeSets) Categories(io.fixprotocol._2020.orchestra.repository.Categories) JAXBException(javax.xml.bind.JAXBException) Actors(io.fixprotocol._2020.orchestra.repository.Actors) JAXBElement(javax.xml.bind.JAXBElement) FieldType(io.fixprotocol._2020.orchestra.repository.FieldType) Repository(io.fixprotocol._2020.orchestra.repository.Repository) Fields(io.fixprotocol._2020.orchestra.repository.Fields) GroupType(io.fixprotocol._2020.orchestra.repository.GroupType) ElementOrRefinementContainer(org.purl.dc.terms.ElementOrRefinementContainer) BigInteger(java.math.BigInteger)

Example 2 with SimpleLiteral

use of org.purl.dc.elements._1.SimpleLiteral in project ARLAS-server by gisaia.

the class RecordBuilder method addSubject.

public static void addSubject(AbstractRecordType abstractRecordType, String subject) {
    SimpleLiteral simpleLiteral = new SimpleLiteral();
    simpleLiteral.getContent().add(subject);
    switch(abstractRecordType.getClass().getSimpleName()) {
        case "SummaryRecordType":
            ((SummaryRecordType) abstractRecordType).getSubject().add(simpleLiteral);
            break;
        case "RecordType":
            JAXBElement<SimpleLiteral> JAXBElementSubject = dcObjectFactory.createSubject(simpleLiteral);
            ((RecordType) abstractRecordType).getDCElement().add(JAXBElementSubject);
            break;
    }
}
Also used : SimpleLiteral(org.purl.dc.elements._1.SimpleLiteral)

Example 3 with SimpleLiteral

use of org.purl.dc.elements._1.SimpleLiteral in project ARLAS-server by gisaia.

the class RecordBuilder method addUrlToWFS.

public static void addUrlToWFS(AbstractRecordType abstractRecordType, String url) {
    SimpleLiteral simpleLiteral = new SimpleLiteral();
    simpleLiteral.getContent().add(url);
    simpleLiteral.setScheme("http://www.opengis.net/wfs/2.0");
    JAXBElement<SimpleLiteral> JAXBElementIdentifier = dctObjectFactory.createReferences((simpleLiteral));
    switch(abstractRecordType.getClass().getSimpleName()) {
        case "BriefRecordType":
            ((BriefRecordType) abstractRecordType).getIdentifier().add(JAXBElementIdentifier);
            break;
        case "SummaryRecordType":
            ((SummaryRecordType) abstractRecordType).getIdentifier().add(JAXBElementIdentifier);
            break;
        case "RecordType":
            ((RecordType) abstractRecordType).getDCElement().add(JAXBElementIdentifier);
            break;
    }
}
Also used : SimpleLiteral(org.purl.dc.elements._1.SimpleLiteral)

Example 4 with SimpleLiteral

use of org.purl.dc.elements._1.SimpleLiteral in project ARLAS-server by gisaia.

the class RecordBuilder method addModified.

public static void addModified(AbstractRecordType abstractRecordType, String modified) {
    SimpleLiteral simpleLiteral = new SimpleLiteral();
    simpleLiteral.getContent().add(modified);
    switch(abstractRecordType.getClass().getSimpleName()) {
        case "SummaryRecordType":
            ((SummaryRecordType) abstractRecordType).getModified().add(simpleLiteral);
            break;
        case "RecordType":
            JAXBElement<SimpleLiteral> JAXBElementDate = dcObjectFactory.createDate(simpleLiteral);
            ((RecordType) abstractRecordType).getDCElement().add(JAXBElementDate);
            break;
    }
}
Also used : SimpleLiteral(org.purl.dc.elements._1.SimpleLiteral)

Example 5 with SimpleLiteral

use of org.purl.dc.elements._1.SimpleLiteral in project ARLAS-server by gisaia.

the class AtomBuilder method setRecordType.

public static void setRecordType(RecordType recordType, EntryType entryType) {
    org.purl.dc.elements._1.ObjectFactory objectFactory = new org.purl.dc.elements._1.ObjectFactory();
    recordType.getDCElement().stream().forEach(simpleLiteralJAXBElement -> {
        String value = simpleLiteralJAXBElement.getValue().getContent().get(0);
        TextType textType = new TextType();
        textType.getContent().add(value);
        SimpleLiteral simpleLiteral = objectFactory.createSimpleLiteral();
        simpleLiteral.getContent().add(value);
        switch(simpleLiteralJAXBElement.getName().getLocalPart()) {
            case "title":
                entryType.setTitle(textType);
                break;
            case "subject":
                entryType.setSubject(simpleLiteral);
                break;
            case "type":
                entryType.setType(simpleLiteral);
                break;
            case "date":
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
                try {
                    GregorianCalendar c = new GregorianCalendar();
                    c.setTime(simpleDateFormat.parse(value));
                    try {
                        XMLGregorianCalendar date = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
                        DateTimeType dateTimeType = new DateTimeType();
                        dateTimeType.setValue(date);
                        entryType.setPublished(dateTimeType);
                        entryType.setUpdated(dateTimeType);
                    } catch (DatatypeConfigurationException e) {
                        e.printStackTrace();
                        throw new WebApplicationException(e);
                    }
                } catch (ParseException e) {
                    e.printStackTrace();
                    throw new WebApplicationException(e);
                }
                break;
            case "format":
                entryType.setFormat(objectFactory.createFormat(simpleLiteral));
                break;
            case "description":
                entryType.setSummary(textType);
                break;
            case "identifier":
                entryType.setIdentifier(objectFactory.createIdentifier(simpleLiteral));
                break;
        }
    });
    String south = recordType.getBoundingBox().get(0).getValue().getLowerCorner().get(1);
    String west = recordType.getBoundingBox().get(0).getValue().getLowerCorner().get(0);
    String north = recordType.getBoundingBox().get(0).getValue().getUpperCorner().get(1);
    String east = recordType.getBoundingBox().get(0).getValue().getUpperCorner().get(0);
    entryType.getBox().add(south);
    entryType.getBox().add(west);
    entryType.getBox().add(north);
    entryType.getBox().add(east);
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) GregorianCalendar(java.util.GregorianCalendar) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) SimpleLiteral(org.purl.dc.elements._1.SimpleLiteral) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

SimpleLiteral (org.purl.dc.elements._1.SimpleLiteral)10 Actors (io.fixprotocol._2020.orchestra.repository.Actors)1 Categories (io.fixprotocol._2020.orchestra.repository.Categories)1 CategoryType (io.fixprotocol._2020.orchestra.repository.CategoryType)1 CodeSetType (io.fixprotocol._2020.orchestra.repository.CodeSetType)1 CodeSets (io.fixprotocol._2020.orchestra.repository.CodeSets)1 ComponentRefType (io.fixprotocol._2020.orchestra.repository.ComponentRefType)1 ComponentType (io.fixprotocol._2020.orchestra.repository.ComponentType)1 Components (io.fixprotocol._2020.orchestra.repository.Components)1 Datatypes (io.fixprotocol._2020.orchestra.repository.Datatypes)1 FieldRefType (io.fixprotocol._2020.orchestra.repository.FieldRefType)1 FieldType (io.fixprotocol._2020.orchestra.repository.FieldType)1 Fields (io.fixprotocol._2020.orchestra.repository.Fields)1 GroupRefType (io.fixprotocol._2020.orchestra.repository.GroupRefType)1 GroupType (io.fixprotocol._2020.orchestra.repository.GroupType)1 Groups (io.fixprotocol._2020.orchestra.repository.Groups)1 MessageType (io.fixprotocol._2020.orchestra.repository.MessageType)1 Messages (io.fixprotocol._2020.orchestra.repository.Messages)1 Repository (io.fixprotocol._2020.orchestra.repository.Repository)1 Sections (io.fixprotocol._2020.orchestra.repository.Sections)1