diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/EcfVersionActivity.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/EcfVersionActivity.java index 588816281e..871314e84f 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/EcfVersionActivity.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/EcfVersionActivity.java @@ -102,7 +102,7 @@ public void onClick(ClickEvent event) { registrations.add(listView.getAddButton().addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { - KaaAdmin.getDataSource().saveEventClassFamilyVersion(place.getEcfId(), place.getEventClassDtoList(), + KaaAdmin.getDataSource().addEventClassFamilyVersionFromView(place.getEcfId(), place.getEventClassDtoList(), new AsyncCallback() { @Override public void onFailure(Throwable caught) { diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/DataSource.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/DataSource.java index 913dfcb195..e90bf41592 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/DataSource.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/data/DataSource.java @@ -36,9 +36,9 @@ import org.kaaproject.kaa.common.dto.ProfileFilterRecordDto; import org.kaaproject.kaa.common.dto.ProfileVersionPairDto; import org.kaaproject.kaa.common.dto.ServerProfileSchemaDto; +import org.kaaproject.kaa.common.dto.TenantDto; import org.kaaproject.kaa.common.dto.TopicDto; import org.kaaproject.kaa.common.dto.VersionDto; -import org.kaaproject.kaa.common.dto.admin.*; import org.kaaproject.kaa.common.dto.admin.RecordKey.RecordFiles; import org.kaaproject.kaa.common.dto.admin.SchemaVersions; import org.kaaproject.kaa.common.dto.admin.SdkPlatform; @@ -69,6 +69,7 @@ import org.kaaproject.kaa.server.admin.shared.schema.ConverterType; 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.EventClassViewDto; import org.kaaproject.kaa.server.admin.shared.schema.LogSchemaViewDto; import org.kaaproject.kaa.server.admin.shared.schema.NotificationSchemaViewDto; import org.kaaproject.kaa.server.admin.shared.schema.ProfileSchemaViewDto; @@ -233,7 +234,7 @@ public void loadTenants(final AsyncCallback> callback) { public void loadTenants(final AsyncCallback> callback, boolean refresh) { if (tenants == null || refresh) { - tenants = new ArrayList<>(); + tenants = new ArrayList(); tenantRpcService.getTenants(new DataCallback>(callback) { @Override protected void onResult(List result) { @@ -490,7 +491,7 @@ protected void onResult(RecordField result) { public void generateEcfVersionForm(String fileItemName, final AsyncCallback callback) { - rpcService.generateEcfSchemaForm(fileItemName, + eventRpcService.generateEcfSchemaForm(fileItemName, new DataCallback(callback) { @Override protected void onResult(RecordField result) { @@ -548,7 +549,7 @@ protected void onResult(EventClassFamilyDto result) { } public void getEventClassView(String eventClassId, final AsyncCallback callback) { - rpcService.getEventClassView(eventClassId, new DataCallback(callback) { + eventRpcService.getEventClassView(eventClassId, new DataCallback(callback) { @Override protected void onResult(EventClassViewDto result) { } @@ -557,7 +558,7 @@ protected void onResult(EventClassViewDto result) { } public void getEventClassViewByCtlSchemaId(EventClassDto eventClassViewDto, final AsyncCallback callback) { - rpcService.getEventClassViewByCtlSchemaId(eventClassViewDto, new DataCallback(callback) { + eventRpcService.getEventClassViewByCtlSchemaId(eventClassViewDto, new DataCallback(callback) { @Override protected void onResult(EventClassViewDto result) { } @@ -566,7 +567,7 @@ protected void onResult(EventClassViewDto result) { } public void saveEventClassView(EventClassViewDto eventClassViewDto, final AsyncCallback callback) { - rpcService.saveEventClassView(eventClassViewDto, new DataCallback(callback) { + eventRpcService.saveEventClassView(eventClassViewDto, new DataCallback(callback) { @Override protected void onResult(EventClassViewDto result) { } @@ -575,7 +576,7 @@ protected void onResult(EventClassViewDto result) { } public void createEventClassFormCtlSchema(CtlSchemaFormDto ctlSchemaFormDto, final AsyncCallback callback) { - rpcService.createEventClassFormCtlSchema(ctlSchemaFormDto , new DataCallback(callback) { + eventRpcService.createEventClassFormCtlSchema(ctlSchemaFormDto , new DataCallback(callback) { @Override protected void onResult(EventClassViewDto result) { } @@ -584,7 +585,7 @@ protected void onResult(EventClassViewDto result) { } public void getEventClassTypes(final AsyncCallback> callback) { - rpcService.getEventClassTypes(new DataCallback>(callback) { + eventRpcService.getEventClassTypes(new DataCallback>(callback) { @Override protected void onResult(List result) { } @@ -593,7 +594,7 @@ protected void onResult(List result) { } public void getEventClassFamilyVersions(String eventClassFamilyId, final AsyncCallback> callback) { - rpcService.getEventClassFamilyVersions(eventClassFamilyId, new DataCallback>(callback) { + eventRpcService.getEventClassFamilyVersions(eventClassFamilyId, new DataCallback>(callback) { @Override protected void onResult(List result) { } @@ -602,7 +603,7 @@ protected void onResult(List result) { } public void getLastCtlSchemaReferenceDto(String ctlSchemaId, final AsyncCallback callback) { - rpcService.getLastCtlSchemaReferenceDto(ctlSchemaId, new DataCallback(callback) { + ctlRpcService.getLastCtlSchemaReferenceDto(ctlSchemaId, new DataCallback(callback) { @Override protected void onResult(CtlSchemaReferenceDto result) { } @@ -610,19 +611,19 @@ protected void onResult(CtlSchemaReferenceDto result) { } - public void saveEventClassFamilyVersion(String eventClassFamilyId, List eventClassViewDto, final AsyncCallback callback) { - rpcService.saveEventClassFamilyVersion(eventClassFamilyId, eventClassViewDto, + public void addEventClassFamilyVersionFromView(String eventClassFamilyId, List eventClassViewDto, final AsyncCallback callback) { + eventRpcService.addEventClassFamilyVersionFromView(eventClassFamilyId, eventClassViewDto, new DataCallback(callback) { @Override protected void onResult(Void result) { - eventBus.fireEvent(new DataEvent(EventSchemaVersionDto.class)); + eventBus.fireEvent(new DataEvent(EventClassFamilyVersionDto.class)); //: todo } }); } public void getEventClassesByFamilyIdVersionAndType(String eventClassFamilyId, int version, EventClassType type, final AsyncCallback> callback) { - rpcService.getEventClassesByFamilyIdVersionAndType(eventClassFamilyId, version, type, + eventRpcService.getEventClassesByFamilyIdVersionAndType(eventClassFamilyId, version, type, new DataCallback>(callback) { @Override protected void onResult(List result) { @@ -632,7 +633,7 @@ protected void onResult(List result) { public void addEventClassFamilyVersion(String eventClassFamilyId, EventClassFamilyVersionDto eventClassFamilyVersion, final AsyncCallback callback) { - rpcService.addEventClassFamilyVersion(eventClassFamilyId, eventClassFamilyVersion, + eventRpcService.addEventClassFamilyVersion(eventClassFamilyId, eventClassFamilyVersion, new DataCallback(callback) { @Override protected void onResult(Void result) { @@ -948,19 +949,19 @@ protected void onResult(List result) { }); } - public void getLastCreatedCTLSchemaByFqnAndVersion(String fqn, Integer version, - final AsyncCallback callback) { - rpcService.getLastCreatedCTLSchemaByFqnAndVersion(fqn, version, - new DataCallback(callback) { - @Override - protected void onResult(CTLSchemaMetaInfoDto result) { - } - }); - } +// public void getLastCreatedCTLSchemaByFqnAndVersion(String fqn, Integer version, +// final AsyncCallback callback) { +// ctlRpcService.getLastCreatedCTLSchemaByFqnAndVersion(fqn, version, +// new DataCallback(callback) { +// @Override +// protected void onResult(CTLSchemaMetaInfoDto result) { +// } +// }); +// } public void getCTLSchemaById(String ctlSchemaId, final AsyncCallback callback) { - rpcService.getCTLSchemaById(ctlSchemaId, + ctlRpcService.getCTLSchemaById(ctlSchemaId, new DataCallback(callback) { @Override protected void onResult(CTLSchemaDto result) { diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/EventClassPlace.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/EventClassPlace.java index 19afddd393..f1b4ebf33d 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/EventClassPlace.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/EventClassPlace.java @@ -58,7 +58,7 @@ public void setNameEC(String nameEC) { @Override public String getName() { - return Utils.constants.schemas(); + return Utils.constants.versions(); } @Prefix(value = "eventClass") diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/SchemasPlaceApplication.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/SchemasPlaceApplication.java index 6f61fa2a56..42bef27b41 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/SchemasPlaceApplication.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/SchemasPlaceApplication.java @@ -42,7 +42,7 @@ public String getApplicationId() { @Override public String getName() { - return Utils.constants.schemas(); + return Utils.constants.versions(); } public static abstract class Tokenizer

implements PlaceTokenizer

, PlaceConstants { diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/SchemasPlaceEvent.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/SchemasPlaceEvent.java index 3d83b505a0..b71a01e60b 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/SchemasPlaceEvent.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/SchemasPlaceEvent.java @@ -76,7 +76,7 @@ public int getEcfVersion() { @Override public String getName() { - return Utils.constants.schemas(); + return Utils.constants.versions(); } public static abstract class Tokenizer

implements PlaceTokenizer

, PlaceConstants { diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/event/EcfViewImpl.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/event/EcfViewImpl.java index d57accca6e..917c17c180 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/event/EcfViewImpl.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/event/EcfViewImpl.java @@ -166,7 +166,7 @@ protected void initDetailsTable() { ecfVersionsGrid = new EcfVersionsGrid(); ecfVersionsGrid.setSize("700px", "200px"); - Label ecfVersionsLabel = new Label(Utils.constants.schemas()); + Label ecfVersionsLabel = new Label(Utils.constants.versions()); ecfVersionsLabel.addStyleName(Utils.kaaAdminStyle.bAppContentTitleLabel()); addEcfVersionButton = new Button(Utils.constants.addSchema()); diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/controller/EventController.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/controller/EventController.java index 72b62cab02..19779bdace 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/controller/EventController.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/controller/EventController.java @@ -26,6 +26,7 @@ import org.kaaproject.kaa.common.dto.event.EcfInfoDto; import org.kaaproject.kaa.common.dto.event.EventClassDto; import org.kaaproject.kaa.common.dto.event.EventClassFamilyDto; +import org.kaaproject.kaa.common.dto.event.EventClassFamilyVersionDto; import org.kaaproject.kaa.common.dto.event.EventClassType; import org.kaaproject.kaa.server.admin.shared.services.KaaAdminServiceException; import org.springframework.http.HttpStatus; @@ -113,36 +114,6 @@ public EventClassFamilyDto editEventClassFamily( return eventService.editEventClassFamily(eventClassFamily); } - /** - * Adds the event class family schema to the event class family with - * specific id. Current user will be marked as creator of schema. - * - * @param eventClassFamilyId the event class family id - * @param file the file - * @throws KaaAdminServiceException the kaa admin service exception - */ - @ApiOperation(value = "Add event class family schema", - notes = "Adds the event class family schema to the event class family with the specified ID. The current user will be marked as the creator of " + - "schema. Only users with the TENANT_ADMIN role are allowed to perform this operation.") - @ApiResponses(value = { - @ApiResponse(code = 400, message = "The specified event class family schema is not a valid avro schema"), - @ApiResponse(code = 401, message = "The user is not authenticated or invalid credentials were provided"), - @ApiResponse(code = 403, message = "The authenticated user does not have the required role (TENANT_ADMIN) or the Tenant ID of the specified " + - "event class family does not match the Tenant ID of the authenticated user"), - @ApiResponse(code = 404, message = "A file with the event class family schema was not found in the form data or an event class family with the " + - "specified ID does not exist"), - @ApiResponse(code = 500, message = "An unexpected error occurred on the server side")}) - @RequestMapping(value = "addEventClassFamilySchema", method = RequestMethod.POST, consumes = {"multipart/mixed", "multipart/form-data"}) - @ResponseStatus(value = HttpStatus.OK) - public void addEventClassFamilySchema( - @ApiParam(name = "eventClassFamilyId", value = "A unique event class family identifier", required = true) - @RequestPart(value = "eventClassFamilyId") String eventClassFamilyId, - @ApiParam(name = "file", value = "Event class family schema represented in json format", required = true) - @RequestPart("file") MultipartFile file) throws KaaAdminServiceException { - byte[] data = getFileContent(file); - eventService.addEventClassFamilySchema(eventClassFamilyId, data); - } - /** * Gets the event classes by family its id, version and type. * @@ -299,4 +270,51 @@ public List getEventClassFamiliesByApplicationToken( return eventService.getEventClassFamiliesByApplicationToken(applicationToken); } + /** + * Gets the event class family versions by its id. + * + * @param eventClassFamilyId + * the event class family id + * @return the list of event class family version dto + * @throws KaaAdminServiceException + * the kaa admin service exception + */ + @RequestMapping(value = "eventClassFamilyVersions/{eventClassFamilyId}", method = RequestMethod.GET) + @ResponseBody + public List getEventClassFamilyVersions(@PathVariable String eventClassFamilyId) throws KaaAdminServiceException { + return eventService.getEventClassFamilyVersions(eventClassFamilyId); + } + + /** + * Adds the event class family version to existing event class family with + * specific id. Current user will be marked as creator of schema. + * + * @param eventClassFamilyId + * the event class family id + * @param eventClassFamilyVersion + * the version of event class family + * @throws KaaAdminServiceException + * the kaa admin service exception + */ + @ApiOperation(value = "Add event class family schema", + notes = "Adds the event class family schema to the event class family with the specified ID. The current user will be marked as the creator of " + + "schema. Only users with the TENANT_ADMIN role are allowed to perform this operation.") + @ApiResponses(value = { + @ApiResponse(code = 400, message = "The specified event class family schema is not a valid avro schema"), + @ApiResponse(code = 401, message = "The user is not authenticated or invalid credentials were provided"), + @ApiResponse(code = 403, message = "The authenticated user does not have the required role (TENANT_ADMIN) or the Tenant ID of the specified " + + "event class family does not match the Tenant ID of the authenticated user"), + @ApiResponse(code = 404, message = "A file with the event class family schema was not found in the form data or an event class family with the " + + "specified ID does not exist"), + @ApiResponse(code = 500, message = "An unexpected error occurred on the server side")}) + @RequestMapping(value = "addEventClassFamilyVersion", method = RequestMethod.POST, consumes = { "multipart/mixed", "multipart/form-data" }) + @ResponseStatus(value = HttpStatus.OK) + public void addEventClassFamilyVersion( + @ApiParam(name = "eventClassFamilyId", value = "A unique event class family identifier", required = true) + @RequestPart(value = "eventClassFamilyId") String eventClassFamilyId, + @ApiParam(name = "eventClassFamilyVersion", value = "Version of ECF", required = true) + @RequestPart(value = "eventClassFamilyVersion") EventClassFamilyVersionDto eventClassFamilyVersion) throws KaaAdminServiceException { + eventService.addEventClassFamilyVersion(eventClassFamilyId, eventClassFamilyVersion); + } + } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/CtlServiceImpl.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/CtlServiceImpl.java index d4fe3c4d05..bf75b9328b 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/CtlServiceImpl.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/CtlServiceImpl.java @@ -412,9 +412,8 @@ public CtlSchemaFormDto saveCTLSchemaForm(CtlSchemaFormDto ctlSchemaForm, Conver @Override public List getAvailableApplicationCTLSchemaReferences(String applicationId) throws KaaAdminServiceException { - checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); + checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER, KaaAuthorityDto.TENANT_ADMIN); try { - this.checkApplicationId(applicationId); AuthUserDto currentUser = getCurrentUser(); List result = new ArrayList<>(); List availableMetaInfo = controlService.getAvailableCTLSchemasMetaInfoForApplication(currentUser.getTenantId(), applicationId); @@ -655,4 +654,19 @@ private String asText(Collection types) { return message.toString(); } + @Override + public CtlSchemaReferenceDto getLastCtlSchemaReferenceDto(String ctlSchemaId) throws KaaAdminServiceException { + try { + if (!isEmpty(ctlSchemaId)) { + CTLSchemaDto ctlSchemaDto = controlService.getCTLSchemaById(ctlSchemaId); + CtlSchemaReferenceDto ctlSchemaReference = getAvailableApplicationCTLSchemaReferences(null).stream(). + filter(ctlSchemaReferenceDto -> ctlSchemaReferenceDto.getMetaInfo().getId().equals(ctlSchemaDto.getMetaInfo().getId())).findFirst().get(); + return ctlSchemaReference; + } + } catch (Exception e) { + throw Utils.handleException(e); + } + return null; + } + } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/EventServiceImpl.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/EventServiceImpl.java index be486d4d87..1083c6e66e 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/EventServiceImpl.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/EventServiceImpl.java @@ -17,22 +17,29 @@ package org.kaaproject.kaa.server.admin.services; import org.apache.avro.Schema; -import org.kaaproject.avro.ui.converter.SchemaFormAvroConverter; import org.kaaproject.avro.ui.shared.RecordField; import org.kaaproject.kaa.common.dto.KaaAuthorityDto; +import org.kaaproject.kaa.common.dto.ctl.CTLSchemaDto; import org.kaaproject.kaa.common.dto.event.AefMapInfoDto; import org.kaaproject.kaa.common.dto.event.ApplicationEventFamilyMapDto; import org.kaaproject.kaa.common.dto.event.EcfInfoDto; import org.kaaproject.kaa.common.dto.event.EventClassDto; import org.kaaproject.kaa.common.dto.event.EventClassFamilyDto; +import org.kaaproject.kaa.common.dto.event.EventClassFamilyVersionDto; import org.kaaproject.kaa.common.dto.event.EventClassType; -import org.kaaproject.kaa.common.dto.event.EventSchemaVersionDto; import org.kaaproject.kaa.server.admin.services.util.Utils; +import org.kaaproject.kaa.server.admin.shared.schema.ConverterType; +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.EventClassViewDto; +import org.kaaproject.kaa.server.admin.shared.services.CtlService; import org.kaaproject.kaa.server.admin.shared.services.EventService; import org.kaaproject.kaa.server.admin.shared.services.KaaAdminServiceException; -import org.kaaproject.kaa.server.control.service.sdk.SchemaUtil; +import org.kaaproject.kaa.server.control.service.exception.ControlServiceException; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.ArrayList; import java.util.List; import static org.kaaproject.kaa.server.admin.services.util.Utils.getCurrentUser; @@ -41,6 +48,9 @@ @Service("eventService") public class EventServiceImpl extends AbstractAdminService implements EventService { + @Autowired + CtlService ctlService; + @Override public List getEventClassFamilies() throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_ADMIN); @@ -58,11 +68,6 @@ public EventClassFamilyDto getEventClassFamily(String eventClassFamilyId) throws EventClassFamilyDto eventClassFamily = controlService.getEventClassFamily(eventClassFamilyId); Utils.checkNotNull(eventClassFamily); checkTenantId(eventClassFamily.getTenantId()); - for (EventSchemaVersionDto eventSchemaVersion : eventClassFamily.getSchemas()) { - Schema schema = new Schema.Parser().parse(eventSchemaVersion.getSchema()); - RecordField schemaForm = ecfSchemaFormAvroConverter.createSchemaFormFromSchema(schema); - eventSchemaVersion.setSchemaForm(schemaForm); - } return eventClassFamily; } catch (Exception e) { throw Utils.handleException(e); @@ -89,35 +94,17 @@ public EventClassFamilyDto editEventClassFamily(EventClassFamilyDto eventClassFa } @Override - public void addEventClassFamilySchema(String eventClassFamilyId, byte[] data) throws KaaAdminServiceException { + public void addEventClassFamilyVersion(String eventClassFamilyId, EventClassFamilyVersionDto eventClassFamilyVersion) throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_ADMIN); try { checkEventClassFamilyId(eventClassFamilyId); - String schema = new String(data); - SchemaUtil.compileAvroSchema(validateSchema(schema, false)); EventClassFamilyDto storedEventClassFamily = controlService.getEventClassFamily(eventClassFamilyId); Utils.checkNotNull(storedEventClassFamily); checkTenantId(storedEventClassFamily.getTenantId()); String username = getCurrentUser().getUsername(); - controlService.addEventClassFamilySchema(eventClassFamilyId, schema, username); - } catch (Exception e) { - throw Utils.handleException(e); - } - } - - @Override - public List getEventClassesByFamilyIdVersionAndType(String eventClassFamilyId, int version, EventClassType type) - throws KaaAdminServiceException { - checkAuthority(KaaAuthorityDto.TENANT_ADMIN, KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); - try { - checkEventClassFamilyId(eventClassFamilyId); - EventClassFamilyDto storedEventClassFamily = controlService.getEventClassFamily(eventClassFamilyId); - Utils.checkNotNull(storedEventClassFamily); - checkTenantId(storedEventClassFamily.getTenantId()); - - return controlService.getEventClassesByFamilyIdVersionAndType(eventClassFamilyId, version, type); + controlService.addEventClassFamilyVersion(eventClassFamilyId, eventClassFamilyVersion, username); } catch (Exception e) { throw Utils.handleException(e); } @@ -236,20 +223,134 @@ public RecordField generateEcfSchemaForm(String fileItemName) throws KaaAdminSer } @Override - public void addEventClassFamilySchemaForm(String eventClassFamilyId, RecordField schemaForm) throws KaaAdminServiceException { + public List getEventClassFamilyVersions(String eventClassFamilyId) throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_ADMIN); try { - Schema schema = ecfSchemaFormAvroConverter.createSchemaFromSchemaForm(schemaForm); - String schemaString = SchemaFormAvroConverter.createSchemaString(schema, true); + return controlService.getEventClassFamilyVersions(eventClassFamilyId); + } catch (Exception e) { + throw Utils.handleException(e); + } + } + + @Override + public EventClassViewDto getEventClassView(String eventClassId) throws KaaAdminServiceException { + checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER, KaaAuthorityDto.TENANT_ADMIN); + try { + EventClassDto eventClassDto = getEventClass(eventClassId); + CTLSchemaDto ctlSchemaDto = controlService.getCTLSchemaById(eventClassDto.getCtlSchemaId()); + EventClassViewDto eventClassViewDto = new EventClassViewDto(eventClassDto, toCtlSchemaForm(ctlSchemaDto, ConverterType.FORM_AVRO_CONVERTER)); + return eventClassViewDto; + } catch (Exception e) { + throw Utils.handleException(e); + } + } + @Override + public EventClassViewDto getEventClassViewByCtlSchemaId(EventClassDto eventClassDto) throws KaaAdminServiceException { + try { + CTLSchemaDto ctlSchemaDto = controlService.getCTLSchemaById(eventClassDto.getCtlSchemaId()); + EventClassViewDto eventClassViewDto = new EventClassViewDto(eventClassDto, toCtlSchemaForm(ctlSchemaDto, ConverterType.FORM_AVRO_CONVERTER)); + eventClassDto.setCreatedTime(System.currentTimeMillis()); + eventClassDto.setFqn(ctlSchemaDto.getMetaInfo().getFqn()); + eventClassDto.setTenantId(getCurrentUser().getTenantId()); + return eventClassViewDto; + } catch (ControlServiceException e) { + throw Utils.handleException(e); + } + } + + @Override + public EventClassDto getEventClass(String eventClassId) throws KaaAdminServiceException { + try { + return controlService.getEventClassById(eventClassId); + } catch (ControlServiceException e) { + throw Utils.handleException(e); + } + } + + @Override + public EventClassViewDto saveEventClassView(EventClassViewDto eventClassViewDto) throws KaaAdminServiceException { + checkAuthority(KaaAuthorityDto.TENANT_ADMIN); + try { + EventClassDto eventClassDto = eventClassViewDto.getSchema(); + String ctlSchemaId = eventClassDto.getCtlSchemaId(); + CtlSchemaFormDto ctlSchemaForm = null; + if (isEmpty(ctlSchemaId)) { + if (eventClassViewDto.useExistingCtlSchema()) { + CtlSchemaReferenceDto metaInfo = eventClassViewDto.getExistingMetaInfo(); + CTLSchemaDto schema = controlService.getCTLSchemaByFqnVersionTenantIdAndApplicationId(metaInfo.getMetaInfo().getFqn(), + metaInfo.getVersion(), + metaInfo.getMetaInfo().getTenantId(), + metaInfo.getMetaInfo().getApplicationId()); + eventClassDto.setCtlSchemaId(schema.getId()); + } else { + ctlSchemaForm = ctlService.saveCTLSchemaForm(eventClassViewDto.getCtlSchemaForm(), ConverterType.FORM_AVRO_CONVERTER); + eventClassDto.setCtlSchemaId(ctlSchemaForm.getId()); + } + } + return getEventClassViewByCtlSchemaId(eventClassDto); + } catch (Exception e) { + throw Utils.handleException(e); + } + } + + @Override + public EventClassViewDto createEventClassFormCtlSchema(CtlSchemaFormDto ctlSchemaForm) throws KaaAdminServiceException { + checkAuthority(KaaAuthorityDto.TENANT_ADMIN); + try { + checkTenantId(ctlSchemaForm.getMetaInfo().getTenantId()); + EventClassDto eventClassDto = new EventClassDto(); + eventClassDto.setName(ctlSchemaForm.getSchema().getDisplayNameFieldValue()); + eventClassDto.setDescription(ctlSchemaForm.getSchema().getDescriptionFieldValue()); + CtlSchemaFormDto savedCtlSchemaForm = ctlService.saveCTLSchemaForm(ctlSchemaForm, ConverterType.FORM_AVRO_CONVERTER); + eventClassDto.setCtlSchemaId(savedCtlSchemaForm.getId()); + return getEventClassViewByCtlSchemaId(eventClassDto); + } catch (Exception e) { + throw Utils.handleException(e); + } + } + + @Override + public List getEventClassTypes() throws KaaAdminServiceException { + List eventClassTypeList = new ArrayList<>(EventClassType.values().length); + for (EventClassType eventClassType : EventClassType.values()) { + eventClassTypeList.add(eventClassType.name()); + } + return eventClassTypeList; + } + + @Override + public void addEventClassFamilyVersionFromView(String eventClassFamilyId, List eventClassViewDto) throws KaaAdminServiceException { + EventClassFamilyVersionDto eventClassFamilyVersionDto = new EventClassFamilyVersionDto(); + eventClassFamilyVersionDto.setCreatedTime(System.currentTimeMillis()); + eventClassFamilyVersionDto.setCreatedUsername(getCurrentUser().getUsername()); + List eventClassDtoList = new ArrayList<>(); + for(EventClassViewDto classViewDto : eventClassViewDto){ + EventClassDto eventClassDto = classViewDto.getSchema(); + eventClassDto.setId(null); + eventClassDto.setFqn(classViewDto.getExistingMetaInfo().getMetaInfo().getFqn()); + eventClassDto.setCreatedUsername(getCurrentUser().getUsername()); + eventClassDto.setCreatedTime(System.currentTimeMillis()); + eventClassDtoList.add(eventClassDto); + } + eventClassFamilyVersionDto.setRecords(eventClassDtoList); + addEventClassFamilyVersion(eventClassFamilyId, eventClassFamilyVersionDto); + } + + @Override + public List getEventClassesByFamilyIdVersionAndType(String eventClassFamilyId, int version, EventClassType type) + throws KaaAdminServiceException { + checkAuthority(KaaAuthorityDto.TENANT_ADMIN, KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); + try { + checkEventClassFamilyId(eventClassFamilyId); EventClassFamilyDto storedEventClassFamily = controlService.getEventClassFamily(eventClassFamilyId); Utils.checkNotNull(storedEventClassFamily); checkTenantId(storedEventClassFamily.getTenantId()); - String username = getCurrentUser().getUsername(); - controlService.addEventClassFamilySchema(eventClassFamilyId, schemaString, username); + return controlService.getEventClassesByFamilyIdVersionAndType(eventClassFamilyId, version, type); } catch (Exception e) { throw Utils.handleException(e); } } + } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/shared/services/CtlService.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/shared/services/CtlService.java index 606f4ede75..26eccc5323 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/shared/services/CtlService.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/shared/services/CtlService.java @@ -84,4 +84,6 @@ public interface CtlService extends RemoteService { String getFlatSchemaByCtlSchemaId(String logSchemaId) throws KaaAdminServiceException; + CtlSchemaReferenceDto getLastCtlSchemaReferenceDto(String ctlSchemaId) throws KaaAdminServiceException; + } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/shared/services/EventService.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/shared/services/EventService.java index fedbcc9017..7e6bd73f5d 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/shared/services/EventService.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/shared/services/EventService.java @@ -24,7 +24,11 @@ import org.kaaproject.kaa.common.dto.event.EcfInfoDto; import org.kaaproject.kaa.common.dto.event.EventClassDto; import org.kaaproject.kaa.common.dto.event.EventClassFamilyDto; +import org.kaaproject.kaa.common.dto.event.EventClassFamilyVersionDto; import org.kaaproject.kaa.common.dto.event.EventClassType; +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.EventClassViewDto; import java.util.List; @@ -37,8 +41,6 @@ public interface EventService extends RemoteService { EventClassFamilyDto editEventClassFamily(EventClassFamilyDto eventClassFamily) throws KaaAdminServiceException; - void addEventClassFamilySchema(String eventClassFamilyId, byte[] schema) throws KaaAdminServiceException; - List getEventClassesByFamilyIdVersionAndType(String eventClassFamilyId, int version, EventClassType type) throws KaaAdminServiceException; List getApplicationEventFamilyMapsByApplicationToken(String applicationToken) throws KaaAdminServiceException; @@ -61,6 +63,22 @@ public interface EventService extends RemoteService { RecordField generateEcfSchemaForm(String fileItemName) throws KaaAdminServiceException; - void addEventClassFamilySchemaForm(String eventClassFamilyId, RecordField schemaForm) throws KaaAdminServiceException; + List getEventClassFamilyVersions(String eventClassFamilyId) throws KaaAdminServiceException; + + void addEventClassFamilyVersion(String eventClassFamilyId, EventClassFamilyVersionDto eventClassFamilyVersion) throws KaaAdminServiceException; + + EventClassViewDto getEventClassView(String eventClassId) throws KaaAdminServiceException; + + EventClassViewDto getEventClassViewByCtlSchemaId(EventClassDto eventClassDto) throws KaaAdminServiceException; + + EventClassDto getEventClass(String eventClassId) throws KaaAdminServiceException; + + EventClassViewDto saveEventClassView(EventClassViewDto eventClassViewDto) throws KaaAdminServiceException; + + EventClassViewDto createEventClassFormCtlSchema(CtlSchemaFormDto ctlSchemaForm) throws KaaAdminServiceException; + + List getEventClassTypes() throws KaaAdminServiceException; + + void addEventClassFamilyVersionFromView(String eventClassFamilyId, List eventClassViewDto) throws KaaAdminServiceException; } diff --git a/server/node/src/test/java/org/kaaproject/kaa/server/control/ControlServerEventClassFamilyIT.java b/server/node/src/test/java/org/kaaproject/kaa/server/control/ControlServerEventClassFamilyIT.java index cf620094ec..2a04564eb9 100644 --- a/server/node/src/test/java/org/kaaproject/kaa/server/control/ControlServerEventClassFamilyIT.java +++ b/server/node/src/test/java/org/kaaproject/kaa/server/control/ControlServerEventClassFamilyIT.java @@ -22,6 +22,7 @@ import org.junit.Assert; import org.junit.Test; +import org.kaaproject.kaa.common.dto.admin.UserDto; import org.kaaproject.kaa.common.dto.event.EventClassDto; import org.kaaproject.kaa.common.dto.event.EventClassFamilyDto; import org.kaaproject.kaa.common.dto.event.EventClassType; @@ -39,7 +40,7 @@ public class ControlServerEventClassFamilyIT extends AbstractTestControlServer { protected boolean createTenantAdminNeeded() { return false; } - + /* (non-Javadoc) * @see org.kaaproject.kaa.server.control.AbstractTestControlServer#createTenantDeveloperNeeded() */ @@ -47,7 +48,7 @@ protected boolean createTenantAdminNeeded() { protected boolean createTenantDeveloperNeeded() { return false; } - + /** * Test create event class family. * @@ -58,7 +59,7 @@ public void testCreateEventClassFamily() throws Exception { EventClassFamilyDto eventClassFamily = createEventClassFamily(); Assert.assertFalse(strIsEmpty(eventClassFamily.getId())); } - + /** * Test get event class family. * @@ -67,13 +68,13 @@ public void testCreateEventClassFamily() throws Exception { @Test public void testGetEventClassFamily() throws Exception { EventClassFamilyDto eventClassFamily = createEventClassFamily(); - + EventClassFamilyDto storedEventClassFamily = client.getEventClassFamilyById(eventClassFamily.getId()); - + Assert.assertNotNull(storedEventClassFamily); assertEventClassFamiliesEquals(eventClassFamily, storedEventClassFamily); } - + /** * Test get event class families by tenant id. * @@ -81,28 +82,28 @@ public void testGetEventClassFamily() throws Exception { */ @Test public void testGetEventClassFamiliesByTenantId() throws Exception { - List eventClassFamilies = new ArrayList<>(10); - org.kaaproject.kaa.common.dto.admin.UserDto tenant = createTenantAdmin(tenantAdminUser); + List eventClassFamilies = new ArrayList<>(10); + UserDto tenant = createTenantAdmin(tenantAdminUser); loginTenantAdmin(tenantAdminUser); - for (int i=0;i<10;i++) { - EventClassFamilyDto eventClassFamily = createEventClassFamily(tenantAdminDto.getId(), ""+i); + for (int i = 0; i < 10; i++) { + EventClassFamilyDto eventClassFamily = createEventClassFamily(tenant.getId(), "" + i); eventClassFamilies.add(eventClassFamily); } - + Collections.sort(eventClassFamilies, new IdComparator()); - + List storedEventClassFamilies = client.getEventClassFamilies(); Collections.sort(storedEventClassFamilies, new IdComparator()); - + Assert.assertEquals(eventClassFamilies.size(), storedEventClassFamilies.size()); - for (int i=0;i eventClasses = client.getEventClassesByFamilyIdVersionAndType(eventClassFamily.getId(), 1, EventClassType.EVENT); Assert.assertNotNull(eventClasses); @@ -135,10 +136,10 @@ public void testGetEventClassesByFamilyIdVersionAndType() throws Exception { eventClassFamilyVersion = client.getEventClassFamilyVersionsById(eventClassFamily.getId()).get(0); for (EventClassDto eventClass : eventClasses) { Assert.assertEquals(eventClassFamilyVersion.getId(), eventClass.getEcfvId()); - Assert.assertEquals(0, eventClass.getVersion()); + Assert.assertEquals(1, eventClass.getVersion()); } } - + /** * Test duplicate event class family name. * @@ -167,10 +168,10 @@ public void executeRestCall() throws Exception { */ @Test public void testAddEventClassFamilyVersion() throws Exception { - TenantUserDto tenant = createTenant(tenantAdminUser); + UserDto tenantAdmin = createTenantAdmin(tenantAdminUser); loginTenantAdmin(tenantAdminUser); - EventClassFamilyDto eventClassFamily = createEventClassFamily(tenant.getTenantId()); - EventClassFamilyVersionDto eventClassFamilyVersion = createEventClassFamilyVersion(tenant.getTenantId()); + EventClassFamilyDto eventClassFamily = createEventClassFamily(tenantAdmin.getTenantId()); + EventClassFamilyVersionDto eventClassFamilyVersion = createEventClassFamilyVersion(tenantAdmin.getTenantId()); client.addEventClassFamilyVersion(eventClassFamily.getId(), eventClassFamilyVersion); List schemas = eventClassService.findEventClassFamilyVersionsById(eventClassFamily.getId()); Assert.assertNotNull(schemas); @@ -212,7 +213,7 @@ public void executeRestCall() throws Exception { /** * Assert event class families equals. * - * @param eventClassFamily the event class family + * @param eventClassFamily the event class family * @param storedEventClassFamily the stored event class family */ private void assertEventClassFamiliesEquals(EventClassFamilyDto eventClassFamily, EventClassFamilyDto storedEventClassFamily) {