Search in sources :

Example 51 with Namespace

use of com.google.cloud.servicedirectory.v1.Namespace in project qpp-conversion-tool by CMSgov.

the class QrdaUpdater method updateQrdaMeasureData.

static Document updateQrdaMeasureData(Path path) {
    try {
        SAXBuilder saxBuilder = new SAXBuilder();
        InputStream inputStream = Files.newInputStream(path);
        Document document = saxBuilder.build(inputStream);
        Element rootElement = document.getDocument().getRootElement();
        rootElement.detach();
        Namespace rootNamespace = rootElement.getNamespace();
        List<Element> measureComponents = rootElement.getChild("component", rootNamespace).getChild("structuredBody", rootNamespace).getChildren("component", rootNamespace);
        Element measureComponent = measureComponents.stream().filter(component -> component.getChild("section", rootNamespace).getChildren("templateId", rootNamespace).stream().anyMatch(templateIdElement -> TemplateId.MEASURE_SECTION_V3.getRoot().equals(templateIdElement.getAttribute("root").getValue()))).findFirst().orElse(null);
        List<Element> measureEntries = measureComponent.getChild("section", rootNamespace).getChildren("entry", rootNamespace);
        for (Element measureEntry : measureEntries) {
            Element measureEntryOrganizer = measureEntry.getChild("organizer", rootNamespace);
            if (measureEntryOrganizer != null) {
                Element measureRnrTemplateId = measureEntryOrganizer.getChildren("templateId", rootNamespace).stream().filter(childElement -> TemplateId.MEASURE_REFERENCE_RESULTS_CMS_V4.getRoot().equals(childElement.getAttribute("root").getValue())).findAny().orElse(null);
                if (measureRnrTemplateId != null) {
                    String currentMeasureUuid = measureEntryOrganizer.getChild("reference", rootNamespace).getChild("externalDocument", rootNamespace).getChild("id", rootNamespace).getAttribute("extension").getValue();
                    MeasureConfig previousYearMeasureConfig = (MeasureConfig) previousYearMeasureConfigMap.get(currentMeasureUuid);
                    if ("CMS166v6".equals(previousYearMeasureConfig.getElectronicMeasureId()))
                        break;
                    String updatedElectronicMeasureId = updateElectronicMeasureId(previousYearMeasureConfig.getElectronicMeasureId());
                    MeasureConfig currentYearMeasureConfig = (MeasureConfig) currentYearMeasureConfigMap.get(updatedElectronicMeasureId);
                    updateMeasureUuid(rootNamespace, currentYearMeasureConfig, measureEntryOrganizer);
                    List<Element> subpopulationComponents = measureEntryOrganizer.getChildren("component", rootNamespace);
                    Long numberOfPerformanceRates = subpopulationComponents.stream().filter(subpopulationElement -> subpopulationElement.getChild("observation", rootNamespace).getChildren("templateId", rootNamespace).stream().anyMatch(templateElements -> TemplateId.PERFORMANCE_RATE_PROPORTION_MEASURE.getRoot().equals(templateElements.getAttribute("root").getValue()))).count();
                    if (numberOfPerformanceRates == 1L) {
                        subpopulationComponents.forEach(component -> {
                            Element componentObservation = component.getChild("observation", rootNamespace);
                            Attribute subpopulationGuidAttribute = componentObservation.getChild("reference", rootNamespace).getChild("externalObservation", rootNamespace).getChild("id", rootNamespace).getAttribute("root");
                            if (isPerformanceRate(componentObservation, rootNamespace)) {
                                subpopulationGuidAttribute.setValue(currentYearMeasureConfig.getStrata().get(0).getElectronicMeasureUuids().getNumeratorUuid());
                            } else {
                                String currentSubpopulationType = componentObservation.getChild("value", rootNamespace).getAttribute("code").getValue();
                                SubPopulation subPopulationUuids = currentYearMeasureConfig.getStrata().get(0).getElectronicMeasureUuids();
                                if ("IPOP".equals(currentSubpopulationType) || "IPP".equals(currentSubpopulationType) && currentYearMeasureConfig.getStrata().get(0).getElectronicMeasureUuids().getInitialPopulationUuid() != null) {
                                    subpopulationGuidAttribute.setValue(subPopulationUuids.getInitialPopulationUuid());
                                } else if ("DENOM".equals(currentSubpopulationType) && currentYearMeasureConfig.getStrata().get(0).getElectronicMeasureUuids().getDenominatorUuid() != null) {
                                    subpopulationGuidAttribute.setValue(subPopulationUuids.getDenominatorUuid());
                                } else if ("NUMER".equals(currentSubpopulationType) && currentYearMeasureConfig.getStrata().get(0).getElectronicMeasureUuids().getNumeratorUuid() != null) {
                                    subpopulationGuidAttribute.setValue(subPopulationUuids.getNumeratorUuid());
                                } else if ("DENEXCEP".equals(currentSubpopulationType) && currentYearMeasureConfig.getStrata().get(0).getElectronicMeasureUuids().getDenominatorExceptionsUuid() != null) {
                                    subpopulationGuidAttribute.setValue(subPopulationUuids.getDenominatorExceptionsUuid());
                                } else if ("DENEX".equals(currentSubpopulationType) && currentYearMeasureConfig.getStrata().get(0).getElectronicMeasureUuids().getDenominatorExclusionsUuid() != null) {
                                    subpopulationGuidAttribute.setValue(subPopulationUuids.getDenominatorExclusionsUuid());
                                }
                            }
                        });
                    }
                }
            }
        }
        document.addContent(rootElement);
        return document;
    } catch (Exception exc) {
        exc.printStackTrace();
    }
    return null;
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) MeasureConfig(gov.cms.qpp.conversion.model.validation.MeasureConfig) Format(org.jdom2.output.Format) Files(java.nio.file.Files) Collection(java.util.Collection) FileWriter(java.io.FileWriter) IOException(java.io.IOException) FileSystem(java.nio.file.FileSystem) XMLOutputter(org.jdom2.output.XMLOutputter) Document(org.jdom2.Document) Strings(com.google.common.base.Strings) Attribute(org.jdom2.Attribute) List(java.util.List) SubPopulation(gov.cms.qpp.conversion.model.validation.SubPopulation) Map(java.util.Map) Namespace(org.jdom2.Namespace) TemplateId(gov.cms.qpp.conversion.model.TemplateId) LinkedList(java.util.LinkedList) Path(java.nio.file.Path) FileSystems(java.nio.file.FileSystems) Element(org.jdom2.Element) InputStream(java.io.InputStream) SubPopulation(gov.cms.qpp.conversion.model.validation.SubPopulation) SAXBuilder(org.jdom2.input.SAXBuilder) Attribute(org.jdom2.Attribute) InputStream(java.io.InputStream) Element(org.jdom2.Element) MeasureConfig(gov.cms.qpp.conversion.model.validation.MeasureConfig) Document(org.jdom2.Document) Namespace(org.jdom2.Namespace) IOException(java.io.IOException)

Example 52 with Namespace

use of com.google.cloud.servicedirectory.v1.Namespace in project jspwiki by apache.

the class WebContainerAuthorizer method isConstrained.

/**
 * <p>
 * Protected method that identifies whether a particular webapp URL is
 * constrained to a particular Role. The resource is considered constrained
 * if:
 * </p>
 * <ul>
 * <li>the web application deployment descriptor contains a
 * <code>security-constraint</code> with a child
 * <code>web-resource-collection/url-pattern</code> element matching the
 * URL, <em>and</em>:</li>
 * <li>this constraint also contains an
 * <code>auth-constraint/role-name</code> element equal to the supplied
 * Role's <code>getName()</code> method. If the supplied Role is Role.ALL,
 * it matches all roles</li>
 * </ul>
 * @param url the web resource
 * @param role the role
 * @return <code>true</code> if the resource is constrained to the role,
 *         <code>false</code> otherwise
 */
public boolean isConstrained(final String url, final Role role) {
    final Element root = m_webxml.getRootElement();
    final Namespace jeeNs = Namespace.getNamespace("j", J2EE_SCHEMA_25_NAMESPACE);
    // Get all constraints that have our URL pattern
    // (Note the crazy j: prefix to denote the jee schema)
    final String constrainsSelector = "//j:web-app/j:security-constraint[j:web-resource-collection/j:url-pattern=\"" + url + "\"]";
    final List<Element> constraints = XPathFactory.instance().compile(constrainsSelector, Filters.element(), null, jeeNs).evaluate(root);
    // Get all constraints that match our Role pattern
    final String rolesSelector = "//j:web-app/j:security-constraint[j:auth-constraint/j:role-name=\"" + role.getName() + "\"]";
    final List<Element> roles = XPathFactory.instance().compile(rolesSelector, Filters.element(), null, jeeNs).evaluate(root);
    // If we can't find either one, we must not be constrained
    if (constraints.size() == 0) {
        return false;
    }
    // Shortcut: if the role is ALL, we are constrained
    if (role.equals(Role.ALL)) {
        return true;
    }
    // If no roles, we must not be constrained
    if (roles.size() == 0) {
        return false;
    }
    // If a constraint is contained in both lists, we must be constrained
    for (final Element constraint : constraints) {
        for (final Element roleConstraint : roles) {
            if (constraint.equals(roleConstraint)) {
                return true;
            }
        }
    }
    return false;
}
Also used : Element(org.jdom2.Element) Namespace(org.jdom2.Namespace)

Example 53 with Namespace

use of com.google.cloud.servicedirectory.v1.Namespace in project android_packages_apps_GmsCore by microg.

the class CastDeviceControllerImpl method createMetadataFromApplication.

protected ApplicationMetadata createMetadataFromApplication(Application app) {
    if (app == null) {
        return null;
    }
    ApplicationMetadata metadata = new ApplicationMetadata();
    metadata.applicationId = app.id;
    metadata.name = app.name;
    Log.d(TAG, "unimplemented: ApplicationMetadata.images");
    Log.d(TAG, "unimplemented: ApplicationMetadata.senderAppLaunchUri");
    metadata.images = new ArrayList<WebImage>();
    metadata.namespaces = new ArrayList<String>();
    for (Namespace namespace : app.namespaces) {
        metadata.namespaces.add(namespace.name);
    }
    metadata.senderAppIdentifier = this.context.getPackageName();
    return metadata;
}
Also used : ApplicationMetadata(com.google.android.gms.cast.ApplicationMetadata) WebImage(com.google.android.gms.common.images.WebImage) Namespace(su.litvak.chromecast.api.v2.Namespace)

Example 54 with Namespace

use of com.google.cloud.servicedirectory.v1.Namespace in project oozie by apache.

the class EmailActionExecutor method validateAndMail.

@SuppressWarnings("unchecked")
protected void validateAndMail(Context context, Element element) throws ActionExecutorException {
    // The XSD does the min/max occurrence validation for us.
    Namespace ns = element.getNamespace();
    String[] tos = new String[0];
    String[] ccs = new String[0];
    String[] bccs;
    String subject = "";
    String body = "";
    String[] attachments = new String[0];
    String contentType;
    Element child = null;
    // <to> - One ought to exist.
    String text = element.getChildTextTrim(TO, ns);
    if (text.isEmpty()) {
        throw new ActionExecutorException(ErrorType.ERROR, "EM001", "No recipients were specified in the to-address field.");
    }
    tos = text.split(COMMA);
    // <cc> - Optional, but only one ought to exist.
    try {
        ccs = element.getChildTextTrim(CC, ns).split(COMMA);
    } catch (Exception e) {
        // It is alright for cc to be given empty or not be present.
        ccs = new String[0];
    }
    // <bcc> - Optional, but only one ought to exist.
    try {
        bccs = element.getChildTextTrim(BCC, ns).split(COMMA);
    } catch (Exception e) {
        // It is alright for bcc to be given empty or not be present.
        bccs = new String[0];
    }
    // <subject> - One ought to exist.
    subject = element.getChildTextTrim(SUB, ns);
    // <body> - One ought to exist.
    body = element.getChildTextTrim(BOD, ns);
    // <attachment> - Optional
    String attachment = element.getChildTextTrim(ATTACHMENT, ns);
    if (attachment != null) {
        attachments = attachment.split(COMMA);
    }
    contentType = element.getChildTextTrim(CONTENT_TYPE, ns);
    if (contentType == null || contentType.isEmpty()) {
        contentType = DEFAULT_CONTENT_TYPE;
    }
    // All good - lets try to mail!
    email(tos, ccs, bccs, subject, body, attachments, contentType, context.getWorkflow().getUser());
}
Also used : Element(org.jdom2.Element) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) Namespace(org.jdom2.Namespace) URISyntaxException(java.net.URISyntaxException) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) MessagingException(javax.mail.MessagingException) AddressException(javax.mail.internet.AddressException) HadoopAccessorException(org.apache.oozie.service.HadoopAccessorException) IOException(java.io.IOException) NoSuchProviderException(javax.mail.NoSuchProviderException)

Example 55 with Namespace

use of com.google.cloud.servicedirectory.v1.Namespace in project oozie by apache.

the class JavaActionExecutor method getCaptureOutput.

protected boolean getCaptureOutput(WorkflowAction action) throws JDOMException {
    Element eConf = XmlUtils.parseXml(action.getConf());
    Namespace ns = eConf.getNamespace();
    Element captureOutput = eConf.getChild("capture-output", ns);
    return captureOutput != null;
}
Also used : Element(org.jdom2.Element) Namespace(org.jdom2.Namespace)

Aggregations

Namespace (org.jdom2.Namespace)176 Element (org.jdom2.Element)145 IOException (java.io.IOException)45 Document (org.jdom2.Document)36 ArrayList (java.util.ArrayList)30 Attribute (org.jdom2.Attribute)25 HashMap (java.util.HashMap)23 List (java.util.List)21 XConfiguration (org.apache.oozie.util.XConfiguration)19 StringReader (java.io.StringReader)18 JDOMException (org.jdom2.JDOMException)18 Configuration (org.apache.hadoop.conf.Configuration)15 SAXBuilder (org.jdom2.input.SAXBuilder)15 Map (java.util.Map)14 ActionExecutorException (org.apache.oozie.action.ActionExecutorException)14 Namespace.getNamespace (org.jdom2.Namespace.getNamespace)14 MigrationReport (com.mulesoft.tools.migration.step.category.MigrationReport)13 File (java.io.File)13 Path (org.apache.hadoop.fs.Path)12 Path (java.nio.file.Path)11