diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/KaaAdmin.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/KaaAdmin.java index 6cd0dadf0d..3f4b858c25 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/KaaAdmin.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/KaaAdmin.java @@ -34,6 +34,8 @@ import com.google.gwt.user.client.ui.RootLayoutPanel; import com.google.web.bindery.event.shared.EventBus; +import jline.internal.Log; + import org.kaaproject.kaa.common.dto.KaaAuthorityDto; import org.kaaproject.kaa.common.dto.admin.AuthResultDto; import org.kaaproject.kaa.common.dto.admin.AuthResultDto.Result; @@ -89,7 +91,8 @@ public static boolean isDevMode() { } public static void signOut() { - RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, GWT.getModuleBaseURL() + "j_spring_security_logout"); + RequestBuilder builder = new RequestBuilder( + RequestBuilder.POST, GWT.getModuleBaseURL() + "j_spring_security_logout"); try { builder.sendRequest(null, new RequestCallback() { @Override @@ -103,7 +106,8 @@ public void onError(Request request, Throwable exception) { redirectToModule(".."); } }); - } catch (RequestException e) { + } catch (RequestException ex) { + GWT.log("Exception: " + ex.getMessage()); } } @@ -154,14 +158,14 @@ private void init() { dataSource = new DataSource(eventBus); - PlaceController placeController = clientFactory.getPlaceController(); - ActivityMapper headerActivityMapper = new HeaderActivityMapper(clientFactory); ActivityManager headerActivityManager = new ActivityManager(headerActivityMapper, eventBus); headerActivityManager.setDisplay(appWidget.getAppHeaderHolder()); - ActivityMapper navigationActivityMapper = new NavigationActivityMapper(clientFactory, eventBus); - ActivityManager navigationActivityManager = new ActivityManager(navigationActivityMapper, eventBus); + ActivityMapper navigationActivityMapper = new NavigationActivityMapper( + clientFactory, eventBus); + ActivityManager navigationActivityManager = new ActivityManager( + navigationActivityMapper, eventBus); navigationActivityManager.setDisplay(appWidget.getNavContentHolder()); ActivityMapper appActivityMapper = new AppActivityMapper(clientFactory); @@ -186,7 +190,8 @@ private void init() { historyMapper = GWT.create(TenantUserPlaceHistoryMapper.class); clientFactory.setHomePlace(new ApplicationsPlace()); break; - + default: + break; } PlaceHistoryHandler historyHandler = new PlaceHistoryHandler(historyMapper); @@ -198,6 +203,7 @@ private void init() { place = new ApplicationsPlace(); } + PlaceController placeController = clientFactory.getPlaceController(); historyHandler.register(placeController, eventBus, place); RootLayoutPanel.get().add(appWidget); diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/layout/CustomDeckLayoutPanel.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/layout/CustomDeckLayoutPanel.java index 0ad660d0ab..8de43e25e6 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/layout/CustomDeckLayoutPanel.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/layout/CustomDeckLayoutPanel.java @@ -54,8 +54,8 @@ public CustomDeckLayoutPanel() { } @Override - public void add(Widget w) { - insert(w, getWidgetCount()); + public void add(Widget widget) { + insert(widget, getWidgetCount()); } @Override @@ -114,8 +114,8 @@ public int getVisibleWidgetIndex() { } @Override - public void insert(IsWidget w, int beforeIndex) { - insert(asWidgetOrNull(w), beforeIndex); + public void insert(IsWidget widget, int beforeIndex) { + insert(asWidgetOrNull(widget), beforeIndex); } @Override @@ -190,20 +190,20 @@ public void onResize() { } @Override - public boolean remove(Widget w) { - boolean removed = super.remove(w); + public boolean remove(Widget widget) { + boolean removed = super.remove(widget); if (removed) { - Layer layer = (Layer) w.getLayoutData(); + Layer layer = (Layer) widget.getLayoutData(); layout.removeChild(layer); - w.setLayoutData(null); + widget.setLayoutData(null); - if (visibleWidget == w) { + if (visibleWidget == widget) { visibleWidget = null; } - if (hidingWidget == w) { + if (hidingWidget == widget) { hidingWidget = null; } - if (lastVisibleWidget == w) { + if (lastVisibleWidget == widget) { lastVisibleWidget = null; } } @@ -215,23 +215,23 @@ public boolean remove(Widget w) { * is added to the end of the panel. If the specified widget is null, the * currently-visible widget will be hidden. * - * @param w the widget to show, and add if not a child + * @param widget the widget to show, and add if not a child */ @Override - public void setWidget(IsWidget w) { + public void setWidget(IsWidget widget) { // Hide the currently visible widget. - if (w == null) { + if (widget == null) { showWidget(null); return; } // Add the widget if it is not already a child. - if (w.asWidget().getParent() != this) { - add(w); + if (widget.asWidget().getParent() != this) { + add(widget); } // Show the widget. - showWidget(w.asWidget()); + showWidget(widget.asWidget()); } /** @@ -294,7 +294,8 @@ protected void onDetach() { * @param widget the widget to check */ void assertIsChild(Widget widget) { - assert (widget == null) || (widget.getParent() == this) : "The specified widget is not a child of this panel"; + assert (widget == null) + || (widget.getParent() == this) : "The specified widget is not a child of this panel"; } /** @@ -322,8 +323,8 @@ private void doBeforeLayout() { int oldIndex = getWidgetIndex(lastVisibleWidget); int newIndex = getWidgetIndex(visibleWidget); double direction = (oldIndex < newIndex) ? 100.0 : -100.0; - double vDirection = isAnimationVertical ? direction : 0.0; - double hDirection = isAnimationVertical ? 0.0 + double vertDirection = isAnimationVertical ? direction : 0.0; + double horizDirection = isAnimationVertical ? 0.0 : LocaleInfo.getCurrentLocale().isRTL() ? -direction : direction; /* @@ -342,8 +343,8 @@ private void doBeforeLayout() { } if (newLayer != null) { // The new layer starts off to one side. - newLayer.setTopHeight(vDirection, Unit.PCT, 100.0, Unit.PCT); - newLayer.setLeftWidth(hDirection, Unit.PCT, 100.0, Unit.PCT); + newLayer.setTopHeight(vertDirection, Unit.PCT, 100.0, Unit.PCT); + newLayer.setLeftWidth(horizDirection, Unit.PCT, 100.0, Unit.PCT); setWidgetVisible(visibleWidget, newLayer, true); } layout.layout(); @@ -353,8 +354,8 @@ private void doBeforeLayout() { // Set the end positions of the layers. if (oldLayer != null) { // The old layer ends off to one side. - oldLayer.setTopHeight(-vDirection, Unit.PCT, 100.0, Unit.PCT); - oldLayer.setLeftWidth(-hDirection, Unit.PCT, 100.0, Unit.PCT); + oldLayer.setTopHeight(-vertDirection, Unit.PCT, 100.0, Unit.PCT); + oldLayer.setLeftWidth(-horizDirection, Unit.PCT, 100.0, Unit.PCT); setWidgetVisible(lastVisibleWidget, oldLayer, true); } if (newLayer != null) { @@ -373,14 +374,14 @@ private void doBeforeLayout() { lastVisibleWidget = visibleWidget; } - private void setWidgetVisible(Widget w, Layer layer, boolean visible) { + private void setWidgetVisible(Widget widget, Layer layer, boolean visible) { layer.setVisible(visible); /* * Set the visibility of the widget. This is used by lazy panel to * initialize the widget. */ - w.setVisible(visible); + widget.setVisible(visible); } /** diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/layout/SimpleWidgetPanel.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/layout/SimpleWidgetPanel.java index 927b4e71ca..4431e4cb21 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/layout/SimpleWidgetPanel.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/layout/SimpleWidgetPanel.java @@ -26,26 +26,26 @@ public class SimpleWidgetPanel extends LayoutPanel implements AcceptsOneWidget { private Widget widget; @Override - public void setWidget(IsWidget w) { - setOneWidget(asWidgetOrNull(w)); + public void setWidget(IsWidget widget) { + setOneWidget(asWidgetOrNull(widget)); } - private void setOneWidget(Widget w) { + private void setOneWidget(Widget widget) { // validate - if (w == widget) { + if (widget == this.widget) { return; } // remove the old widget - if (widget != null) { - super.remove(widget); + if (this.widget != null) { + super.remove(this.widget); } // logical attach - widget = w; + this.widget = widget; - if (w != null) { - super.add(w); + if (widget != null) { + super.add(widget); } forceLayout(); } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/login/LoginView.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/login/LoginView.java index d24c4deedb..ea06ea883b 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/login/LoginView.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/login/LoginView.java @@ -65,20 +65,21 @@ public LoginView() { initWidget(uiBinder.createAndBindUi(this)); - loginTitle.getElement().setInnerSafeHtml(SafeHtmlUtils.fromSafeConstant(Utils.messages.loginTitle())); + loginTitle.getElement().setInnerSafeHtml( + SafeHtmlUtils.fromSafeConstant(Utils.messages.loginTitle())); - Label loginLabel = new Label(Utils.constants.username()); usernameBox = new TextBox(); usernameBox.setName("j_username"); usernameBox.setWidth("100%"); - Label passwordLabel = new Label(Utils.constants.password()); passwordBox = new PasswordTextBox(); passwordBox.setName("j_password"); passwordBox.setWidth("100%"); + Label loginLabel = new Label(Utils.constants.username()); loginTable.setWidget(0, 0, loginLabel); loginTable.setWidget(0, 1, usernameBox); + Label passwordLabel = new Label(Utils.constants.password()); loginTable.setWidget(1, 0, passwordLabel); loginTable.setWidget(1, 1, passwordBox); @@ -87,10 +88,14 @@ public LoginView() { loginTable.setWidget(2, 0, forgotPasswordLabel); loginTable.getFlexCellFormatter().setWidth(0, 0, "130px"); - loginTable.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_RIGHT); - loginTable.getFlexCellFormatter().setHorizontalAlignment(1, 0, HasHorizontalAlignment.ALIGN_RIGHT); - loginTable.getFlexCellFormatter().setHorizontalAlignment(2, 0, HasHorizontalAlignment.ALIGN_RIGHT); - loginTable.getFlexCellFormatter().setColSpan(2, 0, 2); + loginTable.getFlexCellFormatter() + .setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_RIGHT); + loginTable.getFlexCellFormatter() + .setHorizontalAlignment(1, 0, HasHorizontalAlignment.ALIGN_RIGHT); + loginTable.getFlexCellFormatter() + .setHorizontalAlignment(2, 0, HasHorizontalAlignment.ALIGN_RIGHT); + loginTable.getFlexCellFormatter() + .setColSpan(2, 0, 2); loginButton = new Button(Utils.constants.login()); loginButton.addStyleName(Utils.kaaAdminStyle.loginButton()); diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/ClientFactoryImpl.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/ClientFactoryImpl.java index 89be6cbc73..da4a70b381 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/ClientFactoryImpl.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/ClientFactoryImpl.java @@ -135,9 +135,12 @@ public class ClientFactoryImpl implements ClientFactory { private final TenantView createTenantView = new TenantViewImpl(true); private final TenantView tenantView = new TenantViewImpl(false); - private final BaseListView applicationsView = new ApplicationsViewImpl(KaaAdmin.checkAuthorities(KaaAuthorityDto.TENANT_ADMIN)); - private final ApplicationView createApplicationView = new ApplicationViewImpl(true, KaaAdmin.checkAuthorities(KaaAuthorityDto.TENANT_ADMIN)); - private final ApplicationView applicationView = new ApplicationViewImpl(false, KaaAdmin.checkAuthorities(KaaAuthorityDto.TENANT_ADMIN)); + private final BaseListView applicationsView = + new ApplicationsViewImpl(KaaAdmin.checkAuthorities(KaaAuthorityDto.TENANT_ADMIN)); + private final ApplicationView createApplicationView = + new ApplicationViewImpl(true, KaaAdmin.checkAuthorities(KaaAuthorityDto.TENANT_ADMIN)); + private final ApplicationView applicationView = + new ApplicationViewImpl(false, KaaAdmin.checkAuthorities(KaaAuthorityDto.TENANT_ADMIN)); private final BaseListView sdkProfilesView = new SdkProfilesViewImpl(); private final SdkProfileView sdkProfileView = new SdkProfileViewImpl(); @@ -147,21 +150,33 @@ public class ClientFactoryImpl implements ClientFactory { private final UserView createUserView = new UserViewImpl(true); private final UserView userView = new UserViewImpl(false); - private final BaseListView profileSchemasView = new ProfileSchemasViewImpl(); - private final BaseCtlSchemaView profileSchemaView = new ProfileSchemaViewImpl(false); - private final BaseCtlSchemaView createProfileSchemaView = new ProfileSchemaViewImpl(true); - - private final BaseListView serverProfileSchemasView = new ServerProfileSchemasViewImpl(); - private final BaseCtlSchemaView serverProfileSchemaView = new ServerProfileSchemaViewImpl(false); - private final BaseCtlSchemaView createServerProfileSchemaView = new ServerProfileSchemaViewImpl(true); - - private final BaseListView configurationSchemasView = new ConfigurationSchemasViewImpl(); - private final BaseCtlSchemaView configurationSchemaView = new ConfigurationSchemaViewImpl(false); - private final BaseCtlSchemaView createConfigurationSchemaView = new ConfigurationSchemaViewImpl(true); - - private final BaseListView notificationSchemasView = new NotificationSchemasViewImpl(); - private final BaseCtlSchemaView notificationSchemaView = new NotificationSchemaViewImpl(false); - private final BaseCtlSchemaView createNotificationSchemaView = new NotificationSchemaViewImpl(true); + private final BaseListView profileSchemasView = + new ProfileSchemasViewImpl(); + private final BaseCtlSchemaView profileSchemaView = + new ProfileSchemaViewImpl(false); + private final BaseCtlSchemaView createProfileSchemaView = + new ProfileSchemaViewImpl(true); + + private final BaseListView serverProfileSchemasView = + new ServerProfileSchemasViewImpl(); + private final BaseCtlSchemaView serverProfileSchemaView = + new ServerProfileSchemaViewImpl(false); + private final BaseCtlSchemaView createServerProfileSchemaView = + new ServerProfileSchemaViewImpl(true); + + private final BaseListView configurationSchemasView = + new ConfigurationSchemasViewImpl(); + private final BaseCtlSchemaView configurationSchemaView = + new ConfigurationSchemaViewImpl(false); + private final BaseCtlSchemaView createConfigurationSchemaView = + new ConfigurationSchemaViewImpl(true); + + private final BaseListView notificationSchemasView = + new NotificationSchemasViewImpl(); + private final BaseCtlSchemaView notificationSchemaView = + new NotificationSchemaViewImpl(false); + private final BaseCtlSchemaView createNotificationSchemaView = + new NotificationSchemaViewImpl(true); private final BaseListView logSchemasView = new LogSchemasViewImpl(); private final BaseCtlSchemaView logSchemaView = new LogSchemaViewImpl(false); @@ -217,7 +232,8 @@ public class ClientFactoryImpl implements ClientFactory { private final CtlSchemaView createCtlSchemaView = new CtlSchemaViewImpl(true, true); private final CtlSchemaView editCtlSchemaView = new CtlSchemaViewImpl(false, true); - private final CtlSchemaView editApplicationCtlSchemaView = new ApplicationCtlSchemaViewImpl(false, true); + private final CtlSchemaView editApplicationCtlSchemaView = + new ApplicationCtlSchemaViewImpl(false, true); private final CtlSchemaView viewCtlSchemaView = new CtlSchemaViewImpl(false, false); private Place homePlace; diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/CtlSchemaActivity.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/CtlSchemaActivity.java index 99f67cb4d5..e694f6d300 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/CtlSchemaActivity.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/CtlSchemaActivity.java @@ -398,7 +398,7 @@ public void onSuccessImpl(CtlSchemaFormDto result) { } else if (place.getSchemaType() == SchemaType.EVENT_CLASS && place.getPreviousPlace() != null) { EventClassPlace eventClassPlace = new EventClassPlace(place.getEcfId(), place.getEcfVersionId(), place.getEcfVersion(), ""); eventClassPlace.setCtlSchemaId(ctlSchemaID); - eventClassPlace.setNameEC(nameEC); + eventClassPlace.setNameEc(nameEC); goTo(eventClassPlace); } } else if (place.getPreviousPlace() != null) { diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/EventClassActivity.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/EventClassActivity.java index 91b6a719e4..7def705f2e 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/EventClassActivity.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/activity/EventClassActivity.java @@ -182,7 +182,7 @@ public void onFailure(Throwable caught) { @Override public void onSuccess(CtlSchemaReferenceDto ctlSchemaReferenceDto) { detailsView.getCtlSchemaReference().setValue(ctlSchemaReferenceDto); - detailsView.getName().setValue(place.getNameEC()); + detailsView.getName().setValue(place.getNameEc()); place.setCtlSchemaId(null); } }); diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/AbstractPluginPlace.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/AbstractPluginPlace.java index 549932474a..ec24cd84b9 100755 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/AbstractPluginPlace.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/AbstractPluginPlace.java @@ -64,7 +64,8 @@ public boolean equals(Object obj) { return true; } - public static abstract class Tokenizer

implements PlaceTokenizer

, PlaceConstants { + public abstract static class Tokenizer

+ implements PlaceTokenizer

, PlaceConstants { @Override public P getPlace(String token) { diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/AbstractPluginsPlace.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/AbstractPluginsPlace.java index f3974a9d8d..d02bf1122a 100755 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/AbstractPluginsPlace.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/AbstractPluginsPlace.java @@ -68,7 +68,8 @@ public TreePlaceDataProvider getDataProvider(EventBus eventBus) { return null; } - public static abstract class Tokenizer

implements PlaceTokenizer

, PlaceConstants { + public static abstract class Tokenizer

+ implements PlaceTokenizer

, PlaceConstants { @Override public P getPlace(String token) { diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/AbstractPropertiesPlace.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/AbstractPropertiesPlace.java index 70207826d4..620e424d57 100755 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/AbstractPropertiesPlace.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/AbstractPropertiesPlace.java @@ -38,7 +38,8 @@ public TreePlace createDefaultPreviousPlace() { return null; } - public static abstract class Tokenizer

implements PlaceTokenizer

, PlaceConstants { + public abstract static class Tokenizer

+ implements PlaceTokenizer

, PlaceConstants { @Override public String getToken(P place) { diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/AbstractRecordPlace.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/AbstractRecordPlace.java index 29ab9c564e..4acf9ddc6f 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/AbstractRecordPlace.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/AbstractRecordPlace.java @@ -100,7 +100,8 @@ public TreePlace createDefaultPreviousPlace() { return new EndpointGroupPlace(applicationId, endpointGroupId, false, false); } - public static abstract class Tokenizer

implements PlaceTokenizer

, PlaceConstants { + public abstract static class Tokenizer

+ implements PlaceTokenizer

, PlaceConstants { @Override public P getPlace(String token) { @@ -112,7 +113,8 @@ public P getPlace(String token) { PlaceParams.getDoubleParam(RANDOM)); } - protected abstract P getPlaceImpl(String applicationId, String endpointGroupId, boolean create, boolean showActive, double random); + protected abstract P getPlaceImpl(String applicationId, String endpointGroupId, + boolean create, boolean showActive, double random); @Override public String getToken(P place) { diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/AbstractSchemaPlaceApplication.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/AbstractSchemaPlaceApplication.java index 213f31a0d0..a2f2747132 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/AbstractSchemaPlaceApplication.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/AbstractSchemaPlaceApplication.java @@ -42,7 +42,8 @@ public TreePlaceDataProvider getDataProvider(EventBus eventBus) { return null; } - public static abstract class Tokenizer

implements PlaceTokenizer

, PlaceConstants { + public abstract static class Tokenizer

+ implements PlaceTokenizer

, PlaceConstants { @Override public P getPlace(String token) { diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/AbstractSchemaPlaceEvent.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/AbstractSchemaPlaceEvent.java index bbcda200c5..b12cee3436 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/AbstractSchemaPlaceEvent.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/AbstractSchemaPlaceEvent.java @@ -23,7 +23,10 @@ public abstract class AbstractSchemaPlaceEvent extends SchemasPlaceEvent { protected String schemaId; - public AbstractSchemaPlaceEvent(String ecfId, String ecfVersionId, int ecfVersion, String schemaId) { + public AbstractSchemaPlaceEvent(String ecfId, + String ecfVersionId, + int ecfVersion, + String schemaId) { super(ecfId, ecfVersionId, ecfVersion); this.schemaId = schemaId; } @@ -42,15 +45,23 @@ public TreePlaceDataProvider getDataProvider(EventBus eventBus) { return null; } - public static abstract class Tokenizer

implements PlaceTokenizer

, PlaceConstants { + public abstract static class Tokenizer

+ implements PlaceTokenizer

, PlaceConstants { @Override public P getPlace(String token) { PlaceParams.paramsFromToken(token); - return getPlaceImpl(PlaceParams.getParam(ECF_ID), PlaceParams.getParam(ECF_VERSION_ID), PlaceParams.getIntParam(ECF_VERSION), PlaceParams.getParam(SCHEMA_ID)); + return getPlaceImpl( + PlaceParams.getParam(ECF_ID), + PlaceParams.getParam(ECF_VERSION_ID), + PlaceParams.getIntParam(ECF_VERSION), + PlaceParams.getParam(SCHEMA_ID)); } - protected abstract P getPlaceImpl(String ecfId, String ecfVersionId, int ecfVersion, String schemaId); + protected abstract P getPlaceImpl(String ecfId, + String ecfVersionId, + int ecfVersion, + String schemaId); @Override public String getToken(P place) { diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/AefMapPlace.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/AefMapPlace.java index 57ebf2bd52..ce01a20fd7 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/AefMapPlace.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/AefMapPlace.java @@ -77,7 +77,9 @@ public static class Tokenizer implements PlaceTokenizer, PlaceConst @Override public AefMapPlace getPlace(String token) { PlaceParams.paramsFromToken(token); - return new AefMapPlace(PlaceParams.getParam(APPLICATION_ID), PlaceParams.getParam(AEF_MAP_ID)); + return new AefMapPlace( + PlaceParams.getParam(APPLICATION_ID), + PlaceParams.getParam(AEF_MAP_ID)); } @Override diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/ApplicationCtlSchemasPlace.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/ApplicationCtlSchemasPlace.java index 2c9a53ca0c..79a598b9e3 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/ApplicationCtlSchemasPlace.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/ApplicationCtlSchemasPlace.java @@ -40,18 +40,24 @@ public String getName() { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + + if (getClass() != obj.getClass()) { return false; + } + ApplicationCtlSchemasPlace other = (ApplicationCtlSchemasPlace) obj; - if (applicationId == null) { - if (other.applicationId != null) + if (applicationId == null && other.applicationId != null) { return false; - } else if (!applicationId.equals(other.applicationId)) + } else if (!applicationId.equals(other.applicationId)) { return false; + } return true; } @@ -66,7 +72,8 @@ public TreePlace createDefaultPreviousPlace() { } @Prefix(value = "appCtlSchemas") - public static class Tokenizer implements PlaceTokenizer, PlaceConstants { + public static class Tokenizer + implements PlaceTokenizer, PlaceConstants { @Override public ApplicationCtlSchemasPlace getPlace(String token) { diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/ApplicationPlace.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/ApplicationPlace.java index 7d6313c9cc..415cf2a4c1 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/ApplicationPlace.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/ApplicationPlace.java @@ -75,7 +75,9 @@ public String getName() { @Override public boolean isLeaf() { - return !KaaAdmin.checkAuthorities(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); + return !KaaAdmin.checkAuthorities( + KaaAuthorityDto.TENANT_DEVELOPER, + KaaAuthorityDto.TENANT_USER); } @Override diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/ConfigurationPlace.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/ConfigurationPlace.java index bd60f2e9dc..38d190bfb1 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/ConfigurationPlace.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/ConfigurationPlace.java @@ -24,7 +24,8 @@ public class ConfigurationPlace extends AbstractRecordPlace { private String schemaId; - public ConfigurationPlace(String applicationId, String schemaId, String endpointGroupId, boolean create, boolean showActive, double random) { + public ConfigurationPlace(String applicationId, String schemaId, String endpointGroupId, + boolean create, boolean showActive, double random) { super(applicationId, endpointGroupId, create, showActive, random); this.schemaId = schemaId; } @@ -64,8 +65,11 @@ public boolean equals(Object obj) { public static class Tokenizer extends AbstractRecordPlace.Tokenizer { @Override - protected ConfigurationPlace getPlaceImpl(String applicationId, String endpointGroupId, boolean create, boolean showActive, double random) { - return new ConfigurationPlace(applicationId, PlaceParams.getParam(SCHEMA_ID), endpointGroupId, create, showActive, random); + protected ConfigurationPlace getPlaceImpl(String applicationId, String endpointGroupId, + boolean create, boolean showActive, double random) { + return new ConfigurationPlace( + applicationId, PlaceParams.getParam(SCHEMA_ID), + endpointGroupId, create, showActive, random); } @Override diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/ConfigurationSchemaPlace.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/ConfigurationSchemaPlace.java index 95882b27f0..865d37b40a 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/ConfigurationSchemaPlace.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/ConfigurationSchemaPlace.java @@ -59,7 +59,8 @@ public TreePlace createDefaultPreviousPlace() { } @Prefix(value = "confSchema") - public static class Tokenizer extends AbstractSchemaPlaceApplication.Tokenizer { + public static class Tokenizer + extends AbstractSchemaPlaceApplication.Tokenizer { @Override protected ConfigurationSchemaPlace getPlaceImpl(String applicationId, diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/ConfigurationSchemasPlace.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/ConfigurationSchemasPlace.java index 5a6054a0c8..a92d5b17ee 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/ConfigurationSchemasPlace.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/ConfigurationSchemasPlace.java @@ -65,7 +65,8 @@ public TreePlaceDataProvider getDataProvider(EventBus eventBus) { } @Prefix(value = "confSchemas") - public static class Tokenizer extends SchemasPlaceApplication.Tokenizer { + public static class Tokenizer + extends SchemasPlaceApplication.Tokenizer { @Override protected ConfigurationSchemasPlace getPlaceImpl(String applicationId) { diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/CtlSchemaPlace.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/CtlSchemaPlace.java index 29f5ce0da3..5d34bcbadf 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/CtlSchemaPlace.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/CtlSchemaPlace.java @@ -115,36 +115,52 @@ public void setSchemaType(SchemaType schemaType) { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + + if (getClass() != obj.getClass()) { return false; + } + CtlSchemaPlace other = (CtlSchemaPlace) obj; - if (applicationId == null) { - if (other.applicationId != null) - return false; - } else if (!applicationId.equals(other.applicationId)) + if (applicationId == null && other.applicationId != null) { return false; - if (create != other.create) + } else if (!applicationId.equals(other.applicationId)) { return false; - if (editable != other.editable) + } + + if (create != other.create) { return false; - if (metaInfoId == null) { - if (other.metaInfoId != null) + } + + if (editable != other.editable) { + return false; + } + + if (metaInfoId == null && other.metaInfoId != null) { return false; - } else if (!metaInfoId.equals(other.metaInfoId)) + } else if (!metaInfoId.equals(other.metaInfoId)) { return false; - if (scope != other.scope) + } + + if (scope != other.scope) { return false; - if (schemaType != other.schemaType) + } + + if (schemaType != other.schemaType) { return false; - if (version == null) { - if (other.version != null) + } + + if (version == null && other.version != null) { return false; - } else if (!version.equals(other.version)) + } else if (!version.equals(other.version)) { return false; + } return true; } @@ -234,7 +250,8 @@ public CtlSchemaPlace getPlace(String token) { if (PlaceParams.getParam(ECF_VERSION) != null) { ecfVersion = Integer.valueOf(PlaceParams.getParam(ECF_VERSION)); } - place = new CtlSchemaPlace(metaInfoId, version, scope, ecfId, ecfVersionId, ecfVersion, editable, create); + place = new CtlSchemaPlace( + metaInfoId, version, scope, ecfId, ecfVersionId, ecfVersion, editable, create); } place.setSchemaType(schemaType); return place; diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/EcfVersionPlace.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/EcfVersionPlace.java index 16471d499a..f7a860e9c0 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/EcfVersionPlace.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/EcfVersionPlace.java @@ -29,7 +29,8 @@ public EcfVersionPlace(String ecfId, String ecfVersionId, int ecfVersion) { super(ecfId, ecfVersionId, ecfVersion); } - public EcfVersionPlace(String ecfId, String ecfVersionId, int ecfVersion, List eventClassViewDtoList) { + public EcfVersionPlace(String ecfId, String ecfVersionId, + int ecfVersion, List eventClassViewDtoList) { super(ecfId, ecfVersionId, ecfVersion, eventClassViewDtoList); } @@ -83,7 +84,10 @@ public static class Tokenizer implements PlaceTokenizer, PlaceC @Override public EcfVersionPlace getPlace(String token) { PlaceParams.paramsFromToken(token); - return new EcfVersionPlace(PlaceParams.getParam(ECF_ID), PlaceParams.getParam(ECF_VERSION_ID), PlaceParams.getIntParam(ECF_VERSION)); + return new EcfVersionPlace( + PlaceParams.getParam(ECF_ID), + PlaceParams.getParam(ECF_VERSION_ID), + PlaceParams.getIntParam(ECF_VERSION)); } @Override diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/EndpointUsersPlace.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/EndpointUsersPlace.java index f0c750ce75..4e1cd5b7fa 100755 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/EndpointUsersPlace.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/EndpointUsersPlace.java @@ -84,7 +84,8 @@ public TreePlace createDefaultPreviousPlace() { return new ApplicationPlace(applicationId); } - public static abstract class Tokenizer

implements PlaceTokenizer

, PlaceConstants { + public abstract static class Tokenizer

+ implements PlaceTokenizer

, PlaceConstants { @Override public P getPlace(String token) { 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 e4b2ade14c..ed308dc991 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 @@ -26,9 +26,12 @@ public class EventClassPlace extends AbstractSchemaPlaceEvent { private String ctlSchemaId; - private String nameEC; + private String nameEc; - public EventClassPlace(String ecfId, String ecfVersionId, int ecfVersion, String schemaId, List eventClassDtoList) { + public EventClassPlace(String ecfId, String ecfVersionId, + int ecfVersion, + String schemaId, + List eventClassDtoList) { super(ecfId, ecfVersionId, ecfVersion, schemaId); this.eventClassDtoList = eventClassDtoList; } @@ -45,12 +48,12 @@ public void setCtlSchemaId(String ctlSchemaId) { this.ctlSchemaId = ctlSchemaId; } - public String getNameEC() { - return nameEC; + public String getNameEc() { + return nameEc; } - public void setNameEC(String nameEC) { - this.nameEC = nameEC; + public void setNameEc(String nameEc) { + this.nameEc = nameEc; } @Override @@ -64,15 +67,24 @@ public TreePlace createDefaultPreviousPlace() { } @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof EventClassPlace)) return false; - if (!super.equals(o)) return false; + public boolean equals(Object object) { + if (this == object) { + return true; + } + + if (!(object instanceof EventClassPlace)) { + return false; + } - EventClassPlace that = (EventClassPlace) o; + if (!super.equals(object)) { + return false; + } - return getEcfVersionId() != null ? getEcfVersionId().equals(that.getEcfVersionId()) : that.getEcfVersionId() == null; + EventClassPlace that = (EventClassPlace) object; + return getEcfVersionId() != null + ? getEcfVersionId().equals(that.getEcfVersionId()) + : that.getEcfVersionId() == null; } @Override diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/GetUserConfigPlace.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/GetUserConfigPlace.java index 27149a3f32..1e1d8f6ca6 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/GetUserConfigPlace.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/GetUserConfigPlace.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.kaaproject.kaa.server.admin.client.mvp.place; import com.google.gwt.place.shared.Prefix; diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/NotificationSchemaPlace.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/NotificationSchemaPlace.java index 0b18b40d8f..38be1089f7 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/NotificationSchemaPlace.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/NotificationSchemaPlace.java @@ -59,7 +59,8 @@ public TreePlace createDefaultPreviousPlace() { } @Prefix(value = "notifSchema") - public static class Tokenizer extends AbstractSchemaPlaceApplication.Tokenizer { + public static class Tokenizer + extends AbstractSchemaPlaceApplication.Tokenizer { @Override protected NotificationSchemaPlace getPlaceImpl(String applicationId, diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/NotificationSchemasPlace.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/NotificationSchemasPlace.java index a463888302..970c340b89 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/NotificationSchemasPlace.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/NotificationSchemasPlace.java @@ -65,7 +65,8 @@ public TreePlaceDataProvider getDataProvider(EventBus eventBus) { } @Prefix(value = "notifSchemas") - public static class Tokenizer extends SchemasPlaceApplication.Tokenizer { + public static class Tokenizer + extends SchemasPlaceApplication.Tokenizer { @Override protected NotificationSchemasPlace getPlaceImpl(String applicationId) { diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/ProfileFilterPlace.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/ProfileFilterPlace.java index aea1e6f552..fc54496a33 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/ProfileFilterPlace.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/ProfileFilterPlace.java @@ -25,7 +25,13 @@ public class ProfileFilterPlace extends AbstractRecordPlace { private String endpointProfileSchemaId; private String serverProfileSchemaId; - public ProfileFilterPlace(String applicationId, String endpointProfileSchemaId, String serverProfileSchemaId, String endpointGroupId, boolean create, boolean showActive, double random) { + public ProfileFilterPlace(String applicationId, + String endpointProfileSchemaId, + String serverProfileSchemaId, + String endpointGroupId, + boolean create, + boolean showActive, + double random) { super(applicationId, endpointGroupId, create, showActive, random); this.endpointProfileSchemaId = endpointProfileSchemaId; this.serverProfileSchemaId = serverProfileSchemaId; @@ -78,7 +84,11 @@ public boolean equals(Object obj) { public static class Tokenizer extends AbstractRecordPlace.Tokenizer { @Override - protected ProfileFilterPlace getPlaceImpl(String applicationId, String endpointGroupId, boolean create, boolean showActive, double random) { + protected ProfileFilterPlace getPlaceImpl(String applicationId, + String endpointGroupId, + boolean create, + boolean showActive, + double random) { return new ProfileFilterPlace(applicationId, PlaceParams.getParam(ENDPOINT_PROFILE_SCHEMA_ID), PlaceParams.getParam(SERVER_PROFILE_SCHEMA_ID), diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/ProfileSchemaPlace.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/ProfileSchemaPlace.java index 007b16cfb0..35944cc61b 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/ProfileSchemaPlace.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/ProfileSchemaPlace.java @@ -59,7 +59,8 @@ public TreePlace createDefaultPreviousPlace() { } @Prefix(value = "profSchema") - public static class Tokenizer extends AbstractSchemaPlaceApplication.Tokenizer { + public static class Tokenizer + extends AbstractSchemaPlaceApplication.Tokenizer { @Override protected ProfileSchemaPlace getPlaceImpl(String applicationId, 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 42cd903c58..60e6a02def 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 @@ -84,7 +84,8 @@ public TreePlace createDefaultPreviousPlace() { return new ApplicationPlace(applicationId); } - public static abstract class Tokenizer

implements PlaceTokenizer

, PlaceConstants { + public abstract static class Tokenizer

+ implements PlaceTokenizer

, PlaceConstants { @Override public P getPlace(String token) { 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 c44afb8d8e..4682b21b0f 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 @@ -40,7 +40,8 @@ public SchemasPlaceEvent(String ecfId, String ecfVersionId, int ecfVersion) { this.ecfVersion = ecfVersion; } - public SchemasPlaceEvent(String ecfId, String ecfVersionId, int ecfVersion, List eventClassDtoList) { + public SchemasPlaceEvent(String ecfId, String ecfVersionId, + int ecfVersion, List eventClassDtoList) { this.ecfId = ecfId; this.ecfVersionId = ecfVersionId; this.ecfVersion = ecfVersion; @@ -97,12 +98,16 @@ public TreePlace createDefaultPreviousPlace() { return new TenantPlace(PlaceParams.getParam(USER_ID)); } - public static abstract class Tokenizer

implements PlaceTokenizer

, PlaceConstants { + public abstract static class Tokenizer

+ implements PlaceTokenizer

, PlaceConstants { @Override public P getPlace(String token) { PlaceParams.paramsFromToken(token); - return getPlaceImpl(PlaceParams.getParam(ECF_ID), PlaceParams.getParam(ECF_VERSION_ID), PlaceParams.getIntParam(ECF_VERSION)); + return getPlaceImpl( + PlaceParams.getParam(ECF_ID), + PlaceParams.getParam(ECF_VERSION_ID), + PlaceParams.getIntParam(ECF_VERSION)); } protected abstract P getPlaceImpl(String ecfId, String ecfVersionId, int ecfVersion); diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/SdkProfilePlace.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/SdkProfilePlace.java index 4ab67353bf..e8ab1e13a9 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/SdkProfilePlace.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/SdkProfilePlace.java @@ -35,20 +35,22 @@ public String getSdkProfileId() { } @Override - public boolean equals(Object o) { - if (this == o) { + public boolean equals(Object object) { + if (this == object) { return true; } - if (o == null || getClass() != o.getClass()) { + if (object == null || getClass() != object.getClass()) { return false; } - if (!super.equals(o)) { + if (!super.equals(object)) { return false; } - SdkProfilePlace that = (SdkProfilePlace) o; + SdkProfilePlace that = (SdkProfilePlace) object; - return !(sdkProfileId != null ? !sdkProfileId.equals(that.sdkProfileId) : that.sdkProfileId != null); + return !(sdkProfileId != null + ? !sdkProfileId.equals(that.sdkProfileId) + : that.sdkProfileId != null); } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/SdkProfilesPlace.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/SdkProfilesPlace.java index 3c22fdda19..ecfeafb436 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/SdkProfilesPlace.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/SdkProfilesPlace.java @@ -53,17 +53,17 @@ public TreePlace createDefaultPreviousPlace() { } @Override - public boolean equals(Object o) { - if (this == o) { + public boolean equals(Object object) { + if (this == object) { return true; } - if (o == null) { + if (object == null) { return false; } - if (this.getClass() != o.getClass()) { + if (this.getClass() != object.getClass()) { return false; } - SdkProfilesPlace other = (SdkProfilesPlace) o; + SdkProfilesPlace other = (SdkProfilesPlace) object; if (applicationId == null) { if (other.applicationId != null) { return false; diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/SendNotificationPlace.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/SendNotificationPlace.java index 3c902106cf..52fd437ad2 100755 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/SendNotificationPlace.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/SendNotificationPlace.java @@ -89,7 +89,8 @@ public static class Tokenizer implements PlaceTokenizer, @Override public SendNotificationPlace getPlace(String token) { PlaceParams.paramsFromToken(token); - return new SendNotificationPlace(PlaceParams.getParam(APPLICATION_ID), PlaceParams.getParam(TOPIC_ID)); + return new SendNotificationPlace( + PlaceParams.getParam(APPLICATION_ID), PlaceParams.getParam(TOPIC_ID)); } @Override diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/ServerProfileSchemaPlace.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/ServerProfileSchemaPlace.java index 6a418d7896..972eaecf16 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/ServerProfileSchemaPlace.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/ServerProfileSchemaPlace.java @@ -37,21 +37,22 @@ public TreePlace createDefaultPreviousPlace() { } @Override - public boolean equals(Object o) { - if (this == o) { + public boolean equals(Object object) { + if (this == object) { return true; } - if (o == null || getClass() != o.getClass()) { + if (object == null || getClass() != object.getClass()) { return false; } - if (!super.equals(o)) { + if (!super.equals(object)) { return false; } - ServerProfileSchemaPlace that = (ServerProfileSchemaPlace) o; - - return !(applicationId != null ? !applicationId.equals(that.applicationId) : that.applicationId != null); + ServerProfileSchemaPlace that = (ServerProfileSchemaPlace) object; + return !(applicationId != null + ? !applicationId.equals(that.applicationId) + : that.applicationId != null); } @Override @@ -60,7 +61,8 @@ public int hashCode() { } @Prefix(value = "serverProfSchema") - public static class Tokenizer extends AbstractSchemaPlaceApplication.Tokenizer { + public static class Tokenizer + extends AbstractSchemaPlaceApplication.Tokenizer { @Override protected ServerProfileSchemaPlace getPlaceImpl(String applicationId, diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/ServerProfileSchemasPlace.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/ServerProfileSchemasPlace.java index 21d7897f9d..72b8028df1 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/ServerProfileSchemasPlace.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/ServerProfileSchemasPlace.java @@ -43,20 +43,22 @@ public TreePlaceDataProvider getDataProvider(EventBus eventBus) { } @Override - public boolean equals(Object o) { - if (this == o) { + public boolean equals(Object object) { + if (this == object) { return true; } - if (o == null || getClass() != o.getClass()) { + if (object == null || getClass() != object.getClass()) { return false; } - if (!super.equals(o)) { + if (!super.equals(object)) { return false; } - ServerProfileSchemasPlace that = (ServerProfileSchemasPlace) o; + ServerProfileSchemasPlace that = (ServerProfileSchemasPlace) object; - return !(applicationId != null ? !applicationId.equals(that.applicationId) : that.applicationId != null); + return !(applicationId != null + ? !applicationId.equals(that.applicationId) + : that.applicationId != null); } @@ -68,7 +70,8 @@ public int hashCode() { } @Prefix(value = "serverProfSchemas") - public static class Tokenizer extends SchemasPlaceApplication.Tokenizer { + public static class Tokenizer + extends SchemasPlaceApplication.Tokenizer { @Override protected ServerProfileSchemasPlace getPlaceImpl(String applicationId) { diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/TreePlace.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/TreePlace.java index 9a56c81a80..3154109827 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/TreePlace.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/place/TreePlace.java @@ -69,7 +69,7 @@ public void render(com.google.gwt.cell.client.Cell.Context context, } } - public static abstract class TreePlaceDataProvider extends AsyncDataProvider { + public abstract static class TreePlaceDataProvider extends AsyncDataProvider { protected List data; private LoadCallback callback; diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/widget/MultiValueListBox.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/widget/MultiValueListBox.java index 49c53d91c5..0fde5c097b 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/widget/MultiValueListBox.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/client/mvp/view/widget/MultiValueListBox.java @@ -118,6 +118,20 @@ public void setValue(List value) { setValue(value, false); } + public void setValue(List value, boolean fireEvents) { + if (value == this.value || (this.value != null && this.value.equals(value))) { + return; + } + + List before = this.value; + this.value = value; + updateListBox(); + + if (fireEvents) { + ValueChangeEvent.fireIfNotEqual(this, before, value); + } + } + @Override public boolean isEnabled() { return getListBox().isEnabled(); @@ -151,20 +165,6 @@ public void setFocus(boolean focused) { getListBox().setFocus(focused); } - public void setValue(List value, boolean fireEvents) { - if (value == this.value || (this.value != null && this.value.equals(value))) { - return; - } - - List before = this.value; - this.value = value; - updateListBox(); - - if (fireEvents) { - ValueChangeEvent.fireIfNotEqual(this, before, value); - } - } - public List getValues() { return values; } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/AbstractAdminService.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/AbstractAdminService.java index 0d6fbdc6c9..64008cc326 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/AbstractAdminService.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/AbstractAdminService.java @@ -43,7 +43,7 @@ import org.kaaproject.kaa.server.admin.services.entity.CreateUserResult; import org.kaaproject.kaa.server.admin.services.entity.User; import org.kaaproject.kaa.server.admin.services.messaging.MessagingService; -import org.kaaproject.kaa.server.admin.services.schema.CTLSchemaParser; +import org.kaaproject.kaa.server.admin.services.schema.CtlSchemaParser; import org.kaaproject.kaa.server.admin.services.schema.ConfigurationSchemaFormAvroConverter; import org.kaaproject.kaa.server.admin.services.schema.EcfSchemaFormAvroConverter; import org.kaaproject.kaa.server.admin.services.schema.SimpleSchemaFormAvroConverter; @@ -131,23 +131,31 @@ public void setPasswordEncoder(PasswordEncoder passwordEncoder) { void validateRecordSchema(Schema schema) throws KaaAdminServiceException { SchemaUtil.compileAvroSchema(schema); if (schema.getType() != Schema.Type.RECORD) { - throw new KaaAdminServiceException("Schema " + schema.getFullName() + " is not a record schema!", ServiceErrorCode.INVALID_SCHEMA); + throw new KaaAdminServiceException("Schema " + + schema.getFullName() + " is not a record schema!", ServiceErrorCode.INVALID_SCHEMA); } } + void validateRecordSchema(String avroSchema, boolean isCtl) throws KaaAdminServiceException { + Schema schema = validateSchema(avroSchema, isCtl); + validateRecordSchema(schema); + } + byte[] getFileContent(String fileItemName) throws KaaAdminServiceException { if (!isEmpty(fileItemName)) { try { byte[] data = cacheService.uploadedFile(fileItemName, null); if (data == null) { - throw new KaaAdminServiceException("Unable to get file content!", ServiceErrorCode.FILE_NOT_FOUND); + throw new KaaAdminServiceException( + "Unable to get file content!", ServiceErrorCode.FILE_NOT_FOUND); } return data; } finally { cacheService.removeUploadedFile(fileItemName); } } else { - throw new KaaAdminServiceException("Unable to get file content, file item name is empty!", ServiceErrorCode.FILE_NOT_FOUND); + throw new KaaAdminServiceException( + "Unable to get file content, file item name is empty!", ServiceErrorCode.FILE_NOT_FOUND); } } @@ -161,7 +169,9 @@ void checkAuthority(KaaAuthorityDto... authorities) throws KaaAdminServiceExcept } } if (!matched) { - throw new KaaAdminServiceException("You do not have permission to perform this operation!", ServiceErrorCode.PERMISSION_DENIED); + throw new KaaAdminServiceException( + "You do not have permission to perform this operation!", + ServiceErrorCode.PERMISSION_DENIED); } } @@ -187,8 +197,8 @@ ApplicationDto checkApplicationId(String applicationId) throws KaaAdminServiceEx ApplicationDto application = controlService.getApplication(applicationId); checkApplication(application); return application; - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @@ -197,11 +207,12 @@ String checkApplicationToken(String applicationToken) throws KaaAdminServiceExce if (isEmpty(applicationToken)) { throw new KaaAdminServiceException(ServiceErrorCode.INVALID_ARGUMENTS); } - ApplicationDto application = controlService.getApplicationByApplicationToken(applicationToken); + ApplicationDto application = controlService.getApplicationByApplicationToken( + applicationToken); checkApplication(application); return application.getId(); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @@ -219,8 +230,8 @@ EndpointGroupDto checkEndpointGroupId(String endpointGroupId) throws KaaAdminSer Utils.checkNotNull(endpointGroup); checkApplicationId(endpointGroup.getApplicationId()); return endpointGroup; - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @@ -238,7 +249,8 @@ boolean isGroupAll(EndpointGroupDto groupDto) { @Override public void afterPropertiesSet() throws Exception { - ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false); + ClassPathScanningCandidateComponentProvider scanner = + new ClassPathScanningCandidateComponentProvider(false); scanner.addIncludeFilter(new AnnotationTypeFilter(KaaPluginConfig.class)); scanPluginsPackage(scanner, "org.kaaproject.kaa.server.appenders"); scanPluginsPackage(scanner, "org.kaaproject.kaa.server.verifiers"); @@ -251,14 +263,17 @@ public void afterPropertiesSet() throws Exception { ecfSchemaFormAvroConverter = new EcfSchemaFormAvroConverter(); } - private void scanPluginsPackage(ClassPathScanningCandidateComponentProvider scanner, String packageName) throws Exception { + private void scanPluginsPackage(ClassPathScanningCandidateComponentProvider scanner, + String packageName) throws Exception { Set beans = scanner.findCandidateComponents(packageName); for (BeanDefinition bean : beans) { Class clazz = Class.forName(bean.getBeanClassName()); KaaPluginConfig annotation = clazz.getAnnotation(KaaPluginConfig.class); PluginConfig pluginConfig = (PluginConfig) clazz.newInstance(); - RecordField fieldConfiguration = FormAvroConverter.createRecordFieldFromSchema(pluginConfig.getPluginConfigSchema()); - PluginInfoDto pluginInfo = new PluginInfoDto(pluginConfig.getPluginTypeName(), fieldConfiguration, + RecordField fieldConfiguration = + FormAvroConverter.createRecordFieldFromSchema(pluginConfig.getPluginConfigSchema()); + PluginInfoDto pluginInfo = + new PluginInfoDto(pluginConfig.getPluginTypeName(), fieldConfiguration, pluginConfig.getPluginClassName()); pluginsInfo.get(annotation.pluginType()).put(pluginInfo.getPluginClassName(), pluginInfo); } @@ -270,15 +285,10 @@ void setSchema(AbstractSchemaDto schemaDto, byte[] data) throws KaaAdminServiceE schemaDto.setSchema(new KaaSchemaFactoryImpl().createDataSchema(schema).getRawSchema()); } - void validateRecordSchema(String avroSchema, boolean isCtl) throws KaaAdminServiceException { - Schema schema = validateSchema(avroSchema, isCtl); - validateRecordSchema(schema); - } - Schema validateSchema(String avroSchema, boolean isCtl) throws KaaAdminServiceException { try { if (isCtl) { - return CTLSchemaParser.parseStringCtlSchema(avroSchema); + return CtlSchemaParser.parseStringCtlSchema(avroSchema); } else { Schema.Parser parser = new Schema.Parser(); return parser.parse(avroSchema); @@ -289,7 +299,8 @@ Schema validateSchema(String avroSchema, boolean isCtl) throws KaaAdminServiceEx } } - RecordField createRecordFieldFromCtlSchemaAndBody(String ctlSchemaId, String body) throws KaaAdminServiceException { + RecordField createRecordFieldFromCtlSchemaAndBody(String ctlSchemaId, String body) + throws KaaAdminServiceException { try { RecordField recordField; CTLSchemaDto ctlSchema = controlService.getCTLSchemaById(ctlSchemaId); @@ -302,8 +313,8 @@ RecordField createRecordFieldFromCtlSchemaAndBody(String ctlSchemaId, String bod recordField = FormAvroConverter.createRecordFieldFromSchema(schema); } return recordField; - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @@ -315,16 +326,19 @@ CreateUserResult saveUser(org.kaaproject.kaa.common.dto.admin.UserDto user) thro result.getPassword(), user.getMail()); } - } catch (Exception e) { - LOG.error("Can't send temporary password. Exception was catched: ", e); + } catch (Exception ex) { + LOG.error("Can't send temporary password. Exception was catched: ", ex); if (isEmpty(user.getExternalUid())) { userFacade.deleteUser(result.getUserId()); } - StringBuilder errorMessage = new StringBuilder("Failed to send email with temporary password. "); - if (e instanceof MailException) { + StringBuilder errorMessage = + new StringBuilder("Failed to send email with temporary password. "); + if (ex instanceof MailException) { errorMessage.append("Please, check outgoing email settings. "); } - throw new KaaAdminServiceException(String.valueOf(errorMessage.append("See server logs for details.")), ServiceErrorCode.GENERAL_ERROR); + throw new KaaAdminServiceException( + String.valueOf(errorMessage.append("See server logs for details.")), + ServiceErrorCode.GENERAL_ERROR); } return result; } @@ -364,7 +378,8 @@ void editUserFacadeUser(org.kaaproject.kaa.common.dto.admin.UserDto user) userFacade.save(storedUserOld); } - org.kaaproject.kaa.common.dto.admin.UserDto editControlServiceUser(org.kaaproject.kaa.common.dto.admin.UserDto user) + org.kaaproject.kaa.common.dto.admin.UserDto editControlServiceUser( + org.kaaproject.kaa.common.dto.admin.UserDto user) throws KaaAdminServiceException, ControlServiceException { if (!isEmpty(getTenantId())) { user.setTenantId(getTenantId()); @@ -387,14 +402,16 @@ void checkCreateUserPermission(UserDto user) throws KaaAdminServiceException { } } - void checkEditUserPermission(UserDto user) throws KaaAdminServiceException, ControlServiceException { + void checkEditUserPermission(UserDto user) + throws KaaAdminServiceException, ControlServiceException { checkUserId(user.getId()); } void setPluginJsonConfigurationFromRaw(PluginDto plugin, PluginType type) { PluginInfoDto pluginInfo = pluginsInfo.get(type).get(plugin.getPluginClassName()); byte[] rawConfiguration = plugin.getRawConfiguration(); - String jsonConfiguration = GenericAvroConverter.toJson(rawConfiguration, pluginInfo.getFieldConfiguration().getSchema()); + String jsonConfiguration = GenericAvroConverter.toJson( + rawConfiguration, pluginInfo.getFieldConfiguration().getSchema()); plugin.setJsonConfiguration(jsonConfiguration); } @@ -402,24 +419,33 @@ void setPluginRawConfigurationFromJson(PluginDto plugin, PluginType type) { LOG.trace("Updating plugin {} configuration using info {}", plugin, pluginsInfo.get(type)); PluginInfoDto pluginInfo = pluginsInfo.get(type).get(plugin.getPluginClassName()); if (pluginInfo == null) { - LOG.error("Plugin configuration for class name {} is not found", plugin.getPluginClassName()); - throw new InvalidParameterException("Plugin configuration for class name " + plugin.getPluginClassName() + " is not found"); + LOG.error( + "Plugin configuration for class name {} is not found", plugin.getPluginClassName()); + throw new InvalidParameterException( + "Plugin configuration for class name " + plugin.getPluginClassName() + " is not found"); } - byte[] rawConfiguration = GenericAvroConverter.toRawData(plugin.getJsonConfiguration(), pluginInfo.getFieldConfiguration() + byte[] rawConfiguration = GenericAvroConverter.toRawData( + plugin.getJsonConfiguration(), pluginInfo.getFieldConfiguration() .getSchema()); plugin.setRawConfiguration(rawConfiguration); } - CtlSchemaFormDto toCtlSchemaForm(CTLSchemaDto ctlSchema, ConverterType converterType) throws KaaAdminServiceException { + CtlSchemaFormDto toCtlSchemaForm(CTLSchemaDto ctlSchema, ConverterType converterType) + throws KaaAdminServiceException { try { CtlSchemaFormDto ctlSchemaForm = new CtlSchemaFormDto(ctlSchema); - SchemaFormAvroConverter converter = getCtlSchemaConverterForScope(ctlSchemaForm.getMetaInfo().getTenantId(), + SchemaFormAvroConverter converter = getCtlSchemaConverterForScope( + ctlSchemaForm.getMetaInfo().getTenantId(), ctlSchemaForm.getMetaInfo().getApplicationId(), converterType); RecordField form = converter.createSchemaFormFromSchema(ctlSchema.getBody()); ctlSchemaForm.setSchema(form); - List availableVersions = controlService.getAllCTLSchemaVersionsByFqnTenantIdAndApplicationId( - ctlSchema.getMetaInfo().getFqn(), ctlSchema.getMetaInfo().getTenantId(), ctlSchema.getMetaInfo().getApplicationId()); - availableVersions = availableVersions == null ? Collections.emptyList() : availableVersions; + List availableVersions = + controlService.getAllCTLSchemaVersionsByFqnTenantIdAndApplicationId( + ctlSchema.getMetaInfo().getFqn(), ctlSchema.getMetaInfo().getTenantId(), + ctlSchema.getMetaInfo().getApplicationId()); + availableVersions = availableVersions == null + ? Collections.emptyList() + : availableVersions; Collections.sort(availableVersions); ctlSchemaForm.getMetaInfo().setVersions(availableVersions); return ctlSchemaForm; @@ -428,7 +454,10 @@ CtlSchemaFormDto toCtlSchemaForm(CTLSchemaDto ctlSchema, ConverterType converter } } - SchemaFormAvroConverter getCtlSchemaConverterForScope(String tenantId, String applicationId, ConverterType converterType) throws KaaAdminServiceException { + SchemaFormAvroConverter getCtlSchemaConverterForScope(String tenantId, + String applicationId, + ConverterType converterType) + throws KaaAdminServiceException { try { if (isEmpty(tenantId)) { return getCtlSchemaConverterForSystem(converterType); @@ -442,31 +471,42 @@ SchemaFormAvroConverter getCtlSchemaConverterForScope(String tenantId, String ap } } - private SchemaFormAvroConverter getCtlSchemaConverterForSystem(ConverterType converterType) throws KaaAdminServiceException { + private SchemaFormAvroConverter getCtlSchemaConverterForSystem(ConverterType converterType) + throws KaaAdminServiceException { try { - return createSchemaConverterFromCtlTypes(controlService.getAvailableCTLSchemaVersionsForSystem(), converterType); + return createSchemaConverterFromCtlTypes( + controlService.getAvailableCTLSchemaVersionsForSystem(), converterType); } catch (Exception cause) { throw Utils.handleException(cause); } } - private SchemaFormAvroConverter getCtlSchemaConverterForTenant(String tenantId, ConverterType converterType) throws KaaAdminServiceException { + private SchemaFormAvroConverter getCtlSchemaConverterForTenant(String tenantId, + ConverterType converterType) + throws KaaAdminServiceException { try { - return createSchemaConverterFromCtlTypes(controlService.getAvailableCTLSchemaVersionsForTenant(tenantId), converterType); + return createSchemaConverterFromCtlTypes( + controlService.getAvailableCTLSchemaVersionsForTenant(tenantId), converterType); } catch (Exception cause) { throw Utils.handleException(cause); } } - private SchemaFormAvroConverter getCtlSchemaConverterForApplication(String tenantId, String applicationId, ConverterType converterType) throws KaaAdminServiceException { + private SchemaFormAvroConverter getCtlSchemaConverterForApplication(String tenantId, + String applicationId, + ConverterType converterType) + throws KaaAdminServiceException { try { - return createSchemaConverterFromCtlTypes(controlService.getAvailableCTLSchemaVersionsForApplication(tenantId, applicationId), converterType); + return createSchemaConverterFromCtlTypes( + controlService.getAvailableCTLSchemaVersionsForApplication(tenantId, applicationId), + converterType); } catch (Exception cause) { throw Utils.handleException(cause); } } - private SchemaFormAvroConverter createSchemaConverterFromCtlTypes(final Map> ctlTypes, ConverterType converterType) throws KaaAdminServiceException { + private SchemaFormAvroConverter createSchemaConverterFromCtlTypes(final Map> ctlTypes, ConverterType converterType) throws KaaAdminServiceException { try { CtlSource ctlSource = new CtlSource() { @Override @@ -484,13 +524,17 @@ public Map> getCtlTypes() { } } - void convertToSchemaForm(AbstractSchemaDto dto, SchemaFormAvroConverter converter) throws IOException { + void convertToSchemaForm(AbstractSchemaDto dto, + SchemaFormAvroConverter converter) + throws IOException { Schema schema = new Schema.Parser().parse(dto.getSchema()); RecordField schemaForm = converter.createSchemaFormFromSchema(schema); dto.setSchemaForm(schemaForm); } - void convertToStringSchema(AbstractSchemaDto dto, SchemaFormAvroConverter converter) throws Exception { + void convertToStringSchema(AbstractSchemaDto dto, + SchemaFormAvroConverter converter) + throws Exception { Schema schema = converter.createSchemaFromSchemaForm(dto.getSchemaForm()); validateRecordSchema(schema); String schemaString = SchemaFormAvroConverter.createSchemaString(schema, true); @@ -499,7 +543,8 @@ void convertToStringSchema(AbstractSchemaDto dto, SchemaFormAvroConverter conver void setPluginRawConfigurationFromForm(PluginDto plugin) throws IOException { RecordField fieldConfiguration = plugin.getFieldConfiguration(); - GenericRecord record = FormAvroConverter.createGenericRecordFromRecordField(fieldConfiguration); + GenericRecord record = FormAvroConverter.createGenericRecordFromRecordField( + fieldConfiguration); GenericAvroConverter converter = new GenericAvroConverter<>(record.getSchema()); byte[] rawConfiguration = converter.encode(record); plugin.setRawConfiguration(rawConfiguration); @@ -509,7 +554,8 @@ void setPluginFormConfigurationFromRaw(PluginDto plugin, PluginType type) throws LOG.trace("Updating plugin {} configuration", plugin); PluginInfoDto pluginInfo = pluginsInfo.get(type).get(plugin.getPluginClassName()); byte[] rawConfiguration = plugin.getRawConfiguration(); - GenericAvroConverter converter = new GenericAvroConverter<>(pluginInfo.getFieldConfiguration().getSchema()); + GenericAvroConverter converter = new GenericAvroConverter<>( + pluginInfo.getFieldConfiguration().getSchema()); GenericRecord record = converter.decodeBinary(rawConfiguration); RecordField formData = FormAvroConverter.createRecordFieldFromGenericRecord(record); plugin.setFieldConfiguration(formData); @@ -517,7 +563,8 @@ void setPluginFormConfigurationFromRaw(PluginDto plugin, PluginType type) throws protected org.kaaproject.kaa.common.dto.admin.UserDto toUser(UserDto tenantUser) { User user = userFacade.findById(Long.valueOf(tenantUser.getExternalUid())); - org.kaaproject.kaa.common.dto.admin.UserDto result = new org.kaaproject.kaa.common.dto.admin.UserDto( + org.kaaproject.kaa.common.dto.admin.UserDto result = + new org.kaaproject.kaa.common.dto.admin.UserDto( user.getId().toString(), user.getUsername(), user.getFirstName(), diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/AdminUIServiceImpl.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/AdminUiServiceImpl.java similarity index 71% rename from server/node/src/main/java/org/kaaproject/kaa/server/admin/services/AdminUIServiceImpl.java rename to server/node/src/main/java/org/kaaproject/kaa/server/admin/services/AdminUiServiceImpl.java index d5a6a80361..4220ea5422 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/AdminUIServiceImpl.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/AdminUiServiceImpl.java @@ -34,27 +34,29 @@ import org.springframework.stereotype.Service; @Service("adminUIService") -public class AdminUIServiceImpl extends AbstractAdminService implements AdminUIService { +public class AdminUiServiceImpl extends AbstractAdminService implements AdminUIService { @Override public PropertiesDto getMailProperties() throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.KAA_ADMIN); try { return propertiesFacade.getPropertiesDto(SmtpMailProperties.class); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public PropertiesDto editMailProperties(PropertiesDto mailPropertiesDto) throws KaaAdminServiceException { + public PropertiesDto editMailProperties(PropertiesDto mailPropertiesDto) + throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.KAA_ADMIN); try { - PropertiesDto storedPropertiesDto = propertiesFacade.editPropertiesDto(mailPropertiesDto, SmtpMailProperties.class); + PropertiesDto storedPropertiesDto = propertiesFacade.editPropertiesDto( + mailPropertiesDto, SmtpMailProperties.class); messagingService.configureMailSender(); return storedPropertiesDto; - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @@ -63,98 +65,116 @@ public PropertiesDto getGeneralProperties() throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.KAA_ADMIN); try { return propertiesFacade.getPropertiesDto(GeneralProperties.class); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public PropertiesDto editGeneralProperties(PropertiesDto generalPropertiesDto) throws KaaAdminServiceException { + public PropertiesDto editGeneralProperties(PropertiesDto generalPropertiesDto) + throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.KAA_ADMIN); try { - PropertiesDto storedPropertiesDto = propertiesFacade.editPropertiesDto(generalPropertiesDto, GeneralProperties.class); + PropertiesDto storedPropertiesDto = propertiesFacade.editPropertiesDto( + generalPropertiesDto, GeneralProperties.class); messagingService.configureMailSender(); return storedPropertiesDto; - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public String getRecordDataByApplicationIdAndSchemaVersion(String applicationId, int schemaVersion, RecordKey.RecordFiles file) + public String getRecordDataByApplicationIdAndSchemaVersion(String applicationId, + int schemaVersion, + RecordKey.RecordFiles file) throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { checkApplicationId(applicationId); RecordKey sdkKey = new RecordKey(applicationId, schemaVersion, file); return Base64.encodeObject(sdkKey, Base64.URL_SAFE); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public String getRecordLibraryByApplicationIdAndSchemaVersion(String applicationId, int logSchemaVersion, RecordKey.RecordFiles file) + public String getRecordLibraryByApplicationIdAndSchemaVersion(String applicationId, + int logSchemaVersion, + RecordKey.RecordFiles file) throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { checkApplicationId(applicationId); RecordKey sdkKey = new RecordKey(applicationId, logSchemaVersion, file); return Base64.encodeObject(sdkKey, Base64.URL_SAFE); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override public RecordField createSimpleEmptySchemaForm() throws KaaAdminServiceException { - checkAuthority(KaaAuthorityDto.TENANT_ADMIN, KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); + checkAuthority( + KaaAuthorityDto.TENANT_ADMIN, + KaaAuthorityDto.TENANT_DEVELOPER, + KaaAuthorityDto.TENANT_USER); try { return simpleSchemaFormAvroConverter.getEmptySchemaFormInstance(); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override public RecordField createCommonEmptySchemaForm() throws KaaAdminServiceException { - checkAuthority(KaaAuthorityDto.TENANT_ADMIN, KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); + checkAuthority( + KaaAuthorityDto.TENANT_ADMIN, + KaaAuthorityDto.TENANT_DEVELOPER, + KaaAuthorityDto.TENANT_USER); try { return commonSchemaFormAvroConverter.getEmptySchemaFormInstance(); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public RecordField generateSimpleSchemaForm(String fileItemName) throws KaaAdminServiceException { - checkAuthority(KaaAuthorityDto.TENANT_ADMIN, KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); + public RecordField generateSimpleSchemaForm(String fileItemName) + throws KaaAdminServiceException { + checkAuthority( + KaaAuthorityDto.TENANT_ADMIN, + KaaAuthorityDto.TENANT_DEVELOPER, + KaaAuthorityDto.TENANT_USER); try { byte[] data = getFileContent(fileItemName); String avroSchema = new String(data); Schema schema = new Schema.Parser().parse(avroSchema); validateRecordSchema(schema); return simpleSchemaFormAvroConverter.createSchemaFormFromSchema(schema); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public RecordField generateCommonSchemaForm(String fileItemName) throws KaaAdminServiceException { + public RecordField generateCommonSchemaForm(String fileItemName) + throws KaaAdminServiceException { try { byte[] data = getFileContent(fileItemName); String avroSchema = new String(data); Schema schema = new Schema.Parser().parse(avroSchema); validateRecordSchema(schema); return commonSchemaFormAvroConverter.createSchemaFormFromSchema(schema); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public RecordField getRecordDataFromFile(String schema, String fileItemName) throws KaaAdminServiceException { + public RecordField getRecordDataFromFile(String schema, String fileItemName) + throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { byte[] body = getFileContent(fileItemName); @@ -162,8 +182,8 @@ public RecordField getRecordDataFromFile(String schema, String fileItemName) thr GenericRecord record = converter.decodeJson(body); RecordField recordData = FormAvroConverter.createRecordFieldFromGenericRecord(record); return recordData; - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } } \ No newline at end of file diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/ApplicationServiceImpl.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/ApplicationServiceImpl.java index b4227aa89c..19fa858bfb 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/ApplicationServiceImpl.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/ApplicationServiceImpl.java @@ -33,17 +33,24 @@ public class ApplicationServiceImpl extends AbstractAdminService implements Appl @Override public List getApplications() throws KaaAdminServiceException { - checkAuthority(KaaAuthorityDto.TENANT_ADMIN, KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); + checkAuthority( + KaaAuthorityDto.TENANT_ADMIN, + KaaAuthorityDto.TENANT_DEVELOPER, + KaaAuthorityDto.TENANT_USER); try { return controlService.getApplicationsByTenantId(getTenantId()); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public ApplicationDto getApplicationByApplicationToken(String applicationToken) throws KaaAdminServiceException { - checkAuthority(KaaAuthorityDto.TENANT_ADMIN, KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); + public ApplicationDto getApplicationByApplicationToken(String applicationToken) + throws KaaAdminServiceException { + checkAuthority( + KaaAuthorityDto.TENANT_ADMIN, + KaaAuthorityDto.TENANT_DEVELOPER, + KaaAuthorityDto.TENANT_USER); try { if (isEmpty(applicationToken)) { throw new KaaAdminServiceException(ServiceErrorCode.INVALID_ARGUMENTS); @@ -51,23 +58,27 @@ public ApplicationDto getApplicationByApplicationToken(String applicationToken) ApplicationDto application = controlService.getApplicationByApplicationToken(applicationToken); checkApplication(application); return application; - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override public ApplicationDto getApplication(String applicationId) throws KaaAdminServiceException { - checkAuthority(KaaAuthorityDto.TENANT_ADMIN, KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); + checkAuthority( + KaaAuthorityDto.TENANT_ADMIN, + KaaAuthorityDto.TENANT_DEVELOPER, + KaaAuthorityDto.TENANT_USER); try { return checkApplicationId(applicationId); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public ApplicationDto editApplication(ApplicationDto application) throws KaaAdminServiceException { + public ApplicationDto editApplication(ApplicationDto application) + throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_ADMIN); try { if (!isEmpty(application.getId())) { @@ -78,8 +89,8 @@ public ApplicationDto editApplication(ApplicationDto application) throws KaaAdmi } application.setTenantId(getTenantId()); return controlService.editApplication(application); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } 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 6999cff094..9b561699d7 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 @@ -33,7 +33,7 @@ import org.kaaproject.kaa.common.dto.ctl.CTLSchemaScopeDto; import org.kaaproject.kaa.common.dto.file.FileData; import org.kaaproject.kaa.server.admin.services.entity.AuthUserDto; -import org.kaaproject.kaa.server.admin.services.schema.CTLSchemaParser; +import org.kaaproject.kaa.server.admin.services.schema.CtlSchemaParser; 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.CtlSchemaExportKey; @@ -62,8 +62,9 @@ public CTLSchemaDto saveCTLSchema(CTLSchemaDto schema) throws KaaAdminServiceExc this.checkAuthority(KaaAuthorityDto.values()); try { Utils.checkNotNull(schema); - checkCTLSchemaVersion(schema.getVersion()); - checkCTLSchemaEditScope(schema.getMetaInfo().getTenantId(), schema.getMetaInfo().getApplicationId()); + checkCtlSchemaVersion(schema.getVersion()); + checkCtlSchemaEditScope( + schema.getMetaInfo().getTenantId(), schema.getMetaInfo().getApplicationId()); // Check if the schema dependencies are present in the database List missingDependencies = new ArrayList<>(); @@ -75,19 +76,22 @@ public CTLSchemaDto saveCTLSchema(CTLSchemaDto schema) throws KaaAdminServiceExc dependency.getMetaInfo().getFqn(), dependency.getVersion(), schema.getMetaInfo().getTenantId(), schema.getMetaInfo().getApplicationId()); if (schemaFound == null) { - missingDependencies.add(new FqnVersion(dependency.getMetaInfo().getFqn(), dependency.getVersion())); + missingDependencies.add( + new FqnVersion(dependency.getMetaInfo().getFqn(), dependency.getVersion())); } else { dependencies.add(schemaFound); } } } if (!missingDependencies.isEmpty()) { - String message = "The following dependencies are missing from the database: " + Arrays.toString(missingDependencies.toArray()); + String message = "The following dependencies are missing from the database: " + + Arrays.toString(missingDependencies.toArray()); throw new IllegalArgumentException(message); } // Check if the schema body is valid - CTLSchemaParser parser = new CTLSchemaParser(controlService, schema.getMetaInfo().getTenantId()); + CtlSchemaParser parser = new CtlSchemaParser( + controlService, schema.getMetaInfo().getTenantId()); parser.validate(schema); CTLSchemaDto result = controlService.saveCTLSchema(schema); @@ -98,22 +102,14 @@ public CTLSchemaDto saveCTLSchema(CTLSchemaDto schema) throws KaaAdminServiceExc } @Override - public CTLSchemaDto saveCTLSchemaWithAppToken(String body, String tenantId, String applicationToken) throws KaaAdminServiceException { - String applicationId = null; - if (!isEmpty(applicationToken)) { - applicationId = checkApplicationToken(applicationToken); - } - return saveCTLSchema(body, tenantId, applicationId); - } - - @Override - public CTLSchemaDto saveCTLSchema(String body, String tenantId, String applicationId) throws KaaAdminServiceException { + public CTLSchemaDto saveCTLSchema(String body, String tenantId, String applicationId) + throws KaaAdminServiceException { this.checkAuthority(KaaAuthorityDto.values()); try { - checkCTLSchemaEditScope(tenantId, applicationId); - CTLSchemaParser parser = new CTLSchemaParser(controlService, tenantId); + checkCtlSchemaEditScope(tenantId, applicationId); + CtlSchemaParser parser = new CtlSchemaParser(controlService, tenantId); CTLSchemaDto schema = parser.parse(body, applicationId); - checkCTLSchemaVersion(schema.getVersion()); + checkCtlSchemaVersion(schema.getVersion()); // Check if the schema body is valid parser.validate(schema); CTLSchemaDto result = controlService.saveCTLSchema(schema); @@ -124,7 +120,23 @@ public CTLSchemaDto saveCTLSchema(String body, String tenantId, String applicati } @Override - public void deleteCTLSchemaByFqnVersionTenantIdAndApplicationToken(String fqn, Integer version, String tenantId, String applicationToken) throws KaaAdminServiceException { + public CTLSchemaDto saveCTLSchemaWithAppToken(String body, + String tenantId, + String applicationToken) + throws KaaAdminServiceException { + String applicationId = null; + if (!isEmpty(applicationToken)) { + applicationId = checkApplicationToken(applicationToken); + } + return saveCTLSchema(body, tenantId, applicationId); + } + + @Override + public void deleteCTLSchemaByFqnVersionTenantIdAndApplicationToken(String fqn, + Integer version, + String tenantId, + String applicationToken) + throws KaaAdminServiceException { String applicationId = null; if (!isEmpty(applicationToken)) { applicationId = checkApplicationToken(applicationToken); @@ -133,32 +145,44 @@ public void deleteCTLSchemaByFqnVersionTenantIdAndApplicationToken(String fqn, I } @Override - public void deleteCTLSchemaByFqnVersionTenantIdAndApplicationId(String fqn, Integer version, String tenantId, String applicationId) throws KaaAdminServiceException { + public void deleteCTLSchemaByFqnVersionTenantIdAndApplicationId(String fqn, + Integer version, + String tenantId, + String applicationId) + throws KaaAdminServiceException { this.checkAuthority(KaaAuthorityDto.values()); try { - this.checkCTLSchemaFqn(fqn); - this.checkCTLSchemaVersion(version); + this.checkCtlSchemaFqn(fqn); + this.checkCtlSchemaVersion(version); if (!isEmpty(applicationId)) { this.checkApplicationId(applicationId); } - CTLSchemaDto schemaFound = controlService.getCTLSchemaByFqnVersionTenantIdAndApplicationId(fqn, version, tenantId, applicationId); + CTLSchemaDto schemaFound = controlService.getCTLSchemaByFqnVersionTenantIdAndApplicationId( + fqn, version, tenantId, applicationId); Utils.checkNotNull(schemaFound); - checkCTLSchemaEditScope(schemaFound.getMetaInfo().getTenantId(), schemaFound.getMetaInfo().getApplicationId()); - List schemaDependents = controlService.getCTLSchemaDependents(fqn, version, tenantId, applicationId); + checkCtlSchemaEditScope( + schemaFound.getMetaInfo().getTenantId(), schemaFound.getMetaInfo().getApplicationId()); + List schemaDependents = controlService.getCTLSchemaDependents( + fqn, version, tenantId, applicationId); if (schemaDependents != null && !schemaDependents.isEmpty()) { - String message = "Can't delete the common type version as it is referenced by the following common type(s): " + String message = "Can't delete the common type version as it is referenced" + + " by the following common type(s): " + this.asText(schemaDependents); throw new IllegalArgumentException(message); } - controlService.deleteCTLSchemaByFqnAndVersionTenantIdAndApplicationId(fqn, version, tenantId, applicationId); + controlService.deleteCTLSchemaByFqnAndVersionTenantIdAndApplicationId( + fqn, version, tenantId, applicationId); } catch (Exception cause) { throw Utils.handleException(cause); } } @Override - public CTLSchemaDto getCTLSchemaByFqnVersionTenantIdAndApplicationToken(String fqn, Integer version, String tenantId, String applicationToken) + public CTLSchemaDto getCTLSchemaByFqnVersionTenantIdAndApplicationToken(String fqn, + Integer version, + String tenantId, + String applicationToken) throws KaaAdminServiceException { String applicationId = null; if (!isEmpty(applicationToken)) { @@ -168,18 +192,23 @@ public CTLSchemaDto getCTLSchemaByFqnVersionTenantIdAndApplicationToken(String f } @Override - public CTLSchemaDto getCTLSchemaByFqnVersionTenantIdAndApplicationId(String fqn, Integer version, String tenantId, String applicationId) + public CTLSchemaDto getCTLSchemaByFqnVersionTenantIdAndApplicationId(String fqn, + Integer version, + String tenantId, + String applicationId) throws KaaAdminServiceException { this.checkAuthority(KaaAuthorityDto.values()); try { - this.checkCTLSchemaFqn(fqn); - this.checkCTLSchemaVersion(version); + this.checkCtlSchemaFqn(fqn); + this.checkCtlSchemaVersion(version); if (!isEmpty(applicationId)) { this.checkApplicationId(applicationId); } - CTLSchemaDto schemaFound = controlService.getCTLSchemaByFqnVersionTenantIdAndApplicationId(fqn, version, tenantId, applicationId); + CTLSchemaDto schemaFound = controlService.getCTLSchemaByFqnVersionTenantIdAndApplicationId( + fqn, version, tenantId, applicationId); Utils.checkNotNull(schemaFound); - checkCTLSchemaReadScope(schemaFound.getMetaInfo().getTenantId(), schemaFound.getMetaInfo().getApplicationId()); + checkCtlSchemaReadScope( + schemaFound.getMetaInfo().getTenantId(), schemaFound.getMetaInfo().getApplicationId()); return schemaFound; } catch (Exception cause) { throw Utils.handleException(cause); @@ -190,10 +219,11 @@ public CTLSchemaDto getCTLSchemaByFqnVersionTenantIdAndApplicationId(String fqn, public CTLSchemaDto getCTLSchemaById(String schemaId) throws KaaAdminServiceException { this.checkAuthority(KaaAuthorityDto.values()); try { - this.checkCTLSchemaId(schemaId); + this.checkCtlSchemaId(schemaId); CTLSchemaDto schemaFound = controlService.getCTLSchemaById(schemaId); Utils.checkNotNull(schemaFound); - checkCTLSchemaReadScope(schemaFound.getMetaInfo().getTenantId(), schemaFound.getMetaInfo().getApplicationId()); + checkCtlSchemaReadScope( + schemaFound.getMetaInfo().getTenantId(), schemaFound.getMetaInfo().getApplicationId()); return schemaFound; } catch (Exception cause) { throw Utils.handleException(cause); @@ -201,7 +231,8 @@ public CTLSchemaDto getCTLSchemaById(String schemaId) throws KaaAdminServiceExce } @Override - public boolean checkFqnExistsWithAppToken(String fqn, String tenantId, String applicationToken) throws KaaAdminServiceException { + public boolean checkFqnExistsWithAppToken(String fqn, String tenantId, String applicationToken) + throws KaaAdminServiceException { String applicationId = null; if (!isEmpty(applicationToken)) { applicationId = checkApplicationToken(applicationToken); @@ -214,8 +245,9 @@ public boolean checkFqnExists(String fqn, String tenantId, String applicationId) throws KaaAdminServiceException { this.checkAuthority(KaaAuthorityDto.values()); try { - this.checkCTLSchemaFqn(fqn); - List result = controlService.getSiblingsByFqnTenantIdAndApplicationId(fqn, tenantId, applicationId); + this.checkCtlSchemaFqn(fqn); + List result = controlService.getSiblingsByFqnTenantIdAndApplicationId( + fqn, tenantId, applicationId); return result != null && !result.isEmpty(); } catch (Exception cause) { throw Utils.handleException(cause); @@ -245,23 +277,28 @@ public CTLSchemaMetaInfoDto promoteScopeToTenant(String applicationId, String fq checkAuthority(KaaAuthorityDto.values()); final String tenantId = getTenantId(); checkApplicationId(applicationId); - checkCTLSchemaEditScope(tenantId, applicationId); + checkCtlSchemaEditScope(tenantId, applicationId); try { Set dependencies = new HashSet<>(); - List versions = controlService.getAllCTLSchemaVersionsByFqnTenantIdAndApplicationId(fqn, tenantId, applicationId); + List versions = controlService.getAllCTLSchemaVersionsByFqnTenantIdAndApplicationId( + fqn, tenantId, applicationId); if (versions.isEmpty()) { - throw new KaaAdminServiceException("The requested item was not found!", ServiceErrorCode.ITEM_NOT_FOUND); + throw new KaaAdminServiceException( + "The requested item was not found!", ServiceErrorCode.ITEM_NOT_FOUND); } // meta info same for all versions - CTLSchemaMetaInfoDto ctlSchemaMetaInfo = controlService.getCTLSchemaByFqnVersionTenantIdAndApplicationId(fqn, versions.get(0), tenantId, applicationId).getMetaInfo(); + CTLSchemaMetaInfoDto ctlSchemaMetaInfo = + controlService.getCTLSchemaByFqnVersionTenantIdAndApplicationId( + fqn, versions.get(0), tenantId, applicationId).getMetaInfo(); ctlSchemaMetaInfo.setApplicationId(null); //promote to tenant // get dep of all versions for (Integer version : versions) { - CTLSchemaDto schema = controlService.getCTLSchemaByFqnVersionTenantIdAndApplicationId(fqn, version, tenantId, applicationId); + CTLSchemaDto schema = controlService.getCTLSchemaByFqnVersionTenantIdAndApplicationId( + fqn, version, tenantId, applicationId); Set schemaDependents = schema.getDependencySet(); dependencies.addAll(schemaDependents.stream() .filter(dep -> dep.getMetaInfo().getScope() == CTLSchemaScopeDto.APPLICATION) @@ -270,7 +307,8 @@ public CTLSchemaMetaInfoDto promoteScopeToTenant(String applicationId, String fq // check if CT has dependencies with application scope if (!dependencies.isEmpty()) { - String message = "Can't promote the common type version as it has references on following common type(s) with application scope: " + String message = "Can't promote the common type version as it has references" + + " on following common type(s) with application scope: " + asText(dependencies); throw new KaaAdminServiceException(message, ServiceErrorCode.CONFLICT); } @@ -293,7 +331,10 @@ public List getSystemLevelCTLSchemas() throws KaaAdminServ @Override public List getTenantLevelCTLSchemas() throws KaaAdminServiceException { - checkAuthority(KaaAuthorityDto.TENANT_ADMIN, KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); + checkAuthority( + KaaAuthorityDto.TENANT_ADMIN, + KaaAuthorityDto.TENANT_DEVELOPER, + KaaAuthorityDto.TENANT_USER); try { AuthUserDto currentUser = getCurrentUser(); return controlService.getAvailableCTLSchemasMetaInfoForTenant(currentUser.getTenantId()); @@ -303,51 +344,60 @@ public List getTenantLevelCTLSchemas() throws KaaAdminServ } @Override - public List getTenantLevelCTLSchemaReferenceForECF(String ecfId, List eventClassViewDtoList) throws KaaAdminServiceException { + public List getTenantLevelCTLSchemaReferenceForECF( + String ecfId, List eventClassViewDtoList) + throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_ADMIN); try { AuthUserDto currentUser = getCurrentUser(); - List ctlSchemaReferenceDtoListForTenant = controlService.getAvailableCTLSchemasMetaInfoForTenant(currentUser.getTenantId()); - Set fqnListOfCurrentECF = controlService.getFqnSetForECF(ecfId); + List ctlSchemaReferenceDtoListForTenant = + controlService.getAvailableCTLSchemasMetaInfoForTenant(currentUser.getTenantId()); + Set fqnListOfCurrentEcf = controlService.getFqnSetForECF(ecfId); if (eventClassViewDtoList != null) { for (EventClassViewDto eventClassViewDto : eventClassViewDtoList) { String fqn = eventClassViewDto.getCtlSchemaForm().getMetaInfo().getFqn(); - fqnListOfCurrentECF.add(fqn); + fqnListOfCurrentEcf.add(fqn); } } - List availableCtlSchemaReferenceForECF = new ArrayList<>(); + List availableCtlSchemaReferenceForEcf = new ArrayList<>(); for (CTLSchemaMetaInfoDto metaInfo : ctlSchemaReferenceDtoListForTenant) { - if (!fqnListOfCurrentECF.contains(metaInfo.getFqn())) { + if (!fqnListOfCurrentEcf.contains(metaInfo.getFqn())) { for (int version : metaInfo.getVersions()) { - availableCtlSchemaReferenceForECF.add(new CtlSchemaReferenceDto(metaInfo, version)); + availableCtlSchemaReferenceForEcf.add(new CtlSchemaReferenceDto(metaInfo, version)); } } } - return availableCtlSchemaReferenceForECF; + return availableCtlSchemaReferenceForEcf; } catch (Exception cause) { throw Utils.handleException(cause); } } @Override - public List getApplicationLevelCTLSchemasByAppToken(String applicationToken) throws KaaAdminServiceException { + public List getApplicationLevelCTLSchemasByAppToken( + String applicationToken) throws KaaAdminServiceException { return getApplicationLevelCTLSchemas(checkApplicationToken(applicationToken)); } @Override - public List getApplicationLevelCTLSchemas(String applicationId) throws KaaAdminServiceException { + public List getApplicationLevelCTLSchemas(String applicationId) + throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { this.checkApplicationId(applicationId); AuthUserDto currentUser = getCurrentUser(); - return controlService.getAvailableCTLSchemasMetaInfoForApplication(currentUser.getTenantId(), applicationId); + return controlService.getAvailableCTLSchemasMetaInfoForApplication( + currentUser.getTenantId(),applicationId); } catch (Exception cause) { throw Utils.handleException(cause); } } @Override - public FileData exportCTLSchemaByAppToken(String fqn, int version, String applicationToken, CTLSchemaExportMethod method) throws KaaAdminServiceException { + public FileData exportCTLSchemaByAppToken(String fqn, int version, + String applicationToken, + CTLSchemaExportMethod method) + throws KaaAdminServiceException { String applicationId = null; if (!isEmpty(applicationToken)) { applicationId = checkApplicationToken(applicationToken); @@ -356,14 +406,18 @@ public FileData exportCTLSchemaByAppToken(String fqn, int version, String applic } @Override - public FileData exportCTLSchema(String fqn, int version, String applicationId, CTLSchemaExportMethod method) throws KaaAdminServiceException { + public FileData exportCTLSchema(String fqn, int version, + String applicationId, + CTLSchemaExportMethod method) throws KaaAdminServiceException { try { - this.checkCTLSchemaFqn(fqn); - this.checkCTLSchemaVersion(version); + this.checkCtlSchemaFqn(fqn); + this.checkCtlSchemaVersion(version); String tenantId = getCurrentUser().getTenantId(); - CTLSchemaDto schemaFound = controlService.getCTLSchemaByFqnVersionTenantIdAndApplicationId(fqn, version, tenantId, applicationId); + CTLSchemaDto schemaFound = controlService.getCTLSchemaByFqnVersionTenantIdAndApplicationId( + fqn, version, tenantId, applicationId); Utils.checkNotNull(schemaFound); - checkCTLSchemaReadScope(schemaFound.getMetaInfo().getTenantId(), schemaFound.getMetaInfo().getApplicationId()); + checkCtlSchemaReadScope( + schemaFound.getMetaInfo().getTenantId(), schemaFound.getMetaInfo().getApplicationId()); switch (method) { case SHALLOW: return controlService.exportCTLSchemaShallow(schemaFound); @@ -372,7 +426,8 @@ public FileData exportCTLSchema(String fqn, int version, String applicationId, C case DEEP: return controlService.exportCTLSchemaDeep(schemaFound); default: - throw new IllegalArgumentException("The export method " + method.name() + " is not currently supported!"); + throw new IllegalArgumentException( + "The export method " + method.name()+ " is not currently supported!"); } } catch (Exception cause) { throw Utils.handleException(cause); @@ -380,7 +435,9 @@ public FileData exportCTLSchema(String fqn, int version, String applicationId, C } @Override - public CtlSchemaFormDto saveCTLSchemaForm(CtlSchemaFormDto ctlSchemaForm, ConverterType converterType) throws KaaAdminServiceException { + public CtlSchemaFormDto saveCTLSchemaForm(CtlSchemaFormDto ctlSchemaForm, + ConverterType converterType) + throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.values()); try { AuthUserDto currentUser = getCurrentUser(); @@ -406,7 +463,8 @@ public CtlSchemaFormDto saveCTLSchemaForm(CtlSchemaFormDto ctlSchemaForm, Conver Set dependencies = new HashSet<>(); List missingDependencies = new ArrayList<>(); for (FqnVersion fqnVersion : dependenciesList) { - CTLSchemaDto dependency = controlService.getAnyCTLSchemaByFqnVersionTenantIdAndApplicationId( + CTLSchemaDto dependency = + controlService.getAnyCTLSchemaByFqnVersionTenantIdAndApplicationId( fqnVersion.getFqnString(), fqnVersion.getVersion(), ctlSchema.getMetaInfo().getTenantId(), ctlSchema.getMetaInfo().getApplicationId()); if (dependency != null) { @@ -416,11 +474,13 @@ public CtlSchemaFormDto saveCTLSchemaForm(CtlSchemaFormDto ctlSchemaForm, Conver } } if (!missingDependencies.isEmpty()) { - String message = "The following dependencies are missing from the database: " + Arrays.toString(missingDependencies.toArray()); + String message = "The following dependencies are missing from the database: " + + Arrays.toString(missingDependencies.toArray()); throw new IllegalArgumentException(message); } ctlSchema.setDependencySet(dependencies); - SchemaFormAvroConverter converter = getCtlSchemaConverterForScope(ctlSchema.getMetaInfo().getTenantId(), + SchemaFormAvroConverter converter = getCtlSchemaConverterForScope( + ctlSchema.getMetaInfo().getTenantId(), ctlSchema.getMetaInfo().getApplicationId(), converterType); Schema avroSchema = converter.createSchemaFromSchemaForm(schemaForm); String schemaBody = SchemaFormAvroConverter.createSchemaString(avroSchema, true); @@ -438,13 +498,19 @@ public CtlSchemaFormDto saveCTLSchemaForm(CtlSchemaFormDto ctlSchemaForm, Conver } @Override - public List getAvailableApplicationCTLSchemaReferences(String applicationId) + public List getAvailableApplicationCTLSchemaReferences( + String applicationId) throws KaaAdminServiceException { - checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER, KaaAuthorityDto.TENANT_ADMIN); + checkAuthority( + KaaAuthorityDto.TENANT_DEVELOPER, + KaaAuthorityDto.TENANT_USER, + KaaAuthorityDto.TENANT_ADMIN); try { AuthUserDto currentUser = getCurrentUser(); List result = new ArrayList<>(); - List availableMetaInfo = controlService.getAvailableCTLSchemasMetaInfoForApplication(currentUser.getTenantId(), applicationId); + List availableMetaInfo = + controlService.getAvailableCTLSchemasMetaInfoForApplication( + currentUser.getTenantId(), applicationId); for (CTLSchemaMetaInfoDto metaInfo : availableMetaInfo) { for (int version : metaInfo.getVersions()) { result.add(new CtlSchemaReferenceDto(metaInfo, version)); @@ -458,13 +524,15 @@ public List getAvailableApplicationCTLSchemaReferences(St @Override - public CtlSchemaFormDto getLatestCTLSchemaForm(String metaInfoId) throws KaaAdminServiceException { + public CtlSchemaFormDto getLatestCTLSchemaForm(String metaInfoId) + throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.values()); try { - this.checkCTLSchemaMetaInfoId(metaInfoId); + this.checkCtlSchemaMetaInfoId(metaInfoId); CTLSchemaDto ctlSchema = controlService.getLatestCTLSchemaByMetaInfoId(metaInfoId); Utils.checkNotNull(ctlSchema); - checkCTLSchemaReadScope(ctlSchema.getMetaInfo().getTenantId(), ctlSchema.getMetaInfo().getApplicationId()); + checkCtlSchemaReadScope( + ctlSchema.getMetaInfo().getTenantId(), ctlSchema.getMetaInfo().getApplicationId()); return toCtlSchemaForm(ctlSchema, ConverterType.FORM_AVRO_CONVERTER); } catch (Exception cause) { throw Utils.handleException(cause); @@ -472,14 +540,17 @@ public CtlSchemaFormDto getLatestCTLSchemaForm(String metaInfoId) throws KaaAdmi } @Override - public CtlSchemaFormDto getCTLSchemaFormByMetaInfoIdAndVer(String metaInfoId, int version) throws KaaAdminServiceException { + public CtlSchemaFormDto getCTLSchemaFormByMetaInfoIdAndVer(String metaInfoId, int version) + throws KaaAdminServiceException { this.checkAuthority(KaaAuthorityDto.values()); try { - this.checkCTLSchemaMetaInfoId(metaInfoId); - this.checkCTLSchemaVersion(version); - CTLSchemaDto schemaFound = controlService.getCTLSchemaByMetaInfoIdAndVer(metaInfoId, version); + this.checkCtlSchemaMetaInfoId(metaInfoId); + this.checkCtlSchemaVersion(version); + CTLSchemaDto schemaFound = controlService.getCTLSchemaByMetaInfoIdAndVer( + metaInfoId, version); Utils.checkNotNull(schemaFound); - checkCTLSchemaReadScope(schemaFound.getMetaInfo().getTenantId(), schemaFound.getMetaInfo().getApplicationId()); + checkCtlSchemaReadScope( + schemaFound.getMetaInfo().getTenantId(), schemaFound.getMetaInfo().getApplicationId()); return toCtlSchemaForm(schemaFound, ConverterType.FORM_AVRO_CONVERTER); } catch (Exception cause) { throw Utils.handleException(cause); @@ -487,10 +558,15 @@ public CtlSchemaFormDto getCTLSchemaFormByMetaInfoIdAndVer(String metaInfoId, in } @Override - public CtlSchemaFormDto createNewCTLSchemaFormInstance(String metaInfoId, Integer sourceVersion, String applicationId, ConverterType converterType) throws KaaAdminServiceException { + public CtlSchemaFormDto createNewCTLSchemaFormInstance(String metaInfoId, + Integer sourceVersion, + String applicationId, + ConverterType converterType) + throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.values()); try { - SchemaFormAvroConverter converter = getCtlSchemaConverterForScope(getCurrentUser().getTenantId(), applicationId, converterType); + SchemaFormAvroConverter converter = getCtlSchemaConverterForScope( + getCurrentUser().getTenantId(), applicationId, converterType); CtlSchemaFormDto sourceCtlSchema = null; if (!isEmpty(metaInfoId) && sourceVersion != null) { sourceCtlSchema = getCTLSchemaFormByMetaInfoIdAndVer(metaInfoId, sourceVersion); @@ -498,14 +574,17 @@ public CtlSchemaFormDto createNewCTLSchemaFormInstance(String metaInfoId, Intege } CtlSchemaFormDto ctlSchemaForm = null; if (sourceCtlSchema != null) { - checkCTLSchemaEditScope(sourceCtlSchema.getMetaInfo().getTenantId(), sourceCtlSchema.getMetaInfo().getApplicationId()); + checkCtlSchemaEditScope( + sourceCtlSchema.getMetaInfo().getTenantId(), + sourceCtlSchema.getMetaInfo().getApplicationId()); ctlSchemaForm = new CtlSchemaFormDto(); ctlSchemaForm.setMetaInfo(sourceCtlSchema.getMetaInfo()); RecordField form = sourceCtlSchema.getSchema(); - form.updateVersion(form.getContext().getMaxVersion(new Fqn(sourceCtlSchema.getMetaInfo().getFqn())) + 1); + form.updateVersion(form.getContext().getMaxVersion( + new Fqn(sourceCtlSchema.getMetaInfo().getFqn())) + 1); ctlSchemaForm.setSchema(form); } else { - checkCTLSchemaEditScope(getCurrentUser().getTenantId(), applicationId); + checkCtlSchemaEditScope(getCurrentUser().getTenantId(), applicationId); ctlSchemaForm = new CtlSchemaFormDto(); RecordField form = converter.getEmptySchemaFormInstance(); form.updateVersion(1); @@ -525,33 +604,36 @@ public RecordField generateCtlSchemaForm(String fileItemName, String application throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.values()); try { - checkCTLSchemaReadScope(getCurrentUser().getTenantId(), applicationId); + checkCtlSchemaReadScope(getCurrentUser().getTenantId(), applicationId); byte[] data = getFileContent(fileItemName); String avroSchema = new String(data); validateRecordSchema(avroSchema, true); - SchemaFormAvroConverter converter = getCtlSchemaConverterForScope(getCurrentUser().getTenantId(), applicationId, ConverterType.FORM_AVRO_CONVERTER); + SchemaFormAvroConverter converter = getCtlSchemaConverterForScope( + getCurrentUser().getTenantId(), applicationId, ConverterType.FORM_AVRO_CONVERTER); RecordField form = converter.createSchemaFormFromSchema(avroSchema); if (form.getVersion() == null) { form.updateVersion(1); } return form; - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override public String prepareCTLSchemaExport(String ctlSchemaId, - CTLSchemaExportMethod method) throws KaaAdminServiceException { + CTLSchemaExportMethod method) + throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.values()); try { CTLSchemaDto schemaFound = controlService.getCTLSchemaById(ctlSchemaId); Utils.checkNotNull(schemaFound); - checkCTLSchemaReadScope(schemaFound.getMetaInfo().getTenantId(), schemaFound.getMetaInfo().getApplicationId()); + checkCtlSchemaReadScope( + schemaFound.getMetaInfo().getTenantId(), schemaFound.getMetaInfo().getApplicationId()); CtlSchemaExportKey key = new CtlSchemaExportKey(ctlSchemaId, method); return Base64.encodeObject(key, Base64.URL_SAFE); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @@ -560,12 +642,13 @@ public String getFlatSchemaByCtlSchemaId(String schemaId) throws KaaAdminService this.checkAuthority(KaaAuthorityDto.values()); try { return controlService.getFlatSchemaByCtlSchemaId(schemaId); - } catch (ControlServiceException e) { - throw Utils.handleException(e); + } catch (ControlServiceException ex) { + throw Utils.handleException(ex); } } - private void checkCTLSchemaEditScope(String tenantId, String applicationId) throws KaaAdminServiceException { + private void checkCtlSchemaEditScope(String tenantId, String applicationId) + throws KaaAdminServiceException { AuthUserDto currentUser = getCurrentUser(); CTLSchemaScopeDto scope = detectScope(tenantId, applicationId); boolean allowed = false; @@ -593,25 +676,25 @@ private void checkCTLSchemaEditScope(String tenantId, String applicationId) thro } } - private void checkCTLSchemaId(String schemaId) throws KaaAdminServiceException { + private void checkCtlSchemaId(String schemaId) throws KaaAdminServiceException { if (schemaId == null || schemaId.isEmpty()) { throw new IllegalArgumentException("Missing CTL schema ID!"); } } - private void checkCTLSchemaMetaInfoId(String metaInfoId) throws KaaAdminServiceException { + private void checkCtlSchemaMetaInfoId(String metaInfoId) throws KaaAdminServiceException { if (metaInfoId == null || metaInfoId.isEmpty()) { throw new IllegalArgumentException("Missing CTL schema meta info ID!"); } } - private void checkCTLSchemaFqn(String fqn) throws KaaAdminServiceException { + private void checkCtlSchemaFqn(String fqn) throws KaaAdminServiceException { if (fqn == null || fqn.isEmpty()) { throw new IllegalArgumentException("Missing fully qualified CTL schema name!"); } } - private void checkCTLSchemaVersion(Integer version) throws KaaAdminServiceException { + private void checkCtlSchemaVersion(Integer version) throws KaaAdminServiceException { if (version == null) { throw new IllegalArgumentException("Missing CTL schema version number!"); } else if (version <= 0) { @@ -631,7 +714,8 @@ private CTLSchemaScopeDto detectScope(String tenantId, String applicationId) { return scope; } - private void checkCTLSchemaReadScope(String tenantId, String applicationId) throws KaaAdminServiceException { + private void checkCtlSchemaReadScope(String tenantId, String applicationId) + throws KaaAdminServiceException { AuthUserDto currentUser = getCurrentUser(); CTLSchemaScopeDto scope = detectScope(tenantId, applicationId); boolean allowed = false; @@ -676,23 +760,32 @@ private String asText(Collection types) { if (types != null) { for (CTLSchemaDto type : types) { CTLSchemaMetaInfoDto details = type.getMetaInfo(); - message.append("\n").append("FQN: ").append(details.getFqn()).append(", version: ").append(type.getVersion()); + message.append("\n").append("FQN: ") + .append(details.getFqn()) + .append(", version: ") + .append(type.getVersion()); } } return message.toString(); } @Override - public CtlSchemaReferenceDto getLastCtlSchemaReferenceDto(String ctlSchemaId) throws KaaAdminServiceException { + 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(); + 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); + } catch (Exception ex) { + throw Utils.handleException(ex); } return null; } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/DeviceManagementServiceImpl.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/DeviceManagementServiceImpl.java index 1b10346cc0..3179e8de44 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/DeviceManagementServiceImpl.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/DeviceManagementServiceImpl.java @@ -36,10 +36,13 @@ import java.util.Optional; @Service("deviceManagementService") -public class DeviceManagementServiceImpl extends AbstractAdminService implements DeviceManagementService { +public class DeviceManagementServiceImpl + extends AbstractAdminService + implements DeviceManagementService { @Override - public CredentialsDto provisionCredentials(String applicationToken, String credentialsBody) throws KaaAdminServiceException { + public CredentialsDto provisionCredentials(String applicationToken, String credentialsBody) + throws KaaAdminServiceException { this.checkAuthority(KaaAuthorityDto.TENANT_ADMIN); try { String applicationId = checkApplicationToken(applicationToken); @@ -59,29 +62,37 @@ public void provisionRegistration( this.checkAuthority(KaaAuthorityDto.TENANT_ADMIN); try { String applicationId = checkApplicationToken(applicationToken); - Optional credentials = this.controlService.getCredentials(applicationId, credentialsId); + Optional credentials = this.controlService.getCredentials( + applicationId, credentialsId); Validate.isTrue(credentials.isPresent(), "No credentials with the given ID found!"); - Validate.isTrue(credentials.get().getStatus() != CredentialsStatus.REVOKED, "The credentials with the given ID are revoked!"); + Validate.isTrue( + credentials.get().getStatus() != CredentialsStatus.REVOKED, + "The credentials with the given ID are revoked!"); if (serverProfileVersion != null && serverProfileBody != null) { - ServerProfileSchemaDto serverProfileSchema = this.getServerProfileSchema(applicationId, serverProfileVersion); + ServerProfileSchemaDto serverProfileSchema = this.getServerProfileSchema( + applicationId, serverProfileVersion); this.validateServerProfile(serverProfileSchema, serverProfileBody); } else if (serverProfileVersion != null || serverProfileBody != null) { String missingParameter = (serverProfileVersion == null ? "schema version" : "body"); - String message = MessageFormat.format("The server-side endpoint profile {0} provided is empty!", missingParameter); + String message = MessageFormat.format( + "The server-side endpoint profile {0} provided is empty!", missingParameter); throw new IllegalArgumentException(message); } - this.controlService.provisionRegistration(applicationId, credentialsId, serverProfileVersion, serverProfileBody); + this.controlService.provisionRegistration( + applicationId, credentialsId, serverProfileVersion, serverProfileBody); } catch (Exception cause) { throw Utils.handleException(cause); } } @Override - public void revokeCredentials(String applicationToken, String credentialsId) throws KaaAdminServiceException { + public void revokeCredentials(String applicationToken, String credentialsId) + throws KaaAdminServiceException { this.checkAuthority(KaaAuthorityDto.TENANT_ADMIN); try { String applicationId = checkApplicationToken(applicationToken); - Validate.isTrue(this.controlService.getCredentials(applicationId, credentialsId).isPresent(), "No credentials with the given ID found!"); + Validate.isTrue(this.controlService.getCredentials( + applicationId, credentialsId).isPresent(), "No credentials with the given ID found!"); this.controlService.revokeCredentials(applicationId, credentialsId); } catch (Exception cause) { throw Utils.handleException(cause); @@ -89,13 +100,17 @@ public void revokeCredentials(String applicationToken, String credentialsId) thr } @Override - public void onCredentialsRevoked(String applicationToken, String credentialsId) throws KaaAdminServiceException { + public void onCredentialsRevoked(String applicationToken, String credentialsId) + throws KaaAdminServiceException { this.checkAuthority(KaaAuthorityDto.TENANT_ADMIN); try { String applicationId = checkApplicationToken(applicationToken); - Optional credentials = this.controlService.getCredentials(applicationId, credentialsId); + Optional credentials = this.controlService.getCredentials( + applicationId, credentialsId); Validate.isTrue(credentials.isPresent(), "No credentials with the given ID found!"); - Validate.isTrue(credentials.get().getStatus() == CredentialsStatus.REVOKED, "Credentails with the given ID are not revoked!"); + Validate.isTrue( + credentials.get().getStatus() == CredentialsStatus.REVOKED, + "Credentails with the given ID are not revoked!"); this.controlService.onCredentailsRevoked(applicationId, credentials.get().getId()); } catch (Exception cause) { throw Utils.handleException(cause); @@ -110,7 +125,8 @@ public CredentialsStatus getCredentialsStatus( this.checkAuthority(KaaAuthorityDto.TENANT_ADMIN); try { String applicationId = checkApplicationToken(applicationToken); - Optional credentials = this.controlService.getCredentials(applicationId, credentialsId); + Optional credentials = this.controlService.getCredentials( + applicationId, credentialsId); Validate.isTrue(credentials.isPresent(), "No credentials with the given ID found!"); return credentials.get().getStatus(); } catch (Exception cause) { @@ -128,16 +144,22 @@ public List getCredentialsServiceNames() throws KaaAdminServiceException } } - private ServerProfileSchemaDto getServerProfileSchema(String applicationId, Integer serverProfileVersion) throws Exception { - ServerProfileSchemaDto serverProfileSchema = this.controlService.getServerProfileSchemaByApplicationIdAndVersion(applicationId, serverProfileVersion); + private ServerProfileSchemaDto getServerProfileSchema(String applicationId, + Integer serverProfileVersion) + throws Exception { + ServerProfileSchemaDto serverProfileSchema = + this.controlService.getServerProfileSchemaByApplicationIdAndVersion( + applicationId, serverProfileVersion); if (serverProfileSchema == null) { throw new NotFoundException("No server-side endpoint profile schema found!"); } return serverProfileSchema; } - private void validateServerProfile(ServerProfileSchemaDto serverProfileSchema, String serverProfileBody) throws Exception { - CTLSchemaDto commonType = this.controlService.getCTLSchemaById(serverProfileSchema.getCtlSchemaId()); + private void validateServerProfile(ServerProfileSchemaDto serverProfileSchema, + String serverProfileBody) throws Exception { + CTLSchemaDto commonType = this.controlService.getCTLSchemaById( + serverProfileSchema.getCtlSchemaId()); Schema typeSchema = this.controlService.exportCTLSchemaFlatAsSchema(commonType); try { new GenericAvroConverter(typeSchema).decodeJson(serverProfileBody); 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 43670b52bf..4ac9346029 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 @@ -56,30 +56,34 @@ public List getEventClassFamilies() throws KaaAdminServiceE checkAuthority(KaaAuthorityDto.TENANT_ADMIN); try { return controlService.getEventClassFamiliesByTenantId(getTenantId()); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public EventClassFamilyDto getEventClassFamily(String eventClassFamilyId) throws KaaAdminServiceException { + public EventClassFamilyDto getEventClassFamily(String eventClassFamilyId) + throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_ADMIN); try { - EventClassFamilyDto eventClassFamily = controlService.getEventClassFamily(eventClassFamilyId); + EventClassFamilyDto eventClassFamily = + controlService.getEventClassFamily(eventClassFamilyId); Utils.checkNotNull(eventClassFamily); checkTenantId(eventClassFamily.getTenantId()); return eventClassFamily; - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public EventClassFamilyDto editEventClassFamily(EventClassFamilyDto eventClassFamily) throws KaaAdminServiceException { + public EventClassFamilyDto editEventClassFamily(EventClassFamilyDto eventClassFamily) + throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_ADMIN); try { if (!isEmpty(eventClassFamily.getId())) { - EventClassFamilyDto storedEventClassFamily = controlService.getEventClassFamily(eventClassFamily.getId()); + EventClassFamilyDto storedEventClassFamily = + controlService.getEventClassFamily(eventClassFamily.getId()); Utils.checkNotNull(storedEventClassFamily); checkTenantId(storedEventClassFamily.getTenantId()); } else { @@ -88,61 +92,71 @@ public EventClassFamilyDto editEventClassFamily(EventClassFamilyDto eventClassFa } eventClassFamily.setTenantId(getTenantId()); return controlService.editEventClassFamily(eventClassFamily); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public void addEventClassFamilyVersion(String eventClassFamilyId, EventClassFamilyVersionDto eventClassFamilyVersion) throws KaaAdminServiceException { + public void addEventClassFamilyVersion(String eventClassFamilyId, + EventClassFamilyVersionDto eventClassFamilyVersion) + throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_ADMIN); try { checkEventClassFamilyId(eventClassFamilyId); - EventClassFamilyDto storedEventClassFamily = controlService.getEventClassFamily(eventClassFamilyId); + EventClassFamilyDto storedEventClassFamily = + controlService.getEventClassFamily(eventClassFamilyId); Utils.checkNotNull(storedEventClassFamily); checkTenantId(storedEventClassFamily.getTenantId()); String username = getCurrentUser().getUsername(); - controlService.addEventClassFamilyVersion(eventClassFamilyId, eventClassFamilyVersion, username); - } catch (Exception e) { - throw Utils.handleException(e); + controlService.addEventClassFamilyVersion( + eventClassFamilyId, eventClassFamilyVersion, username); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public List getApplicationEventFamilyMapsByApplicationToken(String applicationToken) + public List getApplicationEventFamilyMapsByApplicationToken( + String applicationToken) throws KaaAdminServiceException { return getApplicationEventFamilyMapsByApplicationId(checkApplicationToken(applicationToken)); } @Override - public List getApplicationEventFamilyMapsByApplicationId(String applicationId) + public List getApplicationEventFamilyMapsByApplicationId( + String applicationId) throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { checkApplicationId(applicationId); return controlService.getApplicationEventFamilyMapsByApplicationId(applicationId); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public ApplicationEventFamilyMapDto getApplicationEventFamilyMap(String applicationEventFamilyMapId) throws KaaAdminServiceException { + public ApplicationEventFamilyMapDto getApplicationEventFamilyMap( + String applicationEventFamilyMapId) + throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { - ApplicationEventFamilyMapDto aefMap = controlService.getApplicationEventFamilyMap(applicationEventFamilyMapId); + ApplicationEventFamilyMapDto aefMap = controlService.getApplicationEventFamilyMap( + applicationEventFamilyMapId); Utils.checkNotNull(aefMap); checkApplicationId(aefMap.getApplicationId()); return aefMap; - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public ApplicationEventFamilyMapDto editApplicationEventFamilyMap(ApplicationEventFamilyMapDto applicationEventFamilyMap) + public ApplicationEventFamilyMapDto editApplicationEventFamilyMap( + ApplicationEventFamilyMapDto applicationEventFamilyMap) throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { @@ -157,40 +171,45 @@ public ApplicationEventFamilyMapDto editApplicationEventFamilyMap(ApplicationEve checkApplicationId(storedApplicationEventFamilyMap.getApplicationId()); } return controlService.editApplicationEventFamilyMap(applicationEventFamilyMap); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public List getVacantEventClassFamiliesByApplicationToken(String applicationToken) throws KaaAdminServiceException { + public List getVacantEventClassFamiliesByApplicationToken( + String applicationToken) + throws KaaAdminServiceException { return getVacantEventClassFamiliesByApplicationId(checkApplicationToken(applicationToken)); } @Override - public List getVacantEventClassFamiliesByApplicationId(String applicationId) throws KaaAdminServiceException { + public List getVacantEventClassFamiliesByApplicationId(String applicationId) + throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { checkApplicationId(applicationId); return controlService.getVacantEventClassFamiliesByApplicationId(applicationId); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public List getEventClassFamiliesByApplicationToken(String applicationToken) throws KaaAdminServiceException { + public List getEventClassFamiliesByApplicationToken(String applicationToken) + throws KaaAdminServiceException { return getEventClassFamiliesByApplicationId(checkApplicationToken(applicationToken)); } @Override - public List getEventClassFamiliesByApplicationId(String applicationId) throws KaaAdminServiceException { + public List getEventClassFamiliesByApplicationId(String applicationId) + throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { checkApplicationId(applicationId); return controlService.getEventClassFamiliesByApplicationId(applicationId); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @@ -202,11 +221,14 @@ private void checkEventClassFamilyId(String eventClassFamilyId) throws IllegalAr @Override public RecordField createEcfEmptySchemaForm() throws KaaAdminServiceException { - checkAuthority(KaaAuthorityDto.TENANT_ADMIN, KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); + checkAuthority( + KaaAuthorityDto.TENANT_ADMIN, + KaaAuthorityDto.TENANT_DEVELOPER, + KaaAuthorityDto.TENANT_USER); try { return ecfSchemaFormAvroConverter.getEmptySchemaFormInstance(); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @@ -217,43 +239,50 @@ public RecordField generateEcfSchemaForm(String fileItemName) throws KaaAdminSer String avroSchema = new String(data); Schema schema = new Schema.Parser().parse(avroSchema); return ecfSchemaFormAvroConverter.createSchemaFormFromSchema(schema); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public List getEventClassFamilyVersions(String eventClassFamilyId) throws KaaAdminServiceException { + public List getEventClassFamilyVersions(String eventClassFamilyId) + throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_ADMIN); try { return controlService.getEventClassFamilyVersions(eventClassFamilyId); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override public EventClassViewDto getEventClassView(String eventClassId) throws KaaAdminServiceException { - checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER, KaaAuthorityDto.TENANT_ADMIN); + 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)); + EventClassViewDto eventClassViewDto = new EventClassViewDto( + eventClassDto, toCtlSchemaForm(ctlSchemaDto, ConverterType.FORM_AVRO_CONVERTER)); return eventClassViewDto; - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public EventClassViewDto getEventClassViewByCtlSchemaId(EventClassDto eventClassDto) throws KaaAdminServiceException { + public EventClassViewDto getEventClassViewByCtlSchemaId(EventClassDto eventClassDto) + throws KaaAdminServiceException { try { CTLSchemaDto ctlSchemaDto = controlService.getCTLSchemaById(eventClassDto.getCtlSchemaId()); Utils.checkNotNull(ctlSchemaDto); - EventClassViewDto eventClassViewDto = new EventClassViewDto(eventClassDto, toCtlSchemaForm(ctlSchemaDto, ConverterType.FORM_AVRO_CONVERTER)); + EventClassViewDto eventClassViewDto = new EventClassViewDto( + eventClassDto, toCtlSchemaForm(ctlSchemaDto, ConverterType.FORM_AVRO_CONVERTER)); return eventClassViewDto; - } catch (ControlServiceException e) { - throw Utils.handleException(e); + } catch (ControlServiceException ex) { + throw Utils.handleException(ex); } } @@ -261,13 +290,14 @@ public EventClassViewDto getEventClassViewByCtlSchemaId(EventClassDto eventClass public EventClassDto getEventClass(String eventClassId) throws KaaAdminServiceException { try { return controlService.getEventClassById(eventClassId); - } catch (ControlServiceException e) { - throw Utils.handleException(e); + } catch (ControlServiceException ex) { + throw Utils.handleException(ex); } } @Override - public EventClassViewDto saveEventClassView(EventClassViewDto eventClassViewDto) throws KaaAdminServiceException { + public EventClassViewDto saveEventClassView(EventClassViewDto eventClassViewDto) + throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_ADMIN); try { EventClassDto eventClassDto = eventClassViewDto.getSchema(); @@ -276,42 +306,49 @@ public EventClassViewDto saveEventClassView(EventClassViewDto eventClassViewDto) if (isEmpty(ctlSchemaId)) { if (eventClassViewDto.useExistingCtlSchema()) { CtlSchemaReferenceDto metaInfo = eventClassViewDto.getExistingMetaInfo(); - CTLSchemaDto schema = controlService.getCTLSchemaByFqnVersionTenantIdAndApplicationId(metaInfo.getMetaInfo().getFqn(), + 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); + ctlSchemaForm = ctlService.saveCTLSchemaForm( + eventClassViewDto.getCtlSchemaForm(), ConverterType.FORM_AVRO_CONVERTER); eventClassDto.setCtlSchemaId(ctlSchemaForm.getId()); } } return getEventClassViewByCtlSchemaId(eventClassDto); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public EventClassViewDto createEventClassFormCtlSchema(CtlSchemaFormDto ctlSchemaForm) throws KaaAdminServiceException { + 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); + CtlSchemaFormDto savedCtlSchemaForm = ctlService.saveCTLSchemaForm( + ctlSchemaForm, ConverterType.FORM_AVRO_CONVERTER); eventClassDto.setCtlSchemaId(savedCtlSchemaForm.getId()); return getEventClassViewByCtlSchemaId(eventClassDto); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public void addEventClassFamilyVersionFromView(String eventClassFamilyId, List eventClassViewDto) throws KaaAdminServiceException { + public void addEventClassFamilyVersionFromView(String eventClassFamilyId, + List eventClassViewDto) + throws KaaAdminServiceException { if (eventClassViewDto.isEmpty()) { - throw Utils.handleException(new IllegalArgumentException("Event Class Family Version cannot be without Event Classes")); + throw Utils.handleException(new IllegalArgumentException( + "Event Class Family Version cannot be without Event Classes")); } EventClassFamilyVersionDto eventClassFamilyVersionDto = new EventClassFamilyVersionDto(); eventClassFamilyVersionDto.setCreatedTime(System.currentTimeMillis()); @@ -328,27 +365,35 @@ public void addEventClassFamilyVersionFromView(String eventClassFamilyId, List ecfList) throws KaaAdminServiceException { + public void validateECFListInSdkProfile(List ecfList) + throws KaaAdminServiceException { try { controlService.validateECFListInSdkProfile(ecfList); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public List getEventClassesByFamilyIdVersionAndType(String eventClassFamilyId, int version, EventClassType type) + public List getEventClassesByFamilyIdVersionAndType(String eventClassFamilyId, + int version, + EventClassType type) throws KaaAdminServiceException { - checkAuthority(KaaAuthorityDto.TENANT_ADMIN, KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); + checkAuthority( + KaaAuthorityDto.TENANT_ADMIN, + KaaAuthorityDto.TENANT_DEVELOPER, + KaaAuthorityDto.TENANT_USER); try { checkEventClassFamilyId(eventClassFamilyId); - EventClassFamilyDto storedEventClassFamily = controlService.getEventClassFamily(eventClassFamilyId); + EventClassFamilyDto storedEventClassFamily = controlService.getEventClassFamily( + eventClassFamilyId); Utils.checkNotNull(storedEventClassFamily); checkTenantId(storedEventClassFamily.getTenantId()); - return controlService.getEventClassesByFamilyIdVersionAndType(eventClassFamilyId, version, type); - } catch (Exception e) { - throw Utils.handleException(e); + return controlService.getEventClassesByFamilyIdVersionAndType( + eventClassFamilyId, version, type); + } catch (Exception ex) { + throw Utils.handleException(ex); } } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/GroupServiceImpl.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/GroupServiceImpl.java index 9816da66ca..5811aa17cf 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/GroupServiceImpl.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/GroupServiceImpl.java @@ -60,33 +60,37 @@ public class GroupServiceImpl extends AbstractAdminService implements GroupServi ProfileService profileService; @Override - public List getEndpointGroupsByApplicationToken(String applicationToken) throws KaaAdminServiceException { + public List getEndpointGroupsByApplicationToken(String applicationToken) + throws KaaAdminServiceException { return getEndpointGroupsByApplicationId(checkApplicationToken(applicationToken)); } @Override - public List getEndpointGroupsByApplicationId(String applicationId) throws KaaAdminServiceException { + public List getEndpointGroupsByApplicationId(String applicationId) + throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { checkApplicationId(applicationId); return controlService.getEndpointGroupsByApplicationId(applicationId); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public EndpointGroupDto getEndpointGroup(String endpointGroupId) throws KaaAdminServiceException { + public EndpointGroupDto getEndpointGroup(String endpointGroupId) + throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { return checkEndpointGroupId(endpointGroupId); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public EndpointGroupDto editEndpointGroup(EndpointGroupDto endpointGroup) throws KaaAdminServiceException { + public EndpointGroupDto editEndpointGroup(EndpointGroupDto endpointGroup) + throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { checkEndpointGroupWeight(endpointGroup.getWeight()); @@ -97,8 +101,8 @@ public EndpointGroupDto editEndpointGroup(EndpointGroupDto endpointGroup) throws checkEndpointGroupId(endpointGroup.getId()); } return controlService.editEndpointGroup(endpointGroup); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @@ -108,49 +112,57 @@ public void deleteEndpointGroup(String endpointGroupId) throws KaaAdminServiceEx try { checkEndpointGroupId(endpointGroupId); controlService.deleteEndpointGroup(endpointGroupId); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public List getProfileFilterRecordsByEndpointGroupId(String endpointGroupId, - boolean includeDeprecated) throws KaaAdminServiceException { + public List getProfileFilterRecordsByEndpointGroupId( + String endpointGroupId, boolean includeDeprecated) throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { checkEndpointGroupId(endpointGroupId); - return controlService.getProfileFilterRecordsByEndpointGroupId(endpointGroupId, includeDeprecated); - } catch (Exception e) { - throw Utils.handleException(e); + return controlService.getProfileFilterRecordsByEndpointGroupId( + endpointGroupId, includeDeprecated); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public ProfileFilterRecordDto getProfileFilterRecord(String endpointProfileSchemaId, String serverProfileSchemaId, - String endpointGroupId) throws KaaAdminServiceException { + public ProfileFilterRecordDto getProfileFilterRecord(String endpointProfileSchemaId, + String serverProfileSchemaId, + String endpointGroupId) + throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { checkEndpointGroupId(endpointGroupId); - ProfileFilterRecordDto record = controlService.getProfileFilterRecord(endpointProfileSchemaId, serverProfileSchemaId, endpointGroupId); + ProfileFilterRecordDto record = controlService.getProfileFilterRecord( + endpointProfileSchemaId, + serverProfileSchemaId, + endpointGroupId); return record; - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public List getVacantProfileSchemasByEndpointGroupId(String endpointGroupId) throws KaaAdminServiceException { + public List getVacantProfileSchemasByEndpointGroupId( + String endpointGroupId) throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { checkEndpointGroupId(endpointGroupId); return controlService.getVacantProfileSchemasByEndpointGroupId(endpointGroupId); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public ProfileFilterDto editProfileFilter(ProfileFilterDto profileFilter) throws KaaAdminServiceException { + public ProfileFilterDto editProfileFilter(ProfileFilterDto profileFilter) + throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { String username = getCurrentUser().getUsername(); @@ -159,7 +171,8 @@ public ProfileFilterDto editProfileFilter(ProfileFilterDto profileFilter) throws checkEndpointGroupId(profileFilter.getEndpointGroupId()); } else { profileFilter.setModifiedUsername(username); - ProfileFilterDto storedProfileFilter = controlService.getProfileFilter(profileFilter.getId()); + ProfileFilterDto storedProfileFilter = controlService.getProfileFilter( + profileFilter.getId()); Utils.checkNotNull(storedProfileFilter); checkEndpointGroupId(storedProfileFilter.getEndpointGroupId()); } @@ -167,13 +180,14 @@ public ProfileFilterDto editProfileFilter(ProfileFilterDto profileFilter) throws profileFilter.getServerProfileSchemaId(), profileFilter.getBody()); return controlService.editProfileFilter(profileFilter); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public ProfileFilterDto activateProfileFilter(String profileFilterId) throws KaaAdminServiceException { + public ProfileFilterDto activateProfileFilter(String profileFilterId) + throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { ProfileFilterDto storedProfileFilter = controlService.getProfileFilter(profileFilterId); @@ -181,13 +195,14 @@ public ProfileFilterDto activateProfileFilter(String profileFilterId) throws Kaa checkEndpointGroupId(storedProfileFilter.getEndpointGroupId()); String username = getCurrentUser().getUsername(); return controlService.activateProfileFilter(profileFilterId, username); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public ProfileFilterDto deactivateProfileFilter(String profileFilterId) throws KaaAdminServiceException { + public ProfileFilterDto deactivateProfileFilter(String profileFilterId) + throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { ProfileFilterDto storedProfileFilter = controlService.getProfileFilter(profileFilterId); @@ -195,32 +210,38 @@ public ProfileFilterDto deactivateProfileFilter(String profileFilterId) throws K checkEndpointGroupId(storedProfileFilter.getEndpointGroupId()); String username = getCurrentUser().getUsername(); return controlService.deactivateProfileFilter(profileFilterId, username); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public void deleteProfileFilterRecord(String endpointProfileSchemaId, String serverProfileSchemaId, String endpointGroupId) throws KaaAdminServiceException { + public void deleteProfileFilterRecord(String endpointProfileSchemaId, + String serverProfileSchemaId, + String endpointGroupId) throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { - ProfileFilterRecordDto record = controlService.getProfileFilterRecord(endpointProfileSchemaId, - serverProfileSchemaId, endpointGroupId); + ProfileFilterRecordDto record = controlService.getProfileFilterRecord( + endpointProfileSchemaId, serverProfileSchemaId, endpointGroupId); checkEndpointGroupId(record.getEndpointGroupId()); String username = getCurrentUser().getUsername(); - controlService.deleteProfileFilterRecord(endpointProfileSchemaId, serverProfileSchemaId, endpointGroupId, username); - } catch (Exception e) { - throw Utils.handleException(e); + controlService.deleteProfileFilterRecord( + endpointProfileSchemaId, serverProfileSchemaId, endpointGroupId, username); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public EndpointProfilesPageDto getEndpointProfileByEndpointGroupId(String endpointGroupId, String limit, String offset) + public EndpointProfilesPageDto getEndpointProfileByEndpointGroupId(String endpointGroupId, + String limit, + String offset) throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { if (Integer.valueOf(limit) > MAX_LIMIT) { - throw new IllegalArgumentException("Incorrect limit parameter. You must enter value not more than " + MAX_LIMIT); + throw new IllegalArgumentException( + "Incorrect limit parameter. You must enter value not more than " + MAX_LIMIT); } EndpointGroupDto endpointGroupDto = getEndpointGroup(endpointGroupId); PageLinkDto pageLinkDto = new PageLinkDto(endpointGroupId, limit, offset); @@ -228,18 +249,21 @@ public EndpointProfilesPageDto getEndpointProfileByEndpointGroupId(String endpoi pageLinkDto.setApplicationId(endpointGroupDto.getApplicationId()); } return controlService.getEndpointProfileByEndpointGroupId(pageLinkDto); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public EndpointProfilesBodyDto getEndpointProfileBodyByEndpointGroupId(String endpointGroupId, String limit, String offset) + public EndpointProfilesBodyDto getEndpointProfileBodyByEndpointGroupId(String endpointGroupId, + String limit, + String offset) throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { if (Integer.valueOf(limit) > MAX_LIMIT) { - throw new IllegalArgumentException("Incorrect limit parameter. You must enter value not more than " + MAX_LIMIT); + throw new IllegalArgumentException( + "Incorrect limit parameter. You must enter value not more than " + MAX_LIMIT); } EndpointGroupDto endpointGroupDto = getEndpointGroup(endpointGroupId); PageLinkDto pageLinkDto = new PageLinkDto(endpointGroupId, limit, offset); @@ -247,8 +271,8 @@ public EndpointProfilesBodyDto getEndpointProfileBodyByEndpointGroupId(String en pageLinkDto.setApplicationId(endpointGroupDto.getApplicationId()); } return controlService.getEndpointProfileBodyByEndpointGroupId(pageLinkDto); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @@ -258,39 +282,46 @@ private void checkEndpointGroupWeight(int weight) throws KaaAdminServiceExceptio } } - private void validateProfileFilterBody(String endpointProfileSchemaId, String serverProfileSchemaId, + private void validateProfileFilterBody(String endpointProfileSchemaId, + String serverProfileSchemaId, String filterBody) throws KaaAdminServiceException { GenericRecord endpointProfileRecord = null; GenericRecord serverProfileRecord = null; try { if (endpointProfileSchemaId != null) { - EndpointProfileSchemaDto endpointProfileSchema = profileService.getProfileSchema(endpointProfileSchemaId); - endpointProfileRecord = getDefaultRecordFromCtlSchema(endpointProfileSchema.getCtlSchemaId()); + EndpointProfileSchemaDto endpointProfileSchema = profileService.getProfileSchema( + endpointProfileSchemaId); + endpointProfileRecord = getDefaultRecordFromCtlSchema( + endpointProfileSchema.getCtlSchemaId()); } if (serverProfileSchemaId != null) { - ServerProfileSchemaDto serverProfileSchema = profileService.getServerProfileSchema(serverProfileSchemaId); + ServerProfileSchemaDto serverProfileSchema = profileService.getServerProfileSchema( + serverProfileSchemaId); serverProfileRecord = getDefaultRecordFromCtlSchema(serverProfileSchema.getCtlSchemaId()); } - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } try { Expression expression = new SpelExpressionParser().parseExpression(filterBody); StandardEvaluationContext evaluationContext; if (endpointProfileRecord != null) { evaluationContext = new StandardEvaluationContext(endpointProfileRecord); - evaluationContext.setVariable(DefaultFilterEvaluator.CLIENT_PROFILE_VARIABLE_NAME, endpointProfileRecord); + evaluationContext.setVariable( + DefaultFilterEvaluator.CLIENT_PROFILE_VARIABLE_NAME, endpointProfileRecord); } else { evaluationContext = new StandardEvaluationContext(); } evaluationContext.addPropertyAccessor(new GenericRecordPropertyAccessor()); evaluationContext.setVariable(DefaultFilterEvaluator.EP_KEYHASH_VARIABLE_NAME, "test"); if (serverProfileRecord != null) { - evaluationContext.setVariable(DefaultFilterEvaluator.SERVER_PROFILE_VARIABLE_NAME, serverProfileRecord); + evaluationContext.setVariable( + DefaultFilterEvaluator.SERVER_PROFILE_VARIABLE_NAME, serverProfileRecord); } expression.getValue(evaluationContext, Boolean.class); - } catch (Exception e) { - throw new KaaAdminServiceException("Invalid profile filter body!", e, ServiceErrorCode.BAD_REQUEST_PARAMS); + } catch (Exception ex) { + throw new KaaAdminServiceException( + "Invalid profile filter body!", ex, ServiceErrorCode.BAD_REQUEST_PARAMS); } } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/KaaAuthServiceImpl.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/KaaAuthServiceImpl.java index 40263b5d08..738396ee7c 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/KaaAuthServiceImpl.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/KaaAuthServiceImpl.java @@ -118,7 +118,9 @@ public void createKaaAdmin(String username, String password) new org.kaaproject.kaa.server.admin.services.entity.User(); if (!checkPasswordStrength(password)) { - throw new KaaAdminServiceException("Bad password strength. Password length must be greater than 5 characters.", ServiceErrorCode.GENERAL_ERROR); + throw new KaaAdminServiceException( + "Bad password strength. Password length must be greater than 5 characters.", + ServiceErrorCode.GENERAL_ERROR); } userEntity.setUsername(username); @@ -197,10 +199,12 @@ public ResultCode sendPasswordResetLinkByEmail(String usernameOrEmail) User userEntity = userFacade.findByUsernameOrMail(usernameOrEmail); ResultCode result = checkUserAndEmailExists(userEntity); if (result == ResultCode.OK) { - String passwordResetHash = RandomStringUtils.randomAlphanumeric(UrlParams.PASSWORD_RESET_HASH_LENGTH); + String passwordResetHash = RandomStringUtils.randomAlphanumeric( + UrlParams.PASSWORD_RESET_HASH_LENGTH); userEntity.setPasswordResetHash(passwordResetHash); userFacade.save(userEntity); - messagingService.sendPasswordResetLink(passwordResetHash, userEntity.getUsername(), userEntity.getMail()); + messagingService.sendPasswordResetLink( + passwordResetHash, userEntity.getUsername(), userEntity.getMail()); } return result; } @@ -225,11 +229,13 @@ public ResultCode resetPasswordByResetHash(String passwordResetHash) return ResultCode.USER_EMAIL_NOT_DEFINED; } userEntity.setPasswordResetHash(null); - String generatedPassword = RandomStringUtils.randomAlphanumeric(User.TEMPORARY_PASSWORD_LENGTH); + String generatedPassword = RandomStringUtils.randomAlphanumeric( + User.TEMPORARY_PASSWORD_LENGTH); userEntity.setPassword(passwordEncoder.encode(generatedPassword)); userEntity.setTempPassword(true); userFacade.save(userEntity); - messagingService.sendPasswordAfterReset(userEntity.getUsername(), generatedPassword, userEntity.getMail()); + messagingService.sendPasswordAfterReset( + userEntity.getUsername(), generatedPassword, userEntity.getMail()); return ResultCode.OK; } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/LoggingServiceImpl.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/LoggingServiceImpl.java index 4524fed27d..1c989c17f6 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/LoggingServiceImpl.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/LoggingServiceImpl.java @@ -56,18 +56,20 @@ public class LoggingServiceImpl extends AbstractAdminService implements LoggingS CtlService ctlService; @Override - public List getLogSchemasByApplicationToken(String applicationToken) throws KaaAdminServiceException { + public List getLogSchemasByApplicationToken(String applicationToken) + throws KaaAdminServiceException { return getLogSchemasByApplicationId(checkApplicationToken(applicationToken)); } @Override - public List getLogSchemasByApplicationId(String applicationId) throws KaaAdminServiceException { + public List getLogSchemasByApplicationId(String applicationId) + throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { checkApplicationId(applicationId); return controlService.getLogSchemasByApplicationId(applicationId); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @@ -79,22 +81,26 @@ public LogSchemaDto getLogSchema(String logSchemaId) throws KaaAdminServiceExcep Utils.checkNotNull(logSchema); checkApplicationId(logSchema.getApplicationId()); return logSchema; - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public LogSchemaDto getLogSchemaByApplicationTokenAndVersion(String applicationToken, int version) throws KaaAdminServiceException { + public LogSchemaDto getLogSchemaByApplicationTokenAndVersion(String applicationToken, + int version) + throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { - ApplicationDto storedApplication = controlService.getApplicationByApplicationToken(applicationToken); + ApplicationDto storedApplication = controlService.getApplicationByApplicationToken( + applicationToken); checkApplication(storedApplication); - LogSchemaDto logSchema = controlService.getLogSchemaByApplicationIdAndVersion(storedApplication.getId(), version); + LogSchemaDto logSchema = controlService.getLogSchemaByApplicationIdAndVersion( + storedApplication.getId(), version); Utils.checkNotNull(logSchema); return logSchema; - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @@ -111,8 +117,8 @@ public LogSchemaDto saveLogSchema(LogSchemaDto logSchema) throws KaaAdminService checkApplicationId(storedLogSchema.getApplicationId()); } return controlService.saveLogSchema(logSchema); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @@ -122,15 +128,17 @@ public LogSchemaViewDto getLogSchemaView(String logSchemaId) throws KaaAdminServ try { LogSchemaDto logSchema = getLogSchema(logSchemaId); CTLSchemaDto ctlSchemaDto = controlService.getCTLSchemaById(logSchema.getCtlSchemaId()); - LogSchemaViewDto logSchemaViewDto = new LogSchemaViewDto(logSchema, toCtlSchemaForm(ctlSchemaDto, ConverterType.FORM_AVRO_CONVERTER)); + LogSchemaViewDto logSchemaViewDto = new LogSchemaViewDto( + logSchema, toCtlSchemaForm(ctlSchemaDto, ConverterType.FORM_AVRO_CONVERTER)); return logSchemaViewDto; - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public LogSchemaViewDto saveLogSchemaView(LogSchemaViewDto logSchemaView) throws KaaAdminServiceException { + public LogSchemaViewDto saveLogSchemaView(LogSchemaViewDto logSchemaView) + throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { LogSchemaDto logSchemaDto = logSchemaView.getSchema(); @@ -140,25 +148,28 @@ public LogSchemaViewDto saveLogSchemaView(LogSchemaViewDto logSchemaView) throws if (isEmpty(ctlSchemaId)) { if (logSchemaView.useExistingCtlSchema()) { CtlSchemaReferenceDto metaInfo = logSchemaView.getExistingMetaInfo(); - CTLSchemaDto schema = ctlService.getCTLSchemaByFqnVersionTenantIdAndApplicationId(metaInfo.getMetaInfo().getFqn(), + CTLSchemaDto schema = ctlService.getCTLSchemaByFqnVersionTenantIdAndApplicationId( + metaInfo.getMetaInfo().getFqn(), metaInfo.getVersion(), metaInfo.getMetaInfo().getTenantId(), metaInfo.getMetaInfo().getApplicationId()); logSchemaDto.setCtlSchemaId(schema.getId()); } else { - CtlSchemaFormDto ctlSchemaForm = ctlService.saveCTLSchemaForm(logSchemaView.getCtlSchemaForm(), ConverterType.FORM_AVRO_CONVERTER); + CtlSchemaFormDto ctlSchemaForm = ctlService.saveCTLSchemaForm( + logSchemaView.getCtlSchemaForm(), ConverterType.FORM_AVRO_CONVERTER); logSchemaDto.setCtlSchemaId(ctlSchemaForm.getId()); } } LogSchemaDto savedLogSchema = saveLogSchema(logSchemaDto); return getLogSchemaView(savedLogSchema.getId()); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public LogSchemaViewDto createLogSchemaFormCtlSchema(CtlSchemaFormDto ctlSchemaForm) throws KaaAdminServiceException { + public LogSchemaViewDto createLogSchemaFormCtlSchema(CtlSchemaFormDto ctlSchemaForm) + throws KaaAdminServiceException { LOG.error("createLogSchemaFormCtlSchema [{}]", ctlSchemaForm.getSchema().getDisplayString()); checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { @@ -167,22 +178,25 @@ public LogSchemaViewDto createLogSchemaFormCtlSchema(CtlSchemaFormDto ctlSchemaF logSchema.setApplicationId(ctlSchemaForm.getMetaInfo().getApplicationId()); logSchema.setName(ctlSchemaForm.getSchema().getDisplayNameFieldValue()); logSchema.setDescription(ctlSchemaForm.getSchema().getDescriptionFieldValue()); - CtlSchemaFormDto savedCtlSchemaForm = ctlService.saveCTLSchemaForm(ctlSchemaForm, ConverterType.FORM_AVRO_CONVERTER); + CtlSchemaFormDto savedCtlSchemaForm = ctlService.saveCTLSchemaForm( + ctlSchemaForm, ConverterType.FORM_AVRO_CONVERTER); logSchema.setCtlSchemaId(savedCtlSchemaForm.getId()); LogSchemaDto savedLogSchema = saveLogSchema(logSchema); return getLogSchemaView(savedLogSchema.getId()); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public List getRestLogAppendersByApplicationToken(String appToken) throws KaaAdminServiceException { + public List getRestLogAppendersByApplicationToken(String appToken) + throws KaaAdminServiceException { return getRestLogAppendersByApplicationId(checkApplicationToken(appToken)); } @Override - public List getRestLogAppendersByApplicationId(String appId) throws KaaAdminServiceException { + public List getRestLogAppendersByApplicationId(String appId) + throws KaaAdminServiceException { List logAppenders = getLogAppendersByApplicationId(appId); for (LogAppenderDto logAppender : logAppenders) { setPluginJsonConfigurationFromRaw(logAppender, PluginType.LOG_APPENDER); @@ -191,38 +205,42 @@ public List getRestLogAppendersByApplicationId(String appId) thr } @Override - public List getLogAppendersByApplicationId(String appId) throws KaaAdminServiceException { + public List getLogAppendersByApplicationId(String appId) + throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { checkApplicationId(appId); return controlService.getLogAppendersByApplicationId(appId); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public LogAppenderDto getRestLogAppender(String appenderId) throws KaaAdminServiceException { + public LogAppenderDto getRestLogAppender(String appenderId) + throws KaaAdminServiceException { LogAppenderDto logAppender = getLogAppender(appenderId); setPluginJsonConfigurationFromRaw(logAppender, PluginType.LOG_APPENDER); return logAppender; } @Override - public LogAppenderDto getLogAppender(String appenderId) throws KaaAdminServiceException { + public LogAppenderDto getLogAppender(String appenderId) + throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { LogAppenderDto logAppender = controlService.getLogAppender(appenderId); Utils.checkNotNull(logAppender); checkApplicationId(logAppender.getApplicationId()); return logAppender; - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public LogAppenderDto editRestLogAppender(LogAppenderDto logAppender) throws KaaAdminServiceException { + public LogAppenderDto editRestLogAppender(LogAppenderDto logAppender) + throws KaaAdminServiceException { setPluginRawConfigurationFromJson(logAppender, PluginType.LOG_APPENDER); LogAppenderDto savedLogAppender = editLogAppender(logAppender); setPluginJsonConfigurationFromRaw(savedLogAppender, PluginType.LOG_APPENDER); @@ -230,7 +248,8 @@ public LogAppenderDto editRestLogAppender(LogAppenderDto logAppender) throws Kaa } @Override - public LogAppenderDto editLogAppender(LogAppenderDto appender) throws KaaAdminServiceException { + public LogAppenderDto editLogAppender(LogAppenderDto appender) + throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { if (isEmpty(appender.getId())) { @@ -242,8 +261,8 @@ public LogAppenderDto editLogAppender(LogAppenderDto appender) throws KaaAdminSe checkApplicationId(storedlLogAppender.getApplicationId()); } return controlService.editLogAppender(appender); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @@ -258,20 +277,21 @@ public void deleteLogAppender(String appenderId) throws KaaAdminServiceException Utils.checkNotNull(logAppender); checkApplicationId(logAppender.getApplicationId()); controlService.deleteLogAppender(appenderId); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public List getLogSchemasVersions(String applicationId) throws KaaAdminServiceException { + public List getLogSchemasVersions(String applicationId) + throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); List logSchemaVersions = Collections.emptyList(); try { checkApplicationId(applicationId); logSchemaVersions = controlService.getLogSchemaVersionsByApplicationId(applicationId); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } return logSchemaVersions; } @@ -282,19 +302,20 @@ public LogAppenderDto getLogAppenderForm(String appenderId) throws KaaAdminServi try { setPluginFormConfigurationFromRaw(logAppender, PluginType.LOG_APPENDER); return logAppender; - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public LogAppenderDto editLogAppenderForm(LogAppenderDto logAppender) throws KaaAdminServiceException { + public LogAppenderDto editLogAppenderForm(LogAppenderDto logAppender) + throws KaaAdminServiceException { try { setPluginRawConfigurationFromForm(logAppender); LogAppenderDto saved = editLogAppender(logAppender); return saved; - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/NotificationServiceImpl.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/NotificationServiceImpl.java index cb1ee4150f..65714ec4d7 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/NotificationServiceImpl.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/NotificationServiceImpl.java @@ -66,46 +66,53 @@ public class NotificationServiceImpl extends AbstractAdminService implements Not CtlService ctlService; @Override - public List getNotificationSchemasByApplicationToken(String applicationToken) throws KaaAdminServiceException { + public List getNotificationSchemasByApplicationToken( + String applicationToken) throws KaaAdminServiceException { return getNotificationSchemasByApplicationId(checkApplicationToken(applicationToken)); } @Override - public List getNotificationSchemasByApplicationId(String applicationId) throws KaaAdminServiceException { + public List getNotificationSchemasByApplicationId( + String applicationId) throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { checkApplicationId(applicationId); - return controlService.findNotificationSchemasByAppIdAndType(applicationId, NotificationTypeDto.USER); - } catch (Exception e) { - throw Utils.handleException(e); + return controlService.findNotificationSchemasByAppIdAndType( + applicationId, NotificationTypeDto.USER); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public List getUserNotificationSchemasByApplicationToken(String applicationToken) throws KaaAdminServiceException { + public List getUserNotificationSchemasByApplicationToken(String applicationToken) + throws KaaAdminServiceException { return getUserNotificationSchemasByApplicationId(checkApplicationToken(applicationToken)); } @Override - public List getUserNotificationSchemasByApplicationId(String applicationId) throws KaaAdminServiceException { + public List getUserNotificationSchemasByApplicationId(String applicationId) + throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { checkApplicationId(applicationId); return controlService.getUserNotificationSchemasByAppId(applicationId); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } - public NotificationSchemaDto getNotificationSchema(String notificationSchemaId) throws KaaAdminServiceException { + public NotificationSchemaDto getNotificationSchema(String notificationSchemaId) + throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { - NotificationSchemaDto notificationSchema = controlService.getNotificationSchema(notificationSchemaId); + NotificationSchemaDto notificationSchema = controlService.getNotificationSchema( + notificationSchemaId); Utils.checkNotNull(notificationSchema); checkApplicationId(notificationSchema.getApplicationId()); return notificationSchema; - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @@ -118,52 +125,57 @@ public NotificationSchemaDto saveNotificationSchema(NotificationSchemaDto notifi notificationSchema.setCreatedUsername(getCurrentUser().getUsername()); checkApplicationId(notificationSchema.getApplicationId()); } else { - NotificationSchemaDto storedNotificationSchema = controlService.getNotificationSchema(notificationSchema.getId()); + NotificationSchemaDto storedNotificationSchema = controlService.getNotificationSchema( + notificationSchema.getId()); Utils.checkNotNull(storedNotificationSchema); checkApplicationId(storedNotificationSchema.getApplicationId()); } notificationSchema.setType(NotificationTypeDto.USER); return controlService.saveNotificationSchema(notificationSchema); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public List getTopicsByApplicationToken(String applicationToken) throws KaaAdminServiceException { + public List getTopicsByApplicationToken(String applicationToken) + throws KaaAdminServiceException { return getTopicsByApplicationId(checkApplicationToken(applicationToken)); } @Override - public List getTopicsByApplicationId(String applicationId) throws KaaAdminServiceException { + public List getTopicsByApplicationId(String applicationId) + throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { checkApplicationId(applicationId); return controlService.getTopicByAppId(applicationId); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public List getTopicsByEndpointGroupId(String endpointGroupId) throws KaaAdminServiceException { + public List getTopicsByEndpointGroupId(String endpointGroupId) + throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { checkEndpointGroupId(endpointGroupId); return controlService.getTopicByEndpointGroupId(endpointGroupId); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public List getVacantTopicsByEndpointGroupId(String endpointGroupId) throws KaaAdminServiceException { + public List getVacantTopicsByEndpointGroupId(String endpointGroupId) + throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { checkEndpointGroupId(endpointGroupId); return controlService.getVacantTopicByEndpointGroupId(endpointGroupId); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @@ -175,8 +187,8 @@ public TopicDto getTopic(String topicId) throws KaaAdminServiceException { Utils.checkNotNull(topic); checkApplicationId(topic.getApplicationId()); return topic; - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @@ -188,11 +200,12 @@ public TopicDto editTopic(TopicDto topic) throws KaaAdminServiceException { topic.setCreatedUsername(getCurrentUser().getUsername()); checkApplicationId(topic.getApplicationId()); } else { - throw new KaaAdminServiceException("Unable to edit existing topic!", ServiceErrorCode.INVALID_ARGUMENTS); + throw new KaaAdminServiceException( + "Unable to edit existing topic!", ServiceErrorCode.INVALID_ARGUMENTS); } return controlService.editTopic(topic); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @@ -205,13 +218,14 @@ public void deleteTopic(String topicId) throws KaaAdminServiceException { Utils.checkNotNull(topic); checkApplicationId(topic.getApplicationId()); controlService.deleteTopicById(topicId); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public void addTopicToEndpointGroup(String endpointGroupId, String topicId) throws KaaAdminServiceException { + public void addTopicToEndpointGroup(String endpointGroupId, String topicId) + throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { checkEndpointGroupId(endpointGroupId); @@ -220,13 +234,14 @@ public void addTopicToEndpointGroup(String endpointGroupId, String topicId) thro Utils.checkNotNull(topic); checkApplicationId(topic.getApplicationId()); controlService.addTopicsToEndpointGroup(endpointGroupId, topicId); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public void removeTopicFromEndpointGroup(String endpointGroupId, String topicId) throws KaaAdminServiceException { + public void removeTopicFromEndpointGroup(String endpointGroupId, String topicId) + throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { checkEndpointGroupId(endpointGroupId); @@ -235,13 +250,14 @@ public void removeTopicFromEndpointGroup(String endpointGroupId, String topicId) Utils.checkNotNull(topic); checkApplicationId(topic.getApplicationId()); controlService.removeTopicsFromEndpointGroup(endpointGroupId, topicId); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public NotificationDto sendNotification(NotificationDto notification, byte[] body) throws KaaAdminServiceException { + public NotificationDto sendNotification(NotificationDto notification, byte[] body) + throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { checkExpiredDate(notification); @@ -251,13 +267,37 @@ public NotificationDto sendNotification(NotificationDto notification, byte[] bod Utils.checkNotNull(topic); checkApplicationId(topic.getApplicationId()); return controlService.editNotification(notification); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); + } + } + + @Override + public void sendNotification(NotificationDto notification, RecordField notificationData) + throws KaaAdminServiceException { + checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); + try { + checkExpiredDate(notification); + GenericRecord record = FormAvroConverter.createGenericRecordFromRecordField( + notificationData); + GenericAvroConverter converter = new GenericAvroConverter<>( + record.getSchema()); + byte[] body = converter.encodeToJsonBytes(record); + notification.setBody(body); + checkApplicationId(notification.getApplicationId()); + TopicDto topic = controlService.getTopic(notification.getTopicId()); + Utils.checkNotNull(topic); + checkApplicationId(topic.getApplicationId()); + controlService.editNotification(notification); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public EndpointNotificationDto sendUnicastNotification(NotificationDto notification, String clientKeyHash, byte[] body) + public EndpointNotificationDto sendUnicastNotification(NotificationDto notification, + String clientKeyHash, + byte[] body) throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { @@ -268,11 +308,30 @@ public EndpointNotificationDto sendUnicastNotification(NotificationDto notificat Utils.checkNotNull(topic); checkApplicationId(topic.getApplicationId()); EndpointNotificationDto unicastNotification = new EndpointNotificationDto(); - unicastNotification.setEndpointKeyHash(Base64.decode(clientKeyHash.getBytes(Charsets.UTF_8))); + unicastNotification.setEndpointKeyHash( + Base64.decode(clientKeyHash.getBytes(Charsets.UTF_8))); unicastNotification.setNotificationDto(notification); return controlService.editUnicastNotification(unicastNotification); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); + } + } + + @Override + public EndpointNotificationDto sendUnicastNotification(NotificationDto notification, + String clientKeyHash, + RecordField notificationData) + throws KaaAdminServiceException { + checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); + try { + GenericRecord record = FormAvroConverter.createGenericRecordFromRecordField( + notificationData); + GenericAvroConverter converter = new GenericAvroConverter<>( + record.getSchema()); + byte[] body = converter.encodeToJsonBytes(record); + return sendUnicastNotification(notification, clientKeyHash, body); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @@ -289,41 +348,48 @@ private void checkExpiredDate(NotificationDto notification) throws KaaAdminServi } @Override - public List getUserNotificationSchemaInfosByApplicationId(String applicationId) throws KaaAdminServiceException { + public List getUserNotificationSchemaInfosByApplicationId(String applicationId) + throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { checkApplicationId(applicationId); - List notificationSchemas = controlService.findNotificationSchemasByAppIdAndType(applicationId, - NotificationTypeDto.USER); + List notificationSchemas = + controlService.findNotificationSchemasByAppIdAndType( + applicationId, NotificationTypeDto.USER); List schemaInfos = new ArrayList<>(notificationSchemas.size()); for (NotificationSchemaDto notificationSchema : notificationSchemas) { SchemaInfoDto schemaInfo = new SchemaInfoDto(notificationSchema); - RecordField schemaForm = createRecordFieldFromCtlSchemaAndBody(notificationSchema.getCtlSchemaId(), null); + RecordField schemaForm = createRecordFieldFromCtlSchemaAndBody( + notificationSchema.getCtlSchemaId(), null); schemaInfo.setSchemaForm(schemaForm); schemaInfos.add(schemaInfo); } return schemaInfos; - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public NotificationSchemaViewDto getNotificationSchemaView(String notificationSchemaId) throws KaaAdminServiceException { + public NotificationSchemaViewDto getNotificationSchemaView(String notificationSchemaId) + throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { NotificationSchemaDto notificationSchema = getNotificationSchema(notificationSchemaId); - CTLSchemaDto ctlSchemaDto = controlService.getCTLSchemaById(notificationSchema.getCtlSchemaId()); - NotificationSchemaViewDto notificationSchemaViewDto = new NotificationSchemaViewDto(notificationSchema, toCtlSchemaForm(ctlSchemaDto, + CTLSchemaDto ctlSchemaDto = + controlService.getCTLSchemaById(notificationSchema.getCtlSchemaId()); + NotificationSchemaViewDto notificationSchemaViewDto = new NotificationSchemaViewDto( + notificationSchema, toCtlSchemaForm(ctlSchemaDto, ConverterType.FORM_AVRO_CONVERTER)); return notificationSchemaViewDto; - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public NotificationSchemaViewDto saveNotificationSchemaView(NotificationSchemaViewDto notificationSchemaView) throws KaaAdminServiceException { + public NotificationSchemaViewDto saveNotificationSchemaView( + NotificationSchemaViewDto notificationSchemaView) throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { NotificationSchemaDto notificationSchema = notificationSchemaView.getSchema(); @@ -333,26 +399,30 @@ public NotificationSchemaViewDto saveNotificationSchemaView(NotificationSchemaVi if (isEmpty(ctlSchemaId)) { if (notificationSchemaView.useExistingCtlSchema()) { CtlSchemaReferenceDto metaInfo = notificationSchemaView.getExistingMetaInfo(); - CTLSchemaDto schema = ctlService.getCTLSchemaByFqnVersionTenantIdAndApplicationId(metaInfo.getMetaInfo().getFqn(), + CTLSchemaDto schema = ctlService.getCTLSchemaByFqnVersionTenantIdAndApplicationId( + metaInfo.getMetaInfo().getFqn(), metaInfo.getVersion(), metaInfo.getMetaInfo().getTenantId(), metaInfo.getMetaInfo().getApplicationId()); notificationSchema.setCtlSchemaId(schema.getId()); } else { - CtlSchemaFormDto ctlSchemaForm = ctlService.saveCTLSchemaForm(notificationSchemaView.getCtlSchemaForm(), ConverterType.FORM_AVRO_CONVERTER); + CtlSchemaFormDto ctlSchemaForm = ctlService.saveCTLSchemaForm( + notificationSchemaView.getCtlSchemaForm(), ConverterType.FORM_AVRO_CONVERTER); notificationSchema.setCtlSchemaId(ctlSchemaForm.getId()); } } NotificationSchemaDto savedNotificationSchema = saveNotificationSchema(notificationSchema); return getNotificationSchemaView(savedNotificationSchema.getId()); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public NotificationSchemaViewDto createNotificationSchemaFormCtlSchema(CtlSchemaFormDto ctlSchemaForm) throws KaaAdminServiceException { - LOG.error("createNotificationSchemaFormCtlSchema [{}]", ctlSchemaForm.getSchema().getDisplayString()); + public NotificationSchemaViewDto createNotificationSchemaFormCtlSchema( + CtlSchemaFormDto ctlSchemaForm) throws KaaAdminServiceException { + LOG.error("createNotificationSchemaFormCtlSchema [{}]", + ctlSchemaForm.getSchema().getDisplayString()); checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { checkApplicationId(ctlSchemaForm.getMetaInfo().getApplicationId()); @@ -360,45 +430,13 @@ public NotificationSchemaViewDto createNotificationSchemaFormCtlSchema(CtlSchema notificationSchema.setApplicationId(ctlSchemaForm.getMetaInfo().getApplicationId()); notificationSchema.setName(ctlSchemaForm.getSchema().getDisplayNameFieldValue()); notificationSchema.setDescription(ctlSchemaForm.getSchema().getDescriptionFieldValue()); - CtlSchemaFormDto savedCtlSchemaForm = ctlService.saveCTLSchemaForm(ctlSchemaForm, ConverterType.FORM_AVRO_CONVERTER); + CtlSchemaFormDto savedCtlSchemaForm = ctlService.saveCTLSchemaForm( + ctlSchemaForm, ConverterType.FORM_AVRO_CONVERTER); notificationSchema.setCtlSchemaId(savedCtlSchemaForm.getId()); NotificationSchemaDto savedNotificationSchema = saveNotificationSchema(notificationSchema); return getNotificationSchemaView(savedNotificationSchema.getId()); - } catch (Exception e) { - throw Utils.handleException(e); - } - } - - @Override - public void sendNotification(NotificationDto notification, RecordField notificationData) throws KaaAdminServiceException { - checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); - try { - checkExpiredDate(notification); - GenericRecord record = FormAvroConverter.createGenericRecordFromRecordField(notificationData); - GenericAvroConverter converter = new GenericAvroConverter<>(record.getSchema()); - byte[] body = converter.encodeToJsonBytes(record); - notification.setBody(body); - checkApplicationId(notification.getApplicationId()); - TopicDto topic = controlService.getTopic(notification.getTopicId()); - Utils.checkNotNull(topic); - checkApplicationId(topic.getApplicationId()); - controlService.editNotification(notification); - } catch (Exception e) { - throw Utils.handleException(e); - } - } - - @Override - public EndpointNotificationDto sendUnicastNotification(NotificationDto notification, String clientKeyHash, RecordField notificationData) - throws KaaAdminServiceException { - checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); - try { - GenericRecord record = FormAvroConverter.createGenericRecordFromRecordField(notificationData); - GenericAvroConverter converter = new GenericAvroConverter<>(record.getSchema()); - byte[] body = converter.encodeToJsonBytes(record); - return sendUnicastNotification(notification, clientKeyHash, body); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/SdkServiceImpl.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/SdkServiceImpl.java index b1fdb98d29..9c0c13a426 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/SdkServiceImpl.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/SdkServiceImpl.java @@ -99,12 +99,14 @@ public SdkProfileDto getSdkProfile(String sdkProfileId) throws KaaAdminServiceEx } @Override - public List getSdkProfilesByApplicationToken(String applicationToken) throws KaaAdminServiceException { + public List getSdkProfilesByApplicationToken(String applicationToken) + throws KaaAdminServiceException { return getSdkProfilesByApplicationId(checkApplicationToken(applicationToken)); } @Override - public List getSdkProfilesByApplicationId(String applicationId) throws KaaAdminServiceException { + public List getSdkProfilesByApplicationId(String applicationId) + throws KaaAdminServiceException { this.checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { this.checkApplicationId(applicationId); @@ -115,17 +117,21 @@ public List getSdkProfilesByApplicationId(String applicationId) t } @Override - public FileData getSdk(SdkProfileDto sdkProfile, SdkPlatform targetPlatform) throws KaaAdminServiceException { + public FileData getSdk(SdkProfileDto sdkProfile, SdkPlatform targetPlatform) + throws KaaAdminServiceException { try { return doGenerateSdk(sdkProfile, targetPlatform); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override public void flushSdkCache() throws KaaAdminServiceException { - checkAuthority(KaaAuthorityDto.TENANT_ADMIN, KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); + checkAuthority( + KaaAuthorityDto.TENANT_ADMIN, + KaaAuthorityDto.TENANT_DEVELOPER, + KaaAuthorityDto.TENANT_USER); try { List applications = applicationService.getApplications(); for (ApplicationDto application : applications) { @@ -133,18 +139,20 @@ public void flushSdkCache() throws KaaAdminServiceException { cacheService.flushSdk(key); } } - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public String generateSdk(SdkProfileDto sdkProfile, SdkPlatform targetPlatform) throws KaaAdminServiceException { + public String generateSdk(SdkProfileDto sdkProfile, SdkPlatform targetPlatform) + throws KaaAdminServiceException { try { doGenerateSdk(sdkProfile, targetPlatform); - return Base64.encodeObject(new CacheService.SdkKey(sdkProfile, targetPlatform), Base64.URL_SAFE); - } catch (Exception e) { - throw Utils.handleException(e); + return Base64.encodeObject( + new CacheService.SdkKey(sdkProfile, targetPlatform), Base64.URL_SAFE); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @@ -159,8 +167,8 @@ public SdkProfileViewDto getSdkProfileView(String sdkProfileId) throws KaaAdminS String applicationId = sdkProfile.getApplicationId(); List aefDtoList = new ArrayList<>(); - List aefMaps = controlService. - getApplicationEventFamilyMapsByApplicationId(applicationId); + List aefMaps = controlService + .getApplicationEventFamilyMapsByApplicationId(applicationId); List aefMapIds = sdkProfile.getAefMapIds(); for (ApplicationEventFamilyMapDto aefDto : aefMaps) { if (aefMapIds.contains(aefDto.getId())) { @@ -178,7 +186,8 @@ public SdkProfileViewDto getSdkProfileView(String sdkProfileId) throws KaaAdminS } } - List profileSchemas = controlService.getProfileSchemasByApplicationId(applicationId); + List profileSchemas = + controlService.getProfileSchemasByApplicationId(applicationId); for (EndpointProfileSchemaDto dto : profileSchemas) { if (dto.getVersion() == sdkProfile.getProfileSchemaVersion()) { viewDto.setProfileSchemaName(dto.getName() + " (v." + dto.getVersion() + ")"); @@ -204,39 +213,45 @@ public SdkProfileViewDto getSdkProfileView(String sdkProfileId) throws KaaAdminS } return viewDto; - } catch (ControlServiceException e) { - throw Utils.handleException(e); + } catch (ControlServiceException ex) { + throw Utils.handleException(ex); } } @Override - public SchemaVersions getSchemaVersionsByApplicationToken(String applicationToken) throws KaaAdminServiceException { + public SchemaVersions getSchemaVersionsByApplicationToken(String applicationToken) + throws KaaAdminServiceException { return getSchemaVersionsByApplicationId(checkApplicationToken(applicationToken)); } @Override - public SchemaVersions getSchemaVersionsByApplicationId(String applicationId) throws KaaAdminServiceException { + public SchemaVersions getSchemaVersionsByApplicationId(String applicationId) + throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { checkApplicationId(applicationId); SchemaVersions schemaVersions = new SchemaVersions(); - List configurationSchemaVersions = controlService.getConfigurationSchemaVersionsByApplicationId(applicationId); + List configurationSchemaVersions = + controlService.getConfigurationSchemaVersionsByApplicationId(applicationId); schemaVersions.setConfigurationSchemaVersions(configurationSchemaVersions); - List profileSchemaVersions = controlService.getProfileSchemaVersionsByApplicationId(applicationId); + List profileSchemaVersions = + controlService.getProfileSchemaVersionsByApplicationId(applicationId); schemaVersions.setProfileSchemaVersions(profileSchemaVersions); - List notificationSchemaVersions = controlService.getNotificationSchemaVersionsByApplicationId(applicationId); + List notificationSchemaVersions = + controlService.getNotificationSchemaVersionsByApplicationId(applicationId); schemaVersions.setNotificationSchemaVersions(notificationSchemaVersions); - List logSchemaVersions = controlService.getLogSchemaVersionsByApplicationId(applicationId); + List logSchemaVersions = + controlService.getLogSchemaVersionsByApplicationId(applicationId); schemaVersions.setLogSchemaVersions(logSchemaVersions); return schemaVersions; - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @@ -253,7 +268,8 @@ private SdkProfileDto checkSdkProfileId(String sdkProfileId) throws KaaAdminServ } } - private FileData doGenerateSdk(SdkProfileDto sdkProfile, SdkPlatform targetPlatform) throws KaaAdminServiceException { + private FileData doGenerateSdk(SdkProfileDto sdkProfile, SdkPlatform targetPlatform) + throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { checkApplicationId(sdkProfile.getApplicationId()); @@ -264,8 +280,8 @@ private FileData doGenerateSdk(SdkProfileDto sdkProfile, SdkPlatform targetPlatf cacheService.putSdk(sdkKey, sdkFile); } return sdkFile; - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/TenantServiceImpl.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/TenantServiceImpl.java index 7f9d1f7e08..571be0ee7a 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/TenantServiceImpl.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/TenantServiceImpl.java @@ -43,8 +43,8 @@ public List getTenants() throws KaaAdminServiceException { Utils.checkNotNull(tenants); return tenants; - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @@ -55,8 +55,8 @@ public TenantDto getTenant(String tenantId) throws KaaAdminServiceException { TenantDto tenantDto = controlService.getTenant(tenantId); Utils.checkNotNull(tenantDto); return tenantDto; - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @@ -65,8 +65,8 @@ public TenantDto editTenant(TenantDto tenantUser) throws KaaAdminServiceExceptio checkAuthority(KaaAuthorityDto.KAA_ADMIN); try { return controlService.editTenant(tenantUser); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @@ -75,8 +75,8 @@ public void deleteTenant(String tenantId) throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.KAA_ADMIN); try { controlService.deleteTenant(tenantId); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/UserServiceImpl.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/UserServiceImpl.java index 67e7d1a1e0..09f5894a19 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/UserServiceImpl.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/UserServiceImpl.java @@ -36,11 +36,12 @@ public class UserServiceImpl extends AbstractAdminService implements UserService { @Override - public org.kaaproject.kaa.common.dto.admin.UserDto getUserProfile() throws KaaAdminServiceException { + public org.kaaproject.kaa.common.dto.admin.UserDto getUserProfile() + throws KaaAdminServiceException { try { return toUser(getCurrentUser()); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @@ -59,29 +60,33 @@ public void editUserProfile(UserProfileUpdateDto userDto) user.setMail(userDto.getMail()); } userFacade.save(user); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public List getUsers() throws KaaAdminServiceException { + public List getUsers() + throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_ADMIN); try { - List users = controlService.getTenantUsers(getTenantId()); - List tenantUsers = new ArrayList<>(users.size()); + List users = controlService.getTenantUsers( + getTenantId()); + List tenantUsers = new ArrayList<>( + users.size()); for (org.kaaproject.kaa.common.dto.UserDto user : users) { org.kaaproject.kaa.common.dto.admin.UserDto tenantUser = toUser(user); tenantUsers.add(tenantUser); } return tenantUsers; - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public org.kaaproject.kaa.common.dto.admin.UserDto getUser(String userId) throws KaaAdminServiceException { + public org.kaaproject.kaa.common.dto.admin.UserDto getUser(String userId) + throws KaaAdminServiceException { try { UserDto user = controlService.getUser(userId); Utils.checkNotNull(user); @@ -92,13 +97,14 @@ public org.kaaproject.kaa.common.dto.admin.UserDto getUser(String userId) throws checkTenantId(user.getTenantId()); } return toUser(user); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public org.kaaproject.kaa.common.dto.admin.UserDto editUser(org.kaaproject.kaa.common.dto.admin.UserDto user) + public org.kaaproject.kaa.common.dto.admin.UserDto editUser( + org.kaaproject.kaa.common.dto.admin.UserDto user) throws KaaAdminServiceException { try { boolean createNewUser = (user.getId() == null); @@ -117,8 +123,8 @@ public org.kaaproject.kaa.common.dto.admin.UserDto editUser(org.kaaproject.kaa.c editedUser.setTempPassword(tempPassword); } return editedUser; - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @@ -135,23 +141,25 @@ public void deleteUser(String userId) throws KaaAdminServiceException { } userFacade.deleteUser(Long.valueOf(user.getExternalUid())); controlService.deleteUser(user.getId()); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public List findAllTenantAdminsByTenantId(String tenantId) throws KaaAdminServiceException { + public List findAllTenantAdminsByTenantId( + String tenantId) throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.KAA_ADMIN); List tenantAdminList = new ArrayList<>(); try { List userDtoList = controlService.findAllTenantAdminsByTenantId(tenantId); if (userDtoList != null) { - for (UserDto userDto : userDtoList) + for (UserDto userDto : userDtoList) { tenantAdminList.add(toUser(userDto)); + } } - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } return tenantAdminList; } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/VerifierServiceImpl.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/VerifierServiceImpl.java index efa108ef3b..6c78edb0d1 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/VerifierServiceImpl.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/VerifierServiceImpl.java @@ -35,12 +35,14 @@ public class VerifierServiceImpl extends AbstractAdminService implements VerifierService { @Override - public List getRestUserVerifiersByApplicationToken(String appToken) throws KaaAdminServiceException { + public List getRestUserVerifiersByApplicationToken(String appToken) + throws KaaAdminServiceException { return getRestUserVerifiersByApplicationId(checkApplicationToken(appToken)); } @Override - public List getRestUserVerifiersByApplicationId(String appId) throws KaaAdminServiceException { + public List getRestUserVerifiersByApplicationId(String appId) + throws KaaAdminServiceException { List userVerifiers = getUserVerifiersByApplicationId(appId); for (UserVerifierDto userVerifier : userVerifiers) { setPluginJsonConfigurationFromRaw(userVerifier, PluginType.USER_VERIFIER); @@ -49,38 +51,42 @@ public List getRestUserVerifiersByApplicationId(String appId) t } @Override - public List getUserVerifiersByApplicationId(String appId) throws KaaAdminServiceException { + public List getUserVerifiersByApplicationId(String appId) + throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { checkApplicationId(appId); return controlService.getUserVerifiersByApplicationId(appId); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public UserVerifierDto getRestUserVerifier(String userVerifierId) throws KaaAdminServiceException { + public UserVerifierDto getRestUserVerifier(String userVerifierId) + throws KaaAdminServiceException { UserVerifierDto userVerifier = getUserVerifier(userVerifierId); setPluginJsonConfigurationFromRaw(userVerifier, PluginType.USER_VERIFIER); return userVerifier; } @Override - public UserVerifierDto getUserVerifier(String userVerifierId) throws KaaAdminServiceException { + public UserVerifierDto getUserVerifier(String userVerifierId) + throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { UserVerifierDto userVerifier = controlService.getUserVerifier(userVerifierId); Utils.checkNotNull(userVerifier); checkApplicationId(userVerifier.getApplicationId()); return userVerifier; - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public UserVerifierDto editRestUserVerifier(UserVerifierDto userVerifier) throws KaaAdminServiceException { + public UserVerifierDto editRestUserVerifier(UserVerifierDto userVerifier) + throws KaaAdminServiceException { setPluginRawConfigurationFromJson(userVerifier, PluginType.USER_VERIFIER); UserVerifierDto savedUserVerifier = editUserVerifier(userVerifier); setPluginJsonConfigurationFromRaw(savedUserVerifier, PluginType.USER_VERIFIER); @@ -88,7 +94,8 @@ public UserVerifierDto editRestUserVerifier(UserVerifierDto userVerifier) throws } @Override - public UserVerifierDto editUserVerifier(UserVerifierDto userVerifier) throws KaaAdminServiceException { + public UserVerifierDto editUserVerifier(UserVerifierDto userVerifier) + throws KaaAdminServiceException { checkAuthority(KaaAuthorityDto.TENANT_DEVELOPER, KaaAuthorityDto.TENANT_USER); try { if (isEmpty(userVerifier.getId())) { @@ -100,8 +107,8 @@ public UserVerifierDto editUserVerifier(UserVerifierDto userVerifier) throws Kaa checkApplicationId(storedUserVerifier.getApplicationId()); } return controlService.editUserVerifier(userVerifier); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @@ -116,30 +123,32 @@ public void deleteUserVerifier(String userVerifierId) throws KaaAdminServiceExce Utils.checkNotNull(userVerifier); checkApplicationId(userVerifier.getApplicationId()); controlService.deleteUserVerifier(userVerifierId); - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public UserVerifierDto getUserVerifierForm(String userVerifierId) throws KaaAdminServiceException { + public UserVerifierDto getUserVerifierForm(String userVerifierId) + throws KaaAdminServiceException { UserVerifierDto userVerifier = getUserVerifier(userVerifierId); try { setPluginFormConfigurationFromRaw(userVerifier, PluginType.USER_VERIFIER); return userVerifier; - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } @Override - public UserVerifierDto editUserVerifierForm(UserVerifierDto userVerifier) throws KaaAdminServiceException { + public UserVerifierDto editUserVerifierForm(UserVerifierDto userVerifier) + throws KaaAdminServiceException { try { setPluginRawConfigurationFromForm(userVerifier); UserVerifierDto saved = editUserVerifier(userVerifier); return saved; - } catch (Exception e) { - throw Utils.handleException(e); + } catch (Exception ex) { + throw Utils.handleException(ex); } } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/auth/KaaAdminAuthFailureHandler.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/auth/KaaAdminAuthFailureHandler.java index e7540f0db0..3fd4659ee1 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/auth/KaaAdminAuthFailureHandler.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/auth/KaaAdminAuthFailureHandler.java @@ -49,16 +49,19 @@ public KaaAdminAuthFailureHandler(String defaultFailureUrl) { /** * Performs the redirect or forward to the {@code defaultFailureUrl} if set, otherwise returns a - * 401 error code.

If redirecting or forwarding, {@code saveException} will be called to cache - * the exception for use in the target view. + * 401 error code.

If redirecting or forwarding, {@code saveException} + * will be called to cache the exception for use in the target view. */ public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, - AuthenticationException exception) throws IOException, ServletException { + AuthenticationException exception) + throws IOException, ServletException { if (defaultFailureUrl == null) { LOG.debug("No failure URL set, sending 401 Unauthorized error"); - response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Authentication Failed: " + exception.getLocalizedMessage()); + response.sendError( + HttpServletResponse.SC_UNAUTHORIZED, + "Authentication Failed: " + exception.getLocalizedMessage()); } else { saveException(request, exception); @@ -89,7 +92,8 @@ public void onAuthenticationFailure(HttpServletRequest request, HttpServletRespo * @param request the request * @param exception the exception */ - protected final void saveException(HttpServletRequest request, AuthenticationException exception) { + protected final void saveException(HttpServletRequest request, + AuthenticationException exception) { // Do nothing } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/auth/TempCredentialsException.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/auth/TempCredentialsException.java index b872a31928..84f2d7d250 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/auth/TempCredentialsException.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/auth/TempCredentialsException.java @@ -26,8 +26,8 @@ public TempCredentialsException(String msg) { super(msg); } - public TempCredentialsException(String msg, Throwable t) { - super(msg, t); + public TempCredentialsException(String msg, Throwable throwable) { + super(msg, throwable); } } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/auth/UserDetailsServiceImpl.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/auth/UserDetailsServiceImpl.java index e8a2dc1a90..1b9e9e7d93 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/auth/UserDetailsServiceImpl.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/auth/UserDetailsServiceImpl.java @@ -52,8 +52,8 @@ public UserDetails loadUserByUsername(String username) userDto = controlService.getUserByExternalUid(authUser.getExternalUid()); authUser.setId(userDto.getId()); authUser.setTenantId(userDto.getTenantId()); - } catch (ControlServiceException e) { - throw new UsernameNotFoundException("unable to fetch user details", e); + } catch (ControlServiceException ex) { + throw new UsernameNotFoundException("unable to fetch user details", ex); } } return authUser; diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/dao/PropertiesFacade.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/dao/PropertiesFacade.java index 4553a6a01f..3e57fe5ea3 100755 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/dao/PropertiesFacade.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/dao/PropertiesFacade.java @@ -72,8 +72,9 @@ public S getSpecificProperties(Class propertie new AvroByteArrayConverter<>(propertiesClass); try { specificProperties = converter.fromByteArray(entity.getRawConfiguration()); - } catch (IOException e) { - LOG.error("Unable to parse raw data for specific record " + propertiesClass.getSimpleName(), e); + } catch (IOException ex) { + LOG.error( + "Unable to parse raw data for specific record " + propertiesClass.getSimpleName(), ex); } } if (specificProperties == null) { @@ -82,14 +83,17 @@ public S getSpecificProperties(Class propertie return specificProperties; } - public PropertiesDto getPropertiesDto(Class propertiesClass) throws Exception { + public PropertiesDto getPropertiesDto(Class propertiesClass) + throws Exception { Properties entity = findOrCreateByClass(propertiesClass); return toDto(entity, propertiesClass); } - public PropertiesDto editPropertiesDto(PropertiesDto propertiesDto, Class propertiesClass) throws Exception { + public PropertiesDto editPropertiesDto( + PropertiesDto propertiesDto,Class propertiesClass) throws Exception { Properties entity = findOrCreateByClass(propertiesClass); - GenericRecord record = FormAvroConverter.createGenericRecordFromRecordField(propertiesDto.getConfiguration()); + GenericRecord record = FormAvroConverter.createGenericRecordFromRecordField( + propertiesDto.getConfiguration()); GenericAvroConverter converter = new GenericAvroConverter<>(record.getSchema()); byte[] rawConfiguration = converter.encode(record); entity.setRawConfiguration(rawConfiguration); @@ -118,12 +122,15 @@ private S buildDefaultProperties(Class propert try { Schema schema = (Schema) propertiesClass.getField(SCHEMA).get(null); RawSchema rawSchema = new RawSchema(schema.toString()); - DefaultRecordGenerationAlgorithm algotithm = new DefaultRecordGenerationAlgorithmImpl<>(rawSchema, new RawDataFactory()); + DefaultRecordGenerationAlgorithm algotithm = + new DefaultRecordGenerationAlgorithmImpl<>(rawSchema, new RawDataFactory()); RawData rawData = algotithm.getRootData(); AvroJsonConverter converter = new AvroJsonConverter<>(schema, propertiesClass); result = converter.decodeJson(rawData.getRawData()); - } catch (Exception e) { - LOG.error("Unable to build default specific properties for class " + propertiesClass.getSimpleName(), e); + } catch (Exception ex) { + LOG.error( + "Unable to build default specific properties for class " + + propertiesClass.getSimpleName(), ex); } return result; } @@ -136,8 +143,8 @@ private Properties createDefault(Class propert new AvroByteArrayConverter<>(propertiesClass); try { properties.setRawConfiguration(converter.toByteArray(specificProperties)); - } catch (IOException e) { - LOG.error("Unable to serialize configuration for properties", e); + } catch (IOException ex) { + LOG.error("Unable to serialize configuration for properties", ex); } properties.setFqn(propertiesClass.getName()); Long id = save(properties); @@ -145,7 +152,9 @@ private Properties createDefault(Class propert return properties; } - private PropertiesDto toDto(Properties entity, Class propertiesClass) throws Exception { + private PropertiesDto toDto(Properties entity, + Class propertiesClass) + throws Exception { PropertiesDto propertiesDto = new PropertiesDto(); propertiesDto.setId(String.valueOf(entity.getId())); Schema schema = (Schema) propertiesClass.getField(SCHEMA).get(null); diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/dao/UserFacade.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/dao/UserFacade.java index ac5a016b69..bcf43be7a9 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/dao/UserFacade.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/dao/UserFacade.java @@ -172,7 +172,9 @@ public User checkUserNameOccupied(String userName, Long userId) { Criteria criteria = getCriteria(); Criterion usernameCriterion = Restrictions.eq(USERNAME_PROPERTY, userName); if (userId != null) { - criteria.add(Restrictions.and(usernameCriterion, Restrictions.not(Restrictions.eq(ID_PROPERTY, userId)))); + criteria.add( + Restrictions.and( + usernameCriterion, Restrictions.not(Restrictions.eq(ID_PROPERTY, userId)))); } else { criteria.add(usernameCriterion); } @@ -183,7 +185,8 @@ public User checkEmailOccupied(String mail, Long userId) { Criteria criteria = getCriteria(); Criterion mailCriterion = Restrictions.eq(MAIL_PROPERTY, mail); if (userId != null) { - criteria.add(Restrictions.and(mailCriterion, Restrictions.not(Restrictions.eq(ID_PROPERTY, userId)))); + criteria.add(Restrictions.and( + mailCriterion, Restrictions.not(Restrictions.eq(ID_PROPERTY, userId)))); } else { criteria.add(mailCriterion); } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/messaging/MessagingService.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/messaging/MessagingService.java index c9ca5dd58f..f2b828cbd3 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/messaging/MessagingService.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/messaging/MessagingService.java @@ -18,12 +18,17 @@ public interface MessagingService { - public void configureMailSender(); + void configureMailSender(); - public void sendTempPassword(final String username, final String password, final String email) throws Exception; + void sendTempPassword(final String username, + final String password, + final String email)throws Exception; - public void sendPasswordResetLink(final String passwordResetHash, final String username, final String email); - - public void sendPasswordAfterReset(final String username, final String password, final String email); + void sendPasswordResetLink(final String passwordResetHash, + final String username, + final String email); + void sendPasswordAfterReset(final String username, + final String password, + final String email); } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/messaging/MessagingServiceImpl.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/messaging/MessagingServiceImpl.java index daf1228508..1091292783 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/messaging/MessagingServiceImpl.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/messaging/MessagingServiceImpl.java @@ -86,7 +86,8 @@ public void setSendTimeout(int sendTimeout) { public void init() { String sendName = "send-message-call-runner-%d"; - sendPool = Executors.newFixedThreadPool(sendPoolSize, new ThreadFactoryBuilder().setNameFormat(sendName).build()); + sendPool = Executors.newFixedThreadPool( + sendPoolSize, new ThreadFactoryBuilder().setNameFormat(sendName).build()); configureMailSender(); } @@ -105,17 +106,19 @@ public void destroy() { @Override public void configureMailSender() { - SmtpMailProperties smtpMailProperties = propertiesFacade.getSpecificProperties(SmtpMailProperties.class); - Properties javaMailProperties = toJavaMailProperties(smtpMailProperties); + SmtpMailProperties smtpMailProperties = propertiesFacade.getSpecificProperties( + SmtpMailProperties.class); kaaMessagingMailSender = new JavaMailSenderImpl(); kaaMessagingMailSender.setHost(smtpMailProperties.getSmtpHost()); kaaMessagingMailSender.setPort(smtpMailProperties.getSmtpPort()); kaaMessagingMailSender.setUsername(smtpMailProperties.getUsername()); kaaMessagingMailSender.setPassword(smtpMailProperties.getPassword()); + Properties javaMailProperties = toJavaMailProperties(smtpMailProperties); kaaMessagingMailSender.setJavaMailProperties(javaMailProperties); mailFrom = smtpMailProperties.getMailFrom(); - GeneralProperties generalProperties = propertiesFacade.getSpecificProperties(GeneralProperties.class); + GeneralProperties generalProperties = propertiesFacade.getSpecificProperties( + GeneralProperties.class); appBaseUrl = generalProperties.getBaseUrl(); appName = generalProperties.getAppTitle(); } @@ -124,19 +127,30 @@ private Properties toJavaMailProperties(SmtpMailProperties smtpMailProperties) { Properties javaMailProperties = new Properties(); String protocol = smtpMailProperties.getSmtpProtocol().toString().toLowerCase(); javaMailProperties.put("mail.transport.protocol", protocol); - javaMailProperties.put("mail." + protocol + ".host", smtpMailProperties.getSmtpHost()); - javaMailProperties.put("mail." + protocol + ".port", String.valueOf(smtpMailProperties.getSmtpPort())); - javaMailProperties.put("mail." + protocol + ".timeout", String.valueOf(smtpMailProperties.getTimeout())); - javaMailProperties.put("mail." + protocol + ".auth", String.valueOf(!Utils.isEmpty(smtpMailProperties.getUsername()))); - javaMailProperties.put("mail." + protocol + ".starttls.enable", String.valueOf(smtpMailProperties.getEnableTls())); + javaMailProperties.put("mail." + + protocol + ".host", smtpMailProperties.getSmtpHost()); + javaMailProperties.put("mail." + + protocol + ".port", String.valueOf(smtpMailProperties.getSmtpPort())); + javaMailProperties.put("mail." + + protocol + ".timeout", String.valueOf(smtpMailProperties.getTimeout())); + javaMailProperties.put("mail." + + protocol + ".auth", String.valueOf(!Utils.isEmpty(smtpMailProperties.getUsername()))); + javaMailProperties.put("mail." + + protocol + ".starttls.enable", String.valueOf(smtpMailProperties.getEnableTls())); javaMailProperties.put("mail.debug", "true"); return javaMailProperties; } @Override - public void sendTempPassword(final String username, final String password, final String email) throws Exception { - String subject = messages.getMessage("tempPasswordMailMessageSubject", new Object[]{appName}, Locale.ENGLISH); - String text = messages.getMessage("tempPasswordMailMessageBody", new Object[]{appBaseUrl, appName, username, password}, Locale.ENGLISH); + public void sendTempPassword(final String username, + final String password, + final String email) throws Exception { + String subject = messages.getMessage( + "tempPasswordMailMessageSubject", new Object[]{appName}, Locale.ENGLISH); + String text = messages.getMessage( + "tempPasswordMailMessageBody", + new Object[]{appBaseUrl, appName,username, password}, + Locale.ENGLISH); MimeMessage mimeMsg = kaaMessagingMailSender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(mimeMsg, "UTF-8"); helper.setFrom(mailFrom); @@ -147,7 +161,9 @@ public void sendTempPassword(final String username, final String password, final } @Override - public void sendPasswordResetLink(final String passwordResetHash, final String username, final String email) { + public void sendPasswordResetLink(final String passwordResetHash, + final String username, + final String email) { try { callAsync(new Callable() { @Override @@ -155,8 +171,12 @@ public Void call() throws Exception { Map paramsMap = new HashMap<>(); paramsMap.put(UrlParams.RESET_PASSWORD, passwordResetHash); String params = "#" + UrlParams.generateParamsUrl(paramsMap); - String subject = messages.getMessage("resetPasswordMailMessageSubject", new Object[]{appName}, Locale.ENGLISH); - String text = messages.getMessage("resetPasswordMailMessageBody", new Object[]{username, appName, appBaseUrl + params}, Locale.ENGLISH); + String subject = messages.getMessage( + "resetPasswordMailMessageSubject", new Object[]{appName}, Locale.ENGLISH); + String text = messages.getMessage( + "resetPasswordMailMessageBody", + new Object[]{username, appName, appBaseUrl + params}, + Locale.ENGLISH); MimeMessage mimeMsg = kaaMessagingMailSender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(mimeMsg, "UTF-8"); try { @@ -165,25 +185,31 @@ public Void call() throws Exception { helper.setSubject(subject); helper.setText(text, true); kaaMessagingMailSender.send(helper.getMimeMessage()); - } catch (MessagingException e) { - LOG.error("Unexpected error while sendPasswordResetLinkMail", e); + } catch (MessagingException ex) { + LOG.error("Unexpected error while sendPasswordResetLinkMail", ex); } return null; } }); - } catch (Exception e) { - LOG.error("Unexpected error while sendPasswordResetLinkMail", e); + } catch (Exception ex) { + LOG.error("Unexpected error while sendPasswordResetLinkMail", ex); } } @Override - public void sendPasswordAfterReset(final String username, final String password, final String email) { + public void sendPasswordAfterReset(final String username, + final String password, + final String email) { try { callAsync(new Callable() { @Override public Void call() throws Exception { - String subject = messages.getMessage("passwordWasResetMailMessageSubject", new Object[]{appName}, Locale.ENGLISH); - String text = messages.getMessage("passwordWasResetMailMessageBody", new Object[]{username, appBaseUrl, appName, password}, Locale.ENGLISH); + String subject = messages.getMessage( + "passwordWasResetMailMessageSubject", new Object[]{appName}, Locale.ENGLISH); + String text = messages.getMessage( + "passwordWasResetMailMessageBody", + new Object[]{username, appBaseUrl, appName, password}, + Locale.ENGLISH); MimeMessage mimeMsg = kaaMessagingMailSender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(mimeMsg, "UTF-8"); try { @@ -192,14 +218,14 @@ public Void call() throws Exception { helper.setSubject(subject); helper.setText(text, true); kaaMessagingMailSender.send(helper.getMimeMessage()); - } catch (MessagingException e) { - LOG.error("Unexpected error while sendPasswordAfterResetMail", e); + } catch (MessagingException ex) { + LOG.error("Unexpected error while sendPasswordAfterResetMail", ex); } return null; } }); - } catch (Exception e) { - LOG.error("Unexpected error while sendPasswordAfterResetMail", e); + } catch (Exception ex) { + LOG.error("Unexpected error while sendPasswordAfterResetMail", ex); } } @@ -216,10 +242,10 @@ private T callWithTimeout(Callable callable) throws IOException, Interrup } else { return future.get(); } - } catch (TimeoutException eT) { + } catch (TimeoutException ex) { future.cancel(true); throw new IOException("Callable timed out after " + sendTimeout - + " sec", eT); + + " sec", ex); } catch (ExecutionException e1) { Throwable cause = e1.getCause(); if (cause instanceof IOException) { diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/schema/ConfigurationSchemaFormAvroConverter.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/schema/ConfigurationSchemaFormAvroConverter.java index 117e6aa5fb..d0e6442598 100755 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/schema/ConfigurationSchemaFormAvroConverter.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/schema/ConfigurationSchemaFormAvroConverter.java @@ -98,7 +98,6 @@ private Field createOverrideStrategyField() { } /* (non-Javadoc) - * @see org.kaaproject.avro.ui.converter.SchemaFormAvroConverter#customizeRecordFields(org.apache.avro.Schema, java.util.List) */ @Override protected void customizeRecordFields(Schema recordSchema, List fields) { @@ -116,7 +115,6 @@ protected void customizeRecordFields(Schema recordSchema, List fields) { } /* (non-Javadoc) - * @see org.kaaproject.avro.ui.converter.SchemaFormAvroConverter#customizeType(org.apache.avro.generic.GenericData.Record, org.apache.avro.Schema) */ @Override protected void customizeType(Record record, Schema fieldTypeSchema) { @@ -131,7 +129,6 @@ protected void customizeType(Record record, Schema fieldTypeSchema) { } /* (non-Javadoc) - * @see org.kaaproject.avro.ui.converter.SchemaFormAvroConverter#customizeFormField(org.apache.avro.generic.GenericData.Record, org.apache.avro.Schema.Field) */ @Override protected void customizeFormField(Record fieldType, Field field) { @@ -141,16 +138,17 @@ protected void customizeFormField(Record fieldType, Field field) { fieldType.getSchema().getField(OVERRIDE_STRATEGY).schema(); if (overrideStrategyNode != null && overrideStrategyNode.isTextual()) { fieldType.put(OVERRIDE_STRATEGY, - new GenericData.EnumSymbol(overrideStrategySchema, overrideStrategyNode.asText().toUpperCase())); + new GenericData.EnumSymbol( + overrideStrategySchema, overrideStrategyNode.asText().toUpperCase())); } else { fieldType.put(OVERRIDE_STRATEGY, - new GenericData.EnumSymbol(overrideStrategySchema, OverrideStrategy.REPLACE.name())); + new GenericData.EnumSymbol( + overrideStrategySchema, OverrideStrategy.REPLACE.name())); } } } /* (non-Javadoc) - * @see org.kaaproject.avro.ui.converter.SchemaFormAvroConverter#customizeFieldSchema(org.apache.avro.Schema, org.apache.avro.generic.GenericRecord) */ @Override protected void customizeFieldSchema(Schema fieldSchema, GenericRecord fieldType) { @@ -163,21 +161,20 @@ protected void customizeFieldSchema(Schema fieldSchema, GenericRecord fieldType) } /* (non-Javadoc) - * @see org.kaaproject.avro.ui.converter.SchemaFormAvroConverter#customizeSchemaField(org.apache.avro.Schema.Field, org.apache.avro.generic.GenericData.Record) */ @Override protected void customizeSchemaField(Field avroField, Record fieldType) { if (fieldType.getSchema().getName().equals(ARRAY_FIELD_TYPE)) { GenericData.EnumSymbol overrideStrategy = (GenericData.EnumSymbol) fieldType.get(OVERRIDE_STRATEGY); - if (overrideStrategy != null && !overrideStrategy.toString().equalsIgnoreCase(OverrideStrategy.REPLACE.name())) { + if (overrideStrategy != null + && !overrideStrategy.toString().equalsIgnoreCase(OverrideStrategy.REPLACE.name())) { avroField.addProp(OVERRIDE_STRATEGY, overrideStrategy.toString().toLowerCase()); } } } /* (non-Javadoc) - * @see org.kaaproject.avro.ui.converter.SchemaFormAvroConverter#customizeUiForm(org.kaaproject.avro.ui.shared.RecordField) */ @Override protected RecordField customizeUiForm(RecordField field) { diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/schema/CTLSchemaParser.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/schema/CtlSchemaParser.java similarity index 82% rename from server/node/src/main/java/org/kaaproject/kaa/server/admin/services/schema/CTLSchemaParser.java rename to server/node/src/main/java/org/kaaproject/kaa/server/admin/services/schema/CtlSchemaParser.java index cd9bf52f34..ac99621f10 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/schema/CTLSchemaParser.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/schema/CtlSchemaParser.java @@ -51,7 +51,7 @@ * @see #validate(CTLSchemaDto) * @since v0.8.0 */ -public class CTLSchemaParser { +public class CtlSchemaParser { private static final String VERSION = "version"; @@ -68,14 +68,14 @@ public class CTLSchemaParser { /** * The Constant LOG. */ - private static final Logger LOG = LoggerFactory.getLogger(CTLSchemaParser.class); + private static final Logger LOG = LoggerFactory.getLogger(CtlSchemaParser.class); private final Schema.Parser parser = new Schema.Parser(); private final ControlService controlService; private final String tenantId; - public CTLSchemaParser(ControlService controlService, String tenantId) { + public CtlSchemaParser(ControlService controlService, String tenantId) { this.controlService = controlService; this.tenantId = tenantId; } @@ -111,14 +111,16 @@ public static Schema parseStringCtlSchema(String avroSchema) throws Exception { return parser.parse(avroSchema); } - public CTLSchemaDto parse(String body, String applicationId) throws ControlServiceException, JsonParseException, JsonMappingException, IOException { + public CTLSchemaDto parse(String body, String applicationId) + throws ControlServiceException, JsonParseException, JsonMappingException, IOException { CTLSchemaDto schema = new CTLSchemaDto(); CTLSchemaMetaInfoDto metaInfo = new CTLSchemaMetaInfoDto(); String fqn = null; ObjectNode object = new ObjectMapper().readValue(body, ObjectNode.class); - if (!object.has(TYPE) || !object.get(TYPE).isTextual() || !object.get(TYPE).getTextValue().equals("record")) { + if (!object.has(TYPE) || !object.get(TYPE).isTextual() || + !object.get(TYPE).getTextValue().equals("record")) { throw new IllegalArgumentException("The data provided is not a record!"); } @@ -145,14 +147,16 @@ public CTLSchemaDto parse(String body, String applicationId) throws ControlServi throw new IllegalArgumentException("Illegal dependencies format!"); } else { for (JsonNode child : object.get(DEPENDENCIES)) { - if (!child.isObject() || !child.has(FQN) || !child.get(FQN).isTextual() || !child.has(VERSION) - || !child.get(VERSION).isInt()) { + if (!child.isObject() || !child.has(FQN) || !child.get(FQN).isTextual() + || !child.has(VERSION) || !child.get(VERSION).isInt()) { throw new IllegalArgumentException("Illegal dependency format!"); } else { String dependencyFqn = child.get(FQN).asText(); int dependencyVersion = child.get(VERSION).asInt(); - CTLSchemaDto dependency = controlService.getAnyCTLSchemaByFqnVersionTenantIdAndApplicationId(dependencyFqn, dependencyVersion, tenantId, applicationId); + CTLSchemaDto dependency = + controlService.getAnyCTLSchemaByFqnVersionTenantIdAndApplicationId( + dependencyFqn, dependencyVersion, tenantId, applicationId); if (dependency != null) { dependencies.add(dependency); } else { @@ -161,7 +165,8 @@ public CTLSchemaDto parse(String body, String applicationId) throws ControlServi } } if (!missingDependencies.isEmpty()) { - String message = "The following dependencies are missing from the database: " + Arrays.toString(missingDependencies.toArray()); + String message = "The following dependencies are missing from the database: " + + Arrays.toString(missingDependencies.toArray()); throw new IllegalArgumentException(message); } schema.setDependencySet(dependencies); @@ -184,10 +189,14 @@ public Schema validate(CTLSchemaDto schema) throws KaaAdminServiceException { if (schema.getDependencySet() != null) { for (CTLSchemaDto dependency : schema.getDependencySet()) { try { - CTLSchemaDto dependencySchema = controlService.getCTLSchemaByFqnVersionTenantIdAndApplicationId(dependency.getMetaInfo().getFqn(), - dependency.getVersion(), dependency.getMetaInfo().getTenantId(), dependency.getMetaInfo().getApplicationId()); + CTLSchemaDto dependencySchema = + controlService.getCTLSchemaByFqnVersionTenantIdAndApplicationId( + dependency.getMetaInfo().getFqn(), dependency.getVersion(), + dependency.getMetaInfo().getTenantId(), + dependency.getMetaInfo().getApplicationId()); if (dependencySchema == null) { - String message = "Unable to locate dependency \"" + dependency.getMetaInfo().getFqn() + "\" (version " + dependency.getVersion() + ")"; + String message = "Unable to locate dependency \"" + dependency.getMetaInfo().getFqn() + + "\" (version " + dependency.getVersion() + ")"; throw new IllegalArgumentException(message); } validate(dependencySchema); @@ -204,8 +213,11 @@ public Schema validate(CTLSchemaDto schema) throws KaaAdminServiceException { */ return parser.parse(schema.getBody()); } catch (Exception cause) { - LOG.error("Unable to parse CTL schema \"" + schema.getMetaInfo().getFqn() + "\" (version " + schema.getVersion() + "): ", cause); - throw new IllegalArgumentException("Unable to parse CTL schema \"" + schema.getMetaInfo().getFqn() + "\" (version " + schema.getVersion() + "): " + cause.getMessage()); + LOG.error("Unable to parse CTL schema \"" + + schema.getMetaInfo().getFqn() + "\" (version " + schema.getVersion() + "): ", cause); + throw new IllegalArgumentException("Unable to parse CTL schema \"" + + schema.getMetaInfo().getFqn() + "\" (version " + + schema.getVersion() + "): " + cause.getMessage()); } } } \ No newline at end of file diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/schema/EcfSchemaFormAvroConverter.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/schema/EcfSchemaFormAvroConverter.java index 31712c756d..6efa9b3da9 100755 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/schema/EcfSchemaFormAvroConverter.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/schema/EcfSchemaFormAvroConverter.java @@ -107,7 +107,6 @@ private Field createClassTypeField() { } /* (non-Javadoc) - * @see org.kaaproject.avro.ui.converter.SchemaFormAvroConverter#createConverterSchema() */ @Override protected Schema createConverterSchema() throws IOException { @@ -118,7 +117,6 @@ protected Schema createConverterSchema() throws IOException { } /* (non-Javadoc) - * @see org.kaaproject.avro.ui.converter.SchemaFormAvroConverter#customizeRecordFields(org.apache.avro.Schema, java.util.List) */ @Override protected void customizeRecordFields(Schema recordSchema, List fields) { @@ -132,7 +130,6 @@ protected void customizeRecordFields(Schema recordSchema, List fields) { } /* (non-Javadoc) - * @see org.kaaproject.avro.ui.converter.SchemaFormAvroConverter#customizeType(org.apache.avro.generic.GenericData.Record, org.apache.avro.Schema) */ @Override protected void customizeType(Record record, Schema fieldTypeSchema) { @@ -150,7 +147,6 @@ protected void customizeType(Record record, Schema fieldTypeSchema) { } /* (non-Javadoc) - * @see org.kaaproject.avro.ui.converter.SchemaFormAvroConverter#customizeFieldSchema(org.apache.avro.Schema, org.apache.avro.generic.GenericRecord) */ @Override protected void customizeFieldSchema(Schema fieldSchema, GenericRecord fieldType) { diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/schema/SimpleSchemaFormAvroConverter.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/schema/SimpleSchemaFormAvroConverter.java index 8c01d2d6a8..74519d596b 100755 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/schema/SimpleSchemaFormAvroConverter.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/schema/SimpleSchemaFormAvroConverter.java @@ -38,7 +38,6 @@ public SimpleSchemaFormAvroConverter() throws IOException { } /* (non-Javadoc) - * @see org.kaaproject.avro.ui.converter.SchemaFormAvroConverter#customizeRecordFields(org.apache.avro.Schema, java.util.List) */ @Override protected void customizeRecordFields(Schema recordSchema, List fields) { diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/util/Utils.java b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/util/Utils.java index 65f3ce1edc..b6e9d9e5ea 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/util/Utils.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/admin/services/util/Utils.java @@ -47,7 +47,8 @@ public static KaaAdminServiceException handleException(Exception exception, Stri return new KaaAdminServiceException(message, ServiceErrorCode.GENERAL_ERROR); } - public static KaaAdminServiceException handleException(Exception exception, boolean logException) { + public static KaaAdminServiceException handleException(Exception exception, + boolean logException) { if (logException) { LOG.error("An unexpected exception occured!", exception); } @@ -61,26 +62,35 @@ public static KaaAdminServiceException handleException(Exception exception, bool return (KaaAdminServiceException) exception; } else if (exception instanceof NotFoundException) { return new KaaAdminServiceException(exception.getMessage(), ServiceErrorCode.ITEM_NOT_FOUND); - } else if (exception instanceof IllegalArgumentException || exception instanceof IncorrectParameterException + } else if (exception instanceof IllegalArgumentException + || exception instanceof IncorrectParameterException || cause.contains("IncorrectParameterException")) { - return new KaaAdminServiceException(exception.getMessage(), ServiceErrorCode.BAD_REQUEST_PARAMS); + return new KaaAdminServiceException( + exception.getMessage(), ServiceErrorCode.BAD_REQUEST_PARAMS); } else { - return new KaaAdminServiceException(exception.getMessage(), ServiceErrorCode.GENERAL_ERROR); + return new KaaAdminServiceException( + exception.getMessage(), ServiceErrorCode.GENERAL_ERROR); } } public static T checkNotNull(T reference) throws KaaAdminServiceException { if (reference == null) { - throw new KaaAdminServiceException("The requested item was not found!", ServiceErrorCode.ITEM_NOT_FOUND); + throw new KaaAdminServiceException( + "The requested item was not found!", ServiceErrorCode.ITEM_NOT_FOUND); } return reference; } - public static void checkFieldUniquieness(String field, Set storedEmails, String fieldName) throws KaaAdminServiceException { + public static void checkFieldUniquieness(String field, + Set storedEmails, + String fieldName) + throws KaaAdminServiceException { checkNotNull(field); boolean isAdded = storedEmails.add(field); if (!isAdded) { - throw new KaaAdminServiceException(String.format("Entered %s is already used by another user!", fieldName), ServiceErrorCode.INVALID_ARGUMENTS); + throw new KaaAdminServiceException( + String.format("Entered %s is already used by another user!", fieldName), + ServiceErrorCode.INVALID_ARGUMENTS); } } @@ -90,7 +100,9 @@ public static AuthUserDto getCurrentUser() throws KaaAdminServiceException { if (authentication.getPrincipal() instanceof AuthUserDto) { return (AuthUserDto) authentication.getPrincipal(); } else { - throw new KaaAdminServiceException("You are not authorized to perform this operation!", ServiceErrorCode.NOT_AUTHORIZED); + throw new KaaAdminServiceException( + "You are not authorized to perform this operation!", + ServiceErrorCode.NOT_AUTHORIZED); } } }