Skip to content

Commit

Permalink
Changed rights value from Short to Integer (#827)
Browse files Browse the repository at this point in the history
Signed-off-by: NOIR Nicolas ext <[email protected]>
  • Loading branch information
niconoir committed Oct 2, 2019
1 parent 8d8cde0 commit 84407fc
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,18 @@ public void serialize(DataOutput2 out, NodeInfo nodeInfo) throws IOException {
out.writeBoolean(e.getValue());
}
out.writeInt(nodeInfo.getAccessRights().getUsersRights().size());
for (Map.Entry<String, Short> e : nodeInfo.getAccessRights().getUsersRights().entrySet()) {
for (Map.Entry<String, Integer> e : nodeInfo.getAccessRights().getUsersRights().entrySet()) {
out.writeUTF(e.getKey());
out.writeShort(e.getValue());
out.writeInt(e.getValue());
}
out.writeInt(nodeInfo.getAccessRights().getGroupsRights().size());
for (Map.Entry<String, Short> e : nodeInfo.getAccessRights().getGroupsRights().entrySet()) {
for (Map.Entry<String, Integer> e : nodeInfo.getAccessRights().getGroupsRights().entrySet()) {
out.writeUTF(e.getKey());
out.writeShort(e.getValue());
out.writeInt(e.getValue());
}
out.writeInt(Objects.isNull(nodeInfo.getAccessRights().getOthersRights()) ? 0 : 1);
if (!Objects.isNull(nodeInfo.getAccessRights().getOthersRights())) {
out.writeShort(nodeInfo.getAccessRights().getOthersRights());
out.writeInt(nodeInfo.getAccessRights().getOthersRights());
}
}

Expand Down Expand Up @@ -99,15 +99,15 @@ public NodeInfo deserialize(DataInput2 input, int available) throws IOException
NodeAccessRights accessRights = new NodeAccessRights();
int usersRightsSize = input.readInt();
for (int i = 0; i < usersRightsSize; i++) {
accessRights.setUserRights(input.readUTF(), input.readShort());
accessRights.setUserRights(input.readUTF(), input.readInt());
}
int groupsRightsSize = input.readInt();
for (int i = 0; i < groupsRightsSize; i++) {
accessRights.setGroupRights(input.readUTF(), input.readShort());
accessRights.setGroupRights(input.readUTF(), input.readInt());
}
int othersRightsSize = input.readInt();
for (int i = 0; i < othersRightsSize; i++) {
accessRights.setOthersRights(input.readShort());
accessRights.setOthersRights(input.readInt());
}

return new NodeInfo(nodeId, name, pseudoClass, description, creationTime, modificationTime, version, metadata, accessRights);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,47 +12,47 @@

public class NodeAccessRights {

private final Map<String, Short> usersRights;
private final Map<String, Integer> usersRights;

private final Map<String, Short> groupsRights;
private final Map<String, Integer> groupsRights;

private Short othersRights;
private Integer othersRights;

public NodeAccessRights() {
this(new HashMap<>(), new HashMap<>(), null);
}

public NodeAccessRights(Map<String, Short> usersRights, Map<String, Short> groupsRights, Short othersRights) {
public NodeAccessRights(Map<String, Integer> usersRights, Map<String, Integer> groupsRights, Integer othersRights) {
this.usersRights = Objects.requireNonNull(usersRights);
this.groupsRights = Objects.requireNonNull(groupsRights);
this.othersRights = othersRights;
}

public Map<String, Short> getUsersRights() {
public Map<String, Integer> getUsersRights() {
return usersRights;
}

public NodeAccessRights setUserRights(String user, Short rights) {
public NodeAccessRights setUserRights(String user, Integer rights) {
Objects.requireNonNull(user);
usersRights.put(user, rights);
return this;
}

public Map<String, Short> getGroupsRights() {
public Map<String, Integer> getGroupsRights() {
return groupsRights;
}

public NodeAccessRights setGroupRights(String group, Short rights) {
public NodeAccessRights setGroupRights(String group, Integer rights) {
Objects.requireNonNull(group);
groupsRights.put(group, rights);
return this;
}

public Short getOthersRights() {
public Integer getOthersRights() {
return othersRights;
}

public NodeAccessRights setOthersRights(Short rights) {
public NodeAccessRights setOthersRights(Integer rights) {
othersRights = rights;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ private static void parseFieldName(JsonParser jsonParser, NodeAccessRightsJsonDe
jsonParser.nextToken();
switch (parsingContext.type) {
case NodeAccessRightsJsonSerializer.USER:
parsingContext.accessRights.setUserRights(parsingContext.name, (short) jsonParser.getValueAsInt());
parsingContext.accessRights.setUserRights(parsingContext.name, jsonParser.getValueAsInt());
break;
case NodeAccessRightsJsonSerializer.GROUP:
parsingContext.accessRights.setGroupRights(parsingContext.name, (short) jsonParser.getValueAsInt());
parsingContext.accessRights.setGroupRights(parsingContext.name, jsonParser.getValueAsInt());
break;
case NodeAccessRightsJsonSerializer.OTHERS:
parsingContext.accessRights.setOthersRights((short) jsonParser.getValueAsInt());
parsingContext.accessRights.setOthersRights(jsonParser.getValueAsInt());
break;
default:
throw new AssertionError("Unexpected access right type " + parsingContext.type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ public NodeAccessRightsJsonSerializer() {
@Override
public void serialize(NodeAccessRights nodeAccessRights, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
jsonGenerator.writeStartArray();
for (Map.Entry<String, Short> e : nodeAccessRights.getUsersRights().entrySet()) {
for (Map.Entry<String, Integer> e : nodeAccessRights.getUsersRights().entrySet()) {
jsonGenerator.writeStartObject();
jsonGenerator.writeStringField(TYPE, USER);
jsonGenerator.writeStringField(NAME, e.getKey());
jsonGenerator.writeNumberField(VALUE, e.getValue());
jsonGenerator.writeEndObject();
}
for (Map.Entry<String, Short> e : nodeAccessRights.getGroupsRights().entrySet()) {
for (Map.Entry<String, Integer> e : nodeAccessRights.getGroupsRights().entrySet()) {
jsonGenerator.writeStartObject();
jsonGenerator.writeStringField(TYPE, GROUP);
jsonGenerator.writeStringField(NAME, e.getKey());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void archive() throws IOException {

NodeInfo folder1Info = storage.createNode(rootFolderInfo.getId(), "folder1", AbstractAppStorageTest.FOLDER_PSEUDO_CLASS, "", 0, new NodeGenericMetadata(), new NodeAccessRights());
storage.setConsistent(folder1Info.getId());
NodeInfo file1Info = storage.createNode(folder1Info.getId(), "file1", AbstractAppStorageTest.DATA_FILE_CLASS, "", 0, new NodeGenericMetadata().setInt("i1", 1), new NodeAccessRights().setUserRights("user1", (short) 7));
NodeInfo file1Info = storage.createNode(folder1Info.getId(), "file1", AbstractAppStorageTest.DATA_FILE_CLASS, "", 0, new NodeGenericMetadata().setInt("i1", 1), new NodeAccessRights().setUserRights("user1", 7));
storage.setConsistent(file1Info.getId());

try (OutputStream os = storage.writeBinaryData(file1Info.getId(), "data1")) {
Expand All @@ -86,7 +86,7 @@ public void archive() throws IOException {
NodeInfo folder2Info = storage.createNode(rootFolderInfo.getId(), "folder2", AbstractAppStorageTest.FOLDER_PSEUDO_CLASS, "", 0, new NodeGenericMetadata(), new NodeAccessRights());
storage.setConsistent(folder2Info.getId());
NodeInfo file2Info = storage.createNode(folder2Info.getId(), "file2", AbstractAppStorageTest.DATA_FILE_CLASS, "", 0, new NodeGenericMetadata()
.setString("s1", "a"), new NodeAccessRights().setGroupRights("group1", (short) 5));
.setString("s1", "a"), new NodeAccessRights().setGroupRights("group1", 5));
storage.setConsistent(file2Info.getId());

storage.addDependency(file1Info.getId(), "dependency1", file2Info.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void test() throws IOException, InterruptedException {

// 2) create a test folder
NodeInfo testFolderInfo = storage.createNode(rootFolderInfo.getId(), "test", FOLDER_PSEUDO_CLASS, "", 0,
new NodeGenericMetadata().setString("k", "v"), new NodeAccessRights().setUserRights("user1", (short) 6));
new NodeGenericMetadata().setString("k", "v"), new NodeAccessRights().setUserRights("user1", 6));
storage.flush();

assertFalse(storage.isConsistent(testFolderInfo.getId()));
Expand Down Expand Up @@ -176,7 +176,7 @@ public void test() throws IOException, InterruptedException {
.setDouble("d1", 1d)
.setInt("i1", 2)
.setBoolean("b1", false),
new NodeAccessRights().setUserRights("user1", (short) 2).setUserRights("user2", (short) 4).setGroupRights("group1", (short) 6));
new NodeAccessRights().setUserRights("user1", 2).setUserRights("user2", 4).setGroupRights("group1", 6));
NodeInfo testData3Info = storage.createNode(testFolderInfo.getId(), "data3", DATA_FILE_CLASS, "", 0, new NodeGenericMetadata(), new NodeAccessRights());
storage.setConsistent(testDataInfo.getId());
storage.setConsistent(testData2Info.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void nodeInfoTest() throws IOException {
.setDouble("d1", 1d)
.setInt("i1", 2)
.setBoolean("b1", true),
new NodeAccessRights().setGroupRights("group1", (short) 2).setGroupRights("group2", (short) 4).setUserRights("user1", (short) 6));
new NodeAccessRights().setGroupRights("group1", 2).setGroupRights("group2", 4).setUserRights("user1", 6));
NodeInfo info2 = objectMapper.readValue(objectMapper.writeValueAsString(info), NodeInfo.class);
assertEquals(info, info2);
info.setVersion(1);
Expand Down

0 comments on commit 84407fc

Please sign in to comment.