@@ -5183,62 +5183,6 @@ private void updateDomainAttribute(AtlasVertex vertex, Set<String> existingValue
5183
5183
existingValues .forEach (existingValue -> vertex .removePropertyValue (DOMAIN_GUIDS_ATTR , existingValue ));
5184
5184
vertex .setProperty (DOMAIN_GUIDS_ATTR , meshEntityId );
5185
5185
}
5186
- public AtlasVertex moveBusinessPolicies (Set <String > policyIds , String assetId , String type ) throws AtlasBaseException {
5187
- // Retrieve the AtlasVertex for the given assetId
5188
- AtlasVertex assetVertex = AtlasGraphUtilsV2 .findByGuid (graph , assetId );
5189
-
5190
- if (assetVertex == null ) {
5191
- throw new AtlasBaseException (AtlasErrorCode .INVALID_PARAMETERS , "Asset with guid not found" );
5192
- }
5193
-
5194
- // Get the sets of governed and non-compliant policy GUIDs
5195
- Set <String > governedPolicies = assetVertex .getMultiValuedSetProperty (ASSET_POLICY_GUIDS , String .class );
5196
- Set <String > nonCompliantPolicies = assetVertex .getMultiValuedSetProperty (NON_COMPLIANT_ASSET_POLICY_GUIDS , String .class );
5197
-
5198
- // Determine if the type is governed or non-compliant
5199
- boolean isGoverned = MoveBusinessPolicyRequest .Type .GOVERNED .getDescription ().equals (type );
5200
- Set <String > currentPolicies = isGoverned ? new HashSet <>(governedPolicies ) : new HashSet <>(nonCompliantPolicies );
5201
- policyIds .removeAll (currentPolicies );
5202
-
5203
- // Check if the asset already has the given policy IDs
5204
- if (policyIds .isEmpty ()) {
5205
- return assetVertex ;
5206
- }
5207
-
5208
- // Move policies to the appropriate set
5209
- policyIds .forEach (policyId -> {
5210
- if (isGoverned ) {
5211
- assetVertex .setProperty (ASSET_POLICY_GUIDS , policyId );
5212
- removeItemFromListPropertyValue (assetVertex , NON_COMPLIANT_ASSET_POLICY_GUIDS , policyId );
5213
- } else {
5214
- assetVertex .setProperty (NON_COMPLIANT_ASSET_POLICY_GUIDS , policyId );
5215
- removeItemFromListPropertyValue (assetVertex , ASSET_POLICY_GUIDS , policyId );
5216
- }
5217
- });
5218
-
5219
- // Update the sets after processing
5220
- if (isGoverned ) {
5221
- governedPolicies .addAll (policyIds );
5222
- nonCompliantPolicies .removeAll (policyIds );
5223
- } else {
5224
- nonCompliantPolicies .addAll (policyIds );
5225
- governedPolicies .removeAll (policyIds );
5226
- }
5227
-
5228
- // Update the modification metadata
5229
- updateModificationMetadata (assetVertex );
5230
-
5231
- // Create a differential AtlasEntity to reflect the changes
5232
- AtlasEntity diffEntity = new AtlasEntity (assetVertex .getProperty (TYPE_NAME_PROPERTY_KEY , String .class ));
5233
- setEntityCommonAttributes (assetVertex , diffEntity );
5234
- diffEntity .setAttribute (ASSET_POLICY_GUIDS , governedPolicies );
5235
- diffEntity .setAttribute (NON_COMPLIANT_ASSET_POLICY_GUIDS , nonCompliantPolicies );
5236
-
5237
- // Cache the differential entity for further processing
5238
- RequestContext .get ().cacheDifferentialEntity (diffEntity );
5239
-
5240
- return assetVertex ;
5241
- }
5242
5186
5243
5187
private void cacheDifferentialEntity (AtlasVertex ev , Set <String > complaint , Set <String > nonComplaint ) {
5244
5188
AtlasEntity diffEntity = new AtlasEntity (ev .getProperty (TYPE_NAME_PROPERTY_KEY , String .class ));
@@ -5277,4 +5221,40 @@ private void isAuthorizedToLink(AtlasVertex vertex) throws AtlasBaseException {
5277
5221
"read on source Entity, link/unlink operation denied: " , sourceEntity .getAttribute (NAME ));
5278
5222
5279
5223
}
5224
+
5225
+ public List <AtlasVertex > unlinkBusinessPolicyV2 (Set <String > assetGuids , Set <String > unlinkGuids ) {
5226
+
5227
+ if (CollectionUtils .isEmpty (assetGuids ) || CollectionUtils .isEmpty (unlinkGuids )) {
5228
+ throw new IllegalArgumentException ("assets and unlinkGuids must not be empty" );
5229
+ }
5230
+
5231
+ return assetGuids .stream ()
5232
+ .map (guid -> AtlasGraphUtilsV2 .findByGuid (graph , guid ))
5233
+ .filter (Objects ::nonNull )
5234
+ .map (vertex -> updateVertexPolicyV2 (vertex , unlinkGuids ))
5235
+ .collect (Collectors .toList ());
5236
+ }
5237
+
5238
+
5239
+ private AtlasVertex updateVertexPolicyV2 (AtlasVertex vertex , Set <String > policyIds ) {
5240
+ Set <String > compliantPolicies = getMultiValuedSetProperty (vertex , ASSET_POLICY_GUIDS );
5241
+ Set <String > nonCompliantPolicies = getMultiValuedSetProperty (vertex , NON_COMPLIANT_ASSET_POLICY_GUIDS );
5242
+ policyIds .forEach (policyId -> {
5243
+ vertex .removePropertyValue (ASSET_POLICY_GUIDS , policyId );
5244
+ vertex .removePropertyValue (NON_COMPLIANT_ASSET_POLICY_GUIDS , policyId );
5245
+ });
5246
+
5247
+ int compliantPolicyCount = countPoliciesExcluding (compliantPolicies , "rule" );
5248
+ int nonCompliantPolicyCount = countPoliciesExcluding (nonCompliantPolicies , "rule" );
5249
+ int totalPolicyCount = compliantPolicyCount + nonCompliantPolicyCount ;
5250
+ vertex .setProperty (ASSET_POLICIES_COUNT , totalPolicyCount );
5251
+
5252
+ updateModificationMetadata (vertex );
5253
+ cacheDifferentialEntity (vertex , compliantPolicies , nonCompliantPolicies );
5254
+
5255
+ return vertex ;
5256
+ }
5257
+
5258
+
5259
+
5280
5260
}
0 commit comments