Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
mfriesen committed Jun 8, 2024
1 parent 16a20da commit db6ede0
Show file tree
Hide file tree
Showing 10 changed files with 365 additions and 199 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* MIT License
*
* Copyright (c) 2018 - 2020 FormKiQ
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.formkiq.aws.dynamodb;

import software.amazon.awssdk.services.dynamodb.model.AttributeValue;

import java.util.Map;
import java.util.function.Function;

import static com.formkiq.aws.dynamodb.DbKeys.PK;
import static com.formkiq.aws.dynamodb.DbKeys.SK;

/**
* {@link Function} to convert {@link DynamodbRecord} to {@link Map} keys.
*/
public class DynamodbRecordToKeys
implements Function<DynamodbRecord<?>, Map<String, AttributeValue>> {

/** {@link String}. */
private final String site;

/**
* constructor.
*
* @param siteId {@link String}
*/
public DynamodbRecordToKeys(final String siteId) {
this.site = siteId;
}

@Override
public Map<String, AttributeValue> apply(final DynamodbRecord<?> record) {
return Map.of(PK, AttributeValue.fromS(record.pk(site)), SK, AttributeValue.fromS(record.sk()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.formkiq.stacks.api.transformers;
package com.formkiq.stacks.dynamodb;

import static com.formkiq.aws.dynamodb.objects.Objects.notNull;
import java.util.ArrayList;
Expand All @@ -44,9 +44,9 @@ public class DocumentAttributeSchema
implements Function<Collection<DocumentAttributeRecord>, Collection<DocumentAttributeRecord>> {

/** Document Id. */
private String docId;
private final String docId;
/** Schema. */
private Schema schema;
private final Schema schema;

/**
* constructor.
Expand Down Expand Up @@ -107,8 +107,8 @@ private List<DocumentAttributeRecord> createCompositeKeys(final List<List<String

for (int i = 0; i < compositeKeys.size(); i++) {

String compositeKey = compositeKeys.get(i).stream().collect(Collectors.joining("#"));
String stringValue = compositeValues.get(i).stream().collect(Collectors.joining("#"));
String compositeKey = String.join("#", compositeKeys.get(i));
String stringValue = String.join("#", compositeValues.get(i));

DocumentAttributeRecord r = new DocumentAttributeRecord();
r.key(compositeKey);
Expand Down Expand Up @@ -136,14 +136,13 @@ private Collection<DocumentAttributeRecord> createCompositeKeys(

Collection<DocumentAttributeRecord> compositeKeys = new ArrayList<>();

List<List<DocumentAttributeRecord>> compositeRecords = schemaAttributes.getAttributeKeys()
.stream().filter(attributeKey -> documentAttributeKeys.containsKey(attributeKey))
.map(key -> documentAttributeKeys.get(key)).toList();
List<List<DocumentAttributeRecord>> compositeRecords =
schemaAttributes.getAttributeKeys().stream().filter(documentAttributeKeys::containsKey)
.map(documentAttributeKeys::get).toList();

if (schemaAttributes.getAttributeKeys().size() == compositeRecords.size()) {

int listSize = compositeRecords.stream().map(l -> Integer.valueOf(l.size())).reduce(1,
(aa, bb) -> aa.intValue() * bb.intValue());
int listSize = compositeRecords.stream().map(List::size).reduce(1, (aa, bb) -> aa * bb);

if (listSize > 0) {

Expand Down
Loading

0 comments on commit db6ede0

Please sign in to comment.