From d378c37fbd1ecec7b43394926f1ca32a695e07de Mon Sep 17 00:00:00 2001 From: vasraz Date: Mon, 22 Mar 2021 15:33:06 +0000 Subject: Reformat openecomp-be Signed-off-by: Vasyl Razinkov Issue-ID: SDC-3449 Change-Id: I13e02322f8e00820cc5a1d85752caaeda9bf10d1 --- .../dao/impl/ItemPermissionsDaoFactoryImpl.java | 1 - .../dao/impl/ItemPermissionsDaoImpl.java | 23 ++++--------- .../dao/impl/PermissionsServicesImpl.java | 40 +++++----------------- .../dao/impl/PrmissionsServicesFactoryImpl.java | 15 ++++---- .../dao/impl/UserPermissionsDaoFactoryImpl.java | 1 - .../dao/impl/UserPermissionsDaoImpl.java | 19 +++------- .../itempermissions/servlet/PermissionsFilter.java | 24 ++++--------- 7 files changed, 33 insertions(+), 90 deletions(-) (limited to 'openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src') diff --git a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/ItemPermissionsDaoFactoryImpl.java b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/ItemPermissionsDaoFactoryImpl.java index 6fd83c2233..89db18b30b 100644 --- a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/ItemPermissionsDaoFactoryImpl.java +++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/ItemPermissionsDaoFactoryImpl.java @@ -22,7 +22,6 @@ package org.openecomp.sdc.itempermissions.dao.impl; import org.openecomp.sdc.itempermissions.dao.ItemPermissionsDao; import org.openecomp.sdc.itempermissions.dao.ItemPermissionsDaoFactory; - /** * Created by ayalaben on 6/18/2017. */ diff --git a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/ItemPermissionsDaoImpl.java b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/ItemPermissionsDaoImpl.java index c9c4198081..34c4f39395 100644 --- a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/ItemPermissionsDaoImpl.java +++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/ItemPermissionsDaoImpl.java @@ -13,18 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.itempermissions.dao.impl; import com.datastax.driver.core.ResultSet; import com.datastax.driver.mapping.Result; import com.datastax.driver.mapping.annotations.Accessor; import com.datastax.driver.mapping.annotations.Query; - import java.util.Collection; import java.util.Optional; import java.util.Set; - import org.openecomp.core.nosqldb.api.NoSqlDb; import org.openecomp.core.nosqldb.factory.NoSqlDbFactory; import org.openecomp.sdc.itempermissions.dao.ItemPermissionsDao; @@ -36,8 +33,7 @@ import org.openecomp.sdc.itempermissions.type.ItemPermissionsEntity; public class ItemPermissionsDaoImpl implements ItemPermissionsDao { private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface(); - private static ItemPermissionsAccessor accessor = - noSqlDb.getMappingManager().createAccessor(ItemPermissionsAccessor.class); + private static ItemPermissionsAccessor accessor = noSqlDb.getMappingManager().createAccessor(ItemPermissionsAccessor.class); @Override public Collection listItemPermissions(String itemId) { @@ -45,22 +41,17 @@ public class ItemPermissionsDaoImpl implements ItemPermissionsDao { } @Override - public void updateItemPermissions(String itemId, String permission, Set addedUsersIds, - Set removedUsersIds) { + public void updateItemPermissions(String itemId, String permission, Set addedUsersIds, Set removedUsersIds) { addedUsersIds.forEach(userId -> accessor.addPermission(itemId, userId, permission)); - removedUsersIds.stream() - .filter(userId -> getUserItemPermission(itemId, userId) - .map(userPermissionOnItem -> userPermissionOnItem.equals(permission)) - .orElse(false)) - .forEach(userId -> accessor.deletePermission(itemId, userId)); + removedUsersIds.stream().filter( + userId -> getUserItemPermission(itemId, userId).map(userPermissionOnItem -> userPermissionOnItem.equals(permission)).orElse(false)) + .forEach(userId -> accessor.deletePermission(itemId, userId)); } @Override public Optional getUserItemPermission(String itemId, String userId) { ResultSet result = accessor.getUserItemPermission(itemId, userId); - return result.getAvailableWithoutFetching() < 1 - ? Optional.empty() - : Optional.of(result.one().getString(0)); + return result.getAvailableWithoutFetching() < 1 ? Optional.empty() : Optional.of(result.one().getString(0)); } @Override @@ -68,7 +59,6 @@ public class ItemPermissionsDaoImpl implements ItemPermissionsDao { accessor.deleteItemPermissions(itemId); } - @Accessor interface ItemPermissionsAccessor { @@ -86,6 +76,5 @@ public class ItemPermissionsDaoImpl implements ItemPermissionsDao { @Query("delete from dox.item_permissions where item_id=?") void deleteItemPermissions(String itemId); - } } diff --git a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/PermissionsServicesImpl.java b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/PermissionsServicesImpl.java index d0e41d8c91..7e9d289731 100644 --- a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/PermissionsServicesImpl.java +++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/PermissionsServicesImpl.java @@ -13,13 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.itempermissions.dao.impl; import java.util.Collection; import java.util.Optional; import java.util.Set; - import org.openecomp.sdc.common.session.SessionContextProviderFactory; import org.openecomp.sdc.itempermissions.PermissionsRules; import org.openecomp.sdc.itempermissions.PermissionsServices; @@ -27,29 +25,22 @@ import org.openecomp.sdc.itempermissions.dao.ItemPermissionsDao; import org.openecomp.sdc.itempermissions.dao.UserPermissionsDao; import org.openecomp.sdc.itempermissions.type.ItemPermissionsEntity; - /** * Created by ayalaben on 6/22/2017. */ public class PermissionsServicesImpl implements PermissionsServices { + private static final String CHANGE_PERMISSIONS = "Change_Item_Permissions"; private ItemPermissionsDao itemPermissionsDao; - private UserPermissionsDao userPermissionsDao; - private PermissionsRules permissionsRules; - private static final String CHANGE_PERMISSIONS = "Change_Item_Permissions"; - - public PermissionsServicesImpl(PermissionsRules permissionsRules, - ItemPermissionsDao itemPermissionsDao, - UserPermissionsDao userPermissionsDao) { + public PermissionsServicesImpl(PermissionsRules permissionsRules, ItemPermissionsDao itemPermissionsDao, UserPermissionsDao userPermissionsDao) { this.itemPermissionsDao = itemPermissionsDao; this.permissionsRules = permissionsRules; this.userPermissionsDao = userPermissionsDao; } - @Override public Collection listItemPermissions(String itemId) { return itemPermissionsDao.listItemPermissions(itemId); @@ -61,30 +52,18 @@ public class PermissionsServicesImpl implements PermissionsServices { } @Override - public void updateItemPermissions(String itemId, String permission, Set addedUsersIds, - Set removedUsersIds) { - - String currentUserId = SessionContextProviderFactory.getInstance() - .createInterface().get().getUser().getUserId(); - + public void updateItemPermissions(String itemId, String permission, Set addedUsersIds, Set removedUsersIds) { + String currentUserId = SessionContextProviderFactory.getInstance().createInterface().get().getUser().getUserId(); permissionsRules.executeAction(itemId, currentUserId, CHANGE_PERMISSIONS); - - permissionsRules.updatePermission(itemId, currentUserId, permission, addedUsersIds, - removedUsersIds); - - itemPermissionsDao.updateItemPermissions(itemId, permission, - addedUsersIds, removedUsersIds); - - userPermissionsDao.updatePermissions(itemId, permission, - addedUsersIds, removedUsersIds); - + permissionsRules.updatePermission(itemId, currentUserId, permission, addedUsersIds, removedUsersIds); + itemPermissionsDao.updateItemPermissions(itemId, permission, addedUsersIds, removedUsersIds); + userPermissionsDao.updatePermissions(itemId, permission, addedUsersIds, removedUsersIds); } @Override public boolean isAllowed(String itemId, String userId, String action) { - return itemPermissionsDao.getUserItemPermission(itemId, userId) - .map(permission -> permissionsRules.isAllowed(permission, action)) - .orElse(false); + return itemPermissionsDao.getUserItemPermission(itemId, userId).map(permission -> permissionsRules.isAllowed(permission, action)) + .orElse(false); } @Override @@ -101,5 +80,4 @@ public class PermissionsServicesImpl implements PermissionsServices { public void deleteItemPermissions(String itemId) { itemPermissionsDao.deleteItemPermissions(itemId); } - } diff --git a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/PrmissionsServicesFactoryImpl.java b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/PrmissionsServicesFactoryImpl.java index d009f62270..b86d10ceb1 100644 --- a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/PrmissionsServicesFactoryImpl.java +++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/PrmissionsServicesFactoryImpl.java @@ -24,14 +24,13 @@ import org.openecomp.sdc.itempermissions.dao.UserPermissionsDaoFactory; /** * Created by ayalaben on 6/22/2017 */ -public class PrmissionsServicesFactoryImpl extends PermissionsServicesFactory { +public class PrmissionsServicesFactoryImpl extends PermissionsServicesFactory { - private static final PermissionsServices INSTANCE = - new PermissionsServicesImpl(PermissionsRulesFactory.getInstance().createInterface(), - ItemPermissionsDaoFactory.getInstance().createInterface(), UserPermissionsDaoFactory.getInstance().createInterface()); + private static final PermissionsServices INSTANCE = new PermissionsServicesImpl(PermissionsRulesFactory.getInstance().createInterface(), + ItemPermissionsDaoFactory.getInstance().createInterface(), UserPermissionsDaoFactory.getInstance().createInterface()); - @Override - public PermissionsServices createInterface() { - return INSTANCE; - } + @Override + public PermissionsServices createInterface() { + return INSTANCE; + } } diff --git a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/UserPermissionsDaoFactoryImpl.java b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/UserPermissionsDaoFactoryImpl.java index 4c23743ea5..d60013db77 100644 --- a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/UserPermissionsDaoFactoryImpl.java +++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/UserPermissionsDaoFactoryImpl.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.itempermissions.dao.impl; import org.openecomp.sdc.itempermissions.dao.UserPermissionsDao; diff --git a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/UserPermissionsDaoImpl.java b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/UserPermissionsDaoImpl.java index 8609f2f4a8..25645ab483 100644 --- a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/UserPermissionsDaoImpl.java +++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/UserPermissionsDaoImpl.java @@ -13,17 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.itempermissions.dao.impl; import com.datastax.driver.core.ResultSet; import com.datastax.driver.mapping.annotations.Accessor; import com.datastax.driver.mapping.annotations.Query; - import java.util.Collections; import java.util.HashSet; import java.util.Set; - import org.openecomp.core.nosqldb.api.NoSqlDb; import org.openecomp.core.nosqldb.factory.NoSqlDbFactory; import org.openecomp.sdc.itempermissions.dao.UserPermissionsDao; @@ -31,9 +28,7 @@ import org.openecomp.sdc.itempermissions.dao.UserPermissionsDao; public class UserPermissionsDaoImpl implements UserPermissionsDao { private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface(); - private static UserPermissionsAccessor accessor = - noSqlDb.getMappingManager().createAccessor(UserPermissionsAccessor.class); - + private static UserPermissionsAccessor accessor = noSqlDb.getMappingManager().createAccessor(UserPermissionsAccessor.class); @Override public Set listUserPermittedItems(String userId, String permission) { @@ -46,14 +41,10 @@ public class UserPermissionsDaoImpl implements UserPermissionsDao { } @Override - public void updatePermissions(String itemId, String permission, Set addedUsersIds, - Set removedUsersIds) { + public void updatePermissions(String itemId, String permission, Set addedUsersIds, Set removedUsersIds) { Set itemSet = Collections.singleton(itemId); - - addedUsersIds.forEach(userId -> - accessor.addItem(itemSet, userId, permission)); - removedUsersIds.forEach(userId -> - accessor.removeItem(itemSet, userId, permission)); + addedUsersIds.forEach(userId -> accessor.addItem(itemSet, userId, permission)); + removedUsersIds.forEach(userId -> accessor.removeItem(itemSet, userId, permission)); } @Accessor @@ -67,7 +58,5 @@ public class UserPermissionsDaoImpl implements UserPermissionsDao { @Query("update dox.user_permission_items set item_list=item_list-? WHERE user_id = ? AND permission = ?") void removeItem(Set items, String userId, String permission); - } - } diff --git a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/servlet/PermissionsFilter.java b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/servlet/PermissionsFilter.java index 1edfad3bbc..66b999951e 100644 --- a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/servlet/PermissionsFilter.java +++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/servlet/PermissionsFilter.java @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.itempermissions.servlet; +import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; import javax.servlet.Filter; import javax.servlet.FilterChain; @@ -27,8 +27,6 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.ws.rs.HttpMethod; import javax.ws.rs.core.Response; - -import com.fasterxml.jackson.databind.ObjectMapper; import org.openecomp.sdc.common.errors.ErrorCode; import org.openecomp.sdc.common.errors.ErrorCodeAndMessage; import org.openecomp.sdc.common.errors.Messages; @@ -43,9 +41,9 @@ import org.openecomp.sdc.logging.api.LoggerFactory; public class PermissionsFilter implements Filter { private static final Logger LOGGER = LoggerFactory.getLogger(PermissionsFilter.class); - private final PermissionsServices permissionsServices; private static final String IRRELEVANT_REQUEST = "Irrelevant_Request"; private static final String EDIT_ITEM = "Edit_Item"; + private final PermissionsServices permissionsServices; public PermissionsFilter() { this(PermissionsServicesFactory.getInstance().createInterface()); @@ -62,10 +60,8 @@ public class PermissionsFilter implements Filter { @Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) - throws IOException, ServletException { - - if ((servletRequest instanceof HttpServletRequest) - && isRelevant((HttpServletRequest) servletRequest, servletResponse)) { + throws IOException, ServletException { + if ((servletRequest instanceof HttpServletRequest) && isRelevant((HttpServletRequest) servletRequest, servletResponse)) { filterChain.doFilter(servletRequest, servletResponse); } } @@ -73,19 +69,15 @@ public class PermissionsFilter implements Filter { private boolean isRelevant(HttpServletRequest servletRequest, ServletResponse servletResponse) throws IOException { String method = servletRequest.getMethod(); if (method.equals(HttpMethod.POST) || method.equals(HttpMethod.PUT) || method.equals(HttpMethod.DELETE)) { - String userId = servletRequest.getHeader("USER_ID"); String itemId = parseItemIdFromPath(servletRequest.getPathInfo()); - if (!itemId.equals(IRRELEVANT_REQUEST) && !permissionsServices.isAllowed(itemId, userId, EDIT_ITEM)) { ((HttpServletResponse) servletResponse).setStatus(HttpServletResponse.SC_FORBIDDEN); - servletResponse.getWriter().print(buildResponse(Response.Status.FORBIDDEN, - Messages.PERMISSIONS_ERROR.getErrorMessage(), - Messages.PERMISSIONS_ERROR.name())); + servletResponse.getWriter() + .print(buildResponse(Response.Status.FORBIDDEN, Messages.PERMISSIONS_ERROR.getErrorMessage(), Messages.PERMISSIONS_ERROR.name())); return false; } } - return true; } @@ -104,9 +96,7 @@ public class PermissionsFilter implements Filter { } private String buildResponse(Response.Status status, String message, String id) { - ErrorCode errorCode = new ErrorCode.ErrorCodeBuilder() - .withId(id) - .withMessage(message).build(); + ErrorCode errorCode = new ErrorCode.ErrorCodeBuilder().withId(id).withMessage(message).build(); return objectToJsonString(new ErrorCodeAndMessage(status, errorCode)); } -- cgit 1.2.3-korg