com.braintreegateway.ModificationsRequest Maven / Gradle / Ivy
package com.braintreegateway;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class ModificationsRequest extends Request {
private SubscriptionRequest parent;
private String name;
private List adds;
private List updates;
private List removeModificationIds;
public ModificationsRequest(SubscriptionRequest parent, String name) {
this.name = name;
this.parent = parent;
this.adds = new ArrayList();
this.updates = new ArrayList();
this.removeModificationIds = new ArrayList();
}
public AddModificationRequest add() {
AddModificationRequest addModificationRequest = new AddModificationRequest(this);
adds.add(addModificationRequest);
return addModificationRequest;
}
public SubscriptionRequest done() {
return parent;
}
public ModificationsRequest remove(String... modificationIds) {
return remove(Arrays.asList(modificationIds));
}
public ModificationsRequest remove(List modificationIds) {
removeModificationIds.addAll(modificationIds);
return this;
}
public UpdateModificationRequest update() {
UpdateModificationRequest updateModificationRequest = new UpdateModificationRequest(this);
updates.add(updateModificationRequest);
return updateModificationRequest;
}
public UpdateModificationRequest update(String existingId) {
UpdateModificationRequest updateModificationRequest = new UpdateModificationRequest(this, existingId);
updates.add(updateModificationRequest);
return updateModificationRequest;
}
@Override
public String toXML() {
return buildRequest(name).toXML();
}
protected RequestBuilder buildRequest(String root) {
return new RequestBuilder(root)
.addElement("add", adds)
.addElement("remove", removeModificationIds)
.addElement("update", updates);
}
}