-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: refactor CreateAsset Endpoint
- Loading branch information
Showing
9 changed files
with
181 additions
and
141 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
68 changes: 68 additions & 0 deletions
68
.../main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/EdcPropertyMapperUtils.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,68 @@ | ||
/* | ||
* Copyright (c) 2023 sovity GmbH | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Contributors: | ||
* sovity GmbH - init | ||
*/ | ||
|
||
package de.sovity.edc.ext.wrapper.api.common.mappers.utils; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.eclipse.edc.spi.types.domain.DataAddress; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
@RequiredArgsConstructor | ||
public class EdcPropertyMapperUtils { | ||
|
||
/** | ||
* Converts a {@code Map<String, Object>} to {@code Map<String, String>}. | ||
* <p> | ||
* Our API forsakes asset properties that are complex objects / JSON and only keeps string | ||
* properties. | ||
* | ||
* @param map all properties | ||
* @return string properties | ||
*/ | ||
public Map<String, String> truncateToMapOfString(Map<String, Object> map) { | ||
Map<String, String> result = new HashMap<>(); | ||
|
||
for (Map.Entry<String, Object> entry : map.entrySet()) { | ||
Object value = entry.getValue(); | ||
|
||
String valueString; | ||
if (value == null) { | ||
valueString = null; | ||
} else if (value instanceof String str) { | ||
valueString = str; | ||
} else if (value instanceof Double) { | ||
valueString = String.valueOf(value); | ||
} else if (value instanceof Integer) { | ||
valueString = String.valueOf(value); | ||
} else { | ||
continue; | ||
} | ||
|
||
result.put(entry.getKey(), valueString); | ||
} | ||
return result; | ||
} | ||
|
||
@SuppressWarnings({"unchecked", "rawtypes", "java:S1905"}) | ||
public Map<String, Object> toMapOfObject(Map<String, String> map) { | ||
return new HashMap<>((Map<String, Object>) (Map) map); | ||
} | ||
|
||
public DataAddress buildDataAddress(Map<String, String> properties) { | ||
return DataAddress.Builder.newInstance() | ||
.properties(toMapOfObject(properties)) | ||
.build(); | ||
} | ||
} |
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
Oops, something went wrong.