Skip to content

Commit

Permalink
Merge pull request #140 from TanyaEf/master
Browse files Browse the repository at this point in the history
Fixed bug #139
  • Loading branch information
yaroslav-kovalchyk committed Oct 20, 2015
2 parents a973cdd + 97051ed commit 005ac9d
Show file tree
Hide file tree
Showing 15 changed files with 1,027 additions and 36 deletions.
33 changes: 16 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -486,23 +486,23 @@ OperationResult<Organization> result = session
.createOrUpdate(organization);
```
Be carefully using this method because you can damage existing organization if the `organizationId` of new organization is already used.
The descriptor sent in the request should contain all the properties you want to set on the new organization. Specify the `parentId` value to set the parent of the organization, not the `tenantUri` or `tenantFolderUri` properties.
The descriptor is sent in the request should contain all the properties you want to set on the new organization. Specify the `parentId` value to set the parent of the organization, not the `tenantUri` or `tenantFolderUri` properties.
However, all properties have defaults or can be determined based on the alias value. The minimal descriptor necessary to create an organization is simply the alias property. In this case, the organization is created as child of the logged-in user’s home organization.
####Modifying Organization Properties
To modify the properties of an organization, use the `update` method and specify the organization ID in the URL. The request must include an organization descriptor with the values you want to change. You cannot change the ID of an organization, only its name (used for display) and its alias (used for logging in).
```java
Organization organization = new Organization();
organization.setAlias("lalalaOrg");

OperationResult<Organization> result = session
OperationResult<ClientTenant> result = session
.organizationsService()
.organization("myOrg1")
.createOrUpdate(organization);
```
####Deleting an Organization
To delete an organization, use the `delete()` method and specify the organization ID in the `organization()` method. When deleting an organization, all of its resources in the repository, all of its sub-organizations, all of its users, and all of its roles are permanently deleted.
```java
OperationResult result = session
OperationResult<ClientTenant> result = session
.organizationsService()
.organization("myOrg1")
.delete();
Expand Down Expand Up @@ -603,7 +603,7 @@ ClientUser user = new ClientUser()
client
.authenticate("jasperadmin", "jasperadmin")
.usersService()
.user(user.getUsername())
.user("john.doe")
.createOrUpdate(user);
```
####Deleting a User
Expand Down Expand Up @@ -714,10 +714,10 @@ serverAttributes.setProfileAttributes(asList(new HypermediaAttribute(new ClientU
.createOrUpdate(serverAttributes);
```
Be careful with definition of attribute names because the server uses different strategies for creating or updating attributes depending on list of attribute names, list of attributes and existing attributes on the server:
1. if requested attribute name in `attributes()` method matches with attribute name of object defined in `createOrUpdate()` method and the attribute does not exist on the server it will be *created* on the server;
2. if requested attribute name in `attributes()` method matches with attribute name of object defined in `createOrUpdate()` method and the attribute exists on the server it will be *updated* on the server;
3. if requested attribute name in `attributes()` method does not match with any attribute names of object defined in `createOrUpdate()` method and the attribute exists on the server it will be *deleted* on the server;
4. if requested attribute in `createOrUpdate()` method method does not match with any attribute names in `attributes()` it will be *ignored* and will not be sent to the server;
1. if requested attribute name in `attributes()` method matches with attribute name of object defined in `createOrUpdate()` method and the attribute does not exist on the server it will be *created* on the server;
2. if requested attribute name in `attributes()` method matches with attribute name of object defined in `createOrUpdate()` method and the attribute exists on the server it will be *updated* on the server;
3. if requested attribute name in `attributes()` method does not match with any attribute names of object defined in `createOrUpdate()` method and the attribute exists on the server it will be *deleted* on the server;
4. if requested attribute in `createOrUpdate()` method method does not match with any attribute names in `attributes()` it will be *ignored* and will not be sent to the server;

The second way of using the attributes service is adding or replacing individual attribute:
```java
Expand Down Expand Up @@ -839,21 +839,20 @@ OperationResult<HypermediaAttributesListWrapper> operationResult = session
####Viewing Server Attributes
We have also provided service to get server attributes. Code below return available server attributes.
```java
List<ServerAttribute> attributes = session
.serverAttributesService()
.attributes()
List<HypermediaAttribute> attributes = session
.attributesService()
.allAttributes()
.get()
.getEntity()
.getAttributes();
.getProfileAttributes();
```
Or you can specify any concrete attribute.
```java
List<HypermediaAttribute> attributes = session
HypermediaAttribute entity = session
.attributesService()
.allAttributes()
.attribute("attribute_name")
.get()
.getEntity()
.getProfileAttributes();
.getEntity();
```
####Setting Server Attributes
It is possible to create new server attributes.
Expand Down Expand Up @@ -968,7 +967,7 @@ v2/users service. For details, see section [creating a user](https://github.com/
To delete a role, send the DELETE method and specify the role ID (name) in the URL.
When this method is successful, the role is permanently deleted.
```java
OperationResult operationResult =
OperationResult<ClientRole> operationResult =
client
.authenticate("jasperadmin", "jasperadmin")
.rolesService()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package com.jaspersoft.jasperserver.jaxrs.client.apiadapters.attributes;

import com.jaspersoft.jasperserver.dto.authority.hypermedia.HypermediaAttribute;
import com.jaspersoft.jasperserver.dto.authority.hypermedia.HypermediaAttributeEmbeddedContainer;
import com.jaspersoft.jasperserver.dto.permissions.RepositoryPermission;
import com.jaspersoft.jasperserver.jaxrs.client.RestClientTestUtil;
import com.jaspersoft.jasperserver.jaxrs.client.core.operationresult.OperationResult;
import javax.ws.rs.core.Response;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import static java.util.Arrays.asList;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertNotNull;
import static org.testng.AssertJUnit.assertNull;
Expand Down Expand Up @@ -80,6 +83,40 @@ public void should_delete_attribute() {
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), operationResult.getResponse().getStatus());
}

@Test
public void should_create_attribute_with_permission() {
HypermediaAttribute newAttribute = new HypermediaAttribute(attribute);

newAttribute.setName("OrganizationAttributeTest");
newAttribute.setValue("Organization attribute test value");
newAttribute.setDescription("Organization attribute description");
newAttribute.setPermissionMask(1);
newAttribute.setSecure(false);
newAttribute.setInherited(false);
newAttribute.setHolder("tenant:/organization_1");
RepositoryPermission permission = new RepositoryPermission().setUri("attr:/organizations/organization_1/attributes/OrganizationAttributeTest").setRecipient("role:/ROLE_ADMINISTRATOR").setMask(32);
HypermediaAttributeEmbeddedContainer container = new HypermediaAttributeEmbeddedContainer();
container.setRepositoryPermissions(asList(permission));
newAttribute.setEmbedded(container);

HypermediaAttribute entity = session
.attributesService()
.forOrganization("organization_1")
.attribute("OrganizationAttributeTest")
.setIncludePermissions(true)
.createOrUpdate(newAttribute)
.getEntity();

assertEquals(entity.getValue(), newAttribute.getValue());
assertNotNull(entity.getEmbedded());

OperationResult<HypermediaAttribute> operationResult = session
.attributesService()
.forOrganization("organization_1")
.attribute("OrganizationAttributeTest")
.delete();
}

@AfterClass
public void after() {
session.logout();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ public OperationResult<HypermediaAttributesListWrapper> createOrUpdate(Hypermedi
}
}
attributesListWrapper.setProfileAttributes(list);
return buildRequest().put(attributesListWrapper);
return buildRequest()
.setContentType(MimeTypeUtil.toCorrectContentMime(sessionStorage.getConfiguration(),"application/hal+{mime}"))
.put(attributesListWrapper);
}

public <R> RequestExecution asyncCreateOrUpdate(final HypermediaAttributesListWrapper attributesList,
Expand All @@ -133,6 +135,7 @@ public void run() {
callback.execute(request.put(attributesList));
}
});

ThreadPoolUtil.runAsynchronously(task);
return task;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ public void run() {
}

public OperationResult<HypermediaAttribute> createOrUpdate(ClientUserAttribute attribute) {
return buildRequest().put(attribute);
return buildRequest()
.setContentType(MimeTypeUtil.toCorrectContentMime(sessionStorage.getConfiguration(), "application/hal+{mime}"))
.put(attribute);
}

public <R> RequestExecution asyncCreateOrUpdate(final ClientUserAttribute userAttribute,
Expand All @@ -113,7 +115,7 @@ private JerseyRequest<HypermediaAttribute> buildRequest() {
JerseyRequest<HypermediaAttribute> request = JerseyRequest.buildRequest(sessionStorage,HypermediaAttribute.class,
new String[]{holderUri,"attributes/",attributeName}, new DefaultErrorHandler());
if (includePermissions) {
request.setAccept(MimeTypeUtil.toCorrectAcceptMime(sessionStorage.getConfiguration(),"application/hal+{mime}"));
request.setAccept(MimeTypeUtil.toCorrectAcceptMime(sessionStorage.getConfiguration(), "application/hal+{mime}"));
request.addParam("_embedded", "permission");
}
return request;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,8 @@ private <T> JerseyRequest<T> buildRequest(Class<T> responseType) {
new DefaultErrorHandler());
}
}





Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,13 @@ public SingleOrganizationAdapter organization(String organizationId) {
public BatchOrganizationsAdapter allOrganizations() {
return new BatchOrganizationsAdapter(sessionStorage);
}

/**
* @deprecated Replaced by {@link OrganizationsService#allOrganizations()}.
*/
@Deprecated
public BatchOrganizationsAdapter organizations() {
return new BatchOrganizationsAdapter(sessionStorage);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,10 @@
import com.jaspersoft.jasperserver.jaxrs.client.core.exceptions.handling.DefaultErrorHandler;
import com.jaspersoft.jasperserver.jaxrs.client.core.operationresult.OperationResult;
import javax.ws.rs.core.MultivaluedHashMap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


public class SingleOrganizationAdapter extends AbstractAdapter {

private static final Log log = LogFactory.getLog(SingleOrganizationAdapter.class);

private final ClientTenant clientTenant;
private final MultivaluedHashMap<String, String> params;

Expand Down Expand Up @@ -145,4 +141,15 @@ private JerseyRequest<ClientTenant> request() {
new DefaultErrorHandler()
);
}
}

/**
* @deprecated Replaced by {@link SingleOrganizationAdapter#create()}.
*/
@Deprecated
public OperationResult<ClientTenant> create(ClientTenant clientTenant) {
JerseyRequest<ClientTenant> request = request();
return params.size() != 0
? request.addParams(params).post(clientTenant)
: request.post(clientTenant);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,4 @@ private JerseyRequest<UsersListWrapper> buildRequest() {
return request;
}


}
}
Loading

0 comments on commit 005ac9d

Please sign in to comment.