Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public static TagConfigClient getInstance() {
public abstract Future<List<Tag>> getAllTags(Marker marker);

public abstract Future<Void> storeTag(Marker marker, Tag tag);
public abstract Future<Void> storeSharedTags(Marker marker, List<Tag> sharedTags);

public abstract Future<Tag> deleteTag(Marker marker, String id, String spaceId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package com.here.xyz.hub.config.dynamo;

import com.amazonaws.services.dynamodbv2.document.Item;
import com.amazonaws.services.dynamodbv2.document.ItemUtils;
import com.amazonaws.services.dynamodbv2.document.Table;
import com.amazonaws.services.dynamodbv2.document.TableKeysAndAttributes;
import com.amazonaws.services.dynamodbv2.document.spec.DeleteItemSpec;
Expand All @@ -28,7 +29,10 @@
import com.amazonaws.services.dynamodbv2.model.ExecuteStatementRequest;
import com.amazonaws.services.dynamodbv2.model.ExecuteTransactionRequest;
import com.amazonaws.services.dynamodbv2.model.ParameterizedStatement;
import com.amazonaws.services.dynamodbv2.model.Put;
import com.amazonaws.services.dynamodbv2.model.ReturnValue;
import com.amazonaws.services.dynamodbv2.model.TransactWriteItem;
import com.amazonaws.services.dynamodbv2.model.TransactWriteItemsRequest;
import com.here.xyz.XyzSerializable;
import com.here.xyz.hub.config.TagConfigClient;
import com.here.xyz.models.hub.Ref;
Expand Down Expand Up @@ -185,6 +189,21 @@ public Future<Void> storeTag(Marker marker, Tag tag) {
});
}

@Override
public Future<Void> storeSharedTags(Marker marker, List<Tag> sharedTags) {
return dynamoClient.executeQueryAsync(() -> {
List<TransactWriteItem> transactWriteItems = sharedTags.stream()
.map(tag -> new TransactWriteItem().withPut(new Put()
.withTableName(tagTable.getTableName())
.withItem(ItemUtils.fromSimpleMap(XyzSerializable.toMap(tag, Static.class)))))
.toList();

dynamoClient.client.transactWriteItems(new TransactWriteItemsRequest()
.withTransactItems(transactWriteItems));
return null;
});
}

@Override
public Future<Tag> deleteTag(Marker marker, String id, String spaceId) {
return dynamoClient.executeQueryAsync(() -> {
Expand Down Expand Up @@ -234,6 +253,7 @@ private static List<Tag> tagDataToTags(List<Map<String, AttributeValue>> items)
.withId(tagData.get("id").getS())
.withSpaceId(tagData.get("spaceId").getS())
.withVersion(version)
.withSharedVersion(tagData.get("sharedVersion") != null ? Long.parseLong(tagData.get("sharedVersion").getN()) : null)
.withVersionRef(Ref.fromBranchId(branchId, version))
.withSystem(tagData.get("system") != null ? tagData.get("system").getBOOL() : false)
.withDescription(tagData.get("description") != null ? tagData.get("description").getS() : "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ public Future<Void> storeTag(Marker marker, Tag tag) {
return client.write(query).mapEmpty();
}

@Override
public Future<Void> storeSharedTags(Marker marker, List<Tag> sharedTags) {
return Future.all(sharedTags.stream().map(tag -> storeTag(marker, tag)).toList()).mapEmpty();
}

@Override
public Future<Tag> deleteTag(Marker marker, String id, String spaceId) {
final SQLQuery query = client.getQuery("DELETE FROM ${schema}.${table} WHERE id = #{tagId} AND space = #{spaceId}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,14 @@ public static Future<Tag> createTag(Marker marker, String spaceId, String tagId,
return createTag(marker, spaceId, tagId, new Ref(HEAD), true, "", author, Core.currentTimeMillis());
}

// TODO auth
public static Future<Tag> createTag(Marker marker, String spaceId, String tagId, Ref versionRef, boolean system,
String description, String author, long createdAt) {
return createTag(marker, spaceId, tagId, versionRef, system, description, author, createdAt, false);
}

// TODO auth
public static Future<Tag> createTag(Marker marker, String spaceId, String tagId, Ref versionRef, boolean system,
String description, String author, long createdAt, boolean dryRun) {
if (spaceId == null) {
return Future.failedFuture(new ValidationException("Invalid parameter"));
}
Expand Down Expand Up @@ -186,7 +191,7 @@ public static Future<Tag> createTag(Marker marker, String spaceId, String tagId,
.withDescription(description)
.withAuthor(author)
.withCreatedAt(createdAt);
return Service.tagConfigClient.storeTag(marker, tag).map(v -> tag);
return dryRun ? Future.succeededFuture(tag) : Service.tagConfigClient.storeTag(marker, tag).map(v -> tag);
});
}

Expand Down
16 changes: 16 additions & 0 deletions xyz-models/src/main/java/com/here/xyz/models/hub/Tag.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ public class Tag implements XyzSerializable {
@JsonView({Public.class})
private Ref versionRef;

@JsonView(Static.class)
private Long sharedVersion;

/**
* The indicator that this tag is a system tag, which is not allowed to be deleted or modified by users.
*/
Expand Down Expand Up @@ -146,6 +149,19 @@ public Tag withVersionRef(Ref versionRef) {
return this;
}

public Long getSharedVersion() {
return sharedVersion;
}

public void setSharedVersion(Long sharedVersion) {
this.sharedVersion = sharedVersion;
}

public Tag withSharedVersion(Long sharedVersion) {
setSharedVersion(sharedVersion);
return this;
}

public boolean isSystem() {
return system;
}
Expand Down
Loading