Skip to content

Commit

Permalink
Merge pull request #689 from MrCreosote/develop
Browse files Browse the repository at this point in the history
Convert ObjectInformation to a builder
  • Loading branch information
MrCreosote authored Oct 11, 2023
2 parents 8b3649a + 4519cf9 commit 756aef4
Show file tree
Hide file tree
Showing 18 changed files with 897 additions and 496 deletions.
400 changes: 220 additions & 180 deletions src/us/kbase/workspace/database/ObjectInformation.java

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions src/us/kbase/workspace/database/UncheckedUserMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ public class UncheckedUserMetadata {

private Map<String, String> metadata;

//TODO CODE empty constructor -> empty metadata

/** Create a new unchecked metadata container
* @param meta a map containing metadata. If null, an empty metadata map is
* created.
Expand Down
2 changes: 1 addition & 1 deletion src/us/kbase/workspace/database/Workspace.java
Original file line number Diff line number Diff line change
Expand Up @@ -1522,7 +1522,7 @@ public ObjectInformation copyObject(
for (final WorkspaceEventListener l: listeners) {
if (cr.isAllVersionsCopied()) {
l.copyObject(user, oi.getWorkspaceId(), oi.getObjectId(), oi.getVersion(),
oi.getSavedDate().toInstant(), wsinfo.isGloballyReadable());
oi.getSavedDate(), wsinfo.isGloballyReadable());
} else {
l.copyObject(oi, wsinfo.isGloballyReadable());
}
Expand Down
25 changes: 13 additions & 12 deletions src/us/kbase/workspace/database/mongo/MongoWorkspaceDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -1627,18 +1627,19 @@ private ObjectInformation saveObjectVersion(
version.put(Fields.VER_EXT_IDS, extractedIDsToStrings(pkg.wo.getExtractedIDs()));

saveObjectVersions(user, wsid, objectid, Arrays.asList(version), pkg.wo.isHidden());

return new ObjectInformation(
objectid,
pkg.name,
pkg.wo.getRep().getValidationTypeDefId().getTypeString(),
(Date) version.get(Fields.VER_SAVEDATE),
(Integer) version.get(Fields.VER_VER),
user,
wsid,
pkg.wo.getRep().getMD5().getMD5(),
pkg.wo.getRep().getRelabeledSize(),
new UncheckedUserMetadata(pkg.wo.getUserMeta()));

return ObjectInformation.getBuilder()
.withObjectID(objectid)
.withObjectName(pkg.name)
.withType(pkg.wo.getRep().getValidationTypeDefId())
.withSavedDate((Date) version.get(Fields.VER_SAVEDATE))
.withVersion((int) version.get(Fields.VER_VER))
.withSavedBy(user)
.withWorkspace(wsid)
.withChecksum(pkg.wo.getRep().getMD5())
.withSize(pkg.wo.getRep().getRelabeledSize())
.withUserMetadata(new UncheckedUserMetadata(pkg.wo.getUserMeta()))
.build();
}

private Map<String, Set<String>> extractedIDsToStrings(
Expand Down
29 changes: 16 additions & 13 deletions src/us/kbase/workspace/database/mongo/ObjectInfoUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import org.bson.Document;

import us.kbase.typedobj.core.TypeDefId;
import us.kbase.typedobj.core.AbsoluteTypeDefId;
import us.kbase.typedobj.core.TypeDefName;
import us.kbase.workspace.database.ObjectInformation;
import us.kbase.workspace.database.Permission;
Expand Down Expand Up @@ -129,25 +129,28 @@ static ObjectInformation generateObjectInfo(
final ResolvedWorkspaceID rwsi,
final long objid,
final String name,
// TODO CODE converting from Document to Map is stupid. Stop that
final Map<String, Object> ver) {
@SuppressWarnings("unchecked")
final List<Map<String, String>> meta =
(List<Map<String, String>>) ver.get(Fields.VER_META);
final TypeDefId type = new TypeDefId(
final AbsoluteTypeDefId type = new AbsoluteTypeDefId(
new TypeDefName((String) ver.get(Fields.VER_TYPE_NAME)),
(int) ver.get(Fields.VER_TYPE_MAJOR_VERSION),
(int) ver.get(Fields.VER_TYPE_MINOR_VERSION));
return new ObjectInformation(
objid,
name,
type.getTypeString(),
(Date) ver.get(Fields.VER_SAVEDATE),
(Integer) ver.get(Fields.VER_VER),
new WorkspaceUser((String) ver.get(Fields.VER_SAVEDBY)),
rwsi,
(String) ver.get(Fields.VER_CHKSUM),
(Long) ver.get(Fields.VER_SIZE),
meta == null ? null : new UncheckedUserMetadata(metaMongoArrayToHash(meta)));
return ObjectInformation.getBuilder()
.withObjectID(objid)
.withObjectName(name)
.withType(type)
.withSavedDate((Date) ver.get(Fields.VER_SAVEDATE))
.withVersion((int) ver.get(Fields.VER_VER))
.withSavedBy(new WorkspaceUser((String) ver.get(Fields.VER_SAVEDBY)))
.withWorkspace(rwsi)
.withChecksum((String) ver.get(Fields.VER_CHKSUM))
.withSize((long) ver.get(Fields.VER_SIZE))
.withUserMetadata(meta == null ? null :
new UncheckedUserMetadata(metaMongoArrayToHash(meta)))
.build();
}

// TODO CODE not clear if this is still necessary with Document vs DBObject
Expand Down
12 changes: 2 additions & 10 deletions src/us/kbase/workspace/kbase/ArgUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import java.time.temporal.TemporalAccessor;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -213,11 +212,6 @@ private static List<ExternalData> processExternalData(
return ret;
}

// TODO CODE remove this eventually when everything uses Instants
private static String formatDate(final Date date) {
return formatDate(date.toInstant());
}

private static String formatDate(final Instant date) {
return DATE_FORMATTER.format(date);
}
Expand Down Expand Up @@ -348,8 +342,7 @@ public static List<Tuple7<String, String, String, Long, String, String, Long>> w
.withE8(m.getWorkspaceName())
.withE9(m.getCheckSum())
.withE10(m.getSize())
.withE11(m.getUserMetaData() == null ? null :
m.getUserMetaData().getMetadata()));
.withE11(m.getUserMetaDataMapOrNull()));
}
}
return ret;
Expand Down Expand Up @@ -394,8 +387,7 @@ public static List<Tuple7<String, String, String, Long, String, String, Long>> w
.withE8(m.getWorkspaceName())
.withE9("")//ref is deprecated
.withE10(m.getCheckSum())
.withE11(m.getUserMetaData() == null ? null :
m.getUserMetaData().getMetadata())
.withE11(m.getUserMetaDataMapOrNull())
.withE12(m.getObjectId()));
}
return ret;
Expand Down
6 changes: 3 additions & 3 deletions src/us/kbase/workspace/modules/KafkaNotifierFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ public void renameObject(
public void revertObject(final ObjectInformation oi, final boolean isPublic) {
newEvent(oi.getSavedBy().getUser(), oi.getWorkspaceId(), oi.getObjectId(),
oi.getVersion(), oi.getTypeString(), NEW_VERSION,
oi.getSavedDate().toInstant());
oi.getSavedDate());

}

Expand Down Expand Up @@ -388,7 +388,7 @@ public void setObjectDeleted(
public void copyObject(final ObjectInformation oi, final boolean isPublic) {
newEvent(oi.getSavedBy().getUser(), oi.getWorkspaceId(), oi.getObjectId(),
oi.getVersion(), oi.getTypeString(), NEW_VERSION,
oi.getSavedDate().toInstant());
oi.getSavedDate());
}

@Override
Expand All @@ -406,7 +406,7 @@ public void copyObject(
public void saveObject(final ObjectInformation oi, final boolean isPublic) {
newEvent(oi.getSavedBy().getUser(), oi.getWorkspaceId(), oi.getObjectId(),
oi.getVersion(), oi.getTypeString(), NEW_VERSION,
oi.getSavedDate().toInstant());
oi.getSavedDate());
}

private void newEvent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import us.kbase.typedobj.core.MD5;
import us.kbase.typedobj.core.SubsetSelection;
import us.kbase.typedobj.core.TypeDefId;
import us.kbase.typedobj.core.TypeDefName;
import us.kbase.typedobj.exceptions.TypedObjectExtractionException;
import us.kbase.typedobj.test.DummyValidatedTypedObject;
import us.kbase.workspace.database.ByteArrayFileCacheManager;
Expand Down Expand Up @@ -416,29 +417,37 @@ public void addDataToObjectsNoop() throws Exception {

private List<WorkspaceObjectData.Builder> addDataToObjectsSetup() {
final Provenance p = basicProv(new WorkspaceUser("user1"));
final ObjectInformation oi1 = ObjectInformation.getBuilder()
.withObjectID(1)
.withObjectName("one")
.withType(new AbsoluteTypeDefId(new TypeDefName("a.b"), 1, 1))
.withSavedDate(Instant.now())
.withVersion(1)
.withSavedBy(new WorkspaceUser("u"))
.withWorkspace(new ResolvedWorkspaceID(1, "ws1", false, false))
.withChecksum("c6b87e665ecd549c082db04f0979f551")
.withSize(5)
.build();
final ObjectInformation oi2 = ObjectInformation.getBuilder()
.withObjectID(2)
.withObjectName("two")
.withType(new AbsoluteTypeDefId(new TypeDefName("a.b"), 1, 1))
.withSavedDate(Instant.now())
.withVersion(1)
.withSavedBy(new WorkspaceUser("u"))
.withWorkspace(new ResolvedWorkspaceID(1, "ws1", false, false))
.withChecksum("a06ab5aadd3e058c7236bd6b681eefc7")
.withSize(5)
.build();
final List<WorkspaceObjectData.Builder> objects = list(
WorkspaceObjectData.getBuilder(
new ObjectInformation(
1, "one", "type", new Date(), 1, new WorkspaceUser("u"),
new ResolvedWorkspaceID(1, "ws1", false, false),
"c6b87e665ecd549c082db04f0979f551", 5, null),
p),
WorkspaceObjectData.getBuilder(oi1, p),
// same object accessed in a different way, which can happen
WorkspaceObjectData.getBuilder(
new ObjectInformation(
1, "one", "type", new Date(), 1, new WorkspaceUser("u"),
new ResolvedWorkspaceID(1, "ws1", false, false),
"c6b87e665ecd549c082db04f0979f551", 5, null)
.updateReferencePath(list(
new Reference(2, 2, 2), new Reference(1, 1, 1))),
oi1.updateReferencePath(list(
new Reference(2, 2, 2), new Reference(1, 1, 1))),
p)
.withSubsetSelection(new SubsetSelection(list("/bar"))),
WorkspaceObjectData.getBuilder(
new ObjectInformation(
2, "two", "type", new Date(), 1, new WorkspaceUser("u"),
new ResolvedWorkspaceID(1, "ws1", false, false),
"a06ab5aadd3e058c7236bd6b681eefc7", 5, null),
p)
WorkspaceObjectData.getBuilder(oi2, p)
.withSubsetSelection(new SubsetSelection(list("/foo")))
);
return objects;
Expand Down Expand Up @@ -689,17 +698,17 @@ public void addDataToObjectsBackendScaling() throws Exception {
int counter = 1;
for (final ResolvedSaveObject o: objs) {
wods.add(WorkspaceObjectData.getBuilder(
new ObjectInformation(
counter,
"o" + counter,
"Mod.Meth-1.0",
new Date(),
1,
u,
ws,
o.getRep().getMD5().getMD5(),
o.getRep().getRelabeledSize(),
null),
ObjectInformation.getBuilder()
.withObjectID(counter)
.withObjectName("o" + counter)
.withType(new AbsoluteTypeDefId(new TypeDefName("Mod.Meth"), 1, 0))
.withSavedDate(Instant.now())
.withVersion(1)
.withSavedBy(u)
.withWorkspace(ws)
.withChecksum(o.getRep().getMD5())
.withSize(o.getRep().getRelabeledSize())
.build(),
basicProv(u))
.withSubsetSelection(new SubsetSelection(list("baz"))));
counter++;
Expand Down
15 changes: 12 additions & 3 deletions src/us/kbase/workspace/test/database/mongo/ObjectListerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.mongodb.client.MongoCursor;

import us.kbase.common.test.MapBuilder;
import us.kbase.typedobj.core.AbsoluteTypeDefId;
import us.kbase.typedobj.core.TypeDefId;
import us.kbase.typedobj.core.TypeDefName;
import us.kbase.workspace.database.AllUsers;
Expand Down Expand Up @@ -88,9 +89,17 @@ private static Map<String, Object> makeMapObject(final int id) {
}

private static ObjectInformation makeObjInfo(final int id) {
return new ObjectInformation(
id, "thing", TYPE_3_2, Date.from(inst(10000)), 7,
new WorkspaceUser("someguy"), WSID_1, SHTTY_MD5, 3L, null);
return ObjectInformation.getBuilder()
.withObjectID(id)
.withObjectName("thing")
.withType(AbsoluteTypeDefId.fromAbsoluteTypeString(TYPE_3_2))
.withSavedDate(inst(10000))
.withVersion(7)
.withSavedBy(new WorkspaceUser("someguy"))
.withWorkspace(WSID_1)
.withChecksum(SHTTY_MD5)
.withSize(3)
.build();
}

// start is inclusive, end is exclusive
Expand Down
18 changes: 14 additions & 4 deletions src/us/kbase/workspace/test/kbase/JSONRPCLayerTester.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import us.kbase.common.test.TestCommon;
import us.kbase.common.test.controllers.mongo.MongoController;
import us.kbase.test.auth2.authcontroller.AuthController;
import us.kbase.typedobj.core.AbsoluteTypeDefId;
import us.kbase.typedobj.core.TempFilesManager;
import us.kbase.workspace.AlterWorkspaceMetadataParams;
import us.kbase.workspace.ExternalDataUnit;
Expand Down Expand Up @@ -1554,10 +1555,19 @@ protected Set<ObjectInformation> tupleObjInfoToObjInfo(
throws Exception {
Set<ObjectInformation> s = new HashSet<>();
for (Tuple11<Long, String, String, String, Long, String, Long, String, String, Long, Map<String, String>> t: tpl) {
s.add(new ObjectInformation(t.getE1(), t.getE2(), t.getE3(), DATE_FORMAT.parse(t.getE4()),
t.getE5().intValue(), new WorkspaceUser(t.getE6()),
new ResolvedWorkspaceID(t.getE7(), t.getE8(), false, false), t.getE9(),
t.getE10(), new UncheckedUserMetadata(t.getE11())));
s.add(ObjectInformation.getBuilder()
.withObjectID(t.getE1())
.withObjectName(t.getE2())
.withType(AbsoluteTypeDefId.fromAbsoluteTypeString(t.getE3()))
.withSavedDate(DATE_FORMAT.parse(t.getE4()))
.withVersion(t.getE5().intValue())
.withSavedBy(new WorkspaceUser(t.getE6()))
.withWorkspace(new ResolvedWorkspaceID(t.getE7(), t.getE8(), false, false))
.withChecksum(t.getE9())
.withSize(t.getE10())
.withUserMetadata(new UncheckedUserMetadata(t.getE11()))
.build()
);
}
return s;
}
Expand Down
Loading

0 comments on commit 756aef4

Please sign in to comment.