-
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.
(#24): factors out connector stuff into own module
- Loading branch information
1 parent
58d82ae
commit 1fd01fd
Showing
8 changed files
with
181 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- Licensed to the Apache Software Foundation (ASF) under one or more | ||
contributor | ||
license agreements. See the NOTICE file distributed with this work for | ||
additional | ||
information regarding copyright ownership. The ASF licenses this file to | ||
you under the Apache License, Version 2.0 (the "License"); you may not use | ||
this file except in compliance with the License. You may obtain a copy of | ||
the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required | ||
by applicable law or agreed to in writing, software distributed under the | ||
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS | ||
OF ANY KIND, either express or implied. See the License for the specific | ||
language governing permissions and limitations under the License. --> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>at.ac.univie.nutrition.dita</groupId> | ||
<artifactId>dita-globodiet-connectors</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>dita-globodiet-connectors-nutridb</artifactId> | ||
<name>Dita - Globodiet Connectors (NutriDb)</name> | ||
<description> | ||
Dita library integrating Globodiet with NutriDb (an external FCDB system). | ||
</description> | ||
|
||
<properties> | ||
<jar-plugin.automaticModuleName>at.ac.univie.nutrition.dita.nutridb</jar-plugin.automaticModuleName> | ||
<git-plugin.propertiesDir>at/ac/univie/nutrition/dita/nutridb</git-plugin.propertiesDir> | ||
</properties> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>at.ac.univie.nutrition.dita</groupId> | ||
<artifactId>dita-recall24-dto</artifactId> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
</project> |
79 changes: 79 additions & 0 deletions
79
...ctors/nutridb/src/main/java/dita/globodiet/connectors/nutridb/util/NutriDbConverters.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,79 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package dita.globodiet.connectors.nutridb.util; | ||
|
||
import java.util.stream.Collectors; | ||
|
||
import org.apache.causeway.commons.internal.base._Strings; | ||
|
||
import lombok.experimental.UtilityClass; | ||
|
||
import dita.commons.format.FormatUtils; | ||
import dita.recall24.dto.RecallNode24; | ||
import dita.recall24.dto.RecallNode24.Builder24; | ||
import dita.recall24.dto.Record24; | ||
|
||
@UtilityClass | ||
public class NutriDbConverters { | ||
|
||
@UtilityClass | ||
public class ToNutriDB { | ||
public String convertFacet(final String facetGd) { | ||
var facet = facetGd.substring(0, 2); | ||
var descriptor = facetGd.substring(2); | ||
return "gd:F" + FormatUtils.noLeadingZeros(facet) + "." + descriptor; | ||
} | ||
public String convertFacetList(final String facetSids) { | ||
return _Strings.splitThenStream(facetSids, ",") | ||
.map(ToNutriDB::convertFacet) | ||
.collect(Collectors.joining(",")); | ||
} | ||
public String convertFood(final Record24.Type recordType, final String sid) { | ||
return switch(recordType) { | ||
case FOOD, TYPE_OF_FAT_USED, TYPE_OF_MILK_OR_LIQUID_USED, FRYING_FAT -> | ||
// ndb system-id = 'gd' | ||
"gd:N" + FormatUtils.noLeadingZeros(sid); | ||
case COMPOSITE -> | ||
// ndb system-id = 'gdr' | ||
"gdr:" + FormatUtils.noLeadingZeros(sid); | ||
case PRODUCT -> | ||
// ndb system-id = 'ndb' (supplements only) | ||
"ndb:" + FormatUtils.noLeadingZeros(sid); | ||
}; | ||
} | ||
} | ||
|
||
/** | ||
* Converts GloboDiet to NutriDb identifiers. | ||
*/ | ||
public record ToNutriDbTransfomer() implements RecallNode24.Transfomer { | ||
@Override | ||
public void accept(final Builder24<?> builder) { | ||
switch (builder) { | ||
case Record24.Builder recBuilder -> toNutriDbPrefixes(recBuilder); | ||
default -> {} | ||
}; | ||
} | ||
private void toNutriDbPrefixes(final Record24.Builder recBuilder) { | ||
recBuilder.sid(ToNutriDB.convertFood(recBuilder.type(), recBuilder.sid())); | ||
recBuilder.facetSids(ToNutriDB.convertFacetList(recBuilder.facetSids())); | ||
} | ||
} | ||
|
||
} |
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,38 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- Licensed to the Apache Software Foundation (ASF) under one or more | ||
contributor | ||
license agreements. See the NOTICE file distributed with this work for | ||
additional | ||
information regarding copyright ownership. The ASF licenses this file to | ||
you under the Apache License, Version 2.0 (the "License"); you may not use | ||
this file except in compliance with the License. You may obtain a copy of | ||
the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required | ||
by applicable law or agreed to in writing, software distributed under the | ||
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS | ||
OF ANY KIND, either express or implied. See the License for the specific | ||
language governing permissions and limitations under the License. --> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>at.ac.univie.nutrition.dita</groupId> | ||
<artifactId>dita-globodiet</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>dita-globodiet-connectors</artifactId> | ||
<name>Dita - Globodiet Connectors</name> | ||
<description> | ||
Globodiet connectors to external systems. | ||
</description> | ||
|
||
<packaging>pom</packaging> | ||
|
||
<modules> | ||
<module>nutridb</module> | ||
</modules> | ||
|
||
|
||
</project> |
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