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);
}

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 {
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 {
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.CtlSchemaPlace;
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 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.ProfileSchemaViewDto;

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

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


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

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

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

public void getConfigurationSchemaForm(String configurationSchemaId,
final AsyncCallback<ConfigurationSchemaViewDto> callback) {
rpcService.getConfigurationSchemaForm(configurationSchemaId,
new DataCallback<ConfigurationSchemaDto>(callback) {
public void getConfigurationSchemaView(String configurationSchemaId,
final AsyncCallback<ConfigurationSchemaViewDto> callback) {
rpcService.getConfigurationSchemaView(configurationSchemaId,
new DataCallback<ConfigurationSchemaViewDto>(callback) {
@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 == SchemaType.ENDPOINT_PROFILE) {
return new ProfileSchemasPlace(applicationId);
} if(schemaType == SchemaType.CONFIGURATION) {
return new ConfigurationSchemasPlace(applicationId);
} else {
return new ServerProfileSchemasPlace(applicationId);
}
Expand All @@ -197,8 +199,8 @@ public TreePlace createDefaultPreviousPlace() {
}
}

public static enum SchemaType {

public enum SchemaType {
CONFIGURATION,
ENDPOINT_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.
*
* @param configurationSchema
* the сonfiguration schema
* @param file
* the file
* @param configurationSchema the сonfiguration schema
* @return the сonfiguration schema dto
* @throws KaaAdminServiceException
* the kaa admin service exception
* @throws KaaAdminServiceException the kaa admin service exception
*/
@RequestMapping(value = "createConfigurationSchema", method = RequestMethod.POST, consumes = { "multipart/mixed", "multipart/form-data" })
@RequestMapping(value = "saveConfigurationSchema", method = RequestMethod.POST)
@ResponseBody
public ConfigurationSchemaDto createConfigurationSchema(@RequestPart("configurationSchema") ConfigurationSchemaDto configurationSchema,
@RequestPart("file") MultipartFile file) throws KaaAdminServiceException {
byte[] data = getFileContent(file);
return kaaAdminService.editConfigurationSchema(configurationSchema, data);
public ConfigurationSchemaDto createConfigurationSchema(@RequestBody ConfigurationSchemaDto configurationSchema) throws KaaAdminServiceException {
return kaaAdminService.saveConfigurationSchema(configurationSchema);
}

/**
* 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.
Expand Down
Expand Up @@ -121,12 +121,7 @@
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.properties.PropertiesDto;
import org.kaaproject.kaa.server.admin.shared.schema.CtlSchemaExportKey;
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.schema.*;
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.ServiceErrorCode;
Expand Down Expand Up @@ -1400,59 +1395,74 @@ public ConfigurationSchemaDto getConfigurationSchema(String configurationSchemaI
}
}



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




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



@Override
public ConfigurationSchemaDto editConfigurationSchemaForm(ConfigurationSchemaDto configurationSchema) throws KaaAdminServiceException {
public ConfigurationSchemaViewDto saveConfigurationSchemaView(ConfigurationSchemaViewDto confSchemaView) throws KaaAdminServiceException {
checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER);
try {
if (isEmpty(configurationSchema.getId())) {
configurationSchema.setCreatedUsername(getCurrentUser().getUsername());
checkApplicationId(configurationSchema.getApplicationId());
convertToStringSchema(configurationSchema, configurationSchemaFormAvroConverter);
} else {
ConfigurationSchemaDto storedConfigurationSchema = controlService.getConfigurationSchema(configurationSchema.getId());
Utils.checkNotNull(storedConfigurationSchema);
checkApplicationId(storedConfigurationSchema.getApplicationId());
configurationSchema.setSchema(storedConfigurationSchema.getSchema());
ConfigurationSchemaDto confSchema = confSchemaView.getSchema();
String applicationId = confSchema.getApplicationId();
checkApplicationId(applicationId);
String ctlSchemaId = confSchema.getCtlSchemaId();

if (isEmpty(ctlSchemaId)) {
if (confSchemaView.useExistingCtlSchema()) {
CtlSchemaReferenceDto metaInfo = confSchemaView.getExistingMetaInfo();
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) {
throw Utils.handleException(e);
}
}


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

public class ConfigurationSchemaViewDto extends BaseSchemaViewDto<ConfigurationSchemaDto> {

private static final long serialVersionUID = 8311415263866415408L;

public ConfigurationSchemaViewDto() {
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.plugin.PluginInfoDto;
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.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.schema.*;

import com.google.gwt.user.client.rpc.RemoteService;
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 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;

Expand Down

0 comments on commit 7de1877

Please sign in to comment.