Skip to content

Commit

Permalink
Changed Controller layer and AdminClient and some fixes on GWT client
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirill380 committed Jun 22, 2016
1 parent b68f45b commit 7de1877
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 96 deletions.
Expand Up @@ -226,21 +226,8 @@ public void deleteApplication(String applicationId) throws Exception {
restTemplate.postForLocation(restTemplate.getUrl() + "delApplication", params); restTemplate.postForLocation(restTemplate.getUrl() + "delApplication", params);
} }


public ConfigurationSchemaDto createConfigurationSchema(ConfigurationSchemaDto configurationSchema, String schemaResource)
throws Exception {
return createConfigurationSchema(configurationSchema, getFileResource(schemaResource));
}

public ConfigurationSchemaDto createConfigurationSchema(ConfigurationSchemaDto configurationSchema, ByteArrayResource schemaResource)
throws Exception {
MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
params.add("configurationSchema", configurationSchema);
params.add("file", schemaResource);
return restTemplate.postForObject(restTemplate.getUrl() + "createConfigurationSchema", params, ConfigurationSchemaDto.class);
}

public ConfigurationSchemaDto editConfigurationSchema(ConfigurationSchemaDto configurationSchema) throws Exception { public ConfigurationSchemaDto editConfigurationSchema(ConfigurationSchemaDto configurationSchema) throws Exception {
return restTemplate.postForObject(restTemplate.getUrl() + "editConfigurationSchema", configurationSchema, ConfigurationSchemaDto.class); return restTemplate.postForObject(restTemplate.getUrl() + "saveConfigurationSchema", configurationSchema, ConfigurationSchemaDto.class);
} }


public EndpointProfileSchemaDto saveProfileSchema(EndpointProfileSchemaDto profileSchema) throws Exception { public EndpointProfileSchemaDto saveProfileSchema(EndpointProfileSchemaDto profileSchema) throws Exception {
Expand Down
Expand Up @@ -23,12 +23,10 @@
import org.kaaproject.kaa.server.admin.client.mvp.place.ConfigurationSchemaPlace; import org.kaaproject.kaa.server.admin.client.mvp.place.ConfigurationSchemaPlace;
import org.kaaproject.kaa.server.admin.client.mvp.place.CtlSchemaPlace; import org.kaaproject.kaa.server.admin.client.mvp.place.CtlSchemaPlace;
import org.kaaproject.kaa.server.admin.client.mvp.view.BaseCtlSchemaView; import org.kaaproject.kaa.server.admin.client.mvp.view.BaseCtlSchemaView;
import org.kaaproject.kaa.server.admin.client.mvp.view.BaseSchemaView;


import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.rpc.AsyncCallback;
import org.kaaproject.kaa.server.admin.shared.schema.ConfigurationSchemaViewDto; import org.kaaproject.kaa.server.admin.shared.schema.ConfigurationSchemaViewDto;
import org.kaaproject.kaa.server.admin.shared.schema.CtlSchemaFormDto; import org.kaaproject.kaa.server.admin.shared.schema.CtlSchemaFormDto;
import org.kaaproject.kaa.server.admin.shared.schema.ProfileSchemaViewDto;


public class ConfigurationSchemaActivity extends public class ConfigurationSchemaActivity extends
AbstractBaseCtlSchemaActivity<ConfigurationSchemaDto, ConfigurationSchemaViewDto, BaseCtlSchemaView, ConfigurationSchemaPlace> { AbstractBaseCtlSchemaActivity<ConfigurationSchemaDto, ConfigurationSchemaViewDto, BaseCtlSchemaView, ConfigurationSchemaPlace> {
Expand Down Expand Up @@ -56,13 +54,13 @@ protected BaseCtlSchemaView getView(boolean create) {


@Override @Override
protected void getEntity(String id, AsyncCallback<ConfigurationSchemaViewDto> callback) { protected void getEntity(String id, AsyncCallback<ConfigurationSchemaViewDto> callback) {
KaaAdmin.getDataSource().getConfigurationSchemaForm(id, callback); // refactor on server KaaAdmin.getDataSource().getConfigurationSchemaView(id, callback);
} }




@Override @Override
protected void editEntity(ConfigurationSchemaViewDto entity, AsyncCallback<ConfigurationSchemaViewDto> callback) { protected void editEntity(ConfigurationSchemaViewDto entity, AsyncCallback<ConfigurationSchemaViewDto> callback) {
KaaAdmin.getDataSource().editConfigurationSchemaForm(entity, callback); // refactor on server KaaAdmin.getDataSource().saveConfigurationSchemaView(entity, callback);
} }


@Override @Override
Expand All @@ -80,7 +78,7 @@ protected void createEmptyCtlSchemaForm(AsyncCallback<CtlSchemaFormDto> callback


@Override @Override
protected CtlSchemaPlace.SchemaType getPlaceSchemaType() { protected CtlSchemaPlace.SchemaType getPlaceSchemaType() {
return CtlSchemaPlace.SchemaType.ENDPOINT_PROFILE; return CtlSchemaPlace.SchemaType.CONFIGURATION;
} }




Expand Down
Expand Up @@ -661,25 +661,25 @@ protected void onResult(List<ConfigurationSchemaDto> result) {


} }


public void editConfigurationSchemaForm( public void saveConfigurationSchemaView(
ConfigurationSchemaViewDto configurationSchema, ConfigurationSchemaViewDto configurationSchema,
final AsyncCallback<ConfigurationSchemaViewDto> callback) { final AsyncCallback<ConfigurationSchemaViewDto> callback) {
rpcService.editConfigurationSchemaForm(configurationSchema, rpcService.saveConfigurationSchemaView(configurationSchema,
new DataCallback<ConfigurationSchemaDto>(callback) { new DataCallback<ConfigurationSchemaViewDto>(callback) {
@Override @Override
protected void onResult(ConfigurationSchemaDto result) { protected void onResult(ConfigurationSchemaViewDto result) {
eventBus.fireEvent(new DataEvent( eventBus.fireEvent(new DataEvent(
ConfigurationSchemaDto.class)); ConfigurationSchemaDto.class));
} }
}); });
} }


public void getConfigurationSchemaForm(String configurationSchemaId, public void getConfigurationSchemaView(String configurationSchemaId,
final AsyncCallback<ConfigurationSchemaViewDto> callback) { final AsyncCallback<ConfigurationSchemaViewDto> callback) {
rpcService.getConfigurationSchemaForm(configurationSchemaId, rpcService.getConfigurationSchemaView(configurationSchemaId,
new DataCallback<ConfigurationSchemaDto>(callback) { new DataCallback<ConfigurationSchemaViewDto>(callback) {
@Override @Override
protected void onResult(ConfigurationSchemaDto result) { protected void onResult(ConfigurationSchemaViewDto result) {
} }
}); });
} }
Expand Down
Expand Up @@ -182,6 +182,8 @@ public TreePlace createDefaultPreviousPlace() {
if (schemaType != null) { if (schemaType != null) {
if (schemaType == SchemaType.ENDPOINT_PROFILE) { if (schemaType == SchemaType.ENDPOINT_PROFILE) {
return new ProfileSchemasPlace(applicationId); return new ProfileSchemasPlace(applicationId);
} if(schemaType == SchemaType.CONFIGURATION) {
return new ConfigurationSchemasPlace(applicationId);
} else { } else {
return new ServerProfileSchemasPlace(applicationId); return new ServerProfileSchemasPlace(applicationId);
} }
Expand All @@ -197,8 +199,8 @@ public TreePlace createDefaultPreviousPlace() {
} }
} }


public static enum SchemaType { public enum SchemaType {

CONFIGURATION,
ENDPOINT_PROFILE, ENDPOINT_PROFILE,
SERVER_PROFILE SERVER_PROFILE


Expand Down
Expand Up @@ -1069,37 +1069,16 @@ public ConfigurationSchemaDto getConfigurationSchema(@PathVariable String config
/** /**
* Adds configuration schema to the list of all configuration schemas. * Adds configuration schema to the list of all configuration schemas.
* *
* @param configurationSchema * @param configurationSchema the сonfiguration schema
* the сonfiguration schema
* @param file
* the file
* @return the сonfiguration schema dto * @return the сonfiguration schema dto
* @throws KaaAdminServiceException * @throws KaaAdminServiceException the kaa admin service exception
* the kaa admin service exception
*/ */
@RequestMapping(value = "createConfigurationSchema", method = RequestMethod.POST, consumes = { "multipart/mixed", "multipart/form-data" }) @RequestMapping(value = "saveConfigurationSchema", method = RequestMethod.POST)
@ResponseBody @ResponseBody
public ConfigurationSchemaDto createConfigurationSchema(@RequestPart("configurationSchema") ConfigurationSchemaDto configurationSchema, public ConfigurationSchemaDto createConfigurationSchema(@RequestBody ConfigurationSchemaDto configurationSchema) throws KaaAdminServiceException {
@RequestPart("file") MultipartFile file) throws KaaAdminServiceException { return kaaAdminService.saveConfigurationSchema(configurationSchema);
byte[] data = getFileContent(file);
return kaaAdminService.editConfigurationSchema(configurationSchema, data);
} }


/**
* Edits existing configuration schema.
*
* @param configurationSchema
* the сonfiguration schema
* @return the сonfiguration schema dto
* @throws KaaAdminServiceException
* the kaa admin service exception
*/
@RequestMapping(value = "editConfigurationSchema", method = RequestMethod.POST)
@ResponseBody
public ConfigurationSchemaDto editConfigurationSchema(@RequestBody ConfigurationSchemaDto configurationSchema)
throws KaaAdminServiceException {
return kaaAdminService.editConfigurationSchema(configurationSchema, null);
}


/** /**
* Gets the notification schemas by application token. * Gets the notification schemas by application token.
Expand Down
Expand Up @@ -121,12 +121,7 @@
import org.kaaproject.kaa.server.admin.shared.endpoint.EndpointProfileViewDto; import org.kaaproject.kaa.server.admin.shared.endpoint.EndpointProfileViewDto;
import org.kaaproject.kaa.server.admin.shared.plugin.PluginInfoDto; import org.kaaproject.kaa.server.admin.shared.plugin.PluginInfoDto;
import org.kaaproject.kaa.server.admin.shared.properties.PropertiesDto; import org.kaaproject.kaa.server.admin.shared.properties.PropertiesDto;
import org.kaaproject.kaa.server.admin.shared.schema.CtlSchemaExportKey; import org.kaaproject.kaa.server.admin.shared.schema.*;
import org.kaaproject.kaa.server.admin.shared.schema.CtlSchemaFormDto;
import org.kaaproject.kaa.server.admin.shared.schema.CtlSchemaReferenceDto;
import org.kaaproject.kaa.server.admin.shared.schema.ProfileSchemaViewDto;
import org.kaaproject.kaa.server.admin.shared.schema.SchemaInfoDto;
import org.kaaproject.kaa.server.admin.shared.schema.ServerProfileSchemaViewDto;
import org.kaaproject.kaa.server.admin.shared.services.KaaAdminService; import org.kaaproject.kaa.server.admin.shared.services.KaaAdminService;
import org.kaaproject.kaa.server.admin.shared.services.KaaAdminServiceException; import org.kaaproject.kaa.server.admin.shared.services.KaaAdminServiceException;
import org.kaaproject.kaa.server.admin.shared.services.ServiceErrorCode; import org.kaaproject.kaa.server.admin.shared.services.ServiceErrorCode;
Expand Down Expand Up @@ -1400,59 +1395,74 @@ public ConfigurationSchemaDto getConfigurationSchema(String configurationSchemaI
} }
} }




@Override @Override
public ConfigurationSchemaDto editConfigurationSchema(ConfigurationSchemaDto configurationSchema, byte[] schema) public ConfigurationSchemaDto saveConfigurationSchema(ConfigurationSchemaDto confSchema) throws KaaAdminServiceException {
throws KaaAdminServiceException {
checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER);
try { try {
if (isEmpty(configurationSchema.getId())) { if (isEmpty(confSchema.getId())) {
configurationSchema.setCreatedUsername(getCurrentUser().getUsername()); confSchema.setCreatedUsername(getCurrentUser().getUsername());
checkApplicationId(configurationSchema.getApplicationId()); checkApplicationId(confSchema.getApplicationId());
setSchema(configurationSchema, schema);
} else { } else {
ConfigurationSchemaDto storedConfigurationSchema = controlService.getConfigurationSchema(configurationSchema.getId()); ConfigurationSchemaDto storedConfSchema = controlService.getConfigurationSchema(confSchema.getId());
Utils.checkNotNull(storedConfigurationSchema); Utils.checkNotNull(storedConfSchema);
checkApplicationId(storedConfigurationSchema.getApplicationId()); checkApplicationId(storedConfSchema.getApplicationId());
configurationSchema.setSchema(storedConfigurationSchema.getSchema());
} }
return controlService.editConfigurationSchema(configurationSchema); return controlService.editConfigurationSchema(confSchema); // TODO change realisation of method
} catch (Exception e) { } catch (Exception e) {
throw Utils.handleException(e); throw Utils.handleException(e);
} }
} }





@Override @Override
public ConfigurationSchemaDto getConfigurationSchemaForm(String configurationSchemaId) throws KaaAdminServiceException { public ConfigurationSchemaViewDto getConfigurationSchemaView(String configurationSchemaId) throws KaaAdminServiceException {
checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER);
try { try {
ConfigurationSchemaDto configurationSchema = getConfigurationSchema(configurationSchemaId); ConfigurationSchemaDto confSchema = getConfigurationSchema(configurationSchemaId);
convertToSchemaForm(configurationSchema, configurationSchemaFormAvroConverter); CTLSchemaDto ctlSchemaDto = controlService.getCTLSchemaById(confSchema.getCtlSchemaId());
return configurationSchema; return new ConfigurationSchemaViewDto(confSchema, toCtlSchemaForm(ctlSchemaDto));
} catch (Exception e) { } catch (Exception e) {
throw Utils.handleException(e); throw Utils.handleException(e);
} }
} }




@Override @Override
public ConfigurationSchemaDto editConfigurationSchemaForm(ConfigurationSchemaDto configurationSchema) throws KaaAdminServiceException { public ConfigurationSchemaViewDto saveConfigurationSchemaView(ConfigurationSchemaViewDto confSchemaView) throws KaaAdminServiceException {
checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER);
try { try {
if (isEmpty(configurationSchema.getId())) { ConfigurationSchemaDto confSchema = confSchemaView.getSchema();
configurationSchema.setCreatedUsername(getCurrentUser().getUsername()); String applicationId = confSchema.getApplicationId();
checkApplicationId(configurationSchema.getApplicationId()); checkApplicationId(applicationId);
convertToStringSchema(configurationSchema, configurationSchemaFormAvroConverter); String ctlSchemaId = confSchema.getCtlSchemaId();
} else {
ConfigurationSchemaDto storedConfigurationSchema = controlService.getConfigurationSchema(configurationSchema.getId()); if (isEmpty(ctlSchemaId)) {
Utils.checkNotNull(storedConfigurationSchema); if (confSchemaView.useExistingCtlSchema()) {
checkApplicationId(storedConfigurationSchema.getApplicationId()); CtlSchemaReferenceDto metaInfo = confSchemaView.getExistingMetaInfo();
configurationSchema.setSchema(storedConfigurationSchema.getSchema()); CTLSchemaDto schema = getCTLSchemaByFqnVersionTenantIdAndApplicationId(metaInfo.getMetaInfo().getFqn(),
metaInfo.getVersion(),
metaInfo.getMetaInfo().getTenantId(),
metaInfo.getMetaInfo().getApplicationId());
confSchema.setCtlSchemaId(schema.getId());
} else {
CtlSchemaFormDto ctlSchemaForm = saveCTLSchemaForm(confSchemaView.getCtlSchemaForm());
confSchema.setCtlSchemaId(ctlSchemaForm.getId());
}
} }
return controlService.editConfigurationSchema(configurationSchema);
ConfigurationSchemaDto savedConfSchema = saveConfigurationSchema(confSchema);
return getConfigurationSchemaView(savedConfSchema.getId());
} catch (Exception e) { } catch (Exception e) {
throw Utils.handleException(e); throw Utils.handleException(e);
} }
} }



@Override @Override
public List<NotificationSchemaDto> getNotificationSchemasByApplicationId(String applicationId) throws KaaAdminServiceException { public List<NotificationSchemaDto> getNotificationSchemasByApplicationId(String applicationId) throws KaaAdminServiceException {
checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER);
Expand Down
Expand Up @@ -6,6 +6,8 @@


public class ConfigurationSchemaViewDto extends BaseSchemaViewDto<ConfigurationSchemaDto> { public class ConfigurationSchemaViewDto extends BaseSchemaViewDto<ConfigurationSchemaDto> {


private static final long serialVersionUID = 8311415263866415408L;

public ConfigurationSchemaViewDto() { public ConfigurationSchemaViewDto() {
super(); super();
} }
Expand Down
Expand Up @@ -65,11 +65,7 @@
import org.kaaproject.kaa.server.admin.shared.endpoint.EndpointProfileViewDto; import org.kaaproject.kaa.server.admin.shared.endpoint.EndpointProfileViewDto;
import org.kaaproject.kaa.server.admin.shared.plugin.PluginInfoDto; import org.kaaproject.kaa.server.admin.shared.plugin.PluginInfoDto;
import org.kaaproject.kaa.server.admin.shared.properties.PropertiesDto; import org.kaaproject.kaa.server.admin.shared.properties.PropertiesDto;
import org.kaaproject.kaa.server.admin.shared.schema.CtlSchemaFormDto; import org.kaaproject.kaa.server.admin.shared.schema.*;
import org.kaaproject.kaa.server.admin.shared.schema.CtlSchemaReferenceDto;
import org.kaaproject.kaa.server.admin.shared.schema.ProfileSchemaViewDto;
import org.kaaproject.kaa.server.admin.shared.schema.SchemaInfoDto;
import org.kaaproject.kaa.server.admin.shared.schema.ServerProfileSchemaViewDto;


import com.google.gwt.user.client.rpc.RemoteService; import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
Expand Down Expand Up @@ -191,11 +187,11 @@ public interface KaaAdminService extends RemoteService {


ConfigurationSchemaDto getConfigurationSchema(String configurationSchemaId) throws KaaAdminServiceException; ConfigurationSchemaDto getConfigurationSchema(String configurationSchemaId) throws KaaAdminServiceException;


ConfigurationSchemaDto editConfigurationSchema(ConfigurationSchemaDto configurationSchema, byte[] schema) throws KaaAdminServiceException; ConfigurationSchemaDto saveConfigurationSchema(ConfigurationSchemaDto configurationSchema) throws KaaAdminServiceException;


ConfigurationSchemaDto getConfigurationSchemaForm(String configurationSchemaId) throws KaaAdminServiceException; ConfigurationSchemaViewDto getConfigurationSchemaView(String configurationSchemaId) throws KaaAdminServiceException;


ConfigurationSchemaDto editConfigurationSchemaForm(ConfigurationSchemaDto configurationSchema) throws KaaAdminServiceException; ConfigurationSchemaViewDto saveConfigurationSchemaView(ConfigurationSchemaViewDto confSchemaView) throws KaaAdminServiceException;


List<NotificationSchemaDto> getNotificationSchemasByApplicationId(String applicationId) throws KaaAdminServiceException; List<NotificationSchemaDto> getNotificationSchemasByApplicationId(String applicationId) throws KaaAdminServiceException;


Expand Down

0 comments on commit 7de1877

Please sign in to comment.