Add store order + item id for Ariel

This commit is contained in:
Colin McDonald 2016-07-09 17:21:24 -04:00
parent f999319666
commit 97b296a79d
4 changed files with 32 additions and 13 deletions

View File

@ -54,7 +54,9 @@ public final class GrantConverter implements Block<Document> {
grant.containsKey("created") ? grant.getDate("created").toInstant() : Instant.now(), grant.containsKey("created") ? grant.getDate("created").toInstant() : Instant.now(),
null, null,
null, null,
null null,
-1,
-1
); );
BlockingCallback<Void> callback = new BlockingCallback<>(); BlockingCallback<Void> callback = new BlockingCallback<>();

View File

@ -9,6 +9,7 @@ import fr.javatic.mongo.jacksonCodec.objectId.Id;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import net.frozenorb.apiv3.APIv3; import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.util.SyncUtils;
import org.bson.Document; import org.bson.Document;
import org.bson.types.ObjectId; import org.bson.types.ObjectId;
@ -36,21 +37,24 @@ public final class Grant {
@Getter private Instant removedAt; @Getter private Instant removedAt;
@Getter private String removalReason; @Getter private String removalReason;
@Getter private int storeItemId;
@Getter private int storeOrderId;
public static void findAll(SingleResultCallback<List<Grant>> callback) { public static void findAll(SingleResultCallback<List<Grant>> callback) {
grantsCollection.find().sort(new Document("addedAt", -1)).into(new LinkedList<>(), callback); grantsCollection.find().sort(new Document("addedAt", -1)).into(new LinkedList<>(), SyncUtils.vertxWrap(callback));
} }
public static void findByRank(Collection<Rank> ranks, SingleResultCallback<List<Grant>> callback) { public static void findByRank(Collection<Rank> ranks, SingleResultCallback<List<Grant>> callback) {
Collection<String> convertedRanks = ranks.stream().map(Rank::getId).collect(Collectors.toList()); Collection<String> convertedRanks = ranks.stream().map(Rank::getId).collect(Collectors.toList());
grantsCollection.find(new Document("rank", new Document("$in", convertedRanks))).into(new LinkedList<>(), callback); grantsCollection.find(new Document("rank", new Document("$in", convertedRanks))).into(new LinkedList<>(), SyncUtils.vertxWrap(callback));
} }
public static void findPaginated(Document query, int skip, int pageSize, SingleResultCallback<List<Grant>> callback) { public static void findPaginated(Document query, int skip, int pageSize, SingleResultCallback<List<Grant>> callback) {
grantsCollection.find(query).sort(new Document("addedAt", -1)).skip(skip).limit(pageSize).into(new LinkedList<>(), callback); grantsCollection.find(query).sort(new Document("addedAt", -1)).skip(skip).limit(pageSize).into(new LinkedList<>(), SyncUtils.vertxWrap(callback));
} }
public static void findById(String id, SingleResultCallback<Grant> callback) { public static void findById(String id, SingleResultCallback<Grant> callback) {
grantsCollection.find(new Document("_id", id)).first(callback); grantsCollection.find(new Document("_id", id)).first(SyncUtils.vertxWrap(callback));
} }
public static void findByUser(User user, SingleResultCallback<List<Grant>> callback) { public static void findByUser(User user, SingleResultCallback<List<Grant>> callback) {
@ -58,11 +62,11 @@ public final class Grant {
} }
public static void findByUser(UUID user, SingleResultCallback<List<Grant>> callback) { public static void findByUser(UUID user, SingleResultCallback<List<Grant>> callback) {
grantsCollection.find(new Document("user", user)).into(new LinkedList<>(), callback); grantsCollection.find(new Document("user", user)).into(new LinkedList<>(), SyncUtils.vertxWrap(callback));
} }
public static void findByUserGrouped(Iterable<UUID> users, SingleResultCallback<Map<UUID, List<Grant>>> callback) { public static void findByUserGrouped(Iterable<UUID> users, SingleResultCallback<Map<UUID, List<Grant>>> callback) {
grantsCollection.find(new Document("user", new Document("$in", users))).into(new LinkedList<>(), (grants, error) -> { grantsCollection.find(new Document("user", new Document("$in", users))).into(new LinkedList<>(), SyncUtils.vertxWrap((grants, error) -> {
if (error != null) { if (error != null) {
callback.onResult(null, error); callback.onResult(null, error);
} else { } else {
@ -78,12 +82,16 @@ public final class Grant {
callback.onResult(result, null); callback.onResult(result, null);
} }
}); }));
} }
private Grant() {} // For Jackson private Grant() {} // For Jackson
public Grant(User user, String reason, Set<ServerGroup> scopes, Rank rank, Instant expiresAt, User addedBy) { public Grant(User user, String reason, Set<ServerGroup> scopes, Rank rank, Instant expiresAt, User addedBy) {
this(user, reason, scopes, rank, expiresAt, addedBy, -1, -1);
}
public Grant(User user, String reason, Set<ServerGroup> scopes, Rank rank, Instant expiresAt, User addedBy, int storeItemId, int storeOrderId) {
this.id = new ObjectId().toString(); this.id = new ObjectId().toString();
this.user = user.getId(); this.user = user.getId();
this.reason = reason; this.reason = reason;
@ -92,6 +100,8 @@ public final class Grant {
this.expiresAt = expiresAt; this.expiresAt = expiresAt;
this.addedBy = addedBy == null ? null : addedBy.getId(); this.addedBy = addedBy == null ? null : addedBy.getId();
this.addedAt = Instant.now(); this.addedAt = Instant.now();
this.storeItemId = storeItemId;
this.storeOrderId = storeOrderId;
} }
public boolean isActive() { public boolean isActive() {
@ -115,7 +125,7 @@ public final class Grant {
} }
public void insert(SingleResultCallback<Void> callback) { public void insert(SingleResultCallback<Void> callback) {
grantsCollection.insertOne(this, callback); grantsCollection.insertOne(this, SyncUtils.vertxWrap(callback));
} }
public void delete(User removedBy, String reason, SingleResultCallback<UpdateResult> callback) { public void delete(User removedBy, String reason, SingleResultCallback<UpdateResult> callback) {
@ -123,7 +133,7 @@ public final class Grant {
this.removedAt = Instant.now(); this.removedAt = Instant.now();
this.removalReason = reason; this.removalReason = reason;
grantsCollection.replaceOne(new Document("_id", id), this, callback); grantsCollection.replaceOne(new Document("_id", id), this, SyncUtils.vertxWrap(callback));
} }
} }

View File

@ -7,6 +7,8 @@ import net.frozenorb.apiv3.model.Grant;
import net.frozenorb.apiv3.util.ErrorUtils; import net.frozenorb.apiv3.util.ErrorUtils;
import org.bson.Document; import org.bson.Document;
import java.util.stream.Collectors;
public final class GETGrants implements Handler<RoutingContext> { public final class GETGrants implements Handler<RoutingContext> {
public void handle(RoutingContext ctx) { public void handle(RoutingContext ctx) {
@ -15,8 +17,9 @@ public final class GETGrants implements Handler<RoutingContext> {
int pageSize = ctx.request().getParam("pageSize") == null ? 100 : Integer.parseInt(ctx.request().getParam("pageSize")); int pageSize = ctx.request().getParam("pageSize") == null ? 100 : Integer.parseInt(ctx.request().getParam("pageSize"));
Grant.findPaginated(ctx.request().getParam("user") == null ? new Document() : new Document("user", ctx.request().getParam("user")), skip, pageSize, (grants, error) -> { Grant.findPaginated(ctx.request().getParam("user") == null ? new Document() : new Document("user", ctx.request().getParam("user")), skip, pageSize, (grants, error) -> {
if (error != null) { if (ctx.request().getParam("active") != null) {
ErrorUtils.respondInternalError(ctx, error); boolean requireActive = Boolean.parseBoolean(ctx.request().getParam("active"));
APIv3.respondJson(ctx, 200, grants.stream().filter(grant -> grant.isActive() == requireActive).collect(Collectors.toList()));
} else { } else {
APIv3.respondJson(ctx, 200, grants); APIv3.respondJson(ctx, 200, grants);
} }

View File

@ -4,6 +4,7 @@ import com.google.common.collect.ImmutableMap;
import io.vertx.core.Handler; import io.vertx.core.Handler;
import io.vertx.core.json.JsonObject; import io.vertx.core.json.JsonObject;
import io.vertx.ext.web.RoutingContext; import io.vertx.ext.web.RoutingContext;
import lombok.extern.slf4j.Slf4j;
import net.frozenorb.apiv3.APIv3; import net.frozenorb.apiv3.APIv3;
import net.frozenorb.apiv3.auditLog.AuditLog; import net.frozenorb.apiv3.auditLog.AuditLog;
import net.frozenorb.apiv3.auditLog.AuditLogActionType; import net.frozenorb.apiv3.auditLog.AuditLogActionType;
@ -91,7 +92,10 @@ public final class POSTGrants implements Handler<RoutingContext> {
} }
} }
Grant grant = new Grant(target, reason, scopes, rank, expiresAt, addedBy); int storeItemId = requestBody.getInteger("storeItemId", -1);
int storeOrderId = requestBody.getInteger("storeOrderId", -1);
Grant grant = new Grant(target, reason, scopes, rank, expiresAt, addedBy, storeItemId, storeOrderId);
BlockingCallback<Void> callback = new BlockingCallback<>(); BlockingCallback<Void> callback = new BlockingCallback<>();
grant.insert(callback); grant.insert(callback);
callback.get(); callback.get();