Skip to content

Package: KapuaIdParamConverterProvider$1

KapuaIdParamConverterProvider$1

nameinstructionbranchcomplexitylinemethod
fromString(String)
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
toString(Object)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
{...}
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2021, 2022 Eurotech and/or its affiliates and others
3: *
4: * This program and the accompanying materials are made
5: * available under the terms of the Eclipse Public License 2.0
6: * which is available at https://www.eclipse.org/legal/epl-2.0/
7: *
8: * SPDX-License-Identifier: EPL-2.0
9: *
10: * Contributors:
11: * Eurotech - initial API and implementation
12: *******************************************************************************/
13: package org.eclipse.kapua.job.engine.app.core.converter;
14:
15: import java.lang.annotation.Annotation;
16: import java.lang.reflect.Type;
17:
18: import javax.ws.rs.ext.ParamConverter;
19: import javax.ws.rs.ext.ParamConverterProvider;
20: import javax.ws.rs.ext.Provider;
21:
22: import org.eclipse.kapua.locator.KapuaLocator;
23: import org.eclipse.kapua.model.id.KapuaId;
24: import org.eclipse.kapua.model.id.KapuaIdFactory;
25:
26: @Provider
27: public class KapuaIdParamConverterProvider implements ParamConverterProvider {
28:
29: private final KapuaLocator locator = KapuaLocator.getInstance();
30: private final KapuaIdFactory kapuaIdFactory = locator.getFactory(KapuaIdFactory.class);
31:
32: @Override
33: public <T> ParamConverter<T> getConverter(Class<T> rawType, Type genericType, Annotation[] annotations) {
34: if (rawType == KapuaId.class) {
35: return new ParamConverter<T>() {
36:
37: @Override
38: public T fromString(String value) {
39: return rawType.cast(kapuaIdFactory.newKapuaId(value));
40: }
41:
42: @Override
43: public String toString(T value) {
44: return ((KapuaId) value).toCompactId();
45: }
46:
47: };
48: }
49: return null;
50: }
51:
52: }