Search in sources :

Example 1 with ServiceDocumentDescription

use of com.vmware.xenon.common.ServiceDocumentDescription in project photon-model by vmware.

the class PhotonModelUtils method updateEndpointLinks.

public static <T extends ServiceDocument> T updateEndpointLinks(T state, String endpointLink) {
    if (state == null) {
        return state;
    }
    ServiceDocumentDescription sdDesc = ServiceDocumentDescription.Builder.create().buildDescription(state.getClass());
    // This method will assign the value of the endpointLinks if it does not exist for the given
    // resource OR it will merge it with the existing collection if already set.
    Set<String> endpointLinks = new HashSet<>();
    endpointLinks.add(endpointLink);
    ReflectionUtils.setOrUpdatePropertyValue(sdDesc.propertyDescriptions.get(PhotonModelConstants.FIELD_NAME_ENDPOINT_LINKS), state, endpointLinks);
    return state;
}
Also used : ServiceDocumentDescription(com.vmware.xenon.common.ServiceDocumentDescription) HashSet(java.util.HashSet)

Example 2 with ServiceDocumentDescription

use of com.vmware.xenon.common.ServiceDocumentDescription in project photon-model by vmware.

the class ResourceUtilsTest method testOperationPatchNoChanges.

@Test
public void testOperationPatchNoChanges() {
    ResourceState current = new ResourceState();
    current.tenantLinks = new ArrayList<>(Arrays.asList("tenant1", "tenant2"));
    current.groupLinks = new HashSet<>(Arrays.asList("groupA", "groupB"));
    current.tagLinks = new HashSet<>(Arrays.asList("tag1", "tag2"));
    ResourceState patch = new ResourceState();
    Operation patchOperation = Operation.createPatch(UriUtils.buildUri(this.host, "/resource")).setBody(patch);
    ServiceDocumentDescription desc = ServiceDocumentDescription.Builder.create().buildDescription(ResourceState.class);
    ResourceUtils.handlePatch(null, patchOperation, current, desc, ResourceState.class, null);
    assertTrue(patchOperation.hasPragmaDirective(Operation.PRAGMA_DIRECTIVE_STATE_NOT_MODIFIED));
}
Also used : Operation(com.vmware.xenon.common.Operation) ServiceDocumentDescription(com.vmware.xenon.common.ServiceDocumentDescription) BaseModelTest(com.vmware.photon.controller.model.helpers.BaseModelTest) Test(org.junit.Test)

Example 3 with ServiceDocumentDescription

use of com.vmware.xenon.common.ServiceDocumentDescription in project photon-model by vmware.

the class ResourceUtilsTest method handlePatch.

private <T extends ResourceState> Operation handlePatch(T currentState, T patchState, Class<T> type) {
    Operation patchOperation = Operation.createPatch(UriUtils.buildUri(this.host, "/resource")).setBody(patchState);
    ServiceDocumentDescription desc = ServiceDocumentDescription.Builder.create().buildDescription(type);
    ResourceUtils.handlePatch(null, patchOperation, currentState, desc, type, null);
    return patchOperation;
}
Also used : Operation(com.vmware.xenon.common.Operation) ServiceDocumentDescription(com.vmware.xenon.common.ServiceDocumentDescription)

Aggregations

ServiceDocumentDescription (com.vmware.xenon.common.ServiceDocumentDescription)3 Operation (com.vmware.xenon.common.Operation)2 BaseModelTest (com.vmware.photon.controller.model.helpers.BaseModelTest)1 HashSet (java.util.HashSet)1 Test (org.junit.Test)1