/******************************************************************************** | |
* Copyright (c) 2015-2020 Contributors to the Eclipse Foundation | |
* | |
* See the NOTICE file(s) distributed with this work for additional | |
* information regarding copyright ownership. | |
* | |
* This program and the accompanying materials are made available under the | |
* terms of the Eclipse Public License v. 2.0 which is available at | |
* http://www.eclipse.org/legal/epl-2.0. | |
* | |
* SPDX-License-Identifier: EPL-2.0 | |
* | |
********************************************************************************/ | |
package org.eclipse.mdm.nodeprovider.boundary; | |
import javax.ejb.EJB; | |
import javax.ws.rs.Consumes; | |
import javax.ws.rs.GET; | |
import javax.ws.rs.POST; | |
import javax.ws.rs.Path; | |
import javax.ws.rs.PathParam; | |
import javax.ws.rs.Produces; | |
import javax.ws.rs.WebApplicationException; | |
import javax.ws.rs.core.MediaType; | |
import javax.ws.rs.core.Response; | |
import javax.ws.rs.core.Response.Status; | |
import org.eclipse.mdm.businessobjects.boundary.ChannelResource; | |
import org.eclipse.mdm.businessobjects.utils.ServiceUtils; | |
import org.eclipse.mdm.nodeprovider.entity.Node; | |
import org.eclipse.mdm.nodeprovider.entity.NodeProvider; | |
import org.eclipse.mdm.nodeprovider.entity.NodeProviderResponse; | |
import org.eclipse.mdm.nodeprovider.utils.SerializationUtil; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
import io.swagger.v3.oas.annotations.tags.Tag; | |
/** | |
* {@link NodeProvider} resource | |
* | |
* | |
*/ | |
@Tag(name = "NodeProvder") | |
@Path("/nodeprovider") | |
@Produces(MediaType.APPLICATION_JSON) | |
public class NodeProviderResource { | |
private static final Logger LOG = LoggerFactory.getLogger(ChannelResource.class); | |
@EJB | |
private NodeProviderService nodeProviderRepository; | |
public NodeProviderResource() { | |
} | |
public NodeProviderResource(NodeProviderService nodeProviderRepository) { | |
this.nodeProviderRepository = nodeProviderRepository; | |
} | |
@GET | |
public Response getNodeProviders() { | |
return Response.ok(this.nodeProviderRepository.getNodeProviderNames()).build(); | |
} | |
@GET | |
@Path("{NODEPROVIDER}") | |
public Response getRoots(@PathParam("NODEPROVIDER") String nodeProviderId) { | |
try { | |
java.util.List<Node> nodes = this.nodeProviderRepository.getNodeProvider(nodeProviderId).getRoots(); | |
return ServiceUtils.toResponse(new NodeProviderResponse(nodes), Status.OK); | |
} catch (RuntimeException e) { | |
LOG.error(e.getMessage(), e); | |
throw new WebApplicationException(e.getMessage(), e, Status.INTERNAL_SERVER_ERROR); | |
} | |
} | |
@GET | |
@Path("{NODEPROVIDER}/{PARENT_ID}") | |
public Response getChildren(@PathParam("NODEPROVIDER") String nodeProviderId, | |
@PathParam("PARENT_ID") String parentId) { | |
try { | |
java.util.List<Node> nodes = this.nodeProviderRepository.getNodeProvider(nodeProviderId) | |
.getChildren(SerializationUtil.deserializeNode(parentId)); | |
return ServiceUtils.toResponse(new NodeProviderResponse(nodes), Status.OK); | |
} catch (RuntimeException e) { | |
LOG.error(e.getMessage(), e); | |
throw new WebApplicationException(e.getMessage(), e, Status.INTERNAL_SERVER_ERROR); | |
} | |
} | |
@POST | |
@Consumes(MediaType.APPLICATION_JSON) | |
@Path("{NODEPROVIDER}") | |
public Response getTreePath(@PathParam("NODEPROVIDER") String nodeProviderId, Node node) { | |
try { | |
java.util.List<Node> nodes = this.nodeProviderRepository.getNodeProvider(nodeProviderId).getTreePath(node); | |
return ServiceUtils.toResponse(new NodeProviderResponse(nodes), Status.OK); | |
} catch (RuntimeException e) { | |
LOG.error(e.getMessage(), e); | |
throw new WebApplicationException(e.getMessage(), e, Status.INTERNAL_SERVER_ERROR); | |
} | |
} | |
} |