generated from NASA-PDS/template-repo-java
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d26e447
commit 96f4e63
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
service/src/main/java/gov/nasa/pds/api/registry/model/properties/PdsProperty.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,54 @@ | ||
package gov.nasa.pds.api.registry.model.properties; | ||
|
||
import gov.nasa.pds.api.registry.exceptions.UnsupportedSearchProperty; | ||
import gov.nasa.pds.api.registry.model.exceptions.UnhandledException; | ||
|
||
import static gov.nasa.pds.api.registry.model.SearchUtil.jsonPropertyToOpenProperty; | ||
import static gov.nasa.pds.api.registry.model.SearchUtil.openPropertyToJsonProperty; | ||
|
||
/** | ||
* Provides a unified interface for dealing with PDS product properties, which are named differently depending on the | ||
* context. The canonical names used by OpenSearch use '/' as a separator, whereas users and the API URL interface | ||
* replace these with "." | ||
*/ | ||
public class PdsProperty { | ||
private final String value; | ||
|
||
public PdsProperty(String value) { | ||
this.value = value; | ||
} | ||
|
||
/** | ||
* Returns the property, in the format used by OpenSearch | ||
*/ | ||
public static String toOpenPropertyString(String value) { | ||
// TODO: replace all uses of SearchUtil.jsonPropertyToOpenProperty with PdsProperty, move conversion logic here, | ||
// and excise SearchUtil.jsonPropertyToOpenProperty | ||
return jsonPropertyToOpenProperty(value); | ||
} | ||
|
||
public String toOpenPropertyString() { | ||
return toOpenPropertyString(this.value); | ||
} | ||
|
||
/** | ||
* Returns the property, in the format used by the API interface (i.e. end-users) | ||
*/ | ||
public static String toJsonPropertyString(String value) { | ||
// TODO: replace all uses of SearchUtil.openPropertyToJsonProperty with PdsProperty, move conversion logic here, | ||
// and excise SearchUtil.openPropertyToJsonProperty | ||
|
||
//TODO: Remove this stopgap once https://github.com/NASA-PDS/registry-api/issues/528 is resolved | ||
try{ | ||
return openPropertyToJsonProperty(value); | ||
} catch (UnsupportedSearchProperty err) { | ||
return value.replace('/', '.'); | ||
} | ||
} | ||
|
||
public String toJsonPropertyString() { | ||
return toJsonPropertyString(this.value); | ||
} | ||
|
||
|
||
} |