-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added resolver for bluetooth device info profile
- Loading branch information
Showing
11 changed files
with
205 additions
and
31 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
...o-core/src/main/java/org/eclipse/vorto/repository/internal/resolver/AbstractResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* 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.internal.resolver; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
import org.eclipse.vorto.core.api.model.mapping.MappingModel; | ||
import org.eclipse.vorto.http.model.ModelId; | ||
import org.eclipse.vorto.http.model.ModelResource; | ||
import org.eclipse.vorto.http.model.ModelType; | ||
import org.eclipse.vorto.repository.model.IModelContent; | ||
import org.eclipse.vorto.repository.resolver.IModelIdResolver; | ||
import org.eclipse.vorto.repository.service.IModelRepository; | ||
import org.eclipse.vorto.repository.service.IModelRepository.ContentType; | ||
|
||
public abstract class AbstractResolver implements IModelIdResolver { | ||
|
||
protected IModelRepository repository; | ||
|
||
private String serviceKey; | ||
|
||
public AbstractResolver(IModelRepository repository, String serviceKey) { | ||
this.repository = repository; | ||
this.serviceKey = serviceKey; | ||
} | ||
|
||
@Override | ||
public ModelId resolve(String id) { | ||
List<ModelResource> mappings = this.repository.search(ModelType.Mapping.name()); | ||
Optional<ModelId> foundId = mappings.stream() | ||
.filter(resource -> matchesServiceKey(resource)) | ||
.map(r -> doResolve(r,id)) | ||
.filter(modelId -> Objects.nonNull(modelId)).findFirst(); | ||
return foundId.isPresent() ? foundId.get() : null; | ||
} | ||
|
||
private boolean matchesServiceKey(ModelResource resource) { | ||
IModelContent content = this.repository.getModelContent(resource.getId(), ContentType.DSL); | ||
return ((MappingModel)content.getModel()).getTargetPlatform().equals(this.serviceKey); | ||
} | ||
|
||
protected abstract ModelId doResolve(ModelResource mappingModelResource, String id); | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
...e/src/main/java/org/eclipse/vorto/repository/internal/resolver/BlueToothUUIDResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* 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.internal.resolver; | ||
|
||
import java.util.Optional; | ||
|
||
import org.eclipse.vorto.core.api.model.mapping.Attribute; | ||
import org.eclipse.vorto.core.api.model.mapping.MappingModel; | ||
import org.eclipse.vorto.core.api.model.mapping.MappingRule; | ||
import org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget; | ||
import org.eclipse.vorto.http.model.ModelId; | ||
import org.eclipse.vorto.http.model.ModelResource; | ||
import org.eclipse.vorto.repository.model.IModelContent; | ||
import org.eclipse.vorto.repository.service.IModelRepository; | ||
import org.eclipse.vorto.repository.service.IModelRepository.ContentType; | ||
|
||
public class BlueToothUUIDResolver extends AbstractResolver { | ||
|
||
public BlueToothUUIDResolver(IModelRepository repository, String serviceKey) { | ||
super(repository,serviceKey); | ||
} | ||
|
||
@Override | ||
protected ModelId doResolve(ModelResource mappingModelResource, String id) { | ||
IModelContent content = this.repository.getModelContent(mappingModelResource.getId(), ContentType.DSL); | ||
MappingModel mappingModel = (MappingModel)content.getModel(); | ||
Optional<MappingRule> objectRule = mappingModel.getRules().stream().filter(rule -> rule.getTarget() instanceof StereoTypeTarget && ((StereoTypeTarget)rule.getTarget()).getName().equals("DeviceInfoProfile")).findFirst(); | ||
|
||
if (objectRule.isPresent()) { | ||
Optional<Attribute> objectIdAttribute = ((StereoTypeTarget)objectRule.get().getTarget()).getAttributes().stream().filter(attribute -> attribute.getName().equals("modelNumber")).findFirst(); | ||
if (objectIdAttribute.isPresent() && objectIdAttribute.get().getValue().equals(id)) { | ||
return ModelId.fromReference(mappingModel.getReferences().get(0)); | ||
} | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...st/java/org/eclipse/vorto/repository/resolver/BlueToothDeviceInfoProfileResolverTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* 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.resolver; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
|
||
import org.eclipse.vorto.http.model.ModelId; | ||
import org.eclipse.vorto.repository.internal.resolver.BlueToothUUIDResolver; | ||
import org.eclipse.vorto.repository.service.AbstractIntegrationTest; | ||
import org.junit.Test; | ||
|
||
public class BlueToothDeviceInfoProfileResolverTest extends AbstractIntegrationTest { | ||
|
||
@Test | ||
public void testResolveInfoModelByDeviceInfoProfileSerialNo() { | ||
checkinModel("bluetooth/ColorLight.fbmodel"); | ||
checkinModel("bluetooth/ColorLightIM.infomodel"); | ||
checkinModel("bluetooth/ColorLight_bluetooth.mapping"); | ||
|
||
BlueToothUUIDResolver resolver = new BlueToothUUIDResolver(this.modelRepository,"bluetooth"); | ||
assertEquals(new ModelId("ColorLightIM", "com.mycompany", "1.0.0"),resolver.resolve("4810")); | ||
|
||
assertNotNull(this.modelRepository.getById(resolver.resolve("4810"))); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
server/repo/repo-core/src/test/resources/sample_models/bluetooth/ColorLight.fbmodel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
namespace com.mycompany.fb | ||
version 1.0.0 | ||
displayname "Color Light" | ||
description "Sample Function block model" | ||
category demo | ||
functionblock ColorLight { | ||
|
||
configuration { | ||
mandatory isOn as boolean | ||
} | ||
|
||
status { | ||
optional consumption as double | ||
mandatory r as int <MIN 0, MAX 255> | ||
mandatory g as int <MIN 0, MAX 255> | ||
mandatory b as int <MIN 0, MAX 255> | ||
} | ||
|
||
operations { | ||
on() | ||
off() | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
server/repo/repo-core/src/test/resources/sample_models/bluetooth/ColorLightIM.infomodel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace com.mycompany | ||
version 1.0.0 | ||
displayname "ColorLight IM" | ||
description "Information model for Color Light IM" | ||
category demo | ||
using com.mycompany.fb.ColorLight ; 1.0.0 | ||
|
||
infomodel ColorLightIM { | ||
|
||
functionblocks { | ||
colorLight as ColorLight | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...er/repo/repo-core/src/test/resources/sample_models/bluetooth/ColorLight_bluetooth.mapping
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace examples.mappings.bt | ||
version 1.0.0 | ||
displayname "Color Light BT Mapping" | ||
description "Maps ColorLight functionblock to BT GATT" | ||
using com.mycompany.ColorLightIM;1.0.0 | ||
infomodelmapping ColorLight_bt { | ||
targetplatform bluetooth | ||
|
||
from ColorLightIM to DeviceInfoProfile with {modelNumber:"4810"} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters