@@ -299,16 +299,46 @@ public String getUuid(String resourceId, ResourceObjectType resourceType) {
299299 @ ActionEvent (eventType = EventTypes .EVENT_TAGS_DELETE , eventDescription = "deleting resource tags" )
300300 public boolean deleteTags (List <String > resourceIds , ResourceObjectType resourceType , Map <String , String > tags ) {
301301 Account caller = CallContext .current ().getCallingAccount ();
302+ List <String > uuids = new ArrayList <String >();
303+ List <String > internalIds = new ArrayList <String >();
304+ for (String resourceId : resourceIds ){
305+ if (resourceId .matches ("^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$" )){
306+ uuids .add (resourceId );
307+ }else {
308+ Long internalId = null ;
309+ try {
310+ internalId = Long .parseLong (resourceId );
311+ } catch (final NumberFormatException e ) {
312+ internalId = null ;
313+ }
314+ if (internalId != null ) {
315+ internalIds .add (resourceId );
316+ }else {
317+ throw new InvalidParameterValueException ("Invalid resourceId" );
318+ }
319+ }
320+ }
302321
303322 SearchBuilder <ResourceTagVO > sb = _resourceTagDao .createSearchBuilder ();
304- sb .and ().op ("resourceId" , sb .entity ().getResourceId (), SearchCriteria .Op .IN );
305- sb .or ("resourceUuid" , sb .entity ().getResourceUuid (), SearchCriteria .Op .IN );
306- sb .cp ();
323+
324+ if (!uuids .isEmpty () && !internalIds .isEmpty ()){
325+ throw new InvalidParameterValueException ("Expecting only uuids or Ids" );
326+ }else if (!uuids .isEmpty ()){
327+ sb .and ("resourceUuid" , sb .entity ().getResourceUuid (), SearchCriteria .Op .IN );
328+ }else if (!internalIds .isEmpty ()){
329+ sb .and ("resourceId" , sb .entity ().getResourceId (), SearchCriteria .Op .IN );
330+ }
331+
307332 sb .and ("resourceType" , sb .entity ().getResourceType (), SearchCriteria .Op .EQ );
308333
309334 SearchCriteria <ResourceTagVO > sc = sb .create ();
310- sc .setParameters ("resourceId" , resourceIds .toArray ());
311- sc .setParameters ("resourceUuid" , resourceIds .toArray ());
335+
336+ if (!uuids .isEmpty ()){
337+ sc .setParameters ("resourceUuid" , resourceIds .toArray ());
338+ }else if (!internalIds .isEmpty ()){
339+ sc .setParameters ("resourceId" , resourceIds .toArray ());
340+ }
341+
312342 sc .setParameters ("resourceType" , resourceType );
313343
314344 List <? extends ResourceTag > resourceTags = _resourceTagDao .search (sc , null );
0 commit comments