Search in sources :

Example 41 with Document

use of com.google.cloud.documentai.v1beta2.Document in project mule-migration-assistant by mulesoft.

the class AbstractThrottlingTestCase method createPolicy.

protected Element createPolicy(int rateLimitElements, String algorithmTagName, boolean isRateLimit) {
    Element policy = new Element(POLICY_TAG_NAME, MULE_3_POLICY_NAMESPACE);
    Element throttlingPolicy = new Element(POLICY_TAG_NAME, THROTTLING_GW_MULE_3_NAMESPACE);
    throttlingPolicy.addContent(isRateLimit ? getNewElement(DISCARD_RESPONSE_TAG_NAME) : getDelayResponseElement());
    Element algorithmElement = getNewElement(algorithmTagName);
    IntStream.range(0, rateLimitElements).mapToObj(i -> getRateLimitElement(String.valueOf(i))).forEach(algorithmElement::addContent);
    throttlingPolicy.addContent(algorithmElement);
    new Document().setRootElement(policy.addContent(throttlingPolicy));
    return algorithmElement;
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) IntStream(java.util.stream.IntStream) POLICY_TAG_NAME(com.mulesoft.tools.migration.library.gateway.TestConstants.POLICY_TAG_NAME) SOURCE_TAG_NAME(com.mulesoft.tools.migration.library.gateway.TestConstants.SOURCE_TAG_NAME) XSI_NAMESPACE(com.mulesoft.tools.migration.library.gateway.steps.GatewayNamespaces.XSI_NAMESPACE) ApplicationModel(com.mulesoft.tools.migration.project.model.ApplicationModel) Text(org.jdom2.Text) CONFIG(com.mulesoft.tools.migration.library.gateway.TestConstants.CONFIG) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) TRY_TAG_NAME(com.mulesoft.tools.migration.library.gateway.TestConstants.TRY_TAG_NAME) Document(org.jdom2.Document) STATUS_CODE(com.mulesoft.tools.migration.library.gateway.TestConstants.STATUS_CODE) Namespace(org.jdom2.Namespace) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) SET_RESPONSE_TAG_NAME(com.mulesoft.tools.migration.library.gateway.TestConstants.SET_RESPONSE_TAG_NAME) Path(java.nio.file.Path) PROXY_TAG_NAME(com.mulesoft.tools.migration.library.gateway.TestConstants.PROXY_TAG_NAME) Before(org.junit.Before) ProjectType(com.mulesoft.tools.migration.project.ProjectType) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) THROTTLING_GW_MULE_3_NAMESPACE(com.mulesoft.tools.migration.library.gateway.steps.GatewayNamespaces.THROTTLING_GW_MULE_3_NAMESPACE) FALSE(com.mulesoft.tools.migration.library.gateway.TestConstants.FALSE) MULE_3_POLICY_NAMESPACE(com.mulesoft.tools.migration.library.gateway.steps.GatewayNamespaces.MULE_3_POLICY_NAMESPACE) Mockito.verify(org.mockito.Mockito.verify) THROTTLING_MULE_4_NAMESPACE(com.mulesoft.tools.migration.library.gateway.steps.GatewayNamespaces.THROTTLING_MULE_4_NAMESPACE) Paths(java.nio.file.Paths) MULE_4_CORE_NAMESPACE_NO_PREFIX(com.mulesoft.tools.migration.library.gateway.steps.GatewayNamespaces.MULE_4_CORE_NAMESPACE_NO_PREFIX) HTTP_TRANSFORM_NAMESPACE(com.mulesoft.tools.migration.library.gateway.steps.GatewayNamespaces.HTTP_TRANSFORM_NAMESPACE) SCHEMA_LOCATION(com.mulesoft.tools.migration.library.gateway.TestConstants.SCHEMA_LOCATION) Mockito.mock(org.mockito.Mockito.mock) Element(org.jdom2.Element) Element(org.jdom2.Element) Document(org.jdom2.Document)

Example 42 with Document

use of com.google.cloud.documentai.v1beta2.Document in project mule-migration-assistant by mulesoft.

the class RamlTagMigrationStepTestCase method getTestElement.

private Element getTestElement(boolean hardCodedProperties) {
    Element ramlElement = new Element(RAML, PROXY_NAMESPACE).setAttribute(CONFIG_REF, CONFIG_REF_ATTR_VALUE);
    Element muleElement = new Element(MULE_TAG_NAME, MULE_4_NAMESPACE).addContent(new Element(FLOW_TAG_NAME, MULE_4_NAMESPACE).addContent(ramlElement)).addContent(new Element(RAML_PROXY_CONFIG_TAG_NAME, PROXY_NAMESPACE).setAttribute(NAME, CONFIG_REF_ATTR_VALUE).setAttribute(RAML, hardCodedProperties ? RAML_ATTR_VALUE_3X_HC : RAML_ATTR_VALUE_3X).setAttribute(DISABLE_VALIDATIONS_ATTR_NAME, hardCodedProperties ? FALSE : DISABLE_VALIDATIONS_ATTR_VALUE_3X));
    new Document().setRootElement(muleElement);
    return ramlElement;
}
Also used : Element(org.jdom2.Element) Document(org.jdom2.Document)

Example 43 with Document

use of com.google.cloud.documentai.v1beta2.Document in project mule-migration-assistant by mulesoft.

the class ProtectTagMigrationStepTestCase method getMuleElement.

private Element getMuleElement(boolean isJson) {
    Document doc = new Document();
    Element element = new Element(MULE_4_TAG_NAME, MULE_4_CORE_NAMESPACE_NO_PREFIX).addContent(new Element(isJson ? JSON_CONFIG : XML_CONFIG, isJson ? JSON_THREAT_PROTECTION_NAMESPACE : XML_THREAT_PROTECTION_NAMESPACE));
    doc.setRootElement(element);
    return element;
}
Also used : Element(org.jdom2.Element) Document(org.jdom2.Document)

Example 44 with Document

use of com.google.cloud.documentai.v1beta2.Document in project mule-migration-assistant by mulesoft.

the class RateLimitTagMigrationStepTestCase method getRateLimitSLAElement.

private Element getRateLimitSLAElement() {
    Element rateLimitElement = getRateLimitElement();
    new Document().setRootElement(new Element(POLICY_TAG_NAME, MULE_3_POLICY_NAMESPACE).addContent(new Element(DATA_TAG_NAME, MULE_3_POLICY_NAMESPACE).addContent(new Element(COLLECTION_TAG_NAME, MULE_3_POLICY_NAMESPACE).addContent(new Element(SLA_TAG_NAME, MULE_3_POLICY_NAMESPACE).addContent(rateLimitElement)))));
    return rateLimitElement;
}
Also used : Element(org.jdom2.Element) Document(org.jdom2.Document)

Example 45 with Document

use of com.google.cloud.documentai.v1beta2.Document in project adif-processor by urbancamo.

the class KmlWriter method write.

public void write(String pathname, String name, ActivityDatabases activities, Qsos qsos, TransformResults results) {
    KmlLocalActivities kmlLocalActivities = new KmlLocalActivities();
    KmlCommsUtils kmlCommsUtils = new KmlCommsUtils(control, activities);
    KmlStationUtils kmlStationUtils = new KmlStationUtils(control);
    KmlSatelliteTrack kmlSatelliteTrack = new KmlSatelliteTrack();
    final Kml kml = new Kml();
    Document doc = kml.createAndSetDocument().withName(name).withOpen(true);
    // create a Folder
    Folder contactsFolder = doc.createAndAddFolder();
    contactsFolder.withName("Contacts").withOpen(true);
    if (results.getSatelliteActivity().hasActivity()) {
        results.getSatelliteActivity().spaceOutContactsInPasses();
    }
    Station myStation = null;
    Iterator<Qso> qsoIterator = qsos.getQsos().iterator();
    Folder folder = null;
    while (qsoIterator.hasNext()) {
        Qso qso = qsoIterator.next();
        if (!qso.getFrom().equals(myStation)) {
            folder = contactsFolder.createAndAddFolder().withName(qso.getFrom().getCallsign()).withOpen(true);
            String error = kmlStationUtils.addMyStationToMap(doc, folder, qso);
            if (error != null) {
                results.setError(error);
            }
            if (qso.getFrom().hasActivity() && control.isKmlShowLocalActivationSites()) {
                kmlLocalActivities.addLocalActivities(doc, folder, qso.getFrom(), control.getKmlLocalActivationSitesRadius(), activities);
            }
            myStation = qso.getFrom();
        }
        Folder contactFolder = folder.createAndAddFolder().withName(qso.getTo().getCallsign()).withOpen(false);
        GlobalCoordinates coords = qso.getRecord().getCoordinates();
        if (LatLongUtils.isCoordinateValid(coords)) {
            String error = kmlStationUtils.createStationMarker(control, doc, contactFolder, qso);
            if (error != null) {
                results.setError(error);
            }
            if (qso.getTo().hasActivity() && control.isKmlShowLocalActivationSites()) {
                Folder localActivityFolder = contactFolder.createAndAddFolder().withName("Local Activity").withOpen(false);
                kmlLocalActivities.addLocalActivities(doc, localActivityFolder, qso.getTo(), control.getKmlLocalActivationSitesRadius(), activities);
            }
            error = kmlCommsUtils.createCommsLink(doc, contactFolder, qso, control, kmlStationUtils);
            if (error != null) {
                results.setError(error);
            }
            if (MaidenheadLocatorConversion.isADubiousGridSquare(qso.getRecord().getGridsquare())) {
                results.addContactWithDubiousLocation(qso.getTo().getCallsign());
            }
        } else {
            results.addContactWithoutLocation(qso.getTo().getCallsign());
            logger.warning(String.format("Cannot determine communication link, no location data for: %s", qso.getTo().getCallsign()));
        }
    }
    if (!results.hasErrors()) {
        if (results.getSatelliteActivity().hasActivity()) {
            GlobalCoordinates coords = qsos.getQsos().get(0).getRecord().getMyCoordinates();
            GlobalCoords3D coordinatesWithSourceAccuracy = new GlobalCoords3D(coords, 0.0);
            kmlSatelliteTrack.addSatelliteTracks(control, doc, results.getSatelliteActivity(), coordinatesWithSourceAccuracy);
        }
        try {
            logger.info(String.format("Writing KML to: %s", pathname));
            File file = new File(pathname);
            kml.marshal(file);
            String kmlContent = FileUtils.readFileToString(file, "UTF-8");
            kmlContent = kmlContent.replaceAll("ns2:", "").replace("<kml xmlns:ns2=\"http://www.opengis.net/kml/2.2\" xmlns:ns3=\"http://www.w3.org/2005/Atom\" xmlns:ns4=\"urn:oasis:names:tc:ciq:xsdschema:xAL:2.0\" xmlns:ns5=\"http://www.google.com/kml/ext/2.2\">", "<kml>");
            FileUtils.write(file, kmlContent, "UTF-8");
        } catch (IOException e) {
            results.setError(e.getMessage());
        }
    }
}
Also used : KmlLocalActivities(uk.m0nom.kml.activity.KmlLocalActivities) GlobalCoords3D(uk.m0nom.coords.GlobalCoords3D) Kml(de.micromata.opengis.kml.v_2_2_0.Kml) IOException(java.io.IOException) Document(de.micromata.opengis.kml.v_2_2_0.Document) Folder(de.micromata.opengis.kml.v_2_2_0.Folder) Qso(uk.m0nom.adif3.contacts.Qso) Station(uk.m0nom.adif3.contacts.Station) KmlStationUtils(uk.m0nom.kml.station.KmlStationUtils) KmlSatelliteTrack(uk.m0nom.kml.comms.KmlSatelliteTrack) KmlCommsUtils(uk.m0nom.kml.comms.KmlCommsUtils) GlobalCoordinates(org.gavaghan.geodesy.GlobalCoordinates) File(java.io.File)

Aggregations

Document (org.jdom2.Document)1034 Element (org.jdom2.Element)587 Test (org.junit.Test)340 SAXBuilder (org.jdom2.input.SAXBuilder)271 IOException (java.io.IOException)266 XMLOutputter (org.jdom2.output.XMLOutputter)182 JDOMException (org.jdom2.JDOMException)162 File (java.io.File)148 ArrayList (java.util.ArrayList)75 InputStream (java.io.InputStream)74 StringReader (java.io.StringReader)63 Path (java.nio.file.Path)59 HashMap (java.util.HashMap)57 DocumentHelper.getDocument (com.mulesoft.tools.migration.helper.DocumentHelper.getDocument)53 DocumentHelper.getElementsFromDocument (com.mulesoft.tools.migration.helper.DocumentHelper.getElementsFromDocument)53 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)48 PID (edu.unc.lib.boxc.model.api.ids.PID)47 Attribute (org.jdom2.Attribute)44 List (java.util.List)42 Namespace (org.jdom2.Namespace)39