From 22f74d134763948e52e35d99d6bf5208b9ca2417 Mon Sep 17 00:00:00 2001 From: aedelmann Date: Wed, 5 Oct 2016 03:44:41 +0800 Subject: [PATCH] Fixes #415 --- .../web/ModelResolveController.java | 63 +++++++++++++++++++ .../web/{ => ui}/ModelDetailsResolver.java | 2 +- 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 server/repo/repo-ui/src/main/java/org/eclipse/vorto/repository/web/ModelResolveController.java rename server/repo/repo-ui/src/main/java/org/eclipse/vorto/repository/web/{ => ui}/ModelDetailsResolver.java (98%) diff --git a/server/repo/repo-ui/src/main/java/org/eclipse/vorto/repository/web/ModelResolveController.java b/server/repo/repo-ui/src/main/java/org/eclipse/vorto/repository/web/ModelResolveController.java new file mode 100644 index 0000000000..5338765e45 --- /dev/null +++ b/server/repo/repo-ui/src/main/java/org/eclipse/vorto/repository/web/ModelResolveController.java @@ -0,0 +1,63 @@ +/** + * Copyright (c) 2015-2016 Bosch Software Innovations GmbH and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and Eclipse Distribution License v1.0 which accompany this distribution. + * + * The Eclipse Public License is available at + * http://www.eclipse.org/legal/epl-v10.html + * The Eclipse Distribution License is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * Contributors: + * Bosch Software Innovations GmbH - Please refer to git log + */ +package org.eclipse.vorto.repository.web; + +import org.eclipse.vorto.http.model.ModelId; +import org.eclipse.vorto.repository.internal.resolver.ModelIdResolverFactory; +import org.eclipse.vorto.repository.internal.resolver.UnknownModelIdResolverException; +import org.eclipse.vorto.repository.resolver.IModelIdResolver; +import org.eclipse.vorto.repository.service.ModelNotFoundException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping(value = "/rest/resolve") +public class ModelResolveController { + + @Autowired + private ModelIdResolverFactory resolverFactory; + + @RequestMapping(value = "/{serviceKey}/{id}", method = RequestMethod.GET) + public ModelId resolve(@PathVariable("serviceKey") final String serviceKey, @PathVariable("id") final String id) throws Exception{ + IModelIdResolver resolver = resolverFactory.getResolver(serviceKey); + + ModelId resolvedId = resolver.resolve(id); + + if (resolvedId != null) { + return resolvedId; + } else { + throw new ModelNotFoundException("No Model found"); + } + } + + @ResponseStatus(value=HttpStatus.NOT_FOUND, reason = "Model not found.") // 404 + @ExceptionHandler(ModelNotFoundException.class) + public void NotFound(final ModelNotFoundException ex){ + // do logging + } + + @ResponseStatus(value=HttpStatus.NOT_FOUND, reason = "Unknown resolver.") // 404 + @ExceptionHandler(UnknownModelIdResolverException.class) + public void UnknownModelIdResolver(final UnknownModelIdResolverException ex){ + // do logging + } +} diff --git a/server/repo/repo-ui/src/main/java/org/eclipse/vorto/repository/web/ModelDetailsResolver.java b/server/repo/repo-ui/src/main/java/org/eclipse/vorto/repository/web/ui/ModelDetailsResolver.java similarity index 98% rename from server/repo/repo-ui/src/main/java/org/eclipse/vorto/repository/web/ModelDetailsResolver.java rename to server/repo/repo-ui/src/main/java/org/eclipse/vorto/repository/web/ui/ModelDetailsResolver.java index d8c63543b1..552596dc2a 100644 --- a/server/repo/repo-ui/src/main/java/org/eclipse/vorto/repository/web/ModelDetailsResolver.java +++ b/server/repo/repo-ui/src/main/java/org/eclipse/vorto/repository/web/ui/ModelDetailsResolver.java @@ -12,7 +12,7 @@ * Contributors: * Bosch Software Innovations GmbH - Please refer to git log */ -package org.eclipse.vorto.repository.web; +package org.eclipse.vorto.repository.web.ui; import org.eclipse.vorto.http.model.ModelId; import org.eclipse.vorto.repository.internal.resolver.ModelIdResolverFactory;