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

com.mercateo.common.rest.schemagen.link.ExternalLinkFactory Maven / Gradle / Ivy

There is a newer version: 0.20.0
Show newest version
package com.mercateo.common.rest.schemagen.link;

import java.net.URI;
import java.util.Objects;
import java.util.Optional;

import javax.ws.rs.core.Link;
import javax.ws.rs.core.Link.Builder;

import com.mercateo.common.rest.schemagen.link.injection.BaseUri;
import com.mercateo.common.rest.schemagen.link.relation.RelType;
import com.mercateo.common.rest.schemagen.link.relation.Relation;

/**
 * This LinkFactory is for linking to external URIs. The starting point here is
 * very simple. In the future we may prefix relative URLs with the
 * {@link BaseUri} or check access rights, etc.
 * 
 * @author joerg_adler
 *
 */
public class ExternalLinkFactory {
	public Link createFor(URI uri, Optional schemaForLink, String relName) {
		Objects.requireNonNull(uri);
		Objects.requireNonNull(schemaForLink);
		Objects.requireNonNull(relName);

		Relation rel = Relation.of(relName, RelType.OTHER);
		Builder linkBuilder = LinkCreator.setRelation(rel, uri);
		if (schemaForLink.isPresent()) {
			linkBuilder.param(LinkCreator.SCHEMA_PARAM_KEY, schemaForLink.get());
		}		
		return linkBuilder.build();
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy