Search in sources :

Example 66 with ObjectFactory

use of net.opengis.gml._3.ObjectFactory 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 67 with ObjectFactory

use of net.opengis.gml._3.ObjectFactory in project phoss-smp by phax.

the class MainCreate1MillionEndpoints method main.

public static void main(final String[] args) throws Throwable {
    final SMPServerRESTTestRule aRule = new SMPServerRESTTestRule(ClassPathResource.getAsFile("test-smp-server-mongodb.properties").getAbsolutePath());
    aRule.before();
    try {
        // Set the special PhotonSecurityManager factory
        PhotonSecurityManager.setFactory(new PhotonSecurityManagerFactoryMongoDB());
        final ObjectFactory aObjFactory = new ObjectFactory();
        final PeppolDocumentTypeIdentifier aDT = EPredefinedDocumentTypeIdentifier.INVOICE_EN16931_PEPPOL_V30.getAsDocumentTypeIdentifier();
        final String sDT = aDT.getURIEncoded();
        final PeppolProcessIdentifier aProcID = EPredefinedProcessIdentifier.BIS3_BILLING.getAsProcessIdentifier();
        final StopWatch aSWOverall = StopWatch.createdStarted();
        for (int i = 639276; i < 1_000_000; ++i) {
            final StopWatch aSW = StopWatch.createdStarted();
            final PeppolParticipantIdentifier aPI = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9999:test-philip-" + StringHelper.getLeadingZero(i, 7));
            final String sPI = aPI.getURIEncoded();
            final ServiceMetadataType aSM = new ServiceMetadataType();
            final ServiceInformationType aSI = new ServiceInformationType();
            aSI.setParticipantIdentifier(new SimpleParticipantIdentifier(aPI));
            aSI.setDocumentIdentifier(aDT);
            {
                final ProcessListType aPL = new ProcessListType();
                final ProcessType aProcess = new ProcessType();
                aProcess.setProcessIdentifier(aProcID);
                final ServiceEndpointList aSEL = new ServiceEndpointList();
                final EndpointType aEndpoint = new EndpointType();
                aEndpoint.setEndpointReference(W3CEndpointReferenceHelper.createEndpointReference("http://test.smpserver/as2"));
                aEndpoint.setRequireBusinessLevelSignature(false);
                aEndpoint.setCertificate("blacert");
                aEndpoint.setServiceDescription("Unit test service");
                aEndpoint.setTechnicalContactUrl("https://github.com/phax/phoss-smp");
                aEndpoint.setTransportProfile(ESMPTransportProfile.TRANSPORT_PROFILE_AS2.getID());
                aSEL.addEndpoint(aEndpoint);
                aProcess.setServiceEndpointList(aSEL);
                aPL.addProcess(aProcess);
                aSI.setProcessList(aPL);
            }
            aSM.setServiceInformation(aSI);
            try (final WebScoped aWS = new WebScoped(new MockHttpServletRequest())) {
                // Delete old - don't care about the result
                if (false)
                    ClientBuilder.newClient().target(aRule.getFullURL()).path(sPI).path("services").path(sDT).request().header(CHttpHeader.AUTHORIZATION, CREDENTIALS.getRequestValue()).delete();
                // Create a new
                final Response aResponseMsg = ClientBuilder.newClient().target(aRule.getFullURL()).path(sPI).path("services").path(sDT).request().header(CHttpHeader.AUTHORIZATION, CREDENTIALS.getRequestValue()).put(Entity.xml(aObjFactory.createServiceMetadata(aSM)));
                _testResponseJerseyClient(aResponseMsg, 200);
            }
            aSW.stop();
            LOGGER.info(sPI + " took " + aSW.getMillis() + " ms");
        }
        aSWOverall.stop();
        LOGGER.info("Overall process took " + aSWOverall.getMillis() + " ms or " + aSWOverall.getDuration());
    } finally {
        aRule.after();
    }
}
Also used : WebScoped(com.helger.web.scope.mgr.WebScoped) PhotonSecurityManagerFactoryMongoDB(com.helger.phoss.smp.backend.mongodb.PhotonSecurityManagerFactoryMongoDB) MockHttpServletRequest(com.helger.servlet.mock.MockHttpServletRequest) PeppolProcessIdentifier(com.helger.peppolid.peppol.process.PeppolProcessIdentifier) ServiceInformationType(com.helger.xsds.peppol.smp1.ServiceInformationType) SimpleParticipantIdentifier(com.helger.peppolid.simple.participant.SimpleParticipantIdentifier) SMPServerRESTTestRule(com.helger.phoss.smp.mock.SMPServerRESTTestRule) StopWatch(com.helger.commons.timing.StopWatch) PeppolParticipantIdentifier(com.helger.peppolid.peppol.participant.PeppolParticipantIdentifier) Response(javax.ws.rs.core.Response) ProcessType(com.helger.xsds.peppol.smp1.ProcessType) ObjectFactory(com.helger.xsds.peppol.smp1.ObjectFactory) PeppolDocumentTypeIdentifier(com.helger.peppolid.peppol.doctype.PeppolDocumentTypeIdentifier) EndpointType(com.helger.xsds.peppol.smp1.EndpointType) ProcessListType(com.helger.xsds.peppol.smp1.ProcessListType) ServiceMetadataType(com.helger.xsds.peppol.smp1.ServiceMetadataType) ServiceEndpointList(com.helger.xsds.peppol.smp1.ServiceEndpointList)

Example 68 with ObjectFactory

use of net.opengis.gml._3.ObjectFactory in project testnorge by navikt.

the class ArbeidsforholdDTO method toXmlElement.

@Override
public XMLArbeidsforhold toXmlElement() {
    ObjectFactory factory = new ObjectFactory();
    XMLArbeidsforhold xmlArbeidsforhold = factory.createXMLArbeidsforhold();
    if (utsettelseAvForeldrepengerListe != null) {
        XMLUtsettelseAvForeldrepengerListe xmlUtsettelseAvForeldrepengerListe = factory.createXMLUtsettelseAvForeldrepengerListe();
        xmlUtsettelseAvForeldrepengerListe.withUtsettelseAvForeldrepenger(UtsettelseAvForeldrepengerDTO.convert(utsettelseAvForeldrepengerListe));
        xmlArbeidsforhold.setUtsettelseAvForeldrepengerListe(factory.createXMLArbeidsforholdUtsettelseAvForeldrepengerListe(xmlUtsettelseAvForeldrepengerListe));
    }
    if (graderingIForeldrepengerListe != null) {
        XMLGraderingIForeldrepengerListe xmlGraderingIForeldrepengerListe = factory.createXMLGraderingIForeldrepengerListe();
        xmlGraderingIForeldrepengerListe.withGraderingIForeldrepenger(GraderingIForeldrepengerDTO.convert(graderingIForeldrepengerListe));
        xmlArbeidsforhold.setGraderingIForeldrepengerListe(factory.createXMLArbeidsforholdGraderingIForeldrepengerListe(xmlGraderingIForeldrepengerListe));
    }
    if (avtaltFerieListe != null) {
        XMLAvtaltFerieListe xmlAvtaltFerieListe = factory.createXMLAvtaltFerieListe();
        xmlAvtaltFerieListe.withAvtaltFerie(PeriodeDTO.convert(avtaltFerieListe));
        xmlArbeidsforhold.setAvtaltFerieListe(factory.createXMLArbeidsforholdAvtaltFerieListe(xmlAvtaltFerieListe));
    }
    if (beregnetInntekt != null) {
        xmlArbeidsforhold.setBeregnetInntekt(factory.createXMLArbeidsforholdBeregnetInntekt(beregnetInntekt.toXmlElement()));
    }
    if (Strings.isNotBlank(arbeidsforholdId)) {
        xmlArbeidsforhold.setArbeidsforholdId(factory.createXMLArbeidsforholdArbeidsforholdId(arbeidsforholdId));
    }
    xmlArbeidsforhold.setFoersteFravaersdag(factory.createXMLArbeidsforholdFoersteFravaersdag(foersteFravaersdag));
    return xmlArbeidsforhold;
}
Also used : XMLArbeidsforhold(no.seres.xsd.nav.inntektsmelding_m._20181211.XMLArbeidsforhold) XMLUtsettelseAvForeldrepengerListe(no.seres.xsd.nav.inntektsmelding_m._20181211.XMLUtsettelseAvForeldrepengerListe) ObjectFactory(no.seres.xsd.nav.inntektsmelding_m._20181211.ObjectFactory) XMLGraderingIForeldrepengerListe(no.seres.xsd.nav.inntektsmelding_m._20181211.XMLGraderingIForeldrepengerListe) XMLAvtaltFerieListe(no.seres.xsd.nav.inntektsmelding_m._20181211.XMLAvtaltFerieListe)

Example 69 with ObjectFactory

use of net.opengis.gml._3.ObjectFactory in project testnorge by navikt.

the class ArbeidsgiverDTO method toXmlElement.

@Override
public XMLArbeidsgiver toXmlElement() {
    ObjectFactory factory = new ObjectFactory();
    XMLArbeidsgiver xmlArbeidsgiver = factory.createXMLArbeidsgiver();
    xmlArbeidsgiver.setVirksomhetsnummer(virksomhetsnummer);
    if (kontaktinformasjon != null) {
        xmlArbeidsgiver.setKontaktinformasjon(kontaktinformasjon.toXmlElement());
    }
    return xmlArbeidsgiver;
}
Also used : ObjectFactory(no.seres.xsd.nav.inntektsmelding_m._20181211.ObjectFactory) XMLArbeidsgiver(no.seres.xsd.nav.inntektsmelding_m._20181211.XMLArbeidsgiver)

Example 70 with ObjectFactory

use of net.opengis.gml._3.ObjectFactory in project testnorge by navikt.

the class InntektDTO method toXmlElement.

@Override
public XMLInntekt toXmlElement() {
    ObjectFactory factory = new ObjectFactory();
    XMLInntekt xmlInntekt = factory.createXMLInntekt();
    xmlInntekt.setAarsakVedEndring(factory.createXMLInntektAarsakVedEndring(aarsakVedEndring));
    xmlInntekt.setBeloep(factory.createXMLInntektBeloep(beloep != null ? BigDecimal.valueOf(beloep) : null));
    return xmlInntekt;
}
Also used : XMLInntekt(no.seres.xsd.nav.inntektsmelding_m._20181211.XMLInntekt) ObjectFactory(no.seres.xsd.nav.inntektsmelding_m._20181211.ObjectFactory)

Aggregations

JAXBElement (javax.xml.bind.JAXBElement)34 Test (org.junit.Test)29 ArrayList (java.util.ArrayList)26 Marshaller (javax.xml.bind.Marshaller)23 ObjectFactory (net.opengis.cat.csw.v_2_0_2.ObjectFactory)20 StringWriter (java.io.StringWriter)19 JAXBContext (javax.xml.bind.JAXBContext)18 QueryType (net.opengis.cat.csw.v_2_0_2.QueryType)18 GetRecordsType (net.opengis.cat.csw.v_2_0_2.GetRecordsType)17 ObjectFactory (no.seres.xsd.nav.inntektsmelding_m._20181211.ObjectFactory)16 QName (javax.xml.namespace.QName)15 CswRecordCollection (org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection)13 ObjectFactory (com.opensymphony.xwork2.ObjectFactory)12 XStream (com.thoughtworks.xstream.XStream)12 ByteArrayInputStream (java.io.ByteArrayInputStream)12 GetRecordsResponseType (net.opengis.cat.csw.v_2_0_2.GetRecordsResponseType)12 SearchResultsType (net.opengis.cat.csw.v_2_0_2.SearchResultsType)12 ObjectFactory (slash.navigation.kml.binding22.ObjectFactory)12 BigInteger (java.math.BigInteger)11 ElementSetNameType (net.opengis.cat.csw.v_2_0_2.ElementSetNameType)11