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) { public CTLSchemaMetaInfoDto promoteScopeToTenant(CTLSchemaMetaInfoDto ctlSchemaMetaInfo) {
return restTemplate.postForObject(restTemplate.getUrl() + "CTL/updateScope", ctlSchemaMetaInfo, CTLSchemaMetaInfoDto.class); return restTemplate.postForObject(restTemplate.getUrl() + "CTL/promoteScopeToTenant", ctlSchemaMetaInfo, CTLSchemaMetaInfoDto.class);
} }


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


public void updateCtlSchemaScope(CTLSchemaMetaInfoDto metaInfo, public void promoteScopeToTenant(CTLSchemaMetaInfoDto metaInfo,
final AsyncCallback<CTLSchemaMetaInfoDto> callback) { final AsyncCallback<CTLSchemaMetaInfoDto> callback) {
rpcService.updateCTLSchemaMetaInfoScope(metaInfo, rpcService.promoteScopeToTenant(metaInfo,
new DataCallback<CTLSchemaMetaInfoDto>(callback) { new DataCallback<CTLSchemaMetaInfoDto>(callback) {
@Override @Override
protected void onResult(CTLSchemaMetaInfoDto result) { 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 * @param ctlSchemaMetaInfo
* the CTL schema meta info object. * the CTL schema meta info object.
* *
* @throws KaaAdminServiceException * @throws KaaAdminServiceException
* the kaa admin service exception * 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 @ResponseBody
public CTLSchemaMetaInfoDto updateCTLSchemaMetaInfoScope(@RequestBody CTLSchemaMetaInfoDto ctlSchemaMetaInfo) public CTLSchemaMetaInfoDto promoteScopeToTenant(@RequestBody CTLSchemaMetaInfoDto ctlSchemaMetaInfo)
throws KaaAdminServiceException { 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; 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; List<CTLSchemaMetaInfoDto> getSystemLevelCTLSchemas() throws KaaAdminServiceException;


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


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


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


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

this.checkForbidden(new TestRestCall() { this.checkForbidden(new TestRestCall() {
@Override @Override
public void executeRestCall() throws Exception { 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); saved = this.createCTLSchema(this.ctlRandomFieldType(), CTL_DEFAULT_NAMESPACE, 1, tenantDeveloperDto.getTenantId(), null, null, null);
final CTLSchemaMetaInfoDto metaInfo2 = saved.getMetaInfo(); final CTLSchemaMetaInfoDto metaInfo2 = saved.getMetaInfo();

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

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


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

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

this.checkForbidden(new TestRestCall() { this.checkForbidden(new TestRestCall() {
@Override @Override
public void executeRestCall() throws Exception { 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.