Skip to content

Commit

Permalink
KAA-1146: Admin-UI changes
Browse files Browse the repository at this point in the history
  • Loading branch information
vchizhevsky committed Aug 16, 2016
1 parent b57bc30 commit 9ba7be4
Show file tree
Hide file tree
Showing 15 changed files with 154 additions and 81 deletions.
Expand Up @@ -88,6 +88,8 @@ public interface EventClassService {
*/
List<EventClassDto> findEventClassesByFamilyIdVersionAndType(String ecfId, int version, EventClassType type);

boolean validateEventClassFamilyFqns(String eventClassFamilyId, List<String> fqns);

/**
* Find event class family by tenant id and name.
*
Expand Down Expand Up @@ -132,4 +134,6 @@ public interface EventClassService {
* @return the event class dto
*/
boolean isValidECFListInSdkProfile(List<AefMapInfoDto> ecfList);

List<String> getFqnListForECF(String eventClassId);
}
Expand Up @@ -159,7 +159,7 @@ public void addEventClassFamilyVersion(String eventClassFamilyId,
for (EventClassDto eventClass : records) {
fqns.add(eventClass.getFqn());
}
if (validateEventClassFamilyFqns(eventClassFamily, fqns)) {
if (validateEventClassFamilyFqns(eventClassFamily.getId(), fqns)) {
List<EventClassFamilyVersionDto> schemasDto = findEventClassFamilyVersionsById(eventClassFamilyId);
int version = 1;
if (schemasDto != null && !schemasDto.isEmpty()) {
Expand Down Expand Up @@ -206,12 +206,9 @@ private void setBackreference(List<EventClassFamilyVersion> ecfvList) {
ecfvList.forEach(ecfv -> ecfv.getRecords().forEach(ec -> ec.setEcfv(ecfv)));
}

private boolean validateEventClassFamilyFqns(EventClassFamilyDto eventClassFamily, List<String> fqns) {
String ecfId = eventClassFamily.getId();
EventClassFamily ecf = eventClassFamilyDao.findById(ecfId);
List<String> storedFQNs = new ArrayList<>();
ecf.getSchemas().forEach(ecfv -> ecfv.getRecords().forEach(ec -> storedFQNs.add(ec.getFqn())));

@Override
public boolean validateEventClassFamilyFqns(String eventClassFamilyId, List<String> fqns) {
List<String> storedFQNs = getFqnListForECF(eventClassFamilyId);
for (String storedFQN : storedFQNs) {
long duplicatedFqnCount = fqns.stream().filter(fqn -> fqn.equals(storedFQN)).count();
if (duplicatedFqnCount > 0) return false;
Expand Down Expand Up @@ -282,4 +279,17 @@ public boolean isValidECFListInSdkProfile(List<AefMapInfoDto> ecfList) {

return true;
}

@Override
public List<String> getFqnListForECF(String eventClassId) {
if (isValidSqlId(eventClassId)) {
LOG.debug("Find event class by id [{}] ", eventClassId);
List<String> storedFQNs = new ArrayList<>();
EventClassFamily ecf = eventClassFamilyDao.findById(eventClassId);
ecf.getSchemas().forEach(ecfv -> ecfv.getRecords().forEach(ec -> storedFQNs.add(ec.getFqn())));
return storedFQNs;
} else {
throw new IncorrectParameterException("Incorrect event class id: " + eventClassId);
}
}
}
Expand Up @@ -79,7 +79,7 @@ public void onClick(ClickEvent event) {
}
}));

KaaAdmin.getDataSource().getAvailableApplicationCTLSchemaReferences(null, new BusyAsyncCallback<List<CtlSchemaReferenceDto>>() {
KaaAdmin.getDataSource().getTenantLevelCTLSchemaReferenceForECF(place.getEcfId(), place.getEventClassDtoList(), new BusyAsyncCallback<List<CtlSchemaReferenceDto>>() {
@Override
public void onFailureImpl(Throwable caught) {
Utils.handleException(caught, detailsView);
Expand Down
Expand Up @@ -152,6 +152,19 @@ protected void onSave() {

List<String> aefMapIds = new ArrayList<>();
List<AefMapInfoDto> aefMaps = detailsView.getSelectedAefMaps().getValues();

KaaAdmin.getDataSource().validateECFListInSdkProfile(aefMaps, new AsyncCallback<Void>() {
@Override
public void onFailure(Throwable caught) {
Utils.handleException(caught, detailsView);
}

@Override
public void onSuccess(Void aVoid) {

}
});

if (aefMaps != null) {
for (AefMapInfoDto aefMap : aefMaps) {
aefMapIds.add(aefMap.getAefMapId());
Expand Down
Expand Up @@ -36,6 +36,7 @@
import org.kaaproject.kaa.server.admin.shared.schema.CtlSchemaReferenceDto;
import org.kaaproject.kaa.server.admin.shared.schema.EventClassViewDto;

import java.util.ArrayList;
import java.util.List;

public class EventClassActivity
Expand All @@ -61,13 +62,23 @@ protected EventClassView getView(boolean create) {

@Override
protected void getEntity(String eventClassId,
AsyncCallback<EventClassViewDto> callback) {
final AsyncCallback<EventClassViewDto> callback) {
if (place.getEventClassDtoList() != null) {
EventClassDto eventClassDto = place.getEventClassDtoList().get(Integer.valueOf(eventClassId) - 1).getSchema();
KaaAdmin.getDataSource().getEventClassViewByCtlSchemaId(eventClassDto, callback);
detailsView.getEventClassTypes().setValue(eventClassDto.getType().toString());
detailsView.getEventClassTypes().setValue(eventClassDto.getType().name());
} else {
KaaAdmin.getDataSource().getEventClassView(eventClassId, callback);
KaaAdmin.getDataSource().getEventClassView(eventClassId, new AsyncCallback<EventClassViewDto>() {
@Override
public void onFailure(Throwable caught) {
Utils.handleException(caught, EventClassActivity.this.detailsView);
}
@Override
public void onSuccess(EventClassViewDto eventClassViewDto) {
detailsView.getEventClassTypes().setValue(eventClassViewDto.getSchema().getType().name());
callback.onSuccess(eventClassViewDto);
}
});
}
}

Expand Down Expand Up @@ -150,18 +161,11 @@ protected void onEntityRetrieved() {
super.onEntityRetrieved();
ValueListBox<String> eventClassTypes = this.detailsView.getEventClassTypes();
if (eventClassTypes != null) {
KaaAdmin.getDataSource().getEventClassTypes(new AsyncCallback<List<String>>() {

@Override
public void onFailure(Throwable caught) {
Utils.handleException(caught, EventClassActivity.this.detailsView);
}

@Override
public void onSuccess(List<String> result) {
EventClassActivity.this.detailsView.getEventClassTypes().setAcceptableValues(result);
}
});
List<String> eventClassTypeList = new ArrayList<>();
for (EventClassType eventClassType : EventClassType.values()) {
eventClassTypeList.add(eventClassType.name());
}
EventClassActivity.this.detailsView.getEventClassTypes().setAcceptableValues(eventClassTypeList);
}

if (place.getCtlSchemaId() != null) {
Expand Down
Expand Up @@ -584,15 +584,6 @@ protected void onResult(EventClassViewDto result) {

}

public void getEventClassTypes(final AsyncCallback<List<String>> callback) {
eventRpcService.getEventClassTypes(new DataCallback<List<String>>(callback) {
@Override
protected void onResult(List<String> result) {
}
});

}

public void getEventClassFamilyVersions(String eventClassFamilyId, final AsyncCallback<List<EventClassFamilyVersionDto>> callback) {
eventRpcService.getEventClassFamilyVersions(eventClassFamilyId, new DataCallback<List<EventClassFamilyVersionDto>>(callback) {
@Override
Expand All @@ -616,7 +607,7 @@ public void addEventClassFamilyVersionFromView(String eventClassFamilyId, List<E
new DataCallback<Void>(callback) {
@Override
protected void onResult(Void result) {
eventBus.fireEvent(new DataEvent(EventClassFamilyVersionDto.class)); //: todo

}
});
}
Expand All @@ -641,6 +632,14 @@ protected void onResult(Void result) {
});
}

public void validateECFListInSdkProfile(List<AefMapInfoDto> ecfList, final AsyncCallback<Void> callback) {
eventRpcService.validateECFListInSdkProfile(ecfList, new DataCallback<Void>(callback) {
@Override
protected void onResult(Void result) {
}
});
}

public void loadProfileSchemas(String applicationId,
final AsyncCallback<List<EndpointProfileSchemaDto>> callback) {
profileRpcService.getProfileSchemasByApplicationId(applicationId,
Expand Down Expand Up @@ -788,6 +787,15 @@ protected void onResult(List<CtlSchemaReferenceDto> result) {
});
}

public void getTenantLevelCTLSchemaReferenceForECF(String ecfId, List<EventClassViewDto> eventClassViewDtoList, final AsyncCallback<List<CtlSchemaReferenceDto>> callback) {
ctlRpcService.getTenantLevelCTLSchemaReferenceForECF(ecfId, eventClassViewDtoList,
new DataCallback<List<CtlSchemaReferenceDto>>(callback) {
@Override
protected void onResult(List<CtlSchemaReferenceDto> result) {
}
});
}

public void loadConfigurationSchemas(String applicationId,
final AsyncCallback<List<ConfigurationSchemaDto>> callback) {
configurationRpcService.getConfigurationSchemasByApplicationId(applicationId,
Expand Down Expand Up @@ -949,16 +957,6 @@ protected void onResult(List<CTLSchemaMetaInfoDto> result) {
});
}

// public void getLastCreatedCTLSchemaByFqnAndVersion(String fqn, Integer version,
// final AsyncCallback<CTLSchemaMetaInfoDto> callback) {
// ctlRpcService.getLastCreatedCTLSchemaByFqnAndVersion(fqn, version,
// new DataCallback<CTLSchemaMetaInfoDto>(callback) {
// @Override
// protected void onResult(CTLSchemaMetaInfoDto result) {
// }
// });
// }

public void getCTLSchemaById(String ctlSchemaId,
final AsyncCallback<CTLSchemaDto> callback) {
ctlRpcService.getCTLSchemaById(ctlSchemaId,
Expand Down
Expand Up @@ -16,44 +16,39 @@

package org.kaaproject.kaa.server.admin.client.mvp.view.event;

import com.google.gwt.event.logical.shared.AttachEvent;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import org.kaaproject.avro.ui.gwt.client.widget.grid.AbstractGrid;
import org.kaaproject.avro.ui.gwt.client.widget.grid.event.RowActionEvent;
import org.kaaproject.avro.ui.gwt.client.widget.grid.event.RowActionEventHandler;
import org.kaaproject.kaa.common.dto.event.EventClassDto;
import org.kaaproject.kaa.common.dto.user.UserVerifierDto;
import org.kaaproject.kaa.server.admin.client.mvp.view.EcfVersionView;
import org.kaaproject.kaa.server.admin.client.mvp.view.base.BaseListViewImpl;
import org.kaaproject.kaa.server.admin.client.mvp.view.schema.BaseCtlSchemasGrid;
import org.kaaproject.kaa.server.admin.client.mvp.view.widget.ImageTextButton;
import org.kaaproject.kaa.server.admin.client.util.Utils;

public class EcfVersionViewImpl extends BaseListViewImpl<EventClassDto> implements EcfVersionView {

@UiField
public final ImageTextButton addSchemaButton;
public final ImageTextButton addECButton;

public EcfVersionViewImpl(boolean editable) {
super(true);
this.addSchemaButton = new ImageTextButton(Utils.resources.plus(), addButtonEventClassString());
addSchemaButton.setVisible(editable);
this.addECButton = new ImageTextButton(Utils.resources.plus(), addButtonEventClassString());
addECButton.setVisible(editable);
addButton.setVisible(editable);
supportPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
supportPanel.setWidth("300px");
supportPanel.add(addSchemaButton);
// grid.(new AttachEvent.Handler() {
// @Override
// public void onAttachOrDetach(AttachEvent event) {
// validateAddButton();
// }
// });
supportPanel.add(addECButton);
addButton.setEnabled(false);
addButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
validateAddECButton();
}
});
}

@Override
Expand All @@ -63,12 +58,12 @@ protected AbstractGrid<EventClassDto, String> createGrid() {

@Override
protected String titleString() {
return Utils.constants.eventClasses();
return Utils.constants.familyVersion();
}

@Override
protected String addButtonString() {
return "Save ECF version";
return Utils.constants.save();
}

private String addButtonEventClassString() {
Expand All @@ -77,12 +72,14 @@ private String addButtonEventClassString() {

@Override
public Button addButtonEventClass() {
return addSchemaButton;
return addECButton;
}

public void validateAddButton() {
if (grid.getDataGrid().getVisibleItems().isEmpty()) {
public void validateAddECButton() {
if (grid.getDataGrid().getDisplayedItems().isEmpty()) {
addButton.setEnabled(false);
} else {
addButton.setEnabled(true);
}
}

Expand Down
Expand Up @@ -169,7 +169,7 @@ protected void initDetailsTable() {
Label ecfVersionsLabel = new Label(Utils.constants.versions());
ecfVersionsLabel.addStyleName(Utils.kaaAdminStyle.bAppContentTitleLabel());

addEcfVersionButton = new Button(Utils.constants.addSchema());
addEcfVersionButton = new Button(Utils.constants.addFamilyVersion());
addEcfVersionButton.addStyleName(Utils.kaaAdminStyle.bAppButtonSmall());

detailsTable.setWidget(6, 0, ecfVersionsLabel);
Expand Down
Expand Up @@ -35,6 +35,7 @@
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.EventClassViewDto;
import org.kaaproject.kaa.server.admin.shared.services.CtlService;
import org.kaaproject.kaa.server.admin.shared.services.KaaAdminServiceException;
import org.kaaproject.kaa.server.admin.shared.services.ServiceErrorCode;
Expand Down Expand Up @@ -301,6 +302,35 @@ public List<CTLSchemaMetaInfoDto> getTenantLevelCTLSchemas() throws KaaAdminServ
}
}

@Override
public List<CtlSchemaReferenceDto> getTenantLevelCTLSchemaReferenceForECF(String ecfId, List<EventClassViewDto> eventClassViewDtoList) throws KaaAdminServiceException {
checkAuthority(KaaAuthorityDto.TENANT_ADMIN, KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER);
try {
AuthUserDto currentUser = getCurrentUser();
List<CTLSchemaMetaInfoDto> ctlSchemaReferenceDtoListForTenant = controlService.getAvailableCTLSchemasMetaInfoForTenant(currentUser.getTenantId());
List<String> fqnListOfCurrentECF = controlService.getFqnListForECF(ecfId);
if (eventClassViewDtoList != null) {
for (EventClassViewDto eventClassViewDto : eventClassViewDtoList) {
String fqn = eventClassViewDto.getExistingMetaInfo().getMetaInfo().getFqn();
if (!fqnListOfCurrentECF.contains(fqn)) {
fqnListOfCurrentECF.add(fqn);
}
}
}
List<CtlSchemaReferenceDto> availableCtlSchemaReferenceForECF = new ArrayList<>();
for (CTLSchemaMetaInfoDto metaInfo : ctlSchemaReferenceDtoListForTenant) {
if (!fqnListOfCurrentECF.contains(metaInfo.getFqn())) {
for (int version : metaInfo.getVersions()) {
availableCtlSchemaReferenceForECF.add(new CtlSchemaReferenceDto(metaInfo, version));
}
}
}
return availableCtlSchemaReferenceForECF;
} catch (Exception cause) {
throw Utils.handleException(cause);
}
}

@Override
public List<CTLSchemaMetaInfoDto> getApplicationLevelCTLSchemasByAppToken(String applicationToken) throws KaaAdminServiceException {
return getApplicationLevelCTLSchemas(checkApplicationToken(applicationToken));
Expand Down
Expand Up @@ -310,15 +310,6 @@ public EventClassViewDto createEventClassFormCtlSchema(CtlSchemaFormDto ctlSchem
}
}

@Override
public List<String> getEventClassTypes() throws KaaAdminServiceException {
List<String> 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> eventClassViewDto) throws KaaAdminServiceException {
EventClassFamilyVersionDto eventClassFamilyVersionDto = new EventClassFamilyVersionDto();
Expand All @@ -337,6 +328,15 @@ public void addEventClassFamilyVersionFromView(String eventClassFamilyId, List<E
addEventClassFamilyVersion(eventClassFamilyId, eventClassFamilyVersionDto);
}

@Override
public void validateECFListInSdkProfile(List<AefMapInfoDto> ecfList) throws KaaAdminServiceException {
try {
controlService.validateECFListInSdkProfile(ecfList);
} catch (Exception e) {
throw Utils.handleException(e);
}
}

@Override
public List<EventClassDto> getEventClassesByFamilyIdVersionAndType(String eventClassFamilyId, int version, EventClassType type)
throws KaaAdminServiceException {
Expand Down

0 comments on commit 9ba7be4

Please sign in to comment.