You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2019/03/25 20:42:53 UTC

[GitHub] [nifi-registry] alopresto commented on a change in pull request #162: NIFIREG-238: Allow aliasing of registry url

alopresto commented on a change in pull request #162: NIFIREG-238: Allow aliasing of registry url
URL: https://github.com/apache/nifi-registry/pull/162#discussion_r268842135
 
 

 ##########
 File path: nifi-registry-core/nifi-registry-framework/src/main/java/org/apache/nifi/registry/service/alias/RegistryUrlAliasService.java
 ##########
 @@ -0,0 +1,167 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.registry.service.alias;
+
+import org.apache.commons.lang3.tuple.Pair;
+import org.apache.nifi.registry.flow.VersionedFlowCoordinates;
+import org.apache.nifi.registry.flow.VersionedProcessGroup;
+import org.apache.nifi.registry.properties.NiFiRegistryProperties;
+import org.apache.nifi.registry.provider.ProviderFactoryException;
+import org.apache.nifi.registry.provider.StandardProviderFactory;
+import org.apache.nifi.registry.url.aliaser.generated.Aliases;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.xml.sax.SAXException;
+
+import javax.xml.XMLConstants;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.validation.Schema;
+import javax.xml.validation.SchemaFactory;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+/**
+ * Allows aliasing of registry url(s) without modifying the flows on disk.
+ */
+@Service
+public class RegistryUrlAliasService {
+    private static final String ALIASES_XSD = "/aliases.xsd";
+    private static final String JAXB_GENERATED_PATH = "org.apache.nifi.registry.url.aliaser.generated";
+    private static final JAXBContext JAXB_CONTEXT = initializeJaxbContext();
+
+    /**
+     * Load the JAXBContext.
+     */
+    private static JAXBContext initializeJaxbContext() {
+        try {
+            return JAXBContext.newInstance(JAXB_GENERATED_PATH, RegistryUrlAliasService.class.getClassLoader());
+        } catch (JAXBException e) {
+            throw new RuntimeException("Unable to create JAXBContext.", e);
+        }
+    }
+
+    private final List<Pair<String, String>> aliases;
+
+    @Autowired
+    public RegistryUrlAliasService(NiFiRegistryProperties niFiRegistryProperties) {
+        this(createAliases(niFiRegistryProperties));
+    }
+
+    private static List<Pair<String, String>> createAliases(NiFiRegistryProperties niFiRegistryProperties) {
 
 Review comment:
   Is there a reason this returns `List<Pair<String, String>>` instead of a `Map<String, String>`? If sorting is a concern, `SortedMap<>` is available. 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services