copper-server-impl/src/main/java/com/pogeyan/cmis/impl/services/CmisPolicyService.java
/**
		 * removePolicy() method from cmis object.
		 */
removePolicy() method from cmis object.
removePolicy () method from cmis object .
public static void removePolicy(String repositoryId, String policyId, String objectId, IUserObject userObject,
				String typeId, String tracingId, ISpan parentSpan)
				throws CmisInvalidArgumentException, CmisObjectNotFoundException {
			ISpan span = TracingApiServiceFactory.getApiService().startSpan(tracingId, parentSpan,
					"CmisPolicyService::removePolicy", null);
			String[] principalIds = Helpers.getPrincipalIds(userObject);
			String systemAdmin = System.getenv("SYSTEM_ADMIN");
			boolean aclPropagation = Stream.of(userObject.getGroups())
					.anyMatch(a -> a.getGroupDN() != null && a.getGroupDN().equals(systemAdmin)) ? false : true;
			IBaseObject data = DBUtils.BaseDAO.getByObjectId(repositoryId, principalIds, aclPropagation, objectId, null, typeId);
			if (data == null) {
				LOG.error("Method name: {}, unknown object id: {}, repository: {}, TraceId: {}", "removePolicy",
						objectId, repositoryId, span != null ? span.getTraceId() : null);
				TracingApiServiceFactory.getApiService().updateSpan(span,
						TracingErrorMessage.message(
								TracingWriter.log(String.format(ErrorMessages.UNKNOWN_OBJECT, objectId), span),
								ErrorMessages.OBJECT_NOT_FOUND_EXCEPTION, repositoryId, true));
				TracingApiServiceFactory.getApiService().endSpan(tracingId, span, true);
				throw new CmisObjectNotFoundException(
						TracingWriter.log(String.format(ErrorMessages.UNKNOWN_OBJECT, objectId), span));
			}
			ITypePermissionService typePermissionFlow = TypeServiceFactory
					.createTypePermissionFlowService(repositoryId);
			boolean permission = CmisTypeServices.checkCrudPermission(typePermissionFlow, repositoryId, userObject,
					data.getTypeId(), EnumSet.of(PermissionType.READ, PermissionType.UPDATE), false);
			if (permission) {
				List<String> polIds = null;
				TokenImpl token = new TokenImpl(TokenChangeType.SECURITY, System.currentTimeMillis());
				polIds = data.getPolicies();
				if (null == polIds || !(polIds.contains(policyId))) {
					LOG.error(
							"Method name: {}, policyId: {}, cannot be removed because it is not applied to object: {}, repository: {}, TraceId: {}",
							"removePolicy", policyId, objectId, repositoryId, span != null ? span.getTraceId() : null);
					TracingApiServiceFactory.getApiService().updateSpan(span,
							TracingErrorMessage.message(
									TracingWriter.log(
											String.format(ErrorMessages.POLICY_NOT_APPLIED, policyId, objectId), span),
									ErrorMessages.INVALID_EXCEPTION, repositoryId, true));
					TracingApiServiceFactory.getApiService().endSpan(tracingId, span, true);
					throw new CmisInvalidArgumentException(TracingWriter
							.log(String.format(ErrorMessages.POLICY_NOT_APPLIED, policyId, objectId), span));
				}
				polIds.remove(policyId);
				DBUtils.BaseDAO.updatePolicy(repositoryId, polIds, objectId, token, typeId);
				if (polIds != null) {
					LOG.debug("PolicyObject after removing policyids are: {}", polIds);
				}
				TracingApiServiceFactory.getApiService().endSpan(tracingId, span, false);
			} else {
				LOG.error("read type permission denied for this user: {}, repository: {}, TraceId: {}",
						userObject.getUserDN(), repositoryId, span != null ? span.getTraceId() : null);
				TracingApiServiceFactory.getApiService().updateSpan(span,
						TracingErrorMessage.message(TracingWriter
								.log(String.format(ErrorMessages.READ_PERMISSION_DENIED, userObject.getUserDN()), span),
								ErrorMessages.ROLE_EXCEPTION, repositoryId, true));
				TracingApiServiceFactory.getApiService().endSpan(tracingId, span, true);
				throw new CmisRoleValidationException(TracingWriter
						.log(String.format(ErrorMessages.READ_PERMISSION_DENIED, userObject.getUserDN()), span));
			}
		}
public static void removePolicy ( String repositoryId , String policyId , String objectId , IUserObject userObject , String typeId , String tracingId , ISpan parentSpan ) throws CmisInvalidArgumentException , CmisObjectNotFoundException { ISpan span = TracingApiServiceFactory . getApiService ( ) . startSpan ( tracingId , parentSpan , "CmisPolicyService::removePolicy" , null ) ; String [ ] principalIds = Helpers . getPrincipalIds ( userObject ) ; String systemAdmin = System . getenv ( "SYSTEM_ADMIN" ) ; boolean aclPropagation = Stream . of ( userObject . getGroups ( ) ) . anyMatch ( a -> a . getGroupDN ( ) != null && a . getGroupDN ( ) . equals ( systemAdmin ) ) ? false : true ; IBaseObject data = DBUtils . BaseDAO . getByObjectId ( repositoryId , principalIds , aclPropagation , objectId , null , typeId ) ; if ( data == null ) { LOG . error ( "Method name: {}, unknown object id: {}, repository: {}, TraceId: {}" , "removePolicy" , objectId , repositoryId , span != null ? span . getTraceId ( ) : null ) ; TracingApiServiceFactory . getApiService ( ) . updateSpan ( span , TracingErrorMessage . message ( TracingWriter . log ( String . format ( ErrorMessages . UNKNOWN_OBJECT , objectId ) , span ) , ErrorMessages . OBJECT_NOT_FOUND_EXCEPTION , repositoryId , true ) ) ; TracingApiServiceFactory . getApiService ( ) . endSpan ( tracingId , span , true ) ; throw new CmisObjectNotFoundException ( TracingWriter . log ( String . format ( ErrorMessages . UNKNOWN_OBJECT , objectId ) , span ) ) ; } ITypePermissionService typePermissionFlow = TypeServiceFactory . createTypePermissionFlowService ( repositoryId ) ; boolean permission = CmisTypeServices . checkCrudPermission ( typePermissionFlow , repositoryId , userObject , data . getTypeId ( ) , EnumSet . of ( PermissionType . READ , PermissionType . UPDATE ) , false ) ; if ( permission ) { List < String > polIds = null ; TokenImpl token = new TokenImpl ( TokenChangeType . SECURITY , System . currentTimeMillis ( ) ) ; polIds = data . getPolicies ( ) ; if ( null == polIds || ! ( polIds . contains ( policyId ) ) ) { LOG . error ( "Method name: {}, policyId: {}, cannot be removed because it is not applied to object: {}, repository: {}, TraceId: {}" , "removePolicy" , policyId , objectId , repositoryId , span != null ? span . getTraceId ( ) : null ) ; TracingApiServiceFactory . getApiService ( ) . updateSpan ( span , TracingErrorMessage . message ( TracingWriter . log ( String . format ( ErrorMessages . POLICY_NOT_APPLIED , policyId , objectId ) , span ) , ErrorMessages . INVALID_EXCEPTION , repositoryId , true ) ) ; TracingApiServiceFactory . getApiService ( ) . endSpan ( tracingId , span , true ) ; throw new CmisInvalidArgumentException ( TracingWriter . log ( String . format ( ErrorMessages . POLICY_NOT_APPLIED , policyId , objectId ) , span ) ) ; } polIds . remove ( policyId ) ; DBUtils . BaseDAO . updatePolicy ( repositoryId , polIds , objectId , token , typeId ) ; if ( polIds != null ) { LOG . debug ( "PolicyObject after removing policyids are: {}" , polIds ) ; } TracingApiServiceFactory . getApiService ( ) . endSpan ( tracingId , span , false ) ; } else { LOG . error ( "read type permission denied for this user: {}, repository: {}, TraceId: {}" , userObject . getUserDN ( ) , repositoryId , span != null ? span . getTraceId ( ) : null ) ; TracingApiServiceFactory . getApiService ( ) . updateSpan ( span , TracingErrorMessage . message ( TracingWriter . log ( String . format ( ErrorMessages . READ_PERMISSION_DENIED , userObject . getUserDN ( ) ) , span ) , ErrorMessages . ROLE_EXCEPTION , repositoryId , true ) ) ; TracingApiServiceFactory . getApiService ( ) . endSpan ( tracingId , span , true ) ; throw new CmisRoleValidationException ( TracingWriter . log ( String . format ( ErrorMessages . READ_PERMISSION_DENIED , userObject . getUserDN ( ) ) , span ) ) ; } }
removePolicy() method from cmis object.
removePolicy () method from cmis object .