All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opengis.cite.ogcapiprocesses10.openapi3.UriBuilder Maven / Gradle / Ivy

There is a newer version: 1.2
Show newest version
package org.opengis.cite.ogcapiprocesses10.openapi3;

import java.util.HashMap;
import java.util.Map;

import org.glassfish.jersey.uri.UriTemplate;
import org.glassfish.jersey.uri.internal.UriPart;
import org.glassfish.jersey.uri.internal.UriTemplateParser;

/**
 * Builds a URL out of a TestPoint.
 *
 * @author Lyn Goltz 
 */
public class UriBuilder {

	private final TestPoint testPoint;

	private final Map templateReplacements = new HashMap<>();

	/**
	 * 

* Constructor for UriBuilder. *

* @param testPoint never null */ public UriBuilder(TestPoint testPoint) { this.testPoint = testPoint; this.templateReplacements.putAll(testPoint.getPredefinedTemplateReplacement()); } /** * Adds the collectionName to the URI * @param collectionName never null * @return this UrlBuilder */ public UriBuilder collectionName(String collectionName) { String templateName = retrieveCollectionNameTemplateName(); addTemplateReplacement(collectionName, templateName); return this; } /** * Adds the featureId to the URI * @param featureId never null * @return this UrlBuilder */ public UriBuilder featureId(String featureId) { String templateName = retrieveFeatureIdTemplateName(); addTemplateReplacement(featureId, templateName); return this; } /** *

* buildUrl. *

* @return this URI, never null */ public String buildUrl() { UriTemplate uriTemplate = new UriTemplate(testPoint.getServerUrl() + testPoint.getPath()); return uriTemplate.createURI(templateReplacements); } private void addTemplateReplacement(String collectionName, String templateName) { if (templateName != null) templateReplacements.put(templateName, collectionName); } private String retrieveCollectionNameTemplateName() { String path = testPoint.getPath(); UriTemplateParser uriTemplateParser = new UriTemplateParser(path); for (UriPart templateName : uriTemplateParser.getNames()) { if (path.startsWith("/collections/{" + templateName + "}")) return templateName.getPart(); } return null; } private String retrieveFeatureIdTemplateName() { String path = testPoint.getPath(); UriTemplateParser uriTemplateParser = new UriTemplateParser(path); for (UriPart templateName : uriTemplateParser.getNames()) { if (path.endsWith("items/{" + templateName + "}")) return templateName.getPart(); } return null; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy