Skip to content

Commit

Permalink
Added verification for dependencies in app scope in method promoteSco…
Browse files Browse the repository at this point in the history
…peToTenant
  • Loading branch information
Kirill380 committed Jun 1, 2016
1 parent ca122d9 commit debc0f1
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 148 deletions.
Expand Up @@ -1275,8 +1275,8 @@ public boolean checkFqnExistsWithAppToken(String fqn, String tenantId, String ap
}
}

public CTLSchemaMetaInfoDto updateCTLSchemaMetaInfoScope(CTLSchemaMetaInfoDto ctlSchemaMetaInfo) {
return restTemplate.postForObject(restTemplate.getUrl() + "CTL/updateScope", ctlSchemaMetaInfo, CTLSchemaMetaInfoDto.class);
public CTLSchemaMetaInfoDto promoteScopeToTenant(CTLSchemaMetaInfoDto ctlSchemaMetaInfo) {
return restTemplate.postForObject(restTemplate.getUrl() + "CTL/promoteScopeToTenant", ctlSchemaMetaInfo, CTLSchemaMetaInfoDto.class);
}

public List<CTLSchemaMetaInfoDto> getSystemLevelCTLSchemas() {
Expand Down
Expand Up @@ -98,8 +98,7 @@ public void onClick(ClickEvent event) {
@Override
public void onClick(ClickEvent event) {
CTLSchemaMetaInfoDto metaInfo = entity.getMetaInfo();
metaInfo.setApplicationId(null);
KaaAdmin.getDataSource().updateCtlSchemaScope(metaInfo, new BusyAsyncCallback<CTLSchemaMetaInfoDto>() {
KaaAdmin.getDataSource().promoteScopeToTenant(metaInfo, new BusyAsyncCallback<CTLSchemaMetaInfoDto>() {
@Override
public void onFailureImpl(Throwable caught) {
Utils.handleException(caught, detailsView);
Expand Down
Expand Up @@ -856,9 +856,9 @@ protected void onResult(Boolean result) {
});
}

public void updateCtlSchemaScope(CTLSchemaMetaInfoDto metaInfo,
final AsyncCallback<CTLSchemaMetaInfoDto> callback) {
rpcService.updateCTLSchemaMetaInfoScope(metaInfo,
public void promoteScopeToTenant(CTLSchemaMetaInfoDto metaInfo,
final AsyncCallback<CTLSchemaMetaInfoDto> callback) {
rpcService.promoteScopeToTenant(metaInfo,
new DataCallback<CTLSchemaMetaInfoDto>(callback) {
@Override
protected void onResult(CTLSchemaMetaInfoDto result) {
Expand Down
Expand Up @@ -992,21 +992,21 @@ public boolean checkFqnExistsWithAppToken(@RequestParam String fqn,
}

/**
* Update existing CTL schema meta info scope by the given CTL schema meta info object.
* Promote existing CTL schema meta info from application to tenant scope
*
* @param ctlSchemaMetaInfo
* the CTL schema meta info object.
*
* @throws KaaAdminServiceException
* the kaa admin service exception
*
* @return CTLSchemaMetaInfoDto the updated CTL schema meta info object.
* @return CTLSchemaMetaInfoDto the promoted CTL schema meta info object.
*/
@RequestMapping(value = "CTL/updateScope", method = RequestMethod.POST)
@RequestMapping(value = "CTL/promoteScopeToTenant", method = RequestMethod.POST)
@ResponseBody
public CTLSchemaMetaInfoDto updateCTLSchemaMetaInfoScope(@RequestBody CTLSchemaMetaInfoDto ctlSchemaMetaInfo)
public CTLSchemaMetaInfoDto promoteScopeToTenant(@RequestBody CTLSchemaMetaInfoDto ctlSchemaMetaInfo)
throws KaaAdminServiceException {
return kaaAdminService.updateCTLSchemaMetaInfoScope(ctlSchemaMetaInfo);
return kaaAdminService.promoteScopeToTenant(ctlSchemaMetaInfo);
}

/**
Expand Down

Large diffs are not rendered by default.

Expand Up @@ -409,7 +409,7 @@ public interface KaaAdminService extends RemoteService {

boolean checkFqnExistsWithAppToken(String fqn, String tenantId, String applicationToken) throws KaaAdminServiceException;

CTLSchemaMetaInfoDto updateCTLSchemaMetaInfoScope(CTLSchemaMetaInfoDto ctlSchemaMetaInfo) throws KaaAdminServiceException;
CTLSchemaMetaInfoDto promoteScopeToTenant(CTLSchemaMetaInfoDto ctlSchemaMetaInfo) throws KaaAdminServiceException;

List<CTLSchemaMetaInfoDto> getSystemLevelCTLSchemas() throws KaaAdminServiceException;

Expand Down
Expand Up @@ -31,10 +31,8 @@
import org.springframework.http.HttpStatus;
import org.springframework.web.client.HttpClientErrorException;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.lang.reflect.Array;
import java.util.*;

/**
* @author Bohdan Khablenko
Expand Down Expand Up @@ -428,55 +426,59 @@ public void updateCTLSchemaScopeTest() throws Exception {
this.loginTenantDeveloper(tenantDeveloperUser);
CTLSchemaDto saved = this.createCTLSchema(this.ctlRandomFieldType(), CTL_DEFAULT_NAMESPACE, 1, tenantDeveloperDto.getTenantId(), application.getId(), null, null);
CTLSchemaMetaInfoDto metaInfo = saved.getMetaInfo();
metaInfo.setApplicationId(null);
CTLSchemaMetaInfoDto updatedMetaInfo = client.updateCTLSchemaMetaInfoScope(metaInfo);
metaInfo.setVersions(Arrays.asList(1));
CTLSchemaMetaInfoDto updatedMetaInfo = client.promoteScopeToTenant(metaInfo);
Assert.assertNull(updatedMetaInfo.getApplicationId());
Assert.assertNotNull(updatedMetaInfo.getTenantId());
Assert.assertEquals(tenantDeveloperDto.getTenantId(), updatedMetaInfo.getTenantId());
Assert.assertEquals(CTLSchemaScopeDto.TENANT, updatedMetaInfo.getScope());
}

@Test
public void updateCTLSchemaScopeForbiddenTest() throws Exception {
public void promoteScopeToTenantForbiddenTest() throws Exception {
ApplicationDto application = createApplication(tenantAdminDto);
this.loginTenantDeveloper(tenantDeveloperUser);
CTLSchemaDto saved = this.createCTLSchema(this.ctlRandomFieldType(), CTL_DEFAULT_NAMESPACE, 1, tenantDeveloperDto.getTenantId(), application.getId(), null, null);
final CTLSchemaMetaInfoDto metaInfo = saved.getMetaInfo();
metaInfo.setApplicationId(null);

metaInfo.setVersions(Arrays.asList(1));
metaInfo.setTenantId(null);

this.checkForbidden(new TestRestCall() {
@Override
public void executeRestCall() throws Exception {
client.updateCTLSchemaMetaInfoScope(metaInfo);
client.promoteScopeToTenant(metaInfo);
}
});

saved = this.createCTLSchema(this.ctlRandomFieldType(), CTL_DEFAULT_NAMESPACE, 1, tenantDeveloperDto.getTenantId(), null, null, null);
final CTLSchemaMetaInfoDto metaInfo2 = saved.getMetaInfo();

metaInfo2.setVersions(Arrays.asList(1));
Assert.assertNull(metaInfo2.getApplicationId());
metaInfo2.setApplicationId(application.getId());

this.checkRestErrorStatusCode(new TestRestCall() {
@Override
public void executeRestCall() throws Exception {
client.updateCTLSchemaMetaInfoScope(metaInfo2);
client.promoteScopeToTenant(metaInfo2);
}
}, HttpStatus.INTERNAL_SERVER_ERROR);
}, HttpStatus.NOT_FOUND);

this.loginTenantAdmin(tenantAdminUser);
saved = this.createCTLSchema(this.ctlRandomFieldType(), CTL_DEFAULT_NAMESPACE, 1, tenantAdminDto.getTenantId(), null, null, null);
final CTLSchemaMetaInfoDto metaInfo3 = saved.getMetaInfo();

metaInfo3.setVersions(Arrays.asList(1));
Assert.assertNull(metaInfo3.getApplicationId());
metaInfo3.setApplicationId(application.getId());

this.checkForbidden(new TestRestCall() {
@Override
public void executeRestCall() throws Exception {
client.updateCTLSchemaMetaInfoScope(metaInfo3);
client.promoteScopeToTenant(metaInfo3);
}
});

//Assert.assertNull(updatedMetaInfo.getApplicationId());
//Assert.assertNotNull(updatedMetaInfo.getTenantId());
//Assert.assertEquals(tenantDeveloperDto.getTenantId(), updatedMetaInfo.getTenantId());
//Assert.assertEquals(CTLSchemaScopeDto.TENANT, updatedMetaInfo.getScope());
}

}

0 comments on commit debc0f1

Please sign in to comment.