Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowing clients to pass an empty list of children to assign #5

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions src/main/java/net/nuagenetworks/bambou/RestObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,20 @@ public void instantiateChild(RestObject childRestObj, RestObject fromTemplate, I
}

@Override
public void assign(List<? extends RestObject> childRestObjs) throws RestException {
public void assign(List<? extends RestObject> childRestObjs, Class<? extends RestObject> objectType) throws RestException {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For API backwards compatibility, the following method signature should still be supported:

public void assign(List<? extends RestObject> childRestObjs) throws RestException

RestSession<?> session = RestSession.getCurrentSession();
if (session != null) {
session.assign(this, childRestObjs);
session.assign(this, childRestObjs, objectType);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

} else {
throw new RestException("Session not available in current thread");
}
}

@Override
public void assign(List<? extends RestObject> childRestObjs) throws RestException {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

assign(childRestObjs, null);
}

@Override
public void assign(List<? extends RestObject> childRestObjs, boolean commit) throws RestException {
RestSession<?> session = RestSession.getCurrentSession();
Expand Down Expand Up @@ -334,18 +339,29 @@ public void assign(RestSession<?> session, List<? extends RestObject> childRestO

@Override
public void assign(RestSession<?> session, List<? extends RestObject> childRestObjs, boolean commit) throws RestException {
assign(session, childRestObjs, null, commit);
}

@Override
public void assign(RestSession<?> session, List<? extends RestObject> childRestObjs, Class<? extends RestObject> objectType) throws RestException {
assign(session, childRestObjs, objectType, true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

}

@Override
public void assign(RestSession<?> session, List<? extends RestObject> childRestObjs, Class<? extends RestObject> objectType, boolean commit) throws RestException {
// Make sure there are child objects passed in
if (childRestObjs.isEmpty()) {
if (childRestObjs.isEmpty() && objectType == null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

throw new RestException("No child objects specified");
}


// Extract IDs from the specified child objects
List<String> ids = new ArrayList<String>();
for (RestObject restObject : childRestObjs) {
ids.add(restObject.getId());
}

Class<?> childRestObjClass = childRestObjs.get(0).getClass();
Class<?> childRestObjClass = objectType == null ? childRestObjs.get(0).getClass() : objectType;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

ResponseEntity<RestObject[]> response = session.sendRequestWithRetry(HttpMethod.PUT, getResourceUrlForChildType(session, childRestObjClass), null, null,
ids, BambouUtils.getArrayClass(this));
if (response.getStatusCode().series() == HttpStatus.Series.SUCCESSFUL) {
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/net/nuagenetworks/bambou/RestSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,14 @@ public void instantiateChild(RestObject restObj, RestObject childRestObj, RestOb

@Override
public void assign(RestObject restObj, List<? extends RestObject> childRestObjs) throws RestException {
restObj.assign(this, childRestObjs);
assign(restObj, childRestObjs, null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency, this line should read: restObj.assign(this, childRestObjs) or restObj.assign(this, childRestObjs, null);

}

@Override
public void assign(RestObject restObj, List<? extends RestObject> childRestObjs, Class<? extends RestObject> objectType) throws RestException {
restObj.assign(this, childRestObjs, objectType);
}

@Override
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

public void assign(RestObject restObj, List<? extends RestObject> childRestObjs, boolean commit) throws RestException {
restObj.assign(this, childRestObjs, commit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ public interface RestObjectOperations {
void instantiateChild(RestObject childRestObj, RestObject fromTemplate, Integer responseChoice, boolean commit) throws RestException;

void assign(List<? extends RestObject> childRestObjs) throws RestException;

void assign(List<? extends RestObject> childRestObjs, Class<? extends RestObject> objectType) throws RestException;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok


void assign(List<? extends RestObject> childRestObjs, boolean commit) throws RestException;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove extra spaces. Fairly minor :-)

void fetch(RestSession<?> session) throws RestException;

void save(RestSession<?> session) throws RestException;
Expand All @@ -78,4 +80,8 @@ void instantiateChild(RestSession<?> session, RestObject childRestObj, RestObjec
void assign(RestSession<?> session, List<? extends RestObject> childRestObjs) throws RestException;

void assign(RestSession<?> session, List<? extends RestObject> childRestObjs, boolean commit) throws RestException;

void assign(RestSession<?> session, List<? extends RestObject> childRestObjs, Class<? extends RestObject> objectType, boolean commit) throws RestException;

void assign(RestSession<?> session, List<? extends RestObject> childRestObjs, Class<? extends RestObject> objectType) throws RestException;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public interface RestSessionOperations {
void assign(RestObject restObj, List<? extends RestObject> childRestObjs) throws RestException;

void assign(RestObject restObj, List<? extends RestObject> childRestObjs, boolean commit) throws RestException;

void assign(RestObject restObj, List<? extends RestObject> childRestObjs, Class<? extends RestObject> objectType) throws RestException;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok


<T extends RestObject> List<T> get(RestFetcher<T> fetcher) throws RestException;

Expand Down