-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #189 from thecodeteam/feature-182-assign-tags-to-b…
…ucket Feature 182 assign tags to bucket
- Loading branch information
Showing
12 changed files
with
515 additions
and
19 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
src/main/java/com/emc/ecs/management/sdk/BucketTagsAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.emc.ecs.management.sdk; | ||
|
||
import com.emc.ecs.management.sdk.model.BucketTagsParam; | ||
import com.emc.ecs.management.sdk.model.BucketTagsParamAdd; | ||
import com.emc.ecs.management.sdk.model.BucketTagsParamDelete; | ||
import com.emc.ecs.management.sdk.model.BucketTagsParamUpdate; | ||
import com.emc.ecs.servicebroker.exception.EcsManagementClientException; | ||
|
||
import javax.ws.rs.core.UriBuilder; | ||
|
||
import static com.emc.ecs.management.sdk.Constants.*; | ||
|
||
public class BucketTagsAction { | ||
|
||
private BucketTagsAction(){} | ||
|
||
public static void create(Connection connection, String id, BucketTagsParamAdd tagsParam) | ||
throws EcsManagementClientException { | ||
UriBuilder uri = connection.getUriBuilder().segment(OBJECT, BUCKET, id, TAGS); | ||
connection.handleRemoteCall(POST, uri, tagsParam); | ||
} | ||
|
||
public static void update(Connection connection, String id, BucketTagsParamUpdate tagsParam) { | ||
UriBuilder uri = connection.getUriBuilder().segment(OBJECT, BUCKET, id, TAGS); | ||
connection.handleRemoteCall(PUT, uri, tagsParam); | ||
} | ||
public static void delete(Connection connection, String id, BucketTagsParamDelete tagsParam) { | ||
UriBuilder uri = connection.getUriBuilder().segment(OBJECT, BUCKET, id, TAGS); | ||
connection.handleRemoteCall(DELETE, uri, tagsParam); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/main/java/com/emc/ecs/management/sdk/model/BucketTag.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.emc.ecs.management.sdk.model; | ||
|
||
import javax.xml.bind.annotation.XmlAccessType; | ||
import javax.xml.bind.annotation.XmlAccessorType; | ||
import javax.xml.bind.annotation.XmlElement; | ||
import javax.xml.bind.annotation.XmlRootElement; | ||
|
||
@XmlRootElement(name = "Tag") | ||
@XmlAccessorType(XmlAccessType.FIELD) | ||
public class BucketTag { | ||
|
||
@XmlElement(name = "Key") | ||
private String key; | ||
|
||
@XmlElement(name = "Value") | ||
private String value; | ||
|
||
public BucketTag() { | ||
super(); | ||
} | ||
|
||
public BucketTag(String key, String value) { | ||
super(); | ||
this.key = key; | ||
this.value = value; | ||
} | ||
|
||
public String getKey() { | ||
return key; | ||
} | ||
|
||
public void setKey(String key) { | ||
this.key = key; | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
|
||
public void setValue(String value) { | ||
this.value = value; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return key + ':' + value; | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
src/main/java/com/emc/ecs/management/sdk/model/BucketTagSetRootElement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.emc.ecs.management.sdk.model; | ||
|
||
import javax.xml.bind.annotation.*; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@XmlRootElement | ||
public class BucketTagSetRootElement { | ||
|
||
private static final String KEY = "key"; | ||
private static final String VALUE = "value"; | ||
|
||
private List<BucketTag> tagSet; | ||
|
||
public BucketTagSetRootElement(){}; | ||
|
||
public BucketTagSetRootElement(List<Map<String, String>> tags) { | ||
super(); | ||
setTagSetAsListOfMaps(tags); | ||
} | ||
|
||
@XmlElementWrapper(name = "TagSet") | ||
@XmlElement(name = "Tag") | ||
public List<BucketTag> getTagSet() { | ||
return tagSet; | ||
} | ||
|
||
public void setTagSet(List<BucketTag> tagSet) { | ||
this.tagSet = tagSet; | ||
} | ||
|
||
public List<Map<String, String> > getTagSetAsListOfTags() { | ||
List<Map<String, String> > list = new ArrayList<Map<String, String> >(); | ||
for (BucketTag tag: tagSet) { | ||
Map<String, String> map = new HashMap<String, String>() {{ | ||
put(KEY, tag.getKey()); | ||
put(VALUE, tag.getValue()); | ||
}}; | ||
list.add(map); | ||
} | ||
return list; | ||
} | ||
|
||
public void setTagSetAsListOfMaps(List<Map<String, String> > tags) throws IllegalArgumentException { | ||
List<BucketTag> tagList = new ArrayList<BucketTag>(); | ||
for (Map<String, String> tag: tags) { | ||
try { | ||
String key = tag.get(KEY); | ||
String value = tag.get(VALUE); | ||
tagList.add(new BucketTag(key, value)); | ||
} catch (Exception e) { | ||
throw new IllegalArgumentException("Key and Value should be specified for bucket tag", e); | ||
} | ||
} | ||
tagSet = tagList; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuilder output = new StringBuilder("{"); | ||
for (BucketTag tag: tagSet) { | ||
output.append(tag.toString()).append(", "); | ||
} | ||
int length = output.length(); | ||
if (length != 1) | ||
output.delete(length - 2, length); | ||
output.append("}"); | ||
return output.toString(); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/com/emc/ecs/management/sdk/model/BucketTagsParam.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.emc.ecs.management.sdk.model; | ||
|
||
import javax.xml.bind.annotation.*; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@XmlRootElement | ||
@XmlAccessorType(XmlAccessType.FIELD) | ||
public class BucketTagsParam extends BucketTagSetRootElement{ | ||
|
||
private String namespace; | ||
|
||
public BucketTagsParam(){ | ||
super(); | ||
}; | ||
|
||
public BucketTagsParam(String namespace, List<Map<String, String> > tags) { | ||
super(tags); | ||
this.namespace = namespace; | ||
} | ||
|
||
public String getNamespace() { | ||
return namespace; | ||
} | ||
|
||
public void setNamespace(String namespace) { | ||
this.namespace = namespace; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/emc/ecs/management/sdk/model/BucketTagsParamAdd.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.emc.ecs.management.sdk.model; | ||
|
||
import javax.xml.bind.annotation.XmlRootElement; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@XmlRootElement(name = "add_bucket_tags") | ||
public class BucketTagsParamAdd extends BucketTagsParam { | ||
|
||
public BucketTagsParamAdd(){ | ||
super(); | ||
}; | ||
|
||
public BucketTagsParamAdd(String namespace, List<Map<String, String>> tags) { | ||
super(namespace, tags); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/emc/ecs/management/sdk/model/BucketTagsParamDelete.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.emc.ecs.management.sdk.model; | ||
|
||
import javax.xml.bind.annotation.XmlRootElement; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@XmlRootElement(name = "delete_bucket_tags") | ||
public class BucketTagsParamDelete extends BucketTagsParam { | ||
|
||
public BucketTagsParamDelete(){ | ||
super(); | ||
}; | ||
|
||
public BucketTagsParamDelete(String namespace, List<Map<String, String>> tags) { | ||
super(namespace, tags); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/emc/ecs/management/sdk/model/BucketTagsParamUpdate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.emc.ecs.management.sdk.model; | ||
|
||
import javax.xml.bind.annotation.XmlRootElement; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@XmlRootElement(name = "update_bucket_tags") | ||
public class BucketTagsParamUpdate extends BucketTagsParam { | ||
|
||
public BucketTagsParamUpdate(){ | ||
super(); | ||
}; | ||
|
||
public BucketTagsParamUpdate(String namespace, List<Map<String, String>> tags) { | ||
super(namespace, tags); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.