forked from eclipse/org.eclipse.sensinact.gateway
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleaned up return values by returning DTOs. Added Converters to conve…
…rt DTOs to String values. Signed-off-by: David Leangen <osgi@leangen.net>
- Loading branch information
David Leangen
committed
Mar 11, 2024
1 parent
aed98c6
commit aa24cd5
Showing
10 changed files
with
282 additions
and
111 deletions.
There are no files selected for viewing
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
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
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
62 changes: 62 additions & 0 deletions
62
...rc/main/java/org/eclipse/sensinact/gateway/commands/gogo/converter/MetadataConverter.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,62 @@ | ||
/********************************************************************* | ||
* Copyright (c) 2024 Contributors to the Eclipse Foundation. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Kentyou - initial implementation | ||
**********************************************************************/ | ||
package org.eclipse.sensinact.gateway.commands.gogo.converter; | ||
|
||
import java.util.stream.Collectors; | ||
|
||
import org.apache.felix.service.command.Converter; | ||
import org.eclipse.sensinact.gateway.commands.gogo.MetaCommands.MetaDTO; | ||
import org.osgi.service.component.annotations.Component; | ||
|
||
/** | ||
* @author David Leangen | ||
*/ | ||
@Component | ||
public class MetadataConverter | ||
implements Converter | ||
{ | ||
@Override | ||
public Object convert(Class<?> desiredType, Object in) | ||
throws Exception | ||
{ | ||
return null; | ||
} | ||
|
||
@Override | ||
public CharSequence format(Object target, int level, Converter escape) | ||
throws Exception | ||
{ | ||
if (target instanceof MetaDTO) { | ||
final MetaDTO dto = (MetaDTO) target; | ||
|
||
if (level == INSPECT) { | ||
|
||
if (dto.metadata == null) | ||
return "<EMPTY>"; | ||
|
||
final String data = dto.metadata.entrySet().stream() | ||
.map(e -> " " + e.getKey() + " = " + e.getValue()) | ||
.collect(Collectors.joining("\n ")); | ||
|
||
return "\n" | ||
+ "Resource: " + dto.provider + "/" + dto.service + "/" + dto.resource + "\n" | ||
+ "\n" | ||
+ " Metadata\n" | ||
+ " --------\n" | ||
+ " " + data + "\n"; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...rc/main/java/org/eclipse/sensinact/gateway/commands/gogo/converter/ProviderConverter.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,62 @@ | ||
/********************************************************************* | ||
* Copyright (c) 2024 Contributors to the Eclipse Foundation. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Kentyou - initial implementation | ||
**********************************************************************/ | ||
package org.eclipse.sensinact.gateway.commands.gogo.converter; | ||
|
||
import java.util.stream.Collectors; | ||
|
||
import org.apache.felix.service.command.Converter; | ||
import org.eclipse.sensinact.core.session.ProviderDescription; | ||
import org.osgi.service.component.annotations.Component; | ||
|
||
/** | ||
* @author David Leangen | ||
*/ | ||
@Component | ||
public class ProviderConverter | ||
implements Converter | ||
{ | ||
@Override | ||
public Object convert(Class<?> desiredType, Object in) | ||
throws Exception | ||
{ | ||
return null; | ||
} | ||
|
||
@Override | ||
public CharSequence format(Object target, int level, Converter escape) | ||
throws Exception | ||
{ | ||
if (target instanceof ProviderDescription) { | ||
final ProviderDescription description = (ProviderDescription) target; | ||
|
||
if (level == LINE) { | ||
return description.provider; | ||
} | ||
|
||
if (level == INSPECT) { | ||
|
||
final String services = description.services.stream() | ||
.collect(Collectors.joining("\n ")); | ||
|
||
return "\n" | ||
+ "Provider: " + description.provider + "\n" | ||
+ "\n" | ||
+ " Services\n" | ||
+ " --------\n" | ||
+ " " + services + "\n"; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
} |
Oops, something went wrong.