diff options
Diffstat (limited to 'openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/PermissionHandler.java')
-rw-r--r-- | openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/PermissionHandler.java | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/PermissionHandler.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/PermissionHandler.java new file mode 100644 index 0000000000..9b7b0f62e6 --- /dev/null +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/PermissionHandler.java @@ -0,0 +1,48 @@ +package org.openecomp.core.tools.store; + +import com.datastax.driver.core.ResultSet; +import com.datastax.driver.core.Row; +import com.datastax.driver.mapping.annotations.Accessor; +import com.datastax.driver.mapping.annotations.Query; +import org.openecomp.core.nosqldb.api.NoSqlDb; +import org.openecomp.core.nosqldb.factory.NoSqlDbFactory; + +import java.util.Objects; +import java.util.Optional; + +public class PermissionHandler { + + private static NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface(); + private static PermissionAccessor accessor = + noSqlDb.getMappingManager().createAccessor(PermissionAccessor.class); + + + public Optional<String> getItemUserPermission(String itemId, String user) { + ResultSet resultSet = accessor.getItemUserPermission(itemId, user); + Row row = resultSet.one(); + + if (Objects.nonNull(row)) { + return Optional.of(row.getString("permission")); + } else { + return Optional.empty(); + } + } + + public void setItemUserPermission(String itemId, String user, String permission) { + accessor.setItemUserPermission(itemId, user, permission); + } + + + @Accessor + interface PermissionAccessor { + + + @Query("INSERT into dox.item_permissions (item_id,user_id,permission) VALUES (?,?,?)") + void setItemUserPermission(String permission, String itemId, String userId); + + + @Query("SELECT permission FROM dox.item_permissions WHERE item_id=? AND user_id=?") + ResultSet getItemUserPermission(String itemId, String userId); + } + +}
\ No newline at end of file |