From 8a976cabadba6d454718daf05e8ef6948a5c7d5c Mon Sep 17 00:00:00 2001 From: Asharani Date: Thu, 5 May 2016 16:28:12 +0530 Subject: [PATCH 01/54] Minimize/Maximize upload status popup intial commit Signed-off-by: Asharani --- .../event/UploadArtifactUIEvent.java | 2 +- .../artifacts/state/ArtifactUploadState.java | 39 ++- .../ui/artifacts/upload/UploadHandler.java | 27 +- .../ui/artifacts/upload/UploadLayout.java | 125 ++++++-- .../upload/UploadStatusInfoWindow.java | 272 ++++++++++++++---- .../artifacts/upload/UploadStatusObject.java | 71 +++++ .../footer/AbstractDeleteActionsLayout.java | 8 +- .../ui/common/grid/AbstractGridLayout.java | 3 +- .../FilterManagementView.java | 3 +- .../ui/utils/SPUIComponetIdProvider.java | 21 ++ .../ui/utils/SPUIStyleDefinitions.java | 9 +- 11 files changed, 480 insertions(+), 100 deletions(-) create mode 100644 hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusObject.java diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadArtifactUIEvent.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadArtifactUIEvent.java index 3d75b67a7..de8f5867b 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadArtifactUIEvent.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadArtifactUIEvent.java @@ -16,5 +16,5 @@ package org.eclipse.hawkbit.ui.artifacts.event; */ public enum UploadArtifactUIEvent { - SHOW_DROP_HINTS, HIDE_DROP_HINTS, SOFTWARE_DRAG_START, SOFTWARE_TYPE_DRAG_START, UPDATE_UPLOAD_COUNT, ENABLE_PROCESS_BUTTON, HIDE_FILTER_BY_TYPE, SHOW_FILTER_BY_TYPE, DISCARD_DELETE_SOFTWARE, DISCARD_ALL_DELETE_SOFTWARE, DELETED_ALL_SOFWARE, DISABLE_PROCESS_BUTTON, DISCARD_DELETE_SOFTWARE_TYPE, DISCARD_ALL_DELETE_SOFTWARE_TYPE, DELETED_ALL_SOFWARE_TYPE + SHOW_DROP_HINTS, HIDE_DROP_HINTS, SOFTWARE_DRAG_START, SOFTWARE_TYPE_DRAG_START, UPDATE_UPLOAD_COUNT, ENABLE_PROCESS_BUTTON, HIDE_FILTER_BY_TYPE, SHOW_FILTER_BY_TYPE, DISCARD_DELETE_SOFTWARE, DISCARD_ALL_DELETE_SOFTWARE, DELETED_ALL_SOFWARE, DISABLE_PROCESS_BUTTON, DISCARD_DELETE_SOFTWARE_TYPE, DISCARD_ALL_DELETE_SOFTWARE_TYPE, DELETED_ALL_SOFWARE_TYPE,MINIMIZED_STATUS_POPUP,MAXIMIZED_STATUS_POPUP,UPLOAD_FINISHED,UPLOAD_STARTED, UPLOAD_STREAMINING_FINISHED } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/state/ArtifactUploadState.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/state/ArtifactUploadState.java index f82ce9ccf..ae6a5860e 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/state/ArtifactUploadState.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/state/ArtifactUploadState.java @@ -9,14 +9,17 @@ package org.eclipse.hawkbit.ui.artifacts.state; import java.io.Serializable; +import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Set; import org.eclipse.hawkbit.repository.model.SoftwareModule; +import org.eclipse.hawkbit.ui.artifacts.upload.UploadStatusObject; import org.eclipse.hawkbit.ui.common.ManagmentEntityState; import org.springframework.beans.factory.annotation.Autowired; @@ -58,8 +61,42 @@ public class ArtifactUploadState implements ManagmentEntityState, Serializ private final Set selectedDeleteSWModuleTypes = new HashSet<>(); private boolean noDataAvilableSoftwareModule = Boolean.FALSE; + + private boolean isStatusPopupMinimized = Boolean.FALSE; + + private boolean isUploadCompleted = Boolean.FALSE; + + private List uploadedFileStatusList = new ArrayList<>(); + + public List getUploadedFileStatusList() { + return uploadedFileStatusList; + } + + public void setUploadedFileStatusList(List uploadedFileStatusList) { + this.uploadedFileStatusList = uploadedFileStatusList; + } + + public boolean isUploadCompleted() { + return isUploadCompleted; + } + + public void setUploadCompleted(boolean isUploadCompleted) { + this.isUploadCompleted = isUploadCompleted; + } - /** + + public void setStatusPopupMinimized(boolean isStatusPopupMinimized) { + this.isStatusPopupMinimized = isStatusPopupMinimized; + } + + public boolean isStatusPopupMinimized() { + return isStatusPopupMinimized; + } + + + + + /** * Set software. * * @return diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java index 8c1feeb33..976d5ac27 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java @@ -13,11 +13,13 @@ import java.io.OutputStream; import org.eclipse.hawkbit.repository.exception.ArtifactUploadFailedException; import org.eclipse.hawkbit.repository.model.SoftwareModule; +import org.eclipse.hawkbit.ui.artifacts.event.UploadArtifactUIEvent; import org.eclipse.hawkbit.ui.artifacts.state.CustomFile; import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SpringContextHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.vaadin.spring.events.EventBus; import com.vaadin.server.StreamVariable; import com.vaadin.ui.Upload; @@ -66,6 +68,8 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene private volatile boolean interrupted = false; private String failureReason; private final I18N i18n; + private transient EventBus.SessionEventBus eventBus; + UploadHandler(final String fileName, final long fileSize, final UploadLayout view, final UploadStatusInfoWindow infoWindow, final long maxSize, final Upload upload, final String mimeType) { @@ -78,7 +82,7 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene this.upload = upload; this.mimeType = mimeType; this.i18n = SpringContextHelper.getBean(I18N.class); - + this.eventBus = SpringContextHelper.getBean(EventBus.SessionEventBus.class); } /** @@ -166,7 +170,7 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene if (view.enableProcessBtn()) { infoWindow.uploadSessionFinished(); } - view.updateActionCount(); + eventBus.publish(this, UploadArtifactUIEvent.UPLOAD_STREAMINING_FINISHED); // display the duplicate message after streaming all files view.displayDuplicateValidationMessage(); @@ -237,10 +241,12 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene public void updateProgress(final long readBytes, final long contentLength) { if (readBytes > maxSize || contentLength > maxSize) { LOG.error("User tried to upload more than was allowed ({}).", maxSize); + view.decreaseNumberOfFileUploadsExpected(); final SoftwareModule sw = view.getSoftwareModuleSelected(); view.getFileSelected().remove(new CustomFile(fileName, sw.getName(), sw.getVersion())); view.updateActionCount(); + failureReason = i18n.get("message.uploadedfile.size.exceeded", maxSize); infoWindow.uploadFailed(fileName, failureReason); upload.interruptUpload(); @@ -261,10 +267,12 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene public void onProgress(final StreamingProgressEvent event) { if (event.getBytesReceived() > maxSize || event.getContentLength() > maxSize) { LOG.error("User tried to upload more than was allowed ({}).", maxSize); + view.decreaseNumberOfFileUploadsExpected(); final SoftwareModule sw = view.getSoftwareModuleSelected(); view.getFileSelected().remove(new CustomFile(fileName, sw.getName(), sw.getVersion())); - view.updateActionCount(); + eventBus.publish(this, UploadArtifactUIEvent.UPLOAD_STREAMINING_FINISHED); + failureReason = i18n.get("message.uploadedfile.size.exceeded", maxSize); infoWindow.uploadFailed(event.getFileName(), failureReason); interrupted = true; @@ -285,11 +293,19 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene @Override public void streamingFailed(final StreamingErrorEvent event) { LOG.info("Streaming failed for file :{}", event.getFileName()); + view.decreaseNumberOfFileUploadsExpected(); final SoftwareModule sw = view.getSoftwareModuleSelected(); view.getFileSelected().remove(new CustomFile(fileName, sw.getName(), sw.getVersion())); - view.updateActionCount(); - infoWindow.uploadFailed(event.getFileName(), failureReason); + eventBus.publish(this, UploadArtifactUIEvent.UPLOAD_STREAMINING_FINISHED); + + if (failureReason != null) { + // Display custom error message + infoWindow.uploadFailed(event.getFileName(), failureReason); + } else { + // internal upload error + infoWindow.uploadFailed(event.getFileName(), event.getException().getMessage()); + } // check if we are finished if (view.enableProcessBtn()) { infoWindow.uploadSessionFinished(); @@ -299,6 +315,7 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene LOG.info("Streaming failed due to :{}", event.getException()); } + /** * Upload failed for {@link Upload} variant. * diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java index 7376cce13..340f66287 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java @@ -103,7 +103,7 @@ public class UploadLayout extends VerticalLayout { private final List duplicateFileNamesList = new ArrayList<>(); - private Button processBtn; + private Button processBtn ; private Button discardBtn; @@ -119,6 +119,8 @@ public class UploadLayout extends VerticalLayout { private Boolean hasDirectory = Boolean.FALSE; + private Button uploadStatusButton; + /** * Initialize the upload layout. */ @@ -127,12 +129,13 @@ public class UploadLayout extends VerticalLayout { createComponents(); buildLayout(); updateActionCount(); + restoreState(); eventBus.subscribe(this); ui = UI.getCurrent(); } private void createComponents() { - + createUploadStatusButton(); createProcessButton(); createDiscardBtn(); } @@ -154,12 +157,15 @@ public class UploadLayout extends VerticalLayout { fileUploadLayout = new HorizontalLayout(); fileUploadLayout.setSpacing(true); + fileUploadLayout.addStyleName(SPUIStyleDefinitions.FOOTER_LAYOUT); fileUploadLayout.addComponent(upload); fileUploadLayout.setComponentAlignment(upload, Alignment.MIDDLE_LEFT); fileUploadLayout.addComponent(processBtn); fileUploadLayout.setComponentAlignment(processBtn, Alignment.MIDDLE_RIGHT); fileUploadLayout.addComponent(discardBtn); fileUploadLayout.setComponentAlignment(discardBtn, Alignment.MIDDLE_RIGHT); + fileUploadLayout.addComponent(uploadStatusButton); + fileUploadLayout.setComponentAlignment(uploadStatusButton, Alignment.MIDDLE_RIGHT); setMargin(false); /* create drag-drop wrapper for drop area */ @@ -167,7 +173,13 @@ public class UploadLayout extends VerticalLayout { dropAreaWrapper.setDropHandler(new DropAreahandler()); setSizeFull(); setSpacing(true); + } + private void restoreState() { + if (artifactUploadState.isStatusPopupMinimized()) { + showUploadStatusButton(); + setUploadStatusButtonIconToFinished(); + } } public DragAndDropWrapper getDropAreaWrapper() { @@ -324,8 +336,8 @@ public class UploadLayout extends VerticalLayout { final SoftwareModule selectedSoftwareModule = artifactUploadState.getSelectedBaseSoftwareModule().get(); - final String currentBaseSoftwareModuleKey = HawkbitCommonUtil - .getFormattedNameVersion(selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion()); + final String currentBaseSoftwareModuleKey = HawkbitCommonUtil.getFormattedNameVersion( + selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion()); final CustomFile customFile = new CustomFile(name, size, tempFile.getAbsolutePath(), selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion(), mimeType); @@ -403,8 +415,8 @@ public class UploadLayout extends VerticalLayout { public Boolean checkIfFileIsDuplicate(final String name) { Boolean isDuplicate = false; final SoftwareModule selectedSoftwareModule = artifactUploadState.getSelectedBaseSoftwareModule().get(); - final String currentBaseSoftwareModuleKey = HawkbitCommonUtil - .getFormattedNameVersion(selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion()); + final String currentBaseSoftwareModuleKey = HawkbitCommonUtil.getFormattedNameVersion( + selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion()); for (final CustomFile customFile : artifactUploadState.getFileSelected()) { final String fileSoftwareModuleKey = HawkbitCommonUtil.getFormattedNameVersion( @@ -469,8 +481,8 @@ public class UploadLayout extends VerticalLayout { void updateFileSize(final String name, final long size) { final SoftwareModule selectedSoftwareModule = artifactUploadState.getSelectedBaseSoftwareModule().get(); - final String currentBaseSoftwareModuleKey = HawkbitCommonUtil - .getFormattedNameVersion(selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion()); + final String currentBaseSoftwareModuleKey = HawkbitCommonUtil.getFormattedNameVersion( + selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion()); for (final CustomFile customFile : artifactUploadState.getFileSelected()) { final String fileSoftwareModuleKey = HawkbitCommonUtil.getFormattedNameVersion( @@ -507,9 +519,10 @@ public class UploadLayout extends VerticalLayout { if (event.getButton().equals(discardBtn)) { if (artifactUploadState.getFileSelected().isEmpty()) { uiNotification.displayValidationError(i18n.get("message.error.noFileSelected")); - } else { clearFileList(); + uploadInfoWindow.clearWindow(); + hideUploadStatusButton(); } } } @@ -536,12 +549,12 @@ public class UploadLayout extends VerticalLayout { private void setConfirmationPopupHeightWidth(final float newWidth, final float newHeight) { if (currentUploadConfirmationwindow != null) { - currentUploadConfirmationwindow.getUploadArtifactDetails().setWidth(HawkbitCommonUtil - .getArtifactUploadPopupWidth(newWidth, SPUIDefinitions.MIN_UPLOAD_CONFIRMATION_POPUP_WIDTH), - Unit.PIXELS); - currentUploadConfirmationwindow.getUploadDetailsTable().setHeight(HawkbitCommonUtil - .getArtifactUploadPopupHeight(newHeight, SPUIDefinitions.MIN_UPLOAD_CONFIRMATION_POPUP_HEIGHT), - Unit.PIXELS); + currentUploadConfirmationwindow.getUploadArtifactDetails().setWidth( + HawkbitCommonUtil.getArtifactUploadPopupWidth(newWidth, + SPUIDefinitions.MIN_UPLOAD_CONFIRMATION_POPUP_WIDTH), Unit.PIXELS); + currentUploadConfirmationwindow.getUploadDetailsTable().setHeight( + HawkbitCommonUtil.getArtifactUploadPopupHeight(newHeight, + SPUIDefinitions.MIN_UPLOAD_CONFIRMATION_POPUP_HEIGHT), Unit.PIXELS); } } @@ -558,10 +571,12 @@ public class UploadLayout extends VerticalLayout { && currentUploadConfirmationwindow.getCurrentUploadResultWindow() != null) { final UploadResultWindow uploadResultWindow = currentUploadConfirmationwindow .getCurrentUploadResultWindow(); - uploadResultWindow.getUploadResultsWindow().setWidth(HawkbitCommonUtil.getArtifactUploadPopupWidth(newWidth, - SPUIDefinitions.MIN_UPLOAD_CONFIRMATION_POPUP_WIDTH), Unit.PIXELS); - uploadResultWindow.getUploadResultTable().setHeight(HawkbitCommonUtil.getArtifactUploadPopupHeight( - newHeight, SPUIDefinitions.MIN_UPLOAD_CONFIRMATION_POPUP_HEIGHT), Unit.PIXELS); + uploadResultWindow.getUploadResultsWindow().setWidth( + HawkbitCommonUtil.getArtifactUploadPopupWidth(newWidth, + SPUIDefinitions.MIN_UPLOAD_CONFIRMATION_POPUP_WIDTH), Unit.PIXELS); + uploadResultWindow.getUploadResultTable().setHeight( + HawkbitCommonUtil.getArtifactUploadPopupHeight(newHeight, + SPUIDefinitions.MIN_UPLOAD_CONFIRMATION_POPUP_HEIGHT), Unit.PIXELS); } } @@ -572,8 +587,8 @@ public class UploadLayout extends VerticalLayout { } else { currentUploadConfirmationwindow = new UploadConfirmationwindow(this, artifactUploadState); UI.getCurrent().addWindow(currentUploadConfirmationwindow.getUploadConfrimationWindow()); - setConfirmationPopupHeightWidth(Page.getCurrent().getBrowserWindowWidth(), - Page.getCurrent().getBrowserWindowHeight()); + setConfirmationPopupHeightWidth(Page.getCurrent().getBrowserWindowWidth(), Page.getCurrent() + .getBrowserWindowHeight()); } } } @@ -608,7 +623,20 @@ public class UploadLayout extends VerticalLayout { void onEvent(final UploadArtifactUIEvent event) { if (event == UploadArtifactUIEvent.DELETED_ALL_SOFWARE) { ui.access(() -> updateActionCount()); + } else if (event == UploadArtifactUIEvent.MINIMIZED_STATUS_POPUP) { + ui.access(() -> showUploadStatusButton()); + } else if (event == UploadArtifactUIEvent.MAXIMIZED_STATUS_POPUP) { + ui.access(() -> maximizeStatusPopup()); + } else if (event == UploadArtifactUIEvent.UPLOAD_FINISHED) { + ui.access(() -> setUploadStatusButtonIconToFinished()); + } else if (event == UploadArtifactUIEvent.UPLOAD_STARTED) { + ui.access(() -> setUploadStatusButtonIconToInProgress()); + }else if (event == UploadArtifactUIEvent.UPLOAD_STREAMINING_FINISHED) { + //TODO re-check + updateActionCount(); + enableProcessBtn(); } + } @PreDestroy @@ -637,8 +665,8 @@ public class UploadLayout extends VerticalLayout { * @param selectedBaseSoftwareModule */ public void refreshArtifactDetailsLayout(final SoftwareModule selectedBaseSoftwareModule) { - eventBus.publish(this, - new SoftwareModuleEvent(SoftwareModuleEventType.ARTIFACTS_CHANGED, selectedBaseSoftwareModule)); + eventBus.publish(this, new SoftwareModuleEvent(SoftwareModuleEventType.ARTIFACTS_CHANGED, + selectedBaseSoftwareModule)); } /** @@ -655,4 +683,55 @@ public class UploadLayout extends VerticalLayout { public void setHasDirectory(final Boolean hasDirectory) { this.hasDirectory = hasDirectory; } + + private void createUploadStatusButton() { + uploadStatusButton = SPUIComponentProvider.getButton(SPUIComponetIdProvider.UPLOAD_STATUS_BUTTON, "", "", "", + false, null, SPUIButtonStyleSmall.class); + uploadStatusButton.setStyleName(SPUIStyleDefinitions.ACTION_BUTTON); + uploadStatusButton.addStyleName(SPUIStyleDefinitions.UPLOAD_PROGRESS_INDICATOR_STYLE); + uploadStatusButton.setWidth("100px"); + uploadStatusButton.setHtmlContentAllowed(true); + uploadStatusButton.addClickListener(event -> onClickOfUploadStatusButton()); + uploadStatusButton.setVisible(false); + } + + private void onClickOfUploadStatusButton() { + artifactUploadState.setStatusPopupMinimized(false); + eventBus.publish(this, UploadArtifactUIEvent.MAXIMIZED_STATUS_POPUP); + } + + private void showUploadStatusButton() { + if (uploadStatusButton == null) { + return; + } + uploadStatusButton.setVisible(true); + } + + private void hideUploadStatusButton() { + if (uploadStatusButton == null) { + return; + } + uploadStatusButton.setVisible(false); + } + + private void maximizeStatusPopup() { + hideUploadStatusButton(); + uploadInfoWindow.maximizeStatusPopup(); + } + + private void setUploadStatusButtonIconToFinished() { + if (uploadStatusButton == null) { + return; + } + uploadStatusButton.removeStyleName(SPUIStyleDefinitions.UPLOAD_PROGRESS_INDICATOR_STYLE); + uploadStatusButton.setIcon(FontAwesome.UPLOAD); + } + + private void setUploadStatusButtonIconToInProgress() { + if (uploadStatusButton == null) { + return; + } + uploadStatusButton.addStyleName(SPUIStyleDefinitions.UPLOAD_PROGRESS_INDICATOR_STYLE); + uploadStatusButton.setIcon(null); + } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusInfoWindow.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusInfoWindow.java index 8b36ef39e..4693ab3dc 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusInfoWindow.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusInfoWindow.java @@ -8,20 +8,37 @@ */ package org.eclipse.hawkbit.ui.artifacts.upload; -import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; +import java.util.List; +import java.util.stream.Collectors; +import org.eclipse.hawkbit.ui.artifacts.event.UploadArtifactUIEvent; +import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState; +import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; +import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; +import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; +import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; +import org.springframework.beans.factory.annotation.Autowired; +import org.vaadin.spring.events.EventBus; + +import com.vaadin.data.Container.Indexed; import com.vaadin.data.Item; import com.vaadin.data.util.IndexedContainer; import com.vaadin.server.FontAwesome; import com.vaadin.shared.ui.window.WindowMode; import com.vaadin.spring.annotation.SpringComponent; import com.vaadin.spring.annotation.ViewScope; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.Grid; import com.vaadin.ui.Grid.SelectionMode; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.Label; import com.vaadin.ui.UI; +import com.vaadin.ui.VerticalLayout; import com.vaadin.ui.Window; import com.vaadin.ui.renderers.HtmlRenderer; import com.vaadin.ui.renderers.ProgressBarRenderer; +import com.vaadin.ui.themes.ValoTheme; import elemental.json.JsonValue; @@ -34,7 +51,13 @@ import elemental.json.JsonValue; @ViewScope @SpringComponent -public class UploadStatusInfoWindow extends Window implements Window.CloseListener, Window.WindowModeChangeListener { +public class UploadStatusInfoWindow extends Window { + + @Autowired + private transient EventBus.SessionEventBus eventBus; + + @Autowired + private ArtifactUploadState artifactUploadState; private static final String PROGRESS = "Progress"; @@ -52,39 +75,105 @@ public class UploadStatusInfoWindow extends Window implements Window.CloseListen private volatile boolean errorOccured = false; + private Button minimizeButton; + + private VerticalLayout mainLayout; + + private Label windowCaption; + + private Button closeButton; + + private Button resizeButton; + /** * Default Constructor. */ UploadStatusInfoWindow() { - super("Upload Status"); + super(); - addStyleName(SPUIStyleDefinitions.UPLOAD_INFO); - center(); - setImmediate(true); - setResizable(true); - setDraggable(true); - setClosable(true); - uploads = new IndexedContainer(); - uploads.addContainerProperty(STATUS, String.class, "Active"); - uploads.addContainerProperty(FILE_NAME, String.class, null); - uploads.addContainerProperty(PROGRESS, Double.class, 0D); - uploads.addContainerProperty(REASON, String.class, ""); + setPopupProperties(); + createStatusPopupHeaderComponents(); - grid = new Grid(uploads); - grid.addStyleName(SPUIStyleDefinitions.UPLOAD_STATUS_GRID); - grid.setSelectionMode(SelectionMode.NONE); - grid.getColumn(STATUS).setRenderer(new StatusRenderer()); - grid.getColumn(PROGRESS).setRenderer(new ProgressBarRenderer()); - setColumnWidth(); - grid.setFrozenColumnCount(4); - grid.setColumnOrder(STATUS, PROGRESS, FILE_NAME, REASON); - grid.setHeaderVisible(true); - grid.setImmediate(true); + mainLayout = new VerticalLayout(); + mainLayout.setSpacing(Boolean.TRUE); + mainLayout.setSizeUndefined(); setPopupSizeInMinMode(); - setContent(grid); - addCloseListener(this); - addWindowModeChangeListener(this); + uploads = getGridContainer(); + grid = createGrid(); + setGridColumnProperties(); + + mainLayout.addComponents(getCaptionLayout(), grid); + mainLayout.setExpandRatio(grid, 1.0F); + setContent(mainLayout); + } + + private void restoreState() { + Indexed container = grid.getContainerDataSource(); + if (container.getItemIds().isEmpty()) { + container.removeAllItems(); + for (UploadStatusObject statusObject : artifactUploadState.getUploadedFileStatusList()) { + Item item = container.addItem(statusObject.getFilename()); + item.getItemProperty(REASON).setValue(statusObject.getReason() != null ? statusObject.getReason() : ""); + item.getItemProperty(STATUS).setValue(statusObject.getStatus()); + item.getItemProperty(PROGRESS).setValue(statusObject.getProgress()); + item.getItemProperty(FILE_NAME).setValue(statusObject.getFilename()); + } + artifactUploadState.setUploadCompleted(true); + minimizeButton.setEnabled(false); + } + } + + private void setPopupProperties() { + addStyleName(SPUIStyleDefinitions.UPLOAD_INFO); + setImmediate(true); + setResizable(false); + setDraggable(true); + setClosable(false); + } + + private void setGridColumnProperties() { + grid.getColumn(STATUS).setRenderer(new StatusRenderer()); + grid.getColumn(PROGRESS).setRenderer(new ProgressBarRenderer()); + grid.setColumnOrder(STATUS, PROGRESS, FILE_NAME, REASON); + setColumnWidth(); + grid.setFrozenColumnCount(4); + } + + private Grid createGrid() { + Grid statusGrid = new Grid(uploads); + statusGrid.addStyleName(SPUIStyleDefinitions.UPLOAD_STATUS_GRID); + statusGrid.setSelectionMode(SelectionMode.NONE); + statusGrid.setHeaderVisible(true); + statusGrid.setImmediate(true); + statusGrid.setSizeFull(); + return statusGrid; + } + + private IndexedContainer getGridContainer() { + IndexedContainer uploadContainer = new IndexedContainer(); + uploadContainer.addContainerProperty(STATUS, String.class, "Active"); + uploadContainer.addContainerProperty(FILE_NAME, String.class, null); + uploadContainer.addContainerProperty(PROGRESS, Double.class, 0D); + uploadContainer.addContainerProperty(REASON, String.class, ""); + return uploadContainer; + } + + private HorizontalLayout getCaptionLayout() { + final HorizontalLayout captionLayout = new HorizontalLayout(); + captionLayout.setSizeFull(); + captionLayout.setHeight("36px"); + captionLayout.addComponents(windowCaption, minimizeButton, resizeButton, closeButton); + captionLayout.setExpandRatio(windowCaption, 1.0F); + captionLayout.addStyleName("v-window-header"); + return captionLayout; + } + + private void createStatusPopupHeaderComponents() { + minimizeButton = getMinimizeButton(); + windowCaption = new Label("Upload status"); + closeButton = getCloseButton(); + resizeButton = getResizeButton(); } private void setColumnWidth() { @@ -99,15 +188,13 @@ public class UploadStatusInfoWindow extends Window implements Window.CloseListen grid.getColumn(PROGRESS).setWidthUndefined(); grid.getColumn(FILE_NAME).setWidthUndefined(); grid.getColumn(REASON).setWidthUndefined(); - } private static class StatusRenderer extends HtmlRenderer { @Override public JsonValue encode(final String value) { - - String result = ""; + String result ; switch (value) { case "Finished": result = "
" + FontAwesome.CHECK_CIRCLE.getHtml() + "
"; @@ -129,28 +216,52 @@ public class UploadStatusInfoWindow extends Window implements Window.CloseListen void uploadSessionFinished() { if (!errorOccured) { close(); + eventBus.publish(this, UploadArtifactUIEvent.UPLOAD_FINISHED); + artifactUploadState.setUploadCompleted(true); + minimizeButton.setEnabled(false); } } void uploadSessionStarted() { close(); + openWindow(); + minimizeButton.setEnabled(true); + eventBus.publish(this, UploadArtifactUIEvent.UPLOAD_STARTED); + artifactUploadState.setUploadCompleted(false); + } + + void openWindow() { UI.getCurrent().addWindow(this); center(); } + void maximizeStatusPopup() { + openWindow(); + restoreState(); + } + void uploadStarted(final String filename) { final Item item = uploads.addItem(filename); item.getItemProperty(FILE_NAME).setValue(filename); grid.scrollToEnd(); - + UploadStatusObject uploadStatus = new UploadStatusObject(filename); + uploadStatus.setStatus("Active"); + artifactUploadState.getUploadedFileStatusList().add(uploadStatus); } void updateProgress(final String filename, final long readBytes, final long contentLength) { final Item item = uploads.getItem(filename); if (item != null) { - item.getItemProperty(PROGRESS).setValue((double) readBytes / (double) contentLength); - + double progress = (double) readBytes / (double) contentLength; + item.getItemProperty(PROGRESS).setValue(progress); + List uploadStatusObjectList = (List) artifactUploadState + .getUploadedFileStatusList().stream().filter(e -> e.getFilename().equals(filename)) + .collect(Collectors.toList()); + if (!uploadStatusObjectList.isEmpty()) { + UploadStatusObject uploadStatusObject = uploadStatusObjectList.get(0); + uploadStatusObject.setProgress(progress); + } } } @@ -163,8 +274,15 @@ public class UploadStatusInfoWindow extends Window implements Window.CloseListen public void uploadSucceeded(final String filename) { final Item item = uploads.getItem(filename); if (item != null) { - item.getItemProperty(STATUS).setValue("Finished"); - + String status = "Finished"; + item.getItemProperty(STATUS).setValue(status); + List uploadStatusObjectList = (List) artifactUploadState + .getUploadedFileStatusList().stream().filter(e -> e.getFilename().equals(filename)) + .collect(Collectors.toList()); + if (!uploadStatusObjectList.isEmpty()) { + UploadStatusObject uploadStatusObject = uploadStatusObjectList.get(0); + uploadStatusObject.setStatus(status); + } } } @@ -175,51 +293,81 @@ public class UploadStatusInfoWindow extends Window implements Window.CloseListen errorOccured = true; } item.getItemProperty(REASON).setValue(errorReason); - item.getItemProperty(STATUS).setValue("Failed"); - + String status = "Failed"; + item.getItemProperty(STATUS).setValue(status); + List uploadStatusObjectList = (List) artifactUploadState + .getUploadedFileStatusList().stream().filter(e -> e.getFilename().equals(filename)) + .collect(Collectors.toList()); + if (!uploadStatusObjectList.isEmpty()) { + UploadStatusObject uploadStatusObject = uploadStatusObjectList.get(0); + uploadStatusObject.setStatus(status); + uploadStatusObject.setReason(errorReason); + } } } - /* - * (non-Javadoc) - * - * @see com.vaadin.ui.Window.CloseListener#windowClose(com.vaadin.ui.Window. - * CloseEvent) - */ - @Override - public void windowClose(final CloseEvent e) { - clearWindow(); - } - - private void clearWindow() { + protected void clearWindow() { errorOccured = false; uploads.removeAllItems(); setWindowMode(WindowMode.NORMAL); + this.close(); + artifactUploadState.getUploadedFileStatusList().clear(); } - /* - * (non-Javadoc) - * - * @see com.vaadin.ui.Window.WindowModeChangeListener#windowModeChanged(com. - * vaadin.ui.Window. WindowModeChangeEvent) - */ - @Override - public void windowModeChanged(final WindowModeChangeEvent event) { - if (event.getWindow().getWindowMode() == WindowMode.MAXIMIZED) { + private void setPopupSizeInMinMode() { + mainLayout.setWidth(800, Unit.PIXELS); + mainLayout.setHeight(510, Unit.PIXELS); + } + + private Button getMinimizeButton() { + final Button minimizeBtn = SPUIComponentProvider.getButton( + SPUIComponetIdProvider.UPLOAD_STATUS_POPUP_MINIMIZE_BUTTON_ID, "", "", "", true, FontAwesome.MINUS, + SPUIButtonStyleSmallNoBorder.class); + minimizeBtn.addStyleName(ValoTheme.BUTTON_BORDERLESS); + minimizeBtn.addClickListener(event -> minimizeWindow()); + minimizeBtn.setEnabled(true); + return minimizeBtn; + } + + private Button getResizeButton() { + final Button resizeBtn = SPUIComponentProvider.getButton( + SPUIComponetIdProvider.UPLOAD_STATUS_POPUP_RESIZE_BUTTON_ID, "", "", "", true, FontAwesome.EXPAND, + SPUIButtonStyleSmallNoBorder.class); + resizeBtn.addStyleName(ValoTheme.BUTTON_BORDERLESS); + resizeBtn.addClickListener(event -> resizeWindow(event)); + return resizeBtn; + } + + private void resizeWindow(ClickEvent event) { + if (event.getButton().getIcon() == FontAwesome.EXPAND) { + event.getButton().setIcon(FontAwesome.COMPRESS); + setWindowMode(WindowMode.MAXIMIZED); resetColumnWidth(); grid.getColumn(STATUS).setExpandRatio(0); grid.getColumn(PROGRESS).setExpandRatio(1); grid.getColumn(FILE_NAME).setExpandRatio(2); grid.getColumn(REASON).setExpandRatio(3); - grid.setSizeFull(); + mainLayout.setSizeFull(); } else { + event.getButton().setIcon(FontAwesome.EXPAND); + setWindowMode(WindowMode.NORMAL); setColumnWidth(); setPopupSizeInMinMode(); } } - private void setPopupSizeInMinMode() { - grid.setWidth(800, Unit.PIXELS); - grid.setHeight(510, Unit.PIXELS); + private void minimizeWindow() { + this.close(); + artifactUploadState.setStatusPopupMinimized(true); + eventBus.publish(this, UploadArtifactUIEvent.MINIMIZED_STATUS_POPUP); + } + + private Button getCloseButton() { + final Button closeBtn = SPUIComponentProvider.getButton( + SPUIComponetIdProvider.UPLOAD_STATUS_POPUP_CLOSE_BUTTON_ID, "", "", "", true, FontAwesome.TIMES, + SPUIButtonStyleSmallNoBorder.class); + closeBtn.addStyleName(ValoTheme.BUTTON_BORDERLESS); + closeBtn.addClickListener(event -> clearWindow()); + return closeBtn; } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusObject.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusObject.java new file mode 100644 index 000000000..80c71fe7b --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusObject.java @@ -0,0 +1,71 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.ui.artifacts.upload; + +public class UploadStatusObject { + private String status; + private Double progress; + private String filename; + private String reason; + + public UploadStatusObject(String status, Double progress, String fileName, String reason) { + this(fileName); + this.status = status; + this.progress = progress; + this.reason = reason; + } + + public UploadStatusObject(String fileName) { + this.filename = fileName; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public Double getProgress() { + return progress; + } + + public void setProgress(Double progress) { + this.progress = progress; + } + + public String getFilename() { + return filename; + } + + public void setFilename(String filename) { + this.filename = filename; + } + + public String getReason() { + return reason; + } + + public void setReason(String reason) { + this.reason = reason; + } + + @Override + public boolean equals(Object obj) { + if (this == null || obj == null) { + return false; + } + if (obj instanceof UploadStatusObject && this.getFilename() == ((UploadStatusObject) obj).getFilename()) { + return true; + } + return false; + } + +} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/footer/AbstractDeleteActionsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/footer/AbstractDeleteActionsLayout.java index 75bd43447..09ab92cee 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/footer/AbstractDeleteActionsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/footer/AbstractDeleteActionsLayout.java @@ -130,7 +130,7 @@ public abstract class AbstractDeleteActionsLayout extends VerticalLayout impleme addComponent(hLayout); setComponentAlignment(hLayout, Alignment.BOTTOM_CENTER); } - setStyleName("footer-layout"); + setStyleName(SPUIStyleDefinitions.FOOTER_LAYOUT); setWidth("100%"); } @@ -168,7 +168,7 @@ public abstract class AbstractDeleteActionsLayout extends VerticalLayout impleme final Button button = SPUIComponentProvider.getButton(SPUIComponetIdProvider.BULK_UPLOAD_STATUS_BUTTON, "", "", "", false, null, SPUIButtonStyleSmall.class); button.setStyleName(SPUIStyleDefinitions.ACTION_BUTTON); - button.addStyleName(SPUIStyleDefinitions.BULK_UPLOAD_PROGRESS_INDICATOR_STYLE); + button.addStyleName(SPUIStyleDefinitions.UPLOAD_PROGRESS_INDICATOR_STYLE); button.setWidth("100px"); button.setHtmlContentAllowed(true); button.addClickListener(event -> onClickBulkUploadNotificationButton()); @@ -199,7 +199,7 @@ public abstract class AbstractDeleteActionsLayout extends VerticalLayout impleme if (bulkUploadStatusButton == null) { return; } - bulkUploadStatusButton.removeStyleName(SPUIStyleDefinitions.BULK_UPLOAD_PROGRESS_INDICATOR_STYLE); + bulkUploadStatusButton.removeStyleName(SPUIStyleDefinitions.UPLOAD_PROGRESS_INDICATOR_STYLE); bulkUploadStatusButton.setIcon(FontAwesome.UPLOAD); } @@ -207,7 +207,7 @@ public abstract class AbstractDeleteActionsLayout extends VerticalLayout impleme if (bulkUploadStatusButton == null) { return; } - bulkUploadStatusButton.addStyleName(SPUIStyleDefinitions.BULK_UPLOAD_PROGRESS_INDICATOR_STYLE); + bulkUploadStatusButton.addStyleName(SPUIStyleDefinitions.UPLOAD_PROGRESS_INDICATOR_STYLE); bulkUploadStatusButton.setIcon(null); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/grid/AbstractGridLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/grid/AbstractGridLayout.java index 98c14e698..308bbeec4 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/grid/AbstractGridLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/grid/AbstractGridLayout.java @@ -9,6 +9,7 @@ package org.eclipse.hawkbit.ui.common.grid; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; +import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; import com.vaadin.ui.Alignment; import com.vaadin.ui.HorizontalLayout; @@ -72,7 +73,7 @@ public abstract class AbstractGridLayout extends VerticalLayout { final Label countMessageLabel = getCountMessageLabel(); countMessageLabel.setId(SPUIComponetIdProvider.ROLLOUT_GROUP_TARGET_LABEL); rolloutGroupTargetsCountLayout.addComponent(getCountMessageLabel()); - rolloutGroupTargetsCountLayout.setStyleName("footer-layout"); + rolloutGroupTargetsCountLayout.setStyleName(SPUIStyleDefinitions.FOOTER_LAYOUT); rolloutGroupTargetsCountLayout.setWidth("100%"); return rolloutGroupTargetsCountLayout; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/FilterManagementView.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/FilterManagementView.java index 06cbe4d69..99c586070 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/FilterManagementView.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/FilterManagementView.java @@ -14,6 +14,7 @@ import org.eclipse.hawkbit.ui.HawkbitUI; import org.eclipse.hawkbit.ui.filtermanagement.event.CustomFilterUIEvent; import org.eclipse.hawkbit.ui.filtermanagement.footer.TargetFilterCountMessageLabel; import org.eclipse.hawkbit.ui.filtermanagement.state.FilterManagementUIState; +import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; import org.springframework.beans.factory.annotation.Autowired; import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventScope; @@ -151,7 +152,7 @@ public class FilterManagementView extends VerticalLayout implements View { private HorizontalLayout addTargetFilterMessageLabel() { final HorizontalLayout messageLabelLayout = new HorizontalLayout(); messageLabelLayout.addComponent(targetFilterCountMessageLabel); - messageLabelLayout.addStyleName("footer-layout"); + messageLabelLayout.addStyleName(SPUIStyleDefinitions.FOOTER_LAYOUT); return messageLabelLayout; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIComponetIdProvider.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIComponetIdProvider.java index 48e501e1d..7c25bf90a 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIComponetIdProvider.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIComponetIdProvider.java @@ -883,6 +883,27 @@ public final class SPUIComponetIdProvider { */ public static final String VALIDATION_STATUS_ICON_ID = "validation.status.icon"; + /** + * Artifact upload status popup - minimize button id. + */ + public static final String UPLOAD_STATUS_POPUP_MINIMIZE_BUTTON_ID = "artifact.upload.minimize.button.id"; + + /** + * Artifact upload status popup - close button id. + */ + public static final String UPLOAD_STATUS_POPUP_CLOSE_BUTTON_ID = "artifact.upload.close.button.id"; + + /** + * Artifact upload status popup - resize button id. + */ + public static final String UPLOAD_STATUS_POPUP_RESIZE_BUTTON_ID = "artifact.upload.resize.button.id"; + + /** + * Artifact upload view - upload status button id. + */ + public static final String UPLOAD_STATUS_BUTTON = "artficat.upload.status.button.id"; + + /** * /* Private Constructor. */ diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIStyleDefinitions.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIStyleDefinitions.java index c50135251..ac713a07c 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIStyleDefinitions.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIStyleDefinitions.java @@ -240,9 +240,9 @@ public final class SPUIStyleDefinitions { public static final String DISABLE_ACTION_TYPE_LAYOUT = "disable-action-type-layout"; /** - * Bulk upload progress indicator style. + * Upload progress indicator style. */ - public static final String BULK_UPLOAD_PROGRESS_INDICATOR_STYLE = "app-loading"; + public static final String UPLOAD_PROGRESS_INDICATOR_STYLE = "app-loading"; /** * Target filter search progress indicator style. @@ -293,6 +293,11 @@ public final class SPUIStyleDefinitions { * Status pending icon. */ public static final String STATUS_ICON_PENDING = "statusIconPending"; + + /** + * Footer layout style. + */ + public static final String FOOTER_LAYOUT = "footer-layout"; /** * Constructor. From 68ab2eb30e71f404c8caadd4c47f7e6bce09e788 Mon Sep 17 00:00:00 2001 From: Asharani Date: Fri, 6 May 2016 10:28:50 +0530 Subject: [PATCH 02/54] Set error message from exception Signed-off-by: Asharani --- .../hawkbit/ui/artifacts/upload/UploadHandler.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java index 976d5ac27..c48dac834 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java @@ -333,8 +333,12 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene final SoftwareModule sw = view.getSoftwareModuleSelected(); view.getFileSelected().remove(new CustomFile(fileName, sw.getName(), sw.getVersion())); } - view.updateActionCount(); - infoWindow.uploadFailed(event.getFilename(), failureReason); + eventBus.publish(this, UploadArtifactUIEvent.UPLOAD_STREAMINING_FINISHED); + if (failureReason != null) { + infoWindow.uploadFailed(event.getFilename(), failureReason); + } else { + infoWindow.uploadFailed(event.getFilename(), event.getReason().getMessage()); + } LOG.info("Upload failed for file :{}", event.getReason()); } From 887536b2b79561724e3cf7817fff739b7df650d7 Mon Sep 17 00:00:00 2001 From: Asharani Date: Mon, 9 May 2016 10:42:23 +0530 Subject: [PATCH 03/54] Upload confirmation popup - on discard remove the upload status button Signed-off-by: Asharani --- .../artifacts/upload/UploadConfirmationwindow.java | 2 +- .../hawkbit/ui/artifacts/upload/UploadLayout.java | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadConfirmationwindow.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadConfirmationwindow.java index f009985f9..d7231cafe 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadConfirmationwindow.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadConfirmationwindow.java @@ -544,7 +544,7 @@ public class UploadConfirmationwindow implements Button.ClickListener { if (event.getComponent().getId().equals(SPUIComponetIdProvider.UPLOAD_ARTIFACT_DETAILS_CLOSE)) { uploadConfrimationWindow.close(); } else if (event.getComponent().getId().equals(SPUIComponetIdProvider.UPLOAD_DISCARD_DETAILS_BUTTON)) { - uploadLayout.clearFileList(); + uploadLayout.removeUploadedFileDetails(); uploadConfrimationWindow.close(); } else if (event.getComponent().getId().equals(SPUIComponetIdProvider.UPLOAD_BUTTON)) { processArtifactUpload(); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java index 340f66287..9e304efe8 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java @@ -520,13 +520,17 @@ public class UploadLayout extends VerticalLayout { if (artifactUploadState.getFileSelected().isEmpty()) { uiNotification.displayValidationError(i18n.get("message.error.noFileSelected")); } else { - clearFileList(); - uploadInfoWindow.clearWindow(); - hideUploadStatusButton(); + removeUploadedFileDetails(); } } } + protected void removeUploadedFileDetails() { + clearFileList(); + uploadInfoWindow.clearWindow(); + hideUploadStatusButton(); + } + /** * Clear details. */ @@ -707,7 +711,7 @@ public class UploadLayout extends VerticalLayout { uploadStatusButton.setVisible(true); } - private void hideUploadStatusButton() { + protected void hideUploadStatusButton() { if (uploadStatusButton == null) { return; } From 8fc1f74f807bbc3c7edd33bb734502c49b746bd0 Mon Sep 17 00:00:00 2001 From: Asharani Date: Thu, 12 May 2016 15:16:41 +0530 Subject: [PATCH 04/54] Refactored UploadHandler.java to update upload status using eventing Signed-off-by: Asharani --- hawkbit-ui/pom.xml | 5 + .../event/UploadArtifactUIEvent.java | 2 +- .../ui/artifacts/event/UploadFileStatus.java | 60 ++++++ .../ui/artifacts/event/UploadStatusEvent.java | 34 ++++ .../artifacts/state/ArtifactUploadState.java | 14 ++ .../ui/artifacts/upload/UploadHandler.java | 152 +++++---------- .../ui/artifacts/upload/UploadLayout.java | 183 +++++++++++++----- .../upload/UploadStatusInfoWindow.java | 102 +++++++--- 8 files changed, 374 insertions(+), 178 deletions(-) create mode 100644 hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadFileStatus.java create mode 100644 hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadStatusEvent.java diff --git a/hawkbit-ui/pom.xml b/hawkbit-ui/pom.xml index e0bde576a..38b455367 100644 --- a/hawkbit-ui/pom.xml +++ b/hawkbit-ui/pom.xml @@ -254,5 +254,10 @@ allure-junit-adaptor test + + org.scala-lang + scala-library + 2.10.4 + \ No newline at end of file diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadArtifactUIEvent.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadArtifactUIEvent.java index de8f5867b..8bd33f483 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadArtifactUIEvent.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadArtifactUIEvent.java @@ -16,5 +16,5 @@ package org.eclipse.hawkbit.ui.artifacts.event; */ public enum UploadArtifactUIEvent { - SHOW_DROP_HINTS, HIDE_DROP_HINTS, SOFTWARE_DRAG_START, SOFTWARE_TYPE_DRAG_START, UPDATE_UPLOAD_COUNT, ENABLE_PROCESS_BUTTON, HIDE_FILTER_BY_TYPE, SHOW_FILTER_BY_TYPE, DISCARD_DELETE_SOFTWARE, DISCARD_ALL_DELETE_SOFTWARE, DELETED_ALL_SOFWARE, DISABLE_PROCESS_BUTTON, DISCARD_DELETE_SOFTWARE_TYPE, DISCARD_ALL_DELETE_SOFTWARE_TYPE, DELETED_ALL_SOFWARE_TYPE,MINIMIZED_STATUS_POPUP,MAXIMIZED_STATUS_POPUP,UPLOAD_FINISHED,UPLOAD_STARTED, UPLOAD_STREAMINING_FINISHED + SHOW_DROP_HINTS, HIDE_DROP_HINTS, SOFTWARE_DRAG_START, SOFTWARE_TYPE_DRAG_START, UPDATE_UPLOAD_COUNT, ENABLE_PROCESS_BUTTON, HIDE_FILTER_BY_TYPE, SHOW_FILTER_BY_TYPE, DISCARD_DELETE_SOFTWARE, DISCARD_ALL_DELETE_SOFTWARE, DELETED_ALL_SOFWARE, DISABLE_PROCESS_BUTTON, DISCARD_DELETE_SOFTWARE_TYPE, DISCARD_ALL_DELETE_SOFTWARE_TYPE, DELETED_ALL_SOFWARE_TYPE,MINIMIZED_STATUS_POPUP,MAXIMIZED_STATUS_POPUP, UPLOAD_IN_PROGESS } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadFileStatus.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadFileStatus.java new file mode 100644 index 000000000..776556464 --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadFileStatus.java @@ -0,0 +1,60 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.ui.artifacts.event; + +import java.io.Serializable; + +/** + * + * Holds file and upload status details. + * + */ +public class UploadFileStatus implements Serializable { + + private static final long serialVersionUID = -3599629192216760811L; + + private String fileName; + + private long contentLength; + + private long bytesRead; + + private String failureReason; + + public UploadFileStatus(String fileName){ + this.fileName = fileName; + } + + public UploadFileStatus(String fileName, long bytesRead, long contentLength) { + this.fileName = fileName; + this.contentLength = contentLength; + this.bytesRead = bytesRead; + } + + public UploadFileStatus(String fileName, String failureReason) { + this.failureReason = failureReason; + this.fileName = fileName; + } + + public String getFileName() { + return fileName; + } + + public long getContentLength() { + return contentLength; + } + + public long getBytesRead() { + return bytesRead; + } + + public String getFailureReason() { + return failureReason; + } +} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadStatusEvent.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadStatusEvent.java new file mode 100644 index 000000000..ab10c2e10 --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadStatusEvent.java @@ -0,0 +1,34 @@ +package org.eclipse.hawkbit.ui.artifacts.event; +/** + * + * Holds the upload file status. + * + */ +public class UploadStatusEvent { + + public enum UploadStatusEventType { + UPLOAD_FAILED, UPLOAD_IN_PROGRESS, UPLOAD_STARTED, UPLOAD_FINISHED, UPLOAD_SUCCESSFUL, UPLOAD_STREAMING_FAILED, UPLOAD_STREAMING_FINISHED + } + + private UploadStatusEventType uploadProgressEventType; + + private UploadFileStatus uploadStatus; + + public UploadStatusEvent(UploadStatusEventType eventType, UploadFileStatus entity) { + this.uploadProgressEventType = eventType; + this.uploadStatus = entity; + } + + public UploadFileStatus getUploadStatus() { + return uploadStatus; + } + + public void setUploadStatus(UploadFileStatus uploadStatus) { + this.uploadStatus = uploadStatus; + } + + public UploadStatusEventType getUploadProgressEventType() { + return uploadProgressEventType; + } + +} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/state/ArtifactUploadState.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/state/ArtifactUploadState.java index ae6a5860e..9c0ade8d1 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/state/ArtifactUploadState.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/state/ArtifactUploadState.java @@ -17,6 +17,7 @@ import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Set; +import java.util.concurrent.atomic.AtomicInteger; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.ui.artifacts.upload.UploadStatusObject; @@ -68,6 +69,19 @@ public class ArtifactUploadState implements ManagmentEntityState, Serializ private List uploadedFileStatusList = new ArrayList<>(); + private final AtomicInteger numberOfFileUploadsExpected = new AtomicInteger(); + + private final AtomicInteger numberOfFilesActuallyUpload = new AtomicInteger(); + + public AtomicInteger getNumberOfFilesActuallyUpload() { + return numberOfFilesActuallyUpload; + } + + public AtomicInteger getNumberOfFileUploadsExpected() { + return numberOfFileUploadsExpected; + } + + public List getUploadedFileStatusList() { return uploadedFileStatusList; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java index c48dac834..f9d207193 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java @@ -12,9 +12,10 @@ import java.io.IOException; import java.io.OutputStream; import org.eclipse.hawkbit.repository.exception.ArtifactUploadFailedException; -import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.ui.artifacts.event.UploadArtifactUIEvent; -import org.eclipse.hawkbit.ui.artifacts.state.CustomFile; +import org.eclipse.hawkbit.ui.artifacts.event.UploadFileStatus; +import org.eclipse.hawkbit.ui.artifacts.event.UploadStatusEvent; +import org.eclipse.hawkbit.ui.artifacts.event.UploadStatusEvent.UploadStatusEventType; import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SpringContextHelper; import org.slf4j.Logger; @@ -59,30 +60,29 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene private final long fileSize; private final UploadLayout view; - private final UploadStatusInfoWindow infoWindow; private final long maxSize; private final Upload upload; private volatile String fileName = null; private volatile String mimeType = null; - private volatile boolean interrupted = false; + private volatile boolean streamingInterrupted = false; + private volatile boolean uploadInterrupted = false; + private String failureReason; private final I18N i18n; private transient EventBus.SessionEventBus eventBus; - UploadHandler(final String fileName, final long fileSize, final UploadLayout view, - final UploadStatusInfoWindow infoWindow, final long maxSize, final Upload upload, final String mimeType) { + final long maxSize, final Upload upload, final String mimeType) { super(); this.fileName = fileName; this.fileSize = fileSize; this.view = view; - this.infoWindow = infoWindow; this.maxSize = maxSize; this.upload = upload; this.mimeType = mimeType; this.i18n = SpringContextHelper.getBean(I18N.class); - this.eventBus = SpringContextHelper.getBean(EventBus.SessionEventBus.class); + this.eventBus = SpringContextHelper.getBean(EventBus.SessionEventBus.class); } /** @@ -97,7 +97,7 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene } catch (final ArtifactUploadFailedException e) { LOG.error("Atifact upload failed {} ", e); failureReason = e.getMessage(); - interrupted = true; + streamingInterrupted = true; return new NullOutputStream(); } } @@ -112,7 +112,7 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene public OutputStream receiveUpload(final String fileName, final String mimeType) { this.fileName = fileName; this.mimeType = mimeType; - //reset has directory flag before upload + // reset has directory flag before upload view.setHasDirectory(false); try { if (view.checkIfSoftwareModuleIsSelected()) { @@ -127,6 +127,7 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene LOG.error("Atifact upload failed {} ", e); failureReason = e.getMessage(); upload.interruptUpload(); + uploadInterrupted = true; } // if final validation fails ,final no upload ,return NullOutputStream return new NullOutputStream(); @@ -141,13 +142,8 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene @Override public void uploadSucceeded(final SucceededEvent event) { LOG.debug("Streaming finished for file :{}", event.getFilename()); - view.updateFileSize(event.getFilename(), event.getLength()); - - // recorded that we now one more uploaded - view.increaseNumberOfFilesActuallyUpload(); - - // inform upload status window - infoWindow.uploadSucceeded(event.getFilename()); + eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_SUCCESSFUL, new UploadFileStatus( + event.getFilename(), 0, event.getLength()))); } /** @@ -160,20 +156,8 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene @Override public void streamingFinished(final StreamingEndEvent event) { LOG.debug("Streaming finished for file :{}", event.getFileName()); - // record that we now one more uploaded - view.increaseNumberOfFilesActuallyUpload(); - - // inform upload status window - infoWindow.uploadSucceeded(event.getFileName()); - - // check if we are finished - if (view.enableProcessBtn()) { - infoWindow.uploadSessionFinished(); - } - eventBus.publish(this, UploadArtifactUIEvent.UPLOAD_STREAMINING_FINISHED); - - // display the duplicate message after streaming all files - view.displayDuplicateValidationMessage(); + eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_STREAMING_FINISHED, + new UploadFileStatus(event.getFileName(), 0, event.getContentLength()))); } /** @@ -185,12 +169,8 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene @Override public void uploadFinished(final FinishedEvent event) { LOG.debug("Upload finished for file :{}", event.getFilename()); - // check if we are finished - if (view.enableProcessBtn()) { - infoWindow.uploadSessionFinished(); - } - view.updateActionCount(); - + eventBus.publish(this, + new UploadStatusEvent(UploadStatusEventType.UPLOAD_FINISHED, new UploadFileStatus(event.getFilename()))); } /** @@ -201,7 +181,8 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene @Override public void streamingStarted(final StreamingStartEvent event) { LOG.debug("Streaming started for file :{}", fileName); - infoWindow.uploadStarted(fileName); + eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_STARTED, new UploadFileStatus( + fileName, 0, 0))); } /** @@ -213,12 +194,14 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene public void uploadStarted(final StartedEvent event) { // single file session if (view.isSoftwareModuleSelected() && !view.checkIfFileIsDuplicate(event.getFilename())) { - infoWindow.uploadSessionStarted(); LOG.debug("Upload started for file :{}", event.getFilename()); - infoWindow.uploadStarted(event.getFilename()); + eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_STARTED, new UploadFileStatus( + event.getFilename(), 0, 0))); } else { failureReason = i18n.get("message.upload.failed"); upload.interruptUpload(); + // actual interrupt will happen a bit late so setting the below flag + uploadInterrupted = true; } } @@ -239,23 +222,21 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene */ @Override public void updateProgress(final long readBytes, final long contentLength) { - if (readBytes > maxSize || contentLength > maxSize) { - LOG.error("User tried to upload more than was allowed ({}).", maxSize); - - view.decreaseNumberOfFileUploadsExpected(); - final SoftwareModule sw = view.getSoftwareModuleSelected(); - view.getFileSelected().remove(new CustomFile(fileName, sw.getName(), sw.getVersion())); - view.updateActionCount(); - - failureReason = i18n.get("message.uploadedfile.size.exceeded", maxSize); - infoWindow.uploadFailed(fileName, failureReason); - upload.interruptUpload(); - interrupted = true; - return; + //Update progress is called event after upload interrupted in uploadStarted method + if (!uploadInterrupted) { + if (readBytes > maxSize || contentLength > maxSize) { + LOG.error("User tried to upload more than was allowed ({}).", maxSize); + failureReason = i18n.get("message.uploadedfile.size.exceeded", maxSize); + eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_FAILED, new UploadFileStatus( + fileName, failureReason))); + upload.interruptUpload(); + uploadInterrupted = true; + return; + } + eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_IN_PROGRESS, + new UploadFileStatus(fileName, readBytes, contentLength))); + LOG.info("Update progress - {} : {}", fileName, (double) readBytes / (double) contentLength); } - - infoWindow.updateProgress(fileName, readBytes, contentLength); - LOG.info("Update progress - {} : {}", fileName, (double) readBytes / (double) contentLength); } /** @@ -267,19 +248,14 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene public void onProgress(final StreamingProgressEvent event) { if (event.getBytesReceived() > maxSize || event.getContentLength() > maxSize) { LOG.error("User tried to upload more than was allowed ({}).", maxSize); - - view.decreaseNumberOfFileUploadsExpected(); - final SoftwareModule sw = view.getSoftwareModuleSelected(); - view.getFileSelected().remove(new CustomFile(fileName, sw.getName(), sw.getVersion())); - eventBus.publish(this, UploadArtifactUIEvent.UPLOAD_STREAMINING_FINISHED); - failureReason = i18n.get("message.uploadedfile.size.exceeded", maxSize); - infoWindow.uploadFailed(event.getFileName(), failureReason); - interrupted = true; + eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_FAILED, new UploadFileStatus( + fileName, failureReason))); + streamingInterrupted = true; return; } - - infoWindow.updateProgress(event.getFileName(), event.getBytesReceived(), event.getContentLength()); + eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_IN_PROGRESS, new UploadFileStatus( + fileName, event.getBytesReceived(), event.getContentLength()))); // Logging to solve sonar issue LOG.trace("Streaming in progress for file :{}", event.getFileName()); } @@ -293,29 +269,15 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene @Override public void streamingFailed(final StreamingErrorEvent event) { LOG.info("Streaming failed for file :{}", event.getFileName()); - - view.decreaseNumberOfFileUploadsExpected(); - final SoftwareModule sw = view.getSoftwareModuleSelected(); - view.getFileSelected().remove(new CustomFile(fileName, sw.getName(), sw.getVersion())); - eventBus.publish(this, UploadArtifactUIEvent.UPLOAD_STREAMINING_FINISHED); - - if (failureReason != null) { - // Display custom error message - infoWindow.uploadFailed(event.getFileName(), failureReason); - } else { - // internal upload error - infoWindow.uploadFailed(event.getFileName(), event.getException().getMessage()); + if (failureReason == null) { + failureReason = event.getException().getMessage(); } - // check if we are finished - if (view.enableProcessBtn()) { - infoWindow.uploadSessionFinished(); - } - view.displayDuplicateValidationMessage(); + eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_STREAMING_FAILED, + new UploadFileStatus(fileName, failureReason))); LOG.info("Streaming failed due to :{}", event.getException()); } - /** * Upload failed for {@link Upload} variant. * @@ -324,23 +286,13 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene @Override public void uploadFailed(final FailedEvent event) { LOG.info("Upload failed for file :{}", event.getFilename()); - view.decreaseNumberOfFileUploadsExpected(); - /** - * If upload interrupted because of duplicate file,do not remove the - * file already in upload list - **/ - if (!view.getDuplicateFileNamesList().isEmpty()) { - final SoftwareModule sw = view.getSoftwareModuleSelected(); - view.getFileSelected().remove(new CustomFile(fileName, sw.getName(), sw.getVersion())); - } - eventBus.publish(this, UploadArtifactUIEvent.UPLOAD_STREAMINING_FINISHED); - if (failureReason != null) { - infoWindow.uploadFailed(event.getFilename(), failureReason); - } else { - infoWindow.uploadFailed(event.getFilename(), event.getReason().getMessage()); + if (failureReason == null) { + failureReason = event.getReason().getMessage(); } + System.out.println("failureReason:::"+failureReason); + eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_FAILED, new UploadFileStatus( + fileName, failureReason))); LOG.info("Upload failed for file :{}", event.getReason()); - } /** @@ -348,7 +300,7 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene */ @Override public boolean isInterrupted() { - return interrupted; + return streamingInterrupted; } private static class NullOutputStream extends OutputStream { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java index 9e304efe8..58661773d 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java @@ -16,7 +16,6 @@ import java.io.OutputStream; import java.util.ArrayList; import java.util.List; import java.util.Set; -import java.util.concurrent.atomic.AtomicInteger; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; @@ -26,6 +25,8 @@ import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent.SoftwareModuleEventType; import org.eclipse.hawkbit.ui.artifacts.event.UploadArtifactUIEvent; +import org.eclipse.hawkbit.ui.artifacts.event.UploadStatusEvent; +import org.eclipse.hawkbit.ui.artifacts.event.UploadStatusEvent.UploadStatusEventType; import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState; import org.eclipse.hawkbit.ui.artifacts.state.CustomFile; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; @@ -97,13 +98,9 @@ public class UploadLayout extends VerticalLayout { @Autowired private transient SPInfo spInfo; - private final AtomicInteger numberOfFileUploadsExpected = new AtomicInteger(); - - private final AtomicInteger numberOfFilesActuallyUpload = new AtomicInteger(); - private final List duplicateFileNamesList = new ArrayList<>(); - private Button processBtn ; + private Button processBtn; private Button discardBtn; @@ -128,11 +125,48 @@ public class UploadLayout extends VerticalLayout { void init() { createComponents(); buildLayout(); - updateActionCount(); restoreState(); eventBus.subscribe(this); ui = UI.getCurrent(); } + + + @EventBusListenerMethod(scope = EventScope.SESSION) + void onEvent(final UploadArtifactUIEvent event) { + if (event == UploadArtifactUIEvent.DELETED_ALL_SOFWARE) { + ui.access(() -> updateActionCount()); + } else if (event == UploadArtifactUIEvent.MINIMIZED_STATUS_POPUP) { + ui.access(() -> showUploadStatusButton()); + } else if (event == UploadArtifactUIEvent.MAXIMIZED_STATUS_POPUP) { + ui.access(() -> maximizeStatusPopup()); + } + } + @EventBusListenerMethod(scope = EventScope.SESSION) + void onEvent(final UploadStatusEvent event) { + if (event.getUploadProgressEventType() == UploadStatusEventType.UPLOAD_STARTED) { + ui.access(() -> setUploadStatusButtonIconToInProgress()); + } + else if (event.getUploadProgressEventType() == UploadStatusEventType.UPLOAD_FAILED) { + ui.access(() -> onUploadFailure(event)); + } else if (event.getUploadProgressEventType() == UploadStatusEventType.UPLOAD_FINISHED) { + ui.access(() -> onUploadCompletion()); + } else if (event.getUploadProgressEventType() == UploadStatusEventType.UPLOAD_SUCCESSFUL) { + ui.access(() -> onUploadSuccess(event)); + } else if (event.getUploadProgressEventType() == UploadStatusEventType.UPLOAD_STREAMING_FAILED) { + ui.access(() -> onUploadStreamingFailure(event)); + } else if (event.getUploadProgressEventType() == UploadStatusEventType.UPLOAD_STREAMING_FINISHED) { + ui.access(() -> onUploadStreamingSuccess(event)); + } + } + + @PreDestroy + void destroy() { + /* + * It's good manners to do this, even though vaadin-spring will + * automatically unsubscribe when this UI is garbage collected. + */ + eventBus.unsubscribe(this); + } private void createComponents() { createUploadStatusButton(); @@ -143,8 +177,8 @@ public class UploadLayout extends VerticalLayout { private void buildLayout() { final Upload upload = new Upload(); - final UploadHandler uploadHandler = new UploadHandler(null, 0, this, uploadInfoWindow, - spInfo.getMaxArtifactFileSize(), upload, null); + final UploadHandler uploadHandler = new UploadHandler(null, 0, this, spInfo.getMaxArtifactFileSize(), upload, + null); upload.setButtonCaption(i18n.get("upload.file")); upload.setImmediate(true); upload.setReceiver(uploadHandler); @@ -176,9 +210,15 @@ public class UploadLayout extends VerticalLayout { } private void restoreState() { + updateActionCount(); + if (!artifactUploadState.getFileSelected().isEmpty() && artifactUploadState.isUploadCompleted()) { + processBtn.setEnabled(true); + } if (artifactUploadState.isStatusPopupMinimized()) { showUploadStatusButton(); - setUploadStatusButtonIconToFinished(); + if (artifactUploadState.isUploadCompleted()) { + setUploadStatusButtonIconToFinished(); + } } } @@ -204,10 +244,10 @@ public class UploadLayout extends VerticalLayout { for (final Html5File file : files) { processFile(file); } - if (numberOfFileUploadsExpected.get() > 0) { + if (artifactUploadState.getNumberOfFileUploadsExpected().get() > 0) { processBtn.setEnabled(false); // reset before we start - uploadInfoWindow.uploadSessionStarted(); + // uploadInfoWindow.uploadSessionStarted(); } else { // If the upload is not started, it signifies all // dropped files as either duplicate or directory.So @@ -220,7 +260,7 @@ public class UploadLayout extends VerticalLayout { private void processFile(final Html5File file) { if (!isDirectory(file)) { if (!checkForDuplicate(file.getFileName())) { - numberOfFileUploadsExpected.incrementAndGet(); + artifactUploadState.getNumberOfFileUploadsExpected().incrementAndGet(); file.setStreamVariable(createStreamVariable(file)); } } else { @@ -229,7 +269,7 @@ public class UploadLayout extends VerticalLayout { } private StreamVariable createStreamVariable(final Html5File file) { - return new UploadHandler(file.getFileName(), file.getFileSize(), UploadLayout.this, uploadInfoWindow, + return new UploadHandler(file.getFileName(), file.getFileSize(), UploadLayout.this, spInfo.getMaxArtifactFileSize(), null, file.getType()); } @@ -282,9 +322,7 @@ public class UploadLayout extends VerticalLayout { processBtn.addStyleName(SPUIStyleDefinitions.ACTION_BUTTON); processBtn.addClickListener(event -> displayConfirmWindow(event)); processBtn.setHtmlContentAllowed(true); - if (artifactUploadState.getFileSelected().isEmpty()) { - processBtn.setEnabled(false); - } + processBtn.setEnabled(false); } private void createDiscardBtn() { @@ -349,13 +387,15 @@ public class UploadLayout extends VerticalLayout { artifactUploadState.getBaseSwModuleList().put(currentBaseSoftwareModuleKey, selectedSoftwareModule); } return out; - } catch (final FileNotFoundException e) { + } + catch (final FileNotFoundException e) { LOG.error("Upload failed {}", e); throw new ArtifactUploadFailedException(i18n.get("message.file.not.found")); } catch (final IOException e) { LOG.error("Upload failed {}", e); throw new ArtifactUploadFailedException(i18n.get("message.upload.failed")); } + } Boolean validate(final DragAndDropEvent event) { @@ -430,7 +470,7 @@ public class UploadLayout extends VerticalLayout { } void decreaseNumberOfFileUploadsExpected() { - numberOfFileUploadsExpected.decrementAndGet(); + artifactUploadState.getNumberOfFileUploadsExpected().decrementAndGet(); } List getDuplicateFileNamesList() { @@ -451,7 +491,7 @@ public class UploadLayout extends VerticalLayout { void displayDuplicateValidationMessage() { // check if streaming of all dropped files are completed - if (numberOfFilesActuallyUpload.intValue() == numberOfFileUploadsExpected.intValue()) { + if (artifactUploadState.getNumberOfFilesActuallyUpload().intValue() == artifactUploadState.getNumberOfFileUploadsExpected().intValue()) { displayCompositeMessage(); } } @@ -466,7 +506,6 @@ public class UploadLayout extends VerticalLayout { } else if (duplicateFileNamesList.size() > 1) { message.append(i18n.get("message.no.duplicateFiles")); } - duplicateFileNamesList.clear(); } return message.toString(); } @@ -476,7 +515,7 @@ public class UploadLayout extends VerticalLayout { } void increaseNumberOfFileUploadsExpected() { - numberOfFileUploadsExpected.incrementAndGet(); + artifactUploadState.getNumberOfFileUploadsExpected().incrementAndGet(); } void updateFileSize(final String name, final long size) { @@ -495,17 +534,19 @@ public class UploadLayout extends VerticalLayout { } void increaseNumberOfFilesActuallyUpload() { - numberOfFilesActuallyUpload.incrementAndGet(); + artifactUploadState.getNumberOfFilesActuallyUpload().incrementAndGet(); } /** * Enable process button once upload is completed. */ boolean enableProcessBtn() { - if (numberOfFilesActuallyUpload.intValue() >= numberOfFileUploadsExpected.intValue()) { + if (artifactUploadState.getNumberOfFilesActuallyUpload().intValue() >= artifactUploadState + .getNumberOfFileUploadsExpected().intValue() + && artifactUploadState.getNumberOfFilesActuallyUpload().get() != 0) { processBtn.setEnabled(true); - numberOfFileUploadsExpected.set(0); - numberOfFilesActuallyUpload.set(0); + artifactUploadState.getNumberOfFilesActuallyUpload().set(0); + artifactUploadState.getNumberOfFileUploadsExpected().set(0); return true; } return false; @@ -546,8 +587,8 @@ public class UploadLayout extends VerticalLayout { processBtn.setCaption(SPUILabelDefinitions.PROCESS); /* disable when there is no files to upload. */ processBtn.setEnabled(false); - numberOfFileUploadsExpected.set(0); - numberOfFilesActuallyUpload.set(0); + artifactUploadState.getNumberOfFilesActuallyUpload().set(0); + artifactUploadState.getNumberOfFileUploadsExpected().set(0); duplicateFileNamesList.clear(); } @@ -623,33 +664,70 @@ public class UploadLayout extends VerticalLayout { return dropAreaLayout; } - @EventBusListenerMethod(scope = EventScope.SESSION) - void onEvent(final UploadArtifactUIEvent event) { - if (event == UploadArtifactUIEvent.DELETED_ALL_SOFWARE) { - ui.access(() -> updateActionCount()); - } else if (event == UploadArtifactUIEvent.MINIMIZED_STATUS_POPUP) { - ui.access(() -> showUploadStatusButton()); - } else if (event == UploadArtifactUIEvent.MAXIMIZED_STATUS_POPUP) { - ui.access(() -> maximizeStatusPopup()); - } else if (event == UploadArtifactUIEvent.UPLOAD_FINISHED) { - ui.access(() -> setUploadStatusButtonIconToFinished()); - } else if (event == UploadArtifactUIEvent.UPLOAD_STARTED) { - ui.access(() -> setUploadStatusButtonIconToInProgress()); - }else if (event == UploadArtifactUIEvent.UPLOAD_STREAMINING_FINISHED) { - //TODO re-check - updateActionCount(); - enableProcessBtn(); - } + private void onUploadStreamingSuccess(UploadStatusEvent event) { + increaseNumberOfFilesActuallyUpload(); + updateActionCount(); + enableProcessBtn(); + if (isUploadComplete()) { + uploadInfoWindow.uploadSessionFinished(); + setUploadStatusButtonIconToFinished(); + } + // display the duplicate message after streaming all files + displayDuplicateValidationMessage(); + duplicateFileNamesList.clear(); } - @PreDestroy - void destroy() { - /* - * It's good manners to do this, even though vaadin-spring will - * automatically unsubscribe when this UI is garbage collected. - */ - eventBus.unsubscribe(this); + private void onUploadStreamingFailure(UploadStatusEvent event) { + onUploadFailure(event); + updateActionCount(); + enableProcessBtn(); + // check if we are finished + if (isUploadComplete()) { + uploadInfoWindow.uploadSessionFinished(); + setUploadStatusButtonIconToFinished(); + } + displayDuplicateValidationMessage(); + } + + private void onUploadSuccess(UploadStatusEvent event) { + updateFileSize(event.getUploadStatus().getFileName(), event.getUploadStatus().getContentLength()); + // recorded that we now one more uploaded + increaseNumberOfFilesActuallyUpload(); + } + + private void onUploadCompletion() { + // check if we are finished + if (isUploadComplete()) { + uploadInfoWindow.uploadSessionFinished(); + setUploadStatusButtonIconToFinished(); + } + updateActionCount(); + enableProcessBtn(); + duplicateFileNamesList.clear(); + } + + private boolean isUploadComplete() { + int uploadedCount = artifactUploadState.getNumberOfFilesActuallyUpload().intValue(); + int expectedUploadsCount = artifactUploadState.getNumberOfFileUploadsExpected().intValue(); + return uploadedCount == expectedUploadsCount; + } + + private void onUploadFailure(final UploadStatusEvent event) { + decreaseNumberOfFileUploadsExpected(); + /** + * If upload interrupted because of duplicate file,do not remove the + * file already in upload list + **/ + if (getDuplicateFileNamesList().isEmpty() + || !getDuplicateFileNamesList().contains(event.getUploadStatus().getFileName())) { + final SoftwareModule sw = getSoftwareModuleSelected(); + getFileSelected().remove( + new CustomFile(event.getUploadStatus().getFileName(), sw.getName(), sw.getVersion())); + //failed reason to be updated only if there is error other than duplicate file error + uploadInfoWindow.uploadFailed(event.getUploadStatus().getFileName(), event.getUploadStatus() + .getFailureReason()); + } } /** @@ -738,4 +816,5 @@ public class UploadLayout extends VerticalLayout { uploadStatusButton.addStyleName(SPUIStyleDefinitions.UPLOAD_PROGRESS_INDICATOR_STYLE); uploadStatusButton.setIcon(null); } + } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusInfoWindow.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusInfoWindow.java index 4693ab3dc..2efd929d3 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusInfoWindow.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusInfoWindow.java @@ -11,7 +11,12 @@ package org.eclipse.hawkbit.ui.artifacts.upload; import java.util.List; import java.util.stream.Collectors; +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; + import org.eclipse.hawkbit.ui.artifacts.event.UploadArtifactUIEvent; +import org.eclipse.hawkbit.ui.artifacts.event.UploadStatusEvent; +import org.eclipse.hawkbit.ui.artifacts.event.UploadStatusEvent.UploadStatusEventType; import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; @@ -19,6 +24,8 @@ import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; import org.springframework.beans.factory.annotation.Autowired; import org.vaadin.spring.events.EventBus; +import org.vaadin.spring.events.EventScope; +import org.vaadin.spring.events.annotation.EventBusListenerMethod; import com.vaadin.data.Container.Indexed; import com.vaadin.data.Item; @@ -69,9 +76,9 @@ public class UploadStatusInfoWindow extends Window { private static final long serialVersionUID = 1L; - private final Grid grid; + private Grid grid; - private final IndexedContainer uploads; + private IndexedContainer uploads; private volatile boolean errorOccured = false; @@ -84,12 +91,15 @@ public class UploadStatusInfoWindow extends Window { private Button closeButton; private Button resizeButton; + + private UI ui; + /** * Default Constructor. */ - UploadStatusInfoWindow() { - super(); + @PostConstruct + void init() { setPopupProperties(); createStatusPopupHeaderComponents(); @@ -106,8 +116,45 @@ public class UploadStatusInfoWindow extends Window { mainLayout.addComponents(getCaptionLayout(), grid); mainLayout.setExpandRatio(grid, 1.0F); setContent(mainLayout); + eventBus.subscribe(this); + ui = UI.getCurrent(); + } + + @EventBusListenerMethod(scope = EventScope.SESSION) + void onEvent(final UploadStatusEvent event) { + if (event.getUploadProgressEventType() == UploadStatusEventType.UPLOAD_IN_PROGRESS) { + UI.getCurrent().access( + () -> updateProgress(event.getUploadStatus().getFileName(), event.getUploadStatus().getBytesRead(), + event.getUploadStatus().getContentLength())); + } else if (event.getUploadProgressEventType() == UploadStatusEventType.UPLOAD_STARTED) { + UI.getCurrent().access(() -> onStartOfUpload(event)); + } else if (event.getUploadProgressEventType() == UploadStatusEventType.UPLOAD_STREAMING_FAILED) { + ui.access(() -> uploadFailed(event.getUploadStatus().getFileName(), event.getUploadStatus() + .getFailureReason())); + } else if (event.getUploadProgressEventType() == UploadStatusEventType.UPLOAD_SUCCESSFUL) { + UI.getCurrent().access(() -> uploadSucceeded(event.getUploadStatus().getFileName())); + } else if (event.getUploadProgressEventType() == UploadStatusEventType.UPLOAD_STREAMING_FINISHED) { + ui.access(() -> uploadSucceeded(event.getUploadStatus().getFileName())); + } + } + + private void onStartOfUpload(UploadStatusEvent event) { + uploadSessionStarted(); + uploadStarted(event.getUploadStatus().getFileName()); + } + + + @PreDestroy + void destroy() { + /* + * It's good manners to do this, even though vaadin-spring will + * automatically unsubscribe when this UI is garbage collected. + */ + eventBus.unsubscribe(this); + } + private void restoreState() { Indexed container = grid.getContainerDataSource(); if (container.getItemIds().isEmpty()) { @@ -119,8 +166,10 @@ public class UploadStatusInfoWindow extends Window { item.getItemProperty(PROGRESS).setValue(statusObject.getProgress()); item.getItemProperty(FILE_NAME).setValue(statusObject.getFilename()); } - artifactUploadState.setUploadCompleted(true); - minimizeButton.setEnabled(false); + // artifactUploadState.setUploadCompleted(true); + if (artifactUploadState.isUploadCompleted()) { + minimizeButton.setEnabled(false); + } } } @@ -130,6 +179,7 @@ public class UploadStatusInfoWindow extends Window { setResizable(false); setDraggable(true); setClosable(false); + setModal(true); } private void setGridColumnProperties() { @@ -192,6 +242,8 @@ public class UploadStatusInfoWindow extends Window { private static class StatusRenderer extends HtmlRenderer { + private static final long serialVersionUID = -5365795450234970943L; + @Override public JsonValue encode(final String value) { String result ; @@ -216,18 +268,17 @@ public class UploadStatusInfoWindow extends Window { void uploadSessionFinished() { if (!errorOccured) { close(); - eventBus.publish(this, UploadArtifactUIEvent.UPLOAD_FINISHED); - artifactUploadState.setUploadCompleted(true); - minimizeButton.setEnabled(false); } - + artifactUploadState.setUploadCompleted(true); + minimizeButton.setEnabled(false); } void uploadSessionStarted() { - close(); - openWindow(); + if (!artifactUploadState.isStatusPopupMinimized()) { + close(); + openWindow(); + } minimizeButton.setEnabled(true); - eventBus.publish(this, UploadArtifactUIEvent.UPLOAD_STARTED); artifactUploadState.setUploadCompleted(false); } @@ -287,22 +338,22 @@ public class UploadStatusInfoWindow extends Window { } void uploadFailed(final String filename, final String errorReason) { + if (!errorOccured) { + errorOccured = true; + } + String status = "Failed"; final Item item = uploads.getItem(filename); if (item != null) { - if (!errorOccured) { - errorOccured = true; - } item.getItemProperty(REASON).setValue(errorReason); - String status = "Failed"; item.getItemProperty(STATUS).setValue(status); - List uploadStatusObjectList = (List) artifactUploadState - .getUploadedFileStatusList().stream().filter(e -> e.getFilename().equals(filename)) - .collect(Collectors.toList()); - if (!uploadStatusObjectList.isEmpty()) { - UploadStatusObject uploadStatusObject = uploadStatusObjectList.get(0); - uploadStatusObject.setStatus(status); - uploadStatusObject.setReason(errorReason); - } + } + List uploadStatusObjectList = (List) artifactUploadState + .getUploadedFileStatusList().stream().filter(e -> e.getFilename().equals(filename)) + .collect(Collectors.toList()); + if (!uploadStatusObjectList.isEmpty()) { + UploadStatusObject uploadStatusObject = uploadStatusObjectList.get(0); + uploadStatusObject.setStatus(status); + uploadStatusObject.setReason(errorReason); } } @@ -370,4 +421,5 @@ public class UploadStatusInfoWindow extends Window { closeBtn.addClickListener(event -> clearWindow()); return closeBtn; } + } From 6654d71969d8f64c9f6e4b79f2ad53ed6c9409dc Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Fri, 13 May 2016 08:44:34 +0200 Subject: [PATCH 05/54] Started with #100 by means of splitting the management services into API and Jpa implementation. Signed-off-by: Kai Zimmermann --- .../RepositoryApplicationConfiguration.java | 2 +- .../eventbus/EntityChangeEventListener.java | 12 +- .../repository/ArtifactManagement.java | 563 +++----- .../repository/ControllerManagement.java | 640 ++------- .../repository/DeploymentManagement.java | 1132 ++++----------- .../DistributionSetAssignmentResult.java | 1 + .../repository/DistributionSetManagement.java | 1217 +++++------------ .../hawkbit/repository/ReportManagement.java | 416 +----- .../repository/RolloutGroupManagement.java | 155 +-- .../hawkbit/repository/RolloutManagement.java | 602 +------- .../hawkbit/repository/RolloutScheduler.java | 1 + .../TenantConfigurationManagement.java | 161 +-- .../{ => jpa}/ActionRepository.java | 2 +- .../{ => jpa}/ActionStatusRepository.java | 2 +- .../{ => jpa}/BaseEntityRepository.java | 2 +- .../DistributionSetMetadataRepository.java | 2 +- .../{ => jpa}/DistributionSetRepository.java | 4 +- .../DistributionSetTagRepository.java | 2 +- .../DistributionSetTypeRepository.java | 2 +- .../EclipseLinkTargetInfoRepository.java | 2 +- .../ExternalArtifactProviderRepository.java | 2 +- .../{ => jpa}/ExternalArtifactRepository.java | 2 +- .../repository/jpa/JpaArtifactManagement.java | 270 ++++ .../jpa/JpaControllerManagement.java | 417 ++++++ .../jpa/JpaDeploymentManagement.java | 652 +++++++++ .../jpa/JpaDistributionSetManagement.java | 663 +++++++++ .../repository/jpa/JpaReportManagement.java | 433 ++++++ .../jpa/JpaRolloutGroupManagement.java | 178 +++ .../repository/jpa/JpaRolloutManagement.java | 653 +++++++++ .../jpa/JpaTenantConfigurationManagement.java | 170 +++ .../{ => jpa}/LocalArtifactRepository.java | 2 +- .../{ => jpa}/NoCountPagingRepository.java | 2 +- .../{ => jpa}/OffsetBasedPageRequest.java | 2 +- .../{ => jpa}/RolloutGroupRepository.java | 2 +- .../{ => jpa}/RolloutRepository.java | 2 +- .../RolloutTargetGroupRepository.java | 2 +- .../{ => jpa}/SoftwareManagement.java | 5 +- .../SoftwareModuleMetadataRepository.java | 2 +- .../{ => jpa}/SoftwareModuleRepository.java | 2 +- .../SoftwareModuleTypeRepository.java | 2 +- .../{ => jpa}/SystemManagement.java | 2 +- .../repository/{ => jpa}/TagManagement.java | 2 +- .../TargetFilterQueryManagement.java | 2 +- .../TargetFilterQueryRepository.java | 2 +- .../{ => jpa}/TargetInfoRepository.java | 2 +- .../{ => jpa}/TargetManagement.java | 3 +- .../{ => jpa}/TargetRepository.java | 2 +- .../{ => jpa}/TargetTagRepository.java | 2 +- .../{ => jpa}/TargetWithActionType.java | 2 +- .../TenantConfigurationRepository.java | 2 +- .../{ => jpa}/TenantKeyGenerator.java | 2 +- .../{ => jpa}/TenantMetaDataRepository.java | 2 +- .../{ => jpa}/TenantStatsManagement.java | 8 +- .../model/helper/SystemManagementHolder.java | 2 +- .../condition/PauseRolloutGroupAction.java | 2 +- ...artNextGroupRolloutGroupSuccessAction.java | 2 +- .../ThresholdRolloutGroupErrorCondition.java | 2 +- ...ThresholdRolloutGroupSuccessCondition.java | 2 +- .../hawkbit/AbstractIntegrationTest.java | 42 +- .../org/eclipse/hawkbit/TestDataUtil.java | 4 +- .../repository/ControllerManagementTest.java | 10 +- .../repository/DeploymentManagementTest.java | 23 +- .../DistributionSetManagementTest.java | 2 +- .../repository/ReportManagementTest.java | 2 +- .../repository/RolloutManagementTest.java | 22 +- .../hawkbit/repository/TagManagementTest.java | 1 + .../TargetFilterQueryManagenmentTest.java | 1 + .../TargetManagementSearchTest.java | 10 +- .../repository/TargetManagementTest.java | 2 +- .../rsql/RSQLRolloutGroupFields.java | 2 +- .../utils/RepositoryDataGenerator.java | 24 +- .../controller/ArtifactStoreController.java | 2 +- .../hawkbit/controller/RootController.java | 11 +- .../rest/resource/DistributionSetMapper.java | 2 +- .../resource/DistributionSetResource.java | 8 +- .../resource/DistributionSetTagResource.java | 2 +- .../resource/DistributionSetTypeMapper.java | 2 +- .../resource/DistributionSetTypeResource.java | 4 +- .../resource/DownloadArtifactResource.java | 2 +- .../rest/resource/RolloutResource.java | 2 +- .../rest/resource/SoftwareModuleMapper.java | 2 +- .../rest/resource/SoftwareModuleResource.java | 2 +- .../resource/SoftwareModuleTypeResource.java | 2 +- .../resource/SystemManagementResource.java | 2 +- .../hawkbit/rest/resource/TargetResource.java | 2 +- .../rest/resource/TargetTagResource.java | 4 +- .../resource/DistributionSetResourceTest.java | 8 +- .../rest/resource/TargetResourceTest.java | 7 +- .../artifacts/details/ArtifactBeanQuery.java | 2 +- .../UploadViewConfirmationWindowLayout.java | 2 +- .../smtable/BaseSwModuleBeanQuery.java | 4 +- .../SoftwareModuleAddUpdateWindow.java | 2 +- .../smtable/SoftwareModuleTable.java | 2 +- .../CreateUpdateSoftwareTypeLayout.java | 2 +- .../smtype/SMTypeFilterButtonClick.java | 2 +- .../common/DistributionSetTypeBeanQuery.java | 2 +- .../common/SoftwareModuleTypeBeanQuery.java | 4 +- .../tagdetails/AbstractTargetTagToken.java | 2 +- .../tagdetails/DistributionTagToken.java | 2 +- .../ui/common/tagdetails/TargetTagToken.java | 2 +- .../CreateUpdateDistSetTypeLayout.java | 4 +- .../dstable/DistributionSetDetails.java | 2 +- .../dstable/DistributionSetTable.java | 15 +- .../dstable/ManageDistBeanQuery.java | 4 +- .../footer/DSDeleteActionsLayout.java | 2 +- ...DistributionsConfirmationWindowLayout.java | 2 +- .../smtable/SwModuleBeanQuery.java | 4 +- .../distributions/smtable/SwModuleTable.java | 2 +- .../smtype/DistSMTypeFilterButtonClick.java | 2 +- .../CreateOrUpdateFilterHeader.java | 2 +- .../CustomTargetBeanQuery.java | 2 +- .../FilterQueryValidation.java | 2 +- .../TargetFilterBeanQuery.java | 2 +- .../filtermanagement/TargetFilterTable.java | 2 +- .../DistributionAddUpdateWindowLayout.java | 4 +- .../dstable/DistributionBeanQuery.java | 4 +- .../management/dstable/DistributionTable.java | 2 +- .../dstag/DistributionTagBeanQuery.java | 4 +- .../management/footer/CountMessageLabel.java | 2 +- .../footer/DeleteActionsLayout.java | 2 +- .../ManangementConfirmationWindowLayout.java | 2 +- .../management/tag/CreateUpdateTagLayout.java | 2 +- .../targettable/BulkUploadHandler.java | 4 +- .../TargetAddUpdateWindowLayout.java | 2 +- .../targettable/TargetBeanQuery.java | 4 +- .../TargetBulkUpdateWindowLayout.java | 2 +- .../management/targettable/TargetTable.java | 4 +- .../CustomTargetTagFilterButtonClick.java | 2 +- .../targettag/TargetTagBeanQuery.java | 4 +- .../targettag/TargetTagFilterButtons.java | 2 +- .../rollout/AddUpdateRolloutWindowLayout.java | 2 +- .../rollout/DistributionBeanQuery.java | 2 +- .../ui/rollout/rollout/RolloutBeanQuery.java | 2 +- .../DefaultDistributionSetTypeLayout.java | 2 +- .../hawkbit/ui/utils/HawkbitCommonUtil.java | 2 +- 135 files changed, 4711 insertions(+), 4055 deletions(-) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/{ => jpa}/ActionRepository.java (99%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/{ => jpa}/ActionStatusRepository.java (98%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/{ => jpa}/BaseEntityRepository.java (97%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/{ => jpa}/DistributionSetMetadataRepository.java (96%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/{ => jpa}/DistributionSetRepository.java (99%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/{ => jpa}/DistributionSetTagRepository.java (97%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/{ => jpa}/DistributionSetTypeRepository.java (98%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/{ => jpa}/EclipseLinkTargetInfoRepository.java (98%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/{ => jpa}/ExternalArtifactProviderRepository.java (94%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/{ => jpa}/ExternalArtifactRepository.java (96%) create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaArtifactManagement.java create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaReportManagement.java create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutGroupManagement.java create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTenantConfigurationManagement.java rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/{ => jpa}/LocalArtifactRepository.java (98%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/{ => jpa}/NoCountPagingRepository.java (98%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/{ => jpa}/OffsetBasedPageRequest.java (98%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/{ => jpa}/RolloutGroupRepository.java (99%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/{ => jpa}/RolloutRepository.java (98%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/{ => jpa}/RolloutTargetGroupRepository.java (95%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/{ => jpa}/SoftwareManagement.java (99%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/{ => jpa}/SoftwareModuleMetadataRepository.java (97%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/{ => jpa}/SoftwareModuleRepository.java (99%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/{ => jpa}/SoftwareModuleTypeRepository.java (97%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/{ => jpa}/SystemManagement.java (99%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/{ => jpa}/TagManagement.java (99%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/{ => jpa}/TargetFilterQueryManagement.java (99%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/{ => jpa}/TargetFilterQueryRepository.java (96%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/{ => jpa}/TargetInfoRepository.java (98%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/{ => jpa}/TargetManagement.java (99%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/{ => jpa}/TargetRepository.java (99%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/{ => jpa}/TargetTagRepository.java (97%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/{ => jpa}/TargetWithActionType.java (97%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/{ => jpa}/TenantConfigurationRepository.java (97%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/{ => jpa}/TenantKeyGenerator.java (95%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/{ => jpa}/TenantMetaDataRepository.java (97%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/{ => jpa}/TenantStatsManagement.java (82%) diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java index d5e8db96f..1c562364f 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java @@ -12,8 +12,8 @@ import java.util.HashMap; import java.util.Map; import org.eclipse.hawkbit.aspects.ExceptionMappingAspectHandler; -import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; +import org.eclipse.hawkbit.repository.jpa.SystemManagement; import org.eclipse.hawkbit.repository.model.helper.AfterTransactionCommitExecutorHolder; import org.eclipse.hawkbit.repository.model.helper.CacheManagerHolder; import org.eclipse.hawkbit.repository.model.helper.SecurityTokenGeneratorHolder; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/EntityChangeEventListener.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/EntityChangeEventListener.java index 7bfbd957e..2f63a3122 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/EntityChangeEventListener.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/EntityChangeEventListener.java @@ -19,7 +19,7 @@ import org.eclipse.hawkbit.eventbus.event.TargetCreatedEvent; import org.eclipse.hawkbit.eventbus.event.TargetDeletedEvent; import org.eclipse.hawkbit.eventbus.event.TargetInfoUpdateEvent; import org.eclipse.hawkbit.executor.AfterTransactionCommitExecutor; -import org.eclipse.hawkbit.repository.TargetRepository; +import org.eclipse.hawkbit.repository.jpa.TargetRepository; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetInfo; import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity; @@ -66,7 +66,7 @@ public class EntityChangeEventListener { * in case exception happens in the * {@link ProceedingJoinPoint#proceed()} */ - @Around("execution(* org.eclipse.hawkbit.repository.TargetInfoRepository.save(..))") + @Around("execution(* org.eclipse.hawkbit.repository.jpa.TargetInfoRepository.save(..))") // Exception squid:S00112 - Is aspectJ proxy @SuppressWarnings({ "squid:S00112" }) public Object targetCreated(final ProceedingJoinPoint joinpoint) throws Throwable { @@ -93,7 +93,7 @@ public class EntityChangeEventListener { * in case exception happens in the * {@link ProceedingJoinPoint#proceed()} */ - @Around("execution(* org.eclipse.hawkbit.repository.TargetRepository.deleteByIdIn(..))") + @Around("execution(* org.eclipse.hawkbit.repository.jpa.TargetRepository.deleteByIdIn(..))") // Exception squid:S00112 - Is aspectJ proxy @SuppressWarnings({ "squid:S00112" }) public Object targetDeletedById(final ProceedingJoinPoint joinpoint) throws Throwable { @@ -115,8 +115,8 @@ public class EntityChangeEventListener { * in case exception happens in the * {@link ProceedingJoinPoint#proceed()} */ - @Around("execution(* org.eclipse.hawkbit.repository.TargetRepository.delete(..))") - // Exception squid:S00112 - Is aspectJ proxy + @Around("execution(* org.eclipse.hawkbit.repository.jpa.TargetRepository.delete(..))") + // Exception squid:S00112 - Is aspectJ proxy @SuppressWarnings({ "squid:S00112", "unchecked" }) public Object targetDeleted(final ProceedingJoinPoint joinpoint) throws Throwable { final String currentTenant = tenantAware.getCurrentTenant(); @@ -146,7 +146,7 @@ public class EntityChangeEventListener { afterCommit.afterCommit(() -> eventBus.post(new TargetDeletedEvent(tenant, targetId))); } - private boolean isTargetInfoNew(final Object targetInfo) { + private static boolean isTargetInfoNew(final Object targetInfo) { return ((TargetInfo) targetInfo).isNew(); } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ArtifactManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ArtifactManagement.java index 024ec11cb..977b9f171 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ArtifactManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ArtifactManagement.java @@ -13,11 +13,7 @@ import java.util.List; import javax.validation.constraints.NotNull; -import org.eclipse.hawkbit.artifact.repository.ArtifactRepository; -import org.eclipse.hawkbit.artifact.repository.ArtifactStoreException; -import org.eclipse.hawkbit.artifact.repository.HashNotMatchException; import org.eclipse.hawkbit.artifact.repository.model.DbArtifact; -import org.eclipse.hawkbit.artifact.repository.model.DbArtifactHash; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; import org.eclipse.hawkbit.repository.exception.ArtifactDeleteFailedException; import org.eclipse.hawkbit.repository.exception.ArtifactUploadFailedException; @@ -31,47 +27,110 @@ import org.eclipse.hawkbit.repository.model.ExternalArtifact; import org.eclipse.hawkbit.repository.model.ExternalArtifactProvider; import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; -import org.eclipse.hawkbit.repository.specifications.SoftwareModuleSpecification; import org.hibernate.validator.constraints.NotEmpty; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.data.jpa.repository.Modifying; import org.springframework.hateoas.Identifiable; import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Isolation; import org.springframework.transaction.annotation.Transactional; -import org.springframework.validation.annotation.Validated; /** * Service for {@link Artifact} management operations. * */ -@Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) -@Validated -@Service -public class ArtifactManagement { +public interface ArtifactManagement { - private static final Logger LOG = LoggerFactory.getLogger(ArtifactManagement.class); + /** + * Creates {@link ExternalArtifact} based on given provider. + * + * @param externalRepository + * the artifact is located in + * @param urlSuffix + * of the artifact + * {@link ExternalArtifactProvider#getDefaultSuffix()} is used if + * empty. + * @param moduleId + * to assign the artifact to + * + * @return created {@link ExternalArtifact} + * + * @throws EntityNotFoundException + * if {@link SoftwareModule} with given ID does not exist + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) + ExternalArtifact createExternalArtifact(@NotNull ExternalArtifactProvider externalRepository, String urlSuffix, + @NotNull Long moduleId); - @Autowired - private LocalArtifactRepository localArtifactRepository; + /** + * Persists {@link ExternalArtifactProvider} based on given properties. + * + * @param name + * of the provided + * @param description + * which is optional + * @param basePath + * of all {@link ExternalArtifact}s of the provider + * @param defaultUrlSuffix + * that is used if {@link ExternalArtifact#getUrlSuffix()} is + * empty. + * @return created {@link ExternalArtifactProvider} + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) + ExternalArtifactProvider createExternalArtifactProvider(@NotEmpty String name, String description, + @NotNull String basePath, String defaultUrlSuffix); - @Autowired - private ExternalArtifactRepository externalArtifactRepository; + /** + * Persists artifact binary as provided by given InputStream. assign the + * artifact in addition to given {@link SoftwareModule}. + * + * @param inputStream + * to read from for artifact binary + * @param moduleId + * to assign the new artifact to + * @param filename + * of the artifact + * @param overrideExisting + * to true if the artifact binary can be overridden + * if it already exists + * + * @return uploaded {@link LocalArtifact} + * + * @throw ArtifactUploadFailedException if upload fails + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + default LocalArtifact createLocalArtifact(final InputStream inputStream, final Long moduleId, final String filename, + final boolean overrideExisting) { + return createLocalArtifact(inputStream, moduleId, filename, null, null, overrideExisting, null); + } - @Autowired - private SoftwareModuleRepository softwareModuleRepository; - - @Autowired - private ExternalArtifactProviderRepository externalArtifactProviderRepository; - - @Autowired - private ArtifactRepository artifactRepository; + /** + * Persists artifact binary as provided by given InputStream. assign the + * artifact in addition to given {@link SoftwareModule}. + * + * @param inputStream + * to read from for artifact binary + * @param moduleId + * to assign the new artifact to + * @param filename + * of the artifact + * @param overrideExisting + * to true if the artifact binary can be overridden + * if it already exists + * @param contentType + * the contentType of the file + * + * @return uploaded {@link LocalArtifact} + * + * @throw ArtifactUploadFailedException if upload fails + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + default LocalArtifact createLocalArtifact(final InputStream inputStream, final Long moduleId, final String filename, + final boolean overrideExisting, final String contentType) { + return createLocalArtifact(inputStream, moduleId, filename, null, null, overrideExisting, contentType); + } /** * Persists artifact binary as provided by given InputStream. assign the @@ -105,59 +164,112 @@ public class ArtifactManagement { * @throws InvalidSHA1HashException * if check against provided SHA1 checksum failed */ - @Modifying - @Transactional(isolation = Isolation.READ_UNCOMMITTED) @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) - public LocalArtifact createLocalArtifact(@NotNull final InputStream stream, @NotNull final Long moduleId, - @NotEmpty final String filename, final String providedMd5Sum, final String providedSha1Sum, - final boolean overrideExisting, final String contentType) { - DbArtifact result = null; + LocalArtifact createLocalArtifact(@NotNull InputStream stream, @NotNull Long moduleId, @NotEmpty String filename, + String providedMd5Sum, String providedSha1Sum, boolean overrideExisting, String contentType); - final SoftwareModule softwareModule = getModuleAndThrowExceptionIfThatFails(moduleId); + /** + * Deletes {@link Artifact} based on given id. + * + * @param id + * of the {@link Artifact} that has to be deleted. + * @throws ArtifactDeleteFailedException + * if deletion failed (MongoDB is not available) + * + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY) + void deleteExternalArtifact(@NotNull Long id); - final LocalArtifact existing = checkForExistingArtifact(filename, overrideExisting, softwareModule); + /** + * Deletes a local artifact. + * + * @param existing + * the related local artifact + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY) + void deleteLocalArtifact(@NotNull LocalArtifact existing); - try { - result = artifactRepository.store(stream, filename, contentType, - new DbArtifactHash(providedSha1Sum, providedMd5Sum)); - } catch (final ArtifactStoreException e) { - throw new ArtifactUploadFailedException(e); - } catch (final HashNotMatchException e) { - if (e.getHashFunction().equals(HashNotMatchException.SHA1)) { - throw new InvalidSHA1HashException(e.getMessage(), e); - } else { - throw new InvalidMD5HashException(e.getMessage(), e); - } - } - if (result == null) { - return null; - } + /** + * Deletes {@link Artifact} based on given id. + * + * @param id + * of the {@link Artifact} that has to be deleted. + * @throws ArtifactDeleteFailedException + * if deletion failed (MongoDB is not available) + * + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY) + void deleteLocalArtifact(@NotNull Long id); - return storeArtifactMetadata(softwareModule, filename, result, existing); - } + /** + * Searches for {@link Artifact} with given {@link Identifiable}. + * + * @param id + * to search for + * @return found {@link Artifact} or null is it could not be + * found. + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + Artifact findArtifact(@NotNull Long id); - private static LocalArtifact checkForExistingArtifact(final String filename, final boolean overrideExisting, - final SoftwareModule softwareModule) { - if (softwareModule.getLocalArtifactByFilename(filename).isPresent()) { - if (overrideExisting) { - LOG.debug("overriding existing artifact with new filename {}", filename); - return softwareModule.getLocalArtifactByFilename(filename).get(); - } else { - throw new EntityAlreadyExistsException("File with that name already exists in the Software Module"); - } - } - return null; - } + /** + * Find by artifact by software module id and filename. + * + * @param filename + * file name + * @param softwareModuleId + * software module id. + * @return LocalArtifact if artifact present + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY + SpringEvalExpressions.HAS_AUTH_OR + + SpringEvalExpressions.IS_CONTROLLER) + List findByFilenameAndSoftwareModule(@NotNull String filename, @NotNull Long softwareModuleId); - private SoftwareModule getModuleAndThrowExceptionIfThatFails(final Long moduleId) { - final SoftwareModule softwareModule = findSoftwareModuleWithDetails(moduleId); + /** + * Find all local artifact by sha1 and return the first artifact. + * + * @param sha1 + * the sha1 + * @return the first local artifact + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY + SpringEvalExpressions.HAS_AUTH_OR + + SpringEvalExpressions.IS_CONTROLLER) + LocalArtifact findFirstLocalArtifactsBySHA1(@NotNull String sha1); - if (softwareModule == null) { - LOG.debug("no software module with ID {} exists", moduleId); - throw new EntityNotFoundException("Software Module: " + moduleId); - } - return softwareModule; - } + /** + * Searches for {@link Artifact} with given file name. + * + * @param filename + * to search for + * @return found List of {@link LocalArtifact}s. + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY + SpringEvalExpressions.HAS_AUTH_OR + + SpringEvalExpressions.IS_CONTROLLER) + List findLocalArtifactByFilename(@NotNull String filename); + + /** + * Get local artifact for a base software module. + * + * @param pageReq + * Pageable + * @param swId + * software module id + * @return Page + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + Page findLocalArtifactBySoftwareModule(@NotNull Pageable pageReq, @NotNull Long swId); + + /** + * Finds {@link SoftwareModule} by given id. + * + * @param id + * to search for + * @return the found {@link SoftwareModule}s or null if not + * found. + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY + SpringEvalExpressions.HAS_AUTH_OR + + SpringEvalExpressions.IS_CONTROLLER) + SoftwareModule findSoftwareModuleById(@NotNull Long id); /** * Retrieves software module including details ( @@ -170,7 +282,7 @@ public class ArtifactManagement { * @return the found {@link SoftwareModule}s */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - protected SoftwareModule findSoftwareModuleWithDetails(@NotNull final Long id) { + default SoftwareModule findSoftwareModuleWithDetails(@NotNull final Long id) { final SoftwareModule result = findSoftwareModuleById(id); if (result != null) { result.getArtifacts().size(); @@ -179,211 +291,6 @@ public class ArtifactManagement { return result; } - /** - * Find all local artifact by sha1 and return the first artifact. - * - * @param sha1 - * the sha1 - * @return the first local artifact - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY + SpringEvalExpressions.HAS_AUTH_OR - + SpringEvalExpressions.IS_CONTROLLER) - public LocalArtifact findFirstLocalArtifactsBySHA1(final String sha1) { - return localArtifactRepository.findFirstByGridFsFileName(sha1); - } - - /** - * Finds {@link SoftwareModule} by given id. - * - * @param id - * to search for - * @return the found {@link SoftwareModule}s or null if not - * found. - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY + SpringEvalExpressions.HAS_AUTH_OR - + SpringEvalExpressions.IS_CONTROLLER) - protected SoftwareModule findSoftwareModuleById(@NotNull final Long id) { - - final Specification spec = SoftwareModuleSpecification.byId(id); - - return softwareModuleRepository.findOne(spec); - } - - private LocalArtifact storeArtifactMetadata(final SoftwareModule softwareModule, final String providedFilename, - final DbArtifact result, final LocalArtifact existing) { - LocalArtifact artifact = existing; - if (existing == null) { - artifact = new LocalArtifact(result.getHashes().getSha1(), providedFilename, softwareModule); - } - artifact.setMd5Hash(result.getHashes().getMd5()); - artifact.setSha1Hash(result.getHashes().getSha1()); - artifact.setSize(result.getSize()); - - LOG.debug("storing new artifact into repository {}", artifact); - return localArtifactRepository.save(artifact); - } - - /** - * Persists {@link ExternalArtifactProvider} based on given properties. - * - * @param name - * of the provided - * @param description - * which is optional - * @param basePath - * of all {@link ExternalArtifact}s of the provider - * @param defaultUrlSuffix - * that is used if {@link ExternalArtifact#getUrlSuffix()} is - * empty. - * @return created {@link ExternalArtifactProvider} - */ - @Modifying - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) - public ExternalArtifactProvider createExternalArtifactProvider(@NotEmpty final String name, - final String description, @NotNull final String basePath, final String defaultUrlSuffix) { - return externalArtifactProviderRepository - .save(new ExternalArtifactProvider(name, description, basePath, defaultUrlSuffix)); - } - - /** - * Creates {@link ExternalArtifact} based on given provider. - * - * @param externalRepository - * the artifact is located in - * @param urlSuffix - * of the artifact - * {@link ExternalArtifactProvider#getDefaultSuffix()} is used if - * empty. - * @param moduleId - * to assign the artifact to - * - * @return created {@link ExternalArtifact} - * - * @throws EntityNotFoundException - * if {@link SoftwareModule} with given ID does not exist - */ - @Modifying - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) - public ExternalArtifact createExternalArtifact(@NotNull final ExternalArtifactProvider externalRepository, - final String urlSuffix, @NotNull final Long moduleId) { - - final SoftwareModule module = getModuleAndThrowExceptionIfThatFails(moduleId); - return externalArtifactRepository.save(new ExternalArtifact(externalRepository, urlSuffix, module)); - } - - /** - * Deletes {@link Artifact} based on given id. - * - * @param id - * of the {@link Artifact} that has to be deleted. - * @throws ArtifactDeleteFailedException - * if deletion failed (MongoDB is not available) - * - */ - @Modifying - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY) - public void deleteLocalArtifact(@NotNull final Long id) { - final LocalArtifact existing = localArtifactRepository.findOne(id); - - if (null == existing) { - return; - } - - deleteGridFsArtifact(existing); - - existing.getSoftwareModule().removeArtifact(existing); - softwareModuleRepository.save(existing.getSoftwareModule()); - localArtifactRepository.delete(id); - } - - /** - * Delete a grid fs file. - * - * @param existing - * the related local artifact - */ - @Modifying - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY) - public void deleteGridFsArtifact(@NotNull final LocalArtifact existing) { - if (existing == null) { - return; - } - - boolean artifactIsOnlyUsedByOneSoftwareModule = true; - for (final LocalArtifact lArtifact : localArtifactRepository - .findByGridFsFileName(existing.getGridFsFileName())) { - if (!lArtifact.getSoftwareModule().isDeleted() - && Long.compare(lArtifact.getSoftwareModule().getId(), existing.getSoftwareModule().getId()) != 0) { - artifactIsOnlyUsedByOneSoftwareModule = false; - break; - } - } - - if (artifactIsOnlyUsedByOneSoftwareModule) { - try { - LOG.debug("deleting artifact from repository {}", existing.getGridFsFileName()); - artifactRepository.deleteBySha1(existing.getGridFsFileName()); - } catch (final ArtifactStoreException e) { - throw new ArtifactDeleteFailedException(e); - } - } - } - - /** - * Deletes {@link Artifact} based on given id. - * - * @param id - * of the {@link Artifact} that has to be deleted. - * @throws ArtifactDeleteFailedException - * if deletion failed (MongoDB is not available) - * - */ - @Modifying - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY) - public void deleteExternalArtifact(@NotNull final Long id) { - final ExternalArtifact existing = externalArtifactRepository.findOne(id); - - if (null == existing) { - return; - } - - existing.getSoftwareModule().removeArtifact(existing); - softwareModuleRepository.save(existing.getSoftwareModule()); - externalArtifactRepository.delete(id); - } - - /** - * Searches for {@link Artifact} with given file name. - * - * @param filename - * to search for - * @return found List of {@link LocalArtifact}s. - */ - @NotNull - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY + SpringEvalExpressions.HAS_AUTH_OR - + SpringEvalExpressions.IS_CONTROLLER) - public List findLocalArtifactByFilename(@NotNull final String filename) { - return localArtifactRepository.findByFilename(filename); - } - - /** - * Searches for {@link Artifact} with given {@link Identifiable}. - * - * @param id - * to search for - * @return found {@link Artifact} or null is it could not be - * found. - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - public Artifact findArtifact(@NotNull final Long id) { - return localArtifactRepository.findOne(id); - } - /** * Loads {@link org.eclipse.hawkbit.artifact.server.json.model.Artifact} * from store for given {@link LocalArtifact}. @@ -398,98 +305,6 @@ public class ArtifactManagement { */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DOWNLOAD_ARTIFACT + SpringEvalExpressions.HAS_AUTH_OR + SpringEvalExpressions.HAS_CONTROLLER_DOWNLOAD) - public DbArtifact loadLocalArtifactBinary(@NotNull final LocalArtifact artifact) { - final DbArtifact result = artifactRepository.getArtifactBySha1(artifact.getGridFsFileName()); - if (result == null) { - throw new GridFSDBFileNotFoundException(artifact.getGridFsFileName()); - } + DbArtifact loadLocalArtifactBinary(@NotNull LocalArtifact artifact); - return result; - } - - /** - * Persists artifact binary as provided by given InputStream. assign the - * artifact in addition to given {@link SoftwareModule}. - * - * @param inputStream - * to read from for artifact binary - * @param moduleId - * to assign the new artifact to - * @param filename - * of the artifact - * @param overrideExisting - * to true if the artifact binary can be overridden - * if it already exists - * @param contentType - * the contentType of the file - * - * @return uploaded {@link LocalArtifact} - * - * @throw ArtifactUploadFailedException if upload fails - */ - @Modifying - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - public LocalArtifact createLocalArtifact(final InputStream inputStream, final Long moduleId, final String filename, - final boolean overrideExisting, final String contentType) { - return createLocalArtifact(inputStream, moduleId, filename, null, null, overrideExisting, contentType); - } - - /** - * Persists artifact binary as provided by given InputStream. assign the - * artifact in addition to given {@link SoftwareModule}. - * - * @param inputStream - * to read from for artifact binary - * @param moduleId - * to assign the new artifact to - * @param filename - * of the artifact - * @param overrideExisting - * to true if the artifact binary can be overdiden - * if it already exists - * - * @return uploaded {@link LocalArtifact} - * - * @throw ArtifactUploadFailedException if upload failes - */ - @Modifying - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - public LocalArtifact createLocalArtifact(final InputStream inputStream, final Long moduleId, final String filename, - final boolean overrideExisting) { - return createLocalArtifact(inputStream, moduleId, filename, null, null, overrideExisting, null); - } - - /** - * Get local artifact for a base software module. - * - * @param pageReq - * Pageable - * @param swId - * software module id - * @return Page - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - public Page findLocalArtifactBySoftwareModule(@NotNull final Pageable pageReq, - @NotNull final Long swId) { - return localArtifactRepository.findBySoftwareModuleId(pageReq, swId); - } - - /** - * Find by artifact by software module id and filename. - * - * @param filename - * file name - * @param softwareModuleId - * software module id. - * @return LocalArtifact if artifact present - */ - @NotNull - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY + SpringEvalExpressions.HAS_AUTH_OR - + SpringEvalExpressions.IS_CONTROLLER) - public List findByFilenameAndSoftwareModule(@NotNull final String filename, - @NotNull final Long softwareModuleId) { - return localArtifactRepository.findByFilenameAndSoftwareModuleId(filename, softwareModuleId); - } -} +} \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java index 11879edfd..b70ad3bdd 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java @@ -12,10 +12,6 @@ import java.net.URI; import java.util.List; import java.util.Map; -import javax.persistence.EntityManager; -import javax.persistence.criteria.CriteriaBuilder; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; import javax.validation.constraints.NotNull; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; @@ -26,78 +22,102 @@ import org.eclipse.hawkbit.repository.exception.ToManyStatusEntriesException; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; -import org.eclipse.hawkbit.repository.model.ActionStatus_; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetInfo; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; -import org.eclipse.hawkbit.repository.model.Target_; -import org.eclipse.hawkbit.repository.model.TenantConfiguration; -import org.eclipse.hawkbit.repository.specifications.ActionSpecifications; -import org.eclipse.hawkbit.security.HawkbitSecurityProperties; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; import org.hibernate.validator.constraints.NotEmpty; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.data.jpa.repository.Modifying; import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Isolation; import org.springframework.transaction.annotation.Transactional; -import org.springframework.validation.annotation.Validated; /** - * Service layer for all operations of the controller API (with access - * permissions only for the controller). - * - * + * Service layer for all operations of the DDI API (with access permissions only + * for the controller). * */ -@Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) -@Validated -@Service -public class ControllerManagement { - private static final Logger LOG = LoggerFactory.getLogger(ControllerManagement.class); - private static final Logger LOG_DOS = LoggerFactory.getLogger("server-security.dos"); +public interface ControllerManagement { - public static final String SERVER_MESSAGE_PREFIX = "Update Server: "; + String SERVER_MESSAGE_PREFIX = "Update Server: "; - @Autowired - private EntityManager entityManager; + /** + * Simple addition of a new {@link ActionStatus} entry to the {@link Action} + * . No state changes. + * + * @param statusMessage + * to add to the action + */ + @PreAuthorize(SpringEvalExpressions.IS_CONTROLLER) + void addInformationalActionStatus(@NotNull ActionStatus statusMessage); - @Autowired - private ActionRepository actionRepository; + /** + * Adds an {@link ActionStatus} for a cancel {@link Action} including + * potential state changes for the target and the {@link Action} itself. + * + * @param actionStatus + * to be added + * @return the persisted {@link Action} + * + * @throws EntityAlreadyExistsException + * if a given entity already exists + * + */ + @PreAuthorize(SpringEvalExpressions.IS_CONTROLLER) + Action addCancelActionStatus(@NotNull ActionStatus actionStatus); - @Autowired - private TargetRepository targetRepository; + /** + * Adds an {@link ActionStatus} entry for an update {@link Action} including + * potential state changes for the target and the {@link Action} itself. + * + * @param actionStatus + * to be added + * @return the updated {@link Action} + * + * @throws EntityAlreadyExistsException + * if a given entity already exists + * @throws ToManyStatusEntriesException + * if more than the allowed number of status entries are + * inserted + */ + @PreAuthorize(SpringEvalExpressions.IS_CONTROLLER) + Action addUpdateActionStatus(@NotNull ActionStatus actionStatus); - @Autowired - private TargetManagement targetManagement; + /** + * Retrieves all {@link Action}s which are active and assigned to a + * {@link Target}. + * + * @param target + * the target to retrieve the actions from + * @return a list of actions assigned to given target which are active + */ + @PreAuthorize(SpringEvalExpressions.IS_CONTROLLER) + List findActionByTargetAndActive(@NotNull Target target); - @Autowired - private DeploymentManagement deploymentManagement; + /** + * Get the {@link Action} entity for given actionId with all lazy + * attributes. + * + * @param actionId + * to be id of the action + * @return the corresponding {@link Action} + */ + @PreAuthorize(SpringEvalExpressions.IS_CONTROLLER) + Action findActionWithDetails(@NotNull Long actionId); - @Autowired - private TargetInfoRepository targetInfoRepository; - - @Autowired - private SoftwareModuleRepository softwareModuleRepository; - - @Autowired - private ActionStatusRepository actionStatusRepository; - - @Autowired - private HawkbitSecurityProperties securityProperties; - - @Autowired - private TenantConfigurationRepository tenantConfigurationRepository; - - @Autowired - private TenantConfigurationManagement tenantConfigurationManagement; + /** + * register new target in the repository (plug-and-play). + * + * @param controllerId + * reference + * @param address + * the client IP address of the target, might be {@code null} + * @return target reference + */ + @PreAuthorize(SpringEvalExpressions.IS_CONTROLLER) + Target findOrRegisterTargetIfItDoesNotexist(@NotEmpty String controllerId, URI address); /** * Retrieves all {@link SoftwareModule}s which are assigned to the given @@ -110,46 +130,13 @@ public class ControllerManagement { * {@code distributionSet} */ @PreAuthorize(SpringEvalExpressions.IS_CONTROLLER) - public String findPollingTime() { - final TenantConfigurationKey configurationKey = TenantConfigurationKey.POLLING_TIME_INTERVAL; - final Class propertyType = String.class; - tenantConfigurationManagement.validateTenantConfigurationDataType(configurationKey, propertyType); - final TenantConfiguration tenantConfiguration = tenantConfigurationRepository - .findByKey(configurationKey.getKeyName()); - return tenantConfigurationManagement - .buildTenantConfigurationValueByKey(configurationKey, propertyType, tenantConfiguration).getValue(); - } - - /** - * Refreshes the time of the last time the controller has been connected to - * the server. - * - * @param targetid - * of the target to to update - * @param address - * the client address of the target, might be {@code null} - * @return the updated target - * - * @throws EntityNotFoundException - * if target with given ID could not be found - */ - @Modifying - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @PreAuthorize(SpringEvalExpressions.IS_CONTROLLER) - public Target updateLastTargetQuery(@NotEmpty final String targetid, final URI address) { - final Target target = targetRepository.findByControllerId(targetid); - if (target == null) { - throw new EntityNotFoundException(targetid); - } - - return updateLastTargetQuery(target.getTargetInfo(), address).getTarget(); - } + List findSoftwareModulesByDistributionSet(@NotNull DistributionSet distributionSet); /** * Retrieves last {@link UpdateAction} for a download of an artifact of * given module and target. * - * @param targetId + * @param controllerId * to look for * @param module * that should be assigned to the target @@ -159,17 +146,28 @@ public class ControllerManagement { * if action for given combination could not be found */ @PreAuthorize(SpringEvalExpressions.IS_CONTROLLER) - public Action getActionForDownloadByTargetAndSoftwareModule(@NotNull final String targetId, - @NotNull final SoftwareModule module) { - final List action = actionRepository.findActionByTargetAndSoftwareModule(targetId, module); + Action getActionForDownloadByTargetAndSoftwareModule(@NotEmpty String controllerId, @NotNull SoftwareModule module); - if (action.isEmpty() || action.get(0).isCancelingOrCanceled()) { - throw new EntityNotFoundException( - "No assigment found for module " + module.getId() + " to target " + targetId); - } + /** + * @return current {@link TenantConfigurationKey#POLLING_TIME_INTERVAL}. + */ + @PreAuthorize(SpringEvalExpressions.IS_CONTROLLER) + String getPollingTime(); - return action.get(0); - } + /** + * An direct access to the security token of an + * {@link Target#getSecurityToken()} without authorization. This is + * necessary to be able to access the security-token without any + * security-context information because the security-token is used for + * authentication. + * + * @param controllerId + * the ID of the controller to retrieve the security token for + * @return the security context of the target, in case no target exists for + * the given controllerId {@code null} is returned + */ + @PreAuthorize(SpringEvalExpressions.IS_CONTROLLER) + String getSecurityTokenByControllerId(@NotEmpty String controllerId); /** * Checks if a given target has currently or has even been assigned to the @@ -178,7 +176,7 @@ public class ControllerManagement { * assigned or had ever been assigned to the target and so it's visible to a * specific target e.g. for downloading. * - * @param targetId + * @param controllerId * the ID of the target to check * @param localArtifact * the artifact to verify if the given target had even been @@ -187,14 +185,56 @@ public class ControllerManagement { * relation to the given artifact through the action history, * otherwise {@code false} */ - public boolean hasTargetArtifactAssigned(@NotNull final String targetId, - @NotNull final LocalArtifact localArtifact) { - final Target target = targetRepository.findByControllerId(targetId); - if (target == null) { - return false; - } - return actionRepository.count(ActionSpecifications.hasTargetAssignedArtifact(target, localArtifact)) > 0; - } + @PreAuthorize(SpringEvalExpressions.IS_CONTROLLER) + boolean hasTargetArtifactAssigned(@NotNull String controllerId, @NotNull LocalArtifact localArtifact); + + /** + * Registers retrieved status for given {@link Target} and {@link Action} if + * it does not exist yet. + * + * @param action + * to the handle status for + * @param message + * for the status + * @return the update action in case the status has been changed to + * {@link Status#RETRIEVED} + */ + @PreAuthorize(SpringEvalExpressions.IS_CONTROLLER) + Action registerRetrieved(@NotNull Action action, String message); + + /** + * Updates attributes of the controller. + * + * @param controllerId + * to update + * @param attributes + * to insert + * + * @return updated {@link Target} + * + * @throws EntityNotFoundException + * if target that has to be updated could not be found + * @throws ToManyAttributeEntriesException + * if maximum + */ + @PreAuthorize(SpringEvalExpressions.IS_CONTROLLER) + Target updateControllerAttributes(@NotEmpty String controllerId, @NotNull Map attributes); + + /** + * Refreshes the time of the last time the controller has been connected to + * the server. + * + * @param controllerId + * of the target to to update + * @param address + * the client address of the target, might be {@code null} + * @return the updated target + * + * @throws EntityNotFoundException + * if target with given ID could not be found + */ + @PreAuthorize(SpringEvalExpressions.IS_CONTROLLER) + Target updateLastTargetQuery(@NotEmpty String controllerId, URI address); /** * Refreshes the time of the last time the controller has been connected to @@ -207,83 +247,12 @@ public class ControllerManagement { * @return the updated target * */ - @Modifying - @Transactional(isolation = Isolation.READ_UNCOMMITTED) @PreAuthorize(SpringEvalExpressions.IS_CONTROLLER) - public TargetInfo updateLastTargetQuery(@NotNull final TargetInfo target, final URI address) { + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + default TargetInfo updateLastTargetQuery(@NotNull final TargetInfo target, @NotNull final URI address) { return updateTargetStatus(target, null, System.currentTimeMillis(), address); } - /** - * Retrieves all {@link Action}s which are active and assigned to a - * {@link Target}. - * - * @param target - * the target to retrieve the actions from - * @return a list of actions assigned to given target which are active - */ - @PreAuthorize(SpringEvalExpressions.IS_CONTROLLER) - public List findActionByTargetAndActive(final Target target) { - return actionRepository.findByTargetAndActiveOrderByIdAsc(target, true); - } - - /** - * Retrieves all {@link SoftwareModule}s which are assigned to the given - * {@link DistributionSet}. - * - * @param distributionSet - * the distribution set which should be assigned to the returned - * {@link SoftwareModule}s - * @return a list of {@link SoftwareModule}s assigned to given - * {@code distributionSet} - */ - @PreAuthorize(SpringEvalExpressions.IS_CONTROLLER) - public List findSoftwareModulesByDistributionSet(final DistributionSet distributionSet) { - return softwareModuleRepository.findByAssignedTo(distributionSet); - } - - /** - * Get the {@link Action} entity for given actionId with all lazy - * attributes. - * - * @param actionId - * to be id of the action - * @return the corresponding {@link Action} - */ - @PreAuthorize(SpringEvalExpressions.IS_CONTROLLER) - public Action findActionWithDetails(@NotNull final Long actionId) { - return actionRepository.findById(actionId); - } - - /** - * register new target in the repository (plug-and-play). - * - * @param targetid - * reference - * @param address - * the client IP address of the target, might be {@code null} - * @return target reference - */ - @Modifying - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @PreAuthorize(SpringEvalExpressions.IS_CONTROLLER) - public Target findOrRegisterTargetIfItDoesNotexist(@NotEmpty final String targetid, final URI address) { - final Specification spec = (targetRoot, query, cb) -> cb.equal(targetRoot.get(Target_.controllerId), - targetid); - - Target target = targetRepository.findOne(spec); - - if (target == null) { - target = new Target(targetid); - target.setDescription("Plug and Play target: " + targetid); - target.setName(targetid); - return targetManagement.createTarget(target, TargetUpdateStatus.REGISTERED, System.currentTimeMillis(), - address); - } - - return updateLastTargetQuery(target.getTargetInfo(), address).getTarget(); - } - /** * Update selective the target status of a given {@code target}. * @@ -300,313 +269,8 @@ public class ControllerManagement { * the client address of the target, might be {@code null} * @return the updated TargetInfo */ - @Modifying - @Transactional(isolation = Isolation.READ_UNCOMMITTED) @PreAuthorize(SpringEvalExpressions.IS_CONTROLLER) - public TargetInfo updateTargetStatus(@NotNull final TargetInfo targetInfo, final TargetUpdateStatus status, - final Long lastTargetQuery, final URI address) { - final TargetInfo mtargetInfo = entityManager.merge(targetInfo); - if (status != null) { - mtargetInfo.setUpdateStatus(status); - } - if (lastTargetQuery != null) { - mtargetInfo.setLastTargetQuery(lastTargetQuery); - } - if (address != null) { - mtargetInfo.setAddress(address.toString()); - } - return targetInfoRepository.save(mtargetInfo); - } + TargetInfo updateTargetStatus(@NotNull TargetInfo targetInfo, TargetUpdateStatus status, Long lastTargetQuery, + URI address); - /** - * Adds an {@link ActionStatus} for a {@link UpdateAction} and cancels the - * {@link UpdateAction} if necessary. - * - * @param actionStatus - * to be updated - * @param action - * the status is for - * @return the persisted {@link Action} - * - */ - @Modifying - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @PreAuthorize(SpringEvalExpressions.IS_CONTROLLER) - public Action addCancelActionStatus(@NotNull final ActionStatus actionStatus, final Action action) { - - checkForToManyStatusEntries(action); - action.setStatus(actionStatus.getStatus()); - - switch (actionStatus.getStatus()) { - case WARNING: - case ERROR: - case RUNNING: - break; - case CANCELED: - case FINISHED: - // in case of successful cancellation we also report the success at - // the canceled action itself. - actionStatus.addMessage( - ControllerManagement.SERVER_MESSAGE_PREFIX + "Cancellation completion is finished sucessfully."); - deploymentManagement.successCancellation(action); - break; - case RETRIEVED: - actionStatus.addMessage(ControllerManagement.SERVER_MESSAGE_PREFIX + "Cancellation request retrieved."); - break; - default: - } - actionRepository.save(action); - actionStatusRepository.save(actionStatus); - - return action; - } - - /** - * Updates an {@link ActionStatus} for a {@link UpdateAction}. - * - * @param actionStatus - * to be updated - * @param action - * the update is for - * @return the persisted {@link Action} - * - * @throws EntityAlreadyExistsException - * if a given entity already exists - * @throws ToManyStatusEntriesException - * if more than the allowed number of status entries are - * inserted - */ - @Modifying - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @PreAuthorize(SpringEvalExpressions.IS_CONTROLLER) - public Action addUpdateActionStatus(@NotNull final ActionStatus actionStatus, final Action action) { - - if (!action.isActive()) { - LOG.debug("Update of actionStatus {} for action {} not possible since action not active anymore.", - actionStatus.getId(), action.getId()); - return action; - } - return handleAddUpdateActionStatus(actionStatus, action); - } - - /** - * Sets {@link TargetUpdateStatus} based on given {@link ActionStatus}. - * - * @param actionStatus - * @param action - * @return - */ - public Action handleAddUpdateActionStatus(final ActionStatus actionStatus, final Action action) { - LOG.debug("addUpdateActionStatus for action {}", action.getId()); - - final Action mergedAction = entityManager.merge(action); - Target mergedTarget = mergedAction.getTarget(); - // check for a potential DOS attack - checkForToManyStatusEntries(action); - - switch (actionStatus.getStatus()) { - case ERROR: - mergedTarget = deploymentManagement.updateTargetInfo(mergedTarget, TargetUpdateStatus.ERROR, false); - handleErrorOnAction(mergedAction, mergedTarget); - break; - case FINISHED: - handleFinishedAndStoreInTargetStatus(mergedTarget, mergedAction); - break; - case CANCELED: - case WARNING: - case RUNNING: - deploymentManagement.updateTargetInfo(mergedTarget, TargetUpdateStatus.PENDING, false); - break; - default: - break; - } - - actionStatusRepository.save(actionStatus); - - LOG.debug("addUpdateActionStatus {} for target {} is finished.", action.getId(), mergedTarget.getId()); - - return actionRepository.save(mergedAction); - } - - private void handleErrorOnAction(final Action mergedAction, final Target mergedTarget) { - mergedAction.setActive(false); - mergedAction.setStatus(Status.ERROR); - mergedTarget.setAssignedDistributionSet(null); - targetManagement.updateTarget(mergedTarget); - } - - private void checkForToManyStatusEntries(final Action action) { - if (securityProperties.getDos().getMaxStatusEntriesPerAction() > 0) { - - final Long statusCount = actionStatusRepository.countByAction(action); - - if (statusCount >= securityProperties.getDos().getMaxStatusEntriesPerAction()) { - LOG_DOS.error( - "Potential denial of service (DOS) attack identfied. More status entries in the system than permitted ({})!", - securityProperties.getDos().getMaxStatusEntriesPerAction()); - throw new ToManyStatusEntriesException( - String.valueOf(securityProperties.getDos().getMaxStatusEntriesPerAction())); - } - } - } - - private void handleFinishedAndStoreInTargetStatus(final Target target, final Action action) { - action.setActive(false); - action.setStatus(Status.FINISHED); - final TargetInfo targetInfo = target.getTargetInfo(); - final DistributionSet ds = entityManager.merge(action.getDistributionSet()); - targetInfo.setInstalledDistributionSet(ds); - if (target.getAssignedDistributionSet() != null && targetInfo.getInstalledDistributionSet() != null && target - .getAssignedDistributionSet().getId().equals(targetInfo.getInstalledDistributionSet().getId())) { - targetInfo.setUpdateStatus(TargetUpdateStatus.IN_SYNC); - targetInfo.setInstallationDate(System.currentTimeMillis()); - } else { - targetInfo.setUpdateStatus(TargetUpdateStatus.PENDING); - targetInfo.setInstallationDate(System.currentTimeMillis()); - } - targetInfoRepository.save(targetInfo); - entityManager.detach(ds); - } - - /** - * Updates attributes of the controller. - * - * @param targetid - * to update - * @param data - * to insert - * - * @return updated {@link Target} - * - * @throws EntityNotFoundException - * if target that has to be updated could not be found - * @throws ToManyAttributeEntriesException - * if maximum - */ - @Modifying - @NotNull - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @PreAuthorize(SpringEvalExpressions.IS_CONTROLLER) - public Target updateControllerAttributes(@NotEmpty final String targetid, @NotNull final Map data) { - final Target target = targetRepository.findByControllerId(targetid); - - if (target == null) { - throw new EntityNotFoundException(targetid); - } - - target.getTargetInfo().getControllerAttributes().putAll(data); - - if (target.getTargetInfo().getControllerAttributes().size() > securityProperties.getDos() - .getMaxAttributeEntriesPerTarget()) { - LOG_DOS.info("Target tries to insert more than the allowed number of entries ({}). DOS attack anticipated!", - securityProperties.getDos().getMaxAttributeEntriesPerTarget()); - throw new ToManyAttributeEntriesException( - String.valueOf(securityProperties.getDos().getMaxAttributeEntriesPerTarget())); - } - - target.getTargetInfo().setLastTargetQuery(System.currentTimeMillis()); - target.getTargetInfo().setRequestControllerAttributes(false); - return targetRepository.save(target); - } - - /** - * Registers retrieved status for given {@link Target} and {@link Action} if - * it does not exist yet. - * - * @param action - * to the handle status for - * @param target - * to the handle status for - * @param message - * for the status - * @return the update action in case the status has been changed to - * {@link Status#RETRIEVED} - */ - @Modifying - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @PreAuthorize(SpringEvalExpressions.IS_CONTROLLER) - public Action registerRetrieved(final Action action, final String message) { - return handleRegisterRetrieved(action, message); - } - - /** - * Registers retrieved status for given {@link Target} and {@link Action} if - * it does not exist yet. - * - * @param action - * to the handle status for - * @param message - * for the status - * @return the updated action in case the status has been changed to - * {@link Status#RETRIEVED} - */ - public Action handleRegisterRetrieved(final Action action, final String message) { - // do a manual query with CriteriaBuilder to avoid unnecessary field - // queries and an extra - // count query made by spring-data when using pageable requests, we - // don't need an extra count - // query, we just want to check if the last action status is a retrieved - // or not. - final CriteriaBuilder cb = entityManager.getCriteriaBuilder(); - final CriteriaQuery queryActionStatus = cb.createQuery(Object[].class); - final Root actionStatusRoot = queryActionStatus.from(ActionStatus.class); - final CriteriaQuery query = queryActionStatus - .multiselect(actionStatusRoot.get(ActionStatus_.id), actionStatusRoot.get(ActionStatus_.status)) - .where(cb.equal(actionStatusRoot.get(ActionStatus_.action), action)) - .orderBy(cb.desc(actionStatusRoot.get(ActionStatus_.id))); - final List resultList = entityManager.createQuery(query).setFirstResult(0).setMaxResults(1) - .getResultList(); - - // if the latest status is not in retrieve state then we add a retrieved - // state again, we want - // to document a deployment retrieved status and a cancel retrieved - // status, but multiple - // retrieves after the other we don't want to store to protect to - // overflood action status in - // case controller retrieves a action multiple times. - if (resultList.isEmpty() || resultList.get(0)[1] != Status.RETRIEVED) { - // document that the status has been retrieved - actionStatusRepository - .save(new ActionStatus(action, Status.RETRIEVED, System.currentTimeMillis(), message)); - - // don't change the action status itself in case the action is in - // canceling state otherwise - // we modify the action status and the controller won't get the - // cancel job anymore. - if (!action.isCancelingOrCanceled()) { - final Action actionMerge = entityManager.merge(action); - actionMerge.setStatus(Status.RETRIEVED); - return actionRepository.save(actionMerge); - } - } - return action; - } - - /** - * @param statusMessage - */ - @PreAuthorize(SpringEvalExpressions.IS_CONTROLLER) - @Modifying - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - public void addActionStatusMessage(final ActionStatus statusMessage) { - actionStatusRepository.save(statusMessage); - } - - /** - * An direct access to the security token of an - * {@link Target#getSecurityToken()} without authorization. This is - * necessary to be able to access the security-token without any - * security-context information because the security-token is used for - * authentication. - * - * @param controllerId - * the ID of the controller to retrieve the security token for - * @return the security context of the target, in case no target exists for - * the given controllerId {@code null} is returned - */ - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - public String getSecurityTokenByControllerId(final String controllerId) { - final Target target = targetRepository.findByControllerId(controllerId); - return target != null ? target.getSecurityToken() : null; - } -} +} \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java index 805b66d75..789383ce7 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java @@ -9,114 +9,38 @@ package org.eclipse.hawkbit.repository; import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.function.Function; import java.util.stream.Collectors; -import javax.persistence.EntityManager; -import javax.persistence.criteria.CriteriaBuilder; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Join; -import javax.persistence.criteria.JoinType; -import javax.persistence.criteria.ListJoin; -import javax.persistence.criteria.Root; import javax.validation.constraints.NotNull; -import org.eclipse.hawkbit.Constants; -import org.eclipse.hawkbit.eventbus.event.CancelTargetAssignmentEvent; -import org.eclipse.hawkbit.eventbus.event.TargetAssignDistributionSetEvent; -import org.eclipse.hawkbit.eventbus.event.TargetInfoUpdateEvent; -import org.eclipse.hawkbit.executor.AfterTransactionCommitExecutor; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; import org.eclipse.hawkbit.repository.exception.CancelActionNotAllowedException; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; -import org.eclipse.hawkbit.repository.exception.ForceQuitActionNotAllowedException; -import org.eclipse.hawkbit.repository.exception.IncompleteDistributionSetException; +import org.eclipse.hawkbit.repository.jpa.TargetWithActionType; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.ActionType; -import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; import org.eclipse.hawkbit.repository.model.ActionWithStatusCount; -import org.eclipse.hawkbit.repository.model.Action_; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetType; -import org.eclipse.hawkbit.repository.model.DistributionSet_; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.RolloutGroup; -import org.eclipse.hawkbit.repository.model.Rollout_; -import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.repository.model.Target; -import org.eclipse.hawkbit.repository.model.TargetInfo; -import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; -import org.eclipse.hawkbit.repository.specifications.TargetSpecifications; import org.hibernate.validator.constraints.NotEmpty; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.cache.annotation.CacheEvict; -import org.springframework.data.domain.AuditorAware; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; import org.springframework.data.jpa.domain.Specification; -import org.springframework.data.jpa.repository.Modifying; import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Isolation; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.validation.annotation.Validated; - -import com.google.common.collect.Lists; -import com.google.common.eventbus.EventBus; /** - * Business service facade for managing all deployment related data and actions. - * + * A DeploymentManagement service provides operations for the deployment of + * {@link DistributionSet}s to {@link Target}s. * */ -@Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) -@Validated -@Service -public class DeploymentManagement { - private static final Logger LOG = LoggerFactory.getLogger(DeploymentManagement.class); - - @Autowired - private EntityManager entityManager; - - @Autowired - private ActionRepository actionRepository; - - @Autowired - private DistributionSetRepository distributoinSetRepository; - - @Autowired - private SoftwareModuleRepository softwareModuleRepository; - - @Autowired - private TargetRepository targetRepository; - - @Autowired - private ActionStatusRepository actionStatusRepository; - - @Autowired - private TargetManagement targetManagement; - - @Autowired - private TargetInfoRepository targetInfoRepository; - - @Autowired - private AuditorAware auditorProvider; - - @Autowired - private EventBus eventBus; - - @Autowired - private AfterTransactionCommitExecutor afterCommit; +public interface DeploymentManagement { /** * method assigns the {@link DistributionSet} to all {@link Target}s. @@ -134,19 +58,81 @@ public class DeploymentManagement { * {@link SoftwareModuleType} are not assigned as define by the * {@link DistributionSetType}. * */ - @Transactional(isolation = Isolation.READ_COMMITTED) - @Modifying @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_UPDATE_TARGET) - @CacheEvict(value = { "distributionUsageAssigned" }, allEntries = true) - public DistributionSetAssignmentResult assignDistributionSet(@NotNull final DistributionSet pset, - @NotEmpty final List targets) { - - return assignDistributionSetByTargetId(pset, - targets.stream().map(target -> target.getControllerId()).collect(Collectors.toList()), - ActionType.FORCED, Action.NO_FORCE_TIME); + DistributionSetAssignmentResult assignDistributionSet(@NotNull DistributionSet pset, + @NotEmpty List targets); + /** + * method assigns the {@link DistributionSet} to all {@link Target}s by + * their IDs with a specific {@link ActionType} and {@code forcetime}. + * + * @param dsID + * the ID of the distribution set to assign + * @param actionType + * the type of the action to apply on the assignment + * @param forcedTimestamp + * the time when the action should be forced, only necessary for + * {@link ActionType#TIMEFORCED} + * @param targetIDs + * the IDs of the target to assign the distribution set + * @return the assignment result + * + * @throw IncompleteDistributionSetException if mandatory + * {@link SoftwareModuleType} are not assigned as define by the + * {@link DistributionSetType}. + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_UPDATE_TARGET) + // Exception squid:S2095: see + // https://jira.sonarsource.com/browse/SONARJAVA-1478 + @SuppressWarnings({ "squid:S2095" }) + default DistributionSetAssignmentResult assignDistributionSet(@NotNull final Long dsID, final ActionType actionType, + final long forcedTimestamp, @NotEmpty final String... targetIDs) { + return assignDistributionSet(dsID, Arrays.stream(targetIDs) + .map(t -> new TargetWithActionType(t, actionType, forcedTimestamp)).collect(Collectors.toList())); } + /** + * method assigns the {@link DistributionSet} to all {@link Target}s by + * their IDs with a specific {@link ActionType} and {@code forcetime}. + * + * @param dsID + * the ID of the distribution set to assign + * @param targets + * a list of all targets and their action type + * @return the assignment result + * + * @throw IncompleteDistributionSetException if mandatory + * {@link SoftwareModuleType} are not assigned as define by the + * {@link DistributionSetType}. + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_UPDATE_TARGET) + DistributionSetAssignmentResult assignDistributionSet(@NotNull Long dsID, + @NotEmpty List targets); + + // TODO document: why are rollouts in the signature ? can all the parameters + // be null or the list empty? + /** + * method assigns the {@link DistributionSet} to all {@link Target}s by + * their IDs with a specific {@link ActionType} and {@code forcetime}. + * + * @param dsID + * the ID of the distribution set to assign + * @param targets + * a list of all targets and their action type + * @param rollout + * the rollout for this assignment + * @param rolloutGroup + * the rollout group for this assignment + * @return the assignment result + * + * @throw IncompleteDistributionSetException if mandatory + * {@link SoftwareModuleType} are not assigned as define by the + * {@link DistributionSetType}. + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_UPDATE_TARGET) + DistributionSetAssignmentResult assignDistributionSet(@NotNull Long dsID, + @NotEmpty List targets, Rollout rollout, RolloutGroup rolloutGroup); + /** * method assigns the {@link DistributionSet} to all {@link Target}s by * their IDs. @@ -167,338 +153,12 @@ public class DeploymentManagement { * {@link SoftwareModuleType} are not assigned as define by the * {@link DistributionSetType}. */ - @Modifying - @Transactional(isolation = Isolation.READ_COMMITTED) @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_UPDATE_TARGET) - @CacheEvict(value = { "distributionUsageAssigned" }, allEntries = true) - public DistributionSetAssignmentResult assignDistributionSet(@NotNull final Long dsID, + default DistributionSetAssignmentResult assignDistributionSet(@NotNull final Long dsID, @NotEmpty final String... targetIDs) { return assignDistributionSet(dsID, ActionType.FORCED, Action.NO_FORCE_TIME, targetIDs); } - /** - * method assigns the {@link DistributionSet} to all {@link Target}s by - * their IDs with a specific {@link ActionType} and {@code forcetime}. - * - * @param dsID - * the ID of the distribution set to assign - * @param actionType - * the type of the action to apply on the assignment - * @param forcedTimestamp - * the time when the action should be forced, only necessary for - * {@link ActionType#TIMEFORCED} - * @param targetIDs - * the IDs of the target to assign the distribution set - * @return the assignment result - * - * @throw IncompleteDistributionSetException if mandatory - * {@link SoftwareModuleType} are not assigned as define by the - * {@link DistributionSetType}. - */ - @Modifying - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_UPDATE_TARGET) - @CacheEvict(value = { "distributionUsageAssigned" }, allEntries = true) - // Exception squid:S2095: see - // https://jira.sonarsource.com/browse/SONARJAVA-1478 - @SuppressWarnings({ "squid:S2095" }) - public DistributionSetAssignmentResult assignDistributionSet(@NotNull final Long dsID, final ActionType actionType, - final long forcedTimestamp, @NotEmpty final String... targetIDs) { - return assignDistributionSet(dsID, Arrays.stream(targetIDs) - .map(t -> new TargetWithActionType(t, actionType, forcedTimestamp)).collect(Collectors.toList())); - } - - /** - * method assigns the {@link DistributionSet} to all {@link Target}s by - * their IDs with a specific {@link ActionType} and {@code forcetime}. - * - * @param dsID - * the ID of the distribution set to assign - * @param targets - * a list of all targets and their action type - * @return the assignment result - * - * @throw IncompleteDistributionSetException if mandatory - * {@link SoftwareModuleType} are not assigned as define by the - * {@link DistributionSetType}. - */ - @Modifying - @Transactional(isolation = Isolation.READ_COMMITTED) - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_UPDATE_TARGET) - @CacheEvict(value = { "distributionUsageAssigned" }, allEntries = true) - public DistributionSetAssignmentResult assignDistributionSet(@NotNull final Long dsID, - final List targets) { - final DistributionSet set = distributoinSetRepository.findOne(dsID); - if (set == null) { - throw new EntityNotFoundException( - String.format("no %s with id %d found", DistributionSet.class.getSimpleName(), dsID)); - } - - return assignDistributionSetToTargets(set, targets, null, null); - } - - /** - * method assigns the {@link DistributionSet} to all {@link Target}s by - * their IDs with a specific {@link ActionType} and {@code forcetime}. - * - * @param dsID - * the ID of the distribution set to assign - * @param targets - * a list of all targets and their action type - * @param rollout - * the rollout for this assignment - * @param rolloutGroup - * the rollout group for this assignment - * @return the assignment result - * - * @throw IncompleteDistributionSetException if mandatory - * {@link SoftwareModuleType} are not assigned as define by the - * {@link DistributionSetType}. - */ - @Modifying - @Transactional(isolation = Isolation.READ_COMMITTED) - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_UPDATE_TARGET) - @CacheEvict(value = { "distributionUsageAssigned" }, allEntries = true) - public DistributionSetAssignmentResult assignDistributionSet(@NotNull final Long dsID, - final List targets, final Rollout rollout, final RolloutGroup rolloutGroup) { - final DistributionSet set = distributoinSetRepository.findOne(dsID); - if (set == null) { - throw new EntityNotFoundException( - String.format("no %s with id %d found", DistributionSet.class.getSimpleName(), dsID)); - } - - return assignDistributionSetToTargets(set, targets, rollout, rolloutGroup); - } - - /** - * method assigns the {@link DistributionSet} to all {@link Target}s by - * their IDs with a specific {@link ActionType} and {@code forcetime}. - * - * @param dsID - * the ID of the distribution set to assign - * @param targets - * a list of all targets and their action type - * @param rollout - * the rollout for this assignment - * @param rolloutGroup - * the rollout group for this assignment - * @return the assignment result - * - * @throw IncompleteDistributionSetException if mandatory - * {@link SoftwareModuleType} are not assigned as define by the - * {@link DistributionSetType}. - */ - private DistributionSetAssignmentResult assignDistributionSetToTargets(@NotNull final DistributionSet set, - final List targetsWithActionType, final Rollout rollout, - final RolloutGroup rolloutGroup) { - - if (!set.isComplete()) { - throw new IncompleteDistributionSetException( - "Distribution set of type " + set.getType().getKey() + " is incomplete: " + set.getId()); - } - - final List controllerIDs = targetsWithActionType.stream().map(TargetWithActionType::getTargetId) - .collect(Collectors.toList()); - - LOG.debug("assignDistribution({}) to {} targets", set, controllerIDs.size()); - - final Map targetsWithActionMap = targetsWithActionType.stream() - .collect(Collectors.toMap(TargetWithActionType::getTargetId, Function.identity())); - - // split tIDs length into max entries in-statement because many database - // have constraint of max entries in in-statements e.g. Oracle with - // maximum 1000 elements, so we need to split the entries here and - // execute multiple statements we take the target only into account if - // the requested operation is no duplicate of a previous one - final List targets = Lists.partition(controllerIDs, Constants.MAX_ENTRIES_IN_STATEMENT).stream() - .map(ids -> targetRepository - .findAll(TargetSpecifications.hasControllerIdAndAssignedDistributionSetIdNot(ids, set.getId()))) - .flatMap(t -> t.stream()).collect(Collectors.toList()); - - if (targets.isEmpty()) { - // detaching as it is not necessary to persist the set itself - entityManager.detach(set); - // return with nothing as all targets had the DS already assigned - return new DistributionSetAssignmentResult(Collections.emptyList(), 0, targetsWithActionType.size(), - Collections.emptyList(), targetManagement); - } - - final List> targetIds = Lists.partition( - targets.stream().map(Target::getId).collect(Collectors.toList()), Constants.MAX_ENTRIES_IN_STATEMENT); - - // override all active actions and set them into canceling state, we - // need to remember which one we have been switched to canceling state - // because for targets which we have changed to canceling we don't want - // to publish the new action update event. - final Set targetIdsCancellList = new HashSet<>(); - targetIds.forEach(ids -> targetIdsCancellList.addAll(overrideObsoleteUpdateActions(ids))); - - // cancel all scheduled actions which are in-active, these actions were - // not active before and the manual assignment which has been done - // cancels the - targetIds.forEach(tIds -> actionRepository.switchStatus(Status.CANCELED, tIds, false, Status.SCHEDULED)); - - // set assigned distribution set and TargetUpdateStatus - final String currentUser; - if (auditorProvider != null) { - currentUser = auditorProvider.getCurrentAuditor(); - } else { - currentUser = null; - } - - targetIds.forEach(tIds -> targetRepository.setAssignedDistributionSet(set, System.currentTimeMillis(), - currentUser, tIds)); - targetIds.forEach(tIds -> targetInfoRepository.setTargetUpdateStatus(TargetUpdateStatus.PENDING, tIds)); - final Map targetIdsToActions = actionRepository - .save(targets.stream().map(t -> createTargetAction(targetsWithActionMap, t, set, rollout, rolloutGroup)) - .collect(Collectors.toList())) - .stream().collect(Collectors.toMap(a -> a.getTarget().getControllerId(), Function.identity())); - - // create initial action status when action is created so we remember - // the initial running status because we will change the status - // of the action itself and with this action status we have a nicer - // action history. - targetIdsToActions.values().forEach(action -> { - final ActionStatus actionStatus = new ActionStatus(); - actionStatus.setAction(action); - actionStatus.setOccurredAt(action.getCreatedAt()); - actionStatus.setStatus(Status.RUNNING); - actionStatusRepository.save(actionStatus); - }); - - // flush to get action IDs - entityManager.flush(); - // collect updated target and actions IDs in order to return them - final DistributionSetAssignmentResult result = new DistributionSetAssignmentResult( - targets.stream().map(target -> target.getControllerId()).collect(Collectors.toList()), targets.size(), - controllerIDs.size() - targets.size(), - targetIdsToActions.values().stream().map(Action::getId).collect(Collectors.toList()), targetManagement); - - LOG.debug("assignDistribution({}) finished {}", set, result); - - final List softwareModules = softwareModuleRepository.findByAssignedTo(set); - - // detaching as it is not necessary to persist the set itself - entityManager.detach(set); - - sendDistributionSetAssignmentEvent(targets, targetIdsCancellList, targetIdsToActions, softwareModules); - - return result; - } - - private void sendDistributionSetAssignmentEvent(final List targets, final Set targetIdsCancellList, - final Map targetIdsToActions, final List softwareModules) { - targets.stream().filter(t -> !!!targetIdsCancellList.contains(t.getId())) - .forEach(t -> assignDistributionSetEvent(t, targetIdsToActions.get(t.getControllerId()).getId(), - softwareModules)); - } - - private static Action createTargetAction(final Map targetsWithActionMap, - final Target target, final DistributionSet set, final Rollout rollout, final RolloutGroup rolloutGroup) { - final Action actionForTarget = new Action(); - final TargetWithActionType targetWithActionType = targetsWithActionMap.get(target.getControllerId()); - actionForTarget.setActionType(targetWithActionType.getActionType()); - actionForTarget.setForcedTime(targetWithActionType.getForceTime()); - actionForTarget.setActive(true); - actionForTarget.setStatus(Status.RUNNING); - actionForTarget.setTarget(target); - actionForTarget.setDistributionSet(set); - actionForTarget.setRollout(rollout); - actionForTarget.setRolloutGroup(rolloutGroup); - return actionForTarget; - } - - /** - * Sends the {@link TargetAssignDistributionSetEvent} for a specific target - * to the {@link EventBus}. - * - * @param target - * the Target which has been assigned to a distribution set - * @param actionId - * the action id of the assignment - * @param softwareModules - * the software modules which have been assigned - */ - private void assignDistributionSetEvent(final Target target, final Long actionId, - final List softwareModules) { - target.getTargetInfo().setUpdateStatus(TargetUpdateStatus.PENDING); - afterCommit.afterCommit(() -> { - eventBus.post(new TargetInfoUpdateEvent(target.getTargetInfo())); - eventBus.post(new TargetAssignDistributionSetEvent(target.getOptLockRevision(), target.getTenant(), - target.getControllerId(), actionId, softwareModules, target.getTargetInfo().getAddress(), - target.getSecurityToken())); - }); - } - - /** - * Removes {@link UpdateAction}s that are no longer necessary and sends - * cancellations to the controller. - * - * @param myTarget - * to override {@link UpdateAction}s - */ - private Set overrideObsoleteUpdateActions(final List targetsIds) { - - final Set cancelledTargetIds = new HashSet<>(); - - // Figure out if there are potential target/action combinations that - // need to be considered - // for cancelation - final List activeActions = actionRepository - .findByActiveAndTargetIdInAndActionStatusNotEqualToAndDistributionSetRequiredMigrationStep(targetsIds, - Action.Status.CANCELING); - activeActions.forEach(action -> { - action.setStatus(Status.CANCELING); - // document that the status has been retrieved - - actionStatusRepository.save(new ActionStatus(action, Status.CANCELING, System.currentTimeMillis(), - "manual cancelation requested")); - - cancelAssignDistributionSetEvent(action.getTarget(), action.getId()); - - cancelledTargetIds.add(action.getTarget().getId()); - }); - - actionRepository.save(activeActions); - - return cancelledTargetIds; - - } - - private DistributionSetAssignmentResult assignDistributionSetByTargetId(@NotNull final DistributionSet set, - @NotEmpty final List tIDs, final ActionType actionType, final long forcedTime) { - - return assignDistributionSetToTargets(set, tIDs.stream() - .map(t -> new TargetWithActionType(t, actionType, forcedTime)).collect(Collectors.toList()), null, - null); - - } - - /** - * Internal helper method used only inside service level. As a result is no - * additional security necessary. - * - * @param target - * to update - * @param status - * of the target - * @param setInstalledDate - * to set - * - * @return updated target - */ - Target updateTargetInfo(@NotNull final Target target, @NotNull final TargetUpdateStatus status, - final boolean setInstalledDate) { - final TargetInfo ts = target.getTargetInfo(); - ts.setUpdateStatus(status); - - if (setInstalledDate) { - ts.setInstallationDate(System.currentTimeMillis()); - } - targetInfoRepository.save(ts); - return entityManager.merge(target); - } - /** * Cancels given {@link Action} for given {@link Target}. The method will * immediately add a {@link ActionStatus.Status#CANCELED} status to the @@ -516,90 +176,32 @@ public class DeploymentManagement { * in case the given action is not active or is already a cancel * action */ - @Modifying - @Transactional(isolation = Isolation.READ_COMMITTED) @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET) - public Action cancelAction(@NotNull final Action action, @NotNull final Target target) { - LOG.debug("cancelAction({}, {})", action, target); - if (action.isCancelingOrCanceled()) { - throw new CancelActionNotAllowedException("Actions in canceling or canceled state cannot be canceled"); - } - final Action myAction = entityManager.merge(action); - - if (myAction.isActive()) { - LOG.debug("action ({}) was still active. Change to {}.", action, Status.CANCELING); - myAction.setStatus(Status.CANCELING); - - // document that the status has been retrieved - actionStatusRepository.save(new ActionStatus(myAction, Status.CANCELING, System.currentTimeMillis(), - "manual cancelation requested")); - final Action saveAction = actionRepository.save(myAction); - cancelAssignDistributionSetEvent(target, myAction.getId()); - - return saveAction; - } else { - throw new CancelActionNotAllowedException( - "Action [id: " + action.getId() + "] is not active and cannot be canceled"); - } - } + Action cancelAction(@NotNull Action action, @NotNull Target target); /** - * Sends the {@link CancelTargetAssignmentEvent} for a specific target to - * the {@link EventBus}. + * counts all actions associated to a specific target. * + * @param spec + * the specification to filter the count result * @param target - * the Target which has been assigned to a distribution set - * @param actionId - * the action id of the assignment + * the target associated to the actions to count + * @return the count value of found actions associated to the target */ - private void cancelAssignDistributionSetEvent(final Target target, final Long actionId) { - afterCommit.afterCommit(() -> eventBus.post(new CancelTargetAssignmentEvent(target.getOptLockRevision(), - target.getTenant(), target.getControllerId(), actionId, target.getTargetInfo().getAddress()))); - } + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + Long countActionsByTarget(@NotNull Specification spec, @NotNull Target target); /** - * Force cancels given {@link Action} for given {@link Target}. Force - * canceling means that the action is marked as canceled on the SP server - * and a cancel request is sent to the target. But however it's not tracked, - * if the targets handles the cancel request or not. + * counts all actions associated to a specific target. * - * @param action - * to be canceled * @param target - * for which the action needs cancellation - * - * @return generated {@link CancelAction} or null if not in - * {@link Target#getActiveActions()}. - * @throws CancelActionNotAllowedException - * in case the given action is not active + * the target associated to the actions to count + * @return the count value of found actions associated to the target */ - @Modifying - @Transactional(isolation = Isolation.READ_COMMITTED) - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET) - public Action forceQuitAction(@NotNull final Action action) { - final Action mergedAction = entityManager.merge(action); - - if (!mergedAction.isCancelingOrCanceled()) { - throw new ForceQuitActionNotAllowedException( - "Action [id: " + action.getId() + "] is not canceled yet and cannot be force quit"); - } - - if (!mergedAction.isActive()) { - throw new ForceQuitActionNotAllowedException( - "Action [id: " + action.getId() + "] is not active and cannot be force quit"); - } - - LOG.warn("action ({}) was still activ and has been force quite.", action); - - // document that the status has been retrieved - actionStatusRepository.save(new ActionStatus(mergedAction, Status.CANCELED, System.currentTimeMillis(), - "A force quit has been performed.")); - - successCancellation(mergedAction); - - return actionRepository.save(mergedAction); - } + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + Long countActionsByTarget(@NotNull Target target); + // TODO: validate parameters /** * Creates an action entry into the action repository. In case of existing * scheduled actions the scheduled actions gets canceled. A scheduled action @@ -614,96 +216,13 @@ public class DeploymentManagement { * @param forcedTime * the forcedTime of the action * @param rollout - * the rollout for this action + * the roll out for this action * @param rolloutGroup - * the rolloutgroup for this action + * the roll out group for this action */ - @Modifying - @Transactional(isolation = Isolation.READ_COMMITTED) @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET) - public void createScheduledAction(final List targets, final DistributionSet distributionSet, - final ActionType actionType, final long forcedTime, final Rollout rollout, - final RolloutGroup rolloutGroup) { - // cancel all current scheduled actions for this target. E.g. an action - // is already scheduled and a next action is created then cancel the - // current scheduled action to cancel. E.g. a new scheduled action is - // created. - final List targetIds = targets.stream().map(t -> t.getId()).collect(Collectors.toList()); - actionRepository.switchStatus(Action.Status.CANCELED, targetIds, false, Action.Status.SCHEDULED); - targets.forEach(target -> { - final Action action = new Action(); - action.setTarget(target); - action.setActive(false); - action.setDistributionSet(distributionSet); - action.setActionType(actionType); - action.setForcedTime(forcedTime); - action.setStatus(Status.SCHEDULED); - action.setRollout(rollout); - action.setRolloutGroup(rolloutGroup); - actionRepository.save(action); - }); - } - - /** - * Starting an action which is scheduled, e.g. in case of rollout a - * scheduled action must be started now. - * - * @param action - * the action to start now. - * @return the action which has been started - */ - @Modifying - @Transactional(isolation = Isolation.READ_COMMITTED) - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET + SpringEvalExpressions.HAS_AUTH_OR - + SpringEvalExpressions.IS_SYSTEM_CODE) - public Action startScheduledAction(@NotNull final Action action) { - - final Action mergedAction = entityManager.merge(action); - final Target mergedTarget = entityManager.merge(action.getTarget()); - - // check if we need to override running update actions - final Set overrideObsoleteUpdateActions = overrideObsoleteUpdateActions( - Collections.singletonList(action.getTarget().getId())); - - final boolean hasDistributionSetAlreadyAssigned = targetRepository - .count(TargetSpecifications.hasControllerIdAndAssignedDistributionSetIdNot( - Collections.singletonList(mergedTarget.getControllerId()), - action.getDistributionSet().getId())) == 0; - if (hasDistributionSetAlreadyAssigned) { - // the target has already the distribution set assigned, we don't - // need to start the scheduled action, just finished it. - mergedAction.setStatus(Status.FINISHED); - mergedAction.setActive(false); - return actionRepository.save(mergedAction); - } - - mergedAction.setActive(true); - mergedAction.setStatus(Status.RUNNING); - final Action savedAction = actionRepository.save(mergedAction); - - final ActionStatus actionStatus = new ActionStatus(); - actionStatus.setAction(action); - actionStatus.setOccurredAt(action.getCreatedAt()); - actionStatus.setStatus(Status.RUNNING); - actionStatusRepository.save(actionStatus); - - mergedTarget.setAssignedDistributionSet(action.getDistributionSet()); - final TargetInfo targetInfo = mergedTarget.getTargetInfo(); - targetInfo.setUpdateStatus(TargetUpdateStatus.PENDING); - targetRepository.save(mergedTarget); - targetInfoRepository.save(targetInfo); - - // in case we canceled an action before for this target, then don't fire - // assignment event - if (!overrideObsoleteUpdateActions.contains(savedAction.getId())) { - final List softwareModules = softwareModuleRepository - .findByAssignedTo(action.getDistributionSet()); - // send distribution set assignment event - - assignDistributionSetEvent(mergedAction.getTarget(), mergedAction.getId(), softwareModules); - } - return savedAction; - } + void createScheduledAction(List targets, DistributionSet distributionSet, ActionType actionType, + long forcedTime, Rollout rollout, RolloutGroup rolloutGroup); /** * Get the {@link Action} entity for given actionId. @@ -713,269 +232,19 @@ public class DeploymentManagement { * @return the corresponding {@link Action} */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - public Action findAction(@NotNull final Long actionId) { - return actionRepository.findOne(actionId); - } + Action findAction(@NotNull Long actionId); /** - * Get the {@link Action} entity for given actionId with all lazy attributes - * (i.e. distributionSet, target, target.assignedDs). + * Retrieves all actions for a specific rollout and in a specific status. * - * @param actionId - * to be id of the action - * @return the corresponding {@link Action} + * @param rollout + * the rollout the actions beglong to + * @param actionStatus + * the status of the actions + * @return the actions referring a specific rollout an in a specific status */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - public Action findActionWithDetails(@NotNull final Long actionId) { - return actionRepository.findById(actionId); - } - - /** - * Retrieves all {@link Action}s of a specific target. - * - * @param pageable - * pagination parameter - * @param target - * of which the actions have to be searched - * @return a paged list of actions associated with the given target - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - public Slice findActionsByTarget(final Pageable pageable, final Target target) { - return actionRepository.findByTarget(pageable, target); - } - - /** - * Retrieves all {@link Action}s of a specific target ordered by action ID. - * - * @param target - * the target associated with the actions - * @return a list of actions associated with the given target ordered by - * action ID - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - public List findActionsByTarget(final Target target) { - return actionRepository.findByTarget(target); - } - - /** - * Retrieves all {@link Action}s of a specific target ordered by action ID. - * - * @param target - * the target associated with the actions - * @return a list of actions associated with the given target ordered by - * action ID - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - public List findActionsWithStatusCountByTargetOrderByIdDesc(final Target target) { - final CriteriaBuilder cb = entityManager.getCriteriaBuilder(); - final CriteriaQuery query = cb.createQuery(ActionWithStatusCount.class); - final Root actionRoot = query.from(Action.class); - final ListJoin actionStatusJoin = actionRoot.join(Action_.actionStatus, JoinType.LEFT); - final Join actionDsJoin = actionRoot.join(Action_.distributionSet); - final Join actionRolloutJoin = actionRoot.join(Action_.rollout, JoinType.LEFT); - - final CriteriaQuery multiselect = query.distinct(true).multiselect( - actionRoot.get(Action_.id), actionRoot.get(Action_.actionType), actionRoot.get(Action_.active), - actionRoot.get(Action_.forcedTime), actionRoot.get(Action_.status), actionRoot.get(Action_.createdAt), - actionRoot.get(Action_.lastModifiedAt), actionDsJoin.get(DistributionSet_.id), - actionDsJoin.get(DistributionSet_.name), actionDsJoin.get(DistributionSet_.version), - cb.count(actionStatusJoin), actionRolloutJoin.get(Rollout_.name)); - multiselect.where(cb.equal(actionRoot.get(Action_.target), target)); - multiselect.orderBy(cb.desc(actionRoot.get(Action_.id))); - multiselect.groupBy(actionRoot.get(Action_.id)); - return entityManager.createQuery(multiselect).getResultList(); - } - - /** - * Retrieves all {@link Action}s assigned to a specific {@link Target} and a - * given specification. - * - * @param specifiction - * the specification to narrow down the search - * @param target - * the target which must be assigned to the actions - * @param pageable - * the page request - * @return a slice of actions assigned to the specific target and the - * specification - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - public Slice findActionsByTarget(final Specification specifiction, final Target target, - final Pageable pageable) { - - return actionRepository.findAll((Specification) (root, query, cb) -> cb - .and(specifiction.toPredicate(root, query, cb), cb.equal(root.get(Action_.target), target)), pageable); - } - - /** - * Retrieves all {@link Action}s which are referring the given - * {@link Target}. - * - * @param foundTarget - * the target to find actions for - * @param pageable - * the pageable request to limit, sort the actions - * @return a slice of actions found for a specific target - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - public Slice findActionsByTarget(final Target foundTarget, final Pageable pageable) { - return actionRepository.findByTarget(pageable, foundTarget); - } - - /** - * Retrieves all active {@link Action}s of a specific target ordered by - * action ID. - * - * @param pageable - * the pagination parameter - * @param target - * the target associated with the actions - * @return a paged list of actions associated with the given target - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - public Page findActiveActionsByTarget(final Pageable pageable, final Target target) { - return actionRepository.findByActiveAndTarget(pageable, target, true); - } - - /** - * Retrieves all active {@link Action}s of a specific target ordered by - * action ID. - * - * @param target - * the target associated with the actions - * @return a list of actions associated with the given target - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - public List findActiveActionsByTarget(final Target target) { - return actionRepository.findByActiveAndTarget(target, true); - } - - /** - * Retrieves all inactive {@link Action}s of a specific target ordered by - * action ID. - * - * @param target - * the target associated with the actions - * @return a list of actions associated with the given target - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - public List findInActiveActionsByTarget(final Target target) { - return actionRepository.findByActiveAndTarget(target, false); - } - - /** - * Retrieves all inactive {@link Action}s of a specific target ordered by - * action ID. - * - * @param pageable - * the pagination parameter - * @param target - * the target associated with the actions - * @return a paged list of actions associated with the given target - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - public Page findInActiveActionsByTarget(final Pageable pageable, final Target target) { - return actionRepository.findByActiveAndTarget(pageable, target, false); - } - - /** - * counts all actions associated to a specific target. - * - * @param target - * the target associated to the actions to count - * @return the count value of found actions associated to the target - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - public Long countActionsByTarget(@NotNull final Target target) { - return actionRepository.countByTarget(target); - } - - /** - * counts all actions associated to a specific target. - * - * @param spec - * the specification to filter the count result - * @param target - * the target associated to the actions to count - * @return the count value of found actions associated to the target - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - public Long countActionsByTarget(@NotNull final Specification spec, @NotNull final Target target) { - return actionRepository.count((root, query, cb) -> cb.and(spec.toPredicate(root, query, cb), - cb.equal(root.get(Action_.target), target))); - } - - /** - * Updates a {@link TargetAction} and forces the {@link TargetAction} if - * it's not already forced. - * - * @param targetId - * the ID of the target - * @param actionId - * the ID of the action - * @return the updated or the found {@link TargetAction} - */ - @Modifying - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET) - public Action forceTargetAction(final Long actionId) { - final Action action = actionRepository.findOne(actionId); - if (action != null && !action.isForced()) { - action.setActionType(ActionType.FORCED); - return actionRepository.save(action); - } - return action; - } - - /** - * Retrieves all the {@link ActionStatus} entries of the given - * {@link Action} and {@link Target}. - * - * @param pageReq - * pagination parameter - * @param action - * to be filtered on - * @param withMessages - * to true if {@link ActionStatus#getMessages()} - * need to be fetched. - * @return the corresponding {@link Page} of {@link ActionStatus} - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - public Page findActionStatusByAction(final Pageable pageReq, final Action action, - final boolean withMessages) { - if (withMessages) { - return actionStatusRepository.getByAction(pageReq, action); - } else { - return actionStatusRepository.findByAction(pageReq, action); - } - } - - /** - * This method is called, when cancellation has been successful. It sets the - * action to canceled, resets the meta data of the target and in case there - * is a new action this action is triggered. - * - * @param action - * the action which is set to canceled - */ - void successCancellation(final Action action) { - - // set action inactive - action.setActive(false); - action.setStatus(Status.CANCELED); - - final Target target = action.getTarget(); - final List nextActiveActions = actionRepository.findByTargetAndActiveOrderByIdAsc(target, true).stream() - .filter(a -> !a.getId().equals(action.getId())).collect(Collectors.toList()); - - if (nextActiveActions.isEmpty()) { - target.setAssignedDistributionSet(target.getTargetInfo().getInstalledDistributionSet()); - updateTargetInfo(target, TargetUpdateStatus.IN_SYNC, false); - } else { - target.setAssignedDistributionSet(nextActiveActions.get(0).getDistributionSet()); - } - targetManagement.updateTarget(target); - } + List findActionsByRolloutAndStatus(@NotNull Rollout rollout, @NotNull Action.Status actionStatus); /** * Retrieving all actions referring to a given rollout with a specific @@ -994,22 +263,191 @@ public class DeploymentManagement { */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET + SpringEvalExpressions.HAS_AUTH_OR + SpringEvalExpressions.IS_SYSTEM_CODE) - public List findActionsByRolloutGroupParentAndStatus(final Rollout rollout, - final RolloutGroup rolloutGroupParent, final Action.Status actionStatus) { - return actionRepository.findByRolloutAndRolloutGroupParentAndStatus(rollout, rolloutGroupParent, actionStatus); - } + List findActionsByRolloutGroupParentAndStatus(@NotNull Rollout rollout, + @NotNull RolloutGroup rolloutGroupParent, @NotNull Action.Status actionStatus); /** - * Retrieves all actions for a specific rollout and in a specific status. + * Retrieves all {@link Action}s of a specific target. * - * @param rollout - * the rollout the actions beglong to - * @param actionStatus - * the status of the actions - * @return the actions referring a specific rollout an in a specific status + * @param pageable + * pagination parameter + * @param target + * of which the actions have to be searched + * @return a paged list of actions associated with the given target */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - public List findActionsByRolloutAndStatus(final Rollout rollout, final Action.Status actionStatus) { - return actionRepository.findByRolloutAndStatus(rollout, actionStatus); - } -} + Slice findActionsByTarget(@NotNull Pageable pageable, @NotNull Target target); + + /** + * Retrieves all {@link Action}s assigned to a specific {@link Target} and a + * given specification. + * + * @param specifiction + * the specification to narrow down the search + * @param target + * the target which must be assigned to the actions + * @param pageable + * the page request + * @return a slice of actions assigned to the specific target and the + * specification + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + Slice findActionsByTarget(@NotNull Specification specifiction, @NotNull Target target, + @NotNull Pageable pageable); + + /** + * Retrieves all {@link Action}s of a specific target ordered by action ID. + * + * @param target + * the target associated with the actions + * @return a list of actions associated with the given target ordered by + * action ID + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + List findActionsByTarget(@NotNull Target target); + + /** + * Retrieves all {@link Action}s which are referring the given + * {@link Target}. + * + * @param foundTarget + * the target to find actions for + * @param pageable + * the pageable request to limit, sort the actions + * @return a slice of actions found for a specific target + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + Slice findActionsByTarget(@NotNull Target foundTarget, @NotNull Pageable pageable); + + /** + * Retrieves all the {@link ActionStatus} entries of the given + * {@link Action} and {@link Target}. + * + * @param pageReq + * pagination parameter + * @param action + * to be filtered on + * @param withMessages + * to true if {@link ActionStatus#getMessages()} + * need to be fetched. + * @return the corresponding {@link Page} of {@link ActionStatus} + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + Page findActionStatusByAction(@NotNull Pageable pageReq, @NotNull Action action, + boolean withMessages); + + /** + * Retrieves all {@link Action}s of a specific target ordered by action ID. + * + * @param target + * the target associated with the actions + * @return a list of actions associated with the given target ordered by + * action ID + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + List findActionsWithStatusCountByTargetOrderByIdDesc(@NotNull Target target); + + /** + * Get the {@link Action} entity for given actionId with all lazy attributes + * (i.e. distributionSet, target, target.assignedDs). + * + * @param actionId + * to be id of the action + * @return the corresponding {@link Action} + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + Action findActionWithDetails(@NotNull Long actionId); + + /** + * Retrieves all active {@link Action}s of a specific target ordered by + * action ID. + * + * @param pageable + * the pagination parameter + * @param target + * the target associated with the actions + * @return a paged list of actions associated with the given target + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + Page findActiveActionsByTarget(@NotNull Pageable pageable, @NotNull Target target); + + /** + * Retrieves all active {@link Action}s of a specific target ordered by + * action ID. + * + * @param target + * the target associated with the actions + * @return a list of actions associated with the given target + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + List findActiveActionsByTarget(@NotNull Target target); + + /** + * Retrieves all inactive {@link Action}s of a specific target ordered by + * action ID. + * + * @param pageable + * the pagination parameter + * @param target + * the target associated with the actions + * @return a paged list of actions associated with the given target + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + Page findInActiveActionsByTarget(@NotNull Pageable pageable, @NotNull Target target); + + /** + * Retrieves all inactive {@link Action}s of a specific target ordered by + * action ID. + * + * @param target + * the target associated with the actions + * @return a list of actions associated with the given target + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + List findInActiveActionsByTarget(@NotNull Target target); + + /** + * Force cancels given {@link Action} for given {@link Target}. Force + * canceling means that the action is marked as canceled on the SP server + * and a cancel request is sent to the target. But however it's not tracked, + * if the targets handles the cancel request or not. + * + * @param action + * to be canceled + * @param target + * for which the action needs cancellation + * + * @return generated {@link CancelAction} or null if not in + * {@link Target#getActiveActions()}. + * @throws CancelActionNotAllowedException + * in case the given action is not active + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET) + Action forceQuitAction(@NotNull Action action); + + /** + * Updates a {@link TargetAction} and forces the {@link TargetAction} if + * it's not already forced. + * + * @param targetId + * the ID of the target + * @param actionId + * the ID of the action + * @return the updated or the found {@link TargetAction} + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET) + Action forceTargetAction(@NotNull Long actionId); + + /** + * Starting an action which is scheduled, e.g. in case of roll out a + * scheduled action must be started now. + * + * @param action + * the action to start now. + * @return the action which has been started + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET + SpringEvalExpressions.HAS_AUTH_OR + + SpringEvalExpressions.IS_SYSTEM_CODE) + Action startScheduledAction(@NotNull Action action); + +} \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetAssignmentResult.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetAssignmentResult.java index 85e707652..c79fb669d 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetAssignmentResult.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetAssignmentResult.java @@ -11,6 +11,7 @@ package org.eclipse.hawkbit.repository; import java.util.Collections; import java.util.List; +import org.eclipse.hawkbit.repository.jpa.TargetManagement; import org.eclipse.hawkbit.repository.model.AssignmentResult; import org.eclipse.hawkbit.repository.model.Target; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java index db1ade60e..965ecd9f6 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java @@ -8,235 +8,163 @@ */ package org.eclipse.hawkbit.repository; -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.LinkedList; import java.util.List; import java.util.Set; import java.util.stream.Collectors; import javax.persistence.Entity; -import javax.persistence.EntityManager; import javax.validation.constraints.NotNull; -import org.eclipse.hawkbit.eventbus.event.DistributionSetTagAssigmentResultEvent; -import org.eclipse.hawkbit.executor.AfterTransactionCommitExecutor; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; import org.eclipse.hawkbit.repository.DistributionSetFilter.DistributionSetFilterBuilder; import org.eclipse.hawkbit.repository.exception.DistributionSetCreationFailedMissingMandatoryModuleException; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; -import org.eclipse.hawkbit.repository.exception.EntityLockedException; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.exception.EntityReadOnlyException; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetMetadata; -import org.eclipse.hawkbit.repository.model.DistributionSetMetadata_; import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult; import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.DistributionSetTypeElement; -import org.eclipse.hawkbit.repository.model.DistributionSet_; import org.eclipse.hawkbit.repository.model.DsMetadataCompositeKey; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.repository.model.Tag; import org.eclipse.hawkbit.repository.model.Target; -import org.eclipse.hawkbit.repository.specifications.DistributionSetSpecification; -import org.eclipse.hawkbit.repository.specifications.DistributionSetTypeSpecification; -import org.eclipse.hawkbit.repository.specifications.SpecificationsBuilder; import org.hibernate.validator.constraints.NotEmpty; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.domain.Specification; -import org.springframework.data.jpa.repository.Modifying; import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Isolation; import org.springframework.transaction.annotation.Transactional; -import org.springframework.validation.annotation.Validated; -import com.google.common.base.Strings; -import com.google.common.eventbus.EventBus; +public interface DistributionSetManagement { -/** - * Business facade for managing the {@link DistributionSet}s. - * - */ -@Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) -@Validated -@Service -public class DistributionSetManagement { - - @Autowired - private EntityManager entityManager; - - @Autowired - private DistributionSetRepository distributionSetRepository; - - @Autowired - private TagManagement tagManagement; - - @Autowired - private SystemManagement systemManagement; - - @Autowired - private DistributionSetTypeRepository distributionSetTypeRepository; - - @Autowired - private DistributionSetMetadataRepository distributionSetMetadataRepository; - - @Autowired - private ActionRepository actionRepository; - - @Autowired - private EventBus eventBus; - - @Autowired - private AfterTransactionCommitExecutor afterCommit; + // TODO rename/document the whole with details thing (document what the + // details are and maybe find a better name, e.g. with dependencies?) /** - * Find {@link DistributionSet} based on given ID including (lazy loaded) - * details, e.g. {@link DistributionSet#getAgentHub()}. - * - * Note: for performance reasons it is recommended to use - * {@link #findDistributionSetById(Long)} if details are not necessary. - * - * @param distid - * to look for. - * @return {@link DistributionSet} or null if it does not exist - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - public DistributionSet findDistributionSetByIdWithDetails(@NotNull final Long distid) { - return distributionSetRepository.findOne(DistributionSetSpecification.byId(distid)); - } - - /** - * Find {@link DistributionSet} based on given ID without details, e.g. - * {@link DistributionSet#getAgentHub()}. - * - * @param distid - * to look for. - * @return {@link DistributionSet} or null if it does not exist - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - public DistributionSet findDistributionSetById(@NotNull final Long distid) { - return distributionSetRepository.findOne(distid); - } - - /** - * {@link Entity} based method call for - * {@link #toggleTagAssignment(Collection, String)}. - * - * @param sets - * to toggle for - * @param tag - * to toggle - * @return {@link DistributionSetTagAssignmentResult} with all meta data of - * the assignment outcome. - */ - @Modifying - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @NotNull - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - public DistributionSetTagAssignmentResult toggleTagAssignment(@NotEmpty final List sets, - @NotNull final DistributionSetTag tag) { - return toggleTagAssignment(sets.stream().map(ds -> ds.getId()).collect(Collectors.toList()), tag.getName()); - } - - /** - * Toggles {@link DistributionSetTag} assignment to given - * {@link DistributionSet}s by means that if some (or all) of the targets in - * the list have the {@link Tag} not yet assigned, they will be. If all of - * theme have the tag already assigned they will be removed instead. - * - * @param dsIds - * to toggle for - * @param tagName - * to toggle - * @return {@link DistributionSetTagAssignmentResult} with all meta data of - * the assignment outcome. - */ - @Modifying - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @NotNull - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - public DistributionSetTagAssignmentResult toggleTagAssignment(@NotEmpty final Collection dsIds, - @NotNull final String tagName) { - - final Iterable sets = findDistributionSetListWithDetails(dsIds); - final DistributionSetTag myTag = tagManagement.findDistributionSetTag(tagName); - - DistributionSetTagAssignmentResult result; - final List toBeChangedDSs = new ArrayList<>(); - for (final DistributionSet set : sets) { - if (set.getTags().add(myTag)) { - toBeChangedDSs.add(set); - } - } - - // un-assignment case - if (toBeChangedDSs.isEmpty()) { - for (final DistributionSet set : sets) { - if (set.getTags().remove(myTag)) { - toBeChangedDSs.add(set); - } - } - result = new DistributionSetTagAssignmentResult(dsIds.size() - toBeChangedDSs.size(), 0, - toBeChangedDSs.size(), Collections.emptyList(), distributionSetRepository.save(toBeChangedDSs), - myTag); - } else { - result = new DistributionSetTagAssignmentResult(dsIds.size() - toBeChangedDSs.size(), toBeChangedDSs.size(), - 0, distributionSetRepository.save(toBeChangedDSs), Collections.emptyList(), myTag); - } - - final DistributionSetTagAssignmentResult resultAssignment = result; - afterCommit.afterCommit(() -> eventBus.post(new DistributionSetTagAssigmentResultEvent(resultAssignment))); - - // no reason to persist the tag - entityManager.detach(myTag); - return result; - } - - /** - * Retrieves {@link DistributionSet} List including details information, - * i.e. @link BaseSoftwareModule}s and {@link DistributionSetTag}s. - * - * @param distributionIdSet - * List of {@link DistributionSet} IDs to be found - * @return the found {@link DistributionSet}s - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - public List findDistributionSetListWithDetails( - @NotEmpty final Collection distributionIdSet) { - return distributionSetRepository.findAll(DistributionSetSpecification.byIds(distributionIdSet)); - } - - /** - * Updates existing {@link DistributionSet}. + * Assigns {@link SoftwareModule} to existing {@link DistributionSet}. * * @param ds - * to update - * @return the saved {@link Entity}. - * @throws NullPointerException - * of {@link DistributionSet#getId()} is null - * @throw DataDependencyViolationException in case of illegal update + * to assign and update + * @param softwareModules + * to get assigned + * @return the updated {@link DistributionSet}. */ - @Modifying - @Transactional(isolation = Isolation.READ_UNCOMMITTED) @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - public DistributionSet updateDistributionSet(@NotNull final DistributionSet ds) { - checkNotNull(ds.getId()); - final DistributionSet persisted = findDistributionSetByIdWithDetails(ds.getId()); - checkDistributionSetSoftwareModulesIsAllowedToModify(ds, persisted.getModules()); - return distributionSetRepository.save(ds); + DistributionSet assignSoftwareModules(@NotNull DistributionSet ds, Set softwareModules); + + /** + * Assign a {@link DistributionSetTag} assignment to given + * {@link DistributionSet}s. + * + * @param dsIds + * to assign for + * @param tag + * to assign + * @return list of assigned ds + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) + List assignTag(@NotEmpty Collection dsIds, @NotNull DistributionSetTag tag); + + /** + * Count all {@link DistributionSet}s in the repository that are not marked + * as deleted. + * + * @return number of {@link DistributionSet}s + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + Long countDistributionSetsAll(); + + /** + * @return number of {@link DistributionSetType}s in the repository. + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + Long countDistributionSetTypesAll(); + + /** + * Creates a new {@link DistributionSet}. + * + * @param dSet + * {@link DistributionSet} to be created + * @return the new persisted {@link DistributionSet} + * + * @throws EntityAlreadyExistsException + * if a given entity already exists + * @throws DistributionSetCreationFailedMissingMandatoryModuleException + * is {@link DistributionSet} does not contain mandatory + * {@link SoftwareModule}s. + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) + DistributionSet createDistributionSet(@NotNull DistributionSet dSet); + + /** + * creates a list of distribution set meta data entries. + * + * @param metadata + * the meta data entries to create or update + * @return the updated or created distribution set meta data entries + * @throws EntityAlreadyExistsException + * in case one of the meta data entry already exists for the + * specific key + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) + List createDistributionSetMetadata(@NotEmpty Collection metadata); + + /** + * creates or updates a single distribution set meta data entry. + * + * @param metadata + * the meta data entry to create or update + * @return the updated or created distribution set meta data entry + * @throws EntityAlreadyExistsException + * in case the meta data entry already exists for the specific + * key + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) + DistributionSetMetadata createDistributionSetMetadata(@NotNull DistributionSetMetadata metadata); + + /** + * Creates multiple {@link DistributionSet}s. + * + * @param distributionSets + * to be created + * @return the new {@link DistributionSet}s + * @throws EntityAlreadyExistsException + * if a given entity already exists + * @throws DistributionSetCreationFailedMissingMandatoryModuleException + * is {@link DistributionSet} does not contain mandatory + * {@link SoftwareModule}s. + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) + List createDistributionSets(@NotNull Collection distributionSets); + + /** + * Creates new {@link DistributionSetType}. + * + * @param type + * to create + * @return created {@link Entity} + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) + DistributionSetType createDistributionSetType(@NotNull DistributionSetType type); + + /** + * Creates multiple {@link DistributionSetType}s. + * + * @param types + * to create + * @return created {@link Entity} + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + default List createDistributionSetTypes(@NotNull final Collection types) { + return types.stream().map(this::createDistributionSetType).collect(Collectors.toList()); } /** @@ -254,10 +182,9 @@ public class DistributionSetManagement { * @param set * to delete */ - @Modifying - @Transactional(isolation = Isolation.READ_UNCOMMITTED) @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY) - public void deleteDistributionSet(@NotNull final DistributionSet set) { + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + default void deleteDistributionSet(@NotNull final DistributionSet set) { deleteDistributionSet(set.getId()); } @@ -269,228 +196,133 @@ public class DistributionSetManagement { * @param distributionSetIDs * to be deleted */ - @Modifying - @Transactional(isolation = Isolation.READ_UNCOMMITTED) @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY) - public void deleteDistributionSet(@NotEmpty final Long... distributionSetIDs) { - final List toHardDelete = new ArrayList<>(); - - final List assigned = distributionSetRepository.findAssignedDistributionSetsById(distributionSetIDs); - - // soft delete assigned - if (!assigned.isEmpty()) { - distributionSetRepository.deleteDistributionSet(assigned.toArray(new Long[assigned.size()])); - } - - // mark the rest as hard delete - for (final Long setId : distributionSetIDs) { - if (!assigned.contains(setId)) { - toHardDelete.add(setId); - } - } - - // hard delete the rest if exixts - if (!toHardDelete.isEmpty()) { - // don't give the delete statement an empty list, JPA/Oracle cannot - // handle the empty list - distributionSetRepository.deleteByIdIn(toHardDelete); - } - } + void deleteDistributionSet(@NotEmpty Long... distributionSetIDs); /** - * Creates a new {@link DistributionSet}. + * deletes a distribution set meta data entry. * - * @param dSet - * {@link DistributionSet} to be created - * @return the new persisted {@link DistributionSet} - * - * @throws EntityAlreadyExistsException - * if a given entity already exists - * @throws DistributionSetCreationFailedMissingMandatoryModuleException - * is {@link DistributionSet} does not contain mandatory - * {@link SoftwareModule}s. + * @param id + * the ID of the distribution set meta data to delete */ - @Modifying - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) - public DistributionSet createDistributionSet(@NotNull final DistributionSet dSet) { - prepareDsSave(dSet); - if (dSet.getType() == null) { - dSet.setType(systemManagement.getTenantMetadata().getDefaultDsType()); - } - return distributionSetRepository.save(dSet); - } - - private void prepareDsSave(final DistributionSet dSet) { - if (dSet.getId() != null) { - throw new EntityAlreadyExistsException("Parameter seems to be an existing, already persisted entity"); - } - - if (distributionSetRepository.countByNameAndVersion(dSet.getName(), dSet.getVersion()) > 0) { - throw new EntityAlreadyExistsException("DistributionSet with that name and version already exists."); - } - - } - - /** - * Creates multiple {@link DistributionSet}s. - * - * @param distributionSets - * to be created - * @return the new {@link DistributionSet}s - * @throws EntityAlreadyExistsException - * if a given entity already exists - * @throws DistributionSetCreationFailedMissingMandatoryModuleException - * is {@link DistributionSet} does not contain mandatory - * {@link SoftwareModule}s. - */ - @Modifying - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) - public List createDistributionSets(@NotNull final Iterable distributionSets) { - for (final DistributionSet ds : distributionSets) { - prepareDsSave(ds); - if (ds.getType() == null) { - ds.setType(systemManagement.getTenantMetadata().getDefaultDsType()); - } - } - return distributionSetRepository.save(distributionSets); - } - - /** - * Assigns {@link SoftwareModule} to existing {@link DistributionSet}. - * - * @param ds - * to assign and update - * @param softwareModules - * to get assigned - * @return the updated {@link DistributionSet}. - */ - @Modifying - @Transactional(isolation = Isolation.READ_UNCOMMITTED) @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - public DistributionSet assignSoftwareModules(@NotNull final DistributionSet ds, - final Set softwareModules) { - checkDistributionSetSoftwareModulesIsAllowedToModify(ds, softwareModules); - for (final SoftwareModule softwareModule : softwareModules) { - ds.addModule(softwareModule); - } - return distributionSetRepository.save(ds); - } + void deleteDistributionSetMetadata(@NotNull DsMetadataCompositeKey id); /** - * Unassigns a {@link SoftwareModule} form an existing - * {@link DistributionSet}. + * Deletes or mark as delete in case the type is in use. * - * @param ds - * to get unassigned form - * @param softwareModule - * to get unassigned - * @return the updated {@link DistributionSet}. + * @param type + * to delete */ - @Modifying - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - public DistributionSet unassignSoftwareModule(@NotNull final DistributionSet ds, - final SoftwareModule softwareModule) { - final Set softwareModules = new HashSet<>(); - softwareModules.add(softwareModule); - ds.removeModule(softwareModule); - checkDistributionSetSoftwareModulesIsAllowedToModify(ds, softwareModules); - return distributionSetRepository.save(ds); - } + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY) + void deleteDistributionSetType(@NotNull DistributionSetType type); /** - * Updates existing {@link DistributionSetType}. However, keep in mind that - * is not possible to change the {@link DistributionSetTypeElement}s while - * the DS type is already in use. + * retrieves the distribution set for a given action. * - * @param dsType - * to update - * @return updated {@link Entity} - * - * @throws EntityReadOnlyException - * if use tries to change the {@link DistributionSetTypeElement} - * s while the DS type is already in use. + * @param action + * the action associated with the distribution set + * @return the distribution set which is associated with the action */ - @Modifying - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - public DistributionSetType updateDistributionSetType(@NotNull final DistributionSetType dsType) { - checkNotNull(dsType.getId()); + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + DistributionSet findDistributionSetByAction(@NotNull Action action); - final DistributionSetType persisted = distributionSetTypeRepository.findOne(dsType.getId()); - - // throw exception if user tries to update a DS type that is already in - // use - if (!persisted.areModuleEntriesIdentical(dsType) && distributionSetRepository.countByType(persisted) > 0) { - throw new EntityReadOnlyException( - String.format("distribution set type %s set is already assigned to targets and cannot be changed", - dsType.getName())); - } - - return distributionSetTypeRepository.save(dsType); + /** + * Find {@link DistributionSet} based on given ID without details, e.g. + * {@link DistributionSet#getAgentHub()}. + * + * @param distid + * to look for. + * @return {@link DistributionSet} or null if it does not exist + */ + @Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + default DistributionSet findDistributionSetById(@NotNull final Long distid) { + return findDistributionSetByIdWithDetails(distid); } /** - * Generic predicate based query for {@link DistributionSetType}. + * Find {@link DistributionSet} based on given ID including (lazy loaded) + * details, e.g. {@link DistributionSet#getAgentHub()}. * + * Note: for performance reasons it is recommended to use + * {@link #findDistributionSetById(Long)} if details are not necessary. + * + * @param distid + * to look for. + * @return {@link DistributionSet} or null if it does not exist + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + DistributionSet findDistributionSetByIdWithDetails(@NotNull Long distid); + + /** + * Find distribution set by name and version. + * + * @param distributionName + * name of {@link DistributionSet}; case insensitive + * @param version + * version of {@link DistributionSet} + * @return the page with the found {@link DistributionSet} + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + DistributionSet findDistributionSetByNameAndVersion(@NotEmpty String distributionName, @NotEmpty String version); + + /** + * Retrieves {@link DistributionSet} List for overview purposes (no + * {@link SoftwareModule}s and {@link DistributionSetTag}s). + * + * Please use {@link #findDistributionSetListWithDetails(Iterable)} if + * details are required. + * + * @param dist + * List of {@link DistributionSet} IDs to be found + * @return the found {@link DistributionSet}s + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + Iterable findDistributionSetList(Collection dist); + + /** + * Retrieves {@link DistributionSet} List including details information, + * i.e. @link BaseSoftwareModule}s and {@link DistributionSetTag}s. + * + * @param distributionIdSet + * List of {@link DistributionSet} IDs to be found + * @return the found {@link DistributionSet}s + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + List findDistributionSetListWithDetails(Collection distributionIdSet); + + /** + * finds all meta data by the given distribution set id. + * + * @param distributionSetId + * the distribution set id to retrieve the meta data from + * @param pageable + * the page request to page the result + * @return a paged result of all meta data entries for a given distribution + * set id + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + Page findDistributionSetMetadataByDistributionSetId(@NotNull Long distributionSetId, + @NotNull Pageable pageable); + + /** + * finds all meta data by the given distribution set id. + * + * @param distributionSetId + * the distribution set id to retrieve the meta data from * @param spec - * of the search + * the specification to filter the result * @param pageable - * parameter for paging - * - * @return the found {@link SoftwareModuleType}s + * the page request to page the result + * @return a paged result of all meta data entries for a given distribution + * set id */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - public Page findDistributionSetTypesByPredicate( - @NotNull final Specification spec, @NotNull final Pageable pageable) { - return distributionSetTypeRepository.findAll(spec, pageable); - } - - /** - * @param pageable - * parameter - * @return all {@link DistributionSetType}s in the repository. - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - public Page findDistributionSetTypesAll(@NotNull final Pageable pageable) { - return distributionSetTypeRepository.findByDeleted(pageable, false); - } - - /** - * retrieves {@link DistributionSet}s by filtering on the given parameters. - * - * @param pageable - * page parameter - * @param distributionSetFilter - * has details of filters to be applied. - * @return the page of found {@link DistributionSet} - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - public Page findDistributionSetsByFilters(@NotNull final Pageable pageable, - final DistributionSetFilter distributionSetFilter) { - final List> specList = buildDistributionSetSpecifications(distributionSetFilter); - return findByCriteriaAPI(pageable, specList); - } - - /** - * - * @param distributionSetFilter - * had details of filters to be applied - * @return a single DistributionSet which is either installed or assigned to - * a specific target or {@code null}. - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - private DistributionSet findDistributionSetsByFiltersAndInstalledOrAssignedTarget( - final DistributionSetFilter distributionSetFilter) { - final List> specList = buildDistributionSetSpecifications(distributionSetFilter); - if (specList == null || specList.isEmpty()) { - return null; - } - return distributionSetRepository.findOne(SpecificationsBuilder.combineWithAnd(specList)); - } + Page findDistributionSetMetadataByDistributionSetId(@NotNull Long distributionSetId, + @NotNull Specification spec, @NotNull Pageable pageable); + // TODO discuss: use enum instead of the true,false,null switch ? /** * finds all {@link DistributionSet}s. * @@ -504,31 +336,16 @@ public class DistributionSetManagement { * @param complete * to true for returning only completed distribution * sets or false for only incomplete ones nor - * null to return both.. + * null to return both. * @param complete - * set to if false uncomplete DS should also be + * set to if false incomplete DS should also be * shown. * * * @return all found {@link DistributionSet}s */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - public Page findDistributionSetsAll(@NotNull final Pageable pageReq, final Boolean deleted, - final Boolean complete) { - final List> specList = new ArrayList<>(); - - if (deleted != null) { - final Specification spec = DistributionSetSpecification.isDeleted(deleted); - specList.add(spec); - } - - if (complete != null) { - final Specification spec = DistributionSetSpecification.isCompleted(complete); - specList.add(spec); - } - - return findByCriteriaAPI(pageReq, specList); - } + Page findDistributionSetsAll(@NotNull Pageable pageReq, Boolean deleted, Boolean complete); /** * finds all {@link DistributionSet}s. @@ -545,18 +362,11 @@ public class DistributionSetManagement { * @return all found {@link DistributionSet}s */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - public Page findDistributionSetsAll(@NotNull final Specification spec, - @NotNull final Pageable pageReq, final Boolean deleted) { - final List> specList = new ArrayList<>(); - if (deleted != null) { - specList.add(DistributionSetSpecification.isDeleted(deleted)); - } - specList.add(spec); - return findByCriteriaAPI(pageReq, specList); - } + Page findDistributionSetsAll(@NotNull Specification spec, + @NotNull Pageable pageReq, Boolean deleted); /** - * method retrieves all {@link DistributionSet}s from the repo in the + * method retrieves all {@link DistributionSet}s from the repository in the * following order: *

* 1) {@link DistributionSet}s which have the given {@link Target} as @@ -573,120 +383,25 @@ public class DistributionSetManagement { * @param distributionSetFilterBuilder * has details of filters to be applied * @param assignedOrInstalled - * the ID of the Target to be ordered by + * the controllerID of the Target to be ordered by * @return */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - public Page findDistributionSetsAllOrderedByLinkTarget(@NotNull final Pageable pageable, - @NotNull final DistributionSetFilterBuilder distributionSetFilterBuilder, - @NotNull final String assignedOrInstalled) { - - final DistributionSetFilter filterWithInstalledTargets = distributionSetFilterBuilder - .setInstalledTargetId(assignedOrInstalled).setAssignedTargetId(null).build(); - final DistributionSet installedDS = findDistributionSetsByFiltersAndInstalledOrAssignedTarget( - filterWithInstalledTargets); - - final DistributionSetFilter filterWithAssignedTargets = distributionSetFilterBuilder.setInstalledTargetId(null) - .setAssignedTargetId(assignedOrInstalled).build(); - final DistributionSet assignedDS = findDistributionSetsByFiltersAndInstalledOrAssignedTarget( - filterWithAssignedTargets); - - final DistributionSetFilter dsFilterWithNoTargetLinked = distributionSetFilterBuilder.setInstalledTargetId(null) - .setAssignedTargetId(null).build(); - // first fine the distribution sets filtered by the given filter - // parameters - final Page findDistributionSetsByFilters = findDistributionSetsByFilters(pageable, - dsFilterWithNoTargetLinked); - - final List resultSet = new LinkedList<>(findDistributionSetsByFilters.getContent()); - int orderIndex = 0; - if (installedDS != null) { - final boolean remove = resultSet.remove(installedDS); - if (!remove) { - resultSet.remove(resultSet.size() - 1); - } - resultSet.add(orderIndex, installedDS); - orderIndex++; - } - if (assignedDS != null && !assignedDS.equals(installedDS)) { - final boolean remove = resultSet.remove(assignedDS); - if (!remove) { - resultSet.remove(resultSet.size() - 1); - } - resultSet.add(orderIndex, assignedDS); - } - - return new PageImpl<>(resultSet, pageable, findDistributionSetsByFilters.getTotalElements()); - } + Page findDistributionSetsAllOrderedByLinkTarget(@NotNull Pageable pageable, + @NotNull DistributionSetFilterBuilder distributionSetFilterBuilder, @NotEmpty String assignedOrInstalled); /** - * Find distribution set by name and version. + * retrieves {@link DistributionSet}s by filtering on the given parameters. * - * @param distributionName - * name of {@link DistributionSet}; case insensitive - * @param version - * version of {@link DistributionSet} - * @return the page with the found {@link DistributionSet} + * @param pageable + * page parameter + * @param distributionSetFilter + * has details of filters to be applied. + * @return the page of found {@link DistributionSet} */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - public DistributionSet findDistributionSetByNameAndVersion(@NotEmpty final String distributionName, - @NotEmpty final String version) { - final Specification spec = DistributionSetSpecification - .equalsNameAndVersionIgnoreCase(distributionName, version); - return distributionSetRepository.findOne(spec); - - } - - /** - * Retrieves {@link DistributionSet} List for overview purposes (no - * {@link SoftwareModule}s and {@link DistributionSetTag}s). - * - * Please use {@link #findDistributionSetListWithDetails(Iterable)} if - * details are required. - * - * @param dist - * List of {@link DistributionSet} IDs to be found - * @return the found {@link DistributionSet}s - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - public Iterable findDistributionSetList(@NotEmpty final Collection dist) { - return distributionSetRepository.findAll(dist); - } - - /** - * Count all {@link DistributionSet}s in the repository that are not marked - * as deleted. - * - * @return number of {@link DistributionSet}s - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - public Long countDistributionSetsAll() { - - final List> specList = new ArrayList<>(); - - final Specification spec = DistributionSetSpecification.isDeleted(Boolean.FALSE); - specList.add(spec); - - return distributionSetRepository.count(SpecificationsBuilder.combineWithAnd(specList)); - } - - /** - * @return number of {@link DistributionSetType}s in the repository. - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - public Long countDistributionSetTypesAll() { - return distributionSetTypeRepository.countByDeleted(false); - } - - /** - * @param name - * as {@link DistributionSetType#getName()} - * @return {@link DistributionSetType} if found or null if not - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - public DistributionSetType findDistributionSetTypeByName(@NotNull final String name) { - return distributionSetTypeRepository.findOne(DistributionSetTypeSpecification.byName(name)); - } + Page findDistributionSetsByFilters(@NotNull Pageable pageable, + @NotNull DistributionSetFilter distributionSetFilter); /** * @param id @@ -694,186 +409,46 @@ public class DistributionSetManagement { * @return {@link DistributionSetType} if found or null if not */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - public DistributionSetType findDistributionSetTypeById(@NotNull final Long id) { - return distributionSetTypeRepository.findOne(DistributionSetTypeSpecification.byId(id)); - } + DistributionSetType findDistributionSetTypeById(@NotNull Long id); /** * @param key * as {@link DistributionSetType#getKey()} * @return {@link DistributionSetType} if found or null if not */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - public DistributionSetType findDistributionSetTypeByKey(@NotNull final String key) { - return distributionSetTypeRepository.findOne(DistributionSetTypeSpecification.byKey(key)); - } + DistributionSetType findDistributionSetTypeByKey(@NotNull String key); /** - * Creates new {@link DistributionSetType}. - * - * @param type - * to create - * @return created {@link Entity} + * @param name + * as {@link DistributionSetType#getName()} + * @return {@link DistributionSetType} if found or null if not */ - @Modifying - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) - public DistributionSetType createDistributionSetType(@NotNull final DistributionSetType type) { - if (type.getId() != null) { - throw new EntityAlreadyExistsException("Given type contains an Id!"); - } - - return distributionSetTypeRepository.save(type); - } + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + DistributionSetType findDistributionSetTypeByName(@NotEmpty String name); /** - * Deletes or markes as delete in case the type is in use. - * - * @param type - * to delete - */ - @Modifying - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY) - public void deleteDistributionSetType(@NotNull final DistributionSetType type) { - - if (distributionSetRepository.countByType(type) > 0) { - final DistributionSetType toDelete = entityManager.merge(type); - toDelete.setDeleted(true); - distributionSetTypeRepository.save(toDelete); - } else { - distributionSetTypeRepository.delete(type.getId()); - } - } - - /** - * creates or updates a single distribution set meta data entry. - * - * @param metadata - * the meta data entry to create or update - * @return the updated or created distribution set meta data entry - * @throws EntityAlreadyExistsException - * in case the meta data entry already exists for the specific - * key - */ - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @Modifying - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - public DistributionSetMetadata createDistributionSetMetadata(@NotNull final DistributionSetMetadata metadata) { - if (distributionSetMetadataRepository.exists(metadata.getId())) { - throwMetadataKeyAlreadyExists(metadata.getId().getKey()); - } - // merge base distribution set so optLockRevision gets updated and audit - // log written because - // modifying metadata is modifying the base distribution set itself for - // auditing purposes. - entityManager.merge(metadata.getDistributionSet()).setLastModifiedAt(0L); - return distributionSetMetadataRepository.save(metadata); - } - - /** - * creates a list of distribution set meta data entries. - * - * @param metadata - * the meta data entries to create or update - * @return the updated or created distribution set meta data entries - * @throws EntityAlreadyExistsException - * in case one of the meta data entry already exists for the - * specific key - */ - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @Modifying - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - public List createDistributionSetMetadata( - @NotEmpty final Collection metadata) { - for (final DistributionSetMetadata distributionSetMetadata : metadata) { - checkAndThrowAlreadyIfDistributionSetMetadataExists(distributionSetMetadata.getId()); - } - metadata.forEach(m -> entityManager.merge(m.getDistributionSet()).setLastModifiedAt(-1L)); - return (List) distributionSetMetadataRepository.save(metadata); - } - - /** - * updates a distribution set meta data value if corresponding entry exists. - * - * @param metadata - * the meta data entry to be updated - * @return the updated meta data entry - * @throws EntityNotFoundException - * in case the meta data entry does not exists and cannot be - * updated - */ - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @Modifying - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - public DistributionSetMetadata updateDistributionSetMetadata(@NotNull final DistributionSetMetadata metadata) { - // check if exists otherwise throw entity not found exception - findOne(metadata.getId()); - // touch it to update the lock revision because we are modifying the - // DS indirectly - entityManager.merge(metadata.getDistributionSet()).setLastModifiedAt(0L); - return distributionSetMetadataRepository.save(metadata); - } - - /** - * deletes a distribution set meta data entry. - * - * @param id - * the ID of the distribution set meta data to delete - */ - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @Modifying - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - public void deleteDistributionSetMetadata(@NotNull final DsMetadataCompositeKey id) { - distributionSetMetadataRepository.delete(id); - } - - /** - * finds all meta data by the given distribution set id. - * - * @param distributionSetId - * the distribution set id to retrieve the meta data from * @param pageable - * the page request to page the result - * @return a paged result of all meta data entries for a given distribution - * set id + * parameter + * @return all {@link DistributionSetType}s in the repository. */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - public Page findDistributionSetMetadataByDistributionSetId( - @NotNull final Long distributionSetId, @NotNull final Pageable pageable) { - - return distributionSetMetadataRepository.findAll( - (Specification) (root, query, cb) -> cb.equal( - root.get(DistributionSetMetadata_.distributionSet).get(DistributionSet_.id), distributionSetId), - pageable); - - } + Page findDistributionSetTypesAll(@NotNull Pageable pageable); /** - * finds all meta data by the given distribution set id. + * Generic predicate based query for {@link DistributionSetType}. * - * @param distributionSetId - * the distribution set id to retrieve the meta data from * @param spec - * the specification to filter the result + * of the search * @param pageable - * the page request to page the result - * @return a paged result of all meta data entries for a given distribution - * set id + * parameter for paging + * + * @return the found {@link SoftwareModuleType}s */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - public Page findDistributionSetMetadataByDistributionSetId( - @NotNull final Long distributionSetId, @NotNull final Specification spec, - @NotNull final Pageable pageable) { - return distributionSetMetadataRepository - .findAll( - (Specification) (root, query, - cb) -> cb.and( - cb.equal(root.get(DistributionSetMetadata_.distributionSet) - .get(DistributionSet_.id), distributionSetId), - spec.toPredicate(root, query, cb)), - pageable); - } + Page findDistributionSetTypesAll(@NotNull Specification spec, + @NotNull Pageable pageable); /** * finds a single distribution set meta data by its id. @@ -886,188 +461,53 @@ public class DistributionSetManagement { * in case the meta data does not exists for the given key */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - public DistributionSetMetadata findOne(@NotNull final DsMetadataCompositeKey id) { - final DistributionSetMetadata findOne = distributionSetMetadataRepository.findOne(id); - if (findOne == null) { - throw new EntityNotFoundException("Metadata with key '" + id.getKey() + "' does not exist"); - } - return findOne; - } + DistributionSetMetadata findOne(@NotNull DsMetadataCompositeKey id); /** - * retrieves the distribution set for a given action. - * - * @param action - * the action associated with the distribution set - * @return the distribution set which is associated with the action - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - public DistributionSet findDistributionSetByAction(@NotNull final Action action) { - return distributionSetRepository.findByAction(action); - } - - /** - * Creates multiple {@link DistributionSetType}s. - * - * @param types - * to create - * @return created {@link Entity} - */ - @Modifying - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) - public List createDistributionSetTypes(@NotNull final Collection types) { - return types.stream().map(this::createDistributionSetType).collect(Collectors.toList()); - } - - /** - * Checking Distribution Set is already using while assign Software module. + * Checks if a {@link DistributionSet} is currently in use by a target in + * the repository. * * @param distributionSet - * @param softwareModules + * to check + * + * @return true if in use */ - @Modifying - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - public void checkDistributionSetAlreadyUse(final DistributionSet distributionSet) { - checkDistributionSetSoftwareModulesIsAllowedToModify(distributionSet); - } - - private List> buildDistributionSetSpecifications( - final DistributionSetFilter distributionSetFilter) { - final List> specList = new ArrayList<>(); - - Specification spec; - - if (null != distributionSetFilter.getIsComplete()) { - spec = DistributionSetSpecification.isCompleted(distributionSetFilter.getIsComplete()); - specList.add(spec); - } - - if (null != distributionSetFilter.getIsDeleted()) { - spec = DistributionSetSpecification.isDeleted(distributionSetFilter.getIsDeleted()); - specList.add(spec); - } - - if (distributionSetFilter.getType() != null) { - spec = DistributionSetSpecification.byType(distributionSetFilter.getType()); - specList.add(spec); - } - - if (!Strings.isNullOrEmpty(distributionSetFilter.getSearchText())) { - spec = DistributionSetSpecification.likeNameOrDescriptionOrVersion(distributionSetFilter.getSearchText()); - specList.add(spec); - } - - if (isDSWithNoTagSelected(distributionSetFilter) || isTagsSelected(distributionSetFilter)) { - spec = DistributionSetSpecification.hasTags(distributionSetFilter.getTagNames(), - distributionSetFilter.getSelectDSWithNoTag()); - specList.add(spec); - } - if (distributionSetFilter.getInstalledTargetId() != null) { - spec = DistributionSetSpecification.installedTarget(distributionSetFilter.getInstalledTargetId()); - specList.add(spec); - } - if (distributionSetFilter.getAssignedTargetId() != null) { - spec = DistributionSetSpecification.assignedTarget(distributionSetFilter.getAssignedTargetId()); - specList.add(spec); - } - return specList; - } - - private void checkDistributionSetSoftwareModulesIsAllowedToModify(final DistributionSet distributionSet, - final Set softwareModules) { - if (!new HashSet(distributionSet.getModules()).equals(softwareModules) - && actionRepository.countByDistributionSet(distributionSet) > 0) { - throw new EntityLockedException( - String.format("distribution set %s:%s is already assigned to targets and cannot be changed", - distributionSet.getName(), distributionSet.getVersion())); - } - } - - private void checkDistributionSetSoftwareModulesIsAllowedToModify(final DistributionSet distributionSet) { - if (actionRepository.countByDistributionSet(distributionSet) > 0) { - throw new EntityLockedException( - String.format("distribution set %s:%s is already assigned to targets and cannot be changed", - distributionSet.getName(), distributionSet.getVersion())); - } - } - - private static Boolean isDSWithNoTagSelected(final DistributionSetFilter distributionSetFilter) { - if (distributionSetFilter.getSelectDSWithNoTag() != null && distributionSetFilter.getSelectDSWithNoTag()) { - return true; - } - return false; - } - - private static Boolean isTagsSelected(final DistributionSetFilter distributionSetFilter) { - if (distributionSetFilter.getTagNames() != null && !distributionSetFilter.getTagNames().isEmpty()) { - return true; - } - return false; - } + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + boolean isDistributionSetInUse(@NotNull DistributionSet distributionSet); /** - * executes findAll with the given {@link DistributionSet} - * {@link Specification}s. + * {@link Entity} based method call for + * {@link #toggleTagAssignment(Collection, String)}. * - * @param pageable - * paging parameter - * @param specList - * list of @link {@link Specification} - * @return the page with the found {@link DistributionSet} + * @param sets + * to toggle for + * @param tag + * to toggle + * @return {@link DistributionSetTagAssignmentResult} with all meta data of + * the assignment outcome. */ - private Page findByCriteriaAPI(@NotNull final Pageable pageable, - final List> specList) { - - if (specList == null || specList.isEmpty()) { - return distributionSetRepository.findAll(pageable); - } - - return distributionSetRepository.findAll(SpecificationsBuilder.combineWithAnd(specList), pageable); - } - - private void checkAndThrowAlreadyIfDistributionSetMetadataExists(final DsMetadataCompositeKey metadataId) { - if (distributionSetMetadataRepository.exists(metadataId)) { - throw new EntityAlreadyExistsException( - "Metadata entry with key '" + metadataId.getKey() + "' already exists"); - } - } - - private static void throwMetadataKeyAlreadyExists(final String metadataKey) { - throw new EntityAlreadyExistsException("Metadata entry with key '" + metadataKey + "' already exists"); + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + default DistributionSetTagAssignmentResult toggleTagAssignment(@NotEmpty final Collection sets, + @NotNull final DistributionSetTag tag) { + return toggleTagAssignment(sets.stream().map(ds -> ds.getId()).collect(Collectors.toList()), tag.getName()); } /** - * Assign a {@link DistributionSetTag} assignment to given - * {@link DistributionSet}s. + * Toggles {@link DistributionSetTag} assignment to given + * {@link DistributionSet}s by means that if some (or all) of the targets in + * the list have the {@link Tag} not yet assigned, they will be. If all of + * theme have the tag already assigned they will be removed instead. * * @param dsIds - * to assign for - * @param tag - * to assign - * @return list of assigned ds + * to toggle for + * @param tagName + * to toggle + * @return {@link DistributionSetTagAssignmentResult} with all meta data of + * the assignment outcome. */ - @Modifying - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @NotNull - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET) - public List assignTag(@NotEmpty final Collection dsIds, - @NotNull final DistributionSetTag tag) { - final List allDs = findDistributionSetListWithDetails(dsIds); - - allDs.forEach(ds -> ds.getTags().add(tag)); - final List save = distributionSetRepository.save(allDs); - - afterCommit.afterCommit(() -> { - - final DistributionSetTagAssignmentResult result = new DistributionSetTagAssignmentResult(0, save.size(), 0, - save, Collections.emptyList(), tag); - eventBus.post(new DistributionSetTagAssigmentResultEvent(result)); - }); - - return save; - } + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) + DistributionSetTagAssignmentResult toggleTagAssignment(@NotEmpty Collection dsIds, @NotNull String tagName); /** * Unassign all {@link DistributionSet} from a given @@ -1077,13 +517,21 @@ public class DistributionSetManagement { * to unassign all ds * @return list of unassigned ds */ - @Modifying - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @NotNull - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET) - public List unAssignAllDistributionSetsByTag(@NotNull final DistributionSetTag tag) { - return unAssignTag(tag.getAssignedToDistributionSet(), tag); - } + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) + List unAssignAllDistributionSetsByTag(@NotNull DistributionSetTag tag); + + /** + * Unassigns a {@link SoftwareModule} form an existing + * {@link DistributionSet}. + * + * @param ds + * to get unassigned form + * @param softwareModule + * to get unassigned + * @return the updated {@link DistributionSet}. + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) + DistributionSet unassignSoftwareModule(@NotNull DistributionSet ds, @NotNull SoftwareModule softwareModule); /** * Unassign a {@link DistributionSetTag} assignment to given @@ -1095,18 +543,49 @@ public class DistributionSetManagement { * to unassign * @return the unassigned ds or if no ds is unassigned */ - @Modifying - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET) - public DistributionSet unAssignTag(@NotNull final Long dsId, @NotNull final DistributionSetTag distributionSetTag) { - final List allDs = findDistributionSetListWithDetails(Arrays.asList(dsId)); - final List unAssignTag = unAssignTag(allDs, distributionSetTag); - return unAssignTag.isEmpty() ? null : unAssignTag.get(0); - } + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) + DistributionSet unAssignTag(@NotNull Long dsId, @NotNull DistributionSetTag distributionSetTag); - private List unAssignTag(final Collection distributionSets, - final DistributionSetTag tag) { - distributionSets.forEach(ds -> ds.getTags().remove(tag)); - return distributionSetRepository.save(distributionSets); - } -} + /** + * Updates existing {@link DistributionSet}. + * + * @param ds + * to update + * @return the saved {@link Entity}. + * @throws NullPointerException + * of {@link DistributionSet#getId()} is null + * @throw DataDependencyViolationException in case of illegal update + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) + DistributionSet updateDistributionSet(@NotNull DistributionSet ds); + + /** + * updates a distribution set meta data value if corresponding entry exists. + * + * @param metadata + * the meta data entry to be updated + * @return the updated meta data entry + * @throws EntityNotFoundException + * in case the meta data entry does not exists and cannot be + * updated + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) + DistributionSetMetadata updateDistributionSetMetadata(@NotNull DistributionSetMetadata metadata); + + /** + * Updates existing {@link DistributionSetType}. However, keep in mind that + * is not possible to change the {@link DistributionSetTypeElement}s while + * the DS type is already in use. + * + * @param dsType + * to update + * @return updated {@link Entity} + * + * @throws EntityReadOnlyException + * if use tries to change the {@link DistributionSetTypeElement} + * s while the DS type is already in use. + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) + DistributionSetType updateDistributionSetType(@NotNull DistributionSetType dsType); + +} \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ReportManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ReportManagement.java index 326442283..40ee21d9b 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ReportManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ReportManagement.java @@ -12,77 +12,24 @@ import java.io.Serializable; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.YearMonth; -import java.time.ZoneId; import java.time.format.DateTimeFormatter; -import java.util.ArrayList; -import java.util.Collections; -import java.util.LinkedHashMap; import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; -import javax.persistence.EntityManager; -import javax.persistence.Query; -import javax.persistence.criteria.CriteriaBuilder; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Expression; -import javax.persistence.criteria.Join; -import javax.persistence.criteria.JoinType; -import javax.persistence.criteria.ListJoin; -import javax.persistence.criteria.Root; +import javax.validation.constraints.NotNull; +import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; import org.eclipse.hawkbit.report.model.DataReportSeries; -import org.eclipse.hawkbit.report.model.DataReportSeriesItem; import org.eclipse.hawkbit.report.model.InnerOuterDataReportSeries; import org.eclipse.hawkbit.report.model.ListReportSeries; import org.eclipse.hawkbit.report.model.SeriesTime; -import org.eclipse.hawkbit.repository.model.DistributionSet; -import org.eclipse.hawkbit.repository.model.DistributionSet_; -import org.eclipse.hawkbit.repository.model.Target; -import org.eclipse.hawkbit.repository.model.TargetInfo; -import org.eclipse.hawkbit.repository.model.TargetInfo_; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; -import org.eclipse.hawkbit.repository.model.Target_; -import org.eclipse.hawkbit.tenancy.TenantAware; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.cache.annotation.Cacheable; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Isolation; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.validation.annotation.Validated; +import org.springframework.security.access.prepost.PreAuthorize; /** - * Service layer for generating hawkBit reports. + * Service layer for generating hawkBit statistics and reports. * */ -@Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) -@Validated -@Service -public class ReportManagement { - - @Value("${spring.jpa.database}") - private String databaseType; - - private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM"); - - private static final String H2_TARGET_CREATED_SQL_TEMPLATE = "SELECT TO_CHAR( DATEADD('second', target0_.created_at / 1000, DATE '1970-01-01'), '%s') AS col_0_0_, count(target0_.controller_id) AS col_1_0_ from sp_target target0_ WHERE TO_CHAR(DATEADD('second', target0_.created_at / 1000, DATE '1970-01-01'),'%s') BETWEEN TO_CHAR('%s', '%s') and TO_CHAR('%s', '%s') AND UPPER(target0_.tenant)=UPPER('%s') GROUP BY TO_CHAR(DATEADD('second', target0_.created_at / 1000, DATE '1970-01-01'), '%s')"; - - private static final String H2_CONTROLLER_FRRDBACK_SQL_TEMPLATE = "SELECT TO_CHAR(DATEADD('second', action_.created_at / 1000, DATE '1970-01-01'), '%s') AS col_0_0_, count(action_.id) AS col_1_0_ FROM sp_action action_ WHERE TO_CHAR(DATEADD('second', action_.created_at / 1000, DATE '1970-01-01'), '%s') BETWEEN TO_CHAR('%s', '%s') AND TO_CHAR('%s', '%s') AND UPPER(action_.tenant)=UPPER('%s') GROUP BY TO_CHAR(DATEADD('second', action_.created_at / 1000, DATE '1970-01-01'), '%s')"; - - private static final String MYSQL_TARGET_CREATED_SQL_TEMPLATE = "SELECT DATE_FORMAT(FROM_UNIXTIME(target0_.created_at / 1000), '%s') AS col_0_0_, COUNT(target0_.controller_id) AS col_1_0_ FROM sp_target target0_ WHERE DATE_FORMAT(FROM_UNIXTIME(target0_.created_at / 1000),'%s') BETWEEN DATE_FORMAT('%s', '%s') AND DATE_FORMAT('%s', '%s') AND UPPER(target0_.tenant)=UPPER('%s') GROUP BY DATE_FORMAT(FROM_UNIXTIME(target0_.created_at / 1000), '%s')"; - - private static final String MYSQL_CONTROLLER_FRRDBACK_SQL_TEMPLATE = "SELECT DATE_FORMAT(FROM_UNIXTIME(action_.created_at / 1000), '%s') AS col_0_0_, COUNT(action_.id) as col_1_0_ FROM sp_action action_ WHERE DATE_FORMAT(FROM_UNIXTIME(action_.created_at / 1000),'%s') BETWEEN DATE_FORMAT('%s', '%s') AND DATE_FORMAT('%s', '%s') AND UPPER(action_.tenant)=UPPER('%s') GROUP BY DATE_FORMAT(FROM_UNIXTIME(action_.created_at / 1000), '%s')"; - - private static final String MYSQL_DB_TYPE = "MYSQL"; - - private static final String H2_DB_TYPE = "H2"; - - @Autowired - private EntityManager entityManager; - - @Autowired - private TenantAware tenantAware; +public interface ReportManagement { /** * Generates a report of all targets of their current update status count. @@ -92,29 +39,8 @@ public class ReportManagement { * @return a data report series which contains the target count for each * target update status */ - @Cacheable("targetStatus") - public DataReportSeries targetStatus() { - - final CriteriaBuilder cb = entityManager.getCriteriaBuilder(); - final CriteriaQuery query = cb.createQuery(Object[].class); - final Root targetRoot = query.from(Target.class); - final Join targetInfo = targetRoot.join(Target_.targetInfo); - final Expression countColumn = cb.count(targetInfo.get(TargetInfo_.targetId)); - final CriteriaQuery multiselect = query - .multiselect(targetInfo.get(TargetInfo_.updateStatus), countColumn) - .groupBy(targetInfo.get(TargetInfo_.updateStatus)) - .orderBy(cb.desc(targetInfo.get(TargetInfo_.updateStatus))); - - // | col1 | col2 | - // | U_STATUS | COUNT | - final List resultList = entityManager.createQuery(multiselect).getResultList(); - - final List> reportSeriesItems = resultList.stream() - .map(r -> new DataReportSeriesItem((TargetUpdateStatus) r[0], (Long) r[1])) - .collect(Collectors.toList()); - - return new DataReportSeries<>("Target Status Overview", reportSeriesItems); - } + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + DataReportSeries targetStatus(); /** * Generates a report of the top x distribution set assigned usage as a list @@ -132,29 +58,8 @@ public class ReportManagement { * set entries are summarized as "misc" * @return a list of inner and outer series of distribution set usage */ - @Cacheable("distributionUsageAssigned") - public List> distributionUsageAssigned(final int topXEntries) { - - // top X entries distribution usage - final CriteriaBuilder cbTopX = entityManager.getCriteriaBuilder(); - final CriteriaQuery queryTopX = cbTopX.createQuery(Object[].class); - final Root rootTopX = queryTopX.from(DistributionSet.class); - final ListJoin joinTopX = rootTopX.join(DistributionSet_.assignedToTargets, - JoinType.LEFT); - final Expression countColumn = cbTopX.count(joinTopX); - // top x usage query - final CriteriaQuery groupBy = queryTopX - .multiselect(rootTopX.get(DistributionSet_.name), rootTopX.get(DistributionSet_.version), countColumn) - .where(cbTopX.equal(rootTopX.get(DistributionSet_.deleted), false)) - .groupBy(rootTopX.get(DistributionSet_.name), rootTopX.get(DistributionSet_.version)) - .orderBy(cbTopX.desc(countColumn), cbTopX.asc(rootTopX.get(DistributionSet_.name))); - // | col1 | col2 | col3 | - // | NAME | VER | COUNT | - final List resultListTop = entityManager.createQuery(groupBy).getResultList(); - // end of top X entries distribution usage - - return mapDistirbutionUsageResultToDataReport(topXEntries, resultListTop); - } + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + List> distributionUsageAssigned(int topXEntries); /** * Generates a report of the top x distribution set installed usage as a @@ -173,28 +78,8 @@ public class ReportManagement { * set entries are summarized as "misc" * @return a list of inner and outer series of distribution set usage */ - @Cacheable("distributionUsageInstalled") - public List> distributionUsageInstalled(final int topXEntries) { - // top X entries distribution usage - final CriteriaBuilder cbTopX = entityManager.getCriteriaBuilder(); - final CriteriaQuery queryTopX = cbTopX.createQuery(Object[].class); - final Root rootTopX = queryTopX.from(DistributionSet.class); - final ListJoin joinTopX = rootTopX.join(DistributionSet_.installedAtTargets, - JoinType.LEFT); - final Expression countColumn = cbTopX.count(joinTopX); - // top x usage query - final CriteriaQuery groupBy = queryTopX - .multiselect(rootTopX.get(DistributionSet_.name), rootTopX.get(DistributionSet_.version), countColumn) - .where(cbTopX.equal(rootTopX.get(DistributionSet_.deleted), false)) - .groupBy(rootTopX.get(DistributionSet_.name), rootTopX.get(DistributionSet_.version)) - .orderBy(cbTopX.desc(countColumn), cbTopX.asc(rootTopX.get(DistributionSet_.name))); - // | col1 | col2 | col3 | - // | NAME | VER | COUNT | - final List resultListTop = entityManager.createQuery(groupBy).getResultList(); - // end of top X entries distribution usage - - return mapDistirbutionUsageResultToDataReport(topXEntries, resultListTop); - } + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + List> distributionUsageInstalled(int topXEntries); /** * Generates report for target created over period. @@ -208,55 +93,9 @@ public class ReportManagement { * @return DataReportSeries ListReportSeries list of target created * count */ - @Cacheable("targetsCreatedOverPeriod") - public DataReportSeries targetsCreatedOverPeriod(final DateType dateType, - final LocalDateTime from, final LocalDateTime to) { - final Query createNativeQuery = entityManager - .createNativeQuery(getTargetsCreatedQueryTemplate(dateType, from, to)); - final List resultList = createNativeQuery.getResultList(); - - final List> reportItems = resultList.stream() - .map(r -> new DataReportSeriesItem<>(dateType.format((String) r[0]), ((Number) r[1]).longValue())) - .collect(Collectors.toList()); - - return new DataReportSeries<>("CreatedTargets", reportItems); - } - - private String getTargetsCreatedQueryTemplate(final DateType dateType, final LocalDateTime from, - final LocalDateTime to) { - switch (databaseType) { - case H2_DB_TYPE: - return String.format(H2_TARGET_CREATED_SQL_TEMPLATE, dateTimeFormatToSqlFormat(dateType), - dateTimeFormatToSqlFormat(dateType), from.format(DATE_FORMAT), dateTimeFormatToSqlFormat(dateType), - to.format(DATE_FORMAT), dateTimeFormatToSqlFormat(dateType), tenantAware.getCurrentTenant(), - dateTimeFormatToSqlFormat(dateType)); - case MYSQL_DB_TYPE: - return String.format(MYSQL_TARGET_CREATED_SQL_TEMPLATE, dateTimeFormatToSqlFormat(dateType), - dateTimeFormatToSqlFormat(dateType), from.toString(), dateTimeFormatToSqlFormat(dateType), - to.toString(), dateTimeFormatToSqlFormat(dateType), tenantAware.getCurrentTenant(), - dateTimeFormatToSqlFormat(dateType)); - default: - return null; - } - } - - private String getFeedbackReceivedQueryTemplate(final DateType dateType, final LocalDateTime from, - final LocalDateTime to) { - switch (databaseType) { - case H2_DB_TYPE: - return String.format(H2_CONTROLLER_FRRDBACK_SQL_TEMPLATE, dateTimeFormatToSqlFormat(dateType), - dateTimeFormatToSqlFormat(dateType), from.format(DATE_FORMAT), dateTimeFormatToSqlFormat(dateType), - to.format(DATE_FORMAT), dateTimeFormatToSqlFormat(dateType), tenantAware.getCurrentTenant(), - dateTimeFormatToSqlFormat(dateType)); - case MYSQL_DB_TYPE: - return String.format(MYSQL_CONTROLLER_FRRDBACK_SQL_TEMPLATE, dateTimeFormatToSqlFormat(dateType), - dateTimeFormatToSqlFormat(dateType), from.toString(), dateTimeFormatToSqlFormat(dateType), - to.toString(), dateTimeFormatToSqlFormat(dateType), tenantAware.getCurrentTenant(), - dateTimeFormatToSqlFormat(dateType)); - default: - return null; - } - } + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + DataReportSeries targetsCreatedOverPeriod(@NotNull DateType dateType, + @NotNull LocalDateTime from, @NotNull LocalDateTime to); /** * Generates report for feedback over period. @@ -270,19 +109,9 @@ public class ReportManagement { * @return DataReportSeries ListReportSeries list of action status * count */ - @Cacheable("feedbackReceivedOverTime") - public DataReportSeries feedbackReceivedOverTime(final DateType dateType, - final LocalDateTime from, final LocalDateTime to) { - final Query createNativeQuery = entityManager - .createNativeQuery(getFeedbackReceivedQueryTemplate(dateType, from, to)); - final List resultList = createNativeQuery.getResultList(); - - final List> reportItems = resultList.stream() - .map(r -> new DataReportSeriesItem<>(dateType.format((String) r[0]), ((Number) r[1]).longValue())) - .collect(Collectors.toList()); - - return new DataReportSeries<>("FeedbackRecieved", reportItems); - } + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + DataReportSeries feedbackReceivedOverTime(@NotNull DateType dateType, + @NotNull LocalDateTime from, @NotNull LocalDateTime to); /** * Generates a report as a {@link ListReportSeries} targets polled based on @@ -297,212 +126,8 @@ public class ReportManagement { * than a year, never. * */ - @Cacheable("targetsLastPoll") - public DataReportSeries targetsLastPoll() { - - final LocalDateTime now = LocalDateTime.now(); - final LocalDateTime beforeHour = now.minusHours(1); - final LocalDateTime beforeDay = now.minusDays(1); - final LocalDateTime beforeWeek = now.minusWeeks(1); - final LocalDateTime beforeMonth = now.minusMonths(1); - final LocalDateTime beforeYear = now.minusYears(1); - - final CriteriaBuilder cb = entityManager.getCriteriaBuilder(); - final List> resultList = new ArrayList<>(); - - // hours - resultList.add(new DataReportSeriesItem(SeriesTime.HOUR, - entityManager.createQuery(createCountSelectTargetsLastPoll(cb, beforeHour, now)).getSingleResult())); - // days - resultList.add(new DataReportSeriesItem(SeriesTime.DAY, entityManager - .createQuery(createCountSelectTargetsLastPoll(cb, beforeDay, beforeHour)).getSingleResult())); - // weeks - resultList.add(new DataReportSeriesItem(SeriesTime.WEEK, entityManager - .createQuery(createCountSelectTargetsLastPoll(cb, beforeWeek, beforeDay)).getSingleResult())); - // months - resultList.add(new DataReportSeriesItem(SeriesTime.MONTH, entityManager - .createQuery(createCountSelectTargetsLastPoll(cb, beforeMonth, beforeWeek)).getSingleResult())); - // years - resultList.add(new DataReportSeriesItem(SeriesTime.YEAR, entityManager - .createQuery(createCountSelectTargetsLastPoll(cb, beforeYear, beforeMonth)).getSingleResult())); - // years - resultList.add(new DataReportSeriesItem(SeriesTime.MORE_THAN_YEAR, - entityManager.createQuery(createCountSelectTargetsLastPoll(cb, null, beforeYear)).getSingleResult())); - // never - resultList.add(new DataReportSeriesItem(SeriesTime.NEVER, - entityManager.createQuery(createCountSelectTargetsLastPoll(cb, null, null)).getSingleResult())); - - return new DataReportSeries<>("TargetLastPoll", resultList); - } - - private CriteriaQuery createCountSelectTargetsLastPoll(final CriteriaBuilder cb, final LocalDateTime from, - final LocalDateTime to) { - - Long start = null; - Long end = null; - if (from != null) { - start = from.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); - } - if (to != null) { - end = to.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); - } - - // count select statement - final CriteriaQuery countSelect = cb.createQuery(Long.class); - final Root countSelectRoot = countSelect.from(Target.class); - final Join targetInfoJoin = countSelectRoot.join(Target_.targetInfo); - countSelect.select(cb.count(countSelectRoot)); - if (start != null && end != null) { - countSelect.where(cb.between(targetInfoJoin.get(TargetInfo_.lastTargetQuery), start, end)); - } else if (from == null && to != null) { - countSelect.where(cb.lessThanOrEqualTo(targetInfoJoin.get(TargetInfo_.lastTargetQuery), end)); - } else { - countSelect.where(cb.isNull(targetInfoJoin.get(TargetInfo_.lastTargetQuery))); - } - return countSelect; - } - - private List> mapDistirbutionUsageResultToDataReport(final int topXEntries, - final List resultListTop) { - final List> innerOuterReport = new ArrayList<>(); - final Map map = new LinkedHashMap<>(); - - int topXCounter = 0; - - for (final Object[] objects : resultListTop) { - - final boolean containsInnerOuter = map.containsKey(new DSName((String) objects[0])); - final String name = containsInnerOuter || topXCounter < topXEntries ? (String) objects[0] : null; - final DSName dsName = new DSName(name); - final String version = containsInnerOuter || topXCounter < topXEntries ? (String) objects[1] : null; - final Long count = (Long) objects[2]; - - InnerOuter innerouter = map.get(dsName); - if (innerouter == null) { - topXCounter++; - innerouter = new InnerOuter(dsName); - map.put(new DSName(name), innerouter); - } - innerouter.addOuter(new DSName(version), count); - } - - for (final InnerOuter inner : map.values()) { - final List> outerReportItems = new ArrayList<>(); - - if (inner.name.getName() != null) { - for (final InnerOuter outer : inner.outer) { - outerReportItems.add(outer.toItem()); - } - } else { - outerReportItems.add(new DataReportSeriesItem("misc", inner.count)); - } - - innerOuterReport.add(new InnerOuterDataReportSeries( - new DataReportSeries<>("DS-Name", Collections.singletonList(inner.toItem())), - new DataReportSeries<>("DS-Version", outerReportItems))); - } - - return innerOuterReport; - } - - private static final class InnerOuter { - final DSName name; - long count; - final List outer; - - private InnerOuter(final DSName idName) { - name = idName; - outer = new ArrayList<>(); - } - - private InnerOuter(final DSName idName, final long count) { - name = idName; - this.count = count; - outer = new ArrayList<>(); - } - - private void addOuter(final DSName idName, final long count) { - outer.add(new InnerOuter(idName, count)); - this.count += count; - } - - private DataReportSeriesItem toItem() { - return new DataReportSeriesItem<>(name.getName() != null ? name.getName() : "misc", count); - } - } - - /** - * Object contains the name and the id of an entity. - * - */ - private static final class DSName { - - private final String name; - - /** - * @param id - * the ID of an entity - * @param name - * the name of an entity - */ - private DSName(final String name) { - this.name = name; - } - - /** - * @return the name - */ - private String getName() { - return name; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + (name == null ? 0 : name.hashCode()); - return result; - } - - @Override - public boolean equals(final Object obj) { // NOSONAR - as this is - // generated - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - final DSName other = (DSName) obj; - if (name == null) { - if (other.name != null) { - return false; - } - } else if (!name.equals(other.name)) { - return false; - } - return true; - } - - @Override - public String toString() { - return "DSName [name=" + name + "]"; - } - } - - private String dateTimeFormatToSqlFormat(final DateType datatype) { - switch (databaseType) { - case H2_DB_TYPE: - return datatype.h2Format(); - case MYSQL_DB_TYPE: - return datatype.mySqlFormat(); - default: - return null; - } - } + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + DataReportSeries targetsLastPoll(); /** * Return DateTypes. @@ -580,4 +205,5 @@ public class ReportManagement { } } -} + +} \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupManagement.java index d204154d0..7c5503c19 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupManagement.java @@ -8,65 +8,20 @@ */ package org.eclipse.hawkbit.repository; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -import javax.persistence.EntityManager; -import javax.persistence.criteria.CriteriaBuilder; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Join; -import javax.persistence.criteria.JoinType; -import javax.persistence.criteria.ListJoin; -import javax.persistence.criteria.Root; import javax.validation.constraints.NotNull; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; -import org.eclipse.hawkbit.repository.model.Action; -import org.eclipse.hawkbit.repository.model.Action_; import org.eclipse.hawkbit.repository.model.Rollout; -import org.eclipse.hawkbit.repository.model.Rollout.RolloutStatus; import org.eclipse.hawkbit.repository.model.RolloutGroup; -import org.eclipse.hawkbit.repository.model.RolloutGroup_; -import org.eclipse.hawkbit.repository.model.RolloutTargetGroup; -import org.eclipse.hawkbit.repository.model.RolloutTargetGroup_; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetWithActionStatus; -import org.eclipse.hawkbit.repository.model.Target_; -import org.eclipse.hawkbit.repository.model.TotalTargetCountActionStatus; -import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.domain.Specification; import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Isolation; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.validation.annotation.Validated; -/** - * RolloutGroupManagement to control rollout groups. This service secures all - * the functionality based on the {@link PreAuthorize} annotation on methods. - */ -@Validated -@Service -@Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) -public class RolloutGroupManagement { - - @Autowired - private RolloutGroupRepository rolloutGroupRepository; - - @Autowired - private ActionRepository actionRepository; - - @Autowired - private TargetRepository targetRepository; - - @Autowired - private EntityManager entityManager; +public interface RolloutGroupManagement { /** * Retrieves a single {@link RolloutGroup} by its ID. @@ -77,9 +32,7 @@ public class RolloutGroupManagement { * does not exists */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - public RolloutGroup findRolloutGroupById(final Long rolloutGroupId) { - return rolloutGroupRepository.findOne(rolloutGroupId); - } + RolloutGroup findRolloutGroupById(@NotNull Long rolloutGroupId); /** * Retrieves a page of {@link RolloutGroup}s filtered by a given @@ -92,9 +45,7 @@ public class RolloutGroupManagement { * @return a page of found {@link RolloutGroup}s */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - public Page findRolloutGroupsByRolloutId(final Long rolloutId, final Pageable page) { - return rolloutGroupRepository.findByRolloutId(rolloutId, page); - } + Page findRolloutGroupsByRolloutId(@NotNull Long rolloutId, @NotNull Pageable page); /** * Retrieves a page of {@link RolloutGroup}s filtered by a given @@ -110,12 +61,8 @@ public class RolloutGroupManagement { * @return a page of found {@link RolloutGroup}s */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - public Page findRolloutGroupsByPredicate(final Rollout rollout, - final Specification specification, final Pageable page) { - return rolloutGroupRepository.findAll((root, query, criteriaBuilder) -> criteriaBuilder.and( - criteriaBuilder.equal(root.get(RolloutGroup_.rollout), rollout), - specification.toPredicate(root, query, criteriaBuilder)), page); - } + Page findRolloutGroupsAll(@NotNull Rollout rollout, + @NotNull Specification specification, @NotNull Pageable page); /** * Retrieves a page of {@link RolloutGroup}s filtered by a given @@ -128,21 +75,7 @@ public class RolloutGroupManagement { * @return a page of found {@link RolloutGroup}s */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - public Page findAllRolloutGroupsWithDetailedStatus(final Long rolloutId, final Pageable page) { - final Page rolloutGroups = rolloutGroupRepository.findByRolloutId(rolloutId, page); - final List rolloutGroupIds = rolloutGroups.getContent().stream().map(rollout -> rollout.getId()) - .collect(Collectors.toList()); - final Map> allStatesForRollout = getStatusCountItemForRolloutGroup( - rolloutGroupIds); - - for (final RolloutGroup rolloutGroup : rolloutGroups) { - final TotalTargetCountStatus totalTargetCountStatus = new TotalTargetCountStatus( - allStatesForRollout.get(rolloutGroup.getId()), rolloutGroup.getTotalTargets()); - rolloutGroup.setTotalTargetCountStatus(totalTargetCountStatus); - } - - return rolloutGroups; - } + Page findAllRolloutGroupsWithDetailedStatus(@NotNull Long rolloutId, @NotNull Pageable page); /** * Get count of targets in different status in rollout group. @@ -152,25 +85,9 @@ public class RolloutGroupManagement { * @return rolloutGroup with details of targets count for different statuses */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - public RolloutGroup findRolloutGroupWithDetailedStatus(final Long rolloutGroupId) { - final RolloutGroup rolloutGroup = findRolloutGroupById(rolloutGroupId); - final List rolloutStatusCountItems = actionRepository - .getStatusCountByRolloutGroupId(rolloutGroupId); - - final TotalTargetCountStatus totalTargetCountStatus = new TotalTargetCountStatus(rolloutStatusCountItems, - rolloutGroup.getTotalTargets()); - rolloutGroup.setTotalTargetCountStatus(totalTargetCountStatus); - return rolloutGroup; - - } - - private Map> getStatusCountItemForRolloutGroup( - final List rolloutGroupIds) { - final List resultList = actionRepository - .getStatusCountByRolloutGroupId(rolloutGroupIds); - return resultList.stream().collect(Collectors.groupingBy(TotalTargetCountActionStatus::getId)); - } + RolloutGroup findRolloutGroupWithDetailedStatus(@NotNull Long rolloutGroupId); + // TODO discuss: target read perm missing? /** * Get targets of specified rollout group. * @@ -184,15 +101,10 @@ public class RolloutGroupManagement { * @return Page list of targets of a rollout group */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - public Page findRolloutGroupTargets(final RolloutGroup rolloutGroup, - final Specification specification, final Pageable page) { - return targetRepository.findAll((root, query, criteriaBuilder) -> { - final ListJoin rolloutTargetJoin = root.join(Target_.rolloutTargetGroup); - return criteriaBuilder.and(specification.toPredicate(root, query, criteriaBuilder), - criteriaBuilder.equal(rolloutTargetJoin.get(RolloutTargetGroup_.rolloutGroup), rolloutGroup)); - }, page); - } + Page findRolloutGroupTargets(@NotNull RolloutGroup rolloutGroup, + @NotNull Specification specification, @NotNull Pageable page); + // TODO discuss: target read perm missing? /** * Get targets of specified rollout group. * @@ -204,20 +116,9 @@ public class RolloutGroupManagement { * @return Page list of targets of a rollout group */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - public Page findRolloutGroupTargets(@NotNull final RolloutGroup rolloutGroup, final Pageable page) { - if (isRolloutStatusReady(rolloutGroup)) { - // in case of status ready the action has not been created yet and - // the relation information between target and rollout-group is - // stored in the #TargetRolloutGroup. - return targetRepository.findByRolloutTargetGroupRolloutGroupId(rolloutGroup.getId(), page); - } - return targetRepository.findByActionsRolloutGroup(rolloutGroup, page); - } - - private static boolean isRolloutStatusReady(final RolloutGroup rolloutGroup) { - return rolloutGroup != null && RolloutStatus.READY.equals(rolloutGroup.getRollout().getStatus()); - } + Page findRolloutGroupTargets(@NotNull RolloutGroup rolloutGroup, @NotNull Pageable page); + // TODO discuss: target read perm missing? /** * * Find all targets with action status by rollout group id. The action @@ -233,31 +134,7 @@ public class RolloutGroupManagement { * @return {@link TargetWithActionStatus} target with action status */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - public Page findAllTargetsWithActionStatus(final PageRequest pageRequest, - @NotNull final RolloutGroup rolloutGroup) { + Page findAllTargetsWithActionStatus(@NotNull PageRequest pageRequest, + @NotNull RolloutGroup rolloutGroup); - final CriteriaBuilder cb = entityManager.getCriteriaBuilder(); - final CriteriaQuery query = cb.createQuery(Object[].class); - final CriteriaQuery countQuery = cb.createQuery(Long.class); - - final Root targetRoot = query.distinct(true).from(RolloutTargetGroup.class); - final Join targetJoin = targetRoot.join(RolloutTargetGroup_.target); - final ListJoin actionJoin = targetRoot.join(RolloutTargetGroup_.actions, - JoinType.LEFT); - - final Root countQueryFrom = countQuery.distinct(true).from(RolloutTargetGroup.class); - countQueryFrom.join(RolloutTargetGroup_.target); - countQueryFrom.join(RolloutTargetGroup_.actions, JoinType.LEFT); - countQuery.select(cb.count(countQueryFrom)) - .where(cb.equal(countQueryFrom.get(RolloutTargetGroup_.rolloutGroup), rolloutGroup)); - final Long totalCount = entityManager.createQuery(countQuery).getSingleResult(); - - final CriteriaQuery multiselect = query.multiselect(targetJoin, actionJoin.get(Action_.status)) - .where(cb.equal(targetRoot.get(RolloutTargetGroup_.rolloutGroup), rolloutGroup)); - final List targetWithActionStatus = entityManager.createQuery(multiselect) - .setFirstResult(pageRequest.getOffset()).setMaxResults(pageRequest.getPageSize()).getResultList() - .stream().map(o -> new TargetWithActionStatus((Target) o[0], (Action.Status) o[1])) - .collect(Collectors.toList()); - return new PageImpl<>(targetWithActionStatus, pageRequest, totalCount); - } -} +} \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java index 09decfc03..bf4924692 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java @@ -8,131 +8,29 @@ */ package org.eclipse.hawkbit.repository; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.Executor; -import java.util.stream.Collectors; - -import javax.persistence.EntityManager; import javax.validation.constraints.NotNull; -import org.eclipse.hawkbit.cache.CacheWriteNotify; import org.eclipse.hawkbit.eventbus.event.RolloutGroupCreatedEvent; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; import org.eclipse.hawkbit.repository.exception.RolloutIllegalStateException; -import org.eclipse.hawkbit.repository.model.Action; -import org.eclipse.hawkbit.repository.model.Action.ActionType; -import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.Rollout.RolloutStatus; import org.eclipse.hawkbit.repository.model.RolloutGroup; import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupConditions; -import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupErrorCondition; import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupStatus; -import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupSuccessCondition; -import org.eclipse.hawkbit.repository.model.RolloutTargetGroup; -import org.eclipse.hawkbit.repository.model.Rollout_; -import org.eclipse.hawkbit.repository.model.Target; -import org.eclipse.hawkbit.repository.model.TotalTargetCountActionStatus; -import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; -import org.eclipse.hawkbit.rollout.condition.RolloutGroupActionEvaluator; -import org.eclipse.hawkbit.rollout.condition.RolloutGroupConditionEvaluator; import org.hibernate.validator.constraints.NotEmpty; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.context.ApplicationContext; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; -import org.springframework.data.domain.Sort; -import org.springframework.data.domain.Sort.Direction; import org.springframework.data.jpa.domain.Specification; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.stereotype.Service; -import org.springframework.transaction.PlatformTransactionManager; -import org.springframework.transaction.TransactionDefinition; -import org.springframework.transaction.annotation.Isolation; -import org.springframework.transaction.annotation.Propagation; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.transaction.support.DefaultTransactionDefinition; -import org.springframework.transaction.support.TransactionTemplate; -import org.springframework.util.Assert; -import org.springframework.validation.annotation.Validated; /** * RolloutManagement to control rollouts e.g. like creating, starting, resuming * and pausing rollouts. This service secures all the functionality based on the * {@link PreAuthorize} annotation on methods. */ -@Validated -@Service -@EnableScheduling -@Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) -public class RolloutManagement { - private static final Logger LOGGER = LoggerFactory.getLogger(RolloutManagement.class); - - @Autowired - private EntityManager entityManager; - - @Autowired - private RolloutRepository rolloutRepository; - - @Autowired - private TargetManagement targetManagement; - - @Autowired - private TargetRepository targetRepository; - - @Autowired - private RolloutGroupRepository rolloutGroupRepository; - - @Autowired - private DeploymentManagement deploymentManagement; - - @Autowired - private RolloutTargetGroupRepository rolloutTargetGroupRepository; - - @Autowired - private ActionRepository actionRepository; - - @Autowired - private ApplicationContext context; - - @Autowired - private NoCountPagingRepository criteriaNoCountDao; - - @Autowired - private PlatformTransactionManager txManager; - - @Autowired - private CacheWriteNotify cacheWriteNotify; - - @Autowired - @Qualifier("asyncExecutor") - private Executor executor; - - /* - * set which stores the rollouts which are asynchronously creating. This is - * necessary to verify rollouts which maybe stuck during creationg e.g. - * because of database interruption, failures or even application crash. - * !This is not cluster aware! - */ - private static final Set creatingRollouts = ConcurrentHashMap.newKeySet(); - - /* - * set which stores the rollouts which are asynchronously starting. This is - * necessary to verify rollouts which maybe stuck during starting e.g. - * because of database interruption, failures or even application crash. - * !This is not cluster aware! - */ - private static final Set startingRollouts = ConcurrentHashMap.newKeySet(); +public interface RolloutManagement { /** * Retrieves all rollouts. @@ -142,9 +40,7 @@ public class RolloutManagement { * @return a page of found rollouts */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - public Page findAll(final Pageable page) { - return rolloutRepository.findAll(page); - } + Page findAll(@NotNull Pageable page); /** * Retrieves all rollouts found by the given specification. @@ -156,12 +52,8 @@ public class RolloutManagement { * @return a page of found rollouts */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - public Page findAllWithDetailedStatusByPredicate(final Specification specification, - final Pageable page) { - final Page findAll = rolloutRepository.findAll(specification, page); - setRolloutStatusDetails(findAll); - return findAll; - } + Page findAllWithDetailedStatusByPredicate(@NotNull Specification specification, + @NotNull Pageable page); /** * Retrieves a specific rollout by its ID. @@ -172,9 +64,7 @@ public class RolloutManagement { * not exists */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - public Rollout findRolloutById(final Long rolloutId) { - return rolloutRepository.findOne(rolloutId); - } + Rollout findRolloutById(@NotNull Long rolloutId); /** * Persists a new rollout entity. The filter within the @@ -201,14 +91,8 @@ public class RolloutManagement { * @throws IllegalArgumentException * in case the given groupSize is zero or lower. */ - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @Modifying @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_WRITE) - public Rollout createRollout(final Rollout rollout, final int amountGroup, - final RolloutGroupConditions conditions) { - final Rollout savedRollout = createRollout(rollout, amountGroup); - return createRolloutGroups(amountGroup, conditions, savedRollout); - } + Rollout createRollout(@NotNull Rollout rollout, int amountGroup, @NotNull RolloutGroupConditions conditions); /** * Persists a new rollout entity. The filter within the @@ -244,116 +128,8 @@ public class RolloutManagement { * @return the created rollout entity in state * {@link RolloutStatus#CREATING} */ - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @Modifying @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_WRITE) - public Rollout createRolloutAsync(final Rollout rollout, final int amountGroup, - final RolloutGroupConditions conditions) { - final Rollout savedRollout = createRollout(rollout, amountGroup); - creatingRollouts.add(savedRollout.getName()); - // need to flush the entity manager here to get the ID of the rollout, - // because entity manager is set to FlushMode#Auto, entitymanager will - // flush the Target entity, due the indirect relationship to the Rollout - // entity without set an ID JPA is throwing a Invalid - // 'org.springframework.dao.InvalidDataAccessApiUsageException: During - // synchronization aect was found through a relationship that was not - // marked cascade PERSIST' - entityManager.flush(); - executor.execute(() -> { - try { - createRolloutGroupsInNewTransaction(amountGroup, conditions, savedRollout); - } finally { - creatingRollouts.remove(savedRollout.getName()); - } - }); - return savedRollout; - } - - private Rollout createRollout(final Rollout rollout, final int amountGroup) { - verifyRolloutGroupParameter(amountGroup); - final Long totalTargets = targetManagement.countTargetByTargetFilterQuery(rollout.getTargetFilterQuery()); - rollout.setTotalTargets(totalTargets.longValue()); - return rolloutRepository.save(rollout); - } - - private static void verifyRolloutGroupParameter(final int amountGroup) { - if (amountGroup <= 0) { - throw new IllegalArgumentException("the amountGroup must be greater than zero"); - } else if (amountGroup > 500) { - throw new IllegalArgumentException("the amountGroup must not be greater than 500"); - } - } - - private Rollout createRolloutGroupsInNewTransaction(final int amountOfGroups, - final RolloutGroupConditions conditions, final Rollout savedRollout) { - final DefaultTransactionDefinition def = new DefaultTransactionDefinition(); - def.setName("creatingRollout"); - def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); - return new TransactionTemplate(txManager, def) - .execute(status -> createRolloutGroups(amountOfGroups, conditions, savedRollout)); - } - - /** - * Method for creating rollout groups and calculating group sizes. Group - * sizes are calculated by dividing the total count of targets through the - * amount of given groups. In same cases this will lead to less rollout - * groups than given by client. - * - * @param amountOfGroups - * the amount of groups - * @param conditions - * the rollout group conditions - * @param savedRollout - * the rollout - * @return the rollout with created groups - */ - private Rollout createRolloutGroups(final int amountOfGroups, final RolloutGroupConditions conditions, - final Rollout savedRollout) { - int pageIndex = 0; - int groupIndex = 0; - final Long totalCount = savedRollout.getTotalTargets(); - final int groupSize = (int) Math.ceil((double) totalCount / (double) amountOfGroups); - // validate if the amount of groups that will be created are the amount - // of groups that the client what's to have created. - int amountGroupValidated = amountOfGroups; - final int amountGroupCreation = (int) (Math.ceil((double) totalCount / (double) groupSize)); - if (amountGroupCreation == (amountOfGroups - 1)) { - amountGroupValidated--; - } - RolloutGroup lastSavedGroup = null; - while (pageIndex < totalCount) { - groupIndex++; - final String nameAndDesc = "group-" + groupIndex; - final RolloutGroup group = new RolloutGroup(); - group.setName(nameAndDesc); - group.setDescription(nameAndDesc); - group.setRollout(savedRollout); - group.setParent(lastSavedGroup); - group.setSuccessCondition(conditions.getSuccessCondition()); - group.setSuccessConditionExp(conditions.getSuccessConditionExp()); - group.setErrorCondition(conditions.getErrorCondition()); - group.setErrorConditionExp(conditions.getErrorConditionExp()); - group.setErrorAction(conditions.getErrorAction()); - group.setErrorActionExp(conditions.getErrorActionExp()); - - final RolloutGroup savedGroup = rolloutGroupRepository.save(group); - - final Slice targetGroup = targetManagement.findTargetsAll(savedRollout.getTargetFilterQuery(), - new OffsetBasedPageRequest(pageIndex, groupSize, new Sort(Direction.ASC, "id"))); - savedGroup.setTotalTargets(targetGroup.getContent().size()); - - lastSavedGroup = savedGroup; - - targetGroup - .forEach(target -> rolloutTargetGroupRepository.save(new RolloutTargetGroup(savedGroup, target))); - cacheWriteNotify.rolloutGroupCreated(groupIndex, savedRollout.getId(), savedGroup.getId(), - amountGroupValidated, groupIndex); - pageIndex += groupSize; - } - - savedRollout.setStatus(RolloutStatus.READY); - return rolloutRepository.save(savedRollout); - } + Rollout createRolloutAsync(@NotNull Rollout rollout, int amountGroup, @NotNull RolloutGroupConditions conditions); /** * Starts a rollout which has been created. The rollout must be in @@ -373,15 +149,9 @@ public class RolloutManagement { * if given rollout is not in {@link RolloutStatus#READY}. Only * ready rollouts can be started. */ - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @Modifying @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_WRITE + SpringEvalExpressions.HAS_AUTH_OR + SpringEvalExpressions.IS_SYSTEM_CODE) - public Rollout startRollout(final Rollout rollout) { - final Rollout mergedRollout = entityManager.merge(rollout); - checkIfRolloutCanStarted(rollout, mergedRollout); - return doStartRollout(mergedRollout); - } + Rollout startRollout(@NotNull Rollout rollout); /** * Starts a rollout asynchronously which has been created. The rollout must @@ -402,61 +172,9 @@ public class RolloutManagement { * if given rollout is not in {@link RolloutStatus#READY}. Only * ready rollouts can be started. */ - @Transactional - @Modifying @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_WRITE + SpringEvalExpressions.HAS_AUTH_OR + SpringEvalExpressions.IS_SYSTEM_CODE) - public Rollout startRolloutAsync(final Rollout rollout) { - final Rollout mergedRollout = entityManager.merge(rollout); - checkIfRolloutCanStarted(rollout, mergedRollout); - mergedRollout.setStatus(RolloutStatus.STARTING); - final Rollout updatedRollout = rolloutRepository.save(mergedRollout); - startingRollouts.add(updatedRollout.getName()); - executor.execute(() -> { - try { - final DefaultTransactionDefinition def = new DefaultTransactionDefinition(); - def.setName("startingRollout"); - def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); - new TransactionTemplate(txManager, def).execute(status -> { - doStartRollout(updatedRollout); - return null; - }); - } finally { - startingRollouts.remove(updatedRollout.getName()); - } - }); - return updatedRollout; - - } - - private Rollout doStartRollout(final Rollout rollout) { - final DistributionSet distributionSet = rollout.getDistributionSet(); - final ActionType actionType = rollout.getActionType(); - final long forceTime = rollout.getForcedTime(); - final List rolloutGroups = rolloutGroupRepository.findByRolloutOrderByIdAsc(rollout); - for (int iGroup = 0; iGroup < rolloutGroups.size(); iGroup++) { - final RolloutGroup rolloutGroup = rolloutGroups.get(iGroup); - final List targetGroup = targetRepository.findByRolloutTargetGroupRolloutGroup(rolloutGroup); - // firstgroup can already be started - if (iGroup == 0) { - final List targetsWithActionType = targetGroup.stream() - .map(t -> new TargetWithActionType(t.getControllerId(), actionType, forceTime)) - .collect(Collectors.toList()); - deploymentManagement.assignDistributionSet(distributionSet.getId(), targetsWithActionType, rollout, - rolloutGroup); - rolloutGroup.setStatus(RolloutGroupStatus.RUNNING); - } else { - // create only not active actions with status scheduled so they - // can be activated later - deploymentManagement.createScheduledAction(targetGroup, distributionSet, actionType, forceTime, rollout, - rolloutGroup); - rolloutGroup.setStatus(RolloutGroupStatus.SCHEDULED); - } - rolloutGroupRepository.save(rolloutGroup); - } - rollout.setStatus(RolloutStatus.RUNNING); - return rolloutRepository.save(rollout); - } + Rollout startRolloutAsync(@NotNull Rollout rollout); /** * Pauses a rollout which is currently running. The Rollout switches @@ -477,24 +195,9 @@ public class RolloutManagement { * if given rollout is not in {@link RolloutStatus#RUNNING}. * Only running rollouts can be paused. */ - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @Modifying @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_WRITE + SpringEvalExpressions.HAS_AUTH_OR + SpringEvalExpressions.IS_SYSTEM_CODE) - public void pauseRollout(final Rollout rollout) { - final Rollout mergedRollout = entityManager.merge(rollout); - if (mergedRollout.getStatus() != RolloutStatus.RUNNING) { - throw new RolloutIllegalStateException("Rollout can only be paused in state running but current state is " - + rollout.getStatus().name().toLowerCase()); - } - // setting the complete rollout only in paused state. This is sufficient - // due the currently running groups will be completed and new groups are - // not started until rollout goes back to running state again. The - // periodically check for running rollouts will skip rollouts in pause - // state. - mergedRollout.setStatus(RolloutStatus.PAUSED); - rolloutRepository.save(mergedRollout); - } + void pauseRollout(@NotNull Rollout rollout); /** * Resumes a paused rollout. The rollout switches back to @@ -507,19 +210,9 @@ public class RolloutManagement { * if given rollout is not in {@link RolloutStatus#PAUSED}. Only * paused rollouts can be resumed. */ - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @Modifying @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_WRITE + SpringEvalExpressions.HAS_AUTH_OR + SpringEvalExpressions.IS_SYSTEM_CODE) - public void resumeRollout(final Rollout rollout) { - final Rollout mergedRollout = entityManager.merge(rollout); - if (!(RolloutStatus.PAUSED.equals(mergedRollout.getStatus()))) { - throw new RolloutIllegalStateException("Rollout can only be resumed in state paused but current state is " - + rollout.getStatus().name().toLowerCase()); - } - mergedRollout.setStatus(RolloutStatus.RUNNING); - rolloutRepository.save(mergedRollout); - } + void resumeRollout(@NotNull Rollout rollout); /** * Checking running rollouts. Rollouts which are checked updating the @@ -549,211 +242,30 @@ public class RolloutManagement { * this check. This check is only applied if the last check is * less than (lastcheck-delay). */ - @Transactional(propagation = Propagation.REQUIRES_NEW, isolation = Isolation.READ_UNCOMMITTED) - @Modifying @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_WRITE + SpringEvalExpressions.HAS_AUTH_OR + SpringEvalExpressions.IS_SYSTEM_CODE) - public void checkRunningRollouts(final long delayBetweenChecks) { - verifyStuckedRollouts(); - final long lastCheck = System.currentTimeMillis(); - final int updated = rolloutRepository.updateLastCheck(lastCheck, delayBetweenChecks, RolloutStatus.RUNNING); - - if (updated == 0) { - // nothing to check, maybe another instance already checked in - // between - LOGGER.debug("No rolloutcheck necessary for current scheduled check {}, next check at {}", lastCheck, - lastCheck + delayBetweenChecks); - return; - } - - final List rolloutsToCheck = rolloutRepository.findByLastCheckAndStatus(lastCheck, - RolloutStatus.RUNNING); - LOGGER.info("Found {} running rollouts to check", rolloutsToCheck.size()); - - for (final Rollout rollout : rolloutsToCheck) { - LOGGER.debug("Checking rollout {}", rollout); - final List rolloutGroups = rolloutGroupRepository.findByRolloutAndStatus(rollout, - RolloutGroupStatus.RUNNING); - - if (rolloutGroups.isEmpty()) { - // no running rollouts, probably there was an error - // somewhere at the latest group. And the latest group has - // been switched from running into error state. So we need - // to find the latest group which - executeLatestRolloutGroup(rollout); - } else { - LOGGER.debug("Rollout {} has {} running groups", rollout.getId(), rolloutGroups.size()); - executeRolloutGroups(rollout, rolloutGroups); - } - - if (isRolloutComplete(rollout)) { - LOGGER.info("Rollout {} is finished, setting finished status", rollout); - rollout.setStatus(RolloutStatus.FINISHED); - rolloutRepository.save(rollout); - } - } - } + void checkRunningRollouts(long delayBetweenChecks); /** - * Verifies and handles stucked rollouts in asynchronous creation or - * starting state. If rollouts are created or started asynchronously it - * might be that they keep in state {@link RolloutStatus#CREATING} or - * {@link RolloutStatus#STARTING} due database or application interruption. - * In case this happens, set the rollout to error state. - */ - private void verifyStuckedRollouts() { - final List rolloutsInCreatingState = rolloutRepository.findByStatus(RolloutStatus.CREATING); - rolloutsInCreatingState.stream().filter(rollout -> !creatingRollouts.contains(rollout.getName())) - .forEach(rollout -> { - LOGGER.warn( - "Determined error during rollout creation of rollout {}, stucking in creating state, setting to status", - rollout, RolloutStatus.ERROR_CREATING); - rollout.setStatus(RolloutStatus.ERROR_CREATING); - rolloutRepository.save(rollout); - }); - - final List rolloutsInStartingState = rolloutRepository.findByStatus(RolloutStatus.STARTING); - rolloutsInStartingState.stream().filter(rollout -> !startingRollouts.contains(rollout.getName())) - .forEach(rollout -> { - LOGGER.warn( - "Determined error during rollout starting of rollout {}, stucking in starting state, setting to status", - rollout, RolloutStatus.ERROR_STARTING); - rollout.setStatus(RolloutStatus.ERROR_STARTING); - rolloutRepository.save(rollout); - }); - - } - - private void executeRolloutGroups(final Rollout rollout, final List rolloutGroups) { - for (final RolloutGroup rolloutGroup : rolloutGroups) { - // error state check, do we need to stop the whole - // rollout because of error? - final RolloutGroupErrorCondition errorCondition = rolloutGroup.getErrorCondition(); - final boolean isError = checkErrorState(rollout, rolloutGroup, errorCondition); - if (isError) { - LOGGER.info("Rollout {} {} has error, calling error action", rollout.getName(), rollout.getId()); - callErrorAction(rollout, rolloutGroup); - } else { - // not in error so check finished state, do we need to - // start the next group? - final RolloutGroupSuccessCondition finishedCondition = rolloutGroup.getSuccessCondition(); - checkFinishCondition(rollout, rolloutGroup, finishedCondition); - if (isRolloutGroupComplete(rollout, rolloutGroup)) { - rolloutGroup.setStatus(RolloutGroupStatus.FINISHED); - rolloutGroupRepository.save(rolloutGroup); - } - } - } - } - - private void executeLatestRolloutGroup(final Rollout rollout) { - final List latestRolloutGroup = rolloutGroupRepository - .findByRolloutAndStatusNotOrderByIdDesc(rollout, RolloutGroupStatus.SCHEDULED); - if (latestRolloutGroup.isEmpty()) { - return; - } - executeRolloutGroupSuccessAction(rollout, latestRolloutGroup.get(0)); - } - - private void callErrorAction(final Rollout rollout, final RolloutGroup rolloutGroup) { - try { - context.getBean(rolloutGroup.getErrorAction().getBeanName(), RolloutGroupActionEvaluator.class) - .eval(rollout, rolloutGroup, rolloutGroup.getErrorActionExp()); - } catch (final BeansException e) { - LOGGER.error("Something bad happend when accessing the error action bean {}", - rolloutGroup.getErrorAction().getBeanName(), e); - } - } - - private boolean isRolloutComplete(final Rollout rollout) { - final Long groupsActiveLeft = rolloutGroupRepository.countByRolloutAndStatusOrStatus(rollout, - RolloutGroupStatus.RUNNING, RolloutGroupStatus.SCHEDULED); - return groupsActiveLeft == 0; - } - - private boolean isRolloutGroupComplete(final Rollout rollout, final RolloutGroup rolloutGroup) { - final Long actionsLeftForRollout = actionRepository - .countByRolloutAndRolloutGroupAndStatusNotAndStatusNotAndStatusNot(rollout, rolloutGroup, - Action.Status.ERROR, Action.Status.FINISHED, Action.Status.CANCELED); - return actionsLeftForRollout == 0; - } - - private boolean checkErrorState(final Rollout rollout, final RolloutGroup rolloutGroup, - final RolloutGroupErrorCondition errorCondition) { - if (errorCondition == null) { - // there is no error condition, so return false, don't have error. - return false; - } - try { - return context.getBean(errorCondition.getBeanName(), RolloutGroupConditionEvaluator.class).eval(rollout, - rolloutGroup, rolloutGroup.getErrorConditionExp()); - } catch (final BeansException e) { - LOGGER.error("Something bad happend when accessing the error condition bean {}", - errorCondition.getBeanName(), e); - return false; - } - } - - private boolean checkFinishCondition(final Rollout rollout, final RolloutGroup rolloutGroup, - final RolloutGroupSuccessCondition finishCondition) { - LOGGER.trace("Checking finish condition {} on rolloutgroup {}", finishCondition, rolloutGroup); - try { - final boolean isFinished = context - .getBean(finishCondition.getBeanName(), RolloutGroupConditionEvaluator.class) - .eval(rollout, rolloutGroup, rolloutGroup.getSuccessConditionExp()); - if (isFinished) { - LOGGER.info("Rolloutgroup {} is finished, starting next group", rolloutGroup); - executeRolloutGroupSuccessAction(rollout, rolloutGroup); - } else { - LOGGER.debug("Rolloutgroup {} is still running", rolloutGroup); - } - return isFinished; - } catch (final BeansException e) { - LOGGER.error("Something bad happend when accessing the finish condition bean {}", - finishCondition.getBeanName(), e); - return false; - } - } - - private void executeRolloutGroupSuccessAction(final Rollout rollout, final RolloutGroup rolloutGroup) { - context.getBean(rolloutGroup.getSuccessAction().getBeanName(), RolloutGroupActionEvaluator.class).eval(rollout, - rolloutGroup, rolloutGroup.getSuccessActionExp()); - } - - /** - * Counts all {@link Target}s in the repository. + * Counts all {@link Rollout}s in the repository. * - * @return number of targets + * @return number of roll outs */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - public Long countRolloutsAll() { - return rolloutRepository.count(); - } + Long countRolloutsAll(); /** - * Count rollouts by specified filter text. + * Count rollouts by given text in name or description. * * @param searchText * name or description * @return total count rollouts for specified filter text. */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - public Long countRolloutsAllByFilters(final String searchText) { - return rolloutRepository.count(likeNameOrDescription(searchText)); - } - - private static Specification likeNameOrDescription(final String searchText) { - return (rolloutRoot, query, criteriaBuilder) -> { - final String searchTextToLower = searchText.toLowerCase(); - return criteriaBuilder.or( - criteriaBuilder.like(criteriaBuilder.lower(rolloutRoot.get(Rollout_.name)), searchTextToLower), - criteriaBuilder.like(criteriaBuilder.lower(rolloutRoot.get(Rollout_.description)), - searchTextToLower)); - }; - } + Long countRolloutsAllByFilters(@NotEmpty String searchText); /** - * * Retrieves a specific rollout by its ID. + * Finds rollouts by given text in name or description. * * @param pageable * the page request to sort and limit the result @@ -763,12 +275,7 @@ public class RolloutManagement { * not exists */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - public Slice findRolloutByFilters(final Pageable pageable, @NotEmpty final String searchText) { - final Specification specs = likeNameOrDescription(searchText); - final Slice findAll = criteriaNoCountDao.findAll(specs, pageable, Rollout.class); - setRolloutStatusDetails(findAll); - return findAll; - } + Slice findRolloutByFilters(@NotNull Pageable pageable, @NotEmpty String searchText); /** * Retrieves a specific rollout by its name. @@ -779,9 +286,7 @@ public class RolloutManagement { * does not exists */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - public Rollout findRolloutByName(final String rolloutName) { - return rolloutRepository.findByName(rolloutName); - } + Rollout findRolloutByName(@NotNull String rolloutName); /** * Update rollout details. @@ -791,14 +296,8 @@ public class RolloutManagement { * * @return Rollout updated rollout */ - @NotNull - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @Modifying @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_WRITE) - public Rollout updateRollout(@NotNull final Rollout rollout) { - Assert.notNull(rollout.getId()); - return rolloutRepository.save(rollout); - } + Rollout updateRollout(@NotNull Rollout rollout); /** * Get count of targets in different status in rollout. @@ -810,12 +309,7 @@ public class RolloutManagement { * */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - public Page findAllRolloutsWithDetailedStatus(final Pageable page) { - final Page rollouts = findAll(page); - setRolloutStatusDetails(rollouts); - return rollouts; - - } + Page findAllRolloutsWithDetailedStatus(@NotNull Pageable page); /** * Get count of targets in different status in rollout. @@ -826,40 +320,7 @@ public class RolloutManagement { * */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - public Rollout findRolloutWithDetailedStatus(final Long rolloutId) { - final Rollout rollout = findRolloutById(rolloutId); - final List rolloutStatusCountItems = actionRepository - .getStatusCountByRolloutId(rolloutId); - final TotalTargetCountStatus totalTargetCountStatus = new TotalTargetCountStatus(rolloutStatusCountItems, - rollout.getTotalTargets()); - rollout.setTotalTargetCountStatus(totalTargetCountStatus); - return rollout; - } - - private Map> getStatusCountItemForRollout(final List rolloutIds) { - final List resultList = actionRepository.getStatusCountByRolloutId(rolloutIds); - return resultList.stream().collect(Collectors.groupingBy(TotalTargetCountActionStatus::getId)); - } - - private void setRolloutStatusDetails(final Slice rollouts) { - final List rolloutIds = rollouts.getContent().stream().map(rollout -> rollout.getId()) - .collect(Collectors.toList()); - final Map> allStatesForRollout = getStatusCountItemForRollout( - rolloutIds); - - for (final Rollout rollout : rollouts) { - final TotalTargetCountStatus totalTargetCountStatus = new TotalTargetCountStatus( - allStatesForRollout.get(rollout.getId()), rollout.getTotalTargets()); - rollout.setTotalTargetCountStatus(totalTargetCountStatus); - } - } - - private static void checkIfRolloutCanStarted(final Rollout rollout, final Rollout mergedRollout) { - if (!(RolloutStatus.READY.equals(mergedRollout.getStatus()))) { - throw new RolloutIllegalStateException("Rollout can only be started in state ready but current state is " - + rollout.getStatus().name().toLowerCase()); - } - } + Rollout findRolloutWithDetailedStatus(@NotNull Long rolloutId); /*** * Get finished percentage details for a specified group which is in running @@ -871,16 +332,7 @@ public class RolloutManagement { * the ID of the {@link RolloutGroup} * @return percentage finished */ - public float getFinishedPercentForRunningGroup(final Long rolloutId, final RolloutGroup rolloutGroup) { - final Long totalGroup = rolloutGroup.getTotalTargets(); - final Long finished = actionRepository.countByRolloutIdAndRolloutGroupIdAndStatus(rolloutId, - rolloutGroup.getId(), Action.Status.FINISHED); - if (totalGroup == 0) { - // in case e.g. targets has been deleted we don't have any actions - // left for this group, so the group is finished - return 100; - } - // calculate threshold - return ((float) finished / (float) totalGroup) * 100; - } -} + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) + float getFinishedPercentForRunningGroup(@NotNull Long rolloutId, @NotNull RolloutGroup rolloutGroup); + +} \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutScheduler.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutScheduler.java index 6671ad896..03ece28ee 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutScheduler.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutScheduler.java @@ -10,6 +10,7 @@ package org.eclipse.hawkbit.repository; import java.util.List; +import org.eclipse.hawkbit.repository.jpa.SystemManagement; import org.eclipse.hawkbit.security.SystemSecurityContext; import org.eclipse.hawkbit.tenancy.TenantAware; import org.slf4j.Logger; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantConfigurationManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantConfigurationManagement.java index c292b39e3..10a88b232 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantConfigurationManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantConfigurationManagement.java @@ -1,11 +1,3 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ package org.eclipse.hawkbit.repository; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; @@ -13,39 +5,11 @@ import org.eclipse.hawkbit.repository.model.TenantConfiguration; import org.eclipse.hawkbit.repository.model.TenantConfigurationValue; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; import org.eclipse.hawkbit.tenancy.configuration.validator.TenantConfigurationValidatorException; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.cache.annotation.CacheEvict; -import org.springframework.cache.annotation.Cacheable; -import org.springframework.context.ApplicationContext; -import org.springframework.context.EnvironmentAware; import org.springframework.core.convert.ConversionFailedException; -import org.springframework.core.convert.support.ConfigurableConversionService; -import org.springframework.core.convert.support.DefaultConversionService; import org.springframework.core.env.Environment; -import org.springframework.data.jpa.repository.Modifying; import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Isolation; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.validation.annotation.Validated; -/** - * Central tenant configuration management operations of the SP server. - */ -@Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) -@Validated -@Service -public class TenantConfigurationManagement implements EnvironmentAware { - - @Autowired - private TenantConfigurationRepository tenantConfigurationRepository; - - @Autowired - private ApplicationContext applicationContext; - - private final ConfigurableConversionService conversionService = new DefaultConversionService(); - - private Environment environment; +public interface TenantConfigurationManagement { /** * Retrieves a configuration value from the e.g. tenant overwritten @@ -70,37 +34,10 @@ public class TenantConfigurationManagement implements EnvironmentAware { * if the property cannot be converted to the given * {@code propertyType} */ - - @Cacheable(value = "tenantConfiguration", key = "#configurationKey.getKeyName()") @PreAuthorize(value = SpringEvalExpressions.HAS_AUTH_TENANT_CONFIGURATION + SpringEvalExpressions.HAS_AUTH_OR + SpringEvalExpressions.IS_SYSTEM_CODE) - public TenantConfigurationValue getConfigurationValue(final TenantConfigurationKey configurationKey, - final Class propertyType) { - validateTenantConfigurationDataType(configurationKey, propertyType); - - final TenantConfiguration tenantConfiguration = tenantConfigurationRepository - .findByKey(configurationKey.getKeyName()); - - return buildTenantConfigurationValueByKey(configurationKey, propertyType, tenantConfiguration); - } - - /** - * Validates the data type of the tenant configuration. If it is possible to - * cast to the given data type. - * - * @param configurationKey - * the key - * @param propertyType - * the class - */ - protected void validateTenantConfigurationDataType(final TenantConfigurationKey configurationKey, - final Class propertyType) { - if (!configurationKey.getDataType().isAssignableFrom(propertyType)) { - throw new TenantConfigurationValidatorException( - String.format("Cannot parse the database value of type %s into the type %s.", - configurationKey.getDataType(), propertyType)); - } - } + TenantConfigurationValue getConfigurationValue(TenantConfigurationKey configurationKey, + Class propertyType); /** * Build the tenant configuration by the given key @@ -114,24 +51,10 @@ public class TenantConfigurationManagement implements EnvironmentAware { * @return if no default value is set and no database value available * or returns the tenant configuration value */ - protected TenantConfigurationValue buildTenantConfigurationValueByKey( - final TenantConfigurationKey configurationKey, final Class propertyType, - final TenantConfiguration tenantConfiguration) { - if (tenantConfiguration != null) { - return TenantConfigurationValue. builder().isGlobal(false).createdBy(tenantConfiguration.getCreatedBy()) - .createdAt(tenantConfiguration.getCreatedAt()) - .lastModifiedAt(tenantConfiguration.getLastModifiedAt()) - .lastModifiedBy(tenantConfiguration.getLastModifiedBy()) - .value(conversionService.convert(tenantConfiguration.getValue(), propertyType)).build(); - - } else if (configurationKey.getDefaultKeyName() != null) { - - return TenantConfigurationValue. builder().isGlobal(true).createdBy(null).createdAt(null) - .lastModifiedAt(null).lastModifiedBy(null) - .value(getGlobalConfigurationValue(configurationKey, propertyType)).build(); - } - return null; - } + @PreAuthorize(value = SpringEvalExpressions.HAS_AUTH_TENANT_CONFIGURATION + SpringEvalExpressions.HAS_AUTH_OR + + SpringEvalExpressions.IS_SYSTEM_CODE) + TenantConfigurationValue buildTenantConfigurationValueByKey(TenantConfigurationKey configurationKey, + Class propertyType, TenantConfiguration tenantConfiguration); /** * Retrieves a configuration value from the e.g. tenant overwritten @@ -153,9 +76,7 @@ public class TenantConfigurationManagement implements EnvironmentAware { */ @PreAuthorize(value = SpringEvalExpressions.HAS_AUTH_TENANT_CONFIGURATION + SpringEvalExpressions.HAS_AUTH_OR + SpringEvalExpressions.IS_SYSTEM_CODE) - public TenantConfigurationValue getConfigurationValue(final TenantConfigurationKey configurationKey) { - return getConfigurationValue(configurationKey, configurationKey.getDataType()); - } + TenantConfigurationValue getConfigurationValue(TenantConfigurationKey configurationKey); /** * returns the global configuration property either defined in the property @@ -179,23 +100,7 @@ public class TenantConfigurationManagement implements EnvironmentAware { */ @PreAuthorize(value = SpringEvalExpressions.HAS_AUTH_TENANT_CONFIGURATION + SpringEvalExpressions.HAS_AUTH_OR + SpringEvalExpressions.IS_SYSTEM_CODE) - public T getGlobalConfigurationValue(final TenantConfigurationKey configurationKey, - final Class propertyType) { - - if (!configurationKey.getDataType().isAssignableFrom(propertyType)) { - throw new TenantConfigurationValidatorException( - String.format("Cannot parse the database value of type %s into the type %s.", - configurationKey.getDataType(), propertyType)); - } - - final T valueInProperties = environment.getProperty(configurationKey.getDefaultKeyName(), propertyType); - - if (valueInProperties == null) { - return conversionService.convert(configurationKey.getDefaultValue(), propertyType); - } - - return valueInProperties; - } + T getGlobalConfigurationValue(TenantConfigurationKey configurationKey, Class propertyType); /** * Adds or updates a specific configuration for a specific tenant. @@ -213,41 +118,8 @@ public class TenantConfigurationManagement implements EnvironmentAware { * @throws ConversionFailedException * if the property cannot be converted to the given */ - @CacheEvict(value = "tenantConfiguration", key = "#configurationKey.getKeyName()") - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @Modifying @PreAuthorize(value = SpringEvalExpressions.HAS_AUTH_TENANT_CONFIGURATION) - public TenantConfigurationValue addOrUpdateConfiguration(final TenantConfigurationKey configurationKey, - final T value) { - - if (!configurationKey.getDataType().isAssignableFrom(value.getClass())) { - throw new TenantConfigurationValidatorException(String.format( - "Cannot parse the value %s of type %s into the type %s defined by the configuration key.", value, - value.getClass(), configurationKey.getDataType())); - } - - configurationKey.validate(applicationContext, value); - - TenantConfiguration tenantConfiguration = tenantConfigurationRepository - .findByKey(configurationKey.getKeyName()); - - if (tenantConfiguration == null) { - tenantConfiguration = new TenantConfiguration(configurationKey.getKeyName(), value.toString()); - } else { - tenantConfiguration.setValue(value.toString()); - } - - final TenantConfiguration updatedTenantConfiguration = tenantConfigurationRepository.save(tenantConfiguration); - - final Class clazzT = (Class) value.getClass(); - - return TenantConfigurationValue. builder().isGlobal(false) - .createdBy(updatedTenantConfiguration.getCreatedBy()) - .createdAt(updatedTenantConfiguration.getCreatedAt()) - .lastModifiedAt(updatedTenantConfiguration.getLastModifiedAt()) - .lastModifiedBy(updatedTenantConfiguration.getLastModifiedBy()) - .value(conversionService.convert(updatedTenantConfiguration.getValue(), clazzT)).build(); - } + TenantConfigurationValue addOrUpdateConfiguration(TenantConfigurationKey configurationKey, T value); /** * Deletes a specific configuration for the current tenant. Does nothing in @@ -256,16 +128,7 @@ public class TenantConfigurationManagement implements EnvironmentAware { * @param configurationKey * the configuration key to be deleted */ - @CacheEvict(value = "tenantConfiguration", key = "#configurationKey.getKeyName()") - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @Modifying @PreAuthorize(value = SpringEvalExpressions.HAS_AUTH_TENANT_CONFIGURATION) - public void deleteConfiguration(final TenantConfigurationKey configurationKey) { - tenantConfigurationRepository.deleteByKey(configurationKey.getKeyName()); - } + void deleteConfiguration(TenantConfigurationKey configurationKey); - @Override - public void setEnvironment(final Environment environment) { - this.environment = environment; - } -} +} \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ActionRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/ActionRepository.java similarity index 99% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ActionRepository.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/ActionRepository.java index 742a7d731..56ade85ff 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ActionRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/ActionRepository.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.jpa; import java.util.Collection; import java.util.List; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ActionStatusRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/ActionStatusRepository.java similarity index 98% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ActionStatusRepository.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/ActionStatusRepository.java index 2a0e8cfb3..61d95e15e 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ActionStatusRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/ActionStatusRepository.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.jpa; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/BaseEntityRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/BaseEntityRepository.java similarity index 97% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/BaseEntityRepository.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/BaseEntityRepository.java index 16f80596d..693827803 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/BaseEntityRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/BaseEntityRepository.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.jpa; import java.io.Serializable; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetMetadataRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetMetadataRepository.java similarity index 96% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetMetadataRepository.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetMetadataRepository.java index c042a32d0..68cd380e5 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetMetadataRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetMetadataRepository.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.jpa; import org.eclipse.hawkbit.repository.model.DistributionSetMetadata; import org.eclipse.hawkbit.repository.model.DsMetadataCompositeKey; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetRepository.java similarity index 99% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetRepository.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetRepository.java index f2138bb2d..c7ab44145 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetRepository.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.jpa; import java.util.Collection; import java.util.List; @@ -27,8 +27,6 @@ import org.springframework.transaction.annotation.Transactional; /** * {@link DistributionSet} repository. * - * - * */ @Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) public interface DistributionSetRepository diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetTagRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetTagRepository.java similarity index 97% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetTagRepository.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetTagRepository.java index 8521a96b9..9e55a305b 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetTagRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetTagRepository.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.jpa; import java.util.List; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetTypeRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetTypeRepository.java similarity index 98% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetTypeRepository.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetTypeRepository.java index 289dd6c09..7c0d39b58 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetTypeRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetTypeRepository.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.jpa; import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/EclipseLinkTargetInfoRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/EclipseLinkTargetInfoRepository.java similarity index 98% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/EclipseLinkTargetInfoRepository.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/EclipseLinkTargetInfoRepository.java index e37a51d6c..ca124f81c 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/EclipseLinkTargetInfoRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/EclipseLinkTargetInfoRepository.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.jpa; import java.util.Collection; import java.util.List; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ExternalArtifactProviderRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/ExternalArtifactProviderRepository.java similarity index 94% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ExternalArtifactProviderRepository.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/ExternalArtifactProviderRepository.java index d0802d242..4a29afc4b 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ExternalArtifactProviderRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/ExternalArtifactProviderRepository.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.jpa; import org.eclipse.hawkbit.repository.model.ExternalArtifactProvider; import org.springframework.transaction.annotation.Isolation; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ExternalArtifactRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/ExternalArtifactRepository.java similarity index 96% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ExternalArtifactRepository.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/ExternalArtifactRepository.java index d20da8013..dfc8105dd 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ExternalArtifactRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/ExternalArtifactRepository.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.jpa; import org.eclipse.hawkbit.repository.model.ExternalArtifact; import org.springframework.data.domain.Page; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaArtifactManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaArtifactManagement.java new file mode 100644 index 000000000..c6d30208c --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaArtifactManagement.java @@ -0,0 +1,270 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.jpa; + +import java.io.InputStream; +import java.util.List; + +import org.eclipse.hawkbit.artifact.repository.ArtifactRepository; +import org.eclipse.hawkbit.artifact.repository.ArtifactStoreException; +import org.eclipse.hawkbit.artifact.repository.HashNotMatchException; +import org.eclipse.hawkbit.artifact.repository.model.DbArtifact; +import org.eclipse.hawkbit.artifact.repository.model.DbArtifactHash; +import org.eclipse.hawkbit.repository.ArtifactManagement; +import org.eclipse.hawkbit.repository.exception.ArtifactDeleteFailedException; +import org.eclipse.hawkbit.repository.exception.ArtifactUploadFailedException; +import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; +import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; +import org.eclipse.hawkbit.repository.exception.GridFSDBFileNotFoundException; +import org.eclipse.hawkbit.repository.exception.InvalidMD5HashException; +import org.eclipse.hawkbit.repository.exception.InvalidSHA1HashException; +import org.eclipse.hawkbit.repository.model.Artifact; +import org.eclipse.hawkbit.repository.model.ExternalArtifact; +import org.eclipse.hawkbit.repository.model.ExternalArtifactProvider; +import org.eclipse.hawkbit.repository.model.LocalArtifact; +import org.eclipse.hawkbit.repository.model.SoftwareModule; +import org.eclipse.hawkbit.repository.specifications.SoftwareModuleSpecification; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Isolation; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.validation.annotation.Validated; + +/** + * JPA based {@link ArtifactManagement} implementation. + * + */ +@Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) +@Validated +@Service +public class JpaArtifactManagement implements ArtifactManagement { + + private static final Logger LOG = LoggerFactory.getLogger(JpaArtifactManagement.class); + + @Autowired + private LocalArtifactRepository localArtifactRepository; + + @Autowired + private ExternalArtifactRepository externalArtifactRepository; + + @Autowired + private SoftwareModuleRepository softwareModuleRepository; + + @Autowired + private ExternalArtifactProviderRepository externalArtifactProviderRepository; + + @Autowired + private ArtifactRepository artifactRepository; + + private static LocalArtifact checkForExistingArtifact(final String filename, final boolean overrideExisting, + final SoftwareModule softwareModule) { + if (softwareModule.getLocalArtifactByFilename(filename).isPresent()) { + if (overrideExisting) { + LOG.debug("overriding existing artifact with new filename {}", filename); + return softwareModule.getLocalArtifactByFilename(filename).get(); + } else { + throw new EntityAlreadyExistsException("File with that name already exists in the Software Module"); + } + } + return null; + } + + @Override + @Modifying + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + public ExternalArtifact createExternalArtifact(final ExternalArtifactProvider externalRepository, + final String urlSuffix, final Long moduleId) { + + final SoftwareModule module = getModuleAndThrowExceptionIfThatFails(moduleId); + return externalArtifactRepository.save(new ExternalArtifact(externalRepository, urlSuffix, module)); + } + + @Override + @Modifying + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + public ExternalArtifactProvider createExternalArtifactProvider(final String name, final String description, + final String basePath, final String defaultUrlSuffix) { + return externalArtifactProviderRepository + .save(new ExternalArtifactProvider(name, description, basePath, defaultUrlSuffix)); + } + + @Override + @Modifying + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + public LocalArtifact createLocalArtifact(final InputStream stream, final Long moduleId, final String filename, + final String providedMd5Sum, final String providedSha1Sum, final boolean overrideExisting, + final String contentType) { + DbArtifact result = null; + + final SoftwareModule softwareModule = getModuleAndThrowExceptionIfThatFails(moduleId); + + final LocalArtifact existing = checkForExistingArtifact(filename, overrideExisting, softwareModule); + + try { + result = artifactRepository.store(stream, filename, contentType, + new DbArtifactHash(providedSha1Sum, providedMd5Sum)); + } catch (final ArtifactStoreException e) { + throw new ArtifactUploadFailedException(e); + } catch (final HashNotMatchException e) { + if (e.getHashFunction().equals(HashNotMatchException.SHA1)) { + throw new InvalidSHA1HashException(e.getMessage(), e); + } else { + throw new InvalidMD5HashException(e.getMessage(), e); + } + } + if (result == null) { + return null; + } + + return storeArtifactMetadata(softwareModule, filename, result, existing); + } + + @Override + @Modifying + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + public void deleteExternalArtifact(final Long id) { + final ExternalArtifact existing = externalArtifactRepository.findOne(id); + + if (null == existing) { + return; + } + + existing.getSoftwareModule().removeArtifact(existing); + softwareModuleRepository.save(existing.getSoftwareModule()); + externalArtifactRepository.delete(id); + } + + @Override + @Modifying + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + public void deleteLocalArtifact(final LocalArtifact existing) { + if (existing == null) { + return; + } + + boolean artifactIsOnlyUsedByOneSoftwareModule = true; + for (final LocalArtifact lArtifact : localArtifactRepository + .findByGridFsFileName(existing.getGridFsFileName())) { + if (!lArtifact.getSoftwareModule().isDeleted() + && Long.compare(lArtifact.getSoftwareModule().getId(), existing.getSoftwareModule().getId()) != 0) { + artifactIsOnlyUsedByOneSoftwareModule = false; + break; + } + } + + if (artifactIsOnlyUsedByOneSoftwareModule) { + try { + LOG.debug("deleting artifact from repository {}", existing.getGridFsFileName()); + artifactRepository.deleteBySha1(existing.getGridFsFileName()); + } catch (final ArtifactStoreException e) { + throw new ArtifactDeleteFailedException(e); + } + } + } + + @Override + @Modifying + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + public void deleteLocalArtifact(final Long id) { + final LocalArtifact existing = localArtifactRepository.findOne(id); + + if (null == existing) { + return; + } + + deleteLocalArtifact(existing); + + existing.getSoftwareModule().removeArtifact(existing); + softwareModuleRepository.save(existing.getSoftwareModule()); + localArtifactRepository.delete(id); + } + + @Override + public Artifact findArtifact(final Long id) { + return localArtifactRepository.findOne(id); + } + + @Override + public List findByFilenameAndSoftwareModule(final String filename, final Long softwareModuleId) { + return localArtifactRepository.findByFilenameAndSoftwareModuleId(filename, softwareModuleId); + } + + @Override + public LocalArtifact findFirstLocalArtifactsBySHA1(final String sha1) { + return localArtifactRepository.findFirstByGridFsFileName(sha1); + } + + @Override + public List findLocalArtifactByFilename(final String filename) { + return localArtifactRepository.findByFilename(filename); + } + + @Override + public Page findLocalArtifactBySoftwareModule(final Pageable pageReq, final Long swId) { + return localArtifactRepository.findBySoftwareModuleId(pageReq, swId); + } + + @Override + public SoftwareModule findSoftwareModuleById(final Long id) { + + final Specification spec = SoftwareModuleSpecification.byId(id); + + return softwareModuleRepository.findOne(spec); + } + + @Override + public SoftwareModule findSoftwareModuleWithDetails(final Long id) { + final SoftwareModule result = findSoftwareModuleById(id); + if (result != null) { + result.getArtifacts().size(); + } + + return result; + } + + private SoftwareModule getModuleAndThrowExceptionIfThatFails(final Long moduleId) { + final SoftwareModule softwareModule = findSoftwareModuleWithDetails(moduleId); + + if (softwareModule == null) { + LOG.debug("no software module with ID {} exists", moduleId); + throw new EntityNotFoundException("Software Module: " + moduleId); + } + return softwareModule; + } + + @Override + public DbArtifact loadLocalArtifactBinary(final LocalArtifact artifact) { + final DbArtifact result = artifactRepository.getArtifactBySha1(artifact.getGridFsFileName()); + if (result == null) { + throw new GridFSDBFileNotFoundException(artifact.getGridFsFileName()); + } + + return result; + } + + private LocalArtifact storeArtifactMetadata(final SoftwareModule softwareModule, final String providedFilename, + final DbArtifact result, final LocalArtifact existing) { + LocalArtifact artifact = existing; + if (existing == null) { + artifact = new LocalArtifact(result.getHashes().getSha1(), providedFilename, softwareModule); + } + artifact.setMd5Hash(result.getHashes().getMd5()); + artifact.setSha1Hash(result.getHashes().getSha1()); + artifact.setSize(result.getSize()); + + LOG.debug("storing new artifact into repository {}", artifact); + return localArtifactRepository.save(artifact); + } +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java new file mode 100644 index 000000000..76363cca9 --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java @@ -0,0 +1,417 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.jpa; + +import java.net.URI; +import java.util.List; +import java.util.Map; + +import javax.persistence.EntityManager; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import javax.validation.constraints.NotNull; + +import org.eclipse.hawkbit.repository.ControllerManagement; +import org.eclipse.hawkbit.repository.TenantConfigurationManagement; +import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; +import org.eclipse.hawkbit.repository.exception.ToManyAttributeEntriesException; +import org.eclipse.hawkbit.repository.exception.ToManyStatusEntriesException; +import org.eclipse.hawkbit.repository.model.Action; +import org.eclipse.hawkbit.repository.model.Action.Status; +import org.eclipse.hawkbit.repository.model.ActionStatus; +import org.eclipse.hawkbit.repository.model.ActionStatus_; +import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.LocalArtifact; +import org.eclipse.hawkbit.repository.model.SoftwareModule; +import org.eclipse.hawkbit.repository.model.Target; +import org.eclipse.hawkbit.repository.model.TargetInfo; +import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; +import org.eclipse.hawkbit.repository.model.Target_; +import org.eclipse.hawkbit.repository.model.TenantConfiguration; +import org.eclipse.hawkbit.repository.specifications.ActionSpecifications; +import org.eclipse.hawkbit.security.HawkbitSecurityProperties; +import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Isolation; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.validation.annotation.Validated; + +/** + * JPA based {@link ControllerManagement} implementation. + * + */ +@Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) +@Validated +@Service +public class JpaControllerManagement implements ControllerManagement { + private static final Logger LOG = LoggerFactory.getLogger(ControllerManagement.class); + private static final Logger LOG_DOS = LoggerFactory.getLogger("server-security.dos"); + + @Autowired + private EntityManager entityManager; + + @Autowired + private ActionRepository actionRepository; + + @Autowired + private TargetRepository targetRepository; + + @Autowired + private TargetManagement targetManagement; + + @Autowired + private TargetInfoRepository targetInfoRepository; + + @Autowired + private SoftwareModuleRepository softwareModuleRepository; + + @Autowired + private ActionStatusRepository actionStatusRepository; + + @Autowired + private HawkbitSecurityProperties securityProperties; + + @Autowired + private TenantConfigurationRepository tenantConfigurationRepository; + + @Autowired + private TenantConfigurationManagement tenantConfigurationManagement; + + @Override + public String getPollingTime() { + final TenantConfigurationKey configurationKey = TenantConfigurationKey.POLLING_TIME_INTERVAL; + final Class propertyType = String.class; + JpaTenantConfigurationManagement.validateTenantConfigurationDataType(configurationKey, propertyType); + final TenantConfiguration tenantConfiguration = tenantConfigurationRepository + .findByKey(configurationKey.getKeyName()); + return tenantConfigurationManagement + .buildTenantConfigurationValueByKey(configurationKey, propertyType, tenantConfiguration).getValue(); + } + + @Override + @Modifying + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + public Target updateLastTargetQuery(final String controllerId, final URI address) { + final Target target = targetRepository.findByControllerId(controllerId); + if (target == null) { + throw new EntityNotFoundException(controllerId); + } + + return updateLastTargetQuery(target.getTargetInfo(), address).getTarget(); + } + + @Override + public Action getActionForDownloadByTargetAndSoftwareModule(final String controllerId, + final SoftwareModule module) { + final List action = actionRepository.findActionByTargetAndSoftwareModule(controllerId, module); + + if (action.isEmpty() || action.get(0).isCancelingOrCanceled()) { + throw new EntityNotFoundException( + "No assigment found for module " + module.getId() + " to target " + controllerId); + } + + return action.get(0); + } + + @Override + public boolean hasTargetArtifactAssigned(final String controllerId, final LocalArtifact localArtifact) { + final Target target = targetRepository.findByControllerId(controllerId); + if (target == null) { + return false; + } + return actionRepository.count(ActionSpecifications.hasTargetAssignedArtifact(target, localArtifact)) > 0; + } + + @Override + public List findActionByTargetAndActive(final Target target) { + return actionRepository.findByTargetAndActiveOrderByIdAsc(target, true); + } + + @Override + public List findSoftwareModulesByDistributionSet(final DistributionSet distributionSet) { + return softwareModuleRepository.findByAssignedTo(distributionSet); + } + + @Override + public Action findActionWithDetails(final Long actionId) { + return actionRepository.findById(actionId); + } + + @Override + @Modifying + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + public Target findOrRegisterTargetIfItDoesNotexist(final String controllerId, final URI address) { + final Specification spec = (targetRoot, query, cb) -> cb.equal(targetRoot.get(Target_.controllerId), + controllerId); + + Target target = targetRepository.findOne(spec); + + if (target == null) { + target = new Target(controllerId); + target.setDescription("Plug and Play target: " + controllerId); + target.setName(controllerId); + return targetManagement.createTarget(target, TargetUpdateStatus.REGISTERED, System.currentTimeMillis(), + address); + } + + return updateLastTargetQuery(target.getTargetInfo(), address).getTarget(); + } + + @Override + @Modifying + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + public TargetInfo updateTargetStatus(final TargetInfo targetInfo, final TargetUpdateStatus status, + final Long lastTargetQuery, final URI address) { + final TargetInfo mtargetInfo = entityManager.merge(targetInfo); + if (status != null) { + mtargetInfo.setUpdateStatus(status); + } + if (lastTargetQuery != null) { + mtargetInfo.setLastTargetQuery(lastTargetQuery); + } + if (address != null) { + mtargetInfo.setAddress(address.toString()); + } + return targetInfoRepository.save(mtargetInfo); + } + + @Override + @Modifying + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + public Action addCancelActionStatus(final ActionStatus actionStatus) { + final Action action = actionStatus.getAction(); + + checkForToManyStatusEntries(action); + action.setStatus(actionStatus.getStatus()); + + switch (actionStatus.getStatus()) { + case WARNING: + case ERROR: + case RUNNING: + break; + case CANCELED: + case FINISHED: + // in case of successful cancellation we also report the success at + // the canceled action itself. + actionStatus.addMessage( + ControllerManagement.SERVER_MESSAGE_PREFIX + "Cancellation completion is finished sucessfully."); + DeploymentHelper.successCancellation(action, actionRepository, targetManagement, targetInfoRepository, + entityManager); + break; + case RETRIEVED: + actionStatus.addMessage(ControllerManagement.SERVER_MESSAGE_PREFIX + "Cancellation request retrieved."); + break; + default: + } + actionRepository.save(action); + actionStatusRepository.save(actionStatus); + + return action; + } + + @Override + @Modifying + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + public Action addUpdateActionStatus(@NotNull final ActionStatus actionStatus) { + final Action action = actionStatus.getAction(); + + if (!action.isActive()) { + LOG.debug("Update of actionStatus {} for action {} not possible since action not active anymore.", + actionStatus.getId(), action.getId()); + return action; + } + return handleAddUpdateActionStatus(actionStatus, action); + } + + /** + * Sets {@link TargetUpdateStatus} based on given {@link ActionStatus}. + * + * @param actionStatus + * @param action + * @return + */ + private Action handleAddUpdateActionStatus(final ActionStatus actionStatus, final Action action) { + LOG.debug("addUpdateActionStatus for action {}", action.getId()); + + final Action mergedAction = entityManager.merge(action); + Target mergedTarget = mergedAction.getTarget(); + // check for a potential DOS attack + checkForToManyStatusEntries(action); + + switch (actionStatus.getStatus()) { + case ERROR: + mergedTarget = DeploymentHelper.updateTargetInfo(mergedTarget, TargetUpdateStatus.ERROR, false, + targetInfoRepository, entityManager); + handleErrorOnAction(mergedAction, mergedTarget); + break; + case FINISHED: + handleFinishedAndStoreInTargetStatus(mergedTarget, mergedAction); + break; + case CANCELED: + case WARNING: + case RUNNING: + DeploymentHelper.updateTargetInfo(mergedTarget, TargetUpdateStatus.PENDING, false, targetInfoRepository, + entityManager); + break; + default: + break; + } + + actionStatusRepository.save(actionStatus); + + LOG.debug("addUpdateActionStatus {} for target {} is finished.", action.getId(), mergedTarget.getId()); + + return actionRepository.save(mergedAction); + } + + private void handleErrorOnAction(final Action mergedAction, final Target mergedTarget) { + mergedAction.setActive(false); + mergedAction.setStatus(Status.ERROR); + mergedTarget.setAssignedDistributionSet(null); + targetManagement.updateTarget(mergedTarget); + } + + private void checkForToManyStatusEntries(final Action action) { + if (securityProperties.getDos().getMaxStatusEntriesPerAction() > 0) { + + final Long statusCount = actionStatusRepository.countByAction(action); + + if (statusCount >= securityProperties.getDos().getMaxStatusEntriesPerAction()) { + LOG_DOS.error( + "Potential denial of service (DOS) attack identfied. More status entries in the system than permitted ({})!", + securityProperties.getDos().getMaxStatusEntriesPerAction()); + throw new ToManyStatusEntriesException( + String.valueOf(securityProperties.getDos().getMaxStatusEntriesPerAction())); + } + } + } + + private void handleFinishedAndStoreInTargetStatus(final Target target, final Action action) { + action.setActive(false); + action.setStatus(Status.FINISHED); + final TargetInfo targetInfo = target.getTargetInfo(); + final DistributionSet ds = entityManager.merge(action.getDistributionSet()); + targetInfo.setInstalledDistributionSet(ds); + if (target.getAssignedDistributionSet() != null && targetInfo.getInstalledDistributionSet() != null && target + .getAssignedDistributionSet().getId().equals(targetInfo.getInstalledDistributionSet().getId())) { + targetInfo.setUpdateStatus(TargetUpdateStatus.IN_SYNC); + targetInfo.setInstallationDate(System.currentTimeMillis()); + } else { + targetInfo.setUpdateStatus(TargetUpdateStatus.PENDING); + targetInfo.setInstallationDate(System.currentTimeMillis()); + } + targetInfoRepository.save(targetInfo); + entityManager.detach(ds); + } + + @Override + @Modifying + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + public Target updateControllerAttributes(final String controllerId, final Map data) { + final Target target = targetRepository.findByControllerId(controllerId); + + if (target == null) { + throw new EntityNotFoundException(controllerId); + } + + target.getTargetInfo().getControllerAttributes().putAll(data); + + if (target.getTargetInfo().getControllerAttributes().size() > securityProperties.getDos() + .getMaxAttributeEntriesPerTarget()) { + LOG_DOS.info("Target tries to insert more than the allowed number of entries ({}). DOS attack anticipated!", + securityProperties.getDos().getMaxAttributeEntriesPerTarget()); + throw new ToManyAttributeEntriesException( + String.valueOf(securityProperties.getDos().getMaxAttributeEntriesPerTarget())); + } + + target.getTargetInfo().setLastTargetQuery(System.currentTimeMillis()); + target.getTargetInfo().setRequestControllerAttributes(false); + return targetRepository.save(target); + } + + @Override + @Modifying + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + public Action registerRetrieved(final Action action, final String message) { + return handleRegisterRetrieved(action, message); + } + + /** + * Registers retrieved status for given {@link Target} and {@link Action} if + * it does not exist yet. + * + * @param action + * to the handle status for + * @param message + * for the status + * @return the updated action in case the status has been changed to + * {@link Status#RETRIEVED} + */ + private Action handleRegisterRetrieved(final Action action, final String message) { + // do a manual query with CriteriaBuilder to avoid unnecessary field + // queries and an extra + // count query made by spring-data when using pageable requests, we + // don't need an extra count + // query, we just want to check if the last action status is a retrieved + // or not. + final CriteriaBuilder cb = entityManager.getCriteriaBuilder(); + final CriteriaQuery queryActionStatus = cb.createQuery(Object[].class); + final Root actionStatusRoot = queryActionStatus.from(ActionStatus.class); + final CriteriaQuery query = queryActionStatus + .multiselect(actionStatusRoot.get(ActionStatus_.id), actionStatusRoot.get(ActionStatus_.status)) + .where(cb.equal(actionStatusRoot.get(ActionStatus_.action), action)) + .orderBy(cb.desc(actionStatusRoot.get(ActionStatus_.id))); + final List resultList = entityManager.createQuery(query).setFirstResult(0).setMaxResults(1) + .getResultList(); + + // if the latest status is not in retrieve state then we add a retrieved + // state again, we want + // to document a deployment retrieved status and a cancel retrieved + // status, but multiple + // retrieves after the other we don't want to store to protect to + // overflood action status in + // case controller retrieves a action multiple times. + if (resultList.isEmpty() || resultList.get(0)[1] != Status.RETRIEVED) { + // document that the status has been retrieved + actionStatusRepository + .save(new ActionStatus(action, Status.RETRIEVED, System.currentTimeMillis(), message)); + + // don't change the action status itself in case the action is in + // canceling state otherwise + // we modify the action status and the controller won't get the + // cancel job anymore. + if (!action.isCancelingOrCanceled()) { + final Action actionMerge = entityManager.merge(action); + actionMerge.setStatus(Status.RETRIEVED); + return actionRepository.save(actionMerge); + } + } + return action; + } + + @Override + @Modifying + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + public void addInformationalActionStatus(final ActionStatus statusMessage) { + actionStatusRepository.save(statusMessage); + } + + @Override + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + public String getSecurityTokenByControllerId(final String controllerId) { + final Target target = targetRepository.findByControllerId(controllerId); + return target != null ? target.getSecurityToken() : null; + } +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java new file mode 100644 index 000000000..50bbd2d31 --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java @@ -0,0 +1,652 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.jpa; + +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.function.Function; +import java.util.stream.Collectors; + +import javax.persistence.EntityManager; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Join; +import javax.persistence.criteria.JoinType; +import javax.persistence.criteria.ListJoin; +import javax.persistence.criteria.Root; +import javax.validation.constraints.NotNull; + +import org.eclipse.hawkbit.Constants; +import org.eclipse.hawkbit.eventbus.event.CancelTargetAssignmentEvent; +import org.eclipse.hawkbit.eventbus.event.TargetAssignDistributionSetEvent; +import org.eclipse.hawkbit.eventbus.event.TargetInfoUpdateEvent; +import org.eclipse.hawkbit.executor.AfterTransactionCommitExecutor; +import org.eclipse.hawkbit.repository.DeploymentManagement; +import org.eclipse.hawkbit.repository.DistributionSetAssignmentResult; +import org.eclipse.hawkbit.repository.exception.CancelActionNotAllowedException; +import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; +import org.eclipse.hawkbit.repository.exception.ForceQuitActionNotAllowedException; +import org.eclipse.hawkbit.repository.exception.IncompleteDistributionSetException; +import org.eclipse.hawkbit.repository.model.Action; +import org.eclipse.hawkbit.repository.model.Action.ActionType; +import org.eclipse.hawkbit.repository.model.Action.Status; +import org.eclipse.hawkbit.repository.model.ActionStatus; +import org.eclipse.hawkbit.repository.model.ActionWithStatusCount; +import org.eclipse.hawkbit.repository.model.Action_; +import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.DistributionSetType; +import org.eclipse.hawkbit.repository.model.DistributionSet_; +import org.eclipse.hawkbit.repository.model.Rollout; +import org.eclipse.hawkbit.repository.model.RolloutGroup; +import org.eclipse.hawkbit.repository.model.Rollout_; +import org.eclipse.hawkbit.repository.model.SoftwareModule; +import org.eclipse.hawkbit.repository.model.SoftwareModuleType; +import org.eclipse.hawkbit.repository.model.Target; +import org.eclipse.hawkbit.repository.model.TargetInfo; +import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; +import org.eclipse.hawkbit.repository.specifications.TargetSpecifications; +import org.hibernate.validator.constraints.NotEmpty; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.data.domain.AuditorAware; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Isolation; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.validation.annotation.Validated; + +import com.google.common.collect.Lists; +import com.google.common.eventbus.EventBus; + +/** + * JPA implementation for DeploymentManagement. + * + */ +@Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) +@Validated +@Service +public class JpaDeploymentManagement implements DeploymentManagement { + private static final Logger LOG = LoggerFactory.getLogger(JpaDeploymentManagement.class); + + @Autowired + private EntityManager entityManager; + + @Autowired + private ActionRepository actionRepository; + + @Autowired + private DistributionSetRepository distributoinSetRepository; + + @Autowired + private SoftwareModuleRepository softwareModuleRepository; + + @Autowired + private TargetRepository targetRepository; + + @Autowired + private ActionStatusRepository actionStatusRepository; + + @Autowired + private TargetManagement targetManagement; + + @Autowired + private TargetInfoRepository targetInfoRepository; + + @Autowired + private AuditorAware auditorProvider; + + @Autowired + private EventBus eventBus; + + @Autowired + private AfterTransactionCommitExecutor afterCommit; + + @Override + @Transactional(isolation = Isolation.READ_COMMITTED) + @Modifying + @CacheEvict(value = { "distributionUsageAssigned" }, allEntries = true) + public DistributionSetAssignmentResult assignDistributionSet(final DistributionSet pset, + final List targets) { + + return assignDistributionSetByTargetId(pset, + targets.stream().map(target -> target.getControllerId()).collect(Collectors.toList()), + ActionType.FORCED, Action.NO_FORCE_TIME); + + } + + @Override + @Modifying + @Transactional(isolation = Isolation.READ_COMMITTED) + + @CacheEvict(value = { "distributionUsageAssigned" }, allEntries = true) + public DistributionSetAssignmentResult assignDistributionSet(final Long dsID, final String... targetIDs) { + return assignDistributionSet(dsID, ActionType.FORCED, Action.NO_FORCE_TIME, targetIDs); + } + + @Override + @Modifying + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + @CacheEvict(value = { "distributionUsageAssigned" }, allEntries = true) + // Exception squid:S2095: see + // https://jira.sonarsource.com/browse/SONARJAVA-1478 + @SuppressWarnings({ "squid:S2095" }) + public DistributionSetAssignmentResult assignDistributionSet(final Long dsID, final ActionType actionType, + final long forcedTimestamp, final String... targetIDs) { + return assignDistributionSet(dsID, Arrays.stream(targetIDs) + .map(t -> new TargetWithActionType(t, actionType, forcedTimestamp)).collect(Collectors.toList())); + } + + @Override + @Modifying + @Transactional(isolation = Isolation.READ_COMMITTED) + @CacheEvict(value = { "distributionUsageAssigned" }, allEntries = true) + public DistributionSetAssignmentResult assignDistributionSet(final Long dsID, + final List targets) { + final DistributionSet set = distributoinSetRepository.findOne(dsID); + if (set == null) { + throw new EntityNotFoundException( + String.format("no %s with id %d found", DistributionSet.class.getSimpleName(), dsID)); + } + + return assignDistributionSetToTargets(set, targets, null, null); + } + + @Override + @Modifying + @Transactional(isolation = Isolation.READ_COMMITTED) + @CacheEvict(value = { "distributionUsageAssigned" }, allEntries = true) + public DistributionSetAssignmentResult assignDistributionSet(final Long dsID, + final List targets, final Rollout rollout, final RolloutGroup rolloutGroup) { + final DistributionSet set = distributoinSetRepository.findOne(dsID); + if (set == null) { + throw new EntityNotFoundException( + String.format("no %s with id %d found", DistributionSet.class.getSimpleName(), dsID)); + } + + return assignDistributionSetToTargets(set, targets, rollout, rolloutGroup); + } + + /** + * method assigns the {@link DistributionSet} to all {@link Target}s by + * their IDs with a specific {@link ActionType} and {@code forcetime}. + * + * @param dsID + * the ID of the distribution set to assign + * @param targets + * a list of all targets and their action type + * @param rollout + * the rollout for this assignment + * @param rolloutGroup + * the rollout group for this assignment + * @return the assignment result + * + * @throw IncompleteDistributionSetException if mandatory + * {@link SoftwareModuleType} are not assigned as define by the + * {@link DistributionSetType}. + */ + private DistributionSetAssignmentResult assignDistributionSetToTargets(@NotNull final DistributionSet set, + final List targetsWithActionType, final Rollout rollout, + final RolloutGroup rolloutGroup) { + + if (!set.isComplete()) { + throw new IncompleteDistributionSetException( + "Distribution set of type " + set.getType().getKey() + " is incomplete: " + set.getId()); + } + + final List controllerIDs = targetsWithActionType.stream().map(TargetWithActionType::getTargetId) + .collect(Collectors.toList()); + + LOG.debug("assignDistribution({}) to {} targets", set, controllerIDs.size()); + + final Map targetsWithActionMap = targetsWithActionType.stream() + .collect(Collectors.toMap(TargetWithActionType::getTargetId, Function.identity())); + + // split tIDs length into max entries in-statement because many database + // have constraint of max entries in in-statements e.g. Oracle with + // maximum 1000 elements, so we need to split the entries here and + // execute multiple statements we take the target only into account if + // the requested operation is no duplicate of a previous one + final List targets = Lists.partition(controllerIDs, Constants.MAX_ENTRIES_IN_STATEMENT).stream() + .map(ids -> targetRepository + .findAll(TargetSpecifications.hasControllerIdAndAssignedDistributionSetIdNot(ids, set.getId()))) + .flatMap(t -> t.stream()).collect(Collectors.toList()); + + if (targets.isEmpty()) { + // detaching as it is not necessary to persist the set itself + entityManager.detach(set); + // return with nothing as all targets had the DS already assigned + return new DistributionSetAssignmentResult(Collections.emptyList(), 0, targetsWithActionType.size(), + Collections.emptyList(), targetManagement); + } + + final List> targetIds = Lists.partition( + targets.stream().map(Target::getId).collect(Collectors.toList()), Constants.MAX_ENTRIES_IN_STATEMENT); + + // override all active actions and set them into canceling state, we + // need to remember which one we have been switched to canceling state + // because for targets which we have changed to canceling we don't want + // to publish the new action update event. + final Set targetIdsCancellList = new HashSet<>(); + targetIds.forEach(ids -> targetIdsCancellList.addAll(overrideObsoleteUpdateActions(ids))); + + // cancel all scheduled actions which are in-active, these actions were + // not active before and the manual assignment which has been done + // cancels the + targetIds.forEach(tIds -> actionRepository.switchStatus(Status.CANCELED, tIds, false, Status.SCHEDULED)); + + // set assigned distribution set and TargetUpdateStatus + final String currentUser; + if (auditorProvider != null) { + currentUser = auditorProvider.getCurrentAuditor(); + } else { + currentUser = null; + } + + targetIds.forEach(tIds -> targetRepository.setAssignedDistributionSet(set, System.currentTimeMillis(), + currentUser, tIds)); + targetIds.forEach(tIds -> targetInfoRepository.setTargetUpdateStatus(TargetUpdateStatus.PENDING, tIds)); + final Map targetIdsToActions = actionRepository + .save(targets.stream().map(t -> createTargetAction(targetsWithActionMap, t, set, rollout, rolloutGroup)) + .collect(Collectors.toList())) + .stream().collect(Collectors.toMap(a -> a.getTarget().getControllerId(), Function.identity())); + + // create initial action status when action is created so we remember + // the initial running status because we will change the status + // of the action itself and with this action status we have a nicer + // action history. + targetIdsToActions.values().forEach(action -> { + final ActionStatus actionStatus = new ActionStatus(); + actionStatus.setAction(action); + actionStatus.setOccurredAt(action.getCreatedAt()); + actionStatus.setStatus(Status.RUNNING); + actionStatusRepository.save(actionStatus); + }); + + // flush to get action IDs + entityManager.flush(); + // collect updated target and actions IDs in order to return them + final DistributionSetAssignmentResult result = new DistributionSetAssignmentResult( + targets.stream().map(target -> target.getControllerId()).collect(Collectors.toList()), targets.size(), + controllerIDs.size() - targets.size(), + targetIdsToActions.values().stream().map(Action::getId).collect(Collectors.toList()), targetManagement); + + LOG.debug("assignDistribution({}) finished {}", set, result); + + final List softwareModules = softwareModuleRepository.findByAssignedTo(set); + + // detaching as it is not necessary to persist the set itself + entityManager.detach(set); + + sendDistributionSetAssignmentEvent(targets, targetIdsCancellList, targetIdsToActions, softwareModules); + + return result; + } + + private void sendDistributionSetAssignmentEvent(final List targets, final Set targetIdsCancellList, + final Map targetIdsToActions, final List softwareModules) { + targets.stream().filter(t -> !!!targetIdsCancellList.contains(t.getId())) + .forEach(t -> assignDistributionSetEvent(t, targetIdsToActions.get(t.getControllerId()).getId(), + softwareModules)); + } + + private static Action createTargetAction(final Map targetsWithActionMap, + final Target target, final DistributionSet set, final Rollout rollout, final RolloutGroup rolloutGroup) { + final Action actionForTarget = new Action(); + final TargetWithActionType targetWithActionType = targetsWithActionMap.get(target.getControllerId()); + actionForTarget.setActionType(targetWithActionType.getActionType()); + actionForTarget.setForcedTime(targetWithActionType.getForceTime()); + actionForTarget.setActive(true); + actionForTarget.setStatus(Status.RUNNING); + actionForTarget.setTarget(target); + actionForTarget.setDistributionSet(set); + actionForTarget.setRollout(rollout); + actionForTarget.setRolloutGroup(rolloutGroup); + return actionForTarget; + } + + /** + * Sends the {@link TargetAssignDistributionSetEvent} for a specific target + * to the {@link EventBus}. + * + * @param target + * the Target which has been assigned to a distribution set + * @param actionId + * the action id of the assignment + * @param softwareModules + * the software modules which have been assigned + */ + private void assignDistributionSetEvent(final Target target, final Long actionId, + final List softwareModules) { + target.getTargetInfo().setUpdateStatus(TargetUpdateStatus.PENDING); + afterCommit.afterCommit(() -> { + eventBus.post(new TargetInfoUpdateEvent(target.getTargetInfo())); + eventBus.post(new TargetAssignDistributionSetEvent(target.getOptLockRevision(), target.getTenant(), + target.getControllerId(), actionId, softwareModules, target.getTargetInfo().getAddress(), + target.getSecurityToken())); + }); + } + + /** + * Removes {@link UpdateAction}s that are no longer necessary and sends + * cancellations to the controller. + * + * @param myTarget + * to override {@link UpdateAction}s + */ + private Set overrideObsoleteUpdateActions(final List targetsIds) { + + final Set cancelledTargetIds = new HashSet<>(); + + // Figure out if there are potential target/action combinations that + // need to be considered + // for cancelation + final List activeActions = actionRepository + .findByActiveAndTargetIdInAndActionStatusNotEqualToAndDistributionSetRequiredMigrationStep(targetsIds, + Action.Status.CANCELING); + activeActions.forEach(action -> { + action.setStatus(Status.CANCELING); + // document that the status has been retrieved + + actionStatusRepository.save(new ActionStatus(action, Status.CANCELING, System.currentTimeMillis(), + "manual cancelation requested")); + + cancelAssignDistributionSetEvent(action.getTarget(), action.getId()); + + cancelledTargetIds.add(action.getTarget().getId()); + }); + + actionRepository.save(activeActions); + + return cancelledTargetIds; + + } + + private DistributionSetAssignmentResult assignDistributionSetByTargetId(@NotNull final DistributionSet set, + @NotEmpty final List tIDs, final ActionType actionType, final long forcedTime) { + + return assignDistributionSetToTargets(set, tIDs.stream() + .map(t -> new TargetWithActionType(t, actionType, forcedTime)).collect(Collectors.toList()), null, + null); + } + + @Override + @Modifying + @Transactional(isolation = Isolation.READ_COMMITTED) + public Action cancelAction(final Action action, final Target target) { + LOG.debug("cancelAction({}, {})", action, target); + if (action.isCancelingOrCanceled()) { + throw new CancelActionNotAllowedException("Actions in canceling or canceled state cannot be canceled"); + } + final Action myAction = entityManager.merge(action); + + if (myAction.isActive()) { + LOG.debug("action ({}) was still active. Change to {}.", action, Status.CANCELING); + myAction.setStatus(Status.CANCELING); + + // document that the status has been retrieved + actionStatusRepository.save(new ActionStatus(myAction, Status.CANCELING, System.currentTimeMillis(), + "manual cancelation requested")); + final Action saveAction = actionRepository.save(myAction); + cancelAssignDistributionSetEvent(target, myAction.getId()); + + return saveAction; + } else { + throw new CancelActionNotAllowedException( + "Action [id: " + action.getId() + "] is not active and cannot be canceled"); + } + } + + /** + * Sends the {@link CancelTargetAssignmentEvent} for a specific target to + * the {@link EventBus}. + * + * @param target + * the Target which has been assigned to a distribution set + * @param actionId + * the action id of the assignment + */ + private void cancelAssignDistributionSetEvent(final Target target, final Long actionId) { + afterCommit.afterCommit(() -> eventBus.post(new CancelTargetAssignmentEvent(target.getOptLockRevision(), + target.getTenant(), target.getControllerId(), actionId, target.getTargetInfo().getAddress()))); + } + + @Override + @Modifying + @Transactional(isolation = Isolation.READ_COMMITTED) + public Action forceQuitAction(final Action action) { + final Action mergedAction = entityManager.merge(action); + + if (!mergedAction.isCancelingOrCanceled()) { + throw new ForceQuitActionNotAllowedException( + "Action [id: " + action.getId() + "] is not canceled yet and cannot be force quit"); + } + + if (!mergedAction.isActive()) { + throw new ForceQuitActionNotAllowedException( + "Action [id: " + action.getId() + "] is not active and cannot be force quit"); + } + + LOG.warn("action ({}) was still activ and has been force quite.", action); + + // document that the status has been retrieved + actionStatusRepository.save(new ActionStatus(mergedAction, Status.CANCELED, System.currentTimeMillis(), + "A force quit has been performed.")); + + DeploymentHelper.successCancellation(mergedAction, actionRepository, targetManagement, targetInfoRepository, + entityManager); + + return actionRepository.save(mergedAction); + } + + @Override + @Modifying + @Transactional(isolation = Isolation.READ_COMMITTED) + public void createScheduledAction(final List targets, final DistributionSet distributionSet, + final ActionType actionType, final long forcedTime, final Rollout rollout, + final RolloutGroup rolloutGroup) { + // cancel all current scheduled actions for this target. E.g. an action + // is already scheduled and a next action is created then cancel the + // current scheduled action to cancel. E.g. a new scheduled action is + // created. + final List targetIds = targets.stream().map(t -> t.getId()).collect(Collectors.toList()); + actionRepository.switchStatus(Action.Status.CANCELED, targetIds, false, Action.Status.SCHEDULED); + targets.forEach(target -> { + final Action action = new Action(); + action.setTarget(target); + action.setActive(false); + action.setDistributionSet(distributionSet); + action.setActionType(actionType); + action.setForcedTime(forcedTime); + action.setStatus(Status.SCHEDULED); + action.setRollout(rollout); + action.setRolloutGroup(rolloutGroup); + actionRepository.save(action); + }); + } + + @Override + @Modifying + @Transactional(isolation = Isolation.READ_COMMITTED) + public Action startScheduledAction(final Action action) { + + final Action mergedAction = entityManager.merge(action); + final Target mergedTarget = entityManager.merge(action.getTarget()); + + // check if we need to override running update actions + final Set overrideObsoleteUpdateActions = overrideObsoleteUpdateActions( + Collections.singletonList(action.getTarget().getId())); + + final boolean hasDistributionSetAlreadyAssigned = targetRepository + .count(TargetSpecifications.hasControllerIdAndAssignedDistributionSetIdNot( + Collections.singletonList(mergedTarget.getControllerId()), + action.getDistributionSet().getId())) == 0; + if (hasDistributionSetAlreadyAssigned) { + // the target has already the distribution set assigned, we don't + // need to start the scheduled action, just finished it. + mergedAction.setStatus(Status.FINISHED); + mergedAction.setActive(false); + return actionRepository.save(mergedAction); + } + + mergedAction.setActive(true); + mergedAction.setStatus(Status.RUNNING); + final Action savedAction = actionRepository.save(mergedAction); + + final ActionStatus actionStatus = new ActionStatus(); + actionStatus.setAction(action); + actionStatus.setOccurredAt(action.getCreatedAt()); + actionStatus.setStatus(Status.RUNNING); + actionStatusRepository.save(actionStatus); + + mergedTarget.setAssignedDistributionSet(action.getDistributionSet()); + final TargetInfo targetInfo = mergedTarget.getTargetInfo(); + targetInfo.setUpdateStatus(TargetUpdateStatus.PENDING); + targetRepository.save(mergedTarget); + targetInfoRepository.save(targetInfo); + + // in case we canceled an action before for this target, then don't fire + // assignment event + if (!overrideObsoleteUpdateActions.contains(savedAction.getId())) { + final List softwareModules = softwareModuleRepository + .findByAssignedTo(action.getDistributionSet()); + // send distribution set assignment event + + assignDistributionSetEvent(mergedAction.getTarget(), mergedAction.getId(), softwareModules); + } + return savedAction; + } + + @Override + public Action findAction(final Long actionId) { + return actionRepository.findOne(actionId); + } + + @Override + public Action findActionWithDetails(final Long actionId) { + return actionRepository.findById(actionId); + } + + @Override + public Slice findActionsByTarget(final Pageable pageable, final Target target) { + return actionRepository.findByTarget(pageable, target); + } + + @Override + public List findActionsByTarget(final Target target) { + return actionRepository.findByTarget(target); + } + + @Override + public List findActionsWithStatusCountByTargetOrderByIdDesc(final Target target) { + final CriteriaBuilder cb = entityManager.getCriteriaBuilder(); + final CriteriaQuery query = cb.createQuery(ActionWithStatusCount.class); + final Root actionRoot = query.from(Action.class); + final ListJoin actionStatusJoin = actionRoot.join(Action_.actionStatus, JoinType.LEFT); + final Join actionDsJoin = actionRoot.join(Action_.distributionSet); + final Join actionRolloutJoin = actionRoot.join(Action_.rollout, JoinType.LEFT); + + final CriteriaQuery multiselect = query.distinct(true).multiselect( + actionRoot.get(Action_.id), actionRoot.get(Action_.actionType), actionRoot.get(Action_.active), + actionRoot.get(Action_.forcedTime), actionRoot.get(Action_.status), actionRoot.get(Action_.createdAt), + actionRoot.get(Action_.lastModifiedAt), actionDsJoin.get(DistributionSet_.id), + actionDsJoin.get(DistributionSet_.name), actionDsJoin.get(DistributionSet_.version), + cb.count(actionStatusJoin), actionRolloutJoin.get(Rollout_.name)); + multiselect.where(cb.equal(actionRoot.get(Action_.target), target)); + multiselect.orderBy(cb.desc(actionRoot.get(Action_.id))); + multiselect.groupBy(actionRoot.get(Action_.id)); + return entityManager.createQuery(multiselect).getResultList(); + } + + @Override + public Slice findActionsByTarget(final Specification specifiction, final Target target, + final Pageable pageable) { + + return actionRepository.findAll((Specification) (root, query, cb) -> cb + .and(specifiction.toPredicate(root, query, cb), cb.equal(root.get(Action_.target), target)), pageable); + } + + @Override + public Slice findActionsByTarget(final Target foundTarget, final Pageable pageable) { + return actionRepository.findByTarget(pageable, foundTarget); + } + + @Override + public Page findActiveActionsByTarget(final Pageable pageable, final Target target) { + return actionRepository.findByActiveAndTarget(pageable, target, true); + } + + @Override + public List findActiveActionsByTarget(final Target target) { + return actionRepository.findByActiveAndTarget(target, true); + } + + @Override + public List findInActiveActionsByTarget(final Target target) { + return actionRepository.findByActiveAndTarget(target, false); + } + + @Override + public Page findInActiveActionsByTarget(final Pageable pageable, final Target target) { + return actionRepository.findByActiveAndTarget(pageable, target, false); + } + + @Override + public Long countActionsByTarget(final Target target) { + return actionRepository.countByTarget(target); + } + + @Override + public Long countActionsByTarget(final Specification spec, final Target target) { + return actionRepository.count((root, query, cb) -> cb.and(spec.toPredicate(root, query, cb), + cb.equal(root.get(Action_.target), target))); + } + + @Override + @Modifying + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + public Action forceTargetAction(final Long actionId) { + final Action action = actionRepository.findOne(actionId); + if (action != null && !action.isForced()) { + action.setActionType(ActionType.FORCED); + return actionRepository.save(action); + } + return action; + } + + @Override + public Page findActionStatusByAction(final Pageable pageReq, final Action action, + final boolean withMessages) { + if (withMessages) { + return actionStatusRepository.getByAction(pageReq, action); + } else { + return actionStatusRepository.findByAction(pageReq, action); + } + } + + @Override + public List findActionsByRolloutGroupParentAndStatus(final Rollout rollout, + final RolloutGroup rolloutGroupParent, final Action.Status actionStatus) { + return actionRepository.findByRolloutAndRolloutGroupParentAndStatus(rollout, rolloutGroupParent, actionStatus); + } + + @Override + public List findActionsByRolloutAndStatus(final Rollout rollout, final Action.Status actionStatus) { + return actionRepository.findByRolloutAndStatus(rollout, actionStatus); + } +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java new file mode 100644 index 000000000..160cf613c --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java @@ -0,0 +1,663 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.jpa; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; + +import javax.persistence.EntityManager; + +import org.eclipse.hawkbit.eventbus.event.DistributionSetTagAssigmentResultEvent; +import org.eclipse.hawkbit.executor.AfterTransactionCommitExecutor; +import org.eclipse.hawkbit.repository.DistributionSetFilter; +import org.eclipse.hawkbit.repository.DistributionSetManagement; +import org.eclipse.hawkbit.repository.DistributionSetFilter.DistributionSetFilterBuilder; +import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; +import org.eclipse.hawkbit.repository.exception.EntityLockedException; +import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; +import org.eclipse.hawkbit.repository.exception.EntityReadOnlyException; +import org.eclipse.hawkbit.repository.model.Action; +import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.DistributionSetMetadata; +import org.eclipse.hawkbit.repository.model.DistributionSetMetadata_; +import org.eclipse.hawkbit.repository.model.DistributionSetTag; +import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult; +import org.eclipse.hawkbit.repository.model.DistributionSetType; +import org.eclipse.hawkbit.repository.model.DistributionSet_; +import org.eclipse.hawkbit.repository.model.DsMetadataCompositeKey; +import org.eclipse.hawkbit.repository.model.SoftwareModule; +import org.eclipse.hawkbit.repository.specifications.DistributionSetSpecification; +import org.eclipse.hawkbit.repository.specifications.DistributionSetTypeSpecification; +import org.eclipse.hawkbit.repository.specifications.SpecificationsBuilder; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Isolation; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.validation.annotation.Validated; + +import com.google.common.base.Strings; +import com.google.common.eventbus.EventBus; + +/** + * Business facade for managing the {@link DistributionSet}s. + * + */ +@Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) +@Validated +@Service +public class JpaDistributionSetManagement implements DistributionSetManagement { + + @Autowired + private EntityManager entityManager; + + @Autowired + private DistributionSetRepository distributionSetRepository; + + @Autowired + private TagManagement tagManagement; + + @Autowired + private SystemManagement systemManagement; + + @Autowired + private DistributionSetTypeRepository distributionSetTypeRepository; + + @Autowired + private DistributionSetMetadataRepository distributionSetMetadataRepository; + + @Autowired + private ActionRepository actionRepository; + + @Autowired + private EventBus eventBus; + + @Autowired + private AfterTransactionCommitExecutor afterCommit; + + @Override + public DistributionSet findDistributionSetByIdWithDetails(final Long distid) { + return distributionSetRepository.findOne(DistributionSetSpecification.byId(distid)); + } + + @Override + public DistributionSet findDistributionSetById(final Long distid) { + return distributionSetRepository.findOne(distid); + } + + @Override + @Modifying + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + public DistributionSetTagAssignmentResult toggleTagAssignment(final Collection dsIds, final String tagName) { + + final Iterable sets = findDistributionSetListWithDetails(dsIds); + final DistributionSetTag myTag = tagManagement.findDistributionSetTag(tagName); + + DistributionSetTagAssignmentResult result; + final List toBeChangedDSs = new ArrayList<>(); + for (final DistributionSet set : sets) { + if (set.getTags().add(myTag)) { + toBeChangedDSs.add(set); + } + } + + // un-assignment case + if (toBeChangedDSs.isEmpty()) { + for (final DistributionSet set : sets) { + if (set.getTags().remove(myTag)) { + toBeChangedDSs.add(set); + } + } + result = new DistributionSetTagAssignmentResult(dsIds.size() - toBeChangedDSs.size(), 0, + toBeChangedDSs.size(), Collections.emptyList(), distributionSetRepository.save(toBeChangedDSs), + myTag); + } else { + result = new DistributionSetTagAssignmentResult(dsIds.size() - toBeChangedDSs.size(), toBeChangedDSs.size(), + 0, distributionSetRepository.save(toBeChangedDSs), Collections.emptyList(), myTag); + } + + final DistributionSetTagAssignmentResult resultAssignment = result; + afterCommit.afterCommit(() -> eventBus.post(new DistributionSetTagAssigmentResultEvent(resultAssignment))); + + // no reason to persist the tag + entityManager.detach(myTag); + return result; + } + + @Override + public List findDistributionSetListWithDetails(final Collection distributionIdSet) { + return distributionSetRepository.findAll(DistributionSetSpecification.byIds(distributionIdSet)); + } + + @Override + @Modifying + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + public DistributionSet updateDistributionSet(final DistributionSet ds) { + checkNotNull(ds.getId()); + final DistributionSet persisted = findDistributionSetByIdWithDetails(ds.getId()); + checkDistributionSetSoftwareModulesIsAllowedToModify(ds, persisted.getModules()); + return distributionSetRepository.save(ds); + } + + @Override + @Modifying + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + public void deleteDistributionSet(final Long... distributionSetIDs) { + final List toHardDelete = new ArrayList<>(); + + final List assigned = distributionSetRepository.findAssignedDistributionSetsById(distributionSetIDs); + + // soft delete assigned + if (!assigned.isEmpty()) { + distributionSetRepository.deleteDistributionSet(assigned.toArray(new Long[assigned.size()])); + } + + // mark the rest as hard delete + for (final Long setId : distributionSetIDs) { + if (!assigned.contains(setId)) { + toHardDelete.add(setId); + } + } + + // hard delete the rest if exixts + if (!toHardDelete.isEmpty()) { + // don't give the delete statement an empty list, JPA/Oracle cannot + // handle the empty list + distributionSetRepository.deleteByIdIn(toHardDelete); + } + } + + @Override + @Modifying + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + public DistributionSet createDistributionSet(final DistributionSet dSet) { + prepareDsSave(dSet); + if (dSet.getType() == null) { + dSet.setType(systemManagement.getTenantMetadata().getDefaultDsType()); + } + return distributionSetRepository.save(dSet); + } + + private void prepareDsSave(final DistributionSet dSet) { + if (dSet.getId() != null) { + throw new EntityAlreadyExistsException("Parameter seems to be an existing, already persisted entity"); + } + + if (distributionSetRepository.countByNameAndVersion(dSet.getName(), dSet.getVersion()) > 0) { + throw new EntityAlreadyExistsException("DistributionSet with that name and version already exists."); + } + + } + + @Override + @Modifying + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + public List createDistributionSets(final Collection distributionSets) { + for (final DistributionSet ds : distributionSets) { + prepareDsSave(ds); + if (ds.getType() == null) { + ds.setType(systemManagement.getTenantMetadata().getDefaultDsType()); + } + } + return distributionSetRepository.save(distributionSets); + } + + @Override + @Modifying + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + public DistributionSet assignSoftwareModules(final DistributionSet ds, final Set softwareModules) { + checkDistributionSetSoftwareModulesIsAllowedToModify(ds, softwareModules); + for (final SoftwareModule softwareModule : softwareModules) { + ds.addModule(softwareModule); + } + return distributionSetRepository.save(ds); + } + + @Override + @Modifying + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + public DistributionSet unassignSoftwareModule(final DistributionSet ds, final SoftwareModule softwareModule) { + final Set softwareModules = new HashSet<>(); + softwareModules.add(softwareModule); + ds.removeModule(softwareModule); + checkDistributionSetSoftwareModulesIsAllowedToModify(ds, softwareModules); + return distributionSetRepository.save(ds); + } + + @Override + @Modifying + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + public DistributionSetType updateDistributionSetType(final DistributionSetType dsType) { + checkNotNull(dsType.getId()); + + final DistributionSetType persisted = distributionSetTypeRepository.findOne(dsType.getId()); + + // throw exception if user tries to update a DS type that is already in + // use + if (!persisted.areModuleEntriesIdentical(dsType) && distributionSetRepository.countByType(persisted) > 0) { + throw new EntityReadOnlyException( + String.format("distribution set type %s set is already assigned to targets and cannot be changed", + dsType.getName())); + } + + return distributionSetTypeRepository.save(dsType); + } + + @Override + public Page findDistributionSetTypesAll(final Specification spec, + final Pageable pageable) { + return distributionSetTypeRepository.findAll(spec, pageable); + } + + @Override + public Page findDistributionSetTypesAll(final Pageable pageable) { + return distributionSetTypeRepository.findByDeleted(pageable, false); + } + + @Override + public Page findDistributionSetsByFilters(final Pageable pageable, + final DistributionSetFilter distributionSetFilter) { + final List> specList = buildDistributionSetSpecifications(distributionSetFilter); + return findByCriteriaAPI(pageable, specList); + } + + /** + * + * @param distributionSetFilter + * had details of filters to be applied + * @return a single DistributionSet which is either installed or assigned to + * a specific target or {@code null}. + */ + private DistributionSet findDistributionSetsByFiltersAndInstalledOrAssignedTarget( + final DistributionSetFilter distributionSetFilter) { + final List> specList = buildDistributionSetSpecifications(distributionSetFilter); + if (specList == null || specList.isEmpty()) { + return null; + } + return distributionSetRepository.findOne(SpecificationsBuilder.combineWithAnd(specList)); + } + + @Override + public Page findDistributionSetsAll(final Pageable pageReq, final Boolean deleted, + final Boolean complete) { + final List> specList = new ArrayList<>(); + + if (deleted != null) { + final Specification spec = DistributionSetSpecification.isDeleted(deleted); + specList.add(spec); + } + + if (complete != null) { + final Specification spec = DistributionSetSpecification.isCompleted(complete); + specList.add(spec); + } + + return findByCriteriaAPI(pageReq, specList); + } + + @Override + public Page findDistributionSetsAll(final Specification spec, + final Pageable pageReq, final Boolean deleted) { + final List> specList = new ArrayList<>(); + if (deleted != null) { + specList.add(DistributionSetSpecification.isDeleted(deleted)); + } + specList.add(spec); + return findByCriteriaAPI(pageReq, specList); + } + + @Override + public Page findDistributionSetsAllOrderedByLinkTarget(final Pageable pageable, + final DistributionSetFilterBuilder distributionSetFilterBuilder, final String assignedOrInstalled) { + + final DistributionSetFilter filterWithInstalledTargets = distributionSetFilterBuilder + .setInstalledTargetId(assignedOrInstalled).setAssignedTargetId(null).build(); + final DistributionSet installedDS = findDistributionSetsByFiltersAndInstalledOrAssignedTarget( + filterWithInstalledTargets); + + final DistributionSetFilter filterWithAssignedTargets = distributionSetFilterBuilder.setInstalledTargetId(null) + .setAssignedTargetId(assignedOrInstalled).build(); + final DistributionSet assignedDS = findDistributionSetsByFiltersAndInstalledOrAssignedTarget( + filterWithAssignedTargets); + + final DistributionSetFilter dsFilterWithNoTargetLinked = distributionSetFilterBuilder.setInstalledTargetId(null) + .setAssignedTargetId(null).build(); + // first fine the distribution sets filtered by the given filter + // parameters + final Page findDistributionSetsByFilters = findDistributionSetsByFilters(pageable, + dsFilterWithNoTargetLinked); + + final List resultSet = new LinkedList<>(findDistributionSetsByFilters.getContent()); + int orderIndex = 0; + if (installedDS != null) { + final boolean remove = resultSet.remove(installedDS); + if (!remove) { + resultSet.remove(resultSet.size() - 1); + } + resultSet.add(orderIndex, installedDS); + orderIndex++; + } + if (assignedDS != null && !assignedDS.equals(installedDS)) { + final boolean remove = resultSet.remove(assignedDS); + if (!remove) { + resultSet.remove(resultSet.size() - 1); + } + resultSet.add(orderIndex, assignedDS); + } + + return new PageImpl<>(resultSet, pageable, findDistributionSetsByFilters.getTotalElements()); + } + + @Override + public DistributionSet findDistributionSetByNameAndVersion(final String distributionName, final String version) { + final Specification spec = DistributionSetSpecification + .equalsNameAndVersionIgnoreCase(distributionName, version); + return distributionSetRepository.findOne(spec); + + } + + @Override + public Iterable findDistributionSetList(final Collection dist) { + return distributionSetRepository.findAll(dist); + } + + @Override + public Long countDistributionSetsAll() { + + final List> specList = new ArrayList<>(); + + final Specification spec = DistributionSetSpecification.isDeleted(Boolean.FALSE); + specList.add(spec); + + return distributionSetRepository.count(SpecificationsBuilder.combineWithAnd(specList)); + } + + @Override + public Long countDistributionSetTypesAll() { + return distributionSetTypeRepository.countByDeleted(false); + } + + @Override + public DistributionSetType findDistributionSetTypeByName(final String name) { + return distributionSetTypeRepository.findOne(DistributionSetTypeSpecification.byName(name)); + } + + @Override + public DistributionSetType findDistributionSetTypeById(final Long id) { + return distributionSetTypeRepository.findOne(DistributionSetTypeSpecification.byId(id)); + } + + @Override + public DistributionSetType findDistributionSetTypeByKey(final String key) { + return distributionSetTypeRepository.findOne(DistributionSetTypeSpecification.byKey(key)); + } + + @Override + @Modifying + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + public DistributionSetType createDistributionSetType(final DistributionSetType type) { + if (type.getId() != null) { + throw new EntityAlreadyExistsException("Given type contains an Id!"); + } + + return distributionSetTypeRepository.save(type); + } + + @Override + @Modifying + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + public void deleteDistributionSetType(final DistributionSetType type) { + + if (distributionSetRepository.countByType(type) > 0) { + final DistributionSetType toDelete = entityManager.merge(type); + toDelete.setDeleted(true); + distributionSetTypeRepository.save(toDelete); + } else { + distributionSetTypeRepository.delete(type.getId()); + } + } + + @Override + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + @Modifying + public DistributionSetMetadata createDistributionSetMetadata(final DistributionSetMetadata metadata) { + if (distributionSetMetadataRepository.exists(metadata.getId())) { + throwMetadataKeyAlreadyExists(metadata.getId().getKey()); + } + // merge base distribution set so optLockRevision gets updated and audit + // log written because + // modifying metadata is modifying the base distribution set itself for + // auditing purposes. + entityManager.merge(metadata.getDistributionSet()).setLastModifiedAt(0L); + return distributionSetMetadataRepository.save(metadata); + } + + @Override + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + @Modifying + public List createDistributionSetMetadata( + final Collection metadata) { + for (final DistributionSetMetadata distributionSetMetadata : metadata) { + checkAndThrowAlreadyIfDistributionSetMetadataExists(distributionSetMetadata.getId()); + } + metadata.forEach(m -> entityManager.merge(m.getDistributionSet()).setLastModifiedAt(-1L)); + return (List) distributionSetMetadataRepository.save(metadata); + } + + @Override + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + @Modifying + public DistributionSetMetadata updateDistributionSetMetadata(final DistributionSetMetadata metadata) { + // check if exists otherwise throw entity not found exception + findOne(metadata.getId()); + // touch it to update the lock revision because we are modifying the + // DS indirectly + entityManager.merge(metadata.getDistributionSet()).setLastModifiedAt(0L); + return distributionSetMetadataRepository.save(metadata); + } + + @Override + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + @Modifying + public void deleteDistributionSetMetadata(final DsMetadataCompositeKey id) { + distributionSetMetadataRepository.delete(id); + } + + @Override + public Page findDistributionSetMetadataByDistributionSetId(final Long distributionSetId, + final Pageable pageable) { + + return distributionSetMetadataRepository.findAll( + (Specification) (root, query, cb) -> cb.equal( + root.get(DistributionSetMetadata_.distributionSet).get(DistributionSet_.id), distributionSetId), + pageable); + } + + @Override + public Page findDistributionSetMetadataByDistributionSetId(final Long distributionSetId, + final Specification spec, final Pageable pageable) { + return distributionSetMetadataRepository + .findAll( + (Specification) (root, query, + cb) -> cb.and( + cb.equal(root.get(DistributionSetMetadata_.distributionSet) + .get(DistributionSet_.id), distributionSetId), + spec.toPredicate(root, query, cb)), + pageable); + } + + @Override + public DistributionSetMetadata findOne(final DsMetadataCompositeKey id) { + final DistributionSetMetadata findOne = distributionSetMetadataRepository.findOne(id); + if (findOne == null) { + throw new EntityNotFoundException("Metadata with key '" + id.getKey() + "' does not exist"); + } + return findOne; + } + + @Override + public DistributionSet findDistributionSetByAction(final Action action) { + return distributionSetRepository.findByAction(action); + } + + @Override + public boolean isDistributionSetInUse(final DistributionSet distributionSet) { + return actionRepository.countByDistributionSet(distributionSet) > 0; + } + + private static List> buildDistributionSetSpecifications( + final DistributionSetFilter distributionSetFilter) { + final List> specList = new ArrayList<>(); + + Specification spec; + + if (null != distributionSetFilter.getIsComplete()) { + spec = DistributionSetSpecification.isCompleted(distributionSetFilter.getIsComplete()); + specList.add(spec); + } + + if (null != distributionSetFilter.getIsDeleted()) { + spec = DistributionSetSpecification.isDeleted(distributionSetFilter.getIsDeleted()); + specList.add(spec); + } + + if (distributionSetFilter.getType() != null) { + spec = DistributionSetSpecification.byType(distributionSetFilter.getType()); + specList.add(spec); + } + + if (!Strings.isNullOrEmpty(distributionSetFilter.getSearchText())) { + spec = DistributionSetSpecification.likeNameOrDescriptionOrVersion(distributionSetFilter.getSearchText()); + specList.add(spec); + } + + if (isDSWithNoTagSelected(distributionSetFilter) || isTagsSelected(distributionSetFilter)) { + spec = DistributionSetSpecification.hasTags(distributionSetFilter.getTagNames(), + distributionSetFilter.getSelectDSWithNoTag()); + specList.add(spec); + } + if (distributionSetFilter.getInstalledTargetId() != null) { + spec = DistributionSetSpecification.installedTarget(distributionSetFilter.getInstalledTargetId()); + specList.add(spec); + } + if (distributionSetFilter.getAssignedTargetId() != null) { + spec = DistributionSetSpecification.assignedTarget(distributionSetFilter.getAssignedTargetId()); + specList.add(spec); + } + return specList; + } + + private void checkDistributionSetSoftwareModulesIsAllowedToModify(final DistributionSet distributionSet, + final Set softwareModules) { + if (!new HashSet(distributionSet.getModules()).equals(softwareModules) + && actionRepository.countByDistributionSet(distributionSet) > 0) { + throw new EntityLockedException( + String.format("distribution set %s:%s is already assigned to targets and cannot be changed", + distributionSet.getName(), distributionSet.getVersion())); + } + } + + private static Boolean isDSWithNoTagSelected(final DistributionSetFilter distributionSetFilter) { + if (distributionSetFilter.getSelectDSWithNoTag() != null && distributionSetFilter.getSelectDSWithNoTag()) { + return true; + } + return false; + } + + private static Boolean isTagsSelected(final DistributionSetFilter distributionSetFilter) { + if (distributionSetFilter.getTagNames() != null && !distributionSetFilter.getTagNames().isEmpty()) { + return true; + } + return false; + } + + /** + * executes findAll with the given {@link DistributionSet} + * {@link Specification}s. + * + * @param pageable + * paging parameter + * @param specList + * list of @link {@link Specification} + * @return the page with the found {@link DistributionSet} + */ + private Page findByCriteriaAPI(final Pageable pageable, + final List> specList) { + + if (specList == null || specList.isEmpty()) { + return distributionSetRepository.findAll(pageable); + } + + return distributionSetRepository.findAll(SpecificationsBuilder.combineWithAnd(specList), pageable); + } + + private void checkAndThrowAlreadyIfDistributionSetMetadataExists(final DsMetadataCompositeKey metadataId) { + if (distributionSetMetadataRepository.exists(metadataId)) { + throw new EntityAlreadyExistsException( + "Metadata entry with key '" + metadataId.getKey() + "' already exists"); + } + } + + private static void throwMetadataKeyAlreadyExists(final String metadataKey) { + throw new EntityAlreadyExistsException("Metadata entry with key '" + metadataKey + "' already exists"); + } + + @Override + @Modifying + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + public List assignTag(final Collection dsIds, final DistributionSetTag tag) { + final List allDs = findDistributionSetListWithDetails(dsIds); + + allDs.forEach(ds -> ds.getTags().add(tag)); + final List save = distributionSetRepository.save(allDs); + + afterCommit.afterCommit(() -> { + + final DistributionSetTagAssignmentResult result = new DistributionSetTagAssignmentResult(0, save.size(), 0, + save, Collections.emptyList(), tag); + eventBus.post(new DistributionSetTagAssigmentResultEvent(result)); + }); + + return save; + } + + @Override + @Modifying + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + public List unAssignAllDistributionSetsByTag(final DistributionSetTag tag) { + return unAssignTag(tag.getAssignedToDistributionSet(), tag); + } + + @Override + @Modifying + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + public DistributionSet unAssignTag(final Long dsId, final DistributionSetTag distributionSetTag) { + final List allDs = findDistributionSetListWithDetails(Arrays.asList(dsId)); + final List unAssignTag = unAssignTag(allDs, distributionSetTag); + return unAssignTag.isEmpty() ? null : unAssignTag.get(0); + } + + private List unAssignTag(final Collection distributionSets, + final DistributionSetTag tag) { + distributionSets.forEach(ds -> ds.getTags().remove(tag)); + return distributionSetRepository.save(distributionSets); + } +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaReportManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaReportManagement.java new file mode 100644 index 000000000..f0f704352 --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaReportManagement.java @@ -0,0 +1,433 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.jpa; + +import java.io.Serializable; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import javax.persistence.EntityManager; +import javax.persistence.Query; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Expression; +import javax.persistence.criteria.Join; +import javax.persistence.criteria.JoinType; +import javax.persistence.criteria.ListJoin; +import javax.persistence.criteria.Root; + +import org.eclipse.hawkbit.report.model.DataReportSeries; +import org.eclipse.hawkbit.report.model.DataReportSeriesItem; +import org.eclipse.hawkbit.report.model.InnerOuterDataReportSeries; +import org.eclipse.hawkbit.report.model.SeriesTime; +import org.eclipse.hawkbit.repository.ReportManagement; +import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.DistributionSet_; +import org.eclipse.hawkbit.repository.model.Target; +import org.eclipse.hawkbit.repository.model.TargetInfo; +import org.eclipse.hawkbit.repository.model.TargetInfo_; +import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; +import org.eclipse.hawkbit.repository.model.Target_; +import org.eclipse.hawkbit.tenancy.TenantAware; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Isolation; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.validation.annotation.Validated; + +/** + * Service layer for generating hawkBit reports. + * + */ +@Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) +@Validated +@Service +public class JpaReportManagement implements ReportManagement { + + @Value("${spring.jpa.database}") + private String databaseType; + + private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM"); + + private static final String H2_TARGET_CREATED_SQL_TEMPLATE = "SELECT TO_CHAR( DATEADD('second', target0_.created_at / 1000, DATE '1970-01-01'), '%s') AS col_0_0_, count(target0_.controller_id) AS col_1_0_ from sp_target target0_ WHERE TO_CHAR(DATEADD('second', target0_.created_at / 1000, DATE '1970-01-01'),'%s') BETWEEN TO_CHAR('%s', '%s') and TO_CHAR('%s', '%s') AND UPPER(target0_.tenant)=UPPER('%s') GROUP BY TO_CHAR(DATEADD('second', target0_.created_at / 1000, DATE '1970-01-01'), '%s')"; + + private static final String H2_CONTROLLER_FRRDBACK_SQL_TEMPLATE = "SELECT TO_CHAR(DATEADD('second', action_.created_at / 1000, DATE '1970-01-01'), '%s') AS col_0_0_, count(action_.id) AS col_1_0_ FROM sp_action action_ WHERE TO_CHAR(DATEADD('second', action_.created_at / 1000, DATE '1970-01-01'), '%s') BETWEEN TO_CHAR('%s', '%s') AND TO_CHAR('%s', '%s') AND UPPER(action_.tenant)=UPPER('%s') GROUP BY TO_CHAR(DATEADD('second', action_.created_at / 1000, DATE '1970-01-01'), '%s')"; + + private static final String MYSQL_TARGET_CREATED_SQL_TEMPLATE = "SELECT DATE_FORMAT(FROM_UNIXTIME(target0_.created_at / 1000), '%s') AS col_0_0_, COUNT(target0_.controller_id) AS col_1_0_ FROM sp_target target0_ WHERE DATE_FORMAT(FROM_UNIXTIME(target0_.created_at / 1000),'%s') BETWEEN DATE_FORMAT('%s', '%s') AND DATE_FORMAT('%s', '%s') AND UPPER(target0_.tenant)=UPPER('%s') GROUP BY DATE_FORMAT(FROM_UNIXTIME(target0_.created_at / 1000), '%s')"; + + private static final String MYSQL_CONTROLLER_FRRDBACK_SQL_TEMPLATE = "SELECT DATE_FORMAT(FROM_UNIXTIME(action_.created_at / 1000), '%s') AS col_0_0_, COUNT(action_.id) as col_1_0_ FROM sp_action action_ WHERE DATE_FORMAT(FROM_UNIXTIME(action_.created_at / 1000),'%s') BETWEEN DATE_FORMAT('%s', '%s') AND DATE_FORMAT('%s', '%s') AND UPPER(action_.tenant)=UPPER('%s') GROUP BY DATE_FORMAT(FROM_UNIXTIME(action_.created_at / 1000), '%s')"; + + private static final String MYSQL_DB_TYPE = "MYSQL"; + + private static final String H2_DB_TYPE = "H2"; + + @Autowired + private EntityManager entityManager; + + @Autowired + private TenantAware tenantAware; + + @Override + @Cacheable("targetStatus") + public DataReportSeries targetStatus() { + + final CriteriaBuilder cb = entityManager.getCriteriaBuilder(); + final CriteriaQuery query = cb.createQuery(Object[].class); + final Root targetRoot = query.from(Target.class); + final Join targetInfo = targetRoot.join(Target_.targetInfo); + final Expression countColumn = cb.count(targetInfo.get(TargetInfo_.targetId)); + final CriteriaQuery multiselect = query + .multiselect(targetInfo.get(TargetInfo_.updateStatus), countColumn) + .groupBy(targetInfo.get(TargetInfo_.updateStatus)) + .orderBy(cb.desc(targetInfo.get(TargetInfo_.updateStatus))); + + // | col1 | col2 | + // | U_STATUS | COUNT | + final List resultList = entityManager.createQuery(multiselect).getResultList(); + + final List> reportSeriesItems = resultList.stream() + .map(r -> new DataReportSeriesItem((TargetUpdateStatus) r[0], (Long) r[1])) + .collect(Collectors.toList()); + + return new DataReportSeries<>("Target Status Overview", reportSeriesItems); + } + + @Override + @Cacheable("distributionUsageAssigned") + public List> distributionUsageAssigned(final int topXEntries) { + + // top X entries distribution usage + final CriteriaBuilder cbTopX = entityManager.getCriteriaBuilder(); + final CriteriaQuery queryTopX = cbTopX.createQuery(Object[].class); + final Root rootTopX = queryTopX.from(DistributionSet.class); + final ListJoin joinTopX = rootTopX.join(DistributionSet_.assignedToTargets, + JoinType.LEFT); + final Expression countColumn = cbTopX.count(joinTopX); + // top x usage query + final CriteriaQuery groupBy = queryTopX + .multiselect(rootTopX.get(DistributionSet_.name), rootTopX.get(DistributionSet_.version), countColumn) + .where(cbTopX.equal(rootTopX.get(DistributionSet_.deleted), false)) + .groupBy(rootTopX.get(DistributionSet_.name), rootTopX.get(DistributionSet_.version)) + .orderBy(cbTopX.desc(countColumn), cbTopX.asc(rootTopX.get(DistributionSet_.name))); + // | col1 | col2 | col3 | + // | NAME | VER | COUNT | + final List resultListTop = entityManager.createQuery(groupBy).getResultList(); + // end of top X entries distribution usage + + return mapDistirbutionUsageResultToDataReport(topXEntries, resultListTop); + } + + @Override + @Cacheable("distributionUsageInstalled") + public List> distributionUsageInstalled(final int topXEntries) { + // top X entries distribution usage + final CriteriaBuilder cbTopX = entityManager.getCriteriaBuilder(); + final CriteriaQuery queryTopX = cbTopX.createQuery(Object[].class); + final Root rootTopX = queryTopX.from(DistributionSet.class); + final ListJoin joinTopX = rootTopX.join(DistributionSet_.installedAtTargets, + JoinType.LEFT); + final Expression countColumn = cbTopX.count(joinTopX); + // top x usage query + final CriteriaQuery groupBy = queryTopX + .multiselect(rootTopX.get(DistributionSet_.name), rootTopX.get(DistributionSet_.version), countColumn) + .where(cbTopX.equal(rootTopX.get(DistributionSet_.deleted), false)) + .groupBy(rootTopX.get(DistributionSet_.name), rootTopX.get(DistributionSet_.version)) + .orderBy(cbTopX.desc(countColumn), cbTopX.asc(rootTopX.get(DistributionSet_.name))); + // | col1 | col2 | col3 | + // | NAME | VER | COUNT | + final List resultListTop = entityManager.createQuery(groupBy).getResultList(); + // end of top X entries distribution usage + + return mapDistirbutionUsageResultToDataReport(topXEntries, resultListTop); + } + + @Override + @Cacheable("targetsCreatedOverPeriod") + public DataReportSeries targetsCreatedOverPeriod(final DateType dateType, + final LocalDateTime from, final LocalDateTime to) { + final Query createNativeQuery = entityManager + .createNativeQuery(getTargetsCreatedQueryTemplate(dateType, from, to)); + final List resultList = createNativeQuery.getResultList(); + + final List> reportItems = resultList.stream() + .map(r -> new DataReportSeriesItem<>(dateType.format((String) r[0]), ((Number) r[1]).longValue())) + .collect(Collectors.toList()); + + return new DataReportSeries<>("CreatedTargets", reportItems); + } + + private String getTargetsCreatedQueryTemplate(final DateType dateType, final LocalDateTime from, + final LocalDateTime to) { + switch (databaseType) { + case H2_DB_TYPE: + return String.format(H2_TARGET_CREATED_SQL_TEMPLATE, dateTimeFormatToSqlFormat(dateType), + dateTimeFormatToSqlFormat(dateType), from.format(DATE_FORMAT), dateTimeFormatToSqlFormat(dateType), + to.format(DATE_FORMAT), dateTimeFormatToSqlFormat(dateType), tenantAware.getCurrentTenant(), + dateTimeFormatToSqlFormat(dateType)); + case MYSQL_DB_TYPE: + return String.format(MYSQL_TARGET_CREATED_SQL_TEMPLATE, dateTimeFormatToSqlFormat(dateType), + dateTimeFormatToSqlFormat(dateType), from.toString(), dateTimeFormatToSqlFormat(dateType), + to.toString(), dateTimeFormatToSqlFormat(dateType), tenantAware.getCurrentTenant(), + dateTimeFormatToSqlFormat(dateType)); + default: + return null; + } + } + + private String getFeedbackReceivedQueryTemplate(final DateType dateType, final LocalDateTime from, + final LocalDateTime to) { + switch (databaseType) { + case H2_DB_TYPE: + return String.format(H2_CONTROLLER_FRRDBACK_SQL_TEMPLATE, dateTimeFormatToSqlFormat(dateType), + dateTimeFormatToSqlFormat(dateType), from.format(DATE_FORMAT), dateTimeFormatToSqlFormat(dateType), + to.format(DATE_FORMAT), dateTimeFormatToSqlFormat(dateType), tenantAware.getCurrentTenant(), + dateTimeFormatToSqlFormat(dateType)); + case MYSQL_DB_TYPE: + return String.format(MYSQL_CONTROLLER_FRRDBACK_SQL_TEMPLATE, dateTimeFormatToSqlFormat(dateType), + dateTimeFormatToSqlFormat(dateType), from.toString(), dateTimeFormatToSqlFormat(dateType), + to.toString(), dateTimeFormatToSqlFormat(dateType), tenantAware.getCurrentTenant(), + dateTimeFormatToSqlFormat(dateType)); + default: + return null; + } + } + + @Override + @Cacheable("feedbackReceivedOverTime") + public DataReportSeries feedbackReceivedOverTime(final DateType dateType, + final LocalDateTime from, final LocalDateTime to) { + final Query createNativeQuery = entityManager + .createNativeQuery(getFeedbackReceivedQueryTemplate(dateType, from, to)); + final List resultList = createNativeQuery.getResultList(); + + final List> reportItems = resultList.stream() + .map(r -> new DataReportSeriesItem<>(dateType.format((String) r[0]), ((Number) r[1]).longValue())) + .collect(Collectors.toList()); + + return new DataReportSeries<>("FeedbackRecieved", reportItems); + } + + @Override + @Cacheable("targetsLastPoll") + public DataReportSeries targetsLastPoll() { + + final LocalDateTime now = LocalDateTime.now(); + final LocalDateTime beforeHour = now.minusHours(1); + final LocalDateTime beforeDay = now.minusDays(1); + final LocalDateTime beforeWeek = now.minusWeeks(1); + final LocalDateTime beforeMonth = now.minusMonths(1); + final LocalDateTime beforeYear = now.minusYears(1); + + final CriteriaBuilder cb = entityManager.getCriteriaBuilder(); + final List> resultList = new ArrayList<>(); + + // hours + resultList.add(new DataReportSeriesItem(SeriesTime.HOUR, + entityManager.createQuery(createCountSelectTargetsLastPoll(cb, beforeHour, now)).getSingleResult())); + // days + resultList.add(new DataReportSeriesItem(SeriesTime.DAY, entityManager + .createQuery(createCountSelectTargetsLastPoll(cb, beforeDay, beforeHour)).getSingleResult())); + // weeks + resultList.add(new DataReportSeriesItem(SeriesTime.WEEK, entityManager + .createQuery(createCountSelectTargetsLastPoll(cb, beforeWeek, beforeDay)).getSingleResult())); + // months + resultList.add(new DataReportSeriesItem(SeriesTime.MONTH, entityManager + .createQuery(createCountSelectTargetsLastPoll(cb, beforeMonth, beforeWeek)).getSingleResult())); + // years + resultList.add(new DataReportSeriesItem(SeriesTime.YEAR, entityManager + .createQuery(createCountSelectTargetsLastPoll(cb, beforeYear, beforeMonth)).getSingleResult())); + // years + resultList.add(new DataReportSeriesItem(SeriesTime.MORE_THAN_YEAR, + entityManager.createQuery(createCountSelectTargetsLastPoll(cb, null, beforeYear)).getSingleResult())); + // never + resultList.add(new DataReportSeriesItem(SeriesTime.NEVER, + entityManager.createQuery(createCountSelectTargetsLastPoll(cb, null, null)).getSingleResult())); + + return new DataReportSeries<>("TargetLastPoll", resultList); + } + + private CriteriaQuery createCountSelectTargetsLastPoll(final CriteriaBuilder cb, final LocalDateTime from, + final LocalDateTime to) { + + Long start = null; + Long end = null; + if (from != null) { + start = from.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); + } + if (to != null) { + end = to.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(); + } + + // count select statement + final CriteriaQuery countSelect = cb.createQuery(Long.class); + final Root countSelectRoot = countSelect.from(Target.class); + final Join targetInfoJoin = countSelectRoot.join(Target_.targetInfo); + countSelect.select(cb.count(countSelectRoot)); + if (start != null && end != null) { + countSelect.where(cb.between(targetInfoJoin.get(TargetInfo_.lastTargetQuery), start, end)); + } else if (from == null && to != null) { + countSelect.where(cb.lessThanOrEqualTo(targetInfoJoin.get(TargetInfo_.lastTargetQuery), end)); + } else { + countSelect.where(cb.isNull(targetInfoJoin.get(TargetInfo_.lastTargetQuery))); + } + return countSelect; + } + + private List> mapDistirbutionUsageResultToDataReport(final int topXEntries, + final List resultListTop) { + final List> innerOuterReport = new ArrayList<>(); + final Map map = new LinkedHashMap<>(); + + int topXCounter = 0; + + for (final Object[] objects : resultListTop) { + + final boolean containsInnerOuter = map.containsKey(new DSName((String) objects[0])); + final String name = containsInnerOuter || topXCounter < topXEntries ? (String) objects[0] : null; + final DSName dsName = new DSName(name); + final String version = containsInnerOuter || topXCounter < topXEntries ? (String) objects[1] : null; + final Long count = (Long) objects[2]; + + InnerOuter innerouter = map.get(dsName); + if (innerouter == null) { + topXCounter++; + innerouter = new InnerOuter(dsName); + map.put(new DSName(name), innerouter); + } + innerouter.addOuter(new DSName(version), count); + } + + for (final InnerOuter inner : map.values()) { + final List> outerReportItems = new ArrayList<>(); + + if (inner.name.getName() != null) { + for (final InnerOuter outer : inner.outer) { + outerReportItems.add(outer.toItem()); + } + } else { + outerReportItems.add(new DataReportSeriesItem("misc", inner.count)); + } + + innerOuterReport.add(new InnerOuterDataReportSeries( + new DataReportSeries<>("DS-Name", Collections.singletonList(inner.toItem())), + new DataReportSeries<>("DS-Version", outerReportItems))); + } + + return innerOuterReport; + } + + private static final class InnerOuter { + final DSName name; + long count; + final List outer; + + private InnerOuter(final DSName idName) { + name = idName; + outer = new ArrayList<>(); + } + + private InnerOuter(final DSName idName, final long count) { + name = idName; + this.count = count; + outer = new ArrayList<>(); + } + + private void addOuter(final DSName idName, final long count) { + outer.add(new InnerOuter(idName, count)); + this.count += count; + } + + private DataReportSeriesItem toItem() { + return new DataReportSeriesItem<>(name.getName() != null ? name.getName() : "misc", count); + } + } + + /** + * Object contains the name and the id of an entity. + * + */ + private static final class DSName { + + private final String name; + + /** + * @param id + * the ID of an entity + * @param name + * the name of an entity + */ + private DSName(final String name) { + this.name = name; + } + + /** + * @return the name + */ + private String getName() { + return name; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (name == null ? 0 : name.hashCode()); + return result; + } + + @Override + public boolean equals(final Object obj) { // NOSONAR - as this is + // generated + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final DSName other = (DSName) obj; + if (name == null) { + if (other.name != null) { + return false; + } + } else if (!name.equals(other.name)) { + return false; + } + return true; + } + + @Override + public String toString() { + return "DSName [name=" + name + "]"; + } + } + + private String dateTimeFormatToSqlFormat(final DateType datatype) { + switch (databaseType) { + case H2_DB_TYPE: + return datatype.h2Format(); + case MYSQL_DB_TYPE: + return datatype.mySqlFormat(); + default: + return null; + } + } + +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutGroupManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutGroupManagement.java new file mode 100644 index 000000000..3de83d381 --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutGroupManagement.java @@ -0,0 +1,178 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.jpa; + +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import javax.persistence.EntityManager; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Join; +import javax.persistence.criteria.JoinType; +import javax.persistence.criteria.ListJoin; +import javax.persistence.criteria.Root; + +import org.eclipse.hawkbit.repository.RolloutGroupManagement; +import org.eclipse.hawkbit.repository.model.Action; +import org.eclipse.hawkbit.repository.model.Action_; +import org.eclipse.hawkbit.repository.model.Rollout; +import org.eclipse.hawkbit.repository.model.Rollout.RolloutStatus; +import org.eclipse.hawkbit.repository.model.RolloutGroup; +import org.eclipse.hawkbit.repository.model.RolloutGroup_; +import org.eclipse.hawkbit.repository.model.RolloutTargetGroup; +import org.eclipse.hawkbit.repository.model.RolloutTargetGroup_; +import org.eclipse.hawkbit.repository.model.Target; +import org.eclipse.hawkbit.repository.model.TargetWithActionStatus; +import org.eclipse.hawkbit.repository.model.Target_; +import org.eclipse.hawkbit.repository.model.TotalTargetCountActionStatus; +import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Isolation; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.validation.annotation.Validated; + +/** + * RolloutGroupManagement to control rollout groups. This service secures all + * the functionality based on the {@link PreAuthorize} annotation on methods. + */ +@Validated +@Service +@Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) +public class JpaRolloutGroupManagement implements RolloutGroupManagement { + + @Autowired + private RolloutGroupRepository rolloutGroupRepository; + + @Autowired + private ActionRepository actionRepository; + + @Autowired + private TargetRepository targetRepository; + + @Autowired + private EntityManager entityManager; + + @Override + public RolloutGroup findRolloutGroupById(final Long rolloutGroupId) { + return rolloutGroupRepository.findOne(rolloutGroupId); + } + + @Override + public Page findRolloutGroupsByRolloutId(final Long rolloutId, final Pageable page) { + return rolloutGroupRepository.findByRolloutId(rolloutId, page); + } + + @Override + public Page findRolloutGroupsAll(final Rollout rollout, + final Specification specification, final Pageable page) { + return rolloutGroupRepository.findAll((root, query, criteriaBuilder) -> criteriaBuilder.and( + criteriaBuilder.equal(root.get(RolloutGroup_.rollout), rollout), + specification.toPredicate(root, query, criteriaBuilder)), page); + } + + @Override + public Page findAllRolloutGroupsWithDetailedStatus(final Long rolloutId, final Pageable page) { + final Page rolloutGroups = rolloutGroupRepository.findByRolloutId(rolloutId, page); + final List rolloutGroupIds = rolloutGroups.getContent().stream().map(rollout -> rollout.getId()) + .collect(Collectors.toList()); + final Map> allStatesForRollout = getStatusCountItemForRolloutGroup( + rolloutGroupIds); + + for (final RolloutGroup rolloutGroup : rolloutGroups) { + final TotalTargetCountStatus totalTargetCountStatus = new TotalTargetCountStatus( + allStatesForRollout.get(rolloutGroup.getId()), rolloutGroup.getTotalTargets()); + rolloutGroup.setTotalTargetCountStatus(totalTargetCountStatus); + } + + return rolloutGroups; + } + + @Override + public RolloutGroup findRolloutGroupWithDetailedStatus(final Long rolloutGroupId) { + final RolloutGroup rolloutGroup = findRolloutGroupById(rolloutGroupId); + final List rolloutStatusCountItems = actionRepository + .getStatusCountByRolloutGroupId(rolloutGroupId); + + final TotalTargetCountStatus totalTargetCountStatus = new TotalTargetCountStatus(rolloutStatusCountItems, + rolloutGroup.getTotalTargets()); + rolloutGroup.setTotalTargetCountStatus(totalTargetCountStatus); + return rolloutGroup; + + } + + private Map> getStatusCountItemForRolloutGroup( + final List rolloutGroupIds) { + final List resultList = actionRepository + .getStatusCountByRolloutGroupId(rolloutGroupIds); + return resultList.stream().collect(Collectors.groupingBy(TotalTargetCountActionStatus::getId)); + } + + @Override + public Page findRolloutGroupTargets(final RolloutGroup rolloutGroup, + final Specification specification, final Pageable page) { + return targetRepository.findAll((root, query, criteriaBuilder) -> { + final ListJoin rolloutTargetJoin = root.join(Target_.rolloutTargetGroup); + return criteriaBuilder.and(specification.toPredicate(root, query, criteriaBuilder), + criteriaBuilder.equal(rolloutTargetJoin.get(RolloutTargetGroup_.rolloutGroup), rolloutGroup)); + }, page); + } + + @Override + public Page findRolloutGroupTargets(final RolloutGroup rolloutGroup, final Pageable page) { + if (isRolloutStatusReady(rolloutGroup)) { + // in case of status ready the action has not been created yet and + // the relation information between target and rollout-group is + // stored in the #TargetRolloutGroup. + return targetRepository.findByRolloutTargetGroupRolloutGroupId(rolloutGroup.getId(), page); + } + return targetRepository.findByActionsRolloutGroup(rolloutGroup, page); + } + + private static boolean isRolloutStatusReady(final RolloutGroup rolloutGroup) { + return rolloutGroup != null && RolloutStatus.READY.equals(rolloutGroup.getRollout().getStatus()); + } + + @Override + public Page findAllTargetsWithActionStatus(final PageRequest pageRequest, + final RolloutGroup rolloutGroup) { + + final CriteriaBuilder cb = entityManager.getCriteriaBuilder(); + final CriteriaQuery query = cb.createQuery(Object[].class); + final CriteriaQuery countQuery = cb.createQuery(Long.class); + + final Root targetRoot = query.distinct(true).from(RolloutTargetGroup.class); + final Join targetJoin = targetRoot.join(RolloutTargetGroup_.target); + final ListJoin actionJoin = targetRoot.join(RolloutTargetGroup_.actions, + JoinType.LEFT); + + final Root countQueryFrom = countQuery.distinct(true).from(RolloutTargetGroup.class); + countQueryFrom.join(RolloutTargetGroup_.target); + countQueryFrom.join(RolloutTargetGroup_.actions, JoinType.LEFT); + countQuery.select(cb.count(countQueryFrom)) + .where(cb.equal(countQueryFrom.get(RolloutTargetGroup_.rolloutGroup), rolloutGroup)); + final Long totalCount = entityManager.createQuery(countQuery).getSingleResult(); + + final CriteriaQuery multiselect = query.multiselect(targetJoin, actionJoin.get(Action_.status)) + .where(cb.equal(targetRoot.get(RolloutTargetGroup_.rolloutGroup), rolloutGroup)); + final List targetWithActionStatus = entityManager.createQuery(multiselect) + .setFirstResult(pageRequest.getOffset()).setMaxResults(pageRequest.getPageSize()).getResultList() + .stream().map(o -> new TargetWithActionStatus((Target) o[0], (Action.Status) o[1])) + .collect(Collectors.toList()); + return new PageImpl<>(targetWithActionStatus, pageRequest, totalCount); + } +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java new file mode 100644 index 000000000..1f6e9b9a4 --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java @@ -0,0 +1,653 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.jpa; + +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.Executor; +import java.util.stream.Collectors; + +import javax.persistence.EntityManager; + +import org.eclipse.hawkbit.cache.CacheWriteNotify; +import org.eclipse.hawkbit.repository.DeploymentManagement; +import org.eclipse.hawkbit.repository.RolloutManagement; +import org.eclipse.hawkbit.repository.exception.RolloutIllegalStateException; +import org.eclipse.hawkbit.repository.model.Action; +import org.eclipse.hawkbit.repository.model.Action.ActionType; +import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.Rollout; +import org.eclipse.hawkbit.repository.model.Rollout.RolloutStatus; +import org.eclipse.hawkbit.repository.model.RolloutGroup; +import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupConditions; +import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupErrorCondition; +import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupStatus; +import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupSuccessCondition; +import org.eclipse.hawkbit.repository.model.RolloutTargetGroup; +import org.eclipse.hawkbit.repository.model.Rollout_; +import org.eclipse.hawkbit.repository.model.Target; +import org.eclipse.hawkbit.repository.model.TotalTargetCountActionStatus; +import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; +import org.eclipse.hawkbit.rollout.condition.RolloutGroupActionEvaluator; +import org.eclipse.hawkbit.rollout.condition.RolloutGroupConditionEvaluator; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.ApplicationContext; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; +import org.springframework.data.domain.Sort; +import org.springframework.data.domain.Sort.Direction; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.stereotype.Service; +import org.springframework.transaction.PlatformTransactionManager; +import org.springframework.transaction.TransactionDefinition; +import org.springframework.transaction.annotation.Isolation; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.transaction.support.DefaultTransactionDefinition; +import org.springframework.transaction.support.TransactionTemplate; +import org.springframework.util.Assert; +import org.springframework.validation.annotation.Validated; + +/** + * RolloutManagement to control rollouts e.g. like creating, starting, resuming + * and pausing rollouts. This service secures all the functionality based on the + * {@link PreAuthorize} annotation on methods. + */ +@Validated +@Service +@EnableScheduling +@Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) +public class JpaRolloutManagement implements RolloutManagement { + private static final Logger LOGGER = LoggerFactory.getLogger(RolloutManagement.class); + + @Autowired + private EntityManager entityManager; + + @Autowired + private RolloutRepository rolloutRepository; + + @Autowired + private TargetManagement targetManagement; + + @Autowired + private TargetRepository targetRepository; + + @Autowired + private RolloutGroupRepository rolloutGroupRepository; + + @Autowired + private DeploymentManagement deploymentManagement; + + @Autowired + private RolloutTargetGroupRepository rolloutTargetGroupRepository; + + @Autowired + private ActionRepository actionRepository; + + @Autowired + private ApplicationContext context; + + @Autowired + private NoCountPagingRepository criteriaNoCountDao; + + @Autowired + private PlatformTransactionManager txManager; + + @Autowired + private CacheWriteNotify cacheWriteNotify; + + @Autowired + @Qualifier("asyncExecutor") + private Executor executor; + + /* + * set which stores the rollouts which are asynchronously creating. This is + * necessary to verify rollouts which maybe stuck during creationg e.g. + * because of database interruption, failures or even application crash. + * !This is not cluster aware! + */ + private static final Set creatingRollouts = ConcurrentHashMap.newKeySet(); + + /* + * set which stores the rollouts which are asynchronously starting. This is + * necessary to verify rollouts which maybe stuck during starting e.g. + * because of database interruption, failures or even application crash. + * !This is not cluster aware! + */ + private static final Set startingRollouts = ConcurrentHashMap.newKeySet(); + + @Override + public Page findAll(final Pageable page) { + return rolloutRepository.findAll(page); + } + + @Override + public Page findAllWithDetailedStatusByPredicate(final Specification specification, + final Pageable page) { + final Page findAll = rolloutRepository.findAll(specification, page); + setRolloutStatusDetails(findAll); + return findAll; + } + + @Override + public Rollout findRolloutById(final Long rolloutId) { + return rolloutRepository.findOne(rolloutId); + } + + @Override + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + @Modifying + public Rollout createRollout(final Rollout rollout, final int amountGroup, + final RolloutGroupConditions conditions) { + final Rollout savedRollout = createRollout(rollout, amountGroup); + return createRolloutGroups(amountGroup, conditions, savedRollout); + } + + @Override + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + @Modifying + public Rollout createRolloutAsync(final Rollout rollout, final int amountGroup, + final RolloutGroupConditions conditions) { + final Rollout savedRollout = createRollout(rollout, amountGroup); + creatingRollouts.add(savedRollout.getName()); + // need to flush the entity manager here to get the ID of the rollout, + // because entity manager is set to FlushMode#Auto, entitymanager will + // flush the Target entity, due the indirect relationship to the Rollout + // entity without set an ID JPA is throwing a Invalid + // 'org.springframework.dao.InvalidDataAccessApiUsageException: During + // synchronization aect was found through a relationship that was not + // marked cascade PERSIST' + entityManager.flush(); + executor.execute(() -> { + try { + createRolloutGroupsInNewTransaction(amountGroup, conditions, savedRollout); + } finally { + creatingRollouts.remove(savedRollout.getName()); + } + }); + return savedRollout; + } + + private Rollout createRollout(final Rollout rollout, final int amountGroup) { + verifyRolloutGroupParameter(amountGroup); + final Long totalTargets = targetManagement.countTargetByTargetFilterQuery(rollout.getTargetFilterQuery()); + rollout.setTotalTargets(totalTargets.longValue()); + return rolloutRepository.save(rollout); + } + + private static void verifyRolloutGroupParameter(final int amountGroup) { + if (amountGroup <= 0) { + throw new IllegalArgumentException("the amountGroup must be greater than zero"); + } else if (amountGroup > 500) { + throw new IllegalArgumentException("the amountGroup must not be greater than 500"); + } + } + + private Rollout createRolloutGroupsInNewTransaction(final int amountOfGroups, + final RolloutGroupConditions conditions, final Rollout savedRollout) { + final DefaultTransactionDefinition def = new DefaultTransactionDefinition(); + def.setName("creatingRollout"); + def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); + return new TransactionTemplate(txManager, def) + .execute(status -> createRolloutGroups(amountOfGroups, conditions, savedRollout)); + } + + /** + * Method for creating rollout groups and calculating group sizes. Group + * sizes are calculated by dividing the total count of targets through the + * amount of given groups. In same cases this will lead to less rollout + * groups than given by client. + * + * @param amountOfGroups + * the amount of groups + * @param conditions + * the rollout group conditions + * @param savedRollout + * the rollout + * @return the rollout with created groups + */ + private Rollout createRolloutGroups(final int amountOfGroups, final RolloutGroupConditions conditions, + final Rollout savedRollout) { + int pageIndex = 0; + int groupIndex = 0; + final Long totalCount = savedRollout.getTotalTargets(); + final int groupSize = (int) Math.ceil((double) totalCount / (double) amountOfGroups); + // validate if the amount of groups that will be created are the amount + // of groups that the client what's to have created. + int amountGroupValidated = amountOfGroups; + final int amountGroupCreation = (int) (Math.ceil((double) totalCount / (double) groupSize)); + if (amountGroupCreation == (amountOfGroups - 1)) { + amountGroupValidated--; + } + RolloutGroup lastSavedGroup = null; + while (pageIndex < totalCount) { + groupIndex++; + final String nameAndDesc = "group-" + groupIndex; + final RolloutGroup group = new RolloutGroup(); + group.setName(nameAndDesc); + group.setDescription(nameAndDesc); + group.setRollout(savedRollout); + group.setParent(lastSavedGroup); + group.setSuccessCondition(conditions.getSuccessCondition()); + group.setSuccessConditionExp(conditions.getSuccessConditionExp()); + group.setErrorCondition(conditions.getErrorCondition()); + group.setErrorConditionExp(conditions.getErrorConditionExp()); + group.setErrorAction(conditions.getErrorAction()); + group.setErrorActionExp(conditions.getErrorActionExp()); + + final RolloutGroup savedGroup = rolloutGroupRepository.save(group); + + final Slice targetGroup = targetManagement.findTargetsAll(savedRollout.getTargetFilterQuery(), + new OffsetBasedPageRequest(pageIndex, groupSize, new Sort(Direction.ASC, "id"))); + savedGroup.setTotalTargets(targetGroup.getContent().size()); + + lastSavedGroup = savedGroup; + + targetGroup + .forEach(target -> rolloutTargetGroupRepository.save(new RolloutTargetGroup(savedGroup, target))); + cacheWriteNotify.rolloutGroupCreated(groupIndex, savedRollout.getId(), savedGroup.getId(), + amountGroupValidated, groupIndex); + pageIndex += groupSize; + } + + savedRollout.setStatus(RolloutStatus.READY); + return rolloutRepository.save(savedRollout); + } + + @Override + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + @Modifying + public Rollout startRollout(final Rollout rollout) { + final Rollout mergedRollout = entityManager.merge(rollout); + checkIfRolloutCanStarted(rollout, mergedRollout); + return doStartRollout(mergedRollout); + } + + @Override + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + @Modifying + public Rollout startRolloutAsync(final Rollout rollout) { + final Rollout mergedRollout = entityManager.merge(rollout); + checkIfRolloutCanStarted(rollout, mergedRollout); + mergedRollout.setStatus(RolloutStatus.STARTING); + final Rollout updatedRollout = rolloutRepository.save(mergedRollout); + startingRollouts.add(updatedRollout.getName()); + executor.execute(() -> { + try { + final DefaultTransactionDefinition def = new DefaultTransactionDefinition(); + def.setName("startingRollout"); + def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); + new TransactionTemplate(txManager, def).execute(status -> { + doStartRollout(updatedRollout); + return null; + }); + } finally { + startingRollouts.remove(updatedRollout.getName()); + } + }); + return updatedRollout; + + } + + private Rollout doStartRollout(final Rollout rollout) { + final DistributionSet distributionSet = rollout.getDistributionSet(); + final ActionType actionType = rollout.getActionType(); + final long forceTime = rollout.getForcedTime(); + final List rolloutGroups = rolloutGroupRepository.findByRolloutOrderByIdAsc(rollout); + for (int iGroup = 0; iGroup < rolloutGroups.size(); iGroup++) { + final RolloutGroup rolloutGroup = rolloutGroups.get(iGroup); + final List targetGroup = targetRepository.findByRolloutTargetGroupRolloutGroup(rolloutGroup); + // firstgroup can already be started + if (iGroup == 0) { + final List targetsWithActionType = targetGroup.stream() + .map(t -> new TargetWithActionType(t.getControllerId(), actionType, forceTime)) + .collect(Collectors.toList()); + deploymentManagement.assignDistributionSet(distributionSet.getId(), targetsWithActionType, rollout, + rolloutGroup); + rolloutGroup.setStatus(RolloutGroupStatus.RUNNING); + } else { + // create only not active actions with status scheduled so they + // can be activated later + deploymentManagement.createScheduledAction(targetGroup, distributionSet, actionType, forceTime, rollout, + rolloutGroup); + rolloutGroup.setStatus(RolloutGroupStatus.SCHEDULED); + } + rolloutGroupRepository.save(rolloutGroup); + } + rollout.setStatus(RolloutStatus.RUNNING); + return rolloutRepository.save(rollout); + } + + @Override + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + @Modifying + public void pauseRollout(final Rollout rollout) { + final Rollout mergedRollout = entityManager.merge(rollout); + if (mergedRollout.getStatus() != RolloutStatus.RUNNING) { + throw new RolloutIllegalStateException("Rollout can only be paused in state running but current state is " + + rollout.getStatus().name().toLowerCase()); + } + // setting the complete rollout only in paused state. This is sufficient + // due the currently running groups will be completed and new groups are + // not started until rollout goes back to running state again. The + // periodically check for running rollouts will skip rollouts in pause + // state. + mergedRollout.setStatus(RolloutStatus.PAUSED); + rolloutRepository.save(mergedRollout); + } + + @Override + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + @Modifying + public void resumeRollout(final Rollout rollout) { + final Rollout mergedRollout = entityManager.merge(rollout); + if (!(RolloutStatus.PAUSED.equals(mergedRollout.getStatus()))) { + throw new RolloutIllegalStateException("Rollout can only be resumed in state paused but current state is " + + rollout.getStatus().name().toLowerCase()); + } + mergedRollout.setStatus(RolloutStatus.RUNNING); + rolloutRepository.save(mergedRollout); + } + + @Override + @Transactional(propagation = Propagation.REQUIRES_NEW, isolation = Isolation.READ_UNCOMMITTED) + @Modifying + public void checkRunningRollouts(final long delayBetweenChecks) { + verifyStuckedRollouts(); + final long lastCheck = System.currentTimeMillis(); + final int updated = rolloutRepository.updateLastCheck(lastCheck, delayBetweenChecks, RolloutStatus.RUNNING); + + if (updated == 0) { + // nothing to check, maybe another instance already checked in + // between + LOGGER.debug("No rolloutcheck necessary for current scheduled check {}, next check at {}", lastCheck, + lastCheck + delayBetweenChecks); + return; + } + + final List rolloutsToCheck = rolloutRepository.findByLastCheckAndStatus(lastCheck, + RolloutStatus.RUNNING); + LOGGER.info("Found {} running rollouts to check", rolloutsToCheck.size()); + + for (final Rollout rollout : rolloutsToCheck) { + LOGGER.debug("Checking rollout {}", rollout); + final List rolloutGroups = rolloutGroupRepository.findByRolloutAndStatus(rollout, + RolloutGroupStatus.RUNNING); + + if (rolloutGroups.isEmpty()) { + // no running rollouts, probably there was an error + // somewhere at the latest group. And the latest group has + // been switched from running into error state. So we need + // to find the latest group which + executeLatestRolloutGroup(rollout); + } else { + LOGGER.debug("Rollout {} has {} running groups", rollout.getId(), rolloutGroups.size()); + executeRolloutGroups(rollout, rolloutGroups); + } + + if (isRolloutComplete(rollout)) { + LOGGER.info("Rollout {} is finished, setting finished status", rollout); + rollout.setStatus(RolloutStatus.FINISHED); + rolloutRepository.save(rollout); + } + } + } + + /** + * Verifies and handles stucked rollouts in asynchronous creation or + * starting state. If rollouts are created or started asynchronously it + * might be that they keep in state {@link RolloutStatus#CREATING} or + * {@link RolloutStatus#STARTING} due database or application interruption. + * In case this happens, set the rollout to error state. + */ + private void verifyStuckedRollouts() { + final List rolloutsInCreatingState = rolloutRepository.findByStatus(RolloutStatus.CREATING); + rolloutsInCreatingState.stream().filter(rollout -> !creatingRollouts.contains(rollout.getName())) + .forEach(rollout -> { + LOGGER.warn( + "Determined error during rollout creation of rollout {}, stucking in creating state, setting to status", + rollout, RolloutStatus.ERROR_CREATING); + rollout.setStatus(RolloutStatus.ERROR_CREATING); + rolloutRepository.save(rollout); + }); + + final List rolloutsInStartingState = rolloutRepository.findByStatus(RolloutStatus.STARTING); + rolloutsInStartingState.stream().filter(rollout -> !startingRollouts.contains(rollout.getName())) + .forEach(rollout -> { + LOGGER.warn( + "Determined error during rollout starting of rollout {}, stucking in starting state, setting to status", + rollout, RolloutStatus.ERROR_STARTING); + rollout.setStatus(RolloutStatus.ERROR_STARTING); + rolloutRepository.save(rollout); + }); + + } + + private void executeRolloutGroups(final Rollout rollout, final List rolloutGroups) { + for (final RolloutGroup rolloutGroup : rolloutGroups) { + // error state check, do we need to stop the whole + // rollout because of error? + final RolloutGroupErrorCondition errorCondition = rolloutGroup.getErrorCondition(); + final boolean isError = checkErrorState(rollout, rolloutGroup, errorCondition); + if (isError) { + LOGGER.info("Rollout {} {} has error, calling error action", rollout.getName(), rollout.getId()); + callErrorAction(rollout, rolloutGroup); + } else { + // not in error so check finished state, do we need to + // start the next group? + final RolloutGroupSuccessCondition finishedCondition = rolloutGroup.getSuccessCondition(); + checkFinishCondition(rollout, rolloutGroup, finishedCondition); + if (isRolloutGroupComplete(rollout, rolloutGroup)) { + rolloutGroup.setStatus(RolloutGroupStatus.FINISHED); + rolloutGroupRepository.save(rolloutGroup); + } + } + } + } + + private void executeLatestRolloutGroup(final Rollout rollout) { + final List latestRolloutGroup = rolloutGroupRepository + .findByRolloutAndStatusNotOrderByIdDesc(rollout, RolloutGroupStatus.SCHEDULED); + if (latestRolloutGroup.isEmpty()) { + return; + } + executeRolloutGroupSuccessAction(rollout, latestRolloutGroup.get(0)); + } + + private void callErrorAction(final Rollout rollout, final RolloutGroup rolloutGroup) { + try { + context.getBean(rolloutGroup.getErrorAction().getBeanName(), RolloutGroupActionEvaluator.class) + .eval(rollout, rolloutGroup, rolloutGroup.getErrorActionExp()); + } catch (final BeansException e) { + LOGGER.error("Something bad happend when accessing the error action bean {}", + rolloutGroup.getErrorAction().getBeanName(), e); + } + } + + private boolean isRolloutComplete(final Rollout rollout) { + final Long groupsActiveLeft = rolloutGroupRepository.countByRolloutAndStatusOrStatus(rollout, + RolloutGroupStatus.RUNNING, RolloutGroupStatus.SCHEDULED); + return groupsActiveLeft == 0; + } + + private boolean isRolloutGroupComplete(final Rollout rollout, final RolloutGroup rolloutGroup) { + final Long actionsLeftForRollout = actionRepository + .countByRolloutAndRolloutGroupAndStatusNotAndStatusNotAndStatusNot(rollout, rolloutGroup, + Action.Status.ERROR, Action.Status.FINISHED, Action.Status.CANCELED); + return actionsLeftForRollout == 0; + } + + private boolean checkErrorState(final Rollout rollout, final RolloutGroup rolloutGroup, + final RolloutGroupErrorCondition errorCondition) { + if (errorCondition == null) { + // there is no error condition, so return false, don't have error. + return false; + } + try { + return context.getBean(errorCondition.getBeanName(), RolloutGroupConditionEvaluator.class).eval(rollout, + rolloutGroup, rolloutGroup.getErrorConditionExp()); + } catch (final BeansException e) { + LOGGER.error("Something bad happend when accessing the error condition bean {}", + errorCondition.getBeanName(), e); + return false; + } + } + + private boolean checkFinishCondition(final Rollout rollout, final RolloutGroup rolloutGroup, + final RolloutGroupSuccessCondition finishCondition) { + LOGGER.trace("Checking finish condition {} on rolloutgroup {}", finishCondition, rolloutGroup); + try { + final boolean isFinished = context + .getBean(finishCondition.getBeanName(), RolloutGroupConditionEvaluator.class) + .eval(rollout, rolloutGroup, rolloutGroup.getSuccessConditionExp()); + if (isFinished) { + LOGGER.info("Rolloutgroup {} is finished, starting next group", rolloutGroup); + executeRolloutGroupSuccessAction(rollout, rolloutGroup); + } else { + LOGGER.debug("Rolloutgroup {} is still running", rolloutGroup); + } + return isFinished; + } catch (final BeansException e) { + LOGGER.error("Something bad happend when accessing the finish condition bean {}", + finishCondition.getBeanName(), e); + return false; + } + } + + private void executeRolloutGroupSuccessAction(final Rollout rollout, final RolloutGroup rolloutGroup) { + context.getBean(rolloutGroup.getSuccessAction().getBeanName(), RolloutGroupActionEvaluator.class).eval(rollout, + rolloutGroup, rolloutGroup.getSuccessActionExp()); + } + + @Override + public Long countRolloutsAll() { + return rolloutRepository.count(); + } + + @Override + public Long countRolloutsAllByFilters(final String searchText) { + return rolloutRepository.count(likeNameOrDescription(searchText)); + } + + private static Specification likeNameOrDescription(final String searchText) { + return (rolloutRoot, query, criteriaBuilder) -> { + final String searchTextToLower = searchText.toLowerCase(); + return criteriaBuilder.or( + criteriaBuilder.like(criteriaBuilder.lower(rolloutRoot.get(Rollout_.name)), searchTextToLower), + criteriaBuilder.like(criteriaBuilder.lower(rolloutRoot.get(Rollout_.description)), + searchTextToLower)); + }; + } + + @Override + public Slice findRolloutByFilters(final Pageable pageable, final String searchText) { + final Specification specs = likeNameOrDescription(searchText); + final Slice findAll = criteriaNoCountDao.findAll(specs, pageable, Rollout.class); + setRolloutStatusDetails(findAll); + return findAll; + } + + @Override + public Rollout findRolloutByName(final String rolloutName) { + return rolloutRepository.findByName(rolloutName); + } + + /** + * Update rollout details. + * + * @param rollout + * rollout to be updated + * + * @return Rollout updated rollout + */ + @Override + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + @Modifying + public Rollout updateRollout(final Rollout rollout) { + Assert.notNull(rollout.getId()); + return rolloutRepository.save(rollout); + } + + /** + * Get count of targets in different status in rollout. + * + * @param page + * the page request to sort and limit the result + * @return a list of rollouts with details of targets count for different + * statuses + * + */ + @Override + public Page findAllRolloutsWithDetailedStatus(final Pageable page) { + final Page rollouts = findAll(page); + setRolloutStatusDetails(rollouts); + return rollouts; + + } + + @Override + public Rollout findRolloutWithDetailedStatus(final Long rolloutId) { + final Rollout rollout = findRolloutById(rolloutId); + final List rolloutStatusCountItems = actionRepository + .getStatusCountByRolloutId(rolloutId); + final TotalTargetCountStatus totalTargetCountStatus = new TotalTargetCountStatus(rolloutStatusCountItems, + rollout.getTotalTargets()); + rollout.setTotalTargetCountStatus(totalTargetCountStatus); + return rollout; + } + + private Map> getStatusCountItemForRollout(final List rolloutIds) { + final List resultList = actionRepository.getStatusCountByRolloutId(rolloutIds); + return resultList.stream().collect(Collectors.groupingBy(TotalTargetCountActionStatus::getId)); + } + + private void setRolloutStatusDetails(final Slice rollouts) { + final List rolloutIds = rollouts.getContent().stream().map(rollout -> rollout.getId()) + .collect(Collectors.toList()); + final Map> allStatesForRollout = getStatusCountItemForRollout( + rolloutIds); + + for (final Rollout rollout : rollouts) { + final TotalTargetCountStatus totalTargetCountStatus = new TotalTargetCountStatus( + allStatesForRollout.get(rollout.getId()), rollout.getTotalTargets()); + rollout.setTotalTargetCountStatus(totalTargetCountStatus); + } + } + + private static void checkIfRolloutCanStarted(final Rollout rollout, final Rollout mergedRollout) { + if (!(RolloutStatus.READY.equals(mergedRollout.getStatus()))) { + throw new RolloutIllegalStateException("Rollout can only be started in state ready but current state is " + + rollout.getStatus().name().toLowerCase()); + } + } + + @Override + public float getFinishedPercentForRunningGroup(final Long rolloutId, final RolloutGroup rolloutGroup) { + final Long totalGroup = rolloutGroup.getTotalTargets(); + final Long finished = actionRepository.countByRolloutIdAndRolloutGroupIdAndStatus(rolloutId, + rolloutGroup.getId(), Action.Status.FINISHED); + if (totalGroup == 0) { + // in case e.g. targets has been deleted we don't have any actions + // left for this group, so the group is finished + return 100; + } + // calculate threshold + return ((float) finished / (float) totalGroup) * 100; + } +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTenantConfigurationManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTenantConfigurationManagement.java new file mode 100644 index 000000000..5cc27d75c --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTenantConfigurationManagement.java @@ -0,0 +1,170 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.jpa; + +import org.eclipse.hawkbit.repository.TenantConfigurationManagement; +import org.eclipse.hawkbit.repository.model.TenantConfiguration; +import org.eclipse.hawkbit.repository.model.TenantConfigurationValue; +import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; +import org.eclipse.hawkbit.tenancy.configuration.validator.TenantConfigurationValidatorException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.context.ApplicationContext; +import org.springframework.context.EnvironmentAware; +import org.springframework.core.convert.support.ConfigurableConversionService; +import org.springframework.core.convert.support.DefaultConversionService; +import org.springframework.core.env.Environment; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Isolation; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.validation.annotation.Validated; + +/** + * Central tenant configuration management operations of the SP server. + */ +@Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) +@Validated +@Service +public class JpaTenantConfigurationManagement implements EnvironmentAware, TenantConfigurationManagement { + + @Autowired + private TenantConfigurationRepository tenantConfigurationRepository; + + @Autowired + private ApplicationContext applicationContext; + + private static final ConfigurableConversionService conversionService = new DefaultConversionService(); + + private Environment environment; + + @Override + @Cacheable(value = "tenantConfiguration", key = "#configurationKey.getKeyName()") + public TenantConfigurationValue getConfigurationValue(final TenantConfigurationKey configurationKey, + final Class propertyType) { + validateTenantConfigurationDataType(configurationKey, propertyType); + + final TenantConfiguration tenantConfiguration = tenantConfigurationRepository + .findByKey(configurationKey.getKeyName()); + + return buildTenantConfigurationValueByKey(configurationKey, propertyType, tenantConfiguration); + } + + /** + * Validates the data type of the tenant configuration. If it is possible to + * cast to the given data type. + * + * @param configurationKey + * the key + * @param propertyType + * the class + */ + static void validateTenantConfigurationDataType(final TenantConfigurationKey configurationKey, + final Class propertyType) { + if (!configurationKey.getDataType().isAssignableFrom(propertyType)) { + throw new TenantConfigurationValidatorException( + String.format("Cannot parse the database value of type %s into the type %s.", + configurationKey.getDataType(), propertyType)); + } + } + + @Override + public TenantConfigurationValue buildTenantConfigurationValueByKey( + final TenantConfigurationKey configurationKey, final Class propertyType, + final TenantConfiguration tenantConfiguration) { + if (tenantConfiguration != null) { + return TenantConfigurationValue. builder().isGlobal(false).createdBy(tenantConfiguration.getCreatedBy()) + .createdAt(tenantConfiguration.getCreatedAt()) + .lastModifiedAt(tenantConfiguration.getLastModifiedAt()) + .lastModifiedBy(tenantConfiguration.getLastModifiedBy()) + .value(conversionService.convert(tenantConfiguration.getValue(), propertyType)).build(); + + } else if (configurationKey.getDefaultKeyName() != null) { + + return TenantConfigurationValue. builder().isGlobal(true).createdBy(null).createdAt(null) + .lastModifiedAt(null).lastModifiedBy(null) + .value(getGlobalConfigurationValue(configurationKey, propertyType)).build(); + } + return null; + } + + @Override + public TenantConfigurationValue getConfigurationValue(final TenantConfigurationKey configurationKey) { + return getConfigurationValue(configurationKey, configurationKey.getDataType()); + } + + @Override + public T getGlobalConfigurationValue(final TenantConfigurationKey configurationKey, + final Class propertyType) { + + if (!configurationKey.getDataType().isAssignableFrom(propertyType)) { + throw new TenantConfigurationValidatorException( + String.format("Cannot parse the database value of type %s into the type %s.", + configurationKey.getDataType(), propertyType)); + } + + final T valueInProperties = environment.getProperty(configurationKey.getDefaultKeyName(), propertyType); + + if (valueInProperties == null) { + return conversionService.convert(configurationKey.getDefaultValue(), propertyType); + } + + return valueInProperties; + } + + @Override + @CacheEvict(value = "tenantConfiguration", key = "#configurationKey.getKeyName()") + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + @Modifying + public TenantConfigurationValue addOrUpdateConfiguration(final TenantConfigurationKey configurationKey, + final T value) { + + if (!configurationKey.getDataType().isAssignableFrom(value.getClass())) { + throw new TenantConfigurationValidatorException(String.format( + "Cannot parse the value %s of type %s into the type %s defined by the configuration key.", value, + value.getClass(), configurationKey.getDataType())); + } + + configurationKey.validate(applicationContext, value); + + TenantConfiguration tenantConfiguration = tenantConfigurationRepository + .findByKey(configurationKey.getKeyName()); + + if (tenantConfiguration == null) { + tenantConfiguration = new TenantConfiguration(configurationKey.getKeyName(), value.toString()); + } else { + tenantConfiguration.setValue(value.toString()); + } + + final TenantConfiguration updatedTenantConfiguration = tenantConfigurationRepository.save(tenantConfiguration); + + final Class clazzT = (Class) value.getClass(); + + return TenantConfigurationValue. builder().isGlobal(false) + .createdBy(updatedTenantConfiguration.getCreatedBy()) + .createdAt(updatedTenantConfiguration.getCreatedAt()) + .lastModifiedAt(updatedTenantConfiguration.getLastModifiedAt()) + .lastModifiedBy(updatedTenantConfiguration.getLastModifiedBy()) + .value(conversionService.convert(updatedTenantConfiguration.getValue(), clazzT)).build(); + } + + @Override + @CacheEvict(value = "tenantConfiguration", key = "#configurationKey.getKeyName()") + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + @Modifying + public void deleteConfiguration(final TenantConfigurationKey configurationKey) { + tenantConfigurationRepository.deleteByKey(configurationKey.getKeyName()); + } + + @Override + public void setEnvironment(final Environment environment) { + this.environment = environment; + } +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/LocalArtifactRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/LocalArtifactRepository.java similarity index 98% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/LocalArtifactRepository.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/LocalArtifactRepository.java index 4c106957d..fcad668d2 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/LocalArtifactRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/LocalArtifactRepository.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.jpa; import java.util.List; import java.util.Optional; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/NoCountPagingRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/NoCountPagingRepository.java similarity index 98% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/NoCountPagingRepository.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/NoCountPagingRepository.java index 0624f269a..c0f8b89ff 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/NoCountPagingRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/NoCountPagingRepository.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.jpa; import java.io.Serializable; import java.util.List; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/OffsetBasedPageRequest.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/OffsetBasedPageRequest.java similarity index 98% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/OffsetBasedPageRequest.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/OffsetBasedPageRequest.java index 753ec6963..80bb85461 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/OffsetBasedPageRequest.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/OffsetBasedPageRequest.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.jpa; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Sort; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/RolloutGroupRepository.java similarity index 99% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupRepository.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/RolloutGroupRepository.java index e0cb4cc27..2433eb8aa 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/RolloutGroupRepository.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.jpa; import java.util.List; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/RolloutRepository.java similarity index 98% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutRepository.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/RolloutRepository.java index 5a22f5ab5..212672419 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/RolloutRepository.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.jpa; import java.util.List; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutTargetGroupRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/RolloutTargetGroupRepository.java similarity index 95% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutTargetGroupRepository.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/RolloutTargetGroupRepository.java index 14d9b8353..2e7eac55d 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutTargetGroupRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/RolloutTargetGroupRepository.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.jpa; import org.eclipse.hawkbit.repository.model.RolloutTargetGroup; import org.eclipse.hawkbit.repository.model.RolloutTargetGroupId; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareManagement.java similarity index 99% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareManagement.java index d719667ed..813f2e5a6 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareManagement.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.jpa; import static com.google.common.base.Preconditions.checkNotNull; @@ -27,6 +27,7 @@ import javax.persistence.criteria.Root; import javax.validation.constraints.NotNull; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; +import org.eclipse.hawkbit.repository.ArtifactManagement; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.model.CustomSoftwareModule; @@ -307,7 +308,7 @@ public class SoftwareManagement { private void deleteGridFsArtifacts(final SoftwareModule swModule) { for (final LocalArtifact localArtifact : swModule.getLocalArtifacts()) { - artifactManagement.deleteGridFsArtifact(localArtifact); + artifactManagement.deleteLocalArtifact(localArtifact); } } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SoftwareModuleMetadataRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleMetadataRepository.java similarity index 97% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SoftwareModuleMetadataRepository.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleMetadataRepository.java index c40a96e92..8023a9361 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SoftwareModuleMetadataRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleMetadataRepository.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.jpa; import java.util.List; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SoftwareModuleRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleRepository.java similarity index 99% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SoftwareModuleRepository.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleRepository.java index 95b01c270..e03b3e084 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SoftwareModuleRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleRepository.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.jpa; import java.util.List; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SoftwareModuleTypeRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleTypeRepository.java similarity index 97% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SoftwareModuleTypeRepository.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleTypeRepository.java index ac9425a08..fe2cfadf4 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SoftwareModuleTypeRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleTypeRepository.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.jpa; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.springframework.data.domain.Page; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/SystemManagement.java similarity index 99% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/SystemManagement.java index 49c9183a7..67f7bf93f 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/SystemManagement.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.jpa; import java.lang.reflect.Method; import java.math.BigDecimal; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TagManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TagManagement.java similarity index 99% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TagManagement.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TagManagement.java index 8db9773e6..dbca65a00 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TagManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TagManagement.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.jpa; import static com.google.common.base.Preconditions.checkNotNull; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetFilterQueryManagement.java similarity index 99% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagement.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetFilterQueryManagement.java index 4f7c91da3..18ab0c486 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetFilterQueryManagement.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.jpa; import java.util.ArrayList; import java.util.List; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetFilterQueryRepository.java similarity index 96% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryRepository.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetFilterQueryRepository.java index 3604785cd..346fe2ec2 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetFilterQueryRepository.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.jpa; import org.eclipse.hawkbit.repository.model.TargetFilterQuery; import org.springframework.data.domain.Page; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetInfoRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetInfoRepository.java similarity index 98% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetInfoRepository.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetInfoRepository.java index 436f1e7b6..1c3378bba 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetInfoRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetInfoRepository.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.jpa; import java.util.Collection; import java.util.List; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetManagement.java similarity index 99% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetManagement.java index 4d6540acf..01d6eb527 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetManagement.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.jpa; import java.net.URI; import java.util.ArrayList; @@ -33,6 +33,7 @@ import org.eclipse.hawkbit.Constants; import org.eclipse.hawkbit.eventbus.event.TargetTagAssigmentResultEvent; import org.eclipse.hawkbit.executor.AfterTransactionCommitExecutor; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; +import org.eclipse.hawkbit.repository.TargetFields; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSet_; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetRepository.java similarity index 99% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetRepository.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetRepository.java index 5e37902ab..b3d390016 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetRepository.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.jpa; import java.util.Collection; import java.util.List; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetTagRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetTagRepository.java similarity index 97% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetTagRepository.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetTagRepository.java index e0f03ee78..92f48d699 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetTagRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetTagRepository.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.jpa; import java.util.List; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetWithActionType.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetWithActionType.java similarity index 97% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetWithActionType.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetWithActionType.java index 18efa23a9..a2c0a7d8f 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetWithActionType.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetWithActionType.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.jpa; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.ActionType; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantConfigurationRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TenantConfigurationRepository.java similarity index 97% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantConfigurationRepository.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TenantConfigurationRepository.java index 0497ea924..6494aafea 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantConfigurationRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TenantConfigurationRepository.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.jpa; import java.util.List; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantKeyGenerator.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TenantKeyGenerator.java similarity index 95% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantKeyGenerator.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TenantKeyGenerator.java index 3265b622c..0478d99d7 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantKeyGenerator.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TenantKeyGenerator.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.jpa; import java.lang.reflect.Method; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantMetaDataRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TenantMetaDataRepository.java similarity index 97% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantMetaDataRepository.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TenantMetaDataRepository.java index 4aa4c48dc..63c213d2c 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantMetaDataRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TenantMetaDataRepository.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.jpa; import java.util.List; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantStatsManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TenantStatsManagement.java similarity index 82% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantStatsManagement.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TenantStatsManagement.java index c124037fa..451a6e401 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantStatsManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TenantStatsManagement.java @@ -6,13 +6,16 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.jpa; import java.util.Optional; +import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; import org.eclipse.hawkbit.report.model.TenantUsage; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Isolation; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; @@ -43,7 +46,8 @@ public class TenantStatsManagement { * to collect for * @return collected statistics */ - @Transactional(propagation = Propagation.REQUIRES_NEW) + @Transactional(propagation = Propagation.REQUIRES_NEW, isolation = Isolation.READ_UNCOMMITTED) + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_SYSTEM_ADMIN) public TenantUsage getStatsOfTenant(final String tenant) { final TenantUsage result = new TenantUsage(tenant); diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/helper/SystemManagementHolder.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/helper/SystemManagementHolder.java index d1327c690..fd1d81280 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/helper/SystemManagementHolder.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/helper/SystemManagementHolder.java @@ -8,7 +8,7 @@ */ package org.eclipse.hawkbit.repository.model.helper; -import org.eclipse.hawkbit.repository.SystemManagement; +import org.eclipse.hawkbit.repository.jpa.SystemManagement; import org.springframework.beans.factory.annotation.Autowired; /** diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/rollout/condition/PauseRolloutGroupAction.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/rollout/condition/PauseRolloutGroupAction.java index af335cd0d..3af269819 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/rollout/condition/PauseRolloutGroupAction.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/rollout/condition/PauseRolloutGroupAction.java @@ -10,8 +10,8 @@ package org.eclipse.hawkbit.rollout.condition; import java.util.concurrent.Callable; -import org.eclipse.hawkbit.repository.RolloutGroupRepository; import org.eclipse.hawkbit.repository.RolloutManagement; +import org.eclipse.hawkbit.repository.jpa.RolloutGroupRepository; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.RolloutGroup; import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupStatus; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/rollout/condition/StartNextGroupRolloutGroupSuccessAction.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/rollout/condition/StartNextGroupRolloutGroupSuccessAction.java index 21c499d31..224901053 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/rollout/condition/StartNextGroupRolloutGroupSuccessAction.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/rollout/condition/StartNextGroupRolloutGroupSuccessAction.java @@ -11,7 +11,7 @@ package org.eclipse.hawkbit.rollout.condition; import java.util.List; import org.eclipse.hawkbit.repository.DeploymentManagement; -import org.eclipse.hawkbit.repository.RolloutGroupRepository; +import org.eclipse.hawkbit.repository.jpa.RolloutGroupRepository; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.RolloutGroup; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/rollout/condition/ThresholdRolloutGroupErrorCondition.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/rollout/condition/ThresholdRolloutGroupErrorCondition.java index 6e63efa8e..e38cb0f16 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/rollout/condition/ThresholdRolloutGroupErrorCondition.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/rollout/condition/ThresholdRolloutGroupErrorCondition.java @@ -8,7 +8,7 @@ */ package org.eclipse.hawkbit.rollout.condition; -import org.eclipse.hawkbit.repository.ActionRepository; +import org.eclipse.hawkbit.repository.jpa.ActionRepository; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.RolloutGroup; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/rollout/condition/ThresholdRolloutGroupSuccessCondition.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/rollout/condition/ThresholdRolloutGroupSuccessCondition.java index fcf9762c6..5f9167931 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/rollout/condition/ThresholdRolloutGroupSuccessCondition.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/rollout/condition/ThresholdRolloutGroupSuccessCondition.java @@ -8,7 +8,7 @@ */ package org.eclipse.hawkbit.rollout.condition; -import org.eclipse.hawkbit.repository.ActionRepository; +import org.eclipse.hawkbit.repository.jpa.ActionRepository; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.RolloutGroup; diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/AbstractIntegrationTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/AbstractIntegrationTest.java index b7091edf8..99b93926f 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/AbstractIntegrationTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/AbstractIntegrationTest.java @@ -16,34 +16,34 @@ import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import org.eclipse.hawkbit.cache.TenantAwareCacheManager; -import org.eclipse.hawkbit.repository.ActionRepository; -import org.eclipse.hawkbit.repository.ActionStatusRepository; import org.eclipse.hawkbit.repository.ArtifactManagement; import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement; -import org.eclipse.hawkbit.repository.DistributionSetRepository; -import org.eclipse.hawkbit.repository.DistributionSetTagRepository; -import org.eclipse.hawkbit.repository.DistributionSetTypeRepository; -import org.eclipse.hawkbit.repository.ExternalArtifactRepository; -import org.eclipse.hawkbit.repository.LocalArtifactRepository; import org.eclipse.hawkbit.repository.RolloutGroupManagement; -import org.eclipse.hawkbit.repository.RolloutGroupRepository; import org.eclipse.hawkbit.repository.RolloutManagement; -import org.eclipse.hawkbit.repository.RolloutRepository; -import org.eclipse.hawkbit.repository.SoftwareManagement; -import org.eclipse.hawkbit.repository.SoftwareModuleMetadataRepository; -import org.eclipse.hawkbit.repository.SoftwareModuleRepository; -import org.eclipse.hawkbit.repository.SoftwareModuleTypeRepository; -import org.eclipse.hawkbit.repository.SystemManagement; -import org.eclipse.hawkbit.repository.TagManagement; -import org.eclipse.hawkbit.repository.TargetFilterQueryManagement; -import org.eclipse.hawkbit.repository.TargetInfoRepository; -import org.eclipse.hawkbit.repository.TargetManagement; -import org.eclipse.hawkbit.repository.TargetRepository; -import org.eclipse.hawkbit.repository.TargetTagRepository; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; -import org.eclipse.hawkbit.repository.TenantMetaDataRepository; +import org.eclipse.hawkbit.repository.jpa.ActionRepository; +import org.eclipse.hawkbit.repository.jpa.ActionStatusRepository; +import org.eclipse.hawkbit.repository.jpa.DistributionSetRepository; +import org.eclipse.hawkbit.repository.jpa.DistributionSetTagRepository; +import org.eclipse.hawkbit.repository.jpa.DistributionSetTypeRepository; +import org.eclipse.hawkbit.repository.jpa.ExternalArtifactRepository; +import org.eclipse.hawkbit.repository.jpa.LocalArtifactRepository; +import org.eclipse.hawkbit.repository.jpa.RolloutGroupRepository; +import org.eclipse.hawkbit.repository.jpa.RolloutRepository; +import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; +import org.eclipse.hawkbit.repository.jpa.SoftwareModuleMetadataRepository; +import org.eclipse.hawkbit.repository.jpa.SoftwareModuleRepository; +import org.eclipse.hawkbit.repository.jpa.SoftwareModuleTypeRepository; +import org.eclipse.hawkbit.repository.jpa.SystemManagement; +import org.eclipse.hawkbit.repository.jpa.TagManagement; +import org.eclipse.hawkbit.repository.jpa.TargetFilterQueryManagement; +import org.eclipse.hawkbit.repository.jpa.TargetInfoRepository; +import org.eclipse.hawkbit.repository.jpa.TargetManagement; +import org.eclipse.hawkbit.repository.jpa.TargetRepository; +import org.eclipse.hawkbit.repository.jpa.TargetTagRepository; +import org.eclipse.hawkbit.repository.jpa.TenantMetaDataRepository; import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.repository.utils.RepositoryDataGenerator.DatabaseCleanupUtil; diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/TestDataUtil.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/TestDataUtil.java index 1787d29e4..11106eaf1 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/TestDataUtil.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/TestDataUtil.java @@ -18,8 +18,8 @@ import java.util.UUID; import org.apache.commons.io.IOUtils; import org.eclipse.hawkbit.repository.ArtifactManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement; -import org.eclipse.hawkbit.repository.SoftwareManagement; -import org.eclipse.hawkbit.repository.TargetManagement; +import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; +import org.eclipse.hawkbit.repository.jpa.TargetManagement; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.DistributionSetType; diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ControllerManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ControllerManagementTest.java index 279932ef7..4c0bc1c19 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ControllerManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ControllerManagementTest.java @@ -58,14 +58,14 @@ public class ControllerManagementTest extends AbstractIntegrationTest { System.currentTimeMillis()); actionStatusMessage.addMessage("foobar"); savedAction.setStatus(Status.RUNNING); - controllerManagament.addUpdateActionStatus(actionStatusMessage, savedAction); + controllerManagament.addUpdateActionStatus(actionStatusMessage); assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus()) .isEqualTo(TargetUpdateStatus.PENDING); actionStatusMessage = new ActionStatus(savedAction, Action.Status.FINISHED, System.currentTimeMillis()); actionStatusMessage.addMessage(RandomStringUtils.randomAscii(512)); savedAction.setStatus(Status.FINISHED); - controllerManagament.addUpdateActionStatus(actionStatusMessage, savedAction); + controllerManagament.addUpdateActionStatus(actionStatusMessage); assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus()) .isEqualTo(TargetUpdateStatus.IN_SYNC); @@ -111,21 +111,21 @@ public class ControllerManagementTest extends AbstractIntegrationTest { final ActionStatus actionStatusMessage = new ActionStatus(savedAction, Action.Status.RUNNING, System.currentTimeMillis()); actionStatusMessage.addMessage("running"); - savedAction = controllerManagament.addUpdateActionStatus(actionStatusMessage, savedAction); + savedAction = controllerManagament.addUpdateActionStatus(actionStatusMessage); assertThat(targetManagement.findTargetByControllerID("Rabbit").getTargetInfo().getUpdateStatus()) .isEqualTo(TargetUpdateStatus.PENDING); final ActionStatus actionStatusMessage2 = new ActionStatus(savedAction, Action.Status.ERROR, System.currentTimeMillis()); actionStatusMessage2.addMessage("error"); - savedAction = controllerManagament.addUpdateActionStatus(actionStatusMessage2, savedAction); + savedAction = controllerManagament.addUpdateActionStatus(actionStatusMessage2); assertThat(targetManagement.findTargetByControllerID("Rabbit").getTargetInfo().getUpdateStatus()) .isEqualTo(TargetUpdateStatus.ERROR); final ActionStatus actionStatusMessage3 = new ActionStatus(savedAction, Action.Status.FINISHED, System.currentTimeMillis()); actionStatusMessage3.addMessage("finish"); - controllerManagament.addUpdateActionStatus(actionStatusMessage3, savedAction); + controllerManagament.addUpdateActionStatus(actionStatusMessage3); targetManagement.findTargetByControllerID("Rabbit").getTargetInfo().getUpdateStatus(); diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DeploymentManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DeploymentManagementTest.java index a17054a3d..6a6d92bf0 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DeploymentManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DeploymentManagementTest.java @@ -27,6 +27,7 @@ import org.eclipse.hawkbit.eventbus.event.CancelTargetAssignmentEvent; import org.eclipse.hawkbit.eventbus.event.TargetAssignDistributionSetEvent; import org.eclipse.hawkbit.repository.exception.ForceQuitActionNotAllowedException; import org.eclipse.hawkbit.repository.exception.IncompleteDistributionSetException; +import org.eclipse.hawkbit.repository.jpa.TargetRepository; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.ActionType; import org.eclipse.hawkbit.repository.model.Action.Status; @@ -104,7 +105,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { @Test @Description("Ensures that distribution sets can assigned and unassigned to a distribution set tag. Not exists distribution set will be ignored for the assignment.") public void assignAndUnassignDistributionSetToTag() { - final List assignDS = new ArrayList(); + final List assignDS = new ArrayList<>(); for (int i = 0; i < 4; i++) { assignDS.add(TestDataUtil.generateDistributionSet("DS" + i, "1.0", softwareManagement, distributionSetManagement, new ArrayList()).getId()); @@ -199,8 +200,8 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { secondAction = deploymentManagement.findActionWithDetails(secondAction.getId()); // confirm cancellation secondAction.setStatus(Status.CANCELED); - controllerManagement.addCancelActionStatus( - new ActionStatus(secondAction, Status.CANCELED, System.currentTimeMillis()), secondAction); + controllerManagement + .addCancelActionStatus(new ActionStatus(secondAction, Status.CANCELED, System.currentTimeMillis())); assertThat(actionStatusRepository.findAll()).as("wrong size of actions status").hasSize(4); assertThat(targetManagement.findTargetByControllerID("4712").getAssignedDistributionSet()).as("wrong ds") .isEqualTo(dsFirst); @@ -213,8 +214,8 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { firstAction = deploymentManagement.findActionWithDetails(firstAction.getId()); // confirm cancellation firstAction.setStatus(Status.CANCELED); - controllerManagement.addCancelActionStatus( - new ActionStatus(firstAction, Status.CANCELED, System.currentTimeMillis()), firstAction); + controllerManagement + .addCancelActionStatus(new ActionStatus(firstAction, Status.CANCELED, System.currentTimeMillis())); assertThat(actionStatusRepository.findAll()).as("wrong size of action status").hasSize(6); assertThat(targetManagement.findTargetByControllerID("4712").getAssignedDistributionSet()) .as("wrong assigned ds").isEqualTo(dsInstalled); @@ -256,8 +257,8 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { // confirm cancellation firstAction = deploymentManagement.findActionWithDetails(firstAction.getId()); firstAction.setStatus(Status.CANCELED); - controllerManagement.addCancelActionStatus( - new ActionStatus(firstAction, Status.CANCELED, System.currentTimeMillis()), firstAction); + controllerManagement + .addCancelActionStatus(new ActionStatus(firstAction, Status.CANCELED, System.currentTimeMillis())); assertThat(actionStatusRepository.findAll()).as("wrong size of action status").hasSize(4); assertThat(targetManagement.findTargetByControllerID("4712").getAssignedDistributionSet()) .as("wrong assigned ds").isEqualTo(dsSecond); @@ -273,8 +274,8 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { .as("wrong assigned ds").isEqualTo(dsSecond); // confirm cancellation secondAction.setStatus(Status.CANCELED); - controllerManagement.addCancelActionStatus( - new ActionStatus(secondAction, Status.CANCELED, System.currentTimeMillis()), secondAction); + controllerManagement + .addCancelActionStatus(new ActionStatus(secondAction, Status.CANCELED, System.currentTimeMillis())); // cancelled success -> back to dsInstalled assertThat(targetManagement.findTargetByControllerID("4712").getAssignedDistributionSet()) .as("wrong installed ds").isEqualTo(dsInstalled); @@ -742,7 +743,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { for (final String msg : msgs) { statusMessages.addMessage(msg); } - controllerManagament.addUpdateActionStatus(statusMessages, updActA); + controllerManagament.addUpdateActionStatus(statusMessages); return targetManagement.findTargetByControllerID(t.getControllerId()); } @@ -786,7 +787,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { final Action action = updAct.getContent().get(0); action.setStatus(Status.FINISHED); final ActionStatus statusMessage = new ActionStatus(action, Status.FINISHED, System.currentTimeMillis(), ""); - controllerManagament.addUpdateActionStatus(statusMessage, action); + controllerManagament.addUpdateActionStatus(statusMessage); targ = targetManagement.findTargetByControllerID(targ.getControllerId()); diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DistributionSetManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DistributionSetManagementTest.java index db9618425..8faae175e 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DistributionSetManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DistributionSetManagementTest.java @@ -821,7 +821,7 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest { for (final String msg : msgs) { statusMessages.addMessage(msg); } - controllerManagament.addUpdateActionStatus(statusMessages, updActA); + controllerManagament.addUpdateActionStatus(statusMessages); return targetManagement.findTargetByControllerID(t.getControllerId()); } diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ReportManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ReportManagementTest.java index 0184a9d26..e41491962 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ReportManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ReportManagementTest.java @@ -558,7 +558,7 @@ public class ReportManagementTest extends AbstractIntegrationTest { for (final String msg : msgs) { statusMessages.addMessage(msg); } - controllerManagament.addUpdateActionStatus(statusMessages, updActA); + controllerManagament.addUpdateActionStatus(statusMessages); return targetManagement.findTargetByControllerID(t.getControllerId()); } diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/RolloutManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/RolloutManagementTest.java index 22f9ee8b4..88bb26616 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/RolloutManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/RolloutManagementTest.java @@ -18,6 +18,7 @@ import java.util.concurrent.Callable; import org.eclipse.hawkbit.AbstractIntegrationTest; import org.eclipse.hawkbit.TestDataUtil; +import org.eclipse.hawkbit.repository.jpa.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; @@ -136,8 +137,8 @@ public class RolloutManagementTest extends AbstractIntegrationTest { // 50% final Action action = runningActions.get(0); action.setStatus(Status.FINISHED); - controllerManagament.addUpdateActionStatus( - new ActionStatus(action, Status.FINISHED, System.currentTimeMillis(), ""), action); + controllerManagament + .addUpdateActionStatus(new ActionStatus(action, Status.FINISHED, System.currentTimeMillis(), "")); // check running rollouts again, now the finish condition should be hit // and should start the next group @@ -178,8 +179,8 @@ public class RolloutManagementTest extends AbstractIntegrationTest { // finish actions with error for (final Action action : runningActions) { action.setStatus(Status.ERROR); - controllerManagament.addUpdateActionStatus( - new ActionStatus(action, Status.ERROR, System.currentTimeMillis(), ""), action); + controllerManagament + .addUpdateActionStatus(new ActionStatus(action, Status.ERROR, System.currentTimeMillis(), "")); } // check running rollouts again, now the error condition should be hit @@ -220,8 +221,8 @@ public class RolloutManagementTest extends AbstractIntegrationTest { // finish actions with error for (final Action action : runningActions) { action.setStatus(Status.ERROR); - controllerManagament.addUpdateActionStatus( - new ActionStatus(action, Status.ERROR, System.currentTimeMillis(), ""), action); + controllerManagament + .addUpdateActionStatus(new ActionStatus(action, Status.ERROR, System.currentTimeMillis(), "")); } // check running rollouts again, now the error condition should be hit @@ -977,8 +978,8 @@ public class RolloutManagementTest extends AbstractIntegrationTest { final List runningActions = deploymentManagement.findActionsByRolloutAndStatus(rollout, Status.RUNNING); for (final Action action : runningActions) { action.setStatus(status); - controllerManagament.addUpdateActionStatus(new ActionStatus(action, status, System.currentTimeMillis(), ""), - action); + controllerManagament + .addUpdateActionStatus(new ActionStatus(action, status, System.currentTimeMillis(), "")); } return runningActions.size(); } @@ -989,14 +990,13 @@ public class RolloutManagementTest extends AbstractIntegrationTest { assertThat(runningActions.size()).isGreaterThanOrEqualTo(amountOfTargetsToGetChanged); for (int i = 0; i < amountOfTargetsToGetChanged; i++) { controllerManagament.addUpdateActionStatus( - new ActionStatus(runningActions.get(i), status, System.currentTimeMillis(), ""), - runningActions.get(i)); + new ActionStatus(runningActions.get(i), status, System.currentTimeMillis(), "")); } return runningActions.size(); } private Map createInitStatusMap() { - final Map map = new HashMap(); + final Map map = new HashMap<>(); for (final TotalTargetCountStatus.Status status : TotalTargetCountStatus.Status.values()) { map.put(status, 0L); } diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TagManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TagManagementTest.java index 4c6af0d83..3deba1a56 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TagManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TagManagementTest.java @@ -21,6 +21,7 @@ import org.eclipse.hawkbit.AbstractIntegrationTest; import org.eclipse.hawkbit.TestDataUtil; import org.eclipse.hawkbit.repository.DistributionSetFilter.DistributionSetFilterBuilder; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; +import org.eclipse.hawkbit.repository.jpa.TagManagement; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult; diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagenmentTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagenmentTest.java index 99e08f331..37d4ea683 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagenmentTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagenmentTest.java @@ -13,6 +13,7 @@ import static org.junit.Assert.fail; import org.eclipse.hawkbit.AbstractIntegrationTest; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; +import org.eclipse.hawkbit.repository.jpa.TargetFilterQueryManagement; import org.eclipse.hawkbit.repository.model.TargetFilterQuery; import org.junit.Test; diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetManagementSearchTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetManagementSearchTest.java index 73d549eb7..6b509b257 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetManagementSearchTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetManagementSearchTest.java @@ -96,7 +96,7 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest { final Action action = deploymentManagement.findActionWithDetails(actionId); action.setStatus(Status.FINISHED); controllerManagament.addUpdateActionStatus( - new ActionStatus(action, Status.FINISHED, System.currentTimeMillis(), "message"), action); + new ActionStatus(action, Status.FINISHED, System.currentTimeMillis(), "message")); deploymentManagement.assignDistributionSet(setA.getId(), installedC); final List unknown = new ArrayList<>(); @@ -745,7 +745,7 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest { final Action action = deploymentManagement.findActionWithDetails(actionId); action.setStatus(Status.FINISHED); controllerManagament.addUpdateActionStatus( - new ActionStatus(action, Status.FINISHED, System.currentTimeMillis(), "message"), action); + new ActionStatus(action, Status.FINISHED, System.currentTimeMillis(), "message")); }); deploymentManagement.assignDistributionSet(assignedSet, assignedtargets); @@ -773,7 +773,7 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest { final Action action = deploymentManagement.findActionWithDetails(actionId); action.setStatus(Status.FINISHED); controllerManagament.addUpdateActionStatus( - new ActionStatus(action, Status.FINISHED, System.currentTimeMillis(), "message"), action); + new ActionStatus(action, Status.FINISHED, System.currentTimeMillis(), "message")); }); deploymentManagement.assignDistributionSet(assignedSet, installedtargets); @@ -802,7 +802,7 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest { final Action action = deploymentManagement.findActionWithDetails(actionId); action.setStatus(Status.FINISHED); controllerManagament.addUpdateActionStatus( - new ActionStatus(action, Status.FINISHED, System.currentTimeMillis(), "message"), action); + new ActionStatus(action, Status.FINISHED, System.currentTimeMillis(), "message")); }); deploymentManagement.assignDistributionSet(assignedSet, installedtargets); @@ -840,7 +840,7 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest { for (final String msg : msgs) { statusMessages.addMessage(msg); } - controllerManagament.addUpdateActionStatus(statusMessages, updActA); + controllerManagament.addUpdateActionStatus(statusMessages); return targetManagement.findTargetByControllerID(t.getControllerId()); } diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetManagementTest.java index a223c25b4..ae4447fc6 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetManagementTest.java @@ -187,7 +187,7 @@ public class TargetManagementTest extends AbstractIntegrationTest { final Action action = deploymentManagement.findActionWithDetails(result.getActions().get(0)); action.setStatus(Status.FINISHED); controllerManagament.addUpdateActionStatus( - new ActionStatus(action, Status.FINISHED, System.currentTimeMillis(), "message"), action); + new ActionStatus(action, Status.FINISHED, System.currentTimeMillis(), "message")); deploymentManagement.assignDistributionSet(set2.getId(), "4711"); target = targetManagement.findTargetByControllerIDWithDetails("4711"); diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLRolloutGroupFields.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLRolloutGroupFields.java index 78d333826..18da430c7 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLRolloutGroupFields.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLRolloutGroupFields.java @@ -75,7 +75,7 @@ public class RSQLRolloutGroupFields extends AbstractIntegrationTest { } private void assertRSQLQuery(final String rsqlParam, final long expcetedTargets) { - final Page findTargetPage = rolloutGroupManagement.findRolloutGroupsByPredicate(rollout, + final Page findTargetPage = rolloutGroupManagement.findRolloutGroupsAll(rollout, RSQLUtility.parse(rsqlParam, RolloutGroupFields.class), new PageRequest(0, 100)); final long countTargetsAll = findTargetPage.getTotalElements(); assertThat(findTargetPage).isNotNull(); diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/utils/RepositoryDataGenerator.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/utils/RepositoryDataGenerator.java index a1c74e791..e2e86bed1 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/utils/RepositoryDataGenerator.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/utils/RepositoryDataGenerator.java @@ -30,9 +30,9 @@ import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.DistributionSetAssignmentResult; import org.eclipse.hawkbit.repository.DistributionSetManagement; -import org.eclipse.hawkbit.repository.SoftwareManagement; -import org.eclipse.hawkbit.repository.TagManagement; -import org.eclipse.hawkbit.repository.TargetManagement; +import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; +import org.eclipse.hawkbit.repository.jpa.TagManagement; +import org.eclipse.hawkbit.repository.jpa.TargetManagement; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; @@ -207,14 +207,14 @@ public final class RepositoryDataGenerator { download.setAction(action); download.setStatus(Status.DOWNLOAD); download.addMessage("Controller started download."); - action = controllerManagement.addUpdateActionStatus(download, action); + action = controllerManagement.addUpdateActionStatus(download); // warning final ActionStatus warning = new ActionStatus(); warning.setAction(action); warning.setStatus(Status.WARNING); warning.addMessage("Some warning: " + jlorem.words(new Random().nextInt(50))); - action = controllerManagement.addUpdateActionStatus(warning, action); + action = controllerManagement.addUpdateActionStatus(warning); // garbage for (int i = 0; i < new Random().nextInt(10); i++) { @@ -222,13 +222,13 @@ public final class RepositoryDataGenerator { running.setAction(action); running.setStatus(Status.RUNNING); running.addMessage("Still running: " + jlorem.words(new Random().nextInt(50))); - action = controllerManagement.addUpdateActionStatus(running, action); + action = controllerManagement.addUpdateActionStatus(running); for (int g = 0; g < new Random().nextInt(5); g++) { final ActionStatus rand = new ActionStatus(); rand.setAction(action); rand.setStatus(Status.RUNNING); rand.addMessage(jlorem.words(new Random().nextInt(50))); - action = controllerManagement.addUpdateActionStatus(rand, action); + action = controllerManagement.addUpdateActionStatus(rand); } } @@ -241,13 +241,13 @@ public final class RepositoryDataGenerator { if (incrementAndGet % 5 == 0) { close.setStatus(Status.ERROR); close.addMessage("Controller reported CLOSED with ERROR!"); - action = controllerManagement.addUpdateActionStatus(close, action); + action = controllerManagement.addUpdateActionStatus(close); } // with OK else { close.setStatus(Status.FINISHED); close.addMessage("Controller reported CLOSED with OK!"); - action = controllerManagement.addUpdateActionStatus(close, action); + action = controllerManagement.addUpdateActionStatus(close); } index++; @@ -266,7 +266,7 @@ public final class RepositoryDataGenerator { close.setAction(action); close.setStatus(Status.FINISHED); close.addMessage("Controller reported CLOSED with OK!"); - action = controllerManagement.addUpdateActionStatus(close, action); + action = controllerManagement.addUpdateActionStatus(close); } } @@ -339,8 +339,8 @@ public final class RepositoryDataGenerator { // garbage DS LOG.debug("initDemoRepo - start now DS garbage"); - TestDataUtil.generateDistributionSets("Generic Software Package", sizeMultiplikator, - softwareManagement, distributionSetManagement); + TestDataUtil.generateDistributionSets("Generic Software Package", sizeMultiplikator, softwareManagement, + distributionSetManagement); LOG.debug("initDemoRepo - DS garbage finished"); LOG.debug("initDemoRepo - start now Extra Software Modules and types"); diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/ArtifactStoreController.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/ArtifactStoreController.java index a36443024..d6e057edd 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/ArtifactStoreController.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/ArtifactStoreController.java @@ -149,7 +149,7 @@ public class ArtifactStoreController { actionStatus.addMessage( ControllerManagement.SERVER_MESSAGE_PREFIX + "Target downloads: " + request.getRequestURI()); } - controllerManagement.addActionStatusMessage(actionStatus); + controllerManagement.addInformationalActionStatus(actionStatus); return action; } diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/RootController.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/RootController.java index 14383f30b..9dfcbae55 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/RootController.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/RootController.java @@ -30,8 +30,8 @@ import org.eclipse.hawkbit.controller.model.DeploymentBase; import org.eclipse.hawkbit.controller.model.Result.FinalResult; import org.eclipse.hawkbit.repository.ArtifactManagement; import org.eclipse.hawkbit.repository.ControllerManagement; -import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; +import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; @@ -150,7 +150,7 @@ public class RootController { return new ResponseEntity<>( DataConversionHelper.fromTarget(target, controllerManagement.findActionByTargetAndActive(target), - controllerManagement.findPollingTime(), tenantAware), + controllerManagement.getPollingTime(), tenantAware), HttpStatus.OK); } @@ -222,7 +222,7 @@ public class RootController { statusMessage.addMessage( ControllerManagement.SERVER_MESSAGE_PREFIX + "Target downloads " + request.getRequestURI()); } - controllerManagement.addActionStatusMessage(statusMessage); + controllerManagement.addInformationalActionStatus(statusMessage); return action; } @@ -371,8 +371,7 @@ public class RootController { return new ResponseEntity<>(HttpStatus.GONE); } - controllerManagement.addUpdateActionStatus(generateUpdateStatus(feedback, targetid, feedback.getId(), action), - action); + controllerManagement.addUpdateActionStatus(generateUpdateStatus(feedback, targetid, feedback.getId(), action)); return new ResponseEntity<>(HttpStatus.OK); @@ -546,7 +545,7 @@ public class RootController { } controllerManagement - .addCancelActionStatus(generateActionCancelStatus(feedback, target, feedback.getId(), action), action); + .addCancelActionStatus(generateActionCancelStatus(feedback, target, feedback.getId(), action)); return new ResponseEntity<>(HttpStatus.OK); } diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetMapper.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetMapper.java index 8051146a1..95e3f0c8d 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetMapper.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetMapper.java @@ -16,8 +16,8 @@ import java.util.List; import org.eclipse.hawkbit.repository.DistributionSetAssignmentResult; import org.eclipse.hawkbit.repository.DistributionSetManagement; -import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; +import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetMetadata; import org.eclipse.hawkbit.repository.model.DistributionSetType; diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetResource.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetResource.java index 27231308b..9e9dc2369 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetResource.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetResource.java @@ -18,12 +18,12 @@ import org.eclipse.hawkbit.repository.DistributionSetAssignmentResult; import org.eclipse.hawkbit.repository.DistributionSetFields; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.DistributionSetMetadataFields; -import org.eclipse.hawkbit.repository.SoftwareManagement; -import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.repository.TargetFields; -import org.eclipse.hawkbit.repository.TargetManagement; -import org.eclipse.hawkbit.repository.TargetWithActionType; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; +import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; +import org.eclipse.hawkbit.repository.jpa.SystemManagement; +import org.eclipse.hawkbit.repository.jpa.TargetManagement; +import org.eclipse.hawkbit.repository.jpa.TargetWithActionType; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetMetadata; import org.eclipse.hawkbit.repository.model.DsMetadataCompositeKey; diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTagResource.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTagResource.java index eaa0fec28..e630003c5 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTagResource.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTagResource.java @@ -13,8 +13,8 @@ import java.util.stream.Collectors; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.TagFields; -import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; +import org.eclipse.hawkbit.repository.jpa.TagManagement; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult; diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTypeMapper.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTypeMapper.java index 409caf01d..fbe22af5c 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTypeMapper.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTypeMapper.java @@ -14,8 +14,8 @@ import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn; import java.util.ArrayList; import java.util.List; -import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; +import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.rest.resource.api.DistributionSetTypeRestApi; diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTypeResource.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTypeResource.java index f7346a6ff..32e87e05e 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTypeResource.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTypeResource.java @@ -12,8 +12,8 @@ import java.util.List; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.DistributionSetTypeFields; -import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; +import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.SoftwareModule; @@ -69,7 +69,7 @@ public class DistributionSetTypeResource implements DistributionSetTypeRestApi { final Slice findModuleTypessAll; Long countModulesAll; if (rsqlParam != null) { - findModuleTypessAll = distributionSetManagement.findDistributionSetTypesByPredicate( + findModuleTypessAll = distributionSetManagement.findDistributionSetTypesAll( RSQLUtility.parse(rsqlParam, DistributionSetTypeFields.class), pageable); countModulesAll = ((Page) findModuleTypessAll).getTotalElements(); } else { diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DownloadArtifactResource.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DownloadArtifactResource.java index 00f8f4756..5c057acd4 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DownloadArtifactResource.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DownloadArtifactResource.java @@ -13,8 +13,8 @@ import javax.servlet.http.HttpServletResponse; import org.eclipse.hawkbit.artifact.repository.model.DbArtifact; import org.eclipse.hawkbit.repository.ArtifactManagement; -import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; +import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.rest.resource.helper.RestResourceConversionHelper; diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/RolloutResource.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/RolloutResource.java index 78cfefa0d..d8821f113 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/RolloutResource.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/RolloutResource.java @@ -178,7 +178,7 @@ public class RolloutResource implements RolloutRestApi { final Page findRolloutGroupsAll; if (rsqlParam != null) { - findRolloutGroupsAll = this.rolloutGroupManagement.findRolloutGroupsByPredicate(rollout, + findRolloutGroupsAll = this.rolloutGroupManagement.findRolloutGroupsAll(rollout, RSQLUtility.parse(rsqlParam, RolloutGroupFields.class), pageable); } else { findRolloutGroupsAll = this.rolloutGroupManagement.findRolloutGroupsByRolloutId(rolloutId, pageable); diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleMapper.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleMapper.java index 01dfae9cd..8732cc1d1 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleMapper.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleMapper.java @@ -14,8 +14,8 @@ import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn; import java.util.ArrayList; import java.util.List; -import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; +import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleResource.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleResource.java index 830443cbd..0d7a4b8f0 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleResource.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleResource.java @@ -12,10 +12,10 @@ import java.io.IOException; import java.util.List; import org.eclipse.hawkbit.repository.ArtifactManagement; -import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.SoftwareModuleFields; import org.eclipse.hawkbit.repository.SoftwareModuleMetadataFields; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; +import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata; diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleTypeResource.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleTypeResource.java index e3498f141..df042d38c 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleTypeResource.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleTypeResource.java @@ -10,9 +10,9 @@ package org.eclipse.hawkbit.rest.resource; import java.util.List; -import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.SoftwareModuleTypeFields; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; +import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SystemManagementResource.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SystemManagementResource.java index 27cfdb924..c5663f9f5 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SystemManagementResource.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SystemManagementResource.java @@ -16,8 +16,8 @@ import java.util.stream.Collectors; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; import org.eclipse.hawkbit.report.model.SystemUsageReport; import org.eclipse.hawkbit.report.model.TenantUsage; -import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; +import org.eclipse.hawkbit.repository.jpa.SystemManagement; import org.eclipse.hawkbit.rest.resource.model.systemmanagement.CacheRest; import org.eclipse.hawkbit.rest.resource.model.systemmanagement.SystemStatisticsRest; import org.eclipse.hawkbit.rest.resource.model.systemmanagement.TenantSystemUsageRest; diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/TargetResource.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/TargetResource.java index 4b068a41e..df779c688 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/TargetResource.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/TargetResource.java @@ -19,8 +19,8 @@ import org.eclipse.hawkbit.repository.ActionFields; import org.eclipse.hawkbit.repository.ActionStatusFields; import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.TargetFields; -import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; +import org.eclipse.hawkbit.repository.jpa.TargetManagement; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.ActionType; import org.eclipse.hawkbit.repository.model.ActionStatus; diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/TargetTagResource.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/TargetTagResource.java index 1a9155828..b6946145d 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/TargetTagResource.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/TargetTagResource.java @@ -12,9 +12,9 @@ import java.util.List; import java.util.stream.Collectors; import org.eclipse.hawkbit.repository.TagFields; -import org.eclipse.hawkbit.repository.TagManagement; -import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; +import org.eclipse.hawkbit.repository.jpa.TagManagement; +import org.eclipse.hawkbit.repository.jpa.TargetManagement; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetTag; import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult; diff --git a/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/DistributionSetResourceTest.java b/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/DistributionSetResourceTest.java index 6254da992..9d823e832 100644 --- a/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/DistributionSetResourceTest.java +++ b/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/DistributionSetResourceTest.java @@ -30,12 +30,12 @@ import org.eclipse.hawkbit.AbstractIntegrationTest; import org.eclipse.hawkbit.MockMvcResultPrinter; import org.eclipse.hawkbit.TestDataUtil; import org.eclipse.hawkbit.WithUser; -import org.eclipse.hawkbit.repository.ActionRepository; import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement; -import org.eclipse.hawkbit.repository.SoftwareManagement; -import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; +import org.eclipse.hawkbit.repository.jpa.ActionRepository; +import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; +import org.eclipse.hawkbit.repository.jpa.TargetManagement; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; @@ -890,7 +890,7 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest { for (final String msg : msgs) { statusMessages.addMessage(msg); } - controllerManagament.addUpdateActionStatus(statusMessages, updActA); + controllerManagament.addUpdateActionStatus(statusMessages); return targetManagement.findTargetByControllerID(t.getControllerId()); } diff --git a/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/TargetResourceTest.java b/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/TargetResourceTest.java index 8d27d5114..2d3a9707e 100644 --- a/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/TargetResourceTest.java +++ b/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/TargetResourceTest.java @@ -108,8 +108,7 @@ public class TargetResourceTest extends AbstractIntegrationTest { final List actions = generateTargetWithTwoUpdatesWithOneOverride(knownTargetId); actions.get(0).setStatus(Status.FINISHED); controllerManagament.addUpdateActionStatus( - new ActionStatus(actions.get(0), Status.FINISHED, System.currentTimeMillis(), "testmessage"), - actions.get(0)); + new ActionStatus(actions.get(0), Status.FINISHED, System.currentTimeMillis(), "testmessage")); final PageRequest pageRequest = new PageRequest(0, 1000, Direction.ASC, ActionFields.ID.getFieldName()); final ActionStatus status = deploymentManagement @@ -1284,8 +1283,8 @@ public class TargetResourceTest extends AbstractIntegrationTest { final Pageable pageReq = new PageRequest(0, 100); final Action action = actionRepository.findByDistributionSet(pageReq, savedSet).getContent().get(0); - final ActionStatus actionStatus = new ActionStatus(action, Status.FINISHED, 0l); - controllerManagement.addUpdateActionStatus(actionStatus, action); + final ActionStatus actionStatus = new ActionStatus(action, Status.FINISHED, 0L); + controllerManagement.addUpdateActionStatus(actionStatus); } /** diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/details/ArtifactBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/details/ArtifactBeanQuery.java index 2fa3763fd..5e7c0f3c7 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/details/ArtifactBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/details/ArtifactBeanQuery.java @@ -12,7 +12,7 @@ import java.util.List; import java.util.Map; import org.eclipse.hawkbit.repository.ArtifactManagement; -import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; +import org.eclipse.hawkbit.repository.jpa.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/footer/UploadViewConfirmationWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/footer/UploadViewConfirmationWindowLayout.java index e6284d5d6..364b659da 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/footer/UploadViewConfirmationWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/footer/UploadViewConfirmationWindowLayout.java @@ -14,7 +14,7 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.eclipse.hawkbit.repository.SoftwareManagement; +import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; import org.eclipse.hawkbit.ui.artifacts.event.UploadArtifactUIEvent; import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState; import org.eclipse.hawkbit.ui.artifacts.state.CustomFile; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/BaseSwModuleBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/BaseSwModuleBeanQuery.java index 29bea30eb..d1d034555 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/BaseSwModuleBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/BaseSwModuleBeanQuery.java @@ -12,8 +12,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; -import org.eclipse.hawkbit.repository.SoftwareManagement; +import org.eclipse.hawkbit.repository.jpa.OffsetBasedPageRequest; +import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.ui.common.UserDetailsFormatter; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleAddUpdateWindow.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleAddUpdateWindow.java index 1e4029087..6a033bfd8 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleAddUpdateWindow.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleAddUpdateWindow.java @@ -10,7 +10,7 @@ package org.eclipse.hawkbit.ui.artifacts.smtable; import java.io.Serializable; -import org.eclipse.hawkbit.repository.SoftwareManagement; +import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; import org.eclipse.hawkbit.ui.common.SoftwareModuleTypeBeanQuery; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java index 478438891..4fea3df08 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java @@ -12,7 +12,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.eclipse.hawkbit.repository.SoftwareManagement; +import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.ui.artifacts.event.SMFilterEvent; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/CreateUpdateSoftwareTypeLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/CreateUpdateSoftwareTypeLayout.java index f2e43c1fb..4039a2be2 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/CreateUpdateSoftwareTypeLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/CreateUpdateSoftwareTypeLayout.java @@ -13,8 +13,8 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.SpPermissionChecker; +import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleTypeEvent; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleTypeEvent.SoftwareModuleTypeEnum; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/SMTypeFilterButtonClick.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/SMTypeFilterButtonClick.java index 4a4006c2a..4727ecae7 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/SMTypeFilterButtonClick.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/SMTypeFilterButtonClick.java @@ -10,7 +10,7 @@ package org.eclipse.hawkbit.ui.artifacts.smtype; import java.io.Serializable; -import org.eclipse.hawkbit.repository.SoftwareManagement; +import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.ui.artifacts.event.SMFilterEvent; import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/DistributionSetTypeBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/DistributionSetTypeBeanQuery.java index b09255bc7..b8f5435dd 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/DistributionSetTypeBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/DistributionSetTypeBeanQuery.java @@ -13,7 +13,7 @@ import java.util.List; import java.util.Map; import org.eclipse.hawkbit.repository.DistributionSetManagement; -import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; +import org.eclipse.hawkbit.repository.jpa.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SpringContextHelper; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/SoftwareModuleTypeBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/SoftwareModuleTypeBeanQuery.java index 6fd382084..f8d6dba66 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/SoftwareModuleTypeBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/SoftwareModuleTypeBeanQuery.java @@ -11,8 +11,8 @@ package org.eclipse.hawkbit.ui.common; import java.util.List; import java.util.Map; -import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; -import org.eclipse.hawkbit.repository.SoftwareManagement; +import org.eclipse.hawkbit.repository.jpa.OffsetBasedPageRequest; +import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SpringContextHelper; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTargetTagToken.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTargetTagToken.java index ce9f101f3..1e3ab9b03 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTargetTagToken.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTargetTagToken.java @@ -10,7 +10,7 @@ package org.eclipse.hawkbit.ui.common.tagdetails; import org.eclipse.hawkbit.eventbus.event.TargetTagCreatedBulkEvent; import org.eclipse.hawkbit.eventbus.event.TargetTagDeletedEvent; -import org.eclipse.hawkbit.repository.TagManagement; +import org.eclipse.hawkbit.repository.jpa.TagManagement; import org.eclipse.hawkbit.repository.model.BaseEntity; import org.eclipse.hawkbit.repository.model.TargetTag; import org.springframework.beans.factory.annotation.Autowired; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/DistributionTagToken.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/DistributionTagToken.java index 178610c23..bc46f50fd 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/DistributionTagToken.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/DistributionTagToken.java @@ -19,7 +19,7 @@ import org.eclipse.hawkbit.eventbus.event.DistributionSetTagCreatedBulkEvent; import org.eclipse.hawkbit.eventbus.event.DistributionSetTagDeletedEvent; import org.eclipse.hawkbit.eventbus.event.DistributionSetTagUpdateEvent; import org.eclipse.hawkbit.repository.DistributionSetManagement; -import org.eclipse.hawkbit.repository.TagManagement; +import org.eclipse.hawkbit.repository.jpa.TagManagement; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/TargetTagToken.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/TargetTagToken.java index 6f03c5860..e607c99d2 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/TargetTagToken.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/TargetTagToken.java @@ -16,7 +16,7 @@ import java.util.stream.Collectors; import org.eclipse.hawkbit.eventbus.event.TargetTagAssigmentResultEvent; import org.eclipse.hawkbit.eventbus.event.TargetTagUpdateEvent; -import org.eclipse.hawkbit.repository.TargetManagement; +import org.eclipse.hawkbit.repository.jpa.TargetManagement; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetTag; import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/CreateUpdateDistSetTypeLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/CreateUpdateDistSetTypeLayout.java index 64a06bd38..0e3ed8da3 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/CreateUpdateDistSetTypeLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/CreateUpdateDistSetTypeLayout.java @@ -14,9 +14,9 @@ import java.util.List; import java.util.Set; import org.eclipse.hawkbit.repository.DistributionSetManagement; -import org.eclipse.hawkbit.repository.DistributionSetRepository; -import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.SpPermissionChecker; +import org.eclipse.hawkbit.repository.jpa.DistributionSetRepository; +import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.ui.common.CoordinatesToColor; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetDetails.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetDetails.java index a1d1ffcfe..32bb0ce86 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetDetails.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetDetails.java @@ -14,7 +14,7 @@ import java.util.Map; import java.util.Set; import org.eclipse.hawkbit.repository.DistributionSetManagement; -import org.eclipse.hawkbit.repository.SoftwareManagement; +import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetIdName; import org.eclipse.hawkbit.repository.model.SoftwareModule; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java index 01c242247..ca469c967 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java @@ -18,10 +18,9 @@ import java.util.Map.Entry; import java.util.Set; import org.eclipse.hawkbit.repository.DistributionSetManagement; -import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.SpPermissionChecker; -import org.eclipse.hawkbit.repository.TargetManagement; -import org.eclipse.hawkbit.repository.exception.EntityLockedException; +import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; +import org.eclipse.hawkbit.repository.jpa.TargetManagement; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetIdName; import org.eclipse.hawkbit.repository.model.SoftwareModule; @@ -322,11 +321,11 @@ public class DistributionSetTable extends AbstractNamedVersionTable Date: Mon, 16 May 2016 14:56:23 +0530 Subject: [PATCH 06/54] Artifact upload : on discard action interupt the ongoing upload Signed-off-by: Asharani --- .../event/UploadArtifactUIEvent.java | 3 +- .../artifacts/state/ArtifactUploadState.java | 6 + .../upload/UploadConfirmationwindow.java | 6 +- .../ui/artifacts/upload/UploadHandler.java | 43 +++++- .../ui/artifacts/upload/UploadLayout.java | 138 +++++++++++++----- .../artifacts/upload/UploadResultWindow.java | 9 ++ .../upload/UploadStatusInfoWindow.java | 11 +- .../themes/hawkbit/customstyles/others.scss | 11 +- 8 files changed, 171 insertions(+), 56 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadArtifactUIEvent.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadArtifactUIEvent.java index 8bd33f483..1f5971f4b 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadArtifactUIEvent.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadArtifactUIEvent.java @@ -15,6 +15,5 @@ package org.eclipse.hawkbit.ui.artifacts.event; * */ public enum UploadArtifactUIEvent { - - SHOW_DROP_HINTS, HIDE_DROP_HINTS, SOFTWARE_DRAG_START, SOFTWARE_TYPE_DRAG_START, UPDATE_UPLOAD_COUNT, ENABLE_PROCESS_BUTTON, HIDE_FILTER_BY_TYPE, SHOW_FILTER_BY_TYPE, DISCARD_DELETE_SOFTWARE, DISCARD_ALL_DELETE_SOFTWARE, DELETED_ALL_SOFWARE, DISABLE_PROCESS_BUTTON, DISCARD_DELETE_SOFTWARE_TYPE, DISCARD_ALL_DELETE_SOFTWARE_TYPE, DELETED_ALL_SOFWARE_TYPE,MINIMIZED_STATUS_POPUP,MAXIMIZED_STATUS_POPUP, UPLOAD_IN_PROGESS + SHOW_DROP_HINTS, HIDE_DROP_HINTS, SOFTWARE_DRAG_START, SOFTWARE_TYPE_DRAG_START, UPDATE_UPLOAD_COUNT, HIDE_FILTER_BY_TYPE, SHOW_FILTER_BY_TYPE, DISCARD_DELETE_SOFTWARE, DISCARD_ALL_DELETE_SOFTWARE, DELETED_ALL_SOFWARE, DISCARD_DELETE_SOFTWARE_TYPE, DISCARD_ALL_DELETE_SOFTWARE_TYPE, DELETED_ALL_SOFWARE_TYPE, MINIMIZED_STATUS_POPUP, MAXIMIZED_STATUS_POPUP, UPLOAD_IN_PROGESS, DISCARD_UPLOAD, ARTIFACT_RESULT_POPUP_CLOSED } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/state/ArtifactUploadState.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/state/ArtifactUploadState.java index 9c0ade8d1..5399e59c8 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/state/ArtifactUploadState.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/state/ArtifactUploadState.java @@ -73,6 +73,12 @@ public class ArtifactUploadState implements ManagmentEntityState, Serializ private final AtomicInteger numberOfFilesActuallyUpload = new AtomicInteger(); + private final AtomicInteger numberOfFileUploadsFailed = new AtomicInteger(); + + public AtomicInteger getNumberOfFileUploadsFailed() { + return numberOfFileUploadsFailed; + } + public AtomicInteger getNumberOfFilesActuallyUpload() { return numberOfFilesActuallyUpload; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadConfirmationwindow.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadConfirmationwindow.java index d7231cafe..83a5c6c95 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadConfirmationwindow.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadConfirmationwindow.java @@ -544,7 +544,7 @@ public class UploadConfirmationwindow implements Button.ClickListener { if (event.getComponent().getId().equals(SPUIComponetIdProvider.UPLOAD_ARTIFACT_DETAILS_CLOSE)) { uploadConfrimationWindow.close(); } else if (event.getComponent().getId().equals(SPUIComponetIdProvider.UPLOAD_DISCARD_DETAILS_BUTTON)) { - uploadLayout.removeUploadedFileDetails(); + uploadLayout.clearUploadedFileDetails(); uploadConfrimationWindow.close(); } else if (event.getComponent().getId().equals(SPUIComponetIdProvider.UPLOAD_BUTTON)) { processArtifactUpload(); @@ -568,10 +568,10 @@ public class UploadConfirmationwindow implements Button.ClickListener { uploadDetailsTable.removeItem(((Button) event.getComponent()).getData()); uploadLayout.getFileSelected().remove(customFile); - uploadLayout.updateActionCount(); + uploadLayout.updateUploadCounts(); if (uploadDetailsTable.getItemIds().isEmpty()) { - uploadLayout.clearFileList(); uploadConfrimationWindow.close(); + uploadLayout.clearUploadedFileDetails(); } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java index f9d207193..2c8220fdf 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java @@ -11,6 +11,8 @@ package org.eclipse.hawkbit.ui.artifacts.upload; import java.io.IOException; import java.io.OutputStream; +import javax.annotation.PreDestroy; + import org.eclipse.hawkbit.repository.exception.ArtifactUploadFailedException; import org.eclipse.hawkbit.ui.artifacts.event.UploadArtifactUIEvent; import org.eclipse.hawkbit.ui.artifacts.event.UploadFileStatus; @@ -21,8 +23,11 @@ import org.eclipse.hawkbit.ui.utils.SpringContextHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.vaadin.spring.events.EventBus; +import org.vaadin.spring.events.EventScope; +import org.vaadin.spring.events.annotation.EventBusListenerMethod; import com.vaadin.server.StreamVariable; +import com.vaadin.ui.UI; import com.vaadin.ui.Upload; import com.vaadin.ui.Upload.FailedEvent; import com.vaadin.ui.Upload.FailedListener; @@ -83,6 +88,24 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene this.mimeType = mimeType; this.i18n = SpringContextHelper.getBean(I18N.class); this.eventBus = SpringContextHelper.getBean(EventBus.SessionEventBus.class); + eventBus.subscribe(this); + } + + @EventBusListenerMethod(scope = EventScope.SESSION) + void onEvent(final UploadArtifactUIEvent event) { + if (event == UploadArtifactUIEvent.DISCARD_UPLOAD) { + UI.getCurrent().access(() ->intreruptUploadOnDiscard()); + } + } + +// + @PreDestroy + void destroy() { + /* + * It's good manners to do this, even though vaadin-spring will + * automatically unsubscribe when this UI is garbage collected. + */ + eventBus.unsubscribe(this); } /** @@ -93,6 +116,7 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene @Override public final OutputStream getOutputStream() { try { + streamingInterrupted = false; return view.saveUploadedFileDetails(fileName, fileSize, mimeType); } catch (final ArtifactUploadFailedException e) { LOG.error("Atifact upload failed {} ", e); @@ -110,18 +134,15 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene */ @Override public OutputStream receiveUpload(final String fileName, final String mimeType) { + uploadInterrupted = false; this.fileName = fileName; this.mimeType = mimeType; // reset has directory flag before upload view.setHasDirectory(false); try { - if (view.checkIfSoftwareModuleIsSelected()) { - if (view.checkForDuplicate(fileName)) { - view.showDuplicateMessage(); - } else { - view.increaseNumberOfFileUploadsExpected(); - return view.saveUploadedFileDetails(fileName, 0, mimeType); - } + if (view.checkIfSoftwareModuleIsSelected() && !view.checkForDuplicate(fileName)) { + view.increaseNumberOfFileUploadsExpected(); + return view.saveUploadedFileDetails(fileName, 0, mimeType); } } catch (final ArtifactUploadFailedException e) { LOG.error("Atifact upload failed {} ", e); @@ -350,5 +371,13 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene } return true; } + + protected void intreruptUploadOnDiscard(){ + if(upload!=null && upload.isUploading()){ + upload.interruptUpload(); + uploadInterrupted = true; + } + streamingInterrupted = true; + } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java index 58661773d..baed534aa 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java @@ -118,6 +118,8 @@ public class UploadLayout extends VerticalLayout { private Button uploadStatusButton; + private Boolean changesDiscarded = Boolean.FALSE; + /** * Initialize the upload layout. */ @@ -129,7 +131,6 @@ public class UploadLayout extends VerticalLayout { eventBus.subscribe(this); ui = UI.getCurrent(); } - @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final UploadArtifactUIEvent event) { @@ -139,14 +140,17 @@ public class UploadLayout extends VerticalLayout { ui.access(() -> showUploadStatusButton()); } else if (event == UploadArtifactUIEvent.MAXIMIZED_STATUS_POPUP) { ui.access(() -> maximizeStatusPopup()); - } + } + else if(event == UploadArtifactUIEvent.ARTIFACT_RESULT_POPUP_CLOSED){ + ui.access(() -> closeUploadStatusPopup()); + } } + @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final UploadStatusEvent event) { if (event.getUploadProgressEventType() == UploadStatusEventType.UPLOAD_STARTED) { - ui.access(() -> setUploadStatusButtonIconToInProgress()); - } - else if (event.getUploadProgressEventType() == UploadStatusEventType.UPLOAD_FAILED) { + ui.access(() -> onStartOfUpload()); + } else if (event.getUploadProgressEventType() == UploadStatusEventType.UPLOAD_FAILED) { ui.access(() -> onUploadFailure(event)); } else if (event.getUploadProgressEventType() == UploadStatusEventType.UPLOAD_FINISHED) { ui.access(() -> onUploadCompletion()); @@ -155,7 +159,7 @@ public class UploadLayout extends VerticalLayout { } else if (event.getUploadProgressEventType() == UploadStatusEventType.UPLOAD_STREAMING_FAILED) { ui.access(() -> onUploadStreamingFailure(event)); } else if (event.getUploadProgressEventType() == UploadStatusEventType.UPLOAD_STREAMING_FINISHED) { - ui.access(() -> onUploadStreamingSuccess(event)); + ui.access(() -> onUploadStreamingSuccess()); } } @@ -211,6 +215,7 @@ public class UploadLayout extends VerticalLayout { private void restoreState() { updateActionCount(); + if (!artifactUploadState.getFileSelected().isEmpty() && artifactUploadState.isUploadCompleted()) { processBtn.setEnabled(true); } @@ -237,6 +242,7 @@ public class UploadLayout extends VerticalLayout { @Override public void drop(final DragAndDropEvent event) { + changesDiscarded = Boolean.FALSE; if (validate(event)) { final Html5File[] files = ((WrapperTransferable) event.getTransferable()).getFiles(); // reset the flag @@ -342,15 +348,6 @@ public class UploadLayout extends VerticalLayout { return isDuplicate; } - @EventBusListenerMethod(scope = EventScope.SESSION) - void toggleProcessButton(final UploadArtifactUIEvent event) { - if (event == UploadArtifactUIEvent.ENABLE_PROCESS_BUTTON) { - processBtn.setEnabled(true); - } else if (event == UploadArtifactUIEvent.DISABLE_PROCESS_BUTTON) { - processBtn.setEnabled(false); - } - } - /** * Save uploaded file details. * @@ -387,15 +384,14 @@ public class UploadLayout extends VerticalLayout { artifactUploadState.getBaseSwModuleList().put(currentBaseSoftwareModuleKey, selectedSoftwareModule); } return out; - } - catch (final FileNotFoundException e) { + } catch (final FileNotFoundException e) { LOG.error("Upload failed {}", e); throw new ArtifactUploadFailedException(i18n.get("message.file.not.found")); } catch (final IOException e) { LOG.error("Upload failed {}", e); throw new ArtifactUploadFailedException(i18n.get("message.upload.failed")); } - + } Boolean validate(final DragAndDropEvent event) { @@ -491,8 +487,10 @@ public class UploadLayout extends VerticalLayout { void displayDuplicateValidationMessage() { // check if streaming of all dropped files are completed - if (artifactUploadState.getNumberOfFilesActuallyUpload().intValue() == artifactUploadState.getNumberOfFileUploadsExpected().intValue()) { + if (artifactUploadState.getNumberOfFilesActuallyUpload().intValue() == artifactUploadState + .getNumberOfFileUploadsExpected().intValue()) { displayCompositeMessage(); + duplicateFileNamesList.clear(); } } @@ -537,6 +535,10 @@ public class UploadLayout extends VerticalLayout { artifactUploadState.getNumberOfFilesActuallyUpload().incrementAndGet(); } + void increaseNumberOfFileUploadsFailed() { + artifactUploadState.getNumberOfFileUploadsFailed().incrementAndGet(); + } + /** * Enable process button once upload is completed. */ @@ -561,15 +563,22 @@ public class UploadLayout extends VerticalLayout { if (artifactUploadState.getFileSelected().isEmpty()) { uiNotification.displayValidationError(i18n.get("message.error.noFileSelected")); } else { - removeUploadedFileDetails(); + clearUploadedFileDetails(); } } } - protected void removeUploadedFileDetails() { + protected void clearUploadedFileDetails() { + eventBus.publish(this, UploadArtifactUIEvent.DISCARD_UPLOAD); + changesDiscarded = Boolean.TRUE; clearFileList(); + closeUploadStatusPopup(); + } + + private void closeUploadStatusPopup() { uploadInfoWindow.clearWindow(); hideUploadStatusButton(); + artifactUploadState.setStatusPopupMinimized(false); } /** @@ -589,6 +598,7 @@ public class UploadLayout extends VerticalLayout { processBtn.setEnabled(false); artifactUploadState.getNumberOfFilesActuallyUpload().set(0); artifactUploadState.getNumberOfFileUploadsExpected().set(0); + artifactUploadState.getNumberOfFileUploadsFailed().set(0); duplicateFileNamesList.clear(); } @@ -664,10 +674,17 @@ public class UploadLayout extends VerticalLayout { return dropAreaLayout; } + private void onStartOfUpload() { + changesDiscarded = Boolean.FALSE; + setUploadStatusButtonIconToInProgress(); + if (artifactUploadState.isStatusPopupMinimized()) { + updateStatusButtonCount(); + } + } - private void onUploadStreamingSuccess(UploadStatusEvent event) { + private void onUploadStreamingSuccess() { increaseNumberOfFilesActuallyUpload(); - updateActionCount(); + updateUploadCounts(); enableProcessBtn(); if (isUploadComplete()) { uploadInfoWindow.uploadSessionFinished(); @@ -675,19 +692,35 @@ public class UploadLayout extends VerticalLayout { } // display the duplicate message after streaming all files displayDuplicateValidationMessage(); - duplicateFileNamesList.clear(); } private void onUploadStreamingFailure(UploadStatusEvent event) { - onUploadFailure(event); - updateActionCount(); - enableProcessBtn(); - // check if we are finished - if (isUploadComplete()) { - uploadInfoWindow.uploadSessionFinished(); - setUploadStatusButtonIconToFinished(); + if (!changesDiscarded) { + /** + * If upload interrupted because of duplicate file,do not remove the + * file already in upload list + **/ + if (getDuplicateFileNamesList().isEmpty() + || !getDuplicateFileNamesList().contains(event.getUploadStatus().getFileName())) { + final SoftwareModule sw = getSoftwareModuleSelected(); + getFileSelected().remove( + new CustomFile(event.getUploadStatus().getFileName(), sw.getName(), sw.getVersion())); + // failed reason to be updated only if there is error other than + // duplicate file error + uploadInfoWindow.uploadFailed(event.getUploadStatus().getFileName(), event.getUploadStatus() + .getFailureReason()); + increaseNumberOfFileUploadsFailed(); + } + decreaseNumberOfFileUploadsExpected(); + updateUploadCounts(); + enableProcessBtn(); + // check if we are finished + if (isUploadComplete()) { + uploadInfoWindow.uploadSessionFinished(); + setUploadStatusButtonIconToFinished(); + } + displayDuplicateValidationMessage(); } - displayDuplicateValidationMessage(); } private void onUploadSuccess(UploadStatusEvent event) { @@ -701,12 +734,14 @@ public class UploadLayout extends VerticalLayout { if (isUploadComplete()) { uploadInfoWindow.uploadSessionFinished(); setUploadStatusButtonIconToFinished(); + displayDuplicateValidationMessage(); } - updateActionCount(); + updateUploadCounts(); enableProcessBtn(); duplicateFileNamesList.clear(); } + private boolean isUploadComplete() { int uploadedCount = artifactUploadState.getNumberOfFilesActuallyUpload().intValue(); int expectedUploadsCount = artifactUploadState.getNumberOfFileUploadsExpected().intValue(); @@ -714,19 +749,22 @@ public class UploadLayout extends VerticalLayout { } private void onUploadFailure(final UploadStatusEvent event) { - decreaseNumberOfFileUploadsExpected(); /** * If upload interrupted because of duplicate file,do not remove the * file already in upload list **/ - if (getDuplicateFileNamesList().isEmpty() - || !getDuplicateFileNamesList().contains(event.getUploadStatus().getFileName())) { + if ((getDuplicateFileNamesList().isEmpty() || !getDuplicateFileNamesList().contains( + event.getUploadStatus().getFileName())) + && !changesDiscarded) { final SoftwareModule sw = getSoftwareModuleSelected(); getFileSelected().remove( new CustomFile(event.getUploadStatus().getFileName(), sw.getName(), sw.getVersion())); - //failed reason to be updated only if there is error other than duplicate file error + // failed reason to be updated only if there is error other than + // duplicate file error uploadInfoWindow.uploadFailed(event.getUploadStatus().getFileName(), event.getUploadStatus() .getFailureReason()); + increaseNumberOfFileUploadsFailed(); + decreaseNumberOfFileUploadsExpected(); } } @@ -777,6 +815,24 @@ public class UploadLayout extends VerticalLayout { uploadStatusButton.setVisible(false); } + void updateStatusButtonCount() { + int uploadsPending = artifactUploadState.getNumberOfFileUploadsExpected().get() + - artifactUploadState.getNumberOfFilesActuallyUpload().get(); + int uploadsFailed = artifactUploadState.getNumberOfFileUploadsFailed().get(); + StringBuilder builder = new StringBuilder(""); + if (uploadsFailed != 0) { + if (uploadsPending != 0) { + builder.append("

" + uploadsFailed + "
"); + } else { + builder.append("
" + uploadsFailed + "
"); + } + } + if (uploadsPending != 0) { + builder.append("
" + uploadsPending + "
"); + } + uploadStatusButton.setCaption(builder.toString()); + } + private void onClickOfUploadStatusButton() { artifactUploadState.setStatusPopupMinimized(false); eventBus.publish(this, UploadArtifactUIEvent.MAXIMIZED_STATUS_POPUP); @@ -787,6 +843,7 @@ public class UploadLayout extends VerticalLayout { return; } uploadStatusButton.setVisible(true); + updateStatusButtonCount(); } protected void hideUploadStatusButton() { @@ -816,5 +873,10 @@ public class UploadLayout extends VerticalLayout { uploadStatusButton.addStyleName(SPUIStyleDefinitions.UPLOAD_PROGRESS_INDICATOR_STYLE); uploadStatusButton.setIcon(null); } - + + + protected void updateUploadCounts() { + updateActionCount(); + updateStatusButtonCount(); + } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadResultWindow.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadResultWindow.java index c5319a221..94029b090 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadResultWindow.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadResultWindow.java @@ -11,6 +11,7 @@ package org.eclipse.hawkbit.ui.artifacts.upload; import java.util.ArrayList; import java.util.List; +import org.eclipse.hawkbit.ui.artifacts.event.UploadArtifactUIEvent; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleTiny; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; @@ -19,6 +20,8 @@ import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; +import org.eclipse.hawkbit.ui.utils.SpringContextHelper; +import org.vaadin.spring.events.EventBus; import com.vaadin.data.Item; import com.vaadin.data.util.IndexedContainer; @@ -63,6 +66,9 @@ public class UploadResultWindow implements Button.ClickListener { private static final String UPLOAD_RESULT = "uploadResult"; private static final String REASON = "reason"; + + private transient EventBus.SessionEventBus eventBus; + /** * Initialize upload status popup. @@ -75,6 +81,7 @@ public class UploadResultWindow implements Button.ClickListener { public UploadResultWindow(final List uploadResultList, final I18N i18n) { this.uploadResultList = uploadResultList; this.i18n = i18n; + eventBus = SpringContextHelper.getBean( EventBus.SessionEventBus.class); createComponents(); createLayout(); } @@ -183,6 +190,8 @@ public class UploadResultWindow implements Button.ClickListener { if (event.getComponent().getId().equals(SPUIComponetIdProvider.UPLOAD_ARTIFACT_RESULT_CLOSE) || event.getComponent().getId().equals(SPUIComponetIdProvider.UPLOAD_ARTIFACT_RESULT_POPUP_CLOSE)) { uploadResultsWindow.close(); + //close upload status popup if open + eventBus.publish(this, UploadArtifactUIEvent.ARTIFACT_RESULT_POPUP_CLOSED); } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusInfoWindow.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusInfoWindow.java index 2efd929d3..177ecd8a3 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusInfoWindow.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusInfoWindow.java @@ -166,7 +166,6 @@ public class UploadStatusInfoWindow extends Window { item.getItemProperty(PROGRESS).setValue(statusObject.getProgress()); item.getItemProperty(FILE_NAME).setValue(statusObject.getFilename()); } - // artifactUploadState.setUploadCompleted(true); if (artifactUploadState.isUploadCompleted()) { minimizeButton.setEnabled(false); } @@ -294,7 +293,9 @@ public class UploadStatusInfoWindow extends Window { void uploadStarted(final String filename) { final Item item = uploads.addItem(filename); - item.getItemProperty(FILE_NAME).setValue(filename); + if (item != null) { + item.getItemProperty(FILE_NAME).setValue(filename); + } grid.scrollToEnd(); UploadStatusObject uploadStatus = new UploadStatusObject(filename); uploadStatus.setStatus("Active"); @@ -302,11 +303,11 @@ public class UploadStatusInfoWindow extends Window { } void updateProgress(final String filename, final long readBytes, final long contentLength) { - final Item item = uploads.getItem(filename); + final Item item = uploads.getItem(filename); if (item != null) { double progress = (double) readBytes / (double) contentLength; item.getItemProperty(PROGRESS).setValue(progress); - List uploadStatusObjectList = (List) artifactUploadState + List uploadStatusObjectList = (List) artifactUploadState .getUploadedFileStatusList().stream().filter(e -> e.getFilename().equals(filename)) .collect(Collectors.toList()); if (!uploadStatusObjectList.isEmpty()) { @@ -363,6 +364,7 @@ public class UploadStatusInfoWindow extends Window { setWindowMode(WindowMode.NORMAL); this.close(); artifactUploadState.getUploadedFileStatusList().clear(); + artifactUploadState.getNumberOfFileUploadsFailed().set(0); } private void setPopupSizeInMinMode() { @@ -421,5 +423,4 @@ public class UploadStatusInfoWindow extends Window { closeBtn.addClickListener(event -> clearWindow()); return closeBtn; } - } diff --git a/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/customstyles/others.scss b/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/customstyles/others.scss index 879fb8dd6..f6f4c2434 100644 --- a/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/customstyles/others.scss +++ b/hawkbit-ui/src/main/resources/VAADIN/themes/hawkbit/customstyles/others.scss @@ -10,7 +10,7 @@ @mixin others { //Style to display the pending action count - .unread { + .unread, .error-count { @include valo-badge-style; position: absolute; pointer-events: none; @@ -21,6 +21,15 @@ border-radius: $v-border-radius; color: $widget-bg; } + + .error-count { + top: round($v-unit-size / -5); + right: round($v-unit-size / 1.9); + } + + .error-count-color{ + @include valo-gradient($color: $red-color); + } //Deployment view - Style of count message .v-caption-count-msg-box { From eadff47f24a8fc360b055032edee26d4d1b3b6e6 Mon Sep 17 00:00:00 2001 From: Asharani Date: Mon, 16 May 2016 16:26:24 +0530 Subject: [PATCH 07/54] Artifact upload : on discard action interupt the ongoing upload - reverted the changes Signed-off-by: Asharani --- .../event/UploadArtifactUIEvent.java | 2 +- .../ui/artifacts/upload/UploadHandler.java | 26 ------------------- .../ui/artifacts/upload/UploadLayout.java | 13 ++-------- 3 files changed, 3 insertions(+), 38 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadArtifactUIEvent.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadArtifactUIEvent.java index 1f5971f4b..e1fe4e07f 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadArtifactUIEvent.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadArtifactUIEvent.java @@ -15,5 +15,5 @@ package org.eclipse.hawkbit.ui.artifacts.event; * */ public enum UploadArtifactUIEvent { - SHOW_DROP_HINTS, HIDE_DROP_HINTS, SOFTWARE_DRAG_START, SOFTWARE_TYPE_DRAG_START, UPDATE_UPLOAD_COUNT, HIDE_FILTER_BY_TYPE, SHOW_FILTER_BY_TYPE, DISCARD_DELETE_SOFTWARE, DISCARD_ALL_DELETE_SOFTWARE, DELETED_ALL_SOFWARE, DISCARD_DELETE_SOFTWARE_TYPE, DISCARD_ALL_DELETE_SOFTWARE_TYPE, DELETED_ALL_SOFWARE_TYPE, MINIMIZED_STATUS_POPUP, MAXIMIZED_STATUS_POPUP, UPLOAD_IN_PROGESS, DISCARD_UPLOAD, ARTIFACT_RESULT_POPUP_CLOSED + SHOW_DROP_HINTS, HIDE_DROP_HINTS, SOFTWARE_DRAG_START, SOFTWARE_TYPE_DRAG_START, UPDATE_UPLOAD_COUNT, HIDE_FILTER_BY_TYPE, SHOW_FILTER_BY_TYPE, DISCARD_DELETE_SOFTWARE, DISCARD_ALL_DELETE_SOFTWARE, DELETED_ALL_SOFWARE, DISCARD_DELETE_SOFTWARE_TYPE, DISCARD_ALL_DELETE_SOFTWARE_TYPE, DELETED_ALL_SOFWARE_TYPE, MINIMIZED_STATUS_POPUP, MAXIMIZED_STATUS_POPUP, UPLOAD_IN_PROGESS, ARTIFACT_RESULT_POPUP_CLOSED } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java index 2c8220fdf..5c0373acf 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java @@ -88,24 +88,6 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene this.mimeType = mimeType; this.i18n = SpringContextHelper.getBean(I18N.class); this.eventBus = SpringContextHelper.getBean(EventBus.SessionEventBus.class); - eventBus.subscribe(this); - } - - @EventBusListenerMethod(scope = EventScope.SESSION) - void onEvent(final UploadArtifactUIEvent event) { - if (event == UploadArtifactUIEvent.DISCARD_UPLOAD) { - UI.getCurrent().access(() ->intreruptUploadOnDiscard()); - } - } - -// - @PreDestroy - void destroy() { - /* - * It's good manners to do this, even though vaadin-spring will - * automatically unsubscribe when this UI is garbage collected. - */ - eventBus.unsubscribe(this); } /** @@ -372,12 +354,4 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene return true; } - protected void intreruptUploadOnDiscard(){ - if(upload!=null && upload.isUploading()){ - upload.interruptUpload(); - uploadInterrupted = true; - } - streamingInterrupted = true; - } - } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java index baed534aa..a9f36e8b8 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java @@ -118,7 +118,6 @@ public class UploadLayout extends VerticalLayout { private Button uploadStatusButton; - private Boolean changesDiscarded = Boolean.FALSE; /** * Initialize the upload layout. @@ -242,7 +241,6 @@ public class UploadLayout extends VerticalLayout { @Override public void drop(final DragAndDropEvent event) { - changesDiscarded = Boolean.FALSE; if (validate(event)) { final Html5File[] files = ((WrapperTransferable) event.getTransferable()).getFiles(); // reset the flag @@ -569,8 +567,6 @@ public class UploadLayout extends VerticalLayout { } protected void clearUploadedFileDetails() { - eventBus.publish(this, UploadArtifactUIEvent.DISCARD_UPLOAD); - changesDiscarded = Boolean.TRUE; clearFileList(); closeUploadStatusPopup(); } @@ -669,13 +665,11 @@ public class UploadLayout extends VerticalLayout { /** * @return */ - VerticalLayout getDropAreaLayout() { return dropAreaLayout; } private void onStartOfUpload() { - changesDiscarded = Boolean.FALSE; setUploadStatusButtonIconToInProgress(); if (artifactUploadState.isStatusPopupMinimized()) { updateStatusButtonCount(); @@ -695,7 +689,6 @@ public class UploadLayout extends VerticalLayout { } private void onUploadStreamingFailure(UploadStatusEvent event) { - if (!changesDiscarded) { /** * If upload interrupted because of duplicate file,do not remove the * file already in upload list @@ -720,7 +713,6 @@ public class UploadLayout extends VerticalLayout { setUploadStatusButtonIconToFinished(); } displayDuplicateValidationMessage(); - } } private void onUploadSuccess(UploadStatusEvent event) { @@ -753,9 +745,8 @@ public class UploadLayout extends VerticalLayout { * If upload interrupted because of duplicate file,do not remove the * file already in upload list **/ - if ((getDuplicateFileNamesList().isEmpty() || !getDuplicateFileNamesList().contains( - event.getUploadStatus().getFileName())) - && !changesDiscarded) { + if (getDuplicateFileNamesList().isEmpty() || !getDuplicateFileNamesList().contains( + event.getUploadStatus().getFileName())) { final SoftwareModule sw = getSoftwareModuleSelected(); getFileSelected().remove( new CustomFile(event.getUploadStatus().getFileName(), sw.getName(), sw.getVersion())); From 0073fdeb403bddd81bcf8c5d688d3657d4e43564 Mon Sep 17 00:00:00 2001 From: Asharani Date: Tue, 17 May 2016 12:48:47 +0530 Subject: [PATCH 08/54] Added comments .Removed changes not required. Signed-off-by: Asharani --- hawkbit-ui/pom.xml | 5 ----- .../hawkbit/ui/artifacts/event/UploadFileStatus.java | 6 +++--- .../hawkbit/ui/artifacts/upload/UploadStatusObject.java | 6 ++++++ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/hawkbit-ui/pom.xml b/hawkbit-ui/pom.xml index 38b455367..e0bde576a 100644 --- a/hawkbit-ui/pom.xml +++ b/hawkbit-ui/pom.xml @@ -254,10 +254,5 @@ allure-junit-adaptor test - - org.scala-lang - scala-library - 2.10.4 - \ No newline at end of file diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadFileStatus.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadFileStatus.java index 776556464..cdfeea653 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadFileStatus.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadFileStatus.java @@ -12,7 +12,7 @@ import java.io.Serializable; /** * - * Holds file and upload status details. + * Holds file and upload status details.Meta data sent with upload events. * */ public class UploadFileStatus implements Serializable { @@ -27,10 +27,10 @@ public class UploadFileStatus implements Serializable { private String failureReason; - public UploadFileStatus(String fileName){ + public UploadFileStatus(String fileName) { this.fileName = fileName; } - + public UploadFileStatus(String fileName, long bytesRead, long contentLength) { this.fileName = fileName; this.contentLength = contentLength; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusObject.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusObject.java index 80c71fe7b..13167b55a 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusObject.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusObject.java @@ -8,6 +8,12 @@ */ package org.eclipse.hawkbit.ui.artifacts.upload; +/** + * + * Holds uploaded file status.Used to display the details in upload status + * popup. + * + */ public class UploadStatusObject { private String status; private Double progress; From 652f480667244dca648a3322fd9d8ff5d7fa65e1 Mon Sep 17 00:00:00 2001 From: Asharani Date: Tue, 17 May 2016 15:01:12 +0530 Subject: [PATCH 09/54] Added liscense header Signed-off-by: Asharani --- .../hawkbit/ui/artifacts/event/UploadStatusEvent.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadStatusEvent.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadStatusEvent.java index ab10c2e10..96513a52a 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadStatusEvent.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadStatusEvent.java @@ -1,3 +1,11 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ package org.eclipse.hawkbit.ui.artifacts.event; /** * From 51db4204d2ad8c12fa3c4ef02d7727d36554d58f Mon Sep 17 00:00:00 2001 From: Asharani Date: Tue, 17 May 2016 17:50:40 +0530 Subject: [PATCH 10/54] Bug fix :- During upload the files when changing the selection of the software module the upload also changes to the new selected software module Signed-off-by: Asharani --- .../ui/artifacts/event/UploadFileStatus.java | 11 ++- .../ui/artifacts/upload/UploadHandler.java | 30 ++++--- .../ui/artifacts/upload/UploadLayout.java | 84 ++++++++++--------- .../upload/UploadStatusInfoWindow.java | 1 + .../ui/utils/SPUIComponetIdProvider.java | 5 ++ 5 files changed, 79 insertions(+), 52 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadFileStatus.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadFileStatus.java index cdfeea653..f594fad8b 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadFileStatus.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadFileStatus.java @@ -10,6 +10,8 @@ package org.eclipse.hawkbit.ui.artifacts.event; import java.io.Serializable; +import org.eclipse.hawkbit.repository.model.SoftwareModule; + /** * * Holds file and upload status details.Meta data sent with upload events. @@ -27,6 +29,8 @@ public class UploadFileStatus implements Serializable { private String failureReason; + private SoftwareModule softwareModule; + public UploadFileStatus(String fileName) { this.fileName = fileName; } @@ -37,9 +41,10 @@ public class UploadFileStatus implements Serializable { this.bytesRead = bytesRead; } - public UploadFileStatus(String fileName, String failureReason) { + public UploadFileStatus(String fileName, String failureReason,SoftwareModule selectedSw) { this.failureReason = failureReason; this.fileName = fileName; + this.softwareModule = selectedSw; } public String getFileName() { @@ -57,4 +62,8 @@ public class UploadFileStatus implements Serializable { public String getFailureReason() { return failureReason; } + + public SoftwareModule getSoftwareModule() { + return softwareModule; + } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java index f51e171ba..277e56967 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java @@ -14,10 +14,12 @@ import java.io.OutputStream; import javax.annotation.PreDestroy; import org.eclipse.hawkbit.repository.exception.ArtifactUploadFailedException; +import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.ui.artifacts.event.UploadArtifactUIEvent; import org.eclipse.hawkbit.ui.artifacts.event.UploadFileStatus; import org.eclipse.hawkbit.ui.artifacts.event.UploadStatusEvent; import org.eclipse.hawkbit.ui.artifacts.event.UploadStatusEvent.UploadStatusEventType; +import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState; import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SpringContextHelper; import org.slf4j.Logger; @@ -68,9 +70,12 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene private String failureReason; private final I18N i18n; private transient EventBus.SessionEventBus eventBus; + private final SoftwareModule selectedSw; + private SoftwareModule selectedSwForUpload; + private ArtifactUploadState artifactUploadState; - UploadHandler(final String fileName, final long fileSize, final UploadLayout view, - final long maxSize, final Upload upload, final String mimeType) { + UploadHandler(final String fileName, final long fileSize, final UploadLayout view, final long maxSize, + final Upload upload, final String mimeType, SoftwareModule selectedSw) { super(); this.fileName = fileName; this.fileSize = fileSize; @@ -78,8 +83,10 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene this.maxSize = maxSize; this.upload = upload; this.mimeType = mimeType; + this.selectedSw = selectedSw; this.i18n = SpringContextHelper.getBean(I18N.class); this.eventBus = SpringContextHelper.getBean(EventBus.SessionEventBus.class); + this.artifactUploadState = SpringContextHelper.getBean(ArtifactUploadState.class); } /** @@ -91,7 +98,7 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene public final OutputStream getOutputStream() { try { streamingInterrupted = false; - return view.saveUploadedFileDetails(fileName, fileSize, mimeType); + return view.saveUploadedFileDetails(fileName, fileSize, mimeType, selectedSw); } catch (final ArtifactUploadFailedException e) { LOG.error("Atifact upload failed {} ", e); failureReason = e.getMessage(); @@ -116,7 +123,8 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene try { if (view.checkIfSoftwareModuleIsSelected() && !view.checkForDuplicate(fileName)) { view.increaseNumberOfFileUploadsExpected(); - return view.saveUploadedFileDetails(fileName, 0, mimeType); + selectedSwForUpload = artifactUploadState.getSelectedBaseSoftwareModule().get(); + return view.saveUploadedFileDetails(fileName, 0, mimeType, selectedSwForUpload); } } catch (final ArtifactUploadFailedException e) { LOG.error("Atifact upload failed {} ", e); @@ -217,13 +225,14 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene */ @Override public void updateProgress(final long readBytes, final long contentLength) { - //Update progress is called event after upload interrupted in uploadStarted method + // Update progress is called event after upload interrupted in + // uploadStarted method if (!uploadInterrupted) { if (readBytes > maxSize || contentLength > maxSize) { LOG.error("User tried to upload more than was allowed ({}).", maxSize); failureReason = i18n.get("message.uploadedfile.size.exceeded", maxSize); eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_FAILED, new UploadFileStatus( - fileName, failureReason))); + fileName, failureReason, selectedSwForUpload))); upload.interruptUpload(); uploadInterrupted = true; return; @@ -245,7 +254,7 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene LOG.error("User tried to upload more than was allowed ({}).", maxSize); failureReason = i18n.get("message.uploadedfile.size.exceeded", maxSize); eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_FAILED, new UploadFileStatus( - fileName, failureReason))); + fileName, failureReason, selectedSw))); streamingInterrupted = true; return; } @@ -268,7 +277,7 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene failureReason = event.getException().getMessage(); } eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_STREAMING_FAILED, - new UploadFileStatus(fileName, failureReason))); + new UploadFileStatus(fileName, failureReason, selectedSw))); LOG.info("Streaming failed due to :{}", event.getException()); } @@ -284,9 +293,8 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene if (failureReason == null) { failureReason = event.getReason().getMessage(); } - System.out.println("failureReason:::"+failureReason); eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_FAILED, new UploadFileStatus( - fileName, failureReason))); + fileName, failureReason, selectedSwForUpload))); LOG.info("Upload failed for file :{}", event.getReason()); } @@ -335,5 +343,5 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene } return true; } - + } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java index a9f36e8b8..fedee30b9 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java @@ -181,7 +181,7 @@ public class UploadLayout extends VerticalLayout { final Upload upload = new Upload(); final UploadHandler uploadHandler = new UploadHandler(null, 0, this, spInfo.getMaxArtifactFileSize(), upload, - null); + null, null); upload.setButtonCaption(i18n.get("upload.file")); upload.setImmediate(true); upload.setReceiver(uploadHandler); @@ -243,15 +243,16 @@ public class UploadLayout extends VerticalLayout { public void drop(final DragAndDropEvent event) { if (validate(event)) { final Html5File[] files = ((WrapperTransferable) event.getTransferable()).getFiles(); + // selected software module at the time of file drop is + // considered for upload + SoftwareModule selectedSw = artifactUploadState.getSelectedBaseSoftwareModule().get(); // reset the flag hasDirectory = Boolean.FALSE; for (final Html5File file : files) { - processFile(file); + processFile(file, selectedSw); } if (artifactUploadState.getNumberOfFileUploadsExpected().get() > 0) { processBtn.setEnabled(false); - // reset before we start - // uploadInfoWindow.uploadSessionStarted(); } else { // If the upload is not started, it signifies all // dropped files as either duplicate or directory.So @@ -261,20 +262,20 @@ public class UploadLayout extends VerticalLayout { } } - private void processFile(final Html5File file) { + private void processFile(final Html5File file, SoftwareModule selectedSw) { if (!isDirectory(file)) { if (!checkForDuplicate(file.getFileName())) { artifactUploadState.getNumberOfFileUploadsExpected().incrementAndGet(); - file.setStreamVariable(createStreamVariable(file)); + file.setStreamVariable(createStreamVariable(file,selectedSw)); } } else { hasDirectory = Boolean.TRUE; } } - private StreamVariable createStreamVariable(final Html5File file) { + private StreamVariable createStreamVariable(final Html5File file, SoftwareModule selectedSw) { return new UploadHandler(file.getFileName(), file.getFileSize(), UploadLayout.this, - spInfo.getMaxArtifactFileSize(), null, file.getType()); + spInfo.getMaxArtifactFileSize(), null, file.getType(),selectedSw); } private boolean isDirectory(final Html5File file) { @@ -357,29 +358,28 @@ public class UploadLayout extends VerticalLayout { * file size * @param mimeType * the mimeType of the file + * @param selectedSw * @throws IOException * in case of upload errors */ - OutputStream saveUploadedFileDetails(final String name, final long size, final String mimeType) { + OutputStream saveUploadedFileDetails(final String name, final long size, final String mimeType, SoftwareModule selectedSw) { File tempFile = null; try { tempFile = File.createTempFile("spUiArtifactUpload", null); final OutputStream out = new FileOutputStream(tempFile); - final SoftwareModule selectedSoftwareModule = artifactUploadState.getSelectedBaseSoftwareModule().get(); - final String currentBaseSoftwareModuleKey = HawkbitCommonUtil.getFormattedNameVersion( - selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion()); + selectedSw.getName(), selectedSw.getVersion()); final CustomFile customFile = new CustomFile(name, size, tempFile.getAbsolutePath(), - selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion(), mimeType); + selectedSw.getName(), selectedSw.getVersion(), mimeType); artifactUploadState.getFileSelected().add(customFile); processBtn.setEnabled(false); if (!artifactUploadState.getBaseSwModuleList().keySet().contains(currentBaseSoftwareModuleKey)) { - artifactUploadState.getBaseSwModuleList().put(currentBaseSoftwareModuleKey, selectedSoftwareModule); + artifactUploadState.getBaseSwModuleList().put(currentBaseSoftwareModuleKey, selectedSw); } return out; } catch (final FileNotFoundException e) { @@ -689,30 +689,32 @@ public class UploadLayout extends VerticalLayout { } private void onUploadStreamingFailure(UploadStatusEvent event) { - /** - * If upload interrupted because of duplicate file,do not remove the - * file already in upload list - **/ - if (getDuplicateFileNamesList().isEmpty() - || !getDuplicateFileNamesList().contains(event.getUploadStatus().getFileName())) { - final SoftwareModule sw = getSoftwareModuleSelected(); + /** + * If upload interrupted because of duplicate file,do not remove the + * file already in upload list + **/ + if (getDuplicateFileNamesList().isEmpty() + || !getDuplicateFileNamesList().contains(event.getUploadStatus().getFileName())) { + final SoftwareModule sw = event.getUploadStatus().getSoftwareModule(); + if (sw != null) { getFileSelected().remove( new CustomFile(event.getUploadStatus().getFileName(), sw.getName(), sw.getVersion())); - // failed reason to be updated only if there is error other than - // duplicate file error - uploadInfoWindow.uploadFailed(event.getUploadStatus().getFileName(), event.getUploadStatus() - .getFailureReason()); - increaseNumberOfFileUploadsFailed(); } - decreaseNumberOfFileUploadsExpected(); - updateUploadCounts(); - enableProcessBtn(); - // check if we are finished - if (isUploadComplete()) { - uploadInfoWindow.uploadSessionFinished(); - setUploadStatusButtonIconToFinished(); - } - displayDuplicateValidationMessage(); + // failed reason to be updated only if there is error other than + // duplicate file error + uploadInfoWindow.uploadFailed(event.getUploadStatus().getFileName(), event.getUploadStatus() + .getFailureReason()); + increaseNumberOfFileUploadsFailed(); + } + decreaseNumberOfFileUploadsExpected(); + updateUploadCounts(); + enableProcessBtn(); + // check if we are finished + if (isUploadComplete()) { + uploadInfoWindow.uploadSessionFinished(); + setUploadStatusButtonIconToFinished(); + } + displayDuplicateValidationMessage(); } private void onUploadSuccess(UploadStatusEvent event) { @@ -745,11 +747,13 @@ public class UploadLayout extends VerticalLayout { * If upload interrupted because of duplicate file,do not remove the * file already in upload list **/ - if (getDuplicateFileNamesList().isEmpty() || !getDuplicateFileNamesList().contains( - event.getUploadStatus().getFileName())) { - final SoftwareModule sw = getSoftwareModuleSelected(); - getFileSelected().remove( - new CustomFile(event.getUploadStatus().getFileName(), sw.getName(), sw.getVersion())); + if (getDuplicateFileNamesList().isEmpty() + || !getDuplicateFileNamesList().contains(event.getUploadStatus().getFileName())) { + final SoftwareModule sw = event.getUploadStatus().getSoftwareModule(); + if (sw != null) { + getFileSelected().remove( + new CustomFile(event.getUploadStatus().getFileName(), sw.getName(), sw.getVersion())); + } // failed reason to be updated only if there is error other than // duplicate file error uploadInfoWindow.uploadFailed(event.getUploadStatus().getFileName(), event.getUploadStatus() diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusInfoWindow.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusInfoWindow.java index 177ecd8a3..e2a486e6c 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusInfoWindow.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusInfoWindow.java @@ -173,6 +173,7 @@ public class UploadStatusInfoWindow extends Window { } private void setPopupProperties() { + setId(SPUIComponetIdProvider.UPLOAD_STATUS_POPUP_ID); addStyleName(SPUIStyleDefinitions.UPLOAD_INFO); setImmediate(true); setResizable(false); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIComponetIdProvider.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIComponetIdProvider.java index 7c25bf90a..2ada1b7bf 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIComponetIdProvider.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIComponetIdProvider.java @@ -902,6 +902,11 @@ public final class SPUIComponetIdProvider { * Artifact upload view - upload status button id. */ public static final String UPLOAD_STATUS_BUTTON = "artficat.upload.status.button.id"; + + /** + * Artifact uplaod view - uplod status popup id. + */ + public static final String UPLOAD_STATUS_POPUP_ID = "artifact.upload.status.popup.id"; /** From a774412055645759be25942342402c61f3ceb076 Mon Sep 17 00:00:00 2001 From: Asharani Date: Wed, 18 May 2016 11:14:51 +0530 Subject: [PATCH 11/54] Bug fix : During upload the files when changing the selection of the software module the upload also changes to the new selected software module Signed-off-by: Asharani --- .../ui/artifacts/event/UploadFileStatus.java | 3 +- .../ui/artifacts/upload/UploadHandler.java | 19 ++++---- .../ui/artifacts/upload/UploadLayout.java | 45 +++++++------------ 3 files changed, 29 insertions(+), 38 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadFileStatus.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadFileStatus.java index f594fad8b..81b096c3e 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadFileStatus.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadFileStatus.java @@ -35,10 +35,11 @@ public class UploadFileStatus implements Serializable { this.fileName = fileName; } - public UploadFileStatus(String fileName, long bytesRead, long contentLength) { + public UploadFileStatus(String fileName, long bytesRead, long contentLength,SoftwareModule softwareModule) { this.fileName = fileName; this.contentLength = contentLength; this.bytesRead = bytesRead; + this.softwareModule = softwareModule; } public UploadFileStatus(String fileName, String failureReason,SoftwareModule selectedSw) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java index 277e56967..848fa2da5 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java @@ -121,9 +121,8 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene // reset has directory flag before upload view.setHasDirectory(false); try { - if (view.checkIfSoftwareModuleIsSelected() && !view.checkForDuplicate(fileName)) { + if (view.checkIfSoftwareModuleIsSelected() && !view.checkForDuplicate(fileName, selectedSwForUpload)) { view.increaseNumberOfFileUploadsExpected(); - selectedSwForUpload = artifactUploadState.getSelectedBaseSoftwareModule().get(); return view.saveUploadedFileDetails(fileName, 0, mimeType, selectedSwForUpload); } } catch (final ArtifactUploadFailedException e) { @@ -146,7 +145,7 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene public void uploadSucceeded(final SucceededEvent event) { LOG.debug("Streaming finished for file :{}", event.getFilename()); eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_SUCCESSFUL, new UploadFileStatus( - event.getFilename(), 0, event.getLength()))); + event.getFilename(), 0, event.getLength(), selectedSwForUpload))); } /** @@ -160,7 +159,7 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene public void streamingFinished(final StreamingEndEvent event) { LOG.debug("Streaming finished for file :{}", event.getFileName()); eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_STREAMING_FINISHED, - new UploadFileStatus(event.getFileName(), 0, event.getContentLength()))); + new UploadFileStatus(event.getFileName(), 0, event.getContentLength(), selectedSw))); } /** @@ -185,7 +184,7 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene public void streamingStarted(final StreamingStartEvent event) { LOG.debug("Streaming started for file :{}", fileName); eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_STARTED, new UploadFileStatus( - fileName, 0, 0))); + fileName, 0, 0, selectedSw))); } /** @@ -195,11 +194,13 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene */ @Override public void uploadStarted(final StartedEvent event) { + selectedSwForUpload = artifactUploadState.getSelectedBaseSoftwareModule().get(); + // single file session - if (view.isSoftwareModuleSelected() && !view.checkIfFileIsDuplicate(event.getFilename())) { + if (view.isSoftwareModuleSelected() && !view.checkIfFileIsDuplicate(event.getFilename(), selectedSwForUpload)) { LOG.debug("Upload started for file :{}", event.getFilename()); eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_STARTED, new UploadFileStatus( - event.getFilename(), 0, 0))); + event.getFilename(), 0, 0, selectedSwForUpload))); } else { failureReason = i18n.get("message.upload.failed"); upload.interruptUpload(); @@ -238,7 +239,7 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene return; } eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_IN_PROGRESS, - new UploadFileStatus(fileName, readBytes, contentLength))); + new UploadFileStatus(fileName, readBytes, contentLength, selectedSwForUpload))); LOG.info("Update progress - {} : {}", fileName, (double) readBytes / (double) contentLength); } } @@ -259,7 +260,7 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene return; } eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_IN_PROGRESS, new UploadFileStatus( - fileName, event.getBytesReceived(), event.getContentLength()))); + fileName, event.getBytesReceived(), event.getContentLength(), selectedSw))); // Logging to solve sonar issue LOG.trace("Streaming in progress for file :{}", event.getFileName()); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java index fedee30b9..cbf766da8 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java @@ -118,7 +118,6 @@ public class UploadLayout extends VerticalLayout { private Button uploadStatusButton; - /** * Initialize the upload layout. */ @@ -139,8 +138,7 @@ public class UploadLayout extends VerticalLayout { ui.access(() -> showUploadStatusButton()); } else if (event == UploadArtifactUIEvent.MAXIMIZED_STATUS_POPUP) { ui.access(() -> maximizeStatusPopup()); - } - else if(event == UploadArtifactUIEvent.ARTIFACT_RESULT_POPUP_CLOSED){ + } else if (event == UploadArtifactUIEvent.ARTIFACT_RESULT_POPUP_CLOSED) { ui.access(() -> closeUploadStatusPopup()); } } @@ -264,9 +262,9 @@ public class UploadLayout extends VerticalLayout { private void processFile(final Html5File file, SoftwareModule selectedSw) { if (!isDirectory(file)) { - if (!checkForDuplicate(file.getFileName())) { + if (!checkForDuplicate(file.getFileName(), selectedSw)) { artifactUploadState.getNumberOfFileUploadsExpected().incrementAndGet(); - file.setStreamVariable(createStreamVariable(file,selectedSw)); + file.setStreamVariable(createStreamVariable(file, selectedSw)); } } else { hasDirectory = Boolean.TRUE; @@ -275,7 +273,7 @@ public class UploadLayout extends VerticalLayout { private StreamVariable createStreamVariable(final Html5File file, SoftwareModule selectedSw) { return new UploadHandler(file.getFileName(), file.getFileSize(), UploadLayout.this, - spInfo.getMaxArtifactFileSize(), null, file.getType(),selectedSw); + spInfo.getMaxArtifactFileSize(), null, file.getType(), selectedSw); } private boolean isDirectory(final Html5File file) { @@ -339,8 +337,8 @@ public class UploadLayout extends VerticalLayout { discardBtn.addClickListener(event -> discardUploadData(event)); } - boolean checkForDuplicate(final String filename) { - final Boolean isDuplicate = checkIfFileIsDuplicate(filename); + boolean checkForDuplicate(final String filename, final SoftwareModule selectedSw) { + final Boolean isDuplicate = checkIfFileIsDuplicate(filename, selectedSw); if (isDuplicate) { getDuplicateFileNamesList().add(filename); } @@ -358,22 +356,23 @@ public class UploadLayout extends VerticalLayout { * file size * @param mimeType * the mimeType of the file - * @param selectedSw + * @param selectedSw * @throws IOException * in case of upload errors */ - OutputStream saveUploadedFileDetails(final String name, final long size, final String mimeType, SoftwareModule selectedSw) { + OutputStream saveUploadedFileDetails(final String name, final long size, final String mimeType, + SoftwareModule selectedSw) { File tempFile = null; try { tempFile = File.createTempFile("spUiArtifactUpload", null); final OutputStream out = new FileOutputStream(tempFile); - final String currentBaseSoftwareModuleKey = HawkbitCommonUtil.getFormattedNameVersion( - selectedSw.getName(), selectedSw.getVersion()); + final String currentBaseSoftwareModuleKey = HawkbitCommonUtil.getFormattedNameVersion(selectedSw.getName(), + selectedSw.getVersion()); - final CustomFile customFile = new CustomFile(name, size, tempFile.getAbsolutePath(), - selectedSw.getName(), selectedSw.getVersion(), mimeType); + final CustomFile customFile = new CustomFile(name, size, tempFile.getAbsolutePath(), selectedSw.getName(), + selectedSw.getVersion(), mimeType); artifactUploadState.getFileSelected().add(customFile); processBtn.setEnabled(false); @@ -424,13 +423,6 @@ public class UploadLayout extends VerticalLayout { return true; } - SoftwareModule getSoftwareModuleSelected() { - if (artifactUploadState.getSelectedBaseSoftwareModule().isPresent()) { - return artifactUploadState.getSelectedBaseSoftwareModule().get(); - } - return null; - } - Boolean isSoftwareModuleSelected() { if (!artifactUploadState.getSelectedBaseSwModuleId().isPresent()) { return false; @@ -446,9 +438,8 @@ public class UploadLayout extends VerticalLayout { * file name * @return Boolean */ - public Boolean checkIfFileIsDuplicate(final String name) { + public Boolean checkIfFileIsDuplicate(final String name, final SoftwareModule selectedSoftwareModule) { Boolean isDuplicate = false; - final SoftwareModule selectedSoftwareModule = artifactUploadState.getSelectedBaseSoftwareModule().get(); final String currentBaseSoftwareModuleKey = HawkbitCommonUtil.getFormattedNameVersion( selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion()); @@ -514,8 +505,7 @@ public class UploadLayout extends VerticalLayout { artifactUploadState.getNumberOfFileUploadsExpected().incrementAndGet(); } - void updateFileSize(final String name, final long size) { - final SoftwareModule selectedSoftwareModule = artifactUploadState.getSelectedBaseSoftwareModule().get(); + void updateFileSize(final String name, final long size, SoftwareModule selectedSoftwareModule) { final String currentBaseSoftwareModuleKey = HawkbitCommonUtil.getFormattedNameVersion( selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion()); @@ -718,7 +708,8 @@ public class UploadLayout extends VerticalLayout { } private void onUploadSuccess(UploadStatusEvent event) { - updateFileSize(event.getUploadStatus().getFileName(), event.getUploadStatus().getContentLength()); + updateFileSize(event.getUploadStatus().getFileName(), event.getUploadStatus().getContentLength(), event + .getUploadStatus().getSoftwareModule()); // recorded that we now one more uploaded increaseNumberOfFilesActuallyUpload(); } @@ -735,7 +726,6 @@ public class UploadLayout extends VerticalLayout { duplicateFileNamesList.clear(); } - private boolean isUploadComplete() { int uploadedCount = artifactUploadState.getNumberOfFilesActuallyUpload().intValue(); int expectedUploadsCount = artifactUploadState.getNumberOfFileUploadsExpected().intValue(); @@ -869,7 +859,6 @@ public class UploadLayout extends VerticalLayout { uploadStatusButton.setIcon(null); } - protected void updateUploadCounts() { updateActionCount(); updateStatusButtonCount(); From 3c0d5396b043434f1e2de19364584f971818a3fa Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Wed, 18 May 2016 16:16:30 +0200 Subject: [PATCH 12/54] Removed default implementations as JaCoCo has problems with those. Split software management. Signed-off-by: Kai Zimmermann --- .../SecurityManagedConfiguration.java | 6 +- .../amqp/AmqpMessageHandlerService.java | 8 +- .../amqp/AmqpMessageHandlerServiceTest.java | 2 +- .../repository/ArtifactManagement.java | 27 +- .../repository/ControllerManagement.java | 6 +- .../repository/DeploymentManagement.java | 19 +- .../repository/DistributionSetFilter.java | 3 - .../repository/DistributionSetManagement.java | 24 +- .../hawkbit/repository/ReportManagement.java | 2 +- .../repository/RolloutGroupManagement.java | 4 + .../hawkbit/repository/RolloutManagement.java | 2 +- .../hawkbit/repository/RolloutScheduler.java | 6 +- .../repository/SoftwareManagement.java | 471 ++++++++++++++++ .../TenantConfigurationManagement.java | 14 +- .../repository/jpa/DeploymentHelper.java | 100 ++++ .../repository/jpa/JpaArtifactManagement.java | 16 + .../jpa/JpaControllerManagement.java | 8 +- .../jpa/JpaDeploymentManagement.java | 1 - .../jpa/JpaDistributionSetManagement.java | 25 +- ...gement.java => JpaSoftwareManagement.java} | 508 ++++-------------- .../hawkbit/AbstractIntegrationTest.java | 2 +- .../org/eclipse/hawkbit/TestDataUtil.java | 2 +- .../repository/SoftwareManagementTest.java | 2 +- .../utils/RepositoryDataGenerator.java | 2 +- .../hawkbit/controller/RootController.java | 2 +- .../rest/resource/DistributionSetMapper.java | 2 +- .../resource/DistributionSetResource.java | 2 +- .../resource/DistributionSetTypeMapper.java | 2 +- .../resource/DistributionSetTypeResource.java | 2 +- .../resource/DownloadArtifactResource.java | 2 +- .../rest/resource/SoftwareModuleMapper.java | 2 +- .../rest/resource/SoftwareModuleResource.java | 2 +- .../resource/SoftwareModuleTypeResource.java | 2 +- .../resource/DistributionSetResourceTest.java | 2 +- .../UploadViewConfirmationWindowLayout.java | 2 +- .../smtable/BaseSwModuleBeanQuery.java | 2 +- .../SoftwareModuleAddUpdateWindow.java | 2 +- .../smtable/SoftwareModuleTable.java | 2 +- .../CreateUpdateSoftwareTypeLayout.java | 2 +- .../smtype/SMTypeFilterButtonClick.java | 2 +- .../common/SoftwareModuleTypeBeanQuery.java | 2 +- .../CreateUpdateDistSetTypeLayout.java | 2 +- .../dstable/DistributionSetDetails.java | 2 +- .../dstable/DistributionSetTable.java | 2 +- ...DistributionsConfirmationWindowLayout.java | 2 +- .../smtable/SwModuleBeanQuery.java | 2 +- .../distributions/smtable/SwModuleTable.java | 2 +- .../smtype/DistSMTypeFilterButtonClick.java | 2 +- .../hawkbit/ui/utils/HawkbitCommonUtil.java | 2 +- pom.xml | 2 +- 50 files changed, 789 insertions(+), 523 deletions(-) create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/DeploymentHelper.java rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/{SoftwareManagement.java => JpaSoftwareManagement.java} (55%) diff --git a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/security/SecurityManagedConfiguration.java b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/security/SecurityManagedConfiguration.java index 9638377eb..0b321842f 100644 --- a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/security/SecurityManagedConfiguration.java +++ b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/security/SecurityManagedConfiguration.java @@ -24,11 +24,11 @@ import org.eclipse.hawkbit.ExcludePathAwareShallowETagFilter; import org.eclipse.hawkbit.cache.CacheConstants; import org.eclipse.hawkbit.im.authentication.SpPermission; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; +import org.eclipse.hawkbit.repository.ControllerManagement; +import org.eclipse.hawkbit.repository.TenantConfigurationManagement; +import org.eclipse.hawkbit.repository.jpa.SystemManagement; import org.eclipse.hawkbit.im.authentication.TenantUserPasswordAuthenticationToken; import org.eclipse.hawkbit.im.authentication.UserAuthenticationFilter; -import org.eclipse.hawkbit.repository.ControllerManagement; -import org.eclipse.hawkbit.repository.SystemManagement; -import org.eclipse.hawkbit.repository.TenantConfigurationManagement; import org.eclipse.hawkbit.rest.resource.RestConstants; import org.eclipse.hawkbit.security.ControllerTenantAwareAuthenticationDetailsSource; import org.eclipse.hawkbit.security.DdiSecurityProperties; diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java index f26d7f3f7..3756688c2 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java +++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java @@ -371,18 +371,18 @@ public class AmqpMessageHandlerService extends BaseAmqpService { logAndThrowMessageError(message, "Status for action does not exisit."); } - final Action addUpdateActionStatus = getUpdateActionStatus(action, actionStatus); + final Action addUpdateActionStatus = getUpdateActionStatus(actionStatus); if (!addUpdateActionStatus.isActive()) { lookIfUpdateAvailable(action.getTarget()); } } - private Action getUpdateActionStatus(final Action action, final ActionStatus actionStatus) { + private Action getUpdateActionStatus(final ActionStatus actionStatus) { if (actionStatus.getStatus().equals(Status.CANCELED)) { - return controllerManagement.addCancelActionStatus(actionStatus, action); + return controllerManagement.addCancelActionStatus(actionStatus); } - return controllerManagement.addUpdateActionStatus(actionStatus, action); + return controllerManagement.addUpdateActionStatus(actionStatus); } private Action checkActionExist(final Message message, final ActionUpdateStatus actionUpdateStatus) { diff --git a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java index 3051e4e22..e057144df 100644 --- a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java +++ b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java @@ -346,7 +346,7 @@ public class AmqpMessageHandlerServiceTest { // Mock final Action action = createActionWithTarget(22L, Status.FINISHED); when(controllerManagementMock.findActionWithDetails(Matchers.any())).thenReturn(action); - when(controllerManagementMock.addUpdateActionStatus(Matchers.any(), Matchers.any())).thenReturn(action); + when(controllerManagementMock.addUpdateActionStatus(Matchers.any())).thenReturn(action); // for the test the same action can be used final List actionList = new ArrayList<>(); actionList.add(action); diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ArtifactManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ArtifactManagement.java index 977b9f171..19f3bcee2 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ArtifactManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ArtifactManagement.java @@ -32,8 +32,6 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.hateoas.Identifiable; import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.transaction.annotation.Isolation; -import org.springframework.transaction.annotation.Transactional; /** * Service for {@link Artifact} management operations. @@ -99,11 +97,8 @@ public interface ArtifactManagement { * @throw ArtifactUploadFailedException if upload fails */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - default LocalArtifact createLocalArtifact(final InputStream inputStream, final Long moduleId, final String filename, - final boolean overrideExisting) { - return createLocalArtifact(inputStream, moduleId, filename, null, null, overrideExisting, null); - } + LocalArtifact createLocalArtifact(@NotNull InputStream inputStream, @NotNull Long moduleId, final String filename, + final boolean overrideExisting); /** * Persists artifact binary as provided by given InputStream. assign the @@ -126,11 +121,8 @@ public interface ArtifactManagement { * @throw ArtifactUploadFailedException if upload fails */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - default LocalArtifact createLocalArtifact(final InputStream inputStream, final Long moduleId, final String filename, - final boolean overrideExisting, final String contentType) { - return createLocalArtifact(inputStream, moduleId, filename, null, null, overrideExisting, contentType); - } + LocalArtifact createLocalArtifact(@NotNull InputStream inputStream, @NotNull Long moduleId, + @NotNull String filename, final boolean overrideExisting, @NotNull String contentType); /** * Persists artifact binary as provided by given InputStream. assign the @@ -282,14 +274,7 @@ public interface ArtifactManagement { * @return the found {@link SoftwareModule}s */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - default SoftwareModule findSoftwareModuleWithDetails(@NotNull final Long id) { - final SoftwareModule result = findSoftwareModuleById(id); - if (result != null) { - result.getArtifacts().size(); - } - - return result; - } + SoftwareModule findSoftwareModuleWithDetails(@NotNull Long id); /** * Loads {@link org.eclipse.hawkbit.artifact.server.json.model.Artifact} @@ -307,4 +292,4 @@ public interface ArtifactManagement { + SpringEvalExpressions.HAS_CONTROLLER_DOWNLOAD) DbArtifact loadLocalArtifactBinary(@NotNull LocalArtifact artifact); -} \ No newline at end of file +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java index b70ad3bdd..2b18ab7ff 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java @@ -249,9 +249,7 @@ public interface ControllerManagement { */ @PreAuthorize(SpringEvalExpressions.IS_CONTROLLER) @Transactional(isolation = Isolation.READ_UNCOMMITTED) - default TargetInfo updateLastTargetQuery(@NotNull final TargetInfo target, @NotNull final URI address) { - return updateTargetStatus(target, null, System.currentTimeMillis(), address); - } + TargetInfo updateLastTargetQuery(@NotNull TargetInfo target, @NotNull URI address); /** * Update selective the target status of a given {@code target}. @@ -273,4 +271,4 @@ public interface ControllerManagement { TargetInfo updateTargetStatus(@NotNull TargetInfo targetInfo, TargetUpdateStatus status, Long lastTargetQuery, URI address); -} \ No newline at end of file +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java index 789383ce7..cffc3b8ad 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java @@ -8,9 +8,7 @@ */ package org.eclipse.hawkbit.repository; -import java.util.Arrays; import java.util.List; -import java.util.stream.Collectors; import javax.validation.constraints.NotNull; @@ -82,14 +80,8 @@ public interface DeploymentManagement { * {@link DistributionSetType}. */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_UPDATE_TARGET) - // Exception squid:S2095: see - // https://jira.sonarsource.com/browse/SONARJAVA-1478 - @SuppressWarnings({ "squid:S2095" }) - default DistributionSetAssignmentResult assignDistributionSet(@NotNull final Long dsID, final ActionType actionType, - final long forcedTimestamp, @NotEmpty final String... targetIDs) { - return assignDistributionSet(dsID, Arrays.stream(targetIDs) - .map(t -> new TargetWithActionType(t, actionType, forcedTimestamp)).collect(Collectors.toList())); - } + DistributionSetAssignmentResult assignDistributionSet(@NotNull final Long dsID, final ActionType actionType, + final long forcedTimestamp, @NotEmpty final String... targetIDs); /** * method assigns the {@link DistributionSet} to all {@link Target}s by @@ -154,10 +146,7 @@ public interface DeploymentManagement { * {@link DistributionSetType}. */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_UPDATE_TARGET) - default DistributionSetAssignmentResult assignDistributionSet(@NotNull final Long dsID, - @NotEmpty final String... targetIDs) { - return assignDistributionSet(dsID, ActionType.FORCED, Action.NO_FORCE_TIME, targetIDs); - } + DistributionSetAssignmentResult assignDistributionSet(@NotNull Long dsID, @NotEmpty String... targetIDs); /** * Cancels given {@link Action} for given {@link Target}. The method will @@ -450,4 +439,4 @@ public interface DeploymentManagement { + SpringEvalExpressions.IS_SYSTEM_CODE) Action startScheduledAction(@NotNull Action action); -} \ No newline at end of file +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetFilter.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetFilter.java index a545209e4..728a4d0c5 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetFilter.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetFilter.java @@ -14,9 +14,6 @@ import org.eclipse.hawkbit.repository.model.DistributionSetType; /** * Holds distribution set filter parameters. - * - * - * */ public final class DistributionSetFilter { private final Boolean isDeleted; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java index 965ecd9f6..bea9f2719 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java @@ -11,7 +11,6 @@ package org.eclipse.hawkbit.repository; import java.util.Collection; import java.util.List; import java.util.Set; -import java.util.stream.Collectors; import javax.persistence.Entity; import javax.validation.constraints.NotNull; @@ -163,9 +162,7 @@ public interface DistributionSetManagement { */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) @Transactional(isolation = Isolation.READ_UNCOMMITTED) - default List createDistributionSetTypes(@NotNull final Collection types) { - return types.stream().map(this::createDistributionSetType).collect(Collectors.toList()); - } + List createDistributionSetTypes(@NotNull Collection types); /** *

@@ -183,10 +180,7 @@ public interface DistributionSetManagement { * to delete */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY) - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - default void deleteDistributionSet(@NotNull final DistributionSet set) { - deleteDistributionSet(set.getId()); - } + void deleteDistributionSet(@NotNull DistributionSet set); /** * Deleted {@link DistributionSet}s by their IDs. That is either a soft @@ -235,11 +229,8 @@ public interface DistributionSetManagement { * to look for. * @return {@link DistributionSet} or null if it does not exist */ - @Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - default DistributionSet findDistributionSetById(@NotNull final Long distid) { - return findDistributionSetByIdWithDetails(distid); - } + DistributionSet findDistributionSetById(@NotNull Long distid); /** * Find {@link DistributionSet} based on given ID including (lazy loaded) @@ -487,11 +478,8 @@ public interface DistributionSetManagement { * the assignment outcome. */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - default DistributionSetTagAssignmentResult toggleTagAssignment(@NotEmpty final Collection sets, - @NotNull final DistributionSetTag tag) { - return toggleTagAssignment(sets.stream().map(ds -> ds.getId()).collect(Collectors.toList()), tag.getName()); - } + DistributionSetTagAssignmentResult toggleTagAssignment(@NotEmpty Collection sets, + @NotNull DistributionSetTag tag); /** * Toggles {@link DistributionSetTag} assignment to given @@ -588,4 +576,4 @@ public interface DistributionSetManagement { @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) DistributionSetType updateDistributionSetType(@NotNull DistributionSetType dsType); -} \ No newline at end of file +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ReportManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ReportManagement.java index 40ee21d9b..6208d395c 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ReportManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ReportManagement.java @@ -206,4 +206,4 @@ public interface ReportManagement { } -} \ No newline at end of file +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupManagement.java index 7c5503c19..9654b8368 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupManagement.java @@ -21,6 +21,10 @@ import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.domain.Specification; import org.springframework.security.access.prepost.PreAuthorize; +/** + * Repository management service for RolloutGroup. + * + */ public interface RolloutGroupManagement { /** diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java index bf4924692..357108576 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java @@ -335,4 +335,4 @@ public interface RolloutManagement { @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) float getFinishedPercentForRunningGroup(@NotNull Long rolloutId, @NotNull RolloutGroup rolloutGroup); -} \ No newline at end of file +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutScheduler.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutScheduler.java index 03ece28ee..1d4150217 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutScheduler.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutScheduler.java @@ -32,7 +32,7 @@ import org.springframework.stereotype.Component; @Profile("!test") public class RolloutScheduler { - private static final Logger logger = LoggerFactory.getLogger(RolloutScheduler.class); + private static final Logger LOGGER = LoggerFactory.getLogger(RolloutScheduler.class); @Autowired private TenantAware tenantAware; @@ -57,7 +57,7 @@ public class RolloutScheduler { */ @Scheduled(initialDelayString = RolloutProperties.Scheduler.PROP_SCHEDULER_DELAY_PLACEHOLDER, fixedDelayString = RolloutProperties.Scheduler.PROP_SCHEDULER_DELAY_PLACEHOLDER) public void rolloutScheduler() { - logger.debug("rollout schedule checker has been triggered."); + LOGGER.debug("rollout schedule checker has been triggered."); // run this code in system code privileged to have the necessary // permission to query and create entities. systemSecurityContext.runAsSystem(() -> { @@ -68,7 +68,7 @@ public class RolloutScheduler { // iterate through all tenants and execute the rollout check for // each tenant seperately. final List tenants = systemManagement.findTenants(); - logger.info("Checking rollouts for {} tenants", tenants.size()); + LOGGER.info("Checking rollouts for {} tenants", tenants.size()); for (final String tenant : tenants) { tenantAware.runAsTenant(tenant, () -> { rolloutManagement.checkRunningRollouts(rolloutProperties.getScheduler().getFixedDelay()); diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java new file mode 100644 index 000000000..063a3a0f1 --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java @@ -0,0 +1,471 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository; + +import java.util.Collection; +import java.util.List; + +import javax.persistence.Entity; +import javax.validation.constraints.NotNull; + +import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; +import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; +import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; +import org.eclipse.hawkbit.repository.model.CustomSoftwareModule; +import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.SoftwareModule; +import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata; +import org.eclipse.hawkbit.repository.model.SoftwareModuleType; +import org.eclipse.hawkbit.repository.model.SwMetadataCompositeKey; +import org.hibernate.validator.constraints.NotEmpty; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.security.access.prepost.PreAuthorize; + +/** + * Service for managing {@link SoftwareModule}s. + * + */ +public interface SoftwareManagement { + + /** + * Updates existing {@link SoftwareModule}. Update-able values are + * {@link SoftwareModule#getDescription()} + * {@link SoftwareModule#getVendor()}. + * + * @param sm + * to update + * + * @return the saved {@link Entity}. + * + * @throws NullPointerException + * of {@link SoftwareModule#getId()} is null + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) + SoftwareModule updateSoftwareModule(@NotNull SoftwareModule sm); + + /** + * Updates existing {@link SoftwareModuleType}. Update-able value is + * {@link SoftwareModuleType#getDescription()} and + * {@link SoftwareModuleType#getColour()}. + * + * @param sm + * to update + * @return updated {@link Entity} + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) + SoftwareModuleType updateSoftwareModuleType(@NotNull SoftwareModuleType sm); + + /** + * + * @param swModule + * SoftwareModule to create + * @return SoftwareModule + * @throws EntityAlreadyExistsException + * if a given entity already exists + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) + SoftwareModule createSoftwareModule(@NotNull SoftwareModule swModule); + + /** + * Create {@link SoftwareModule}s in the repository. + * + * @param swModules + * {@link SoftwareModule}s to create + * @return SoftwareModule + * @throws EntityAlreadyExistsException + * if a given entity already exists + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) + List createSoftwareModule(@NotNull Iterable swModules); + + /** + * retrieves the {@link SoftwareModule}s by their {@link SoftwareModuleType} + * . + * + * @param pageable + * page parameters + * @param type + * to be filtered on + * @return the found {@link SoftwareModule}s + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + Slice findSoftwareModulesByType(@NotNull Pageable pageable, @NotNull SoftwareModuleType type); + + /** + * Counts {@link SoftwareModule}s with given {@link SoftwareModuleType}. + * + * @param type + * to count + * @return number of found {@link SoftwareModule}s + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + Long countSoftwareModulesByType(@NotNull SoftwareModuleType type); + + /** + * Finds {@link SoftwareModule} by given id. + * + * @param id + * to search for + * @return the found {@link SoftwareModule}s or null if not + * found. + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY + SpringEvalExpressions.HAS_AUTH_OR + + SpringEvalExpressions.IS_CONTROLLER) + SoftwareModule findSoftwareModuleById(@NotNull Long id); + + /** + * retrieves {@link SoftwareModule} by their name AND version AND type.. + * + * @param name + * of the {@link SoftwareModule} + * @param version + * of the {@link SoftwareModule} + * @param type + * of the {@link SoftwareModule} + * @return the found {@link SoftwareModule} or null + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + SoftwareModule findSoftwareModuleByNameAndVersion(@NotEmpty String name, @NotEmpty String version, + @NotNull SoftwareModuleType type); + + /** + * Deletes the given {@link SoftwareModule} {@link Entity}. + * + * @param bsm + * is the {@link SoftwareModule} to be deleted + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY) + void deleteSoftwareModule(@NotNull SoftwareModule bsm); + + /** + * Deletes {@link SoftwareModule}s which is any if the given ids. + * + * @param ids + * of the Software Modules to be deleted + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY) + void deleteSoftwareModules(@NotNull Iterable ids); + + /** + * Retrieves all software modules. Deleted ones are filtered. + * + * @param pageable + * pagination parameter + * @return the found {@link SoftwareModule}s + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + Slice findSoftwareModulesAll(@NotNull Pageable pageable); + + /** + * Count all {@link SoftwareModule}s in the repository that are not marked + * as deleted. + * + * @return number of {@link SoftwareModule}s + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + Long countSoftwareModulesAll(); + + /** + * Retrieves software module including details ( + * {@link SoftwareModule#getArtifacts()}). + * + * @param id + * parameter + * @param isDeleted + * parameter + * @return the found {@link SoftwareModule}s + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + SoftwareModule findSoftwareModuleWithDetails(@NotNull Long id); + + /** + * Retrieves all {@link SoftwareModule}s with a given specification. + * + * @param spec + * the specification to filter the software modules + * @param pageable + * pagination parameter + * @return the found {@link SoftwareModule}s + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + Page findSoftwareModulesByPredicate(@NotNull Specification spec, + @NotNull Pageable pageable); + + /** + * Retrieves all {@link SoftwareModuleType}s with a given specification. + * + * @param spec + * the specification to filter the software modules types + * @param pageable + * pagination parameter + * @return the found {@link SoftwareModuleType}s + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + Page findSoftwareModuleTypesByPredicate(@NotNull Specification spec, + @NotNull Pageable pageable); + + /** + * Retrieves all software modules with a given list of ids + * {@link SoftwareModule#getId()}. + * + * @param ids + * to search for + * @return {@link List} of found {@link SoftwareModule}s + */ + List findSoftwareModulesById(@NotEmpty Collection ids); + + /** + * Filter {@link SoftwareModule}s with given + * {@link SoftwareModule#getName()} or {@link SoftwareModule#getVersion()} + * and {@link SoftwareModule#getType()} that are not marked as deleted. + * + * @param pageable + * page parameter + * @param searchText + * to be filtered as "like" on {@link SoftwareModule#getName()} + * @param type + * to be filtered as "like" on {@link SoftwareModule#getType()} + * @return the page of found {@link SoftwareModule} + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + Slice findSoftwareModuleByFilters(@NotNull Pageable pageable, String searchText, + SoftwareModuleType type); + + /** + * Filter {@link SoftwareModule}s with given + * {@link SoftwareModule#getName()} or {@link SoftwareModule#getVersion()} + * search text and {@link SoftwareModule#getType()} that are not marked as + * deleted and sort them by means of given distribution set related modules + * on top of the list. + * + * After that the modules are sorted by {@link SoftwareModule#getName()} and + * {@link SoftwareModule#getVersion()} in ascending order. + * + * @param pageable + * page parameter + * @param orderByDistributionId + * the ID of distribution set to be ordered on top + * @param searchText + * filtered as "like" on {@link SoftwareModule#getName()} + * @param type + * filtered as "equal" on {@link SoftwareModule#getType()} + * @return the page of found {@link SoftwareModule} + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + Slice findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc( + @NotNull Pageable pageable, @NotNull Long orderByDistributionId, String searchText, + SoftwareModuleType type); + + /** + * Counts {@link SoftwareModule}s with given + * {@link SoftwareModule#getName()} or {@link SoftwareModule#getVersion()} + * and {@link SoftwareModule#getType()} that are not marked as deleted. + * + * @param searchText + * to search for in name and version + * @param type + * to filter the result + * @return number of found {@link SoftwareModule}s + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + Long countSoftwareModuleByFilters(String searchText, SoftwareModuleType type); + + /** + * @param pageable + * parameter + * @return all {@link SoftwareModuleType}s in the repository. + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + Page findSoftwareModuleTypesAll(@NotNull Pageable pageable); + + /** + * @return number of {@link SoftwareModuleType}s in the repository. + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + Long countSoftwareModuleTypesAll(); + + /** + * + * @param key + * to search for + * @return {@link SoftwareModuleType} in the repository with given + * {@link SoftwareModuleType#getKey()} + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + SoftwareModuleType findSoftwareModuleTypeByKey(@NotNull String key); + + /** + * + * @param id + * to search for + * @return {@link SoftwareModuleType} in the repository with given + * {@link SoftwareModuleType#getId()} + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + SoftwareModuleType findSoftwareModuleTypeById(@NotNull Long id); + + /** + * + * @param name + * to search for + * @return all {@link SoftwareModuleType}s in the repository with given + * {@link SoftwareModuleType#getName()} + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + SoftwareModuleType findSoftwareModuleTypeByName(@NotNull String name); + + /** + * Creates new {@link SoftwareModuleType}. + * + * @param type + * to create + * @return created {@link Entity} + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) + SoftwareModuleType createSoftwareModuleType(@NotNull SoftwareModuleType type); + + /** + * Creates multiple {@link SoftwareModuleType}s. + * + * @param types + * to create + * @return created {@link Entity} + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) + List createSoftwareModuleType(@NotNull final Collection types); + + /** + * Deletes or marks as delete in case the type is in use. + * + * @param type + * to delete + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY) + void deleteSoftwareModuleType(@NotNull SoftwareModuleType type); + + /** + * @param pageable + * the page request to page the result set + * @param set + * to search for + * @return all {@link SoftwareModule}s that are assigned to given + * {@link DistributionSet}. + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + Page findSoftwareModuleByAssignedTo(@NotNull Pageable pageable, @NotNull DistributionSet set); + + /** + * @param pageable + * the page request to page the result set + * @param set + * to search for + * @param type + * to filter + * @return all {@link SoftwareModule}s that are assigned to given + * {@link DistributionSet} filtered by {@link SoftwareModuleType}. + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + Page findSoftwareModuleByAssignedToAndType(@NotNull Pageable pageable, @NotNull DistributionSet set, + @NotNull SoftwareModuleType type); + + /** + * creates or updates a single software module meta data entry. + * + * @param metadata + * the meta data entry to create or update + * @return the updated or created software module meta data entry + * @throws EntityAlreadyExistsException + * in case the meta data entry already exists for the specific + * key + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) + SoftwareModuleMetadata createSoftwareModuleMetadata(@NotNull SoftwareModuleMetadata metadata); + + /** + * creates a list of software module meta data entries. + * + * @param metadata + * the meta data entries to create or update + * @return the updated or created software module meta data entries + * @throws EntityAlreadyExistsException + * in case one of the meta data entry already exists for the + * specific key + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) + List createSoftwareModuleMetadata(@NotNull Collection metadata); + + /** + * updates a distribution set meta data value if corresponding entry exists. + * + * @param metadata + * the meta data entry to be updated + * @return the updated meta data entry + * @throws EntityNotFoundException + * in case the meta data entry does not exists and cannot be + * updated + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) + SoftwareModuleMetadata updateSoftwareModuleMetadata(@NotNull SoftwareModuleMetadata metadata); + + /** + * deletes a software module meta data entry. + * + * @param id + * the ID of the software module meta data to delete + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) + void deleteSoftwareModuleMetadata(@NotNull SwMetadataCompositeKey id); + + /** + * finds all meta data by the given software module id. + * + * @param swId + * the software module id to retrieve the meta data from + * @param pageable + * the page request to page the result + * @return a paged result of all meta data entries for a given software + * module id + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + Page findSoftwareModuleMetadataBySoftwareModuleId(@NotNull Long swId, + @NotNull Pageable pageable); + + /** + * finds all meta data by the given software module id. + * + * @param softwareModuleId + * the software module id to retrieve the meta data from + * @param spec + * the specification to filter the result + * @param pageable + * the page request to page the result + * @return a paged result of all meta data entries for a given software + * module id + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + Page findSoftwareModuleMetadataBySoftwareModuleId(@NotNull Long softwareModuleId, + @NotNull Specification spec, @NotNull Pageable pageable); + + /** + * finds a single software module meta data by its id. + * + * @param id + * the id of the software module meta data containing the meta + * data key and the ID of the software module + * @return the found SoftwareModuleMetadata or {@code null} if not exits + * @throws EntityNotFoundException + * in case the meta data does not exists for the given key + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + SoftwareModuleMetadata findSoftwareModuleMetadata(@NotNull SwMetadataCompositeKey id); + +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantConfigurationManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantConfigurationManagement.java index 10a88b232..a5eaf4006 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantConfigurationManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantConfigurationManagement.java @@ -1,3 +1,11 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ package org.eclipse.hawkbit.repository; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; @@ -9,6 +17,10 @@ import org.springframework.core.convert.ConversionFailedException; import org.springframework.core.env.Environment; import org.springframework.security.access.prepost.PreAuthorize; +/** + * Management service for tenant configurations. + * + */ public interface TenantConfigurationManagement { /** @@ -131,4 +143,4 @@ public interface TenantConfigurationManagement { @PreAuthorize(value = SpringEvalExpressions.HAS_AUTH_TENANT_CONFIGURATION) void deleteConfiguration(TenantConfigurationKey configurationKey); -} \ No newline at end of file +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/DeploymentHelper.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/DeploymentHelper.java new file mode 100644 index 000000000..adcca7c73 --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/DeploymentHelper.java @@ -0,0 +1,100 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.jpa; + +import java.util.List; +import java.util.stream.Collectors; + +import javax.persistence.EntityManager; +import javax.validation.constraints.NotNull; + +import org.eclipse.hawkbit.repository.model.Action; +import org.eclipse.hawkbit.repository.model.Action.Status; +import org.eclipse.hawkbit.repository.model.Target; +import org.eclipse.hawkbit.repository.model.TargetInfo; +import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; + +/** + * Utility class for deployment related topics. + * + */ +public final class DeploymentHelper { + + private DeploymentHelper() { + // utility class + } + + /** + * Internal helper method used only inside service level. As a result is no + * additional security necessary. + * + * @param target + * to update + * @param status + * of the target + * @param setInstalledDate + * to set + * @param entityManager + * for the operation + * @param targetInfoRepository + * for the operation + * + * @return updated target + */ + static Target updateTargetInfo(@NotNull final Target target, @NotNull final TargetUpdateStatus status, + final boolean setInstalledDate, final TargetInfoRepository targetInfoRepository, + final EntityManager entityManager) { + final TargetInfo ts = target.getTargetInfo(); + ts.setUpdateStatus(status); + + if (setInstalledDate) { + ts.setInstallationDate(System.currentTimeMillis()); + } + targetInfoRepository.save(ts); + return entityManager.merge(target); + } + + /** + * This method is called, when cancellation has been successful. It sets the + * action to canceled, resets the meta data of the target and in case there + * is a new action this action is triggered. + * + * @param action + * the action which is set to canceled + * @param actionRepository + * for the operation + * @param targetManagement + * for the operation + * @param entityManager + * for the operation + * @param targetInfoRepository + * for the operation + */ + static void successCancellation(final Action action, final ActionRepository actionRepository, + final TargetManagement targetManagement, final TargetInfoRepository targetInfoRepository, + final EntityManager entityManager) { + + // set action inactive + action.setActive(false); + action.setStatus(Status.CANCELED); + + final Target target = action.getTarget(); + final List nextActiveActions = actionRepository.findByTargetAndActiveOrderByIdAsc(target, true).stream() + .filter(a -> !a.getId().equals(action.getId())).collect(Collectors.toList()); + + if (nextActiveActions.isEmpty()) { + target.setAssignedDistributionSet(target.getTargetInfo().getInstalledDistributionSet()); + updateTargetInfo(target, TargetUpdateStatus.IN_SYNC, false, targetInfoRepository, entityManager); + } else { + target.setAssignedDistributionSet(nextActiveActions.get(0).getDistributionSet()); + } + targetManagement.updateTarget(target); + } + +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaArtifactManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaArtifactManagement.java index c6d30208c..7bae73a8b 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaArtifactManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaArtifactManagement.java @@ -267,4 +267,20 @@ public class JpaArtifactManagement implements ArtifactManagement { LOG.debug("storing new artifact into repository {}", artifact); return localArtifactRepository.save(artifact); } + + @Override + @Modifying + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + public LocalArtifact createLocalArtifact(final InputStream inputStream, final Long moduleId, final String filename, + final boolean overrideExisting) { + return createLocalArtifact(inputStream, moduleId, filename, null, null, overrideExisting, null); + } + + @Override + @Modifying + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + public LocalArtifact createLocalArtifact(final InputStream inputStream, final Long moduleId, final String filename, + final boolean overrideExisting, final String contentType) { + return createLocalArtifact(inputStream, moduleId, filename, null, null, overrideExisting, contentType); + } } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java index 76363cca9..8834b2ae0 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java @@ -409,9 +409,15 @@ public class JpaControllerManagement implements ControllerManagement { } @Override - @Transactional(isolation = Isolation.READ_UNCOMMITTED) public String getSecurityTokenByControllerId(final String controllerId) { final Target target = targetRepository.findByControllerId(controllerId); return target != null ? target.getSecurityToken() : null; } + + @Override + @Modifying + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + public TargetInfo updateLastTargetQuery(final TargetInfo target, final URI address) { + return updateTargetStatus(target, null, System.currentTimeMillis(), address); + } } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java index 50bbd2d31..d905fb7b1 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java @@ -133,7 +133,6 @@ public class JpaDeploymentManagement implements DeploymentManagement { @Override @Modifying @Transactional(isolation = Isolation.READ_COMMITTED) - @CacheEvict(value = { "distributionUsageAssigned" }, allEntries = true) public DistributionSetAssignmentResult assignDistributionSet(final Long dsID, final String... targetIDs) { return assignDistributionSet(dsID, ActionType.FORCED, Action.NO_FORCE_TIME, targetIDs); diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java index 160cf613c..d045cd549 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java @@ -18,14 +18,15 @@ import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; import javax.persistence.EntityManager; import org.eclipse.hawkbit.eventbus.event.DistributionSetTagAssigmentResultEvent; import org.eclipse.hawkbit.executor.AfterTransactionCommitExecutor; import org.eclipse.hawkbit.repository.DistributionSetFilter; -import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.DistributionSetFilter.DistributionSetFilterBuilder; +import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.exception.EntityLockedException; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; @@ -660,4 +661,26 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { distributionSets.forEach(ds -> ds.getTags().remove(tag)); return distributionSetRepository.save(distributionSets); } + + @Override + @Modifying + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + public List createDistributionSetTypes(final Collection types) { + return types.stream().map(this::createDistributionSetType).collect(Collectors.toList()); + } + + @Override + @Modifying + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + public void deleteDistributionSet(final DistributionSet set) { + deleteDistributionSet(set.getId()); + } + + @Override + @Modifying + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + public DistributionSetTagAssignmentResult toggleTagAssignment(final Collection sets, + final DistributionSetTag tag) { + return toggleTagAssignment(sets.stream().map(ds -> ds.getId()).collect(Collectors.toList()), tag.getName()); + } } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java similarity index 55% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareManagement.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java index 813f2e5a6..a3566f07f 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java @@ -17,17 +17,16 @@ import java.util.List; import java.util.Set; import java.util.stream.Collectors; -import javax.persistence.Entity; import javax.persistence.EntityManager; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.ListJoin; import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Root; -import javax.validation.constraints.NotNull; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; import org.eclipse.hawkbit.repository.ArtifactManagement; +import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.model.CustomSoftwareModule; @@ -42,7 +41,6 @@ import org.eclipse.hawkbit.repository.model.SoftwareModule_; import org.eclipse.hawkbit.repository.model.SwMetadataCompositeKey; import org.eclipse.hawkbit.repository.specifications.SoftwareModuleSpecification; import org.eclipse.hawkbit.repository.specifications.SpecificationsBuilder; -import org.hibernate.validator.constraints.NotEmpty; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.AuditorAware; import org.springframework.data.domain.Page; @@ -61,13 +59,13 @@ import com.google.common.base.Strings; import com.google.common.collect.Sets; /** - * Business facade for managing {@link SoftwareModule}s. + * JPA implementation of SoftwareManagement. * */ @Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) @Validated @Service -public class SoftwareManagement { +public class JpaSoftwareManagement implements SoftwareManagement { @Autowired private EntityManager entityManager; @@ -96,23 +94,10 @@ public class SoftwareManagement { @Autowired private ArtifactManagement artifactManagement; - /** - * Updates existing {@link SoftwareModule}. Update-able values are - * {@link SoftwareModule#getDescription()} - * {@link SoftwareModule#getVendor()}. - * - * @param sm - * to update - * - * @return the saved {@link Entity}. - * - * @throws NullPointerException - * of {@link SoftwareModule#getId()} is null - */ + @Override @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - public SoftwareModule updateSoftwareModule(@NotNull final SoftwareModule sm) { + public SoftwareModule updateSoftwareModule(final SoftwareModule sm) { checkNotNull(sm.getId()); final SoftwareModule module = softwareModuleRepository.findOne(sm.getId()); @@ -130,19 +115,10 @@ public class SoftwareManagement { return updated ? softwareModuleRepository.save(module) : module; } - /** - * Updates existing {@link SoftwareModuleType}. Update-able value is - * {@link SoftwareModuleType#getDescription()} and - * {@link SoftwareModuleType#getColour()}. - * - * @param sm - * to update - * @return updated {@link Entity} - */ + @Override @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - public SoftwareModuleType updateSoftwareModuleType(@NotNull final SoftwareModuleType sm) { + public SoftwareModuleType updateSoftwareModuleType(final SoftwareModuleType sm) { checkNotNull(sm.getId()); final SoftwareModuleType type = softwareModuleTypeRepository.findOne(sm.getId()); @@ -159,37 +135,20 @@ public class SoftwareManagement { return updated ? softwareModuleTypeRepository.save(type) : type; } - /** - * - * @param swModule - * SoftwareModule to create - * @return SoftwareModule - * @throws EntityAlreadyExistsException - * if a given entity already exists - */ + @Override @Modifying - @Transactional - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) - public SoftwareModule createSoftwareModule(@NotNull final SoftwareModule swModule) { + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + public SoftwareModule createSoftwareModule(final SoftwareModule swModule) { if (null != swModule.getId()) { throw new EntityAlreadyExistsException(); } return softwareModuleRepository.save(swModule); } - /** - * Create {@link SoftwareModule}s in the repository. - * - * @param swModules - * {@link SoftwareModule}s to create - * @return SoftwareModule - * @throws EntityAlreadyExistsException - * if a given entity already exists - */ + @Override @Modifying - @Transactional - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) - public List createSoftwareModule(@NotNull final Iterable swModules) { + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + public List createSoftwareModule(final Iterable swModules) { swModules.forEach(swModule -> { if (null != swModule.getId()) { throw new EntityAlreadyExistsException(); @@ -200,19 +159,8 @@ public class SoftwareManagement { } - /** - * retrieves the {@link SoftwareModule}s by their {@link SoftwareModuleType} - * . - * - * @param pageable - * page parameters - * @param type - * to be filtered on - * @return the found {@link SoftwareModule}s - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - public Slice findSoftwareModulesByType(@NotNull final Pageable pageable, - @NotNull final SoftwareModuleType type) { + @Override + public Slice findSoftwareModulesByType(final Pageable pageable, final SoftwareModuleType type) { final List> specList = new ArrayList<>(); @@ -225,15 +173,8 @@ public class SoftwareManagement { return findSwModuleByCriteriaAPI(pageable, specList); } - /** - * Counts {@link SoftwareModule}s with given {@link SoftwareModuleType}. - * - * @param type - * to count - * @return number of found {@link SoftwareModule}s - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - public Long countSoftwareModulesByType(@NotNull final SoftwareModuleType type) { + @Override + public Long countSoftwareModulesByType(final SoftwareModuleType type) { final List> specList = new ArrayList<>(); @@ -246,63 +187,29 @@ public class SoftwareManagement { return countSwModuleByCriteriaAPI(specList); } - /** - * Finds {@link SoftwareModule} by given id. - * - * @param id - * to search for - * @return the found {@link SoftwareModule}s or null if not - * found. - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY + SpringEvalExpressions.HAS_AUTH_OR - + SpringEvalExpressions.IS_CONTROLLER) - public SoftwareModule findSoftwareModuleById(@NotNull final Long id) { + @Override + public SoftwareModule findSoftwareModuleById(final Long id) { return artifactManagement.findSoftwareModuleById(id); } - /** - * retrieves {@link SoftwareModule} by their name AND version AND type.. - * - * @param name - * of the {@link SoftwareModule} - * @param version - * of the {@link SoftwareModule} - * @param type - * of the {@link SoftwareModule} - * @return the found {@link SoftwareModule} or null - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - public SoftwareModule findSoftwareModuleByNameAndVersion(@NotEmpty final String name, - @NotEmpty final String version, @NotNull final SoftwareModuleType type) { + @Override + public SoftwareModule findSoftwareModuleByNameAndVersion(final String name, final String version, + final SoftwareModuleType type) { return softwareModuleRepository.findOneByNameAndVersionAndType(name, version, type); } - /** - * Deletes the given {@link SoftwareModule} {@link Entity}. - * - * @param bsm - * is the {@link SoftwareModule} to be deleted - */ - @Modifying - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY) - public void deleteSoftwareModule(@NotNull final SoftwareModule bsm) { - - deleteSoftwareModules(Sets.newHashSet(bsm.getId())); - } - private boolean isUnassigned(final SoftwareModule bsmMerged) { return distributionSetRepository.findByModules(bsmMerged).isEmpty(); } - private Slice findSwModuleByCriteriaAPI(@NotNull final Pageable pageable, - @NotEmpty final List> specList) { + private Slice findSwModuleByCriteriaAPI(final Pageable pageable, + final List> specList) { return criteriaNoCountDao.findAll(SpecificationsBuilder.combineWithAnd(specList), pageable, SoftwareModule.class); } - private Long countSwModuleByCriteriaAPI(@NotEmpty final List> specList) { + private Long countSwModuleByCriteriaAPI(final List> specList) { return softwareModuleRepository.count(SpecificationsBuilder.combineWithAnd(specList)); } @@ -312,16 +219,10 @@ public class SoftwareManagement { } } - /** - * Deletes {@link SoftwareModule}s which is any if the given ids. - * - * @param ids - * of the Software Modules to be deleted - */ + @Override @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY) - public void deleteSoftwareModules(@NotNull final Iterable ids) { + public void deleteSoftwareModules(final Iterable ids) { final List swModulesToDelete = softwareModuleRepository.findByIdIn(ids); final Set assignedModuleIds = new HashSet<>(); swModulesToDelete.forEach(swModule -> { @@ -349,15 +250,8 @@ public class SoftwareManagement { } } - /** - * Retrieves all software modules. Deleted ones are filtered. - * - * @param pageable - * pagination parameter - * @return the found {@link SoftwareModule}s - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - public Slice findSoftwareModulesAll(@NotNull final Pageable pageable) { + @Override + public Slice findSoftwareModulesAll(final Pageable pageable) { final List> specList = new ArrayList<>(); @@ -376,13 +270,7 @@ public class SoftwareManagement { return findSwModuleByCriteriaAPI(pageable, specList); } - /** - * Count all {@link SoftwareModule}s in the repository that are not marked - * as deleted. - * - * @return number of {@link SoftwareModule}s - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + @Override public Long countSoftwareModulesAll() { final List> specList = new ArrayList<>(); @@ -393,79 +281,31 @@ public class SoftwareManagement { return countSwModuleByCriteriaAPI(specList); } - /** - * Retrieves software module including details ( - * {@link SoftwareModule#getArtifacts()}). - * - * @param id - * parameter - * @param isDeleted - * parameter - * @return the found {@link SoftwareModule}s - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - public SoftwareModule findSoftwareModuleWithDetails(@NotNull final Long id) { + @Override + public SoftwareModule findSoftwareModuleWithDetails(final Long id) { return artifactManagement.findSoftwareModuleWithDetails(id); } - /** - * Retrieves all {@link SoftwareModule}s with a given specification. - * - * @param spec - * the specification to filter the software modules - * @param pageable - * pagination parameter - * @return the found {@link SoftwareModule}s - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - public Page findSoftwareModulesByPredicate(@NotNull final Specification spec, - @NotNull final Pageable pageable) { + @Override + public Page findSoftwareModulesByPredicate(final Specification spec, + final Pageable pageable) { return softwareModuleRepository.findAll(spec, pageable); } - /** - * Retrieves all {@link SoftwareModuleType}s with a given specification. - * - * @param spec - * the specification to filter the software modules types - * @param pageable - * pagination parameter - * @return the found {@link SoftwareModuleType}s - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - public Page findSoftwareModuleTypesByPredicate( - @NotNull final Specification spec, @NotNull final Pageable pageable) { + @Override + public Page findSoftwareModuleTypesByPredicate(final Specification spec, + final Pageable pageable) { return softwareModuleTypeRepository.findAll(spec, pageable); } - /** - * Retrieves all software modules with a given list of ids - * {@link SoftwareModule#getId()}. - * - * @param ids - * to search for - * @return {@link List} of found {@link SoftwareModule}s - */ + @Override @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - public List findSoftwareModulesById(@NotEmpty final List ids) { + public List findSoftwareModulesById(final Collection ids) { return softwareModuleRepository.findByIdIn(ids); } - /** - * Filter {@link SoftwareModule}s with given - * {@link SoftwareModule#getName()} or {@link SoftwareModule#getVersion()} - * and {@link SoftwareModule#getType()} that are not marked as deleted. - * - * @param pageable - * page parameter - * @param searchText - * to be filtered as "like" on {@link SoftwareModule#getName()} - * @param type - * to be filtered as "like" on {@link SoftwareModule#getType()} - * @return the page of found {@link SoftwareModule} - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - public Slice findSoftwareModuleByFilters(@NotNull final Pageable pageable, final String searchText, + @Override + public Slice findSoftwareModuleByFilters(final Pageable pageable, final String searchText, final SoftwareModuleType type) { final List> specList = new ArrayList<>(); @@ -495,29 +335,9 @@ public class SoftwareManagement { return findSwModuleByCriteriaAPI(pageable, specList); } - /** - * Filter {@link SoftwareModule}s with given - * {@link SoftwareModule#getName()} or {@link SoftwareModule#getVersion()} - * search text and {@link SoftwareModule#getType()} that are not marked as - * deleted and sort them by means of given distribution set related modules - * on top of the list. - * - * After that the modules are sorted by {@link SoftwareModule#getName()} and - * {@link SoftwareModule#getVersion()} in ascending order. - * - * @param pageable - * page parameter - * @param orderByDistributionId - * the ID of distribution set to be ordered on top - * @param searchText - * filtered as "like" on {@link SoftwareModule#getName()} - * @param type - * filtered as "equal" on {@link SoftwareModule#getType()} - * @return the page of found {@link SoftwareModule} - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + @Override public Slice findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc( - @NotNull final Pageable pageable, @NotNull final Long orderByDistributionId, final String searchText, + final Pageable pageable, final Long orderByDistributionId, final String searchText, final SoftwareModuleType type) { final List resultList = new ArrayList<>(); @@ -594,9 +414,6 @@ public class SoftwareManagement { return specList; } - /** - * @param specifications - */ private Predicate[] specificationsToPredicate(final List> specifications, final Root root, final CriteriaQuery query, final CriteriaBuilder cb, final Predicate... additionalPredicates) { @@ -608,18 +425,7 @@ public class SoftwareManagement { return predicates.toArray(new Predicate[predicates.size()]); } - /** - * Counts {@link SoftwareModule}s with given - * {@link SoftwareModule#getName()} or {@link SoftwareModule#getVersion()} - * and {@link SoftwareModule#getType()} that are not marked as deleted. - * - * @param searchText - * to search for in name and version - * @param type - * to filter the result - * @return number of found {@link SoftwareModule}s - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + @Override public Long countSoftwareModuleByFilters(final String searchText, final SoftwareModuleType type) { final List> specList = new ArrayList<>(); @@ -640,71 +446,35 @@ public class SoftwareManagement { return countSwModuleByCriteriaAPI(specList); } - /** - * @param pageable - * parameter - * @return all {@link SoftwareModuleType}s in the repository. - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - public Page findSoftwareModuleTypesAll(@NotNull final Pageable pageable) { + @Override + public Page findSoftwareModuleTypesAll(final Pageable pageable) { return softwareModuleTypeRepository.findByDeleted(pageable, false); } - /** - * @return number of {@link SoftwareModuleType}s in the repository. - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + @Override public Long countSoftwareModuleTypesAll() { return softwareModuleTypeRepository.countByDeleted(false); } - /** - * - * @param key - * to search for - * @return {@link SoftwareModuleType} in the repository with given - * {@link SoftwareModuleType#getKey()} - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - public SoftwareModuleType findSoftwareModuleTypeByKey(@NotNull final String key) { + @Override + public SoftwareModuleType findSoftwareModuleTypeByKey(final String key) { return softwareModuleTypeRepository.findByKey(key); } - /** - * - * @param id - * to search for - * @return {@link SoftwareModuleType} in the repository with given - * {@link SoftwareModuleType#getId()} - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - public SoftwareModuleType findSoftwareModuleTypeById(@NotNull final Long id) { + @Override + public SoftwareModuleType findSoftwareModuleTypeById(final Long id) { return softwareModuleTypeRepository.findOne(id); } - /** - * - * @param name - * to search for - * @return all {@link SoftwareModuleType}s in the repository with given - * {@link SoftwareModuleType#getName()} - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - public SoftwareModuleType findSoftwareModuleTypeByName(@NotNull final String name) { + @Override + public SoftwareModuleType findSoftwareModuleTypeByName(final String name) { return softwareModuleTypeRepository.findByName(name); } - /** - * Creates new {@link SoftwareModuleType}. - * - * @param type - * to create - * @return created {@link Entity} - */ + @Override @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) - public SoftwareModuleType createSoftwareModuleType(@NotNull final SoftwareModuleType type) { + public SoftwareModuleType createSoftwareModuleType(final SoftwareModuleType type) { if (type.getId() != null) { throw new EntityAlreadyExistsException("Given type contains an Id!"); } @@ -712,30 +482,10 @@ public class SoftwareManagement { return softwareModuleTypeRepository.save(type); } - /** - * Creates multiple {@link SoftwareModuleType}s. - * - * @param types - * to create - * @return created {@link Entity} - */ + @Override @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) - public List createSoftwareModuleType(@NotNull final Collection types) { - return types.stream().map(this::createSoftwareModuleType).collect(Collectors.toList()); - } - - /** - * Deletes or markes as delete in case the type is in use. - * - * @param type - * to delete - */ - @Modifying - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY) - public void deleteSoftwareModuleType(@NotNull final SoftwareModuleType type) { + public void deleteSoftwareModuleType(final SoftwareModuleType type) { if (softwareModuleRepository.countByType(type) > 0 || distributionSetTypeRepository.countByElementsSmType(type) > 0) { @@ -747,50 +497,21 @@ public class SoftwareManagement { } } - /** - * @param pageable - * the page request to page the result set - * @param set - * to search for - * @return all {@link SoftwareModule}s that are assigned to given - * {@link DistributionSet}. - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - public Page findSoftwareModuleByAssignedTo(@NotNull final Pageable pageable, - @NotNull final DistributionSet set) { + @Override + public Page findSoftwareModuleByAssignedTo(final Pageable pageable, final DistributionSet set) { return softwareModuleRepository.findByAssignedTo(pageable, set); } - /** - * @param pageable - * the page request to page the result set - * @param set - * to search for - * @param type - * to filter - * @return all {@link SoftwareModule}s that are assigned to given - * {@link DistributionSet} filtered by {@link SoftwareModuleType}. - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - public Page findSoftwareModuleByAssignedToAndType(@NotNull final Pageable pageable, - @NotNull final DistributionSet set, @NotNull final SoftwareModuleType type) { + @Override + public Page findSoftwareModuleByAssignedToAndType(final Pageable pageable, + final DistributionSet set, final SoftwareModuleType type) { return softwareModuleRepository.findByAssignedToAndType(pageable, set, type); } - /** - * creates or updates a single software module meta data entry. - * - * @param metadata - * the meta data entry to create or update - * @return the updated or created software module meta data entry - * @throws EntityAlreadyExistsException - * in case the meta data entry already exists for the specific - * key - */ + @Override @Transactional(isolation = Isolation.READ_UNCOMMITTED) @Modifying - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - public SoftwareModuleMetadata createSoftwareModuleMetadata(@NotNull final SoftwareModuleMetadata metadata) { + public SoftwareModuleMetadata createSoftwareModuleMetadata(final SoftwareModuleMetadata metadata) { if (softwareModuleMetadataRepository.exists(metadata.getId())) { throwMetadataKeyAlreadyExists(metadata.getId().getKey()); } @@ -802,21 +523,11 @@ public class SoftwareManagement { return softwareModuleMetadataRepository.save(metadata); } - /** - * creates a list of software module meta data entries. - * - * @param metadata - * the meta data entries to create or update - * @return the updated or created software module meta data entries - * @throws EntityAlreadyExistsException - * in case one of the meta data entry already exists for the - * specific key - */ + @Override @Transactional(isolation = Isolation.READ_UNCOMMITTED) @Modifying - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) public List createSoftwareModuleMetadata( - @NotEmpty final Collection metadata) { + final Collection metadata) { for (final SoftwareModuleMetadata softwareModuleMetadata : metadata) { checkAndThrowAlreadyExistsIfSoftwareModuleMetadataExists(softwareModuleMetadata.getId()); } @@ -824,20 +535,10 @@ public class SoftwareManagement { return softwareModuleMetadataRepository.save(metadata); } - /** - * updates a distribution set meta data value if corresponding entry exists. - * - * @param metadata - * the meta data entry to be updated - * @return the updated meta data entry - * @throws EntityNotFoundException - * in case the meta data entry does not exists and cannot be - * updated - */ + @Override @Transactional(isolation = Isolation.READ_UNCOMMITTED) @Modifying - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - public SoftwareModuleMetadata updateSoftwareModuleMetadata(@NotNull final SoftwareModuleMetadata metadata) { + public SoftwareModuleMetadata updateSoftwareModuleMetadata(final SoftwareModuleMetadata metadata) { // check if exists otherwise throw entity not found exception findSoftwareModuleMetadata(metadata.getId()); // touch it to update the lock revision because we are modifying the @@ -847,50 +548,22 @@ public class SoftwareManagement { return softwareModuleMetadataRepository.save(metadata); } - /** - * deletes a software module meta data entry. - * - * @param id - * the ID of the software module meta data to delete - */ + @Override @Transactional(isolation = Isolation.READ_UNCOMMITTED) @Modifying - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - public void deleteSoftwareModuleMetadata(@NotNull final SwMetadataCompositeKey id) { + public void deleteSoftwareModuleMetadata(final SwMetadataCompositeKey id) { softwareModuleMetadataRepository.delete(id); } - /** - * finds all meta data by the given software module id. - * - * @param swId - * the software module id to retrieve the meta data from - * @param pageable - * the page request to page the result - * @return a paged result of all meta data entries for a given software - * module id - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - public Page findSoftwareModuleMetadataBySoftwareModuleId(@NotNull final Long swId, - @NotNull final Pageable pageable) { + @Override + public Page findSoftwareModuleMetadataBySoftwareModuleId(final Long swId, + final Pageable pageable) { return softwareModuleMetadataRepository.findBySoftwareModuleId(swId, pageable); } - /** - * finds all meta data by the given software module id. - * - * @param softwareModuleId - * the software module id to retrieve the meta data from - * @param spec - * the specification to filter the result - * @param pageable - * the page request to page the result - * @return a paged result of all meta data entries for a given software - * module id - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + @Override public Page findSoftwareModuleMetadataBySoftwareModuleId(final Long softwareModuleId, - @NotNull final Specification spec, @NotNull final Pageable pageable) { + final Specification spec, final Pageable pageable) { return softwareModuleMetadataRepository .findAll( (Specification) (root, query, @@ -901,18 +574,8 @@ public class SoftwareManagement { pageable); } - /** - * finds a single software module meta data by its id. - * - * @param id - * the id of the software module meta data containing the meta - * data key and the ID of the software module - * @return the found SoftwareModuleMetadata or {@code null} if not exits - * @throws EntityNotFoundException - * in case the meta data does not exists for the given key - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - public SoftwareModuleMetadata findSoftwareModuleMetadata(@NotNull final SwMetadataCompositeKey id) { + @Override + public SoftwareModuleMetadata findSoftwareModuleMetadata(final SwMetadataCompositeKey id) { final SoftwareModuleMetadata findOne = softwareModuleMetadataRepository.findOne(id); if (findOne == null) { throw new EntityNotFoundException("Metadata with key '" + id.getKey() + "' does not exist"); @@ -931,4 +594,19 @@ public class SoftwareManagement { throw new EntityAlreadyExistsException("Metadata entry with key '" + metadataKey + "' already exists"); } + @Override + @Modifying + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + public void deleteSoftwareModule(final SoftwareModule bsm) { + deleteSoftwareModules(Sets.newHashSet(bsm.getId())); + } + + @Override + @Modifying + @Transactional(isolation = Isolation.READ_UNCOMMITTED) + public List createSoftwareModuleType(final Collection types) { + + return types.stream().map(this::createSoftwareModuleType).collect(Collectors.toList()); + } + } diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/AbstractIntegrationTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/AbstractIntegrationTest.java index 99b93926f..dafc21eef 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/AbstractIntegrationTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/AbstractIntegrationTest.java @@ -22,6 +22,7 @@ import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.RolloutGroupManagement; import org.eclipse.hawkbit.repository.RolloutManagement; +import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; import org.eclipse.hawkbit.repository.jpa.ActionRepository; import org.eclipse.hawkbit.repository.jpa.ActionStatusRepository; @@ -32,7 +33,6 @@ import org.eclipse.hawkbit.repository.jpa.ExternalArtifactRepository; import org.eclipse.hawkbit.repository.jpa.LocalArtifactRepository; import org.eclipse.hawkbit.repository.jpa.RolloutGroupRepository; import org.eclipse.hawkbit.repository.jpa.RolloutRepository; -import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; import org.eclipse.hawkbit.repository.jpa.SoftwareModuleMetadataRepository; import org.eclipse.hawkbit.repository.jpa.SoftwareModuleRepository; import org.eclipse.hawkbit.repository.jpa.SoftwareModuleTypeRepository; diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/TestDataUtil.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/TestDataUtil.java index 11106eaf1..03a9b230f 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/TestDataUtil.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/TestDataUtil.java @@ -18,7 +18,7 @@ import java.util.UUID; import org.apache.commons.io.IOUtils; import org.eclipse.hawkbit.repository.ArtifactManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement; -import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; +import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.jpa.TargetManagement; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetTag; diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/SoftwareManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/SoftwareManagementTest.java index 849cf8e30..04eccb13e 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/SoftwareManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/SoftwareManagementTest.java @@ -270,7 +270,7 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { @Description("Searches for software modules based on a list of IDs.") public void findSoftwareModulesById() { - final List modules = new ArrayList(); + final List modules = new ArrayList<>(); modules.add(softwareManagement.createSoftwareModule(new SoftwareModule(osType, "poky-una", "3.0.2", null, "")) .getId()); diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/utils/RepositoryDataGenerator.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/utils/RepositoryDataGenerator.java index e2e86bed1..f27c7b707 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/utils/RepositoryDataGenerator.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/utils/RepositoryDataGenerator.java @@ -30,7 +30,7 @@ import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.DistributionSetAssignmentResult; import org.eclipse.hawkbit.repository.DistributionSetManagement; -import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; +import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.jpa.TagManagement; import org.eclipse.hawkbit.repository.jpa.TargetManagement; import org.eclipse.hawkbit.repository.model.Action; diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/RootController.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/RootController.java index 9dfcbae55..db5efd37c 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/RootController.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/RootController.java @@ -30,8 +30,8 @@ import org.eclipse.hawkbit.controller.model.DeploymentBase; import org.eclipse.hawkbit.controller.model.Result.FinalResult; import org.eclipse.hawkbit.repository.ArtifactManagement; import org.eclipse.hawkbit.repository.ControllerManagement; +import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; -import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetMapper.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetMapper.java index 95e3f0c8d..8051146a1 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetMapper.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetMapper.java @@ -16,8 +16,8 @@ import java.util.List; import org.eclipse.hawkbit.repository.DistributionSetAssignmentResult; import org.eclipse.hawkbit.repository.DistributionSetManagement; +import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; -import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetMetadata; import org.eclipse.hawkbit.repository.model.DistributionSetType; diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetResource.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetResource.java index 9e9dc2369..a30927ebf 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetResource.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetResource.java @@ -18,9 +18,9 @@ import org.eclipse.hawkbit.repository.DistributionSetAssignmentResult; import org.eclipse.hawkbit.repository.DistributionSetFields; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.DistributionSetMetadataFields; +import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.TargetFields; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; -import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; import org.eclipse.hawkbit.repository.jpa.SystemManagement; import org.eclipse.hawkbit.repository.jpa.TargetManagement; import org.eclipse.hawkbit.repository.jpa.TargetWithActionType; diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTypeMapper.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTypeMapper.java index fbe22af5c..409caf01d 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTypeMapper.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTypeMapper.java @@ -14,8 +14,8 @@ import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn; import java.util.ArrayList; import java.util.List; +import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; -import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.rest.resource.api.DistributionSetTypeRestApi; diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTypeResource.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTypeResource.java index 32e87e05e..8798f0ec8 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTypeResource.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTypeResource.java @@ -12,8 +12,8 @@ import java.util.List; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.DistributionSetTypeFields; +import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; -import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.SoftwareModule; diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DownloadArtifactResource.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DownloadArtifactResource.java index 5c057acd4..00f8f4756 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DownloadArtifactResource.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DownloadArtifactResource.java @@ -13,8 +13,8 @@ import javax.servlet.http.HttpServletResponse; import org.eclipse.hawkbit.artifact.repository.model.DbArtifact; import org.eclipse.hawkbit.repository.ArtifactManagement; +import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; -import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.rest.resource.helper.RestResourceConversionHelper; diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleMapper.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleMapper.java index 8732cc1d1..01dfae9cd 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleMapper.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleMapper.java @@ -14,8 +14,8 @@ import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn; import java.util.ArrayList; import java.util.List; +import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; -import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleResource.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleResource.java index 0d7a4b8f0..830443cbd 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleResource.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleResource.java @@ -12,10 +12,10 @@ import java.io.IOException; import java.util.List; import org.eclipse.hawkbit.repository.ArtifactManagement; +import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.SoftwareModuleFields; import org.eclipse.hawkbit.repository.SoftwareModuleMetadataFields; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; -import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata; diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleTypeResource.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleTypeResource.java index df042d38c..e3498f141 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleTypeResource.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleTypeResource.java @@ -10,9 +10,9 @@ package org.eclipse.hawkbit.rest.resource; import java.util.List; +import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.SoftwareModuleTypeFields; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; -import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; diff --git a/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/DistributionSetResourceTest.java b/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/DistributionSetResourceTest.java index 9d823e832..ac1c95374 100644 --- a/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/DistributionSetResourceTest.java +++ b/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/DistributionSetResourceTest.java @@ -32,9 +32,9 @@ import org.eclipse.hawkbit.TestDataUtil; import org.eclipse.hawkbit.WithUser; import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement; +import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.jpa.ActionRepository; -import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; import org.eclipse.hawkbit.repository.jpa.TargetManagement; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/footer/UploadViewConfirmationWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/footer/UploadViewConfirmationWindowLayout.java index 364b659da..e6284d5d6 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/footer/UploadViewConfirmationWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/footer/UploadViewConfirmationWindowLayout.java @@ -14,7 +14,7 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; +import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.ui.artifacts.event.UploadArtifactUIEvent; import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState; import org.eclipse.hawkbit.ui.artifacts.state.CustomFile; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/BaseSwModuleBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/BaseSwModuleBeanQuery.java index d1d034555..ea49d2f1f 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/BaseSwModuleBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/BaseSwModuleBeanQuery.java @@ -12,8 +12,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.jpa.OffsetBasedPageRequest; -import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.ui.common.UserDetailsFormatter; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleAddUpdateWindow.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleAddUpdateWindow.java index 6a033bfd8..1e4029087 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleAddUpdateWindow.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleAddUpdateWindow.java @@ -10,7 +10,7 @@ package org.eclipse.hawkbit.ui.artifacts.smtable; import java.io.Serializable; -import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; +import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; import org.eclipse.hawkbit.ui.common.SoftwareModuleTypeBeanQuery; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java index 4fea3df08..478438891 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java @@ -12,7 +12,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; +import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.ui.artifacts.event.SMFilterEvent; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/CreateUpdateSoftwareTypeLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/CreateUpdateSoftwareTypeLayout.java index 4039a2be2..f2e43c1fb 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/CreateUpdateSoftwareTypeLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/CreateUpdateSoftwareTypeLayout.java @@ -13,8 +13,8 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.SpPermissionChecker; -import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleTypeEvent; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleTypeEvent.SoftwareModuleTypeEnum; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/SMTypeFilterButtonClick.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/SMTypeFilterButtonClick.java index 4727ecae7..4a4006c2a 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/SMTypeFilterButtonClick.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/SMTypeFilterButtonClick.java @@ -10,7 +10,7 @@ package org.eclipse.hawkbit.ui.artifacts.smtype; import java.io.Serializable; -import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; +import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.ui.artifacts.event.SMFilterEvent; import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/SoftwareModuleTypeBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/SoftwareModuleTypeBeanQuery.java index f8d6dba66..b1c274672 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/SoftwareModuleTypeBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/SoftwareModuleTypeBeanQuery.java @@ -11,8 +11,8 @@ package org.eclipse.hawkbit.ui.common; import java.util.List; import java.util.Map; +import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.jpa.OffsetBasedPageRequest; -import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SpringContextHelper; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/CreateUpdateDistSetTypeLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/CreateUpdateDistSetTypeLayout.java index 0e3ed8da3..d7f5d2748 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/CreateUpdateDistSetTypeLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/disttype/CreateUpdateDistSetTypeLayout.java @@ -14,9 +14,9 @@ import java.util.List; import java.util.Set; import org.eclipse.hawkbit.repository.DistributionSetManagement; +import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.repository.jpa.DistributionSetRepository; -import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.ui.common.CoordinatesToColor; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetDetails.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetDetails.java index 32bb0ce86..a1d1ffcfe 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetDetails.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetDetails.java @@ -14,7 +14,7 @@ import java.util.Map; import java.util.Set; import org.eclipse.hawkbit.repository.DistributionSetManagement; -import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; +import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetIdName; import org.eclipse.hawkbit.repository.model.SoftwareModule; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java index ca469c967..e92e4e735 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java @@ -18,8 +18,8 @@ import java.util.Map.Entry; import java.util.Set; import org.eclipse.hawkbit.repository.DistributionSetManagement; +import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.SpPermissionChecker; -import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; import org.eclipse.hawkbit.repository.jpa.TargetManagement; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetIdName; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DistributionsConfirmationWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DistributionsConfirmationWindowLayout.java index 45e02b2ca..a97c5786d 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DistributionsConfirmationWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DistributionsConfirmationWindowLayout.java @@ -17,7 +17,7 @@ import java.util.Set; import java.util.stream.Collectors; import org.eclipse.hawkbit.repository.DistributionSetManagement; -import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; +import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetIdName; import org.eclipse.hawkbit.repository.model.SoftwareModule; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleBeanQuery.java index 84ac0f1dc..eb53cef55 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleBeanQuery.java @@ -12,8 +12,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.jpa.OffsetBasedPageRequest; -import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; import org.eclipse.hawkbit.repository.model.CustomSoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTable.java index 17b565774..eeea33723 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTable.java @@ -13,7 +13,7 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; +import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.ui.artifacts.details.ArtifactDetailsLayout; import org.eclipse.hawkbit.ui.artifacts.event.SMFilterEvent; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtype/DistSMTypeFilterButtonClick.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtype/DistSMTypeFilterButtonClick.java index d270c36f2..6f29ed661 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtype/DistSMTypeFilterButtonClick.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtype/DistSMTypeFilterButtonClick.java @@ -10,7 +10,7 @@ package org.eclipse.hawkbit.ui.distributions.smtype; import java.io.Serializable; -import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; +import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.ui.artifacts.event.SMFilterEvent; import org.eclipse.hawkbit.ui.common.filterlayout.AbstractFilterSingleButtonClick; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java index abd1942c4..0e71567af 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java @@ -20,7 +20,7 @@ import java.util.Map.Entry; import java.util.TimeZone; import org.apache.commons.lang3.StringUtils; -import org.eclipse.hawkbit.repository.jpa.SoftwareManagement; +import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.model.AssignmentResult; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.NamedEntity; diff --git a/pom.xml b/pom.xml index b6d09758e..10e60e763 100644 --- a/pom.xml +++ b/pom.xml @@ -119,7 +119,7 @@ https://projects.eclipse.org/projects/iot.hawkbit https://circleci.com/gh/eclipse/hawkbit - 0.7.2.201409121644 + 0.7.6.201602180812 1.4 From c2bf9222b7d4029c30c5c9f41db7eb913f088b61 Mon Sep 17 00:00:00 2001 From: Asharani Date: Thu, 19 May 2016 10:51:12 +0530 Subject: [PATCH 13/54] Signed-off-by: Asharani --- .../ui/artifacts/event/UploadStatusEvent.java | 2 +- .../ui/artifacts/upload/UploadHandler.java | 53 ++++++++++-- .../ui/artifacts/upload/UploadLayout.java | 5 +- .../upload/UploadStatusInfoWindow.java | 83 ++++++++++++++----- .../src/main/resources/messages.properties | 4 + .../src/main/resources/messages_de.properties | 6 +- .../src/main/resources/messages_en.properties | 5 +- 7 files changed, 123 insertions(+), 35 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadStatusEvent.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadStatusEvent.java index 96513a52a..8a4da9f6d 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadStatusEvent.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadStatusEvent.java @@ -15,7 +15,7 @@ package org.eclipse.hawkbit.ui.artifacts.event; public class UploadStatusEvent { public enum UploadStatusEventType { - UPLOAD_FAILED, UPLOAD_IN_PROGRESS, UPLOAD_STARTED, UPLOAD_FINISHED, UPLOAD_SUCCESSFUL, UPLOAD_STREAMING_FAILED, UPLOAD_STREAMING_FINISHED + UPLOAD_FAILED, UPLOAD_IN_PROGRESS, UPLOAD_STARTED, UPLOAD_FINISHED, UPLOAD_SUCCESSFUL, UPLOAD_STREAMING_FAILED, UPLOAD_STREAMING_FINISHED, ABORT_UPLOAD } private UploadStatusEventType uploadProgressEventType; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java index 848fa2da5..45a55d138 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java @@ -15,7 +15,6 @@ import javax.annotation.PreDestroy; import org.eclipse.hawkbit.repository.exception.ArtifactUploadFailedException; import org.eclipse.hawkbit.repository.model.SoftwareModule; -import org.eclipse.hawkbit.ui.artifacts.event.UploadArtifactUIEvent; import org.eclipse.hawkbit.ui.artifacts.event.UploadFileStatus; import org.eclipse.hawkbit.ui.artifacts.event.UploadStatusEvent; import org.eclipse.hawkbit.ui.artifacts.event.UploadStatusEvent.UploadStatusEventType; @@ -29,7 +28,6 @@ import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.annotation.EventBusListenerMethod; import com.vaadin.server.StreamVariable; -import com.vaadin.ui.UI; import com.vaadin.ui.Upload; import com.vaadin.ui.Upload.FailedEvent; import com.vaadin.ui.Upload.FailedListener; @@ -66,6 +64,7 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene private volatile String mimeType = null; private volatile boolean streamingInterrupted = false; private volatile boolean uploadInterrupted = false; + private volatile boolean aborted = false; private String failureReason; private final I18N i18n; @@ -77,6 +76,7 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene UploadHandler(final String fileName, final long fileSize, final UploadLayout view, final long maxSize, final Upload upload, final String mimeType, SoftwareModule selectedSw) { super(); + this.aborted = false; this.fileName = fileName; this.fileSize = fileSize; this.view = view; @@ -87,6 +87,23 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene this.i18n = SpringContextHelper.getBean(I18N.class); this.eventBus = SpringContextHelper.getBean(EventBus.SessionEventBus.class); this.artifactUploadState = SpringContextHelper.getBean(ArtifactUploadState.class); + eventBus.subscribe(this); + } + + @PreDestroy + void destroy() { + /* + * It's good manners to do this, even though vaadin-spring will + * automatically unsubscribe when this UI is garbage collected. + */ + eventBus.unsubscribe(this); + } + + @EventBusListenerMethod(scope = EventScope.SESSION) + void onEvent(final UploadStatusEventType event) { + if (event == UploadStatusEventType.ABORT_UPLOAD) { + aborted = true; + } } /** @@ -98,6 +115,7 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene public final OutputStream getOutputStream() { try { streamingInterrupted = false; + failureReason = null; return view.saveUploadedFileDetails(fileName, fileSize, mimeType, selectedSw); } catch (final ArtifactUploadFailedException e) { LOG.error("Atifact upload failed {} ", e); @@ -116,6 +134,8 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene @Override public OutputStream receiveUpload(final String fileName, final String mimeType) { uploadInterrupted = false; + aborted = false; + failureReason = null; this.fileName = fileName; this.mimeType = mimeType; // reset has directory flag before upload @@ -232,10 +252,13 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene if (readBytes > maxSize || contentLength > maxSize) { LOG.error("User tried to upload more than was allowed ({}).", maxSize); failureReason = i18n.get("message.uploadedfile.size.exceeded", maxSize); - eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_FAILED, new UploadFileStatus( - fileName, failureReason, selectedSwForUpload))); - upload.interruptUpload(); - uploadInterrupted = true; + interruptFileUpload(); + return; + } + if (aborted) { + LOG.error("User aborted file upload"); + failureReason = i18n.get("message.uploadedfile.aborted"); + interruptFileUpload(); return; } eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_IN_PROGRESS, @@ -254,9 +277,13 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene if (event.getBytesReceived() > maxSize || event.getContentLength() > maxSize) { LOG.error("User tried to upload more than was allowed ({}).", maxSize); failureReason = i18n.get("message.uploadedfile.size.exceeded", maxSize); - eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_FAILED, new UploadFileStatus( - fileName, failureReason, selectedSw))); - streamingInterrupted = true; + interruptFileStreaming(); + return; + } + if (aborted) { + LOG.error("User aborted the upload"); + failureReason = i18n.get("message.uploadedfile.aborted"); + interruptFileStreaming(); return; } eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_IN_PROGRESS, new UploadFileStatus( @@ -345,4 +372,12 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene return true; } + private void interruptFileStreaming() { + streamingInterrupted = true; + } + + private void interruptFileUpload() { + upload.interruptUpload(); + uploadInterrupted = true; + } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java index cbf766da8..4eaa61096 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java @@ -532,8 +532,7 @@ public class UploadLayout extends VerticalLayout { */ boolean enableProcessBtn() { if (artifactUploadState.getNumberOfFilesActuallyUpload().intValue() >= artifactUploadState - .getNumberOfFileUploadsExpected().intValue() - && artifactUploadState.getNumberOfFilesActuallyUpload().get() != 0) { + .getNumberOfFileUploadsExpected().intValue() && !getFileSelected().isEmpty()) { processBtn.setEnabled(true); artifactUploadState.getNumberOfFilesActuallyUpload().set(0); artifactUploadState.getNumberOfFileUploadsExpected().set(0); @@ -729,7 +728,7 @@ public class UploadLayout extends VerticalLayout { private boolean isUploadComplete() { int uploadedCount = artifactUploadState.getNumberOfFilesActuallyUpload().intValue(); int expectedUploadsCount = artifactUploadState.getNumberOfFileUploadsExpected().intValue(); - return uploadedCount == expectedUploadsCount; + return uploadedCount == expectedUploadsCount; } private void onUploadFailure(final UploadStatusEvent event) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusInfoWindow.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusInfoWindow.java index e2a486e6c..351d625c9 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusInfoWindow.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusInfoWindow.java @@ -18,8 +18,10 @@ import org.eclipse.hawkbit.ui.artifacts.event.UploadArtifactUIEvent; import org.eclipse.hawkbit.ui.artifacts.event.UploadStatusEvent; import org.eclipse.hawkbit.ui.artifacts.event.UploadStatusEvent.UploadStatusEventType; import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState; +import org.eclipse.hawkbit.ui.common.ConfirmationDialog; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; +import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; import org.springframework.beans.factory.annotation.Autowired; @@ -66,6 +68,9 @@ public class UploadStatusInfoWindow extends Window { @Autowired private ArtifactUploadState artifactUploadState; + @Autowired + private I18N i18n; + private static final String PROGRESS = "Progress"; private static final String FILE_NAME = "File name"; @@ -82,6 +87,8 @@ public class UploadStatusInfoWindow extends Window { private volatile boolean errorOccured = false; + private volatile boolean uploadAborted = false; + private Button minimizeButton; private VerticalLayout mainLayout; @@ -91,9 +98,10 @@ public class UploadStatusInfoWindow extends Window { private Button closeButton; private Button resizeButton; - - private UI ui; + private UI ui; + + private ConfirmationDialog confirmDialog; /** * Default Constructor. @@ -118,10 +126,10 @@ public class UploadStatusInfoWindow extends Window { setContent(mainLayout); eventBus.subscribe(this); ui = UI.getCurrent(); - + + createConfirmDialog(); } - @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final UploadStatusEvent event) { if (event.getUploadProgressEventType() == UploadStatusEventType.UPLOAD_IN_PROGRESS) { @@ -139,13 +147,12 @@ public class UploadStatusInfoWindow extends Window { ui.access(() -> uploadSucceeded(event.getUploadStatus().getFileName())); } } - + private void onStartOfUpload(UploadStatusEvent event) { uploadSessionStarted(); uploadStarted(event.getUploadStatus().getFileName()); } - @PreDestroy void destroy() { /* @@ -154,7 +161,7 @@ public class UploadStatusInfoWindow extends Window { */ eventBus.unsubscribe(this); } - + private void restoreState() { Indexed container = grid.getContainerDataSource(); if (container.getItemIds().isEmpty()) { @@ -246,7 +253,7 @@ public class UploadStatusInfoWindow extends Window { @Override public JsonValue encode(final String value) { - String result ; + String result; switch (value) { case "Finished": result = "

" + FontAwesome.CHECK_CIRCLE.getHtml() + "
"; @@ -266,20 +273,28 @@ public class UploadStatusInfoWindow extends Window { * Automatically close if not error has occured. */ void uploadSessionFinished() { - if (!errorOccured) { - close(); + uploadAborted = false; + if (!errorOccured && !artifactUploadState.isStatusPopupMinimized()) { + clearWindow(); } artifactUploadState.setUploadCompleted(true); minimizeButton.setEnabled(false); + closeButton.setEnabled(true); + confirmDialog.getWindow().close(); + UI.getCurrent().removeWindow(confirmDialog.getWindow()); } void uploadSessionStarted() { - if (!artifactUploadState.isStatusPopupMinimized()) { - close(); + if (artifactUploadState.getNumberOfFilesActuallyUpload().intValue() == 0 + && artifactUploadState.getNumberOfFileUploadsFailed().intValue() == 0 + && !artifactUploadState.isStatusPopupMinimized()) { openWindow(); } - minimizeButton.setEnabled(true); - artifactUploadState.setUploadCompleted(false); + if (!uploadAborted) { + minimizeButton.setEnabled(true); + closeButton.setEnabled(true); + artifactUploadState.setUploadCompleted(false); + } } void openWindow() { @@ -304,11 +319,11 @@ public class UploadStatusInfoWindow extends Window { } void updateProgress(final String filename, final long readBytes, final long contentLength) { - final Item item = uploads.getItem(filename); + final Item item = uploads.getItem(filename); if (item != null) { double progress = (double) readBytes / (double) contentLength; item.getItemProperty(PROGRESS).setValue(progress); - List uploadStatusObjectList = (List) artifactUploadState + List uploadStatusObjectList = (List) artifactUploadState .getUploadedFileStatusList().stream().filter(e -> e.getFilename().equals(filename)) .collect(Collectors.toList()); if (!uploadStatusObjectList.isEmpty()) { @@ -340,9 +355,7 @@ public class UploadStatusInfoWindow extends Window { } void uploadFailed(final String filename, final String errorReason) { - if (!errorOccured) { - errorOccured = true; - } + errorOccured = true; String status = "Failed"; final Item item = uploads.getItem(filename); if (item != null) { @@ -363,6 +376,9 @@ public class UploadStatusInfoWindow extends Window { errorOccured = false; uploads.removeAllItems(); setWindowMode(WindowMode.NORMAL); + setColumnWidth(); + setPopupSizeInMinMode(); + resizeButton.setIcon(FontAwesome.EXPAND); this.close(); artifactUploadState.getUploadedFileStatusList().clear(); artifactUploadState.getNumberOfFileUploadsFailed().set(0); @@ -421,7 +437,34 @@ public class UploadStatusInfoWindow extends Window { SPUIComponetIdProvider.UPLOAD_STATUS_POPUP_CLOSE_BUTTON_ID, "", "", "", true, FontAwesome.TIMES, SPUIButtonStyleSmallNoBorder.class); closeBtn.addStyleName(ValoTheme.BUTTON_BORDERLESS); - closeBtn.addClickListener(event -> clearWindow()); + closeBtn.addClickListener(event -> onClose()); return closeBtn; } + + private void onClose() { + if (!artifactUploadState.isUploadCompleted()) { + confirmAbortAction(); + } else { + clearWindow(); + } + } + + private void confirmAbortAction() { + UI.getCurrent().addWindow(confirmDialog.getWindow()); + confirmDialog.getWindow().bringToFront(); + } + + private void createConfirmDialog() { + confirmDialog = new ConfirmationDialog(i18n.get("caption.cancel.action.confirmbox"), + i18n.get("message.abort.upload"), i18n.get("button.ok"), i18n.get("button.cancel"), ok -> { + if (ok) { + eventBus.publish(this, UploadStatusEventType.ABORT_UPLOAD); + uploadAborted = true; + errorOccured = true; + minimizeButton.setEnabled(false); + closeButton.setEnabled(false); + } + }); + } + } diff --git a/hawkbit-ui/src/main/resources/messages.properties b/hawkbit-ui/src/main/resources/messages.properties index 25dabd354..7efc6e16d 100644 --- a/hawkbit-ui/src/main/resources/messages.properties +++ b/hawkbit-ui/src/main/resources/messages.properties @@ -86,6 +86,7 @@ caption.cancel.action.confirmbox = Confirm action cancel caption.forcequit.action.confirmbox = Confirm force quit action caption.forced.datefield = Force update at time caption.force.action.confirmbox = Confirm Force Active Action +caption.confirm.abort.action = Confirm abort action caption.filter.delete.confirmbox = Confirm Filter Delete Action @@ -321,8 +322,11 @@ message.duplicate.filename = Duplicate file name message.swModule.deleted = {0} Software module(s) deleted message.upload.failed = Streaming Failed message.uploadedfile.size.exceeded = File size exceeded .Allowed size {0} bytes +message.uploadedfile.aborted = File upload aborted message.file.not.found = File not found message.artifact.deleted =Artifact with file {0} deleted successfully +message.abort.upload = Are you sure that you want to abort the upload? + upload.swModuleTable.header = Software module diff --git a/hawkbit-ui/src/main/resources/messages_de.properties b/hawkbit-ui/src/main/resources/messages_de.properties index 39661e3c9..6a1e25222 100644 --- a/hawkbit-ui/src/main/resources/messages_de.properties +++ b/hawkbit-ui/src/main/resources/messages_de.properties @@ -85,8 +85,9 @@ caption.forced.datefield = Force update at time caption.force.action.confirmbox = Confirm Force Active Action caption.filter.simple = Simple Filter caption.filter.custom = Custom Filter - caption.filter.delete.confirmbox = Confirm Filter Delete Action +caption.confirm.abort.action = Confirm abort action + # Labels prefix with - label label.dist.details.type = Type : @@ -319,8 +320,11 @@ message.swModule.deleted = {0} Software module(s) deleted message.error.missing.tagname = Please select tag name message.upload.failed = Streaming Failed message.uploadedfile.size.exceeded = File size exceeded .Allowed size {0} bytes +message.uploadedfile.aborted = File upload aborted message.file.not.found = File not found message.artifact.deleted =Artifact with file {0} deleted successfully +message.abort.upload = Are you sure that you want to abort the upload? + upload.swModuleTable.header = Software module diff --git a/hawkbit-ui/src/main/resources/messages_en.properties b/hawkbit-ui/src/main/resources/messages_en.properties index 23df35ad2..d512b9b97 100644 --- a/hawkbit-ui/src/main/resources/messages_en.properties +++ b/hawkbit-ui/src/main/resources/messages_en.properties @@ -85,8 +85,8 @@ caption.soft.delete.confirmbox = Confirm Software Module Delete Action caption.cancel.action.confirmbox = Confirm action cancellation caption.forced.datefield = Force update at time caption.force.action.confirmbox = Confirm Force Active Action - caption.filter.delete.confirmbox = Confirm Filter Delete Action +caption.confirm.abort.action = Confirm abort action # Labels prefix with - label label.dist.details.type = Type : @@ -313,7 +313,10 @@ message.duplicate.filename = Duplicate file name message.swModule.deleted = {0} Software module(s) deleted message.upload.failed = Streaming Failed message.uploadedfile.size.exceeded = File size exceeded .Allowed size {0} bytes +message.uploadedfile.aborted = File upload aborted message.file.not.found = File not found +message.abort.upload = Are you sure that you want to abort the upload? + upload.swModuleTable.header = Software module upload.selectedfile.name = file selected for upload From 3e5330a5e6d7dc9f02f7ec8b9ae6fa62fd584d88 Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Thu, 19 May 2016 11:16:26 +0200 Subject: [PATCH 14/54] Completed management separation. Signed-off-by: Kai Zimmermann --- .../security/SecurityAutoConfiguration.java | 2 +- .../SecurityManagedConfiguration.java | 6 +- .../RepositoryApplicationConfiguration.java | 2 +- .../repository/ArtifactManagement.java | 6 +- .../repository/ControllerManagement.java | 26 +- .../repository/DeploymentManagement.java | 7 +- .../DistributionSetAssignmentResult.java | 11 +- .../repository/DistributionSetFilter.java | 94 +-- .../repository/DistributionSetManagement.java | 4 + .../hawkbit/repository/ReportManagement.java | 194 +++--- .../repository/RolloutGroupManagement.java | 164 ++--- .../hawkbit/repository/RolloutManagement.java | 336 +++++----- .../hawkbit/repository/RolloutProperties.java | 12 +- .../hawkbit/repository/RolloutScheduler.java | 1 - .../repository/SoftwareManagement.java | 608 ++++++++--------- .../hawkbit/repository/SystemManagement.java | 93 +++ .../hawkbit/repository/TagManagement.java | 236 +++++++ .../TargetFilterQueryManagement.java | 99 +++ .../hawkbit/repository/TargetManagement.java | 604 +++++++++++++++++ .../TenantConfigurationManagement.java | 136 ++-- .../repository/TenantStatsManagement.java | 33 + .../repository/jpa/DeploymentHelper.java | 1 + .../jpa/JpaControllerManagement.java | 1 + .../jpa/JpaDeploymentManagement.java | 12 +- .../jpa/JpaDistributionSetManagement.java | 4 +- .../repository/jpa/JpaReportManagement.java | 2 +- .../jpa/JpaRolloutGroupManagement.java | 4 +- .../repository/jpa/JpaRolloutManagement.java | 6 +- .../repository/jpa/JpaSoftwareManagement.java | 6 +- ...nagement.java => JpaSystemManagement.java} | 89 +-- ...gManagement.java => JpaTagManagement.java} | 239 ++----- ...va => JpaTargetFilterQueryManagement.java} | 102 +-- ...nagement.java => JpaTargetManagement.java} | 631 +++--------------- ...ent.java => JpaTenantStatsManagement.java} | 18 +- .../model/helper/SystemManagementHolder.java | 2 +- .../hawkbit/AbstractIntegrationTest.java | 8 +- .../org/eclipse/hawkbit/TestDataUtil.java | 2 +- .../hawkbit/repository/TagManagementTest.java | 1 - .../TargetFilterQueryManagenmentTest.java | 1 - .../utils/RepositoryDataGenerator.java | 4 +- .../resource/DistributionSetResource.java | 4 +- .../resource/DistributionSetTagResource.java | 2 +- .../resource/SystemManagementResource.java | 2 +- .../hawkbit/rest/resource/TargetResource.java | 2 +- .../rest/resource/TargetTagResource.java | 4 +- .../resource/DistributionSetResourceTest.java | 2 +- .../tagdetails/AbstractTargetTagToken.java | 2 +- .../tagdetails/DistributionTagToken.java | 2 +- .../ui/common/tagdetails/TargetTagToken.java | 2 +- .../dstable/DistributionSetTable.java | 2 +- .../dstable/ManageDistBeanQuery.java | 2 +- .../footer/DSDeleteActionsLayout.java | 2 +- .../CreateOrUpdateFilterHeader.java | 2 +- .../CustomTargetBeanQuery.java | 2 +- .../FilterQueryValidation.java | 2 +- .../TargetFilterBeanQuery.java | 2 +- .../filtermanagement/TargetFilterTable.java | 2 +- .../DistributionAddUpdateWindowLayout.java | 2 +- .../dstable/DistributionBeanQuery.java | 2 +- .../management/dstable/DistributionTable.java | 2 +- .../dstag/DistributionTagBeanQuery.java | 2 +- .../management/footer/CountMessageLabel.java | 2 +- .../footer/DeleteActionsLayout.java | 2 +- .../ManangementConfirmationWindowLayout.java | 2 +- .../management/tag/CreateUpdateTagLayout.java | 2 +- .../targettable/BulkUploadHandler.java | 4 +- .../TargetAddUpdateWindowLayout.java | 2 +- .../targettable/TargetBeanQuery.java | 2 +- .../TargetBulkUpdateWindowLayout.java | 2 +- .../management/targettable/TargetTable.java | 2 +- .../CustomTargetTagFilterButtonClick.java | 2 +- .../targettag/TargetTagBeanQuery.java | 2 +- .../targettag/TargetTagFilterButtons.java | 2 +- .../rollout/AddUpdateRolloutWindowLayout.java | 2 +- .../rollout/DistributionBeanQuery.java | 2 +- .../ui/rollout/rollout/RolloutBeanQuery.java | 2 +- .../DefaultDistributionSetTypeLayout.java | 2 +- 77 files changed, 2095 insertions(+), 1792 deletions(-) create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TagManagement.java create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagement.java create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantStatsManagement.java rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/{SystemManagement.java => JpaSystemManagement.java} (82%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/{TagManagement.java => JpaTagManagement.java} (51%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/{TargetFilterQueryManagement.java => JpaTargetFilterQueryManagement.java} (51%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/{TargetManagement.java => JpaTargetManagement.java} (52%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/{TenantStatsManagement.java => JpaTenantStatsManagement.java} (73%) diff --git a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/security/SecurityAutoConfiguration.java b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/security/SecurityAutoConfiguration.java index 8a3a50ad2..8c44f0496 100644 --- a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/security/SecurityAutoConfiguration.java +++ b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/security/SecurityAutoConfiguration.java @@ -19,8 +19,8 @@ import org.eclipse.hawkbit.im.authentication.PermissionService; import org.eclipse.hawkbit.im.authentication.SpPermission; import org.eclipse.hawkbit.im.authentication.TenantAwareAuthenticationDetails; import org.eclipse.hawkbit.im.authentication.UserAuthenticationFilter; -import org.eclipse.hawkbit.security.SecurityContextTenantAware; import org.eclipse.hawkbit.security.DdiSecurityProperties; +import org.eclipse.hawkbit.security.SecurityContextTenantAware; import org.eclipse.hawkbit.security.SpringSecurityAuditorAware; import org.eclipse.hawkbit.tenancy.TenantAware; import org.slf4j.Logger; diff --git a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/security/SecurityManagedConfiguration.java b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/security/SecurityManagedConfiguration.java index 0b321842f..9638377eb 100644 --- a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/security/SecurityManagedConfiguration.java +++ b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/security/SecurityManagedConfiguration.java @@ -24,11 +24,11 @@ import org.eclipse.hawkbit.ExcludePathAwareShallowETagFilter; import org.eclipse.hawkbit.cache.CacheConstants; import org.eclipse.hawkbit.im.authentication.SpPermission; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; -import org.eclipse.hawkbit.repository.ControllerManagement; -import org.eclipse.hawkbit.repository.TenantConfigurationManagement; -import org.eclipse.hawkbit.repository.jpa.SystemManagement; import org.eclipse.hawkbit.im.authentication.TenantUserPasswordAuthenticationToken; import org.eclipse.hawkbit.im.authentication.UserAuthenticationFilter; +import org.eclipse.hawkbit.repository.ControllerManagement; +import org.eclipse.hawkbit.repository.SystemManagement; +import org.eclipse.hawkbit.repository.TenantConfigurationManagement; import org.eclipse.hawkbit.rest.resource.RestConstants; import org.eclipse.hawkbit.security.ControllerTenantAwareAuthenticationDetailsSource; import org.eclipse.hawkbit.security.DdiSecurityProperties; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java index 1c562364f..d5e8db96f 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java @@ -12,8 +12,8 @@ import java.util.HashMap; import java.util.Map; import org.eclipse.hawkbit.aspects.ExceptionMappingAspectHandler; +import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; -import org.eclipse.hawkbit.repository.jpa.SystemManagement; import org.eclipse.hawkbit.repository.model.helper.AfterTransactionCommitExecutorHolder; import org.eclipse.hawkbit.repository.model.helper.CacheManagerHolder; import org.eclipse.hawkbit.repository.model.helper.SecurityTokenGeneratorHolder; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ArtifactManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ArtifactManagement.java index 19f3bcee2..7854640da 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ArtifactManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ArtifactManagement.java @@ -277,13 +277,11 @@ public interface ArtifactManagement { SoftwareModule findSoftwareModuleWithDetails(@NotNull Long id); /** - * Loads {@link org.eclipse.hawkbit.artifact.server.json.model.Artifact} - * from store for given {@link LocalArtifact}. + * Loads {@link DbArtifact} from store for given {@link LocalArtifact}. * * @param artifact * to search for - * @return loaded - * {@link org.eclipse.hawkbit.artifact.server.json.model.Artifact} + * @return loaded {@link DbArtifact} * * @throws GridFSDBFileNotFoundException * if file could not be found in store diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java index 2b18ab7ff..4ee3b1275 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java @@ -43,16 +43,6 @@ public interface ControllerManagement { String SERVER_MESSAGE_PREFIX = "Update Server: "; - /** - * Simple addition of a new {@link ActionStatus} entry to the {@link Action} - * . No state changes. - * - * @param statusMessage - * to add to the action - */ - @PreAuthorize(SpringEvalExpressions.IS_CONTROLLER) - void addInformationalActionStatus(@NotNull ActionStatus statusMessage); - /** * Adds an {@link ActionStatus} for a cancel {@link Action} including * potential state changes for the target and the {@link Action} itself. @@ -68,6 +58,16 @@ public interface ControllerManagement { @PreAuthorize(SpringEvalExpressions.IS_CONTROLLER) Action addCancelActionStatus(@NotNull ActionStatus actionStatus); + /** + * Simple addition of a new {@link ActionStatus} entry to the {@link Action} + * . No state changes. + * + * @param statusMessage + * to add to the action + */ + @PreAuthorize(SpringEvalExpressions.IS_CONTROLLER) + void addInformationalActionStatus(@NotNull ActionStatus statusMessage); + /** * Adds an {@link ActionStatus} entry for an update {@link Action} including * potential state changes for the target and the {@link Action} itself. @@ -133,14 +133,14 @@ public interface ControllerManagement { List findSoftwareModulesByDistributionSet(@NotNull DistributionSet distributionSet); /** - * Retrieves last {@link UpdateAction} for a download of an artifact of - * given module and target. + * Retrieves last {@link Action} for a download of an artifact of given + * module and target. * * @param controllerId * to look for * @param module * that should be assigned to the target - * @return last {@link UpdateAction} for given combination + * @return last {@link Action} for given combination * * @throws EntityNotFoundException * if action for given combination could not be found diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java index cffc3b8ad..754d66b65 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java @@ -8,6 +8,7 @@ */ package org.eclipse.hawkbit.repository; +import java.util.Collection; import java.util.List; import javax.validation.constraints.NotNull; @@ -99,7 +100,7 @@ public interface DeploymentManagement { */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_UPDATE_TARGET) DistributionSetAssignmentResult assignDistributionSet(@NotNull Long dsID, - @NotEmpty List targets); + @NotEmpty Collection targets); // TODO document: why are rollouts in the signature ? can all the parameters // be null or the list empty? @@ -123,7 +124,7 @@ public interface DeploymentManagement { */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_UPDATE_TARGET) DistributionSetAssignmentResult assignDistributionSet(@NotNull Long dsID, - @NotEmpty List targets, Rollout rollout, RolloutGroup rolloutGroup); + @NotEmpty Collection targets, Rollout rollout, RolloutGroup rolloutGroup); /** * method assigns the {@link DistributionSet} to all {@link Target}s by @@ -210,7 +211,7 @@ public interface DeploymentManagement { * the roll out group for this action */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET) - void createScheduledAction(List targets, DistributionSet distributionSet, ActionType actionType, + void createScheduledAction(Collection targets, DistributionSet distributionSet, ActionType actionType, long forcedTime, Rollout rollout, RolloutGroup rolloutGroup); /** diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetAssignmentResult.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetAssignmentResult.java index c79fb669d..ad947879a 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetAssignmentResult.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetAssignmentResult.java @@ -11,7 +11,6 @@ package org.eclipse.hawkbit.repository; import java.util.Collections; import java.util.List; -import org.eclipse.hawkbit.repository.jpa.TargetManagement; import org.eclipse.hawkbit.repository.model.AssignmentResult; import org.eclipse.hawkbit.repository.model.Target; @@ -53,11 +52,6 @@ public class DistributionSetAssignmentResult extends AssignmentResult { this.targetManagement = targetManagement; } - @Override - public List getAssignedEntity() { - return targetManagement.findTargetByControllerID(assignedTargets); - } - /** * @return the actionIds */ @@ -65,4 +59,9 @@ public class DistributionSetAssignmentResult extends AssignmentResult { return actions; } + @Override + public List getAssignedEntity() { + return targetManagement.findTargetByControllerID(assignedTargets); + } + } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetFilter.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetFilter.java index 728a4d0c5..54f7eb8e5 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetFilter.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetFilter.java @@ -16,32 +16,6 @@ import org.eclipse.hawkbit.repository.model.DistributionSetType; * Holds distribution set filter parameters. */ public final class DistributionSetFilter { - private final Boolean isDeleted; - private final Boolean isComplete; - private final DistributionSetType type; - private final String searchText; - private final Boolean selectDSWithNoTag; - private final Collection tagNames; - private final String assignedTargetId; - private final String installedTargetId; - - /** - * Parametric constructor. - * - * @param builder - * DistributionSetFilterBuilder - */ - public DistributionSetFilter(final DistributionSetFilterBuilder builder) { - this.isDeleted = builder.isDeleted; - this.isComplete = builder.isComplete; - this.type = builder.type; - this.searchText = builder.searchText; - this.selectDSWithNoTag = builder.selectDSWithNoTag; - this.tagNames = builder.tagNames; - this.assignedTargetId = builder.assignedTargetId; - this.installedTargetId = builder.installedTargetId; - } - /** * * Distribution set filter builder. @@ -68,8 +42,13 @@ public final class DistributionSetFilter { return new DistributionSetFilter(this); } - public DistributionSetFilterBuilder setIsDeleted(final Boolean isDeleted) { - this.isDeleted = isDeleted; + public DistributionSetFilterBuilder setAssignedTargetId(final String assignedTargetId) { + this.assignedTargetId = assignedTargetId; + return this; + } + + public DistributionSetFilterBuilder setInstalledTargetId(final String installedTargetId) { + this.installedTargetId = installedTargetId; return this; } @@ -78,8 +57,8 @@ public final class DistributionSetFilter { return this; } - public DistributionSetFilterBuilder setType(final DistributionSetType type) { - this.type = type; + public DistributionSetFilterBuilder setIsDeleted(final Boolean isDeleted) { + this.isDeleted = isDeleted; return this; } @@ -98,28 +77,53 @@ public final class DistributionSetFilter { return this; } - public DistributionSetFilterBuilder setAssignedTargetId(final String assignedTargetId) { - this.assignedTargetId = assignedTargetId; - return this; - } - - public DistributionSetFilterBuilder setInstalledTargetId(final String installedTargetId) { - this.installedTargetId = installedTargetId; + public DistributionSetFilterBuilder setType(final DistributionSetType type) { + this.type = type; return this; } } + private final Boolean isDeleted; + private final Boolean isComplete; + private final DistributionSetType type; + private final String searchText; + private final Boolean selectDSWithNoTag; + private final Collection tagNames; + private final String assignedTargetId; - public Boolean getIsDeleted() { - return isDeleted; + private final String installedTargetId; + + /** + * Parametric constructor. + * + * @param builder + * DistributionSetFilterBuilder + */ + public DistributionSetFilter(final DistributionSetFilterBuilder builder) { + this.isDeleted = builder.isDeleted; + this.isComplete = builder.isComplete; + this.type = builder.type; + this.searchText = builder.searchText; + this.selectDSWithNoTag = builder.selectDSWithNoTag; + this.tagNames = builder.tagNames; + this.assignedTargetId = builder.assignedTargetId; + this.installedTargetId = builder.installedTargetId; + } + + public String getAssignedTargetId() { + return assignedTargetId; + } + + public String getInstalledTargetId() { + return installedTargetId; } public Boolean getIsComplete() { return isComplete; } - public DistributionSetType getType() { - return type; + public Boolean getIsDeleted() { + return isDeleted; } public String getSearchText() { @@ -134,12 +138,8 @@ public final class DistributionSetFilter { return tagNames; } - public String getAssignedTargetId() { - return assignedTargetId; - } - - public String getInstalledTargetId() { - return installedTargetId; + public DistributionSetType getType() { + return type; } } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java index bea9f2719..db737df4a 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java @@ -41,6 +41,10 @@ import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.transaction.annotation.Isolation; import org.springframework.transaction.annotation.Transactional; +/** + * Management service for {@link DistributionSet}s. + * + */ public interface DistributionSetManagement { // TODO rename/document the whole with details thing (document what the diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ReportManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ReportManagement.java index 6208d395c..933f2ad9e 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ReportManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ReportManagement.java @@ -32,15 +32,81 @@ import org.springframework.security.access.prepost.PreAuthorize; public interface ReportManagement { /** - * Generates a report of all targets of their current update status count. - * For each {@link TargetUpdateStatus} an total count of targets which are - * in this status currently. + * Data base format. * - * @return a data report series which contains the target count for each - * target update status + * + * + * @param */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - DataReportSeries targetStatus(); + public interface DateType { + /** + * @param s + * @return T + */ + T format(String s); + + /** + * h2 format. + * + * @return String + */ + String h2Format(); + + /** + * mysql format. + * + * @return String + */ + String mySqlFormat(); + } + + /** + * Return DateTypes. + */ + public static final class DateTypes implements Serializable { + private static final long serialVersionUID = 1L; + private static final PerMonth PER_MONTH = new PerMonth(); + + /** + * @return PerMonth + */ + public static PerMonth perMonth() { + return PER_MONTH; + } + + private DateTypes() { + + } + } + + /** + * Gives the date format based on DB H2 or mySql. + * + * + * + */ + public static final class PerMonth implements DateType, Serializable { + private static final long serialVersionUID = 1L; + private static final String DATE_PATTERN = "yyyy-MM"; + + @Override + public LocalDate format(final String s) { + final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DATE_PATTERN); + final YearMonth ym = YearMonth.parse(s, formatter); + return ym.atDay(1); + } + + @Override + public String h2Format() { + return DATE_PATTERN; + } + + @Override + public String mySqlFormat() { + return "%Y-%m"; + } + + } /** * Generates a report of the top x distribution set assigned usage as a list @@ -81,22 +147,6 @@ public interface ReportManagement { @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) List> distributionUsageInstalled(int topXEntries); - /** - * Generates report for target created over period. - * - * @param dateType - * {@link PerMonth} - * @param from - * start date - * @param to - * end date - * @return DataReportSeries ListReportSeries list of target created - * count - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - DataReportSeries targetsCreatedOverPeriod(@NotNull DateType dateType, - @NotNull LocalDateTime from, @NotNull LocalDateTime to); - /** * Generates report for feedback over period. * @@ -113,6 +163,22 @@ public interface ReportManagement { DataReportSeries feedbackReceivedOverTime(@NotNull DateType dateType, @NotNull LocalDateTime from, @NotNull LocalDateTime to); + /** + * Generates report for target created over period. + * + * @param dateType + * {@link PerMonth} + * @param from + * start date + * @param to + * end date + * @return DataReportSeries ListReportSeries list of target created + * count + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + DataReportSeries targetsCreatedOverPeriod(@NotNull DateType dateType, + @NotNull LocalDateTime from, @NotNull LocalDateTime to); + /** * Generates a report as a {@link ListReportSeries} targets polled based on * the {@link TargetStatus#getLastTargetQuery()} within an hour, day, week, @@ -130,80 +196,14 @@ public interface ReportManagement { DataReportSeries targetsLastPoll(); /** - * Return DateTypes. + * Generates a report of all targets of their current update status count. + * For each {@link TargetUpdateStatus} an total count of targets which are + * in this status currently. + * + * @return a data report series which contains the target count for each + * target update status */ - public static final class DateTypes implements Serializable { - private static final long serialVersionUID = 1L; - private static final PerMonth PER_MONTH = new PerMonth(); - - private DateTypes() { - - } - - /** - * @return PerMonth - */ - public static PerMonth perMonth() { - return PER_MONTH; - } - } - - /** - * Data base format. - * - * - * - * @param - */ - public interface DateType { - /** - * @param s - * @return T - */ - T format(String s); - - /** - * h2 format. - * - * @return String - */ - String h2Format(); - - /** - * mysql format. - * - * @return String - */ - String mySqlFormat(); - } - - /** - * Gives the date format based on DB H2 or mySql. - * - * - * - */ - public static final class PerMonth implements DateType, Serializable { - private static final long serialVersionUID = 1L; - private static final String DATE_PATTERN = "yyyy-MM"; - - @Override - public LocalDate format(final String s) { - final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DATE_PATTERN); - final YearMonth ym = YearMonth.parse(s, formatter); - return ym.atDay(1); - } - - @Override - public String h2Format() { - return DATE_PATTERN; - } - - @Override - public String mySqlFormat() { - return "%Y-%m"; - } - - } + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + DataReportSeries targetStatus(); } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupManagement.java index 9654b8368..baff4586c 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupManagement.java @@ -27,47 +27,6 @@ import org.springframework.security.access.prepost.PreAuthorize; */ public interface RolloutGroupManagement { - /** - * Retrieves a single {@link RolloutGroup} by its ID. - * - * @param rolloutGroupId - * the ID of the rollout group to find - * @return the found {@link RolloutGroup} by its ID or {@code null} if it - * does not exists - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - RolloutGroup findRolloutGroupById(@NotNull Long rolloutGroupId); - - /** - * Retrieves a page of {@link RolloutGroup}s filtered by a given - * {@link Rollout}. - * - * @param rolloutId - * the ID of the rollout to filter the {@link RolloutGroup}s - * @param page - * the page request to sort and limit the result - * @return a page of found {@link RolloutGroup}s - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - Page findRolloutGroupsByRolloutId(@NotNull Long rolloutId, @NotNull Pageable page); - - /** - * Retrieves a page of {@link RolloutGroup}s filtered by a given - * {@link Rollout} and the given {@link Specification}. - * - * @param rolloutId - * the ID of the rollout to filter the {@link RolloutGroup}s - * @param specification - * the specification to filter the result set based on attributes - * of the {@link RolloutGroup} - * @param page - * the page request to sort and limit the result - * @return a page of found {@link RolloutGroup}s - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - Page findRolloutGroupsAll(@NotNull Rollout rollout, - @NotNull Specification specification, @NotNull Pageable page); - /** * Retrieves a page of {@link RolloutGroup}s filtered by a given * {@link Rollout} with the detailed status. @@ -81,47 +40,6 @@ public interface RolloutGroupManagement { @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) Page findAllRolloutGroupsWithDetailedStatus(@NotNull Long rolloutId, @NotNull Pageable page); - /** - * Get count of targets in different status in rollout group. - * - * @param rolloutGroupId - * rollout group id - * @return rolloutGroup with details of targets count for different statuses - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - RolloutGroup findRolloutGroupWithDetailedStatus(@NotNull Long rolloutGroupId); - - // TODO discuss: target read perm missing? - /** - * Get targets of specified rollout group. - * - * @param rolloutGroup - * rollout group - * @param specification - * the specification for filtering the targets of a rollout group - * @param page - * the page request to sort and limit the result - * - * @return Page list of targets of a rollout group - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - Page findRolloutGroupTargets(@NotNull RolloutGroup rolloutGroup, - @NotNull Specification specification, @NotNull Pageable page); - - // TODO discuss: target read perm missing? - /** - * Get targets of specified rollout group. - * - * @param rolloutGroup - * rollout group - * @param page - * the page request to sort and limit the result - * - * @return Page list of targets of a rollout group - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - Page findRolloutGroupTargets(@NotNull RolloutGroup rolloutGroup, @NotNull Pageable page); - // TODO discuss: target read perm missing? /** * @@ -141,4 +59,86 @@ public interface RolloutGroupManagement { Page findAllTargetsWithActionStatus(@NotNull PageRequest pageRequest, @NotNull RolloutGroup rolloutGroup); + /** + * Retrieves a single {@link RolloutGroup} by its ID. + * + * @param rolloutGroupId + * the ID of the rollout group to find + * @return the found {@link RolloutGroup} by its ID or {@code null} if it + * does not exists + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) + RolloutGroup findRolloutGroupById(@NotNull Long rolloutGroupId); + + /** + * Retrieves a page of {@link RolloutGroup}s filtered by a given + * {@link Rollout} and the given {@link Specification}. + * + * @param rolloutId + * the ID of the rollout to filter the {@link RolloutGroup}s + * @param specification + * the specification to filter the result set based on attributes + * of the {@link RolloutGroup} + * @param page + * the page request to sort and limit the result + * @return a page of found {@link RolloutGroup}s + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) + Page findRolloutGroupsAll(@NotNull Rollout rollout, + @NotNull Specification specification, @NotNull Pageable page); + + /** + * Retrieves a page of {@link RolloutGroup}s filtered by a given + * {@link Rollout}. + * + * @param rolloutId + * the ID of the rollout to filter the {@link RolloutGroup}s + * @param page + * the page request to sort and limit the result + * @return a page of found {@link RolloutGroup}s + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) + Page findRolloutGroupsByRolloutId(@NotNull Long rolloutId, @NotNull Pageable page); + + // TODO discuss: target read perm missing? + /** + * Get targets of specified rollout group. + * + * @param rolloutGroup + * rollout group + * @param page + * the page request to sort and limit the result + * + * @return Page list of targets of a rollout group + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) + Page findRolloutGroupTargets(@NotNull RolloutGroup rolloutGroup, @NotNull Pageable page); + + // TODO discuss: target read perm missing? + /** + * Get targets of specified rollout group. + * + * @param rolloutGroup + * rollout group + * @param specification + * the specification for filtering the targets of a rollout group + * @param page + * the page request to sort and limit the result + * + * @return Page list of targets of a rollout group + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) + Page findRolloutGroupTargets(@NotNull RolloutGroup rolloutGroup, + @NotNull Specification specification, @NotNull Pageable page); + + /** + * Get count of targets in different status in rollout group. + * + * @param rolloutGroupId + * rollout group id + * @return rolloutGroup with details of targets count for different statuses + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) + RolloutGroup findRolloutGroupWithDetailedStatus(@NotNull Long rolloutGroupId); + } \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java index 357108576..118be12fa 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java @@ -33,38 +33,54 @@ import org.springframework.security.access.prepost.PreAuthorize; public interface RolloutManagement { /** - * Retrieves all rollouts. + * Checking running rollouts. Rollouts which are checked updating the + * {@link Rollout#setLastCheck(long)} to indicate that the current instance + * is handling the specific rollout. This code should run as system-code. * - * @param page - * the page request to sort and limit the result - * @return a page of found rollouts + *
+     * {@code
+     *  SystemSecurityContext.runAsSystem(new Callable() {
+     *     public Void call() throws Exception {
+     *        //run system-code
+     *     }
+     * });
+     *  }
+     * 
+ * + * This method is attend to be called by a scheduler. + * {@link RolloutScheduler}. And must be running in an transaction so it's + * splitted from the scheduler. + * + * Rollouts which are currently running are investigated, by means the + * error- and finish condition of running groups in this rollout are + * evaluated. + * + * @param delayBetweenChecks + * the time in milliseconds of the delay between the further and + * this check. This check is only applied if the last check is + * less than (lastcheck-delay). */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - Page findAll(@NotNull Pageable page); + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_WRITE + SpringEvalExpressions.HAS_AUTH_OR + + SpringEvalExpressions.IS_SYSTEM_CODE) + void checkRunningRollouts(long delayBetweenChecks); /** - * Retrieves all rollouts found by the given specification. + * Counts all {@link Rollout}s in the repository. * - * @param specification - * the specification to filter rollouts - * @param page - * the page request to sort and limit the result - * @return a page of found rollouts + * @return number of roll outs */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - Page findAllWithDetailedStatusByPredicate(@NotNull Specification specification, - @NotNull Pageable page); + Long countRolloutsAll(); /** - * Retrieves a specific rollout by its ID. + * Count rollouts by given text in name or description. * - * @param rolloutId - * the ID of the rollout to retrieve - * @return the founded rollout or {@code null} if rollout with given ID does - * not exists + * @param searchText + * name or description + * @return total count rollouts for specified filter text. */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - Rollout findRolloutById(@NotNull Long rolloutId); + Long countRolloutsAllByFilters(@NotEmpty String searchText); /** * Persists a new rollout entity. The filter within the @@ -131,6 +147,138 @@ public interface RolloutManagement { @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_WRITE) Rollout createRolloutAsync(@NotNull Rollout rollout, int amountGroup, @NotNull RolloutGroupConditions conditions); + /** + * Retrieves all rollouts. + * + * @param page + * the page request to sort and limit the result + * @return a page of found rollouts + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) + Page findAll(@NotNull Pageable page); + + /** + * Get count of targets in different status in rollout. + * + * @param page + * the page request to sort and limit the result + * @return a list of rollouts with details of targets count for different + * statuses + * + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) + Page findAllRolloutsWithDetailedStatus(@NotNull Pageable page); + + /** + * Retrieves all rollouts found by the given specification. + * + * @param specification + * the specification to filter rollouts + * @param page + * the page request to sort and limit the result + * @return a page of found rollouts + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) + Page findAllWithDetailedStatusByPredicate(@NotNull Specification specification, + @NotNull Pageable page); + + /** + * Finds rollouts by given text in name or description. + * + * @param pageable + * the page request to sort and limit the result + * @param searchText + * search text which matches name or description of rollout + * @return the founded rollout or {@code null} if rollout with given ID does + * not exists + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) + Slice findRolloutByFilters(@NotNull Pageable pageable, @NotEmpty String searchText); + + /** + * Retrieves a specific rollout by its ID. + * + * @param rolloutId + * the ID of the rollout to retrieve + * @return the founded rollout or {@code null} if rollout with given ID does + * not exists + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) + Rollout findRolloutById(@NotNull Long rolloutId); + + /** + * Retrieves a specific rollout by its name. + * + * @param rolloutName + * the name of the rollout to retrieve + * @return the founded rollout or {@code null} if rollout with given name + * does not exists + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) + Rollout findRolloutByName(@NotNull String rolloutName); + + /** + * Get count of targets in different status in rollout. + * + * @param rolloutId + * rollout id + * @return rollout details of targets count for different statuses + * + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) + Rollout findRolloutWithDetailedStatus(@NotNull Long rolloutId); + + /*** + * Get finished percentage details for a specified group which is in running + * state. + * + * @param rolloutId + * the ID of the {@link Rollout} + * @param rolloutGroup + * the ID of the {@link RolloutGroup} + * @return percentage finished + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) + float getFinishedPercentForRunningGroup(@NotNull Long rolloutId, @NotNull RolloutGroup rolloutGroup); + + /** + * Pauses a rollout which is currently running. The Rollout switches + * {@link RolloutStatus#PAUSED}. {@link RolloutGroup}s which are currently + * running will be untouched. {@link RolloutGroup}s which are + * {@link RolloutGroupStatus#SCHEDULED} will not be started and keep in + * {@link RolloutGroupStatus#SCHEDULED} state until the rollout is + * {@link RolloutManagement#resumeRollout(Rollout)}. + * + * Switching the rollout status to {@link RolloutStatus#PAUSED} is + * sufficient due the {@link #checkRunningRollouts(long)} will not check + * this rollout anymore. + * + * @param rollout + * the rollout to be paused. + * + * @throws RolloutIllegalStateException + * if given rollout is not in {@link RolloutStatus#RUNNING}. + * Only running rollouts can be paused. + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_WRITE + SpringEvalExpressions.HAS_AUTH_OR + + SpringEvalExpressions.IS_SYSTEM_CODE) + void pauseRollout(@NotNull Rollout rollout); + + /** + * Resumes a paused rollout. The rollout switches back to + * {@link RolloutStatus#RUNNING} state which is then picked up again by the + * {@link #checkRunningRollouts(long)}. + * + * @param rollout + * the rollout to be resumed + * @throws RolloutIllegalStateException + * if given rollout is not in {@link RolloutStatus#PAUSED}. Only + * paused rollouts can be resumed. + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_WRITE + SpringEvalExpressions.HAS_AUTH_OR + + SpringEvalExpressions.IS_SYSTEM_CODE) + void resumeRollout(@NotNull Rollout rollout); + /** * Starts a rollout which has been created. The rollout must be in * {@link RolloutStatus#READY} state. The according actions will be created @@ -176,118 +324,6 @@ public interface RolloutManagement { + SpringEvalExpressions.IS_SYSTEM_CODE) Rollout startRolloutAsync(@NotNull Rollout rollout); - /** - * Pauses a rollout which is currently running. The Rollout switches - * {@link RolloutStatus#PAUSED}. {@link RolloutGroup}s which are currently - * running will be untouched. {@link RolloutGroup}s which are - * {@link RolloutGroupStatus#SCHEDULED} will not be started and keep in - * {@link RolloutGroupStatus#SCHEDULED} state until the rollout is - * {@link RolloutManagement#resumeRollout(Rollout)}. - * - * Switching the rollout status to {@link RolloutStatus#PAUSED} is - * sufficient due the {@link #checkRunningRollouts(long)} will not check - * this rollout anymore. - * - * @param rollout - * the rollout to be paused. - * - * @throws RolloutIllegalStateException - * if given rollout is not in {@link RolloutStatus#RUNNING}. - * Only running rollouts can be paused. - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_WRITE + SpringEvalExpressions.HAS_AUTH_OR - + SpringEvalExpressions.IS_SYSTEM_CODE) - void pauseRollout(@NotNull Rollout rollout); - - /** - * Resumes a paused rollout. The rollout switches back to - * {@link RolloutStatus#RUNNING} state which is then picked up again by the - * {@link #checkRunningRollouts(long)}. - * - * @param rollout - * the rollout to be resumed - * @throws RolloutIllegalStateException - * if given rollout is not in {@link RolloutStatus#PAUSED}. Only - * paused rollouts can be resumed. - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_WRITE + SpringEvalExpressions.HAS_AUTH_OR - + SpringEvalExpressions.IS_SYSTEM_CODE) - void resumeRollout(@NotNull Rollout rollout); - - /** - * Checking running rollouts. Rollouts which are checked updating the - * {@link Rollout#setLastCheck(long)} to indicate that the current instance - * is handling the specific rollout. This code should run as system-code. - * - *
-     * {@code
-     *  SystemSecurityContext.runAsSystem(new Callable() {
-     *     public Void call() throws Exception {
-     *        //run system-code
-     *     }
-     * });
-     *  }
-     * 
- * - * This method is attend to be called by a scheduler. - * {@link RolloutScheduler}. And must be running in an transaction so it's - * splitted from the scheduler. - * - * Rollouts which are currently running are investigated, by means the - * error- and finish condition of running groups in this rollout are - * evaluated. - * - * @param delayBetweenChecks - * the time in milliseconds of the delay between the further and - * this check. This check is only applied if the last check is - * less than (lastcheck-delay). - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_WRITE + SpringEvalExpressions.HAS_AUTH_OR - + SpringEvalExpressions.IS_SYSTEM_CODE) - void checkRunningRollouts(long delayBetweenChecks); - - /** - * Counts all {@link Rollout}s in the repository. - * - * @return number of roll outs - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - Long countRolloutsAll(); - - /** - * Count rollouts by given text in name or description. - * - * @param searchText - * name or description - * @return total count rollouts for specified filter text. - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - Long countRolloutsAllByFilters(@NotEmpty String searchText); - - /** - * Finds rollouts by given text in name or description. - * - * @param pageable - * the page request to sort and limit the result - * @param searchText - * search text which matches name or description of rollout - * @return the founded rollout or {@code null} if rollout with given ID does - * not exists - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - Slice findRolloutByFilters(@NotNull Pageable pageable, @NotEmpty String searchText); - - /** - * Retrieves a specific rollout by its name. - * - * @param rolloutName - * the name of the rollout to retrieve - * @return the founded rollout or {@code null} if rollout with given name - * does not exists - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - Rollout findRolloutByName(@NotNull String rolloutName); - /** * Update rollout details. * @@ -299,40 +335,4 @@ public interface RolloutManagement { @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_WRITE) Rollout updateRollout(@NotNull Rollout rollout); - /** - * Get count of targets in different status in rollout. - * - * @param page - * the page request to sort and limit the result - * @return a list of rollouts with details of targets count for different - * statuses - * - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - Page findAllRolloutsWithDetailedStatus(@NotNull Pageable page); - - /** - * Get count of targets in different status in rollout. - * - * @param rolloutId - * rollout id - * @return rollout details of targets count for different statuses - * - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - Rollout findRolloutWithDetailedStatus(@NotNull Long rolloutId); - - /*** - * Get finished percentage details for a specified group which is in running - * state. - * - * @param rolloutId - * the ID of the {@link Rollout} - * @param rolloutGroup - * the ID of the {@link RolloutGroup} - * @return percentage finished - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - float getFinishedPercentForRunningGroup(@NotNull Long rolloutId, @NotNull RolloutGroup rolloutGroup); - } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutProperties.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutProperties.java index 2384fa480..9b3a37093 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutProperties.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutProperties.java @@ -18,12 +18,6 @@ import org.springframework.stereotype.Component; @Component @ConfigurationProperties("hawkbit.rollout") public class RolloutProperties { - private final Scheduler scheduler = new Scheduler(); - - public Scheduler getScheduler() { - return scheduler; - } - /** * Rollout scheduler configuration. */ @@ -47,4 +41,10 @@ public class RolloutProperties { } + private final Scheduler scheduler = new Scheduler(); + + public Scheduler getScheduler() { + return scheduler; + } + } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutScheduler.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutScheduler.java index 1d4150217..bc8f25feb 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutScheduler.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutScheduler.java @@ -10,7 +10,6 @@ package org.eclipse.hawkbit.repository; import java.util.List; -import org.eclipse.hawkbit.repository.jpa.SystemManagement; import org.eclipse.hawkbit.security.SystemSecurityContext; import org.eclipse.hawkbit.tenancy.TenantAware; import org.slf4j.Logger; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java index 063a3a0f1..b3b9e7380 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java @@ -36,235 +36,6 @@ import org.springframework.security.access.prepost.PreAuthorize; */ public interface SoftwareManagement { - /** - * Updates existing {@link SoftwareModule}. Update-able values are - * {@link SoftwareModule#getDescription()} - * {@link SoftwareModule#getVendor()}. - * - * @param sm - * to update - * - * @return the saved {@link Entity}. - * - * @throws NullPointerException - * of {@link SoftwareModule#getId()} is null - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - SoftwareModule updateSoftwareModule(@NotNull SoftwareModule sm); - - /** - * Updates existing {@link SoftwareModuleType}. Update-able value is - * {@link SoftwareModuleType#getDescription()} and - * {@link SoftwareModuleType#getColour()}. - * - * @param sm - * to update - * @return updated {@link Entity} - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - SoftwareModuleType updateSoftwareModuleType(@NotNull SoftwareModuleType sm); - - /** - * - * @param swModule - * SoftwareModule to create - * @return SoftwareModule - * @throws EntityAlreadyExistsException - * if a given entity already exists - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) - SoftwareModule createSoftwareModule(@NotNull SoftwareModule swModule); - - /** - * Create {@link SoftwareModule}s in the repository. - * - * @param swModules - * {@link SoftwareModule}s to create - * @return SoftwareModule - * @throws EntityAlreadyExistsException - * if a given entity already exists - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) - List createSoftwareModule(@NotNull Iterable swModules); - - /** - * retrieves the {@link SoftwareModule}s by their {@link SoftwareModuleType} - * . - * - * @param pageable - * page parameters - * @param type - * to be filtered on - * @return the found {@link SoftwareModule}s - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Slice findSoftwareModulesByType(@NotNull Pageable pageable, @NotNull SoftwareModuleType type); - - /** - * Counts {@link SoftwareModule}s with given {@link SoftwareModuleType}. - * - * @param type - * to count - * @return number of found {@link SoftwareModule}s - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Long countSoftwareModulesByType(@NotNull SoftwareModuleType type); - - /** - * Finds {@link SoftwareModule} by given id. - * - * @param id - * to search for - * @return the found {@link SoftwareModule}s or null if not - * found. - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY + SpringEvalExpressions.HAS_AUTH_OR - + SpringEvalExpressions.IS_CONTROLLER) - SoftwareModule findSoftwareModuleById(@NotNull Long id); - - /** - * retrieves {@link SoftwareModule} by their name AND version AND type.. - * - * @param name - * of the {@link SoftwareModule} - * @param version - * of the {@link SoftwareModule} - * @param type - * of the {@link SoftwareModule} - * @return the found {@link SoftwareModule} or null - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - SoftwareModule findSoftwareModuleByNameAndVersion(@NotEmpty String name, @NotEmpty String version, - @NotNull SoftwareModuleType type); - - /** - * Deletes the given {@link SoftwareModule} {@link Entity}. - * - * @param bsm - * is the {@link SoftwareModule} to be deleted - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY) - void deleteSoftwareModule(@NotNull SoftwareModule bsm); - - /** - * Deletes {@link SoftwareModule}s which is any if the given ids. - * - * @param ids - * of the Software Modules to be deleted - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY) - void deleteSoftwareModules(@NotNull Iterable ids); - - /** - * Retrieves all software modules. Deleted ones are filtered. - * - * @param pageable - * pagination parameter - * @return the found {@link SoftwareModule}s - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Slice findSoftwareModulesAll(@NotNull Pageable pageable); - - /** - * Count all {@link SoftwareModule}s in the repository that are not marked - * as deleted. - * - * @return number of {@link SoftwareModule}s - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Long countSoftwareModulesAll(); - - /** - * Retrieves software module including details ( - * {@link SoftwareModule#getArtifacts()}). - * - * @param id - * parameter - * @param isDeleted - * parameter - * @return the found {@link SoftwareModule}s - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - SoftwareModule findSoftwareModuleWithDetails(@NotNull Long id); - - /** - * Retrieves all {@link SoftwareModule}s with a given specification. - * - * @param spec - * the specification to filter the software modules - * @param pageable - * pagination parameter - * @return the found {@link SoftwareModule}s - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Page findSoftwareModulesByPredicate(@NotNull Specification spec, - @NotNull Pageable pageable); - - /** - * Retrieves all {@link SoftwareModuleType}s with a given specification. - * - * @param spec - * the specification to filter the software modules types - * @param pageable - * pagination parameter - * @return the found {@link SoftwareModuleType}s - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Page findSoftwareModuleTypesByPredicate(@NotNull Specification spec, - @NotNull Pageable pageable); - - /** - * Retrieves all software modules with a given list of ids - * {@link SoftwareModule#getId()}. - * - * @param ids - * to search for - * @return {@link List} of found {@link SoftwareModule}s - */ - List findSoftwareModulesById(@NotEmpty Collection ids); - - /** - * Filter {@link SoftwareModule}s with given - * {@link SoftwareModule#getName()} or {@link SoftwareModule#getVersion()} - * and {@link SoftwareModule#getType()} that are not marked as deleted. - * - * @param pageable - * page parameter - * @param searchText - * to be filtered as "like" on {@link SoftwareModule#getName()} - * @param type - * to be filtered as "like" on {@link SoftwareModule#getType()} - * @return the page of found {@link SoftwareModule} - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Slice findSoftwareModuleByFilters(@NotNull Pageable pageable, String searchText, - SoftwareModuleType type); - - /** - * Filter {@link SoftwareModule}s with given - * {@link SoftwareModule#getName()} or {@link SoftwareModule#getVersion()} - * search text and {@link SoftwareModule#getType()} that are not marked as - * deleted and sort them by means of given distribution set related modules - * on top of the list. - * - * After that the modules are sorted by {@link SoftwareModule#getName()} and - * {@link SoftwareModule#getVersion()} in ascending order. - * - * @param pageable - * page parameter - * @param orderByDistributionId - * the ID of distribution set to be ordered on top - * @param searchText - * filtered as "like" on {@link SoftwareModule#getName()} - * @param type - * filtered as "equal" on {@link SoftwareModule#getType()} - * @return the page of found {@link SoftwareModule} - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Slice findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc( - @NotNull Pageable pageable, @NotNull Long orderByDistributionId, String searchText, - SoftwareModuleType type); - /** * Counts {@link SoftwareModule}s with given * {@link SoftwareModule#getName()} or {@link SoftwareModule#getVersion()} @@ -280,12 +51,23 @@ public interface SoftwareManagement { Long countSoftwareModuleByFilters(String searchText, SoftwareModuleType type); /** - * @param pageable - * parameter - * @return all {@link SoftwareModuleType}s in the repository. + * Count all {@link SoftwareModule}s in the repository that are not marked + * as deleted. + * + * @return number of {@link SoftwareModule}s */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Page findSoftwareModuleTypesAll(@NotNull Pageable pageable); + Long countSoftwareModulesAll(); + + /** + * Counts {@link SoftwareModule}s with given {@link SoftwareModuleType}. + * + * @param type + * to count + * @return number of found {@link SoftwareModule}s + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + Long countSoftwareModulesByType(@NotNull SoftwareModuleType type); /** * @return number of {@link SoftwareModuleType}s in the repository. @@ -294,34 +76,63 @@ public interface SoftwareManagement { Long countSoftwareModuleTypesAll(); /** + * Create {@link SoftwareModule}s in the repository. * - * @param key - * to search for - * @return {@link SoftwareModuleType} in the repository with given - * {@link SoftwareModuleType#getKey()} + * @param swModules + * {@link SoftwareModule}s to create + * @return SoftwareModule + * @throws EntityAlreadyExistsException + * if a given entity already exists */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - SoftwareModuleType findSoftwareModuleTypeByKey(@NotNull String key); + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) + List createSoftwareModule(@NotNull Collection swModules); /** * - * @param id - * to search for - * @return {@link SoftwareModuleType} in the repository with given - * {@link SoftwareModuleType#getId()} + * @param swModule + * SoftwareModule to create + * @return SoftwareModule + * @throws EntityAlreadyExistsException + * if a given entity already exists */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - SoftwareModuleType findSoftwareModuleTypeById(@NotNull Long id); + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) + SoftwareModule createSoftwareModule(@NotNull SoftwareModule swModule); /** + * creates a list of software module meta data entries. * - * @param name - * to search for - * @return all {@link SoftwareModuleType}s in the repository with given - * {@link SoftwareModuleType#getName()} + * @param metadata + * the meta data entries to create or update + * @return the updated or created software module meta data entries + * @throws EntityAlreadyExistsException + * in case one of the meta data entry already exists for the + * specific key */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - SoftwareModuleType findSoftwareModuleTypeByName(@NotNull String name); + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) + List createSoftwareModuleMetadata(@NotNull Collection metadata); + + /** + * creates or updates a single software module meta data entry. + * + * @param metadata + * the meta data entry to create or update + * @return the updated or created software module meta data entry + * @throws EntityAlreadyExistsException + * in case the meta data entry already exists for the specific + * key + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) + SoftwareModuleMetadata createSoftwareModuleMetadata(@NotNull SoftwareModuleMetadata metadata); + + /** + * Creates multiple {@link SoftwareModuleType}s. + * + * @param types + * to create + * @return created {@link Entity} + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) + List createSoftwareModuleType(@NotNull final Collection types); /** * Creates new {@link SoftwareModuleType}. @@ -334,14 +145,31 @@ public interface SoftwareManagement { SoftwareModuleType createSoftwareModuleType(@NotNull SoftwareModuleType type); /** - * Creates multiple {@link SoftwareModuleType}s. + * Deletes the given {@link SoftwareModule} {@link Entity}. * - * @param types - * to create - * @return created {@link Entity} + * @param bsm + * is the {@link SoftwareModule} to be deleted */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) - List createSoftwareModuleType(@NotNull final Collection types); + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY) + void deleteSoftwareModule(@NotNull SoftwareModule bsm); + + /** + * deletes a software module meta data entry. + * + * @param id + * the ID of the software module meta data to delete + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) + void deleteSoftwareModuleMetadata(@NotNull SwMetadataCompositeKey id); + + /** + * Deletes {@link SoftwareModule}s which is any if the given ids. + * + * @param ids + * of the Software Modules to be deleted + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY) + void deleteSoftwareModules(@NotNull Collection ids); /** * Deletes or marks as delete in case the type is in use. @@ -378,52 +206,61 @@ public interface SoftwareManagement { @NotNull SoftwareModuleType type); /** - * creates or updates a single software module meta data entry. + * Filter {@link SoftwareModule}s with given + * {@link SoftwareModule#getName()} or {@link SoftwareModule#getVersion()} + * and {@link SoftwareModule#getType()} that are not marked as deleted. * - * @param metadata - * the meta data entry to create or update - * @return the updated or created software module meta data entry - * @throws EntityAlreadyExistsException - * in case the meta data entry already exists for the specific - * key + * @param pageable + * page parameter + * @param searchText + * to be filtered as "like" on {@link SoftwareModule#getName()} + * @param type + * to be filtered as "like" on {@link SoftwareModule#getType()} + * @return the page of found {@link SoftwareModule} */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - SoftwareModuleMetadata createSoftwareModuleMetadata(@NotNull SoftwareModuleMetadata metadata); + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + Slice findSoftwareModuleByFilters(@NotNull Pageable pageable, String searchText, + SoftwareModuleType type); /** - * creates a list of software module meta data entries. - * - * @param metadata - * the meta data entries to create or update - * @return the updated or created software module meta data entries - * @throws EntityAlreadyExistsException - * in case one of the meta data entry already exists for the - * specific key - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - List createSoftwareModuleMetadata(@NotNull Collection metadata); - - /** - * updates a distribution set meta data value if corresponding entry exists. - * - * @param metadata - * the meta data entry to be updated - * @return the updated meta data entry - * @throws EntityNotFoundException - * in case the meta data entry does not exists and cannot be - * updated - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - SoftwareModuleMetadata updateSoftwareModuleMetadata(@NotNull SoftwareModuleMetadata metadata); - - /** - * deletes a software module meta data entry. + * Finds {@link SoftwareModule} by given id. * * @param id - * the ID of the software module meta data to delete + * to search for + * @return the found {@link SoftwareModule}s or null if not + * found. */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - void deleteSoftwareModuleMetadata(@NotNull SwMetadataCompositeKey id); + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY + SpringEvalExpressions.HAS_AUTH_OR + + SpringEvalExpressions.IS_CONTROLLER) + SoftwareModule findSoftwareModuleById(@NotNull Long id); + + /** + * retrieves {@link SoftwareModule} by their name AND version AND type.. + * + * @param name + * of the {@link SoftwareModule} + * @param version + * of the {@link SoftwareModule} + * @param type + * of the {@link SoftwareModule} + * @return the found {@link SoftwareModule} or null + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + SoftwareModule findSoftwareModuleByNameAndVersion(@NotEmpty String name, @NotEmpty String version, + @NotNull SoftwareModuleType type); + + /** + * finds a single software module meta data by its id. + * + * @param id + * the id of the software module meta data containing the meta + * data key and the ID of the software module + * @return the found SoftwareModuleMetadata or {@code null} if not exits + * @throws EntityNotFoundException + * in case the meta data does not exists for the given key + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + SoftwareModuleMetadata findSoftwareModuleMetadata(@NotNull SwMetadataCompositeKey id); /** * finds all meta data by the given software module id. @@ -456,16 +293,179 @@ public interface SoftwareManagement { @NotNull Specification spec, @NotNull Pageable pageable); /** - * finds a single software module meta data by its id. + * Filter {@link SoftwareModule}s with given + * {@link SoftwareModule#getName()} or {@link SoftwareModule#getVersion()} + * search text and {@link SoftwareModule#getType()} that are not marked as + * deleted and sort them by means of given distribution set related modules + * on top of the list. + * + * After that the modules are sorted by {@link SoftwareModule#getName()} and + * {@link SoftwareModule#getVersion()} in ascending order. * - * @param id - * the id of the software module meta data containing the meta - * data key and the ID of the software module - * @return the found SoftwareModuleMetadata or {@code null} if not exits - * @throws EntityNotFoundException - * in case the meta data does not exists for the given key + * @param pageable + * page parameter + * @param orderByDistributionId + * the ID of distribution set to be ordered on top + * @param searchText + * filtered as "like" on {@link SoftwareModule#getName()} + * @param type + * filtered as "equal" on {@link SoftwareModule#getType()} + * @return the page of found {@link SoftwareModule} */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - SoftwareModuleMetadata findSoftwareModuleMetadata(@NotNull SwMetadataCompositeKey id); + Slice findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc( + @NotNull Pageable pageable, @NotNull Long orderByDistributionId, String searchText, + SoftwareModuleType type); + + /** + * Retrieves all software modules. Deleted ones are filtered. + * + * @param pageable + * pagination parameter + * @return the found {@link SoftwareModule}s + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + Slice findSoftwareModulesAll(@NotNull Pageable pageable); + + /** + * Retrieves all software modules with a given list of ids + * {@link SoftwareModule#getId()}. + * + * @param ids + * to search for + * @return {@link List} of found {@link SoftwareModule}s + */ + List findSoftwareModulesById(@NotEmpty Collection ids); + + /** + * Retrieves all {@link SoftwareModule}s with a given specification. + * + * @param spec + * the specification to filter the software modules + * @param pageable + * pagination parameter + * @return the found {@link SoftwareModule}s + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + Page findSoftwareModulesByPredicate(@NotNull Specification spec, + @NotNull Pageable pageable); + + /** + * retrieves the {@link SoftwareModule}s by their {@link SoftwareModuleType} + * . + * + * @param pageable + * page parameters + * @param type + * to be filtered on + * @return the found {@link SoftwareModule}s + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + Slice findSoftwareModulesByType(@NotNull Pageable pageable, @NotNull SoftwareModuleType type); + + /** + * + * @param id + * to search for + * @return {@link SoftwareModuleType} in the repository with given + * {@link SoftwareModuleType#getId()} + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + SoftwareModuleType findSoftwareModuleTypeById(@NotNull Long id); + + /** + * + * @param key + * to search for + * @return {@link SoftwareModuleType} in the repository with given + * {@link SoftwareModuleType#getKey()} + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + SoftwareModuleType findSoftwareModuleTypeByKey(@NotNull String key); + + /** + * + * @param name + * to search for + * @return all {@link SoftwareModuleType}s in the repository with given + * {@link SoftwareModuleType#getName()} + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + SoftwareModuleType findSoftwareModuleTypeByName(@NotNull String name); + + /** + * @param pageable + * parameter + * @return all {@link SoftwareModuleType}s in the repository. + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + Page findSoftwareModuleTypesAll(@NotNull Pageable pageable); + + /** + * Retrieves all {@link SoftwareModuleType}s with a given specification. + * + * @param spec + * the specification to filter the software modules types + * @param pageable + * pagination parameter + * @return the found {@link SoftwareModuleType}s + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + Page findSoftwareModuleTypesByPredicate(@NotNull Specification spec, + @NotNull Pageable pageable); + + /** + * Retrieves software module including details ( + * {@link SoftwareModule#getArtifacts()}). + * + * @param id + * parameter + * @param isDeleted + * parameter + * @return the found {@link SoftwareModule}s + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + SoftwareModule findSoftwareModuleWithDetails(@NotNull Long id); + + /** + * Updates existing {@link SoftwareModule}. Update-able values are + * {@link SoftwareModule#getDescription()} + * {@link SoftwareModule#getVendor()}. + * + * @param sm + * to update + * + * @return the saved {@link Entity}. + * + * @throws NullPointerException + * of {@link SoftwareModule#getId()} is null + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) + SoftwareModule updateSoftwareModule(@NotNull SoftwareModule sm); + + /** + * updates a distribution set meta data value if corresponding entry exists. + * + * @param metadata + * the meta data entry to be updated + * @return the updated meta data entry + * @throws EntityNotFoundException + * in case the meta data entry does not exists and cannot be + * updated + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) + SoftwareModuleMetadata updateSoftwareModuleMetadata(@NotNull SoftwareModuleMetadata metadata); + + /** + * Updates existing {@link SoftwareModuleType}. Update-able value is + * {@link SoftwareModuleType#getDescription()} and + * {@link SoftwareModuleType#getColour()}. + * + * @param sm + * to update + * @return updated {@link Entity} + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) + SoftwareModuleType updateSoftwareModuleType(@NotNull SoftwareModuleType sm); } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java new file mode 100644 index 000000000..b62ed0ad3 --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java @@ -0,0 +1,93 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository; + +import java.util.List; + +import javax.validation.constraints.NotNull; + +import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; +import org.eclipse.hawkbit.report.model.SystemUsageReport; +import org.eclipse.hawkbit.repository.model.TenantMetaData; +import org.eclipse.hawkbit.tenancy.TenantAware; +import org.springframework.cache.interceptor.KeyGenerator; +import org.springframework.context.annotation.Bean; +import org.springframework.security.access.prepost.PreAuthorize; + +/** + * Central system management operations of the update server. + * + */ +public interface SystemManagement { + + /** + * Checks if a specific tenant exists. The tenant will not be created lazy. + * + * @return {@code true} in case the tenant exits or {@code false} if not + */ + String currentTenant(); + + /** + * Deletes all data related to a given tenant. + * + * @param tenant + * to delete + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_SYSTEM_ADMIN) + void deleteTenant(@NotNull String tenant); + + /** + * + * @return list of all tenant names in the system. + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_SYSTEM_ADMIN + SpringEvalExpressions.HAS_AUTH_OR + + SpringEvalExpressions.IS_SYSTEM_CODE) + List findTenants(); + + /** + * Calculated system usage statistics, both overall for the entire system + * and per tenant; + * + * @return SystemUsageReport of the current system + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_SYSTEM_ADMIN) + SystemUsageReport getSystemUsageStatistics(); + + /** + * @return {@link TenantMetaData} of {@link TenantAware#getCurrentTenant()} + */ + TenantMetaData getTenantMetadata(); + + // TODO figure out why this is necessary and clean this up + @Bean + KeyGenerator currentTenantKeyGenerator(); + + /** + * Returns {@link TenantMetaData} of given and current tenant. + * + * DISCLAIMER: this variant is used during initial login (where the tenant + * is not yet in the session). Please user {@link #getTenantMetadata()} for + * regular requests. + * + * @param tenant + * to retrieve data for + * @return {@link TenantMetaData} of given tenant + */ + TenantMetaData getTenantMetadata(@NotNull String tenant); + + /** + * Update call for {@link TenantMetaData}. + * + * @param metaData + * to update + * @return updated {@link TenantMetaData} entity + */ + TenantMetaData updateTenantMetadata(@NotNull TenantMetaData metaData); + +} \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TagManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TagManagement.java new file mode 100644 index 000000000..929bd745c --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TagManagement.java @@ -0,0 +1,236 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository; + +import java.util.Collection; +import java.util.List; + +import javax.validation.constraints.NotNull; + +import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; +import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; +import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.DistributionSetTag; +import org.eclipse.hawkbit.repository.model.Tag; +import org.eclipse.hawkbit.repository.model.Target; +import org.eclipse.hawkbit.repository.model.TargetTag; +import org.hibernate.validator.constraints.NotEmpty; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.security.access.prepost.PreAuthorize; + +/** + * Management service for {@link Tag}s. + * + */ +public interface TagManagement { + + /** + * count {@link TargetTag}s. + * + * @return size of {@link TargetTag}s + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + long countTargetTags(); + + /** + * Creates a {@link DistributionSet}. + * + * @param distributionSetTag + * to be created. + * @return the new {@link DistributionSet} + * @throws EntityAlreadyExistsException + * if distributionSetTag already exists + * + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) + DistributionSetTag createDistributionSetTag(@NotNull DistributionSetTag distributionSetTag); + + /** + * Creates multiple {@link DistributionSetTag}s. + * + * @param distributionSetTags + * to be created + * @return the new {@link DistributionSetTag} + * @throws EntityAlreadyExistsException + * if a given entity already exists + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) + List createDistributionSetTags(@NotNull Collection distributionSetTags); + + /** + * Creates a new {@link TargetTag}. + * + * @param targetTag + * to be created + * + * @return the new created {@link TargetTag} + * + * @throws EntityAlreadyExistsException + * if given object already exists + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_TARGET) + TargetTag createTargetTag(@NotNull TargetTag targetTag); + + /** + * created multiple {@link TargetTag}s. + * + * @param targetTags + * to be created + * @return the new created {@link TargetTag}s + * + * @throws EntityAlreadyExistsException + * if given object has already an ID. + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_TARGET) + List createTargetTags(@NotNull Iterable targetTags); + + /** + * Deletes {@link DistributionSetTag} by given + * {@link DistributionSetTag#getName()}. + * + * @param tagName + * to be deleted + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY) + void deleteDistributionSetTag(@NotEmpty String tagName); + + /** + * Deletes {@link TargetTag} with given name. + * + * @param targetTagName + * tag name of the {@link TargetTag} to be deleted + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_TARGET) + void deleteTargetTag(@NotEmpty String targetTagName); + + /** + * + * @return all {@link DistributionSetTag}s + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + List findAllDistributionSetTags(); + + /** + * returns all {@link DistributionSetTag}s. + * + * @param pageReq + * page parameter + * @return all {@link DistributionSetTag}s + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + Page findAllDistributionSetTags(@NotNull Pageable pageReq); + + /** + * Retrieves all DistributionSet tags based on the given specification. + * + * @param spec + * the specification for the query + * @param pageable + * pagination parameter + * @return the found {@link DistributionSetTag}s, never {@code null} + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + Page findAllDistributionSetTags(@NotNull Specification spec, + @NotNull Pageable pageable); + + /** + * @return all {@link TargetTag}s + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + List findAllTargetTags(); + + /** + * returns all {@link TargetTag}s. + * + * @param pageReq + * page parameter + * + * @return all {@link TargetTag}s + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + Page findAllTargetTags(@NotNull Pageable pageReq); + + /** + * Retrieves all target tags based on the given specification. + * + * @param spec + * the specification for the query + * @param pageable + * pagination parameter + * @return the found {@link Target}s, never {@code null} + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + Page findAllTargetTags(@NotNull Specification spec, @NotNull Pageable pageable); + + /** + * Find {@link DistributionSet} based on given name. + * + * @param name + * to look for. + * @return {@link DistributionSet} or null if it does not exist + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + DistributionSetTag findDistributionSetTag(@NotEmpty String name); + + /** + * Finds {@link DistributionSetTag} by given id. + * + * @param id + * to search for + * @return the found {@link DistributionSetTag}s or null if not + * found. + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + DistributionSetTag findDistributionSetTagById(@NotNull Long id); + + /** + * Find {@link TargetTag} based on given Name. + * + * @param name + * to look for. + * @return {@link TargetTag} or null if it does not exist + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + TargetTag findTargetTag(@NotEmpty String name); + + /** + * Finds {@link TargetTag} by given id. + * + * @param id + * to search for + * @return the found {@link TargetTag}s or null if not found. + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + TargetTag findTargetTagById(@NotNull Long id); + + /** + * Updates an existing {@link DistributionSetTag}. + * + * @param distributionSetTag + * to be updated + * @return the updated {@link DistributionSet} + * @throws NullPointerException + * of {@link DistributionSetTag#getName()} is null + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) + DistributionSetTag updateDistributionSetTag(@NotNull DistributionSetTag distributionSetTag); + + /** + * updates the {@link TargetTag}. + * + * @param targetTag + * the {@link TargetTag} with updated values + * @return the updated {@link TargetTag} + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET) + TargetTag updateTargetTag(@NotNull TargetTag targetTag); + +} \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagement.java new file mode 100644 index 000000000..caf045c93 --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagement.java @@ -0,0 +1,99 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository; + +import javax.validation.constraints.NotNull; + +import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; +import org.eclipse.hawkbit.repository.model.TargetFilterQuery; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.security.access.prepost.PreAuthorize; + +/** + * Management service for {@link TargetFilterQuery}s. + * + */ +public interface TargetFilterQueryManagement { + + /** + * creating new {@link TargetFilterQuery}. + * + * @param customTargetFilter + * @return the created {@link TargetFilterQuery} + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_TARGET) + TargetFilterQuery createTargetFilterQuery(@NotNull TargetFilterQuery customTargetFilter); + + /** + * Delete target filter query. + * + * @param targetFilterQueryId + * IDs of target filter query to be deleted + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_TARGET) + void deleteTargetFilterQuery(@NotNull Long targetFilterQueryId); + + /** + * + * Retrieves all target filter query{@link TargetFilterQuery}. + * + * @param pageable + * pagination parameter + * @return the found {@link TargetFilterQuery}s + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + Page findAllTargetFilterQuery(@NotNull Pageable pageable); + + /** + * Retrieves all target filter query which {@link TargetFilterQuery}. + * + * + * @param pageable + * pagination parameter + * @param name + * target filter query name + * @return the page with the found {@link TargetFilterQuery} + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + Page findTargetFilterQueryByFilters(@NotNull Pageable pageable, String name); + + /** + * Find target filter query by id. + * + * @param targetFilterQueryId + * Target filter query id + * @return the found {@link TargetFilterQuery} + * + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + TargetFilterQuery findTargetFilterQueryById(@NotNull Long targetFilterQueryId); + + /** + * Find target filter query by name. + * + * @param targetFilterQueryName + * Target filter query name + * @return the found {@link TargetFilterQuery} + * + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + TargetFilterQuery findTargetFilterQueryByName(@NotNull String targetFilterQueryName); + + /** + * updates the {@link TargetFilterQuery}. + * + * @param targetFilterQuery + * to be updated + * @return the updated {@link TargetFilterQuery} + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET) + TargetFilterQuery updateTargetFilterQuery(@NotNull TargetFilterQuery targetFilterQuery); + +} \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java new file mode 100644 index 000000000..ae7724e31 --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java @@ -0,0 +1,604 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository; + +import java.net.URI; +import java.util.Collection; +import java.util.List; + +import javax.persistence.Entity; +import javax.validation.constraints.NotNull; + +import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; +import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; +import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.Tag; +import org.eclipse.hawkbit.repository.model.Target; +import org.eclipse.hawkbit.repository.model.TargetFilterQuery; +import org.eclipse.hawkbit.repository.model.TargetIdName; +import org.eclipse.hawkbit.repository.model.TargetInfo; +import org.eclipse.hawkbit.repository.model.TargetTag; +import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult; +import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; +import org.hibernate.validator.constraints.NotEmpty; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.security.access.prepost.PreAuthorize; + +/** + * Management service for {@link Target}s. + * + */ +public interface TargetManagement { + + /** + * Assign a {@link TargetTag} assignment to given {@link Target}s. + * + * @param targetIds + * to assign for + * @param tag + * to assign + * @return list of assigned targets + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET) + List assignTag(@NotEmpty Collection targetIds, @NotNull TargetTag tag); + + /** + * Counts number of targets with given + * {@link Target#getAssignedDistributionSet()}. + * + * @param distId + * to search for + * + * @return number of found {@link Target}s. + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + Long countTargetByAssignedDistributionSet(@NotNull Long distId); + + /** + * Count {@link Target}s for all the given filter parameters. + * + * @param status + * find targets having on of these {@link TargetUpdateStatus}s. + * Set to null in case this is not required. + * @param searchText + * to find targets having the text anywhere in name or + * description. Set null in case this is not + * required. + * @param installedOrAssignedDistributionSetId + * to find targets having the {@link DistributionSet} as + * installed or assigned. Set to null in case this + * is not required. + * @param tagNames + * to find targets which are having any one in this tag names. + * Set null in case this is not required. + * @param selectTargetWithNoTag + * flag to select targets with no tag assigned + * + * @return the found number {@link Target}s + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + Long countTargetByFilters(Collection status, String searchText, + Long installedOrAssignedDistributionSetId, Boolean selectTargetWithNoTag, String... tagNames); + + /** + * Counts number of targets with given + * {@link TargetInfo#getInstalledDistributionSet()}. + * + * @param distId + * to search for + * @return number of found {@link Target}s. + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + Long countTargetByInstalledDistributionSet(@NotNull Long distId); + + /** + * Count {@link TargetFilterQuery}s for given target filter query. + * + * @param targetFilterQuery + * {link TargetFilterQuery} + * @return the found number {@link TargetFilterQuery}s + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + Long countTargetByTargetFilterQuery(@NotEmpty String targetFilterQuery); + + /** + * Count {@link TargetFilterQuery}s for given filter parameter. + * + * @param targetFilterQuery + * {link TargetFilterQuery} + * @return the found number {@link TargetFilterQuery}s + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + Long countTargetByTargetFilterQuery(@NotNull TargetFilterQuery targetFilterQuery); + + /** + * Counts all {@link Target}s in the repository. + * + * @return number of targets + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + Long countTargetsAll(); + + /** + * creating a new {@link Target}. + * + * @param target + * to be created + * @return the created {@link Target} + * + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_TARGET + SpringEvalExpressions.HAS_AUTH_OR + + SpringEvalExpressions.IS_CONTROLLER) + Target createTarget(@NotNull Target target); + + /** + * creating new {@link Target}s including poll status data. useful + * especially in plug and play scenarios. + * + * @param target + * to be created * + * @param status + * of the target + * @param lastTargetQuery + * if a plug and play case + * @param address + * if a plug and play case + * + * @throws EntityAlreadyExistsException + * if {@link Target} with given {@link Target#getControllerId()} + * already exists. + * + * @return created {@link Target} + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_TARGET + SpringEvalExpressions.HAS_AUTH_OR + + SpringEvalExpressions.IS_CONTROLLER) + Target createTarget(@NotNull Target target, @NotNull TargetUpdateStatus status, Long lastTargetQuery, URI address); + + /** + * creates multiple {@link Target}s. If some of the given {@link Target}s + * already exists in the DB a {@link EntityAlreadyExistsException} is + * thrown. {@link Target}s contain all objects of the parameter targets, + * including duplicates. + * + * @param targets + * to be created. + * @return the created {@link Target}s + * + * @throws EntityAlreadyExistsException + * of one of the given targets already exist. + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_TARGET) + List createTargets(@NotNull Collection targets); + + /** + * creating a new {@link Target} including poll status data. useful + * especially in plug and play scenarios. + * + * @param targets + * to be created * + * @param status + * of the target + * @param lastTargetQuery + * if a plug and play case + * @param address + * if a plug and play case + * + * @return newly created target + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_TARGET) + List createTargets(@NotNull Collection targets, @NotNull TargetUpdateStatus status, + Long lastTargetQuery, URI address); + + /** + * Deletes all targets with the given IDs. + * + * @param targetIDs + * the technical IDs of the targets to be deleted + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_TARGET) + void deleteTargets(@NotEmpty Long... targetIDs); + + /** + * finds all {@link Target#getControllerId()} which are currently in the + * database. + * + * @return all IDs of all {@link Target} in the system + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + List findAllTargetIds(); + + /** + * Finds all targets for all the given parameters but returns not the full + * target but {@link TargetIdName}. + * + * @param pageRequest + * the pageRequest to enhance the query for paging and sorting + * + * @param filterByStatus + * find targets having this {@link TargetUpdateStatus}s. Set to + * null in case this is not required. + * @param filterBySearchText + * to find targets having the text anywhere in name or + * description. Set null in case this is not + * required. + * @param installedOrAssignedDistributionSetId + * to find targets having the {@link DistributionSet} as + * installed or assigned. Set to null in case this + * is not required. + * @param filterByTagNames + * to find targets which are having any one in this tag names. + * Set null in case this is not required. + * @param selectTargetWithNoTag + * flag to select targets with no tag assigned + * + * @return the found {@link TargetIdName}s + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + List findAllTargetIdsByFilters(@NotNull Pageable pageRequest, + Collection filterByStatus, String filterBySearchText, + Long installedOrAssignedDistributionSetId, Boolean selectTargetWithNoTag, String... filterByTagNames); + + /** + * Finds all targets for all the given parameter {@link TargetFilterQuery} + * and returns not the full target but {@link TargetIdName}. + * + * @param pageRequest + * the pageRequest to enhance the query for paging and sorting + * @param targetFilterQuery + * {@link TargetFilterQuery} + * @return the found {@link TargetIdName}s + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + List findAllTargetIdsByTargetFilterQuery(@NotNull Pageable pageRequest, + @NotNull TargetFilterQuery targetFilterQuery); + + /** + * retrieves {@link Target}s by the assigned {@link DistributionSet} without + * details, i.e. NO {@link Target#getTags()} and {@link Target#getActions()} + * possible. + * + * + * @param distributionSetID + * the ID of the {@link DistributionSet} + * @param pageReq + * page parameter + * @return the found {@link Target}s + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_READ_TARGET) + Page findTargetByAssignedDistributionSet(@NotNull Long distributionSetID, @NotNull Pageable pageReq); + + /** + * Retrieves {@link Target}s by the assigned {@link DistributionSet} without + * details, i.e. NO {@link Target#getTags()} and {@link Target#getActions()} + * possible including additional filtering based on the given {@code spec}. + * + * @param distributionSetID + * the ID of the {@link DistributionSet} + * @param spec + * the specification to filter the result set + * @param pageReq + * page parameter + * @return the found {@link Target}s, never {@code null} + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_READ_TARGET) + Page findTargetByAssignedDistributionSet(@NotNull Long distributionSetID, + @NotNull Specification spec, @NotNull Pageable pageReq); + + /** + * Find {@link Target} based on given ID returns found Target without + * details, i.e. NO {@link Target#getTags()} and {@link Target#getActions()} + * possible. + * + * @param controllerIDs + * to look for. + * @return List of found{@link Target}s + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + List findTargetByControllerID(@NotEmpty Collection controllerIDs); + + /** + * Find {@link Target} based on given ID returns found Target without + * details, i.e. NO {@link Target#getTags()} and {@link Target#getActions()} + * possible. + * + * @param controllerId + * to look for. + * @return {@link Target} or null if it does not exist + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + Target findTargetByControllerID(@NotEmpty String controllerId); + + /** + * Find {@link Target} based on given ID returns found Target with details, + * i.e. {@link Target#getTags()} and {@link Target#getActions()} are + * possible. + * + * Note: try to use {@link #findTargetByControllerID(String)} as much as + * possible. + * + * @param controllerId + * to look for. + * @return {@link Target} or null if it does not exist + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + Target findTargetByControllerIDWithDetails(@NotEmpty String controllerId); + + /** + * Filter {@link Target}s for all the given parameters. If all parameters + * except pageable are null, all available {@link Target}s are returned. + * + * @param pageable + * page parameters + * @param status + * find targets having this {@link TargetUpdateStatus}s. Set to + * null in case this is not required. + * @param searchText + * to find targets having the text anywhere in name or + * description. Set null in case this is not + * required. + * @param installedOrAssignedDistributionSetId + * to find targets having the {@link DistributionSet} as + * installed or assigned. Set to null in case this + * is not required. + * @param tagNames + * to find targets which are having any one in this tag names. + * Set null in case this is not required. + * @param selectTargetWithNoTag + * flag to select targets with no tag assigned + * + * @return the found {@link Target}s + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + Slice findTargetByFilters(@NotNull Pageable pageable, Collection status, + String searchText, Long installedOrAssignedDistributionSetId, Boolean selectTargetWithNoTag, + String... tagNames); + + /** + * retrieves {@link Target}s by the installed {@link DistributionSet}without + * details, i.e. NO {@link Target#getTags()} and {@link Target#getActions()} + * possible. + * + * @param distributionSetID + * the ID of the {@link DistributionSet} + * @param pageReq + * page parameter + * @return the found {@link Target}s + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_READ_TARGET) + Page findTargetByInstalledDistributionSet(@NotNull Long distributionSetID, @NotNull Pageable pageReq); + + /** + * retrieves {@link Target}s by the installed {@link DistributionSet}without + * details, i.e. NO {@link Target#getTags()} and {@link Target#getActions()} + * possible including additional filtering based on the given {@code spec}. + * + * @param distributionSetId + * the ID of the {@link DistributionSet} + * @param spec + * the specification to filter the result + * @param pageable + * page parameter + * @return the found {@link Target}s, never {@code null} + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_READ_TARGET) + Page findTargetByInstalledDistributionSet(@NotNull Long distributionSetId, + @NotNull Specification spec, @NotNull Pageable pageable); + + /** + * Retrieves the {@link Target} which have a certain + * {@link TargetUpdateStatus} without details, i.e. NO + * {@link Target#getTags()} and {@link Target#getActions()} possible. + * + * @param pageable + * page parameter + * @param status + * the {@link TargetUpdateStatus} to be filtered on + * @return the found {@link Target}s + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + Page findTargetByUpdateStatus(@NotNull Pageable pageable, @NotNull TargetUpdateStatus status); + + /** + * Retrieves all targets without details, i.e. NO {@link Target#getTags()} + * and {@link Target#getActions()} possible + * + * @param pageable + * pagination parameter + * @return the found {@link Target}s + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + Slice findTargetsAll(@NotNull Pageable pageable); + + /** + * Retrieves all targets based on the given specification. + * + * @param spec + * the specification for the query + * @param pageable + * pagination parameter + * @return the found {@link Target}s, never {@code null} + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + Page findTargetsAll(@NotNull Specification spec, @NotNull Pageable pageable); + + /** + * Retrieves all targets without details, i.e. NO {@link Target#getTags()} + * and {@link Target#getActions()} possible based on + * {@link TargetFilterQuery#getQuery()} + * + * @param targetFilterQuery + * in string notation + * @param pageable + * pagination parameter + * @return the found {@link Target}s, never {@code null} + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + Slice findTargetsAll(@NotNull String targetFilterQuery, @NotNull Pageable pageable); + + /** + * Retrieves all targets without details, i.e. NO {@link Target#getTags()} + * and {@link Target#getActions()} possible based on + * {@link TargetFilterQuery#getQuery()} + * + * @param targetFilterQuery + * the specification for the query + * @param pageable + * pagination parameter + * + * @return the found {@link Target}s, never {@code null} + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + Slice findTargetsAll(@NotNull TargetFilterQuery targetFilterQuery, @NotNull Pageable pageable); + + /** + * method retrieves all {@link Target}s from the repo in the following + * order: + *

+ * 1) {@link Target}s which have the given {@link DistributionSet} as + * {@link Target#getTargetInfo()} + * {@link TargetInfo#getInstalledDistributionSet()} + *

+ * 2) {@link Target}s which have the given {@link DistributionSet} as + * {@link Target#getAssignedDistributionSet()} + *

+ * 3) {@link Target}s which have no connection to the given + * {@link DistributionSet}. + * + * @param pageable + * the page request to page the result set + * @param orderByDistributionId + * {@link DistributionSet#getId()} to be ordered by + * @param filterByDistributionId + * {@link DistributionSet#getId()} to be filter the result. Set + * to null in case this is not required. + * @param filterByStatus + * find targets having this {@link TargetUpdateStatus}s. Set to + * null in case this is not required. + * @param filterBySearchText + * to find targets having the text anywhere in name or + * description. Set null in case this is not + * required. + * @param installedOrAssignedDistributionSetId + * to find targets having the {@link DistributionSet} as + * installed or assigned. Set to null in case this + * is not required. + * @param filterByTagNames + * to find targets which are having any one in this tag names. + * Set null in case this is not required. + * @param selectTargetWithNoTag + * flag to select targets with no tag assigned + * @return a paged result {@link Page} of the {@link Target}s in a defined + * order. + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + Slice findTargetsAllOrderByLinkedDistributionSet(@NotNull Pageable pageable, + @NotNull Long orderByDistributionId, Long filterByDistributionId, + Collection filterByStatus, String filterBySearchText, Boolean selectTargetWithNoTag, + String... filterByTagNames); + + /** + * retrieves a list of {@link Target}s by their controller ID with details, + * i.e. {@link Target#getTags()} are possible. + * + * Note: try to use {@link #findTargetByControllerID(String)} as much as + * possible. + * + * @param controllerIDs + * {@link Target}s Names parameter + * @return the found {@link Target}s + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + List findTargetsByControllerIDsWithTags(@NotNull List controllerIDs); + + /** + * Find targets by tag name. + * + * @param tagName + * tag name + * @return list of matching targets + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + List findTargetsByTag(@NotEmpty String tagName); + + /** + * Toggles {@link TargetTag} assignment to given {@link Target}s by means + * that if some (or all) of the targets in the list have the {@link Tag} not + * yet assigned, they will be. If all of theme have the tag already assigned + * they will be removed instead. + * + * @param targetIds + * to toggle for + * @param tagName + * to toggle + * @return TagAssigmentResult with all meta data of the assignment outcome. + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET) + TargetTagAssignmentResult toggleTagAssignment(@NotEmpty Collection targetIds, @NotEmpty String tagName); + + /** + * {@link Entity} based method call for + * {@link #toggleTagAssignment(Collection, String)}. + * + * @param targets + * to toggle for + * @param tag + * to toggle + * @return TagAssigmentResult with all meta data of the assignment outcome. + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET) + TargetTagAssignmentResult toggleTagAssignment(@NotEmpty Collection targets, @NotNull TargetTag tag); + + /** + * Un-assign all {@link Target} from a given {@link TargetTag} . + * + * @param tag + * to un-assign all targets + * @return list of unassigned targets + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET) + List unAssignAllTargetsByTag(@NotNull TargetTag tag); + + /** + * Un-assign a {@link TargetTag} assignment to given {@link Target}. + * + * @param controllerID + * to un-assign for + * @param targetTag + * to un-assign + * @return the unassigned target or if no target is unassigned + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET) + Target unAssignTag(@NotEmpty String controllerID, @NotNull TargetTag targetTag); + + /** + * updates the {@link Target}. + * + * @param target + * to be updated + * @return the updated {@link Target} + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET + SpringEvalExpressions.HAS_AUTH_OR + + SpringEvalExpressions.IS_CONTROLLER) + Target updateTarget(@NotNull Target target); + + /** + * updates multiple {@link Target}s. + * + * @param targets + * to be updated + * @return the updated {@link Target}s + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET + SpringEvalExpressions.HAS_AUTH_OR + + SpringEvalExpressions.IS_CONTROLLER) + List updateTargets(@NotNull Iterable targets); + +} \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantConfigurationManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantConfigurationManagement.java index a5eaf4006..d9647e610 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantConfigurationManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantConfigurationManagement.java @@ -23,6 +23,74 @@ import org.springframework.security.access.prepost.PreAuthorize; */ public interface TenantConfigurationManagement { + /** + * Adds or updates a specific configuration for a specific tenant. + * + * + * @param configurationKey + * the key of the configuration + * @param value + * the configuration value which will be written into the + * database. + * @return the configuration value which was just written into the database. + * @throws TenantConfigurationValidatorException + * if the {@code propertyType} and the value in general does not + * match the expected type and format defined by the Key + * @throws ConversionFailedException + * if the property cannot be converted to the given + */ + @PreAuthorize(value = SpringEvalExpressions.HAS_AUTH_TENANT_CONFIGURATION) + TenantConfigurationValue addOrUpdateConfiguration(TenantConfigurationKey configurationKey, T value); + + /** + * Build the tenant configuration by the given key + * + * @param configurationKey + * the key + * @param propertyType + * the property type + * @param tenantConfiguration + * the configuration + * @return if no default value is set and no database value available + * or returns the tenant configuration value + */ + @PreAuthorize(value = SpringEvalExpressions.HAS_AUTH_TENANT_CONFIGURATION + SpringEvalExpressions.HAS_AUTH_OR + + SpringEvalExpressions.IS_SYSTEM_CODE) + TenantConfigurationValue buildTenantConfigurationValueByKey(TenantConfigurationKey configurationKey, + Class propertyType, TenantConfiguration tenantConfiguration); + + /** + * Deletes a specific configuration for the current tenant. Does nothing in + * case there is no tenant specific configuration value. + * + * @param configurationKey + * the configuration key to be deleted + */ + @PreAuthorize(value = SpringEvalExpressions.HAS_AUTH_TENANT_CONFIGURATION) + void deleteConfiguration(TenantConfigurationKey configurationKey); + + /** + * Retrieves a configuration value from the e.g. tenant overwritten + * configuration values or in case the tenant does not a have a specific + * configuration the global default value hold in the {@link Environment}. + * + * @param configurationKey + * the key of the configuration + * @return the converted configuration value either from the tenant specific + * configuration stored or from the fall back default values or + * {@code null} in case key has not been configured and not default + * value exists + * @throws TenantConfigurationValidatorException + * if the {@code propertyType} and the value in general does not + * match the expected type and format defined by the Key + * @throws ConversionFailedException + * if the property cannot be converted to the given + * {@code propertyType} + */ + @PreAuthorize(value = SpringEvalExpressions.HAS_AUTH_TENANT_CONFIGURATION + SpringEvalExpressions.HAS_AUTH_OR + + SpringEvalExpressions.IS_SYSTEM_CODE) + TenantConfigurationValue getConfigurationValue(TenantConfigurationKey configurationKey); + /** * Retrieves a configuration value from the e.g. tenant overwritten * configuration values or in case the tenant does not a have a specific @@ -51,45 +119,6 @@ public interface TenantConfigurationManagement { TenantConfigurationValue getConfigurationValue(TenantConfigurationKey configurationKey, Class propertyType); - /** - * Build the tenant configuration by the given key - * - * @param configurationKey - * the key - * @param propertyType - * the property type - * @param tenantConfiguration - * the configuration - * @return if no default value is set and no database value available - * or returns the tenant configuration value - */ - @PreAuthorize(value = SpringEvalExpressions.HAS_AUTH_TENANT_CONFIGURATION + SpringEvalExpressions.HAS_AUTH_OR - + SpringEvalExpressions.IS_SYSTEM_CODE) - TenantConfigurationValue buildTenantConfigurationValueByKey(TenantConfigurationKey configurationKey, - Class propertyType, TenantConfiguration tenantConfiguration); - - /** - * Retrieves a configuration value from the e.g. tenant overwritten - * configuration values or in case the tenant does not a have a specific - * configuration the global default value hold in the {@link Environment}. - * - * @param configurationKey - * the key of the configuration - * @return the converted configuration value either from the tenant specific - * configuration stored or from the fall back default values or - * {@code null} in case key has not been configured and not default - * value exists - * @throws TenantConfigurationValidatorException - * if the {@code propertyType} and the value in general does not - * match the expected type and format defined by the Key - * @throws ConversionFailedException - * if the property cannot be converted to the given - * {@code propertyType} - */ - @PreAuthorize(value = SpringEvalExpressions.HAS_AUTH_TENANT_CONFIGURATION + SpringEvalExpressions.HAS_AUTH_OR - + SpringEvalExpressions.IS_SYSTEM_CODE) - TenantConfigurationValue getConfigurationValue(TenantConfigurationKey configurationKey); - /** * returns the global configuration property either defined in the property * file or an default value otherwise. @@ -114,33 +143,4 @@ public interface TenantConfigurationManagement { + SpringEvalExpressions.IS_SYSTEM_CODE) T getGlobalConfigurationValue(TenantConfigurationKey configurationKey, Class propertyType); - /** - * Adds or updates a specific configuration for a specific tenant. - * - * - * @param configurationKey - * the key of the configuration - * @param value - * the configuration value which will be written into the - * database. - * @return the configuration value which was just written into the database. - * @throws TenantConfigurationValidatorException - * if the {@code propertyType} and the value in general does not - * match the expected type and format defined by the Key - * @throws ConversionFailedException - * if the property cannot be converted to the given - */ - @PreAuthorize(value = SpringEvalExpressions.HAS_AUTH_TENANT_CONFIGURATION) - TenantConfigurationValue addOrUpdateConfiguration(TenantConfigurationKey configurationKey, T value); - - /** - * Deletes a specific configuration for the current tenant. Does nothing in - * case there is no tenant specific configuration value. - * - * @param configurationKey - * the configuration key to be deleted - */ - @PreAuthorize(value = SpringEvalExpressions.HAS_AUTH_TENANT_CONFIGURATION) - void deleteConfiguration(TenantConfigurationKey configurationKey); - } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantStatsManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantStatsManagement.java new file mode 100644 index 000000000..bb4ca8ef0 --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantStatsManagement.java @@ -0,0 +1,33 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository; + +import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; +import org.eclipse.hawkbit.report.model.TenantUsage; +import org.springframework.security.access.prepost.PreAuthorize; + +/** + * Management service for statistics of a single tenant. + * + */ +public interface TenantStatsManagement { + + /** + * Service for stats of a single tenant. Opens a new transaction and as a + * result can an be used for multiple tenants, i.e. to allow in one session + * to collect data of all tenants in the system. + * + * @param tenant + * to collect for + * @return collected statistics + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_SYSTEM_ADMIN) + TenantUsage getStatsOfTenant(String tenant); + +} \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/DeploymentHelper.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/DeploymentHelper.java index adcca7c73..f5123c792 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/DeploymentHelper.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/DeploymentHelper.java @@ -14,6 +14,7 @@ import java.util.stream.Collectors; import javax.persistence.EntityManager; import javax.validation.constraints.NotNull; +import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.Target; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java index 8834b2ae0..a7706440d 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java @@ -19,6 +19,7 @@ import javax.persistence.criteria.Root; import javax.validation.constraints.NotNull; import org.eclipse.hawkbit.repository.ControllerManagement; +import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.exception.ToManyAttributeEntriesException; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java index d905fb7b1..0c5df3b3f 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java @@ -9,6 +9,7 @@ package org.eclipse.hawkbit.repository.jpa; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.List; @@ -33,6 +34,7 @@ import org.eclipse.hawkbit.eventbus.event.TargetInfoUpdateEvent; import org.eclipse.hawkbit.executor.AfterTransactionCommitExecutor; import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.DistributionSetAssignmentResult; +import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.exception.CancelActionNotAllowedException; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.exception.ForceQuitActionNotAllowedException; @@ -75,7 +77,7 @@ import com.google.common.collect.Lists; import com.google.common.eventbus.EventBus; /** - * JPA implementation for DeploymentManagement. + * JPA implementation for {@link DeploymentManagement}. * */ @Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) @@ -156,7 +158,7 @@ public class JpaDeploymentManagement implements DeploymentManagement { @Transactional(isolation = Isolation.READ_COMMITTED) @CacheEvict(value = { "distributionUsageAssigned" }, allEntries = true) public DistributionSetAssignmentResult assignDistributionSet(final Long dsID, - final List targets) { + final Collection targets) { final DistributionSet set = distributoinSetRepository.findOne(dsID); if (set == null) { throw new EntityNotFoundException( @@ -171,7 +173,7 @@ public class JpaDeploymentManagement implements DeploymentManagement { @Transactional(isolation = Isolation.READ_COMMITTED) @CacheEvict(value = { "distributionUsageAssigned" }, allEntries = true) public DistributionSetAssignmentResult assignDistributionSet(final Long dsID, - final List targets, final Rollout rollout, final RolloutGroup rolloutGroup) { + final Collection targets, final Rollout rollout, final RolloutGroup rolloutGroup) { final DistributionSet set = distributoinSetRepository.findOne(dsID); if (set == null) { throw new EntityNotFoundException( @@ -200,7 +202,7 @@ public class JpaDeploymentManagement implements DeploymentManagement { * {@link DistributionSetType}. */ private DistributionSetAssignmentResult assignDistributionSetToTargets(@NotNull final DistributionSet set, - final List targetsWithActionType, final Rollout rollout, + final Collection targetsWithActionType, final Rollout rollout, final RolloutGroup rolloutGroup) { if (!set.isComplete()) { @@ -456,7 +458,7 @@ public class JpaDeploymentManagement implements DeploymentManagement { @Override @Modifying @Transactional(isolation = Isolation.READ_COMMITTED) - public void createScheduledAction(final List targets, final DistributionSet distributionSet, + public void createScheduledAction(final Collection targets, final DistributionSet distributionSet, final ActionType actionType, final long forcedTime, final Rollout rollout, final RolloutGroup rolloutGroup) { // cancel all current scheduled actions for this target. E.g. an action diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java index d045cd549..da999e7cb 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java @@ -27,6 +27,8 @@ import org.eclipse.hawkbit.executor.AfterTransactionCommitExecutor; import org.eclipse.hawkbit.repository.DistributionSetFilter; import org.eclipse.hawkbit.repository.DistributionSetFilter.DistributionSetFilterBuilder; import org.eclipse.hawkbit.repository.DistributionSetManagement; +import org.eclipse.hawkbit.repository.SystemManagement; +import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.exception.EntityLockedException; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; @@ -59,7 +61,7 @@ import com.google.common.base.Strings; import com.google.common.eventbus.EventBus; /** - * Business facade for managing the {@link DistributionSet}s. + * JPA implementation of {@link DistributionSetManagement}. * */ @Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaReportManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaReportManagement.java index f0f704352..523f91374 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaReportManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaReportManagement.java @@ -51,7 +51,7 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; /** - * Service layer for generating hawkBit reports. + * JPA implementation of {@link ReportManagement}. * */ @Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutGroupManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutGroupManagement.java index 3de83d381..b7ced5511 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutGroupManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutGroupManagement.java @@ -40,15 +40,13 @@ import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.domain.Specification; -import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Isolation; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; /** - * RolloutGroupManagement to control rollout groups. This service secures all - * the functionality based on the {@link PreAuthorize} annotation on methods. + * JPA implementation of {@link RolloutGroupManagement}. */ @Validated @Service diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java index 1f6e9b9a4..e4636f890 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java @@ -20,6 +20,7 @@ import javax.persistence.EntityManager; import org.eclipse.hawkbit.cache.CacheWriteNotify; import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.RolloutManagement; +import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.exception.RolloutIllegalStateException; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.ActionType; @@ -52,7 +53,6 @@ import org.springframework.data.domain.Sort.Direction; import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.repository.Modifying; import org.springframework.scheduling.annotation.EnableScheduling; -import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Service; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.TransactionDefinition; @@ -65,9 +65,7 @@ import org.springframework.util.Assert; import org.springframework.validation.annotation.Validated; /** - * RolloutManagement to control rollouts e.g. like creating, starting, resuming - * and pausing rollouts. This service secures all the functionality based on the - * {@link PreAuthorize} annotation on methods. + * JPA implementation of {@link RolloutManagement}. */ @Validated @Service diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java index a3566f07f..3f25dff29 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java @@ -59,7 +59,7 @@ import com.google.common.base.Strings; import com.google.common.collect.Sets; /** - * JPA implementation of SoftwareManagement. + * JPA implementation of {@link SoftwareManagement}. * */ @Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) @@ -148,7 +148,7 @@ public class JpaSoftwareManagement implements SoftwareManagement { @Override @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) - public List createSoftwareModule(final Iterable swModules) { + public List createSoftwareModule(final Collection swModules) { swModules.forEach(swModule -> { if (null != swModule.getId()) { throw new EntityAlreadyExistsException(); @@ -222,7 +222,7 @@ public class JpaSoftwareManagement implements SoftwareManagement { @Override @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) - public void deleteSoftwareModules(final Iterable ids) { + public void deleteSoftwareModules(final Collection ids) { final List swModulesToDelete = softwareModuleRepository.findByIdIn(ids); final Set assignedModuleIds = new HashSet<>(); swModulesToDelete.forEach(swModule -> { diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/SystemManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java similarity index 82% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/SystemManagement.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java index 67f7bf93f..b7a08fc2e 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/SystemManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java @@ -14,11 +14,11 @@ import java.util.List; import java.util.stream.Collectors; import javax.persistence.EntityManager; -import javax.validation.constraints.NotNull; import org.eclipse.hawkbit.cache.TenancyCacheManager; -import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; import org.eclipse.hawkbit.report.model.SystemUsageReport; +import org.eclipse.hawkbit.repository.SystemManagement; +import org.eclipse.hawkbit.repository.TenantStatsManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; @@ -33,7 +33,6 @@ import org.springframework.cache.interceptor.KeyGenerator; import org.springframework.cache.interceptor.SimpleKeyGenerator; import org.springframework.context.annotation.Bean; import org.springframework.data.jpa.repository.Modifying; -import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Isolation; import org.springframework.transaction.annotation.Propagation; @@ -41,13 +40,13 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; /** - * Central system management operations of the SP server. + * JPA implementation of {@link SystemManagement}. * */ @Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) @Validated @Service -public class SystemManagement { +public class JpaSystemManagement implements SystemManagement { @Autowired private EntityManager entityManager; @@ -107,14 +106,7 @@ public class SystemManagement { private final ThreadLocal createInitialTenant = new ThreadLocal<>(); - /** - * Calculated system usage statistics, both overall for the entire system - * and per tenant; - * - * @return SystemUsageReport of the current system - */ - @NotNull - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_SYSTEM_ADMIN) + @Override public SystemUsageReport getSystemUsageStatistics() { BigDecimal sumOfArtifacts = (BigDecimal) entityManager @@ -156,35 +148,18 @@ public class SystemManagement { })); } - /** - * Registers the key generator for the {@link #currentTenant()} method - * because this key generator is aware of the {@link #createInitialTenant} - * thread local in case we are currently creating a tenant and insert the - * default distribution set types. - * - * @return the {@link CurrentTenantKeyGenerator} - */ - @Bean + @Override @Transactional(propagation = Propagation.SUPPORTS) - public CurrentTenantKeyGenerator currentTenantKeyGenerator() { + @Bean + public KeyGenerator currentTenantKeyGenerator() { return new CurrentTenantKeyGenerator(); } - /** - * Returns {@link TenantMetaData} of given and current tenant. - * - * DISCLAIMER: this variant is used during initial login (where the tenant - * is not yet in the session). Please user {@link #getTenantMetadata()} for - * regular requests. - * - * @param tenant - * @return - */ + @Override @Cacheable(value = "tenantMetadata", key = "#tenant.toUpperCase()") @Transactional(isolation = Isolation.READ_UNCOMMITTED) @Modifying - @NotNull - public TenantMetaData getTenantMetadata(@NotNull final String tenant) { + public TenantMetaData getTenantMetadata(final String tenant) { final TenantMetaData result = tenantMetaDataRepository.findByTenantIgnoreCase(tenant); // Create if it does not exist @@ -201,28 +176,16 @@ public class SystemManagement { return result; } - /** - * - * @return list of all tenant names in the system. - */ - @NotNull - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_SYSTEM_ADMIN + SpringEvalExpressions.HAS_AUTH_OR - + SpringEvalExpressions.IS_SYSTEM_CODE) + @Override public List findTenants() { return tenantMetaDataRepository.findAll().stream().map(md -> md.getTenant()).collect(Collectors.toList()); } - /** - * Deletes all data related to a given tenant. - * - * @param tenant - * to delete - */ + @Override @CacheEvict(value = { "tenantMetadata" }, key = "#tenant.toUpperCase()") @Transactional(isolation = Isolation.READ_UNCOMMITTED) @Modifying - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_SYSTEM_ADMIN) - public void deleteTenant(@NotNull final String tenant) { + public void deleteTenant(final String tenant) { cacheManager.evictCaches(tenant); cacheManager.getCache("currentTenant").evict(currentTenantKeyGenerator().generate(null, null)); tenantAware.runAsTenant(tenant, () -> { @@ -246,13 +209,10 @@ public class SystemManagement { }); } - /** - * @return {@link TenantMetaData} of {@link TenantAware#getCurrentTenant()} - */ + @Override @Cacheable(value = "tenantMetadata", keyGenerator = "tenantKeyGenerator") @Transactional(isolation = Isolation.READ_UNCOMMITTED) @Modifying - @NotNull public TenantMetaData getTenantMetadata() { if (tenantAware.getCurrentTenant() == null) { throw new IllegalStateException("Tenant not set"); @@ -261,13 +221,7 @@ public class SystemManagement { return getTenantMetadata(tenantAware.getCurrentTenant()); } - /** - * Checks if a specific tenant exists. The tenant will not be created lazy. - * - * @param tenant - * the tenant to check - * @return {@code true} in case the tenant exits or {@code false} if not - */ + @Override @Cacheable(value = "currentTenant", keyGenerator = "currentTenantKeyGenerator") // set transaction to not supported, due we call this in // BaseEntity#prePersist methods @@ -290,18 +244,11 @@ public class SystemManagement { return initialTenantCreation; } - /** - * Update call for {@link TenantMetaData}. - * - * @param metaData - * to update - * @return updated {@link TenantMetaData} entity - */ + @Override @CachePut(value = "tenantMetadata", key = "#metaData.tenant.toUpperCase()") @Transactional(isolation = Isolation.READ_UNCOMMITTED) @Modifying - @NotNull - public TenantMetaData updateTenantMetadata(@NotNull final TenantMetaData metaData) { + public TenantMetaData updateTenantMetadata(final TenantMetaData metaData) { if (!tenantMetaDataRepository.exists(metaData.getId())) { throw new EntityNotFoundException("Metadata does not exist: " + metaData.getId()); } @@ -340,7 +287,7 @@ public class SystemManagement { * currently created and not the one currently in the {@link TenantAware}. * */ - private class CurrentTenantKeyGenerator implements KeyGenerator { + public class CurrentTenantKeyGenerator implements KeyGenerator { @Override // Exception squid:S923 - override @SuppressWarnings({ "squid:S923" }) diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TagManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTagManagement.java similarity index 51% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TagManagement.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTagManagement.java index dbca65a00..f1b885b13 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TagManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTagManagement.java @@ -10,11 +10,10 @@ package org.eclipse.hawkbit.repository.jpa; import static com.google.common.base.Preconditions.checkNotNull; +import java.util.Collection; import java.util.LinkedList; import java.util.List; -import javax.validation.constraints.NotNull; - import org.eclipse.hawkbit.eventbus.event.DistributionSetTagCreatedBulkEvent; import org.eclipse.hawkbit.eventbus.event.DistributionSetTagDeletedEvent; import org.eclipse.hawkbit.eventbus.event.DistributionSetTagUpdateEvent; @@ -22,21 +21,18 @@ import org.eclipse.hawkbit.eventbus.event.TargetTagCreatedBulkEvent; import org.eclipse.hawkbit.eventbus.event.TargetTagDeletedEvent; import org.eclipse.hawkbit.eventbus.event.TargetTagUpdateEvent; import org.eclipse.hawkbit.executor.AfterTransactionCommitExecutor; -import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; +import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetTag; -import org.eclipse.hawkbit.repository.model.Tag; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetTag; import org.eclipse.hawkbit.tenancy.TenantAware; -import org.hibernate.validator.constraints.NotEmpty; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.repository.Modifying; -import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Isolation; import org.springframework.transaction.annotation.Transactional; @@ -45,13 +41,13 @@ import org.springframework.validation.annotation.Validated; import com.google.common.eventbus.EventBus; /** - * Management service class for {@link Tag}s. + * JP>A implementation of {@link TagManagement}. * */ @Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) @Validated @Service -public class TagManagement { +public class JpaTagManagement implements TagManagement { @Autowired private TargetTagRepository targetTagRepository; @@ -74,34 +70,14 @@ public class TagManagement { @Autowired private AfterTransactionCommitExecutor afterCommit; - /** - * Find {@link TargetTag} based on given Name. - * - * @param name - * to look for. - * @return {@link TargetTag} or null if it does not exist - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - public TargetTag findTargetTag(@NotEmpty final String name) { + @Override + public TargetTag findTargetTag(final String name) { return targetTagRepository.findByNameEquals(name); } - /** - * Creates a new {@link TargetTag}. - * - * @param targetTag - * to be created - * - * @return the new created {@link TargetTag} - * - * @throws EntityAlreadyExistsException - * if given object already exists - */ - @Modifying + @Override @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @NotNull - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_TARGET) - public TargetTag createTargetTag(@NotNull final TargetTag targetTag) { + public TargetTag createTargetTag(final TargetTag targetTag) { if (null != targetTag.getId()) { throw new EntityAlreadyExistsException(); } @@ -118,21 +94,10 @@ public class TagManagement { return save; } - /** - * created multiple {@link TargetTag}s. - * - * @param targetTags - * to be created - * @return the new created {@link TargetTag}s - * - * @throws EntityAlreadyExistsException - * if given object has already an ID. - */ + @Override @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @NotNull - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_TARGET) - public List createTargetTags(@NotNull final Iterable targetTags) { + public List createTargetTags(final Iterable targetTags) { targetTags.forEach(tag -> { if (tag.getId() != null) { throw new EntityAlreadyExistsException(); @@ -144,16 +109,10 @@ public class TagManagement { return save; } - /** - * Deletes {@link TargetTag} with given name. - * - * @param targetTagName - * tag name of the {@link TargetTag} to be deleted - */ + @Override @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_TARGET) - public void deleteTargetTag(@NotEmpty final String targetTagName) { + public void deleteTargetTag(final String targetTagName) { final TargetTag tag = targetTagRepository.findByNameEquals(targetTagName); final List changed = new LinkedList<>(); @@ -172,54 +131,25 @@ public class TagManagement { } - /** - * returns all {@link TargetTag}s. - * - * @return all {@link TargetTag}s - */ - @NotNull - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + @Override public List findAllTargetTags() { return targetTagRepository.findAll(); } - /** - * Retrieves all target tags based on the given specification. - * - * @param spec - * the specification for the query - * @param pageable - * pagination parameter - * @return the found {@link Target}s, never {@code null} - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - public Page findAllTargetTags(@NotNull final Specification spec, - @NotNull final Pageable pageable) { + @Override + public Page findAllTargetTags(final Specification spec, final Pageable pageable) { return targetTagRepository.findAll(spec, pageable); } - /** - * count {@link TargetTag}s. - * - * @return size of {@link TargetTag}s - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + @Override public long countTargetTags() { return targetTagRepository.count(); } - /** - * updates the {@link TargetTag}. - * - * @param targetTag - * the {@link TargetTag} - * @return the new {@link TargetTag} - */ + @Override @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @NotNull - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET) - public TargetTag updateTargetTag(@NotNull final TargetTag targetTag) { + public TargetTag updateTargetTag(final TargetTag targetTag) { checkNotNull(targetTag.getName()); checkNotNull(targetTag.getId()); final TargetTag save = targetTagRepository.save(targetTag); @@ -227,32 +157,15 @@ public class TagManagement { return save; } - /** - * Find {@link DistributionSet} based on given name. - * - * @param name - * to look for. - * @return {@link DistributionSet} or null if it does not exist - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - public DistributionSetTag findDistributionSetTag(@NotEmpty final String name) { + @Override + public DistributionSetTag findDistributionSetTag(final String name) { return distributionSetTagRepository.findByNameEquals(name); } - /** - * Creates a {@link DistributionSet}. - * - * @param distributionSetTag - * to be created. - * @return the new {@link DistributionSet} - * @throws EntityAlreadyExistsException - * if distributionSetTag already exists - * - */ + @Override @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) - public DistributionSetTag createDistributionSetTag(@NotNull final DistributionSetTag distributionSetTag) { + public DistributionSetTag createDistributionSetTag(final DistributionSetTag distributionSetTag) { if (null != distributionSetTag.getId()) { throw new EntityAlreadyExistsException(); } @@ -268,20 +181,11 @@ public class TagManagement { return save; } - /** - * Creates multiple {@link DistributionSetTag}s. - * - * @param distributionSetTags - * to be created - * @return the new {@link DistributionSetTag} - * @throws EntityAlreadyExistsException - * if a given entity already exists - */ + @Override @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) public List createDistributionSetTags( - @NotNull final Iterable distributionSetTags) { + final Collection distributionSetTags) { for (final DistributionSetTag dsTag : distributionSetTags) { if (dsTag.getId() != null) { throw new EntityAlreadyExistsException(); @@ -294,17 +198,10 @@ public class TagManagement { return save; } - /** - * Deletes {@link DistributionSetTag} by given - * {@link DistributionSetTag#getName()}. - * - * @param tagNames - * to be deleted - */ + @Override @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY) - public void deleteDistributionSetTag(@NotEmpty final String tagName) { + public void deleteDistributionSetTag(final String tagName) { final DistributionSetTag tag = distributionSetTagRepository.findByNameEquals(tagName); final List changed = new LinkedList<>(); @@ -321,20 +218,10 @@ public class TagManagement { afterCommit.afterCommit(() -> eventBus.post(new DistributionSetTagDeletedEvent(tag))); } - /** - * Updates an existing {@link DistributionSetTag}. - * - * @param distributionSetTag - * to be updated - * @return the updated {@link DistributionSet} - * @throws NullPointerException - * of {@link DistributionSetTag#getName()} is null - */ + @Override @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @NotNull - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - public DistributionSetTag updateDistributionSetTag(@NotNull final DistributionSetTag distributionSetTag) { + public DistributionSetTag updateDistributionSetTag(final DistributionSetTag distributionSetTag) { checkNotNull(distributionSetTag.getName()); checkNotNull(distributionSetTag.getId()); final DistributionSetTag save = distributionSetTagRepository.save(distributionSetTag); @@ -343,80 +230,34 @@ public class TagManagement { return save; } - /** - * returns all {@link DistributionTag}s. - * - * @return all {@link DistributionTag}s - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + @Override public List findAllDistributionSetTags() { return distributionSetTagRepository.findAll(); } - /** - * Finds {@link TargetTag} by given id. - * - * @param id - * to search for - * @return the found {@link TargetTag}s or null if not found. - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - public TargetTag findTargetTagById(@NotNull final Long id) { + @Override + public TargetTag findTargetTagById(final Long id) { return targetTagRepository.findOne(id); } - /** - * Finds {@link DistributionSetTag} by given id. - * - * @param id - * to search for - * @return the found {@link DistributionSetTag}s or null if not - * found. - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - public DistributionSetTag findDistributionSetTagById(@NotNull final Long id) { + @Override + public DistributionSetTag findDistributionSetTagById(final Long id) { return distributionSetTagRepository.findOne(id); } - /** - * returns all {@link TargetTag}s. - * - * @param pageReq - * page parameter - * - * @return all {@link TargetTag}s - */ - @NotNull - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - public Page findAllTargetTags(@NotNull final Pageable pageReq) { + @Override + public Page findAllTargetTags(final Pageable pageReq) { return targetTagRepository.findAll(pageReq); } - /** - * returns all {@link DistributionSetTag}s. - * - * @param pageReq - * page parameter - * @return all {@link DistributionSetTag}s - */ - @NotNull - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - public Page findAllDistributionSetTags(@NotNull final Pageable pageReq) { + @Override + public Page findAllDistributionSetTags(final Pageable pageReq) { return distributionSetTagRepository.findAll(pageReq); } - /** - * Retrieves all DistributionSet tags based on the given specification. - * - * @param spec - * the specification for the query - * @param pageable - * pagination parameter - * @return the found {@link DistributionSetTag}s, never {@code null} - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - public Page findAllDistributionSetTags(@NotNull final Specification spec, - @NotNull final Pageable pageable) { + @Override + public Page findAllDistributionSetTags(final Specification spec, + final Pageable pageable) { return distributionSetTagRepository.findAll(spec, pageable); } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetFilterQueryManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetFilterQueryManagement.java similarity index 51% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetFilterQueryManagement.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetFilterQueryManagement.java index 18ab0c486..a8c6b014f 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetFilterQueryManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetFilterQueryManagement.java @@ -11,9 +11,7 @@ package org.eclipse.hawkbit.repository.jpa; import java.util.ArrayList; import java.util.List; -import javax.validation.constraints.NotNull; - -import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; +import org.eclipse.hawkbit.repository.TargetFilterQueryManagement; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.model.TargetFilterQuery; import org.eclipse.hawkbit.repository.specifications.SpecificationsBuilder; @@ -24,7 +22,6 @@ import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.domain.Specifications; import org.springframework.data.jpa.repository.Modifying; -import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Isolation; import org.springframework.transaction.annotation.Transactional; @@ -34,28 +31,21 @@ import org.springframework.validation.annotation.Validated; import com.google.common.base.Strings; /** - * Business service facade for managing {@link TargetFilterQuery}s. + * JPA implementation of {@link TargetFilterQueryManagement}. * */ @Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) @Validated @Service -public class TargetFilterQueryManagement { +public class JpaTargetFilterQueryManagement implements TargetFilterQueryManagement { @Autowired private TargetFilterQueryRepository targetFilterQueryRepository; - /** - * creating new {@link TargetFilterQuery}. - * - * @param customTargetFilter - * @return the created {@link TargetFilterQuery} - */ + @Override @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @NotNull - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_TARGET) - public TargetFilterQuery createTargetFilterQuery(@NotNull final TargetFilterQuery customTargetFilter) { + public TargetFilterQuery createTargetFilterQuery(final TargetFilterQuery customTargetFilter) { if (targetFilterQueryRepository.findByName(customTargetFilter.getName()) != null) { throw new EntityAlreadyExistsException(customTargetFilter.getName()); @@ -63,44 +53,20 @@ public class TargetFilterQueryManagement { return targetFilterQueryRepository.save(customTargetFilter); } - /** - * Delete target filter query. - * - * @param targetFilterQueryId - * IDs of target filter query to be deleted - */ + @Override @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_TARGET) - public void deleteTargetFilterQuery(@NotNull final Long targetFilterQueryId) { + public void deleteTargetFilterQuery(final Long targetFilterQueryId) { targetFilterQueryRepository.delete(targetFilterQueryId); } - /** - * - * Retrieves all target filter query{@link TargetFilterQuery}. - * - * @param pageable - * pagination parameter - * @return the found {@link TargetFilterQuery}s - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - public Page findAllTargetFilterQuery(@NotNull final Pageable pageable) { + @Override + public Page findAllTargetFilterQuery(final Pageable pageable) { return targetFilterQueryRepository.findAll(pageable); } - /** - * Retrieves all target filter query which {@link TargetFilterQuery}. - * - * - * @param pageable - * pagination parameter - * @param name - * target filter query name - * @return the page with the found {@link TargetFilterQuery} - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - public Page findTargetFilterQueryByFilters(@NotNull final Pageable pageable, final String name) { + @Override + public Page findTargetFilterQueryByFilters(final Pageable pageable, final String name) { final List> specList = new ArrayList<>(); if (!Strings.isNullOrEmpty(name)) { specList.add(TargetFilterQuerySpecification.likeName(name)); @@ -108,15 +74,7 @@ public class TargetFilterQueryManagement { return findTargetFilterQueryByCriteriaAPI(pageable, specList); } - /** - * - * @param pageable - * pagination parameter - * @param specList - * list of @link {@link Specification} - * @return the page with the found {@link TargetFilterQuery} - */ - private Page findTargetFilterQueryByCriteriaAPI(@NotNull final Pageable pageable, + private Page findTargetFilterQueryByCriteriaAPI(final Pageable pageable, final List> specList) { if (specList == null || specList.isEmpty()) { return targetFilterQueryRepository.findAll(pageable); @@ -126,44 +84,20 @@ public class TargetFilterQueryManagement { return targetFilterQueryRepository.findAll(specs, pageable); } - /** - * Find target filter query by name. - * - * @param targetFilterQueryName - * Target filter query name - * @return the found {@link TargetFilterQuery} - * - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - public TargetFilterQuery findTargetFilterQueryByName(@NotNull final String targetFilterQueryName) { + @Override + public TargetFilterQuery findTargetFilterQueryByName(final String targetFilterQueryName) { return targetFilterQueryRepository.findByName(targetFilterQueryName); } - /** - * Find target filter query by id. - * - * @param targetFilterQueryId - * Target filter query id - * @return the found {@link TargetFilterQuery} - * - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - public TargetFilterQuery findTargetFilterQueryById(@NotNull final Long targetFilterQueryId) { + @Override + public TargetFilterQuery findTargetFilterQueryById(final Long targetFilterQueryId) { return targetFilterQueryRepository.findOne(targetFilterQueryId); } - /** - * updates the {@link TargetFilterQuery}. - * - * @param targetFilterQuery - * to be updated - * @return the updated {@link TargetFilterQuery} - */ + @Override @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @NotNull - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET) - public TargetFilterQuery updateTargetFilterQuery(@NotNull final TargetFilterQuery targetFilterQuery) { + public TargetFilterQuery updateTargetFilterQuery(final TargetFilterQuery targetFilterQuery) { Assert.notNull(targetFilterQuery.getId()); return targetFilterQueryRepository.save(targetFilterQuery); } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetManagement.java similarity index 52% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetManagement.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetManagement.java index 01d6eb527..513d5b52c 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetManagement.java @@ -17,7 +17,6 @@ import java.util.List; import java.util.stream.Collectors; import javax.annotation.PreDestroy; -import javax.persistence.Entity; import javax.persistence.EntityManager; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; @@ -27,17 +26,14 @@ import javax.persistence.criteria.JoinType; import javax.persistence.criteria.Order; import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Root; -import javax.validation.constraints.NotNull; import org.eclipse.hawkbit.Constants; import org.eclipse.hawkbit.eventbus.event.TargetTagAssigmentResultEvent; import org.eclipse.hawkbit.executor.AfterTransactionCommitExecutor; -import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; import org.eclipse.hawkbit.repository.TargetFields; +import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; -import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSet_; -import org.eclipse.hawkbit.repository.model.Tag; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetFilterQuery; import org.eclipse.hawkbit.repository.model.TargetIdName; @@ -50,7 +46,6 @@ import org.eclipse.hawkbit.repository.model.Target_; import org.eclipse.hawkbit.repository.rsql.RSQLUtility; import org.eclipse.hawkbit.repository.specifications.SpecificationsBuilder; import org.eclipse.hawkbit.repository.specifications.TargetSpecifications; -import org.hibernate.validator.constraints.NotEmpty; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheEvict; import org.springframework.data.domain.Page; @@ -61,7 +56,6 @@ import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort.Direction; import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.repository.Modifying; -import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Isolation; import org.springframework.transaction.annotation.Transactional; @@ -73,13 +67,13 @@ import com.google.common.collect.Lists; import com.google.common.eventbus.EventBus; /** - * Business service facade for managing {@link Target}s. + * JPA implementation of {@link TargetManagement}. * */ @Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) @Validated @Service -public class TargetManagement { +public class JpaTargetManagement implements TargetManagement { @Autowired private EntityManager entityManager; @@ -102,34 +96,13 @@ public class TargetManagement { @Autowired private AfterTransactionCommitExecutor afterCommit; - /** - * Find {@link Target} based on given ID returns found Target without - * details, i.e. NO {@link Target#getTags()} and - * {@link Target#getActiveActions()} possible. - * - * @param controllerId - * to look for. - * @return {@link Target} or null if it does not exist - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - public Target findTargetByControllerID(@NotEmpty final String controllerId) { + @Override + public Target findTargetByControllerID(final String controllerId) { return targetRepository.findByControllerId(controllerId); } - /** - * Find {@link Target} based on given ID returns found Target with details, - * i.e. {@link Target#getTags()} and {@link Target#getActiveActions()} are - * possible. - * - * Note: try to use {@link #findTargetByControllerID(String)} as much as - * possible. - * - * @param controllerId - * to look for. - * @return {@link Target} or null if it does not exist - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - public Target findTargetByControllerIDWithDetails(@NotEmpty final String controllerId) { + @Override + public Target findTargetByControllerIDWithDetails(final String controllerId) { final Target result = targetRepository.findByControllerId(controllerId); // load lazy relations if (result != null) { @@ -146,40 +119,18 @@ public class TargetManagement { return result; } - /** - * Find {@link Target} based on given ID returns found Target without - * details, i.e. NO {@link Target#getTags()} and - * {@link Target#getActiveActions()} possible. - * - * @param controllerIDs - * to look for. - * @return List of found{@link Target}s - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - public List findTargetByControllerID(@NotEmpty final Collection controllerIDs) { + @Override + public List findTargetByControllerID(final Collection controllerIDs) { return targetRepository.findAll(TargetSpecifications.byControllerIdWithStatusAndAssignedInJoin(controllerIDs)); } - /** - * Counts all {@link Target}s in the repository. - * - * @return number of targets - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + @Override public Long countTargetsAll() { return targetRepository.count(); } - /** - * Retrieves all targets without details, i.e. NO {@link Target#getTags()} - * and {@link Target#getActiveActions()} possible - * - * @param pageable - * pagination parameter - * @return the found {@link Target}s - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - public Slice findTargetsAll(@NotNull final Pageable pageable) { + @Override + public Slice findTargetsAll(final Pageable pageable) { // workarround - no join fetch allowed that is why we need specification // instead of query for // count() of Pageable @@ -192,113 +143,50 @@ public class TargetManagement { return criteriaNoCountDao.findAll(spec, pageable, Target.class); } - /** - * Retrieves all targets without details, i.e. NO {@link Target#getTags()} - * and {@link Target#getActiveActions()} possible based on - * {@link TargetFilterQuery#getQuery()} - * - * @param targetFilterQuery - * @param pageable - * @return - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - public Slice findTargetsAll(@NotNull final TargetFilterQuery targetFilterQuery, - @NotNull final Pageable pageable) { + @Override + public Slice findTargetsAll(final TargetFilterQuery targetFilterQuery, final Pageable pageable) { return findTargetsAll(RSQLUtility.parse(targetFilterQuery.getQuery(), TargetFields.class), pageable); } - /** - * Retrieves all targets without details, i.e. NO {@link Target#getTags()} - * and {@link Target#getActiveActions()} possible based on - * {@link TargetFilterQuery#getQuery()} - * - * @param targetFilterQuery - * @param pageable - * @return - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - public Slice findTargetsAll(@NotNull final String targetFilterQuery, @NotNull final Pageable pageable) { + @Override + public Slice findTargetsAll(final String targetFilterQuery, final Pageable pageable) { return findTargetsAll(RSQLUtility.parse(targetFilterQuery, TargetFields.class), pageable); } - /** - * Retrieves all targets based on the given specification. - * - * @param spec - * the specification for the query - * @param pageable - * pagination parameter - * @return the found {@link Target}s, never {@code null} - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - public Page findTargetsAll(@NotNull final Specification spec, @NotNull final Pageable pageable) { + @Override + public Page findTargetsAll(final Specification spec, final Pageable pageable) { return targetRepository.findAll(spec, pageable); } - /** - * retrieves a list of {@link Target}s by their controller ID with details, - * i.e. {@link Target#getTags()} are possible. - * - * Note: try to use {@link #findTargetByControllerID(String)} as much as - * possible. - * - * @param controllerIDs - * {@link Target}s Names parameter - * @return the found {@link Target}s - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - public List findTargetsByControllerIDsWithTags(@NotNull final List controllerIDs) { + @Override + public List findTargetsByControllerIDsWithTags(final List controllerIDs) { final List> partition = Lists.partition(controllerIDs, Constants.MAX_ENTRIES_IN_STATEMENT); return partition.stream() .map(ids -> targetRepository.findAll(TargetSpecifications.byControllerIdWithStatusAndTagsInJoin(ids))) .flatMap(t -> t.stream()).collect(Collectors.toList()); } - /** - * updates the {@link Target}. - * - * @param target - * to be updated - * @return the updated {@link Target} - */ + @Override @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @NotNull - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET + SpringEvalExpressions.HAS_AUTH_OR - + SpringEvalExpressions.IS_CONTROLLER) - public Target updateTarget(@NotNull final Target target) { + public Target updateTarget(final Target target) { Assert.notNull(target.getId()); target.setNew(false); return targetRepository.save(target); } - /** - * updates multiple {@link Target}s. - * - * @param targets - * to be updated - * @return the updated {@link Target}s - */ + @Override @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @NotNull - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET + SpringEvalExpressions.HAS_AUTH_OR - + SpringEvalExpressions.IS_CONTROLLER) - public List updateTargets(@NotNull final List targets) { + public List updateTargets(final Iterable targets) { targets.forEach(target -> target.setNew(false)); return targetRepository.save(targets); } - /** - * Deletes all targets with the given IDs. - * - * @param targetIDs - * the technical IDs of the targets to be deleted - */ + @Override @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_TARGET) - public void deleteTargets(@NotEmpty final Long... targetIDs) { + public void deleteTargets(final Long... targetIDs) { // we need to select the target IDs first to check the if the targetIDs // belonging to the // tenant! Delete statement are not automatically enhanced with the @@ -312,81 +200,25 @@ public class TargetManagement { } } - /** - * retrieves {@link Target}s by the assigned {@link DistributionSet} without - * details, i.e. NO {@link Target#getTags()} and - * {@link Target#getActiveActions()} possible. - * - * - * @param distributionSetID - * the ID of the {@link DistributionSet} - * @param pageReq - * page parameter - * @return the found {@link Target}s - */ - @NotNull - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_READ_TARGET) - public Page findTargetByAssignedDistributionSet(@NotNull final Long distributionSetID, - @NotNull final Pageable pageReq) { + @Override + public Page findTargetByAssignedDistributionSet(final Long distributionSetID, final Pageable pageReq) { return targetRepository.findByAssignedDistributionSetId(pageReq, distributionSetID); } - /** - * Retrieves {@link Target}s by the assigned {@link DistributionSet} without - * details, i.e. NO {@link Target#getTags()} and - * {@link Target#getActiveActions()} possible including additional filtering - * based on the given {@code spec}. - * - * @param distributionSetID - * the ID of the {@link DistributionSet} - * @param spec - * the specification to filter the result set - * @param pageReq - * page parameter - * @return the found {@link Target}s, never {@code null} - */ - @NotNull - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_READ_TARGET) - public Page findTargetByAssignedDistributionSet(@NotNull final Long distributionSetID, - final Specification spec, @NotNull final Pageable pageReq) { + @Override + public Page findTargetByAssignedDistributionSet(final Long distributionSetID, + final Specification spec, final Pageable pageReq) { return targetRepository.findAll((Specification) (root, query, cb) -> cb.and( TargetSpecifications.hasAssignedDistributionSet(distributionSetID).toPredicate(root, query, cb), spec.toPredicate(root, query, cb)), pageReq); } - /** - * retrieves {@link Target}s by the installed {@link DistributionSet}without - * details, i.e. NO {@link Target#getTags()} and - * {@link Target#getActiveActions()} possible. - * - * @param distributionSetID - * the ID of the {@link DistributionSet} - * @param pageReq - * page parameter - * @return the found {@link Target}s - */ - @NotNull - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_READ_TARGET) - public Page findTargetByInstalledDistributionSet(@NotNull final Long distributionSetID, - @NotNull final Pageable pageReq) { + @Override + public Page findTargetByInstalledDistributionSet(final Long distributionSetID, final Pageable pageReq) { return targetRepository.findByTargetInfoInstalledDistributionSetId(pageReq, distributionSetID); } - /** - * retrieves {@link Target}s by the installed {@link DistributionSet}without - * details, i.e. NO {@link Target#getTags()} and - * {@link Target#getActiveActions()} possible including additional filtering - * based on the given {@code spec}. - * - * @param distributionSetId - * the ID of the {@link DistributionSet} - * @param spec - * the specification to filter the result - * @param pageable - * page parameter - * @return the found {@link Target}s, never {@code null} - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_READ_TARGET) + @Override public Page findTargetByInstalledDistributionSet(final Long distributionSetId, final Specification spec, final Pageable pageable) { return targetRepository.findAll((Specification) (root, query, cb) -> cb.and( @@ -394,82 +226,21 @@ public class TargetManagement { spec.toPredicate(root, query, cb)), pageable); } - /** - * Retrieves the {@link Target} which have a certain - * {@link TargetUpdateStatus} without details, i.e. NO - * {@link Target#getTags()} and {@link Target#getActiveActions()} possible. - * - * @param pageable - * page parameter - * @param status - * the {@link TargetUpdateStatus} to be filtered on - * @return the found {@link Target}s - */ - @NotNull - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - public Page findTargetByUpdateStatus(@NotNull final Pageable pageable, - @NotNull final TargetUpdateStatus status) { + @Override + public Page findTargetByUpdateStatus(final Pageable pageable, final TargetUpdateStatus status) { return targetRepository.findByTargetInfoUpdateStatus(pageable, status); } - /** - * Filter {@link Target}s for all the given parameters. If all parameters - * except pageable are null, all available {@link Target}s are returned. - * - * @param pageable - * page parameters - * @param status - * find targets having this {@link TargetUpdateStatus}s. Set to - * null in case this is not required. - * @param searchText - * to find targets having the text anywhere in name or - * description. Set null in case this is not - * required. - * @param installedOrAssignedDistributionSetId - * to find targets having the {@link DistributionSet} as - * installed or assigned. Set to null in case this - * is not required. - * @param tagNames - * to find targets which are having any one in this tag names. - * Set null in case this is not required. - * @param selectTargetWithNoTag - * flag to select targets with no tag assigned - * - * @return the found {@link Target}s - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - public Slice findTargetByFilters(@NotNull final Pageable pageable, - final Collection status, final String searchText, - final Long installedOrAssignedDistributionSetId, final Boolean selectTargetWithNoTag, - final String... tagNames) { + @Override + public Slice findTargetByFilters(final Pageable pageable, final Collection status, + final String searchText, final Long installedOrAssignedDistributionSetId, + final Boolean selectTargetWithNoTag, final String... tagNames) { final List> specList = buildSpecificationList(status, searchText, installedOrAssignedDistributionSetId, selectTargetWithNoTag, true, tagNames); return findByCriteriaAPI(pageable, specList); } - /** - * Count {@link Target}s for all the given filter parameters. - * - * @param status - * find targets having on of these {@link TargetUpdateStatus}s. - * Set to null in case this is not required. - * @param searchText - * to find targets having the text anywhere in name or - * description. Set null in case this is not - * required. - * @param installedOrAssignedDistributionSetId - * to find targets having the {@link DistributionSet} as - * installed or assigned. Set to null in case this - * is not required. - * @param tagNames - * to find targets which are having any one in this tag names. - * Set null in case this is not required. - * @param selectTargetWithNoTag - * flag to select targets with no tag assigned - * - * @return the found number {@link Target}s - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + @Override public Long countTargetByFilters(final Collection status, final String searchText, final Long installedOrAssignedDistributionSetId, final Boolean selectTargetWithNoTag, final String... tagNames) { @@ -498,15 +269,6 @@ public class TargetManagement { return specList; } - /** - * executes findAll with the given {@link Target} {@link Specification}s. - * - * @param pageable - * paging parameter - * @param specList - * list of @link {@link Specification} - * @return the page with the found {@link Target} - */ private Slice findByCriteriaAPI(final Pageable pageable, final List> specList) { if (specList == null || specList.isEmpty()) { return criteriaNoCountDao.findAll(pageable, Target.class); @@ -522,44 +284,18 @@ public class TargetManagement { return targetRepository.count(SpecificationsBuilder.combineWithAnd(specList)); } - /** - * {@link Entity} based method call for - * {@link #toggleTagAssignment(Collection, String)}. - * - * @param targets - * to toggle for - * @param tag - * to toggle - * @return TagAssigmentResult with all metadata of the assignment outcome. - */ + @Override @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @NotNull - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET) - public TargetTagAssignmentResult toggleTagAssignment(@NotEmpty final List targets, - @NotNull final TargetTag tag) { + public TargetTagAssignmentResult toggleTagAssignment(final Collection targets, final TargetTag tag) { return toggleTagAssignment( targets.stream().map(target -> target.getControllerId()).collect(Collectors.toList()), tag.getName()); } - /** - * Toggles {@link TargetTag} assignment to given {@link Target}s by means - * that if some (or all) of the targets in the list have the {@link Tag} not - * yet assigned, they will be. If all of theme have the tag already assigned - * they will be removed instead. - * - * @param targetIds - * to toggle for - * @param tagName - * to toogle - * @return TagAssigmentResult with all metadata of the assigment outcome. - */ + @Override @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @NotNull - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET) - public TargetTagAssignmentResult toggleTagAssignment(@NotEmpty final Collection targetIds, - @NotNull final String tagName) { + public TargetTagAssignmentResult toggleTagAssignment(final Collection targetIds, final String tagName) { final TargetTag tag = targetTagRepository.findByNameEquals(tagName); final List alreadyAssignedTargets = targetRepository.findByTagNameAndControllerIdIn(tagName, targetIds); final List allTargets = targetRepository @@ -588,20 +324,10 @@ public class TargetManagement { return result; } - /** - * Assign a {@link TargetTag} assignment to given {@link Target}s. - * - * @param targetIds - * to assign for - * @param tagName - * to assign - * @return list of assigned targets - */ + @Override @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @NotNull - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET) - public List assignTag(@NotEmpty final Collection targetIds, @NotNull final TargetTag tag) { + public List assignTag(final Collection targetIds, final TargetTag tag) { final List allTargets = targetRepository .findAll(TargetSpecifications.byControllerIdWithStatusAndTagsInJoin(targetIds)); @@ -617,7 +343,7 @@ public class TargetManagement { return save; } - private List unAssignTag(@NotEmpty final Collection targets, @NotNull final TargetTag tag) { + private List unAssignTag(final Collection targets, final TargetTag tag) { targets.forEach(target -> target.getTags().remove(tag)); final List save = targetRepository.save(targets); @@ -629,83 +355,26 @@ public class TargetManagement { return save; } - /** - * Unassign all {@link Target} from a given {@link TargetTag} . - * - * @param tag - * to unassign all targets - * @return list of unassigned targets - */ + @Override @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @NotNull - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET) - public List unAssignAllTargetsByTag(@NotNull final TargetTag tag) { + public List unAssignAllTargetsByTag(final TargetTag tag) { return unAssignTag(tag.getAssignedToTargets(), tag); } - /** - * Unassign a {@link TargetTag} assignment to given {@link Target}. - * - * @param controllerID - * to unassign for - * @param targetTag - * to unassign - * @return the unassigned target or if no target is unassigned - */ + @Override @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET) - public Target unAssignTag(@NotNull final String controllerID, @NotNull final TargetTag targetTag) { + public Target unAssignTag(final String controllerID, final TargetTag targetTag) { final List allTargets = targetRepository .findAll(TargetSpecifications.byControllerIdWithStatusAndTagsInJoin(Arrays.asList(controllerID))); final List unAssignTag = unAssignTag(allTargets, targetTag); return unAssignTag.isEmpty() ? null : unAssignTag.get(0); } - /** - * method retrieves all {@link Target}s from the repo in the following - * order: - *

- * 1) {@link Target}s which have the given {@link DistributionSet} as - * {@link Target#getTargetStatus()} - * {@link TargetStatus#getInstalledDistributionSet()} - *

- * 2) {@link Target}s which have the given {@link DistributionSet} as - * {@link Target#getAssignedDistributionSet()} - *

- * 3) {@link Target}s which have no connection to the given - * {@link DistributionSet}. - * - * @param pageable - * the page request to page the result set - * @param orderByDistributionId - * {@link DistributionSet#getId()} to be ordered by - * @param filterByDistributionId - * {@link DistributionSet#getId()} to be filter the result. Set - * to null in case this is not required. - * @param filterByStatus - * find targets having this {@link TargetUpdateStatus}s. Set to - * null in case this is not required. - * @param filterBySearchText - * to find targets having the text anywhere in name or - * description. Set null in case this is not - * required. - * @param installedOrAssignedDistributionSetId - * to find targets having the {@link DistributionSet} as - * installed or assigned. Set to null in case this - * is not required. - * @param filterByTagNames - * to find targets which are having any one in this tag names. - * Set null in case this is not required. - * @param selectTargetWithNoTag - * flag to select targets with no tag assigned - * @return a paged result {@link Page} of the {@link Target}s in a defined - * order. - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - public Slice findTargetsAllOrderByLinkedDistributionSet(@NotNull final Pageable pageable, - @NotNull final Long orderByDistributionId, final Long filterByDistributionId, + @Override + public Slice findTargetsAllOrderByLinkedDistributionSet(final Pageable pageable, + final Long orderByDistributionId, final Long filterByDistributionId, final Collection filterByStatus, final String filterBySearchText, final Boolean selectTargetWithNoTag, final String... filterByTagNames) { final CriteriaBuilder cb = entityManager.getCriteriaBuilder(); @@ -756,9 +425,6 @@ public class TargetManagement { return new SliceImpl<>(resultList, pageable, hasNext); } - /** - * @param specifications - */ private static Predicate[] specificationsToPredicate(final List> specifications, final Root root, final CriteriaQuery query, final CriteriaBuilder cb) { final Predicate[] predicates = new Predicate[specifications.size()]; @@ -768,40 +434,17 @@ public class TargetManagement { return predicates; } - /** - * Counts number of targets with given - * {@link Target#getAssignedDistributionSet()}. - * - * @param distId - * to search for - * - * @return number of found {@link Target}s. - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + @Override public Long countTargetByAssignedDistributionSet(final Long distId) { return targetRepository.countByAssignedDistributionSetId(distId); } - /** - * Counts number of targets with given - * {@link TargetStatus#getInstalledDistributionSet()}. - * - * @param distId - * to search for - * @return number of found {@link Target}s. - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + @Override public Long countTargetByInstalledDistributionSet(final Long distId) { return targetRepository.countByTargetInfoInstalledDistributionSetId(distId); } - /** - * finds all {@link Target#getControllerId()} which are currently in the - * database. - * - * @return all IDs of all {@link Target} in the system - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + @Override public List findAllTargetIds() { final CriteriaBuilder cb = entityManager.getCriteriaBuilder(); final CriteriaQuery query = cb.createQuery(TargetIdName.class); @@ -811,34 +454,8 @@ public class TargetManagement { } - /** - * Finds all targets for all the given parameters but returns not the full - * target but {@link TargetIdName}. - * - * @param pageRequest - * the pageRequest to enhance the query for paging and sorting - * - * @param filterByStatus - * find targets having this {@link TargetUpdateStatus}s. Set to - * null in case this is not required. - * @param filterBySearchText - * to find targets having the text anywhere in name or - * description. Set null in case this is not - * required. - * @param installedOrAssignedDistributionSetId - * to find targets having the {@link DistributionSet} as - * installed or assigned. Set to null in case this - * is not required. - * @param filterByTagNames - * to find targets which are having any one in this tag names. - * Set null in case this is not required. - * @param selectTargetWithNoTag - * flag to select targets with no tag assigned - * - * @return the found {@link TargetIdName}s - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - public List findAllTargetIdsByFilters(@NotNull final Pageable pageRequest, + @Override + public List findAllTargetIdsByFilters(final Pageable pageRequest, final Collection filterByStatus, final String filterBySearchText, final Long installedOrAssignedDistributionSetId, final Boolean selectTargetWithNoTag, final String... filterByTagNames) { @@ -871,19 +488,9 @@ public class TargetManagement { .collect(Collectors.toList()); } - /** - * Finds all targets for all the given parameter {@link TargetFilterQuery} - * and returns not the full target but {@link TargetIdName}. - * - * @param pageRequest - * the pageRequest to enhance the query for paging and sorting - * @param targetFilterQuery - * {@link TargetFilterQuery} - * @return the found {@link TargetIdName}s - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + @Override public List findAllTargetIdsByTargetFilterQuery(final Pageable pageRequest, - @NotNull final TargetFilterQuery targetFilterQuery) { + final TargetFilterQuery targetFilterQuery) { final CriteriaBuilder cb = entityManager.getCriteriaBuilder(); final CriteriaQuery query = cb.createQuery(Object[].class); final Root targetRoot = query.from(Target.class); @@ -918,31 +525,12 @@ public class TargetManagement { eventBus.unregister(this); } - /** - * creating new {@link Target}s including poll status data. useful - * especially in plug and play scenarios. - * - * @param target - * to be created * - * @param status - * of the target - * @param lastTargetQuery - * if a plug and play case - * @param address - * if a plug and play case - * - * @throws EntityAlreadyExistsException - * - * @return - */ + @Override @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @NotNull - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_TARGET + SpringEvalExpressions.HAS_AUTH_OR - + SpringEvalExpressions.IS_CONTROLLER) @CacheEvict(value = { "targetsCreatedOverPeriod" }, allEntries = true) - public Target createTarget(@NotNull final Target target, @NotNull final TargetUpdateStatus status, - final Long lastTargetQuery, final URI address) { + public Target createTarget(final Target target, final TargetUpdateStatus status, final Long lastTargetQuery, + final URI address) { if (targetRepository.findByControllerId(target.getControllerId()) != null) { throw new EntityAlreadyExistsException(target.getControllerId()); @@ -965,43 +553,18 @@ public class TargetManagement { } - /** - * creating a new {@link Target}. - * - * @param target - * to be created - * @return the created {@link Target} - * - */ + @Override @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @NotNull - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_TARGET + SpringEvalExpressions.HAS_AUTH_OR - + SpringEvalExpressions.IS_CONTROLLER) @CacheEvict(value = { "targetsCreatedOverPeriod" }, allEntries = true) - public Target createTarget(@NotNull final Target target) { + public Target createTarget(final Target target) { return createTarget(target, TargetUpdateStatus.UNKNOWN, null, null); } - /** - * creates multiple {@link Target}s. If some of the given {@link Target}s - * already exists in the DB a {@link EntityAlreadyExistsException} is - * thrown. {@link Target}s contain all objects of the parameter targets, - * including duplicates. - * - * @param targets - * to be created. - * @return the created {@link Target}s - * - * @throws {@link - * EntityAlreadyExistsException} of one of the given targets - * already exist. - */ + @Override @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @NotNull - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_TARGET) - public List createTargets(@NotNull final List targets) { + public List createTargets(final Collection targets) { if (!targets.isEmpty() && targetRepository.countByControllerIdIn( targets.stream().map(target -> target.getControllerId()).collect(Collectors.toList())) > 0) { throw new EntityAlreadyExistsException(); @@ -1014,27 +577,11 @@ public class TargetManagement { return savedTargets; } - /** - * creating a new {@link Target} including poll status data. useful - * especially in plug and play scenarios. - * - * @param targets - * to be created * - * @param status - * of the target - * @param lastTargetQuery - * if a plug and play case - * @param address - * if a plug and play case - * - * @return newly created target - */ + @Override @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @NotNull - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_TARGET) - public List createTargets(@NotNull final Collection targets, - @NotNull final TargetUpdateStatus status, final long lastTargetQuery, final URI address) { + public List createTargets(final Collection targets, final TargetUpdateStatus status, + final Long lastTargetQuery, final URI address) { if (targetRepository.countByControllerIdIn( targets.stream().map(target -> target.getControllerId()).collect(Collectors.toList())) > 0) { throw new EntityAlreadyExistsException(); @@ -1047,42 +594,20 @@ public class TargetManagement { return savedTargets; } - /** - * Find targets by tag name. - * - * @param tagName - * tag name - * @return list of matching targets - */ - @NotNull - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - public List findTargetsByTag(@NotNull final String tagName) { + @Override + public List findTargetsByTag(final String tagName) { final TargetTag tag = targetTagRepository.findByNameEquals(tagName); return targetRepository.findByTag(tag); } - /** - * Count {@link TargetFilterQuery}s for given filter parameter. - * - * @param targetFilterQuery - * {link TargetFilterQuery} - * @return the found number {@link TargetFilterQuery}s - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - public Long countTargetByTargetFilterQuery(@NotNull final TargetFilterQuery targetFilterQuery) { + @Override + public Long countTargetByTargetFilterQuery(final TargetFilterQuery targetFilterQuery) { final Specification specs = RSQLUtility.parse(targetFilterQuery.getQuery(), TargetFields.class); return targetRepository.count(specs); } - /** - * Count {@link TargetFilterQuery}s for given target filter query. - * - * @param targetFilterQuery - * {link TargetFilterQuery} - * @return the found number {@link TargetFilterQuery}s - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - public Long countTargetByTargetFilterQuery(@NotNull final String targetFilterQuery) { + @Override + public Long countTargetByTargetFilterQuery(final String targetFilterQuery) { final Specification specs = RSQLUtility.parse(targetFilterQuery, TargetFields.class); return targetRepository.count(specs); } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TenantStatsManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTenantStatsManagement.java similarity index 73% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TenantStatsManagement.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTenantStatsManagement.java index 451a6e401..5c9cb7223 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TenantStatsManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTenantStatsManagement.java @@ -10,10 +10,9 @@ package org.eclipse.hawkbit.repository.jpa; import java.util.Optional; -import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; import org.eclipse.hawkbit.report.model.TenantUsage; +import org.eclipse.hawkbit.repository.TenantStatsManagement; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Isolation; import org.springframework.transaction.annotation.Propagation; @@ -21,12 +20,12 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; /** - * Management service for stats of a single tenant. + * Management service for statistics of a single tenant. * */ @Validated @Service -public class TenantStatsManagement { +public class JpaTenantStatsManagement implements TenantStatsManagement { @Autowired private TargetRepository targetRepository; @@ -37,17 +36,8 @@ public class TenantStatsManagement { @Autowired private ActionRepository actionRepository; - /** - * Service for stats of a single tenant. Opens a new transaction and as a - * result can an be used for multiple tenants, i.e. to allow in one session - * to collect data of all tenants in the system. - * - * @param tenant - * to collect for - * @return collected statistics - */ + @Override @Transactional(propagation = Propagation.REQUIRES_NEW, isolation = Isolation.READ_UNCOMMITTED) - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_SYSTEM_ADMIN) public TenantUsage getStatsOfTenant(final String tenant) { final TenantUsage result = new TenantUsage(tenant); diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/helper/SystemManagementHolder.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/helper/SystemManagementHolder.java index fd1d81280..d1327c690 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/helper/SystemManagementHolder.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/helper/SystemManagementHolder.java @@ -8,7 +8,7 @@ */ package org.eclipse.hawkbit.repository.model.helper; -import org.eclipse.hawkbit.repository.jpa.SystemManagement; +import org.eclipse.hawkbit.repository.SystemManagement; import org.springframework.beans.factory.annotation.Autowired; /** diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/AbstractIntegrationTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/AbstractIntegrationTest.java index dafc21eef..b134a3315 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/AbstractIntegrationTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/AbstractIntegrationTest.java @@ -23,6 +23,10 @@ import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.RolloutGroupManagement; import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.SoftwareManagement; +import org.eclipse.hawkbit.repository.SystemManagement; +import org.eclipse.hawkbit.repository.TagManagement; +import org.eclipse.hawkbit.repository.TargetFilterQueryManagement; +import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; import org.eclipse.hawkbit.repository.jpa.ActionRepository; import org.eclipse.hawkbit.repository.jpa.ActionStatusRepository; @@ -36,11 +40,7 @@ import org.eclipse.hawkbit.repository.jpa.RolloutRepository; import org.eclipse.hawkbit.repository.jpa.SoftwareModuleMetadataRepository; import org.eclipse.hawkbit.repository.jpa.SoftwareModuleRepository; import org.eclipse.hawkbit.repository.jpa.SoftwareModuleTypeRepository; -import org.eclipse.hawkbit.repository.jpa.SystemManagement; -import org.eclipse.hawkbit.repository.jpa.TagManagement; -import org.eclipse.hawkbit.repository.jpa.TargetFilterQueryManagement; import org.eclipse.hawkbit.repository.jpa.TargetInfoRepository; -import org.eclipse.hawkbit.repository.jpa.TargetManagement; import org.eclipse.hawkbit.repository.jpa.TargetRepository; import org.eclipse.hawkbit.repository.jpa.TargetTagRepository; import org.eclipse.hawkbit.repository.jpa.TenantMetaDataRepository; diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/TestDataUtil.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/TestDataUtil.java index 03a9b230f..1787d29e4 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/TestDataUtil.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/TestDataUtil.java @@ -19,7 +19,7 @@ import org.apache.commons.io.IOUtils; import org.eclipse.hawkbit.repository.ArtifactManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.SoftwareManagement; -import org.eclipse.hawkbit.repository.jpa.TargetManagement; +import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.DistributionSetType; diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TagManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TagManagementTest.java index 3deba1a56..4c6af0d83 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TagManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TagManagementTest.java @@ -21,7 +21,6 @@ import org.eclipse.hawkbit.AbstractIntegrationTest; import org.eclipse.hawkbit.TestDataUtil; import org.eclipse.hawkbit.repository.DistributionSetFilter.DistributionSetFilterBuilder; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; -import org.eclipse.hawkbit.repository.jpa.TagManagement; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult; diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagenmentTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagenmentTest.java index 37d4ea683..99e08f331 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagenmentTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagenmentTest.java @@ -13,7 +13,6 @@ import static org.junit.Assert.fail; import org.eclipse.hawkbit.AbstractIntegrationTest; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; -import org.eclipse.hawkbit.repository.jpa.TargetFilterQueryManagement; import org.eclipse.hawkbit.repository.model.TargetFilterQuery; import org.junit.Test; diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/utils/RepositoryDataGenerator.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/utils/RepositoryDataGenerator.java index f27c7b707..73958e6fa 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/utils/RepositoryDataGenerator.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/utils/RepositoryDataGenerator.java @@ -31,8 +31,8 @@ import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.DistributionSetAssignmentResult; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.SoftwareManagement; -import org.eclipse.hawkbit.repository.jpa.TagManagement; -import org.eclipse.hawkbit.repository.jpa.TargetManagement; +import org.eclipse.hawkbit.repository.TagManagement; +import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetResource.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetResource.java index a30927ebf..1a766c8c4 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetResource.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetResource.java @@ -19,10 +19,10 @@ import org.eclipse.hawkbit.repository.DistributionSetFields; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.DistributionSetMetadataFields; import org.eclipse.hawkbit.repository.SoftwareManagement; +import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.repository.TargetFields; +import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; -import org.eclipse.hawkbit.repository.jpa.SystemManagement; -import org.eclipse.hawkbit.repository.jpa.TargetManagement; import org.eclipse.hawkbit.repository.jpa.TargetWithActionType; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetMetadata; diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTagResource.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTagResource.java index e630003c5..eaa0fec28 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTagResource.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTagResource.java @@ -13,8 +13,8 @@ import java.util.stream.Collectors; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.TagFields; +import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; -import org.eclipse.hawkbit.repository.jpa.TagManagement; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult; diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SystemManagementResource.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SystemManagementResource.java index c5663f9f5..27cfdb924 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SystemManagementResource.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SystemManagementResource.java @@ -16,8 +16,8 @@ import java.util.stream.Collectors; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; import org.eclipse.hawkbit.report.model.SystemUsageReport; import org.eclipse.hawkbit.report.model.TenantUsage; +import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; -import org.eclipse.hawkbit.repository.jpa.SystemManagement; import org.eclipse.hawkbit.rest.resource.model.systemmanagement.CacheRest; import org.eclipse.hawkbit.rest.resource.model.systemmanagement.SystemStatisticsRest; import org.eclipse.hawkbit.rest.resource.model.systemmanagement.TenantSystemUsageRest; diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/TargetResource.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/TargetResource.java index df779c688..4b068a41e 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/TargetResource.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/TargetResource.java @@ -19,8 +19,8 @@ import org.eclipse.hawkbit.repository.ActionFields; import org.eclipse.hawkbit.repository.ActionStatusFields; import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.TargetFields; +import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; -import org.eclipse.hawkbit.repository.jpa.TargetManagement; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.ActionType; import org.eclipse.hawkbit.repository.model.ActionStatus; diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/TargetTagResource.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/TargetTagResource.java index b6946145d..1a9155828 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/TargetTagResource.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/TargetTagResource.java @@ -12,9 +12,9 @@ import java.util.List; import java.util.stream.Collectors; import org.eclipse.hawkbit.repository.TagFields; +import org.eclipse.hawkbit.repository.TagManagement; +import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; -import org.eclipse.hawkbit.repository.jpa.TagManagement; -import org.eclipse.hawkbit.repository.jpa.TargetManagement; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetTag; import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult; diff --git a/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/DistributionSetResourceTest.java b/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/DistributionSetResourceTest.java index ac1c95374..3705e8da3 100644 --- a/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/DistributionSetResourceTest.java +++ b/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/DistributionSetResourceTest.java @@ -33,9 +33,9 @@ import org.eclipse.hawkbit.WithUser; import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.SoftwareManagement; +import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.jpa.ActionRepository; -import org.eclipse.hawkbit.repository.jpa.TargetManagement; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTargetTagToken.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTargetTagToken.java index 1e3ab9b03..ce9f101f3 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTargetTagToken.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTargetTagToken.java @@ -10,7 +10,7 @@ package org.eclipse.hawkbit.ui.common.tagdetails; import org.eclipse.hawkbit.eventbus.event.TargetTagCreatedBulkEvent; import org.eclipse.hawkbit.eventbus.event.TargetTagDeletedEvent; -import org.eclipse.hawkbit.repository.jpa.TagManagement; +import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.model.BaseEntity; import org.eclipse.hawkbit.repository.model.TargetTag; import org.springframework.beans.factory.annotation.Autowired; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/DistributionTagToken.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/DistributionTagToken.java index bc46f50fd..178610c23 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/DistributionTagToken.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/DistributionTagToken.java @@ -19,7 +19,7 @@ import org.eclipse.hawkbit.eventbus.event.DistributionSetTagCreatedBulkEvent; import org.eclipse.hawkbit.eventbus.event.DistributionSetTagDeletedEvent; import org.eclipse.hawkbit.eventbus.event.DistributionSetTagUpdateEvent; import org.eclipse.hawkbit.repository.DistributionSetManagement; -import org.eclipse.hawkbit.repository.jpa.TagManagement; +import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/TargetTagToken.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/TargetTagToken.java index e607c99d2..6f03c5860 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/TargetTagToken.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/TargetTagToken.java @@ -16,7 +16,7 @@ import java.util.stream.Collectors; import org.eclipse.hawkbit.eventbus.event.TargetTagAssigmentResultEvent; import org.eclipse.hawkbit.eventbus.event.TargetTagUpdateEvent; -import org.eclipse.hawkbit.repository.jpa.TargetManagement; +import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetTag; import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java index e92e4e735..c1ee96146 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java @@ -20,7 +20,7 @@ import java.util.Set; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.SpPermissionChecker; -import org.eclipse.hawkbit.repository.jpa.TargetManagement; +import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetIdName; import org.eclipse.hawkbit.repository.model.SoftwareModule; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/ManageDistBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/ManageDistBeanQuery.java index c22e63241..1fd306816 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/ManageDistBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/ManageDistBeanQuery.java @@ -15,8 +15,8 @@ import java.util.List; import java.util.Map; import org.eclipse.hawkbit.repository.DistributionSetFilter; -import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.DistributionSetFilter.DistributionSetFilterBuilder; +import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.jpa.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetType; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DSDeleteActionsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DSDeleteActionsLayout.java index 940323b53..5bc1627a9 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DSDeleteActionsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/footer/DSDeleteActionsLayout.java @@ -15,7 +15,7 @@ import java.util.List; import java.util.Map.Entry; import java.util.Set; -import org.eclipse.hawkbit.repository.jpa.SystemManagement; +import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.repository.model.DistributionSetIdName; import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.SoftwareModuleIdName; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterHeader.java index 2abfcb731..b41f3dfe9 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterHeader.java @@ -14,7 +14,7 @@ import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; import org.eclipse.hawkbit.repository.SpPermissionChecker; -import org.eclipse.hawkbit.repository.jpa.TargetFilterQueryManagement; +import org.eclipse.hawkbit.repository.TargetFilterQueryManagement; import org.eclipse.hawkbit.repository.model.TargetFilterQuery; import org.eclipse.hawkbit.ui.UiProperties; import org.eclipse.hawkbit.ui.components.SPUIButton; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CustomTargetBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CustomTargetBeanQuery.java index fe0ecf489..35f88f5a1 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CustomTargetBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CustomTargetBeanQuery.java @@ -12,7 +12,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -import org.eclipse.hawkbit.repository.jpa.TargetManagement; +import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.ui.common.UserDetailsFormatter; import org.eclipse.hawkbit.ui.components.ProxyTarget; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/FilterQueryValidation.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/FilterQueryValidation.java index 591a2f457..4f528c74a 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/FilterQueryValidation.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/FilterQueryValidation.java @@ -16,7 +16,7 @@ import java.util.List; import java.util.stream.Collectors; import org.eclipse.hawkbit.repository.TargetFields; -import org.eclipse.hawkbit.repository.jpa.TargetManagement; +import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.rsql.RSQLParameterSyntaxException; import org.eclipse.hawkbit.repository.rsql.RSQLParameterUnsupportedFieldException; import org.eclipse.hawkbit.ui.utils.SpringContextHelper; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/TargetFilterBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/TargetFilterBeanQuery.java index 37e25f152..4a2d6da6c 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/TargetFilterBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/TargetFilterBeanQuery.java @@ -12,7 +12,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -import org.eclipse.hawkbit.repository.jpa.TargetFilterQueryManagement; +import org.eclipse.hawkbit.repository.TargetFilterQueryManagement; import org.eclipse.hawkbit.repository.model.TargetFilterQuery; import org.eclipse.hawkbit.ui.common.UserDetailsFormatter; import org.eclipse.hawkbit.ui.components.ProxyTargetFilter; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/TargetFilterTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/TargetFilterTable.java index b2b6d5913..17bfefe56 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/TargetFilterTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/TargetFilterTable.java @@ -17,7 +17,7 @@ import java.util.Map; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; -import org.eclipse.hawkbit.repository.jpa.TargetFilterQueryManagement; +import org.eclipse.hawkbit.repository.TargetFilterQueryManagement; import org.eclipse.hawkbit.repository.model.TargetFilterQuery; import org.eclipse.hawkbit.ui.common.ConfirmationDialog; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionAddUpdateWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionAddUpdateWindowLayout.java index 1910aafdf..d13dc94cf 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionAddUpdateWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionAddUpdateWindowLayout.java @@ -16,8 +16,8 @@ import java.util.Map; import javax.annotation.PostConstruct; import org.eclipse.hawkbit.repository.DistributionSetManagement; +import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; -import org.eclipse.hawkbit.repository.jpa.SystemManagement; import org.eclipse.hawkbit.repository.jpa.TenantMetaDataRepository; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetType; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionBeanQuery.java index 5d154dced..353ef3e95 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionBeanQuery.java @@ -14,8 +14,8 @@ import java.util.List; import java.util.Map; import org.eclipse.hawkbit.repository.DistributionSetFilter; -import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.DistributionSetFilter.DistributionSetFilterBuilder; +import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.jpa.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.ui.common.UserDetailsFormatter; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java index a9cccc8c1..0df1b0ea5 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java @@ -19,7 +19,7 @@ import java.util.stream.Collectors; import org.apache.commons.lang3.StringUtils; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.SpPermissionChecker; -import org.eclipse.hawkbit.repository.jpa.TargetManagement; +import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetIdName; import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagBeanQuery.java index 0021f7bd1..9b66f2836 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagBeanQuery.java @@ -12,8 +12,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.jpa.OffsetBasedPageRequest; -import org.eclipse.hawkbit.repository.jpa.TagManagement; import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.ui.management.tag.ProxyTag; import org.eclipse.hawkbit.ui.management.tag.TagIdName; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/CountMessageLabel.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/CountMessageLabel.java index 65b5dcdbd..ed002defb 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/CountMessageLabel.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/CountMessageLabel.java @@ -13,7 +13,7 @@ import java.util.List; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; -import org.eclipse.hawkbit.repository.jpa.TargetManagement; +import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.model.DistributionSetIdName; import org.eclipse.hawkbit.repository.model.TargetFilterQuery; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java index 4a6f8d824..ad537e626 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/DeleteActionsLayout.java @@ -10,7 +10,7 @@ package org.eclipse.hawkbit.ui.management.footer; import java.util.Set; -import org.eclipse.hawkbit.repository.jpa.TagManagement; +import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.model.DistributionSetIdName; import org.eclipse.hawkbit.repository.model.TargetIdName; import org.eclipse.hawkbit.ui.common.footer.AbstractDeleteActionsLayout; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/ManangementConfirmationWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/ManangementConfirmationWindowLayout.java index 4e34ef606..56e11a6fe 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/ManangementConfirmationWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/ManangementConfirmationWindowLayout.java @@ -22,7 +22,7 @@ import java.util.stream.Collectors; import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.DistributionSetAssignmentResult; import org.eclipse.hawkbit.repository.DistributionSetManagement; -import org.eclipse.hawkbit.repository.jpa.TargetManagement; +import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.ActionType; import org.eclipse.hawkbit.repository.model.DistributionSetIdName; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/tag/CreateUpdateTagLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/tag/CreateUpdateTagLayout.java index ff88d2004..6bed7dd4f 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/tag/CreateUpdateTagLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/tag/CreateUpdateTagLayout.java @@ -14,7 +14,7 @@ import java.util.Set; import javax.annotation.PreDestroy; import org.eclipse.hawkbit.repository.SpPermissionChecker; -import org.eclipse.hawkbit.repository.jpa.TagManagement; +import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.TargetTag; import org.eclipse.hawkbit.ui.common.CoordinatesToColor; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java index 1d720da22..2369893c7 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java @@ -26,8 +26,8 @@ import java.util.concurrent.Executor; import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement; -import org.eclipse.hawkbit.repository.jpa.TagManagement; -import org.eclipse.hawkbit.repository.jpa.TargetManagement; +import org.eclipse.hawkbit.repository.TagManagement; +import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.model.Action.ActionType; import org.eclipse.hawkbit.repository.model.DistributionSetIdName; import org.eclipse.hawkbit.repository.model.Target; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetAddUpdateWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetAddUpdateWindowLayout.java index d5eb6be5c..e54911d86 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetAddUpdateWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetAddUpdateWindowLayout.java @@ -11,7 +11,7 @@ package org.eclipse.hawkbit.ui.management.targettable; import java.util.HashSet; import java.util.Set; -import org.eclipse.hawkbit.repository.jpa.TargetManagement; +import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetIdName; import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBeanQuery.java index 3645e82d1..f3e0078f3 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBeanQuery.java @@ -13,8 +13,8 @@ import java.util.Collection; import java.util.List; import java.util.Map; +import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.jpa.OffsetBasedPageRequest; -import org.eclipse.hawkbit.repository.jpa.TargetManagement; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetFilterQuery; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBulkUpdateWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBulkUpdateWindowLayout.java index 95e1da7b7..657cd97af 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBulkUpdateWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBulkUpdateWindowLayout.java @@ -16,7 +16,7 @@ import java.util.Map; import javax.annotation.PreDestroy; import org.eclipse.hawkbit.repository.DeploymentManagement; -import org.eclipse.hawkbit.repository.jpa.TargetManagement; +import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.model.DistributionSetIdName; import org.eclipse.hawkbit.ui.UiProperties; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java index 47e896a79..4ed2580f6 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java @@ -22,8 +22,8 @@ import org.eclipse.hawkbit.eventbus.event.TargetCreatedEvent; import org.eclipse.hawkbit.eventbus.event.TargetDeletedEvent; import org.eclipse.hawkbit.eventbus.event.TargetInfoUpdateEvent; import org.eclipse.hawkbit.repository.SpPermissionChecker; +import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.jpa.OffsetBasedPageRequest; -import org.eclipse.hawkbit.repository.jpa.TargetManagement; import org.eclipse.hawkbit.repository.model.DistributionSetIdName; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetFilterQuery; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/CustomTargetTagFilterButtonClick.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/CustomTargetTagFilterButtonClick.java index 26d36c254..ac85b928b 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/CustomTargetTagFilterButtonClick.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/CustomTargetTagFilterButtonClick.java @@ -10,7 +10,7 @@ package org.eclipse.hawkbit.ui.management.targettag; import java.io.Serializable; -import org.eclipse.hawkbit.repository.jpa.TargetFilterQueryManagement; +import org.eclipse.hawkbit.repository.TargetFilterQueryManagement; import org.eclipse.hawkbit.repository.model.TargetFilterQuery; import org.eclipse.hawkbit.ui.common.filterlayout.AbstractFilterSingleButtonClick; import org.eclipse.hawkbit.ui.management.event.TargetFilterEvent; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagBeanQuery.java index b57d4d1c9..066383d8a 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagBeanQuery.java @@ -12,8 +12,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.jpa.OffsetBasedPageRequest; -import org.eclipse.hawkbit.repository.jpa.TagManagement; import org.eclipse.hawkbit.repository.model.TargetTag; import org.eclipse.hawkbit.ui.management.tag.ProxyTag; import org.eclipse.hawkbit.ui.management.tag.TagIdName; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java index 8d76f45b7..48447f112 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java @@ -16,7 +16,7 @@ import org.eclipse.hawkbit.eventbus.event.TargetTagCreatedBulkEvent; import org.eclipse.hawkbit.eventbus.event.TargetTagDeletedEvent; import org.eclipse.hawkbit.eventbus.event.TargetTagUpdateEvent; import org.eclipse.hawkbit.repository.SpPermissionChecker; -import org.eclipse.hawkbit.repository.jpa.TargetManagement; +import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.model.TargetIdName; import org.eclipse.hawkbit.repository.model.TargetTag; import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java index 92b24e301..7e8d45e1b 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java @@ -14,7 +14,7 @@ import java.util.List; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.RolloutManagement; -import org.eclipse.hawkbit.repository.jpa.TargetManagement; +import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.ActionType; import org.eclipse.hawkbit.repository.model.DistributionSetIdName; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/DistributionBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/DistributionBeanQuery.java index 9422e431f..75d2741af 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/DistributionBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/DistributionBeanQuery.java @@ -15,8 +15,8 @@ import java.util.List; import java.util.Map; import org.eclipse.hawkbit.repository.DistributionSetFilter; -import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.DistributionSetFilter.DistributionSetFilterBuilder; +import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.ui.common.UserDetailsFormatter; import org.eclipse.hawkbit.ui.components.ProxyDistribution; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java index c03b9e5d0..8a9675564 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java @@ -13,7 +13,7 @@ import java.util.List; import java.util.Map; import org.eclipse.hawkbit.repository.RolloutManagement; -import org.eclipse.hawkbit.repository.jpa.TargetFilterQueryManagement; +import org.eclipse.hawkbit.repository.TargetFilterQueryManagement; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/DefaultDistributionSetTypeLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/DefaultDistributionSetTypeLayout.java index 4660937cd..0162f6ed8 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/DefaultDistributionSetTypeLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/DefaultDistributionSetTypeLayout.java @@ -11,7 +11,7 @@ package org.eclipse.hawkbit.ui.tenantconfiguration; import javax.annotation.PostConstruct; import org.eclipse.hawkbit.repository.DistributionSetManagement; -import org.eclipse.hawkbit.repository.jpa.SystemManagement; +import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.TenantMetaData; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; From 037e66e197a24b4244a98f0847180f22ecb8a88e Mon Sep 17 00:00:00 2001 From: Asharani Date: Fri, 20 May 2016 15:48:38 +0530 Subject: [PATCH 15/54] Allowe parallel uploads of same file for different software module. Display software module details in status popup. Signed-off-by: Asharani --- .../ui/artifacts/upload/UploadHandler.java | 25 ++-- .../ui/artifacts/upload/UploadLayout.java | 12 +- .../upload/UploadStatusInfoWindow.java | 110 +++++++++++------- .../artifacts/upload/UploadStatusObject.java | 15 ++- 4 files changed, 101 insertions(+), 61 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java index 45a55d138..dc56ff325 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java @@ -249,18 +249,18 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene // Update progress is called event after upload interrupted in // uploadStarted method if (!uploadInterrupted) { - if (readBytes > maxSize || contentLength > maxSize) { - LOG.error("User tried to upload more than was allowed ({}).", maxSize); - failureReason = i18n.get("message.uploadedfile.size.exceeded", maxSize); - interruptFileUpload(); - return; - } if (aborted) { LOG.error("User aborted file upload"); failureReason = i18n.get("message.uploadedfile.aborted"); interruptFileUpload(); return; } + if (readBytes > maxSize || contentLength > maxSize) { + LOG.error("User tried to upload more than was allowed ({}).", maxSize); + failureReason = i18n.get("message.uploadedfile.size.exceeded", maxSize); + interruptFileUpload(); + return; + } eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_IN_PROGRESS, new UploadFileStatus(fileName, readBytes, contentLength, selectedSwForUpload))); LOG.info("Update progress - {} : {}", fileName, (double) readBytes / (double) contentLength); @@ -274,18 +274,18 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene */ @Override public void onProgress(final StreamingProgressEvent event) { - if (event.getBytesReceived() > maxSize || event.getContentLength() > maxSize) { - LOG.error("User tried to upload more than was allowed ({}).", maxSize); - failureReason = i18n.get("message.uploadedfile.size.exceeded", maxSize); - interruptFileStreaming(); - return; - } if (aborted) { LOG.error("User aborted the upload"); failureReason = i18n.get("message.uploadedfile.aborted"); interruptFileStreaming(); return; } + if (event.getBytesReceived() > maxSize || event.getContentLength() > maxSize) { + LOG.error("User tried to upload more than was allowed ({}).", maxSize); + failureReason = i18n.get("message.uploadedfile.size.exceeded", maxSize); + interruptFileStreaming(); + return; + } eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_IN_PROGRESS, new UploadFileStatus( fileName, event.getBytesReceived(), event.getContentLength(), selectedSw))); // Logging to solve sonar issue @@ -380,4 +380,5 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene upload.interruptUpload(); uploadInterrupted = true; } + } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java index 4eaa61096..e19742e4f 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java @@ -222,6 +222,11 @@ public class UploadLayout extends VerticalLayout { setUploadStatusButtonIconToFinished(); } } + if (artifactUploadState.isUploadCompleted()) { + artifactUploadState.getNumberOfFilesActuallyUpload().set(0); + artifactUploadState.getNumberOfFileUploadsExpected().set(0); + artifactUploadState.getNumberOfFileUploadsFailed().set(0); + } } public DragAndDropWrapper getDropAreaWrapper() { @@ -692,7 +697,7 @@ public class UploadLayout extends VerticalLayout { // failed reason to be updated only if there is error other than // duplicate file error uploadInfoWindow.uploadFailed(event.getUploadStatus().getFileName(), event.getUploadStatus() - .getFailureReason()); + .getFailureReason(), event.getUploadStatus().getSoftwareModule()); increaseNumberOfFileUploadsFailed(); } decreaseNumberOfFileUploadsExpected(); @@ -722,13 +727,12 @@ public class UploadLayout extends VerticalLayout { } updateUploadCounts(); enableProcessBtn(); - duplicateFileNamesList.clear(); } private boolean isUploadComplete() { int uploadedCount = artifactUploadState.getNumberOfFilesActuallyUpload().intValue(); int expectedUploadsCount = artifactUploadState.getNumberOfFileUploadsExpected().intValue(); - return uploadedCount == expectedUploadsCount; + return uploadedCount == expectedUploadsCount; } private void onUploadFailure(final UploadStatusEvent event) { @@ -746,7 +750,7 @@ public class UploadLayout extends VerticalLayout { // failed reason to be updated only if there is error other than // duplicate file error uploadInfoWindow.uploadFailed(event.getUploadStatus().getFileName(), event.getUploadStatus() - .getFailureReason()); + .getFailureReason(), event.getUploadStatus().getSoftwareModule()); increaseNumberOfFileUploadsFailed(); decreaseNumberOfFileUploadsExpected(); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusInfoWindow.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusInfoWindow.java index 351d625c9..e4ab8d474 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusInfoWindow.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusInfoWindow.java @@ -14,6 +14,7 @@ import java.util.stream.Collectors; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; +import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.ui.artifacts.event.UploadArtifactUIEvent; import org.eclipse.hawkbit.ui.artifacts.event.UploadStatusEvent; import org.eclipse.hawkbit.ui.artifacts.event.UploadStatusEvent.UploadStatusEventType; @@ -21,8 +22,10 @@ import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState; import org.eclipse.hawkbit.ui.common.ConfirmationDialog; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; +import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; +import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; import org.springframework.beans.factory.annotation.Autowired; import org.vaadin.spring.events.EventBus; @@ -100,7 +103,7 @@ public class UploadStatusInfoWindow extends Window { private Button resizeButton; private UI ui; - + private ConfirmationDialog confirmDialog; /** @@ -126,7 +129,7 @@ public class UploadStatusInfoWindow extends Window { setContent(mainLayout); eventBus.subscribe(this); ui = UI.getCurrent(); - + createConfirmDialog(); } @@ -135,22 +138,25 @@ public class UploadStatusInfoWindow extends Window { if (event.getUploadProgressEventType() == UploadStatusEventType.UPLOAD_IN_PROGRESS) { UI.getCurrent().access( () -> updateProgress(event.getUploadStatus().getFileName(), event.getUploadStatus().getBytesRead(), - event.getUploadStatus().getContentLength())); + event.getUploadStatus().getContentLength(), event.getUploadStatus().getSoftwareModule())); } else if (event.getUploadProgressEventType() == UploadStatusEventType.UPLOAD_STARTED) { UI.getCurrent().access(() -> onStartOfUpload(event)); } else if (event.getUploadProgressEventType() == UploadStatusEventType.UPLOAD_STREAMING_FAILED) { ui.access(() -> uploadFailed(event.getUploadStatus().getFileName(), event.getUploadStatus() - .getFailureReason())); + .getFailureReason(), event.getUploadStatus().getSoftwareModule())); } else if (event.getUploadProgressEventType() == UploadStatusEventType.UPLOAD_SUCCESSFUL) { - UI.getCurrent().access(() -> uploadSucceeded(event.getUploadStatus().getFileName())); + UI.getCurrent().access( + () -> uploadSucceeded(event.getUploadStatus().getFileName(), event.getUploadStatus() + .getSoftwareModule())); } else if (event.getUploadProgressEventType() == UploadStatusEventType.UPLOAD_STREAMING_FINISHED) { - ui.access(() -> uploadSucceeded(event.getUploadStatus().getFileName())); + ui.access(() -> uploadSucceeded(event.getUploadStatus().getFileName(), event.getUploadStatus() + .getSoftwareModule())); } } private void onStartOfUpload(UploadStatusEvent event) { uploadSessionStarted(); - uploadStarted(event.getUploadStatus().getFileName()); + uploadStarted(event.getUploadStatus().getFileName(), event.getUploadStatus().getSoftwareModule()); } @PreDestroy @@ -167,11 +173,15 @@ public class UploadStatusInfoWindow extends Window { if (container.getItemIds().isEmpty()) { container.removeAllItems(); for (UploadStatusObject statusObject : artifactUploadState.getUploadedFileStatusList()) { - Item item = container.addItem(statusObject.getFilename()); + Item item = container.addItem(getItemid(statusObject.getFilename(), + statusObject.getSelectedSoftwareModule())); item.getItemProperty(REASON).setValue(statusObject.getReason() != null ? statusObject.getReason() : ""); item.getItemProperty(STATUS).setValue(statusObject.getStatus()); item.getItemProperty(PROGRESS).setValue(statusObject.getProgress()); item.getItemProperty(FILE_NAME).setValue(statusObject.getFilename()); + SoftwareModule sw = statusObject.getSelectedSoftwareModule(); + item.getItemProperty(SPUILabelDefinitions.NAME_VERSION).setValue( + HawkbitCommonUtil.getFormattedNameVersion(sw.getName(), sw.getVersion())); } if (artifactUploadState.isUploadCompleted()) { minimizeButton.setEnabled(false); @@ -192,9 +202,10 @@ public class UploadStatusInfoWindow extends Window { private void setGridColumnProperties() { grid.getColumn(STATUS).setRenderer(new StatusRenderer()); grid.getColumn(PROGRESS).setRenderer(new ProgressBarRenderer()); - grid.setColumnOrder(STATUS, PROGRESS, FILE_NAME, REASON); + grid.setColumnOrder(STATUS, PROGRESS, FILE_NAME, SPUILabelDefinitions.NAME_VERSION, REASON); setColumnWidth(); - grid.setFrozenColumnCount(4); + grid.getColumn(SPUILabelDefinitions.NAME_VERSION).setHeaderCaption(i18n.get("upload.swModuleTable.header")); + grid.setFrozenColumnCount(5); } private Grid createGrid() { @@ -213,6 +224,7 @@ public class UploadStatusInfoWindow extends Window { uploadContainer.addContainerProperty(FILE_NAME, String.class, null); uploadContainer.addContainerProperty(PROGRESS, Double.class, 0D); uploadContainer.addContainerProperty(REASON, String.class, ""); + uploadContainer.addContainerProperty(SPUILabelDefinitions.NAME_VERSION, String.class, ""); return uploadContainer; } @@ -234,10 +246,11 @@ public class UploadStatusInfoWindow extends Window { } private void setColumnWidth() { - grid.getColumn(STATUS).setWidth(70); + grid.getColumn(STATUS).setWidth(60); grid.getColumn(PROGRESS).setWidth(150); - grid.getColumn(FILE_NAME).setWidth(280); - grid.getColumn(REASON).setWidth(300); + grid.getColumn(FILE_NAME).setWidth(200); + grid.getColumn(REASON).setWidth(290); + grid.getColumn(SPUILabelDefinitions.NAME_VERSION).setWidth(200); } private void resetColumnWidth() { @@ -245,6 +258,7 @@ public class UploadStatusInfoWindow extends Window { grid.getColumn(PROGRESS).setWidthUndefined(); grid.getColumn(FILE_NAME).setWidthUndefined(); grid.getColumn(REASON).setWidthUndefined(); + grid.getColumn(SPUILabelDefinitions.NAME_VERSION).setWidthUndefined(); } private static class StatusRenderer extends HtmlRenderer { @@ -307,29 +321,32 @@ public class UploadStatusInfoWindow extends Window { restoreState(); } - void uploadStarted(final String filename) { - final Item item = uploads.addItem(filename); + void uploadStarted(final String filename, final SoftwareModule softwareModule) { + final Item item = uploads.addItem(getItemid(filename, softwareModule)); if (item != null) { item.getItemProperty(FILE_NAME).setValue(filename); + item.getItemProperty(SPUILabelDefinitions.NAME_VERSION).setValue( + HawkbitCommonUtil.getFormattedNameVersion(softwareModule.getName(), softwareModule.getVersion())); } grid.scrollToEnd(); - UploadStatusObject uploadStatus = new UploadStatusObject(filename); + UploadStatusObject uploadStatus = new UploadStatusObject(filename, softwareModule); uploadStatus.setStatus("Active"); artifactUploadState.getUploadedFileStatusList().add(uploadStatus); } - void updateProgress(final String filename, final long readBytes, final long contentLength) { - final Item item = uploads.getItem(filename); + void updateProgress(final String filename, final long readBytes, final long contentLength, + final SoftwareModule softwareModule) { + final Item item = uploads.getItem(getItemid(filename, softwareModule)); + double progress = (double) readBytes / (double) contentLength; if (item != null) { - double progress = (double) readBytes / (double) contentLength; item.getItemProperty(PROGRESS).setValue(progress); - List uploadStatusObjectList = (List) artifactUploadState - .getUploadedFileStatusList().stream().filter(e -> e.getFilename().equals(filename)) - .collect(Collectors.toList()); - if (!uploadStatusObjectList.isEmpty()) { - UploadStatusObject uploadStatusObject = uploadStatusObjectList.get(0); - uploadStatusObject.setProgress(progress); - } + } + List uploadStatusObjectList = (List) artifactUploadState + .getUploadedFileStatusList().stream().filter(e -> e.getFilename().equals(filename)) + .collect(Collectors.toList()); + if (!uploadStatusObjectList.isEmpty()) { + UploadStatusObject uploadStatusObject = uploadStatusObjectList.get(0); + uploadStatusObject.setProgress(progress); } } @@ -338,26 +355,29 @@ public class UploadStatusInfoWindow extends Window { * * @param filename * of the uploaded file. + * @param softwareModule + * selected software module */ - public void uploadSucceeded(final String filename) { - final Item item = uploads.getItem(filename); + public void uploadSucceeded(final String filename, SoftwareModule softwareModule) { + final Item item = uploads.getItem(getItemid(filename, softwareModule)); + String status = "Finished"; if (item != null) { - String status = "Finished"; item.getItemProperty(STATUS).setValue(status); - List uploadStatusObjectList = (List) artifactUploadState - .getUploadedFileStatusList().stream().filter(e -> e.getFilename().equals(filename)) - .collect(Collectors.toList()); - if (!uploadStatusObjectList.isEmpty()) { - UploadStatusObject uploadStatusObject = uploadStatusObjectList.get(0); - uploadStatusObject.setStatus(status); - } + } + List uploadStatusObjectList = (List) artifactUploadState + .getUploadedFileStatusList().stream().filter(e -> e.getFilename().equals(filename)) + .collect(Collectors.toList()); + if (!uploadStatusObjectList.isEmpty()) { + UploadStatusObject uploadStatusObject = uploadStatusObjectList.get(0); + uploadStatusObject.setStatus(status); + uploadStatusObject.setProgress(1d); } } - void uploadFailed(final String filename, final String errorReason) { + void uploadFailed(final String filename, final String errorReason, SoftwareModule softwareModule) { errorOccured = true; String status = "Failed"; - final Item item = uploads.getItem(filename); + final Item item = uploads.getItem(getItemid(filename, softwareModule)); if (item != null) { item.getItemProperty(REASON).setValue(errorReason); item.getItemProperty(STATUS).setValue(status); @@ -385,7 +405,7 @@ public class UploadStatusInfoWindow extends Window { } private void setPopupSizeInMinMode() { - mainLayout.setWidth(800, Unit.PIXELS); + mainLayout.setWidth(900, Unit.PIXELS); mainLayout.setHeight(510, Unit.PIXELS); } @@ -417,6 +437,7 @@ public class UploadStatusInfoWindow extends Window { grid.getColumn(PROGRESS).setExpandRatio(1); grid.getColumn(FILE_NAME).setExpandRatio(2); grid.getColumn(REASON).setExpandRatio(3); + grid.getColumn(SPUILabelDefinitions.NAME_VERSION).setExpandRatio(4); mainLayout.setSizeFull(); } else { event.getButton().setIcon(FontAwesome.EXPAND); @@ -455,7 +476,7 @@ public class UploadStatusInfoWindow extends Window { } private void createConfirmDialog() { - confirmDialog = new ConfirmationDialog(i18n.get("caption.cancel.action.confirmbox"), + confirmDialog = new ConfirmationDialog(i18n.get("caption.confirm.abort.action"), i18n.get("message.abort.upload"), i18n.get("button.ok"), i18n.get("button.cancel"), ok -> { if (ok) { eventBus.publish(this, UploadStatusEventType.ABORT_UPLOAD); @@ -463,8 +484,13 @@ public class UploadStatusInfoWindow extends Window { errorOccured = true; minimizeButton.setEnabled(false); closeButton.setEnabled(false); - } - }); + } + }); } + private String getItemid(final String filename, final SoftwareModule softwareModule) { + return new StringBuilder(filename).append( + HawkbitCommonUtil.getFormattedNameVersion(softwareModule.getName(), softwareModule.getVersion())) + .toString(); + } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusObject.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusObject.java index 13167b55a..4ea82d7dd 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusObject.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusObject.java @@ -8,6 +8,8 @@ */ package org.eclipse.hawkbit.ui.artifacts.upload; +import org.eclipse.hawkbit.repository.model.SoftwareModule; + /** * * Holds uploaded file status.Used to display the details in upload status @@ -19,16 +21,23 @@ public class UploadStatusObject { private Double progress; private String filename; private String reason; + private SoftwareModule selectedSoftwareModule; - public UploadStatusObject(String status, Double progress, String fileName, String reason) { - this(fileName); + public UploadStatusObject(final String status, final Double progress, final String fileName, final String reason, + final SoftwareModule selectedSoftwareModule) { + this(fileName,selectedSoftwareModule); this.status = status; this.progress = progress; this.reason = reason; } - public UploadStatusObject(String fileName) { + public UploadStatusObject(String fileName, SoftwareModule selectedSoftwareModule) { this.filename = fileName; + this.selectedSoftwareModule = selectedSoftwareModule; + } + + public SoftwareModule getSelectedSoftwareModule() { + return selectedSoftwareModule; } public String getStatus() { From e3041aa9ae8b3fa71197807a7ecd2a954e952a1e Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Fri, 20 May 2016 17:25:38 +0200 Subject: [PATCH 16/54] Started to split the actual model. Signed-off-by: Kai Zimmermann --- .../eventbus/EntityChangeEventListener.java | 3 +- .../repository/ControllerManagement.java | 10 +- .../repository/DeploymentManagement.java | 13 +- .../DistributionSetAssignmentResult.java | 5 +- .../repository/DistributionSetManagement.java | 40 +- .../repository/RolloutGroupManagement.java | 14 +- .../hawkbit/repository/RolloutManagement.java | 17 +- .../repository/SoftwareManagement.java | 24 +- .../hawkbit/repository/TagManagement.java | 22 +- .../hawkbit/repository/TargetManagement.java | 35 +- .../TenantConfigurationManagement.java | 1 - .../repository/jpa/ActionRepository.java | 80 +-- .../jpa/ActionStatusRepository.java | 12 +- .../repository/jpa/BaseEntityRepository.java | 3 +- .../repository/jpa/DeploymentHelper.java | 13 +- .../DistributionSetMetadataRepository.java | 10 +- .../jpa/DistributionSetRepository.java | 33 +- .../jpa/DistributionSetTagRepository.java | 9 +- .../jpa/DistributionSetTypeRepository.java | 9 +- .../jpa/EclipseLinkTargetInfoRepository.java | 8 +- .../ExternalArtifactProviderRepository.java | 3 +- .../jpa/ExternalArtifactRepository.java | 5 +- .../repository/jpa/JpaArtifactManagement.java | 33 +- .../jpa/JpaControllerManagement.java | 88 +-- .../jpa/JpaDeploymentManagement.java | 172 +++--- .../jpa/JpaDistributionSetManagement.java | 228 +++++--- .../repository/jpa/JpaReportManagement.java | 63 +-- .../jpa/JpaRolloutGroupManagement.java | 80 ++- .../repository/jpa/JpaRolloutManagement.java | 112 ++-- .../repository/jpa/JpaSoftwareManagement.java | 223 +++++--- .../repository/jpa/JpaSystemManagement.java | 30 +- .../repository/jpa/JpaTagManagement.java | 89 ++- .../jpa/JpaTargetFilterQueryManagement.java | 26 +- .../repository/jpa/JpaTargetManagement.java | 190 ++++--- .../jpa/JpaTenantConfigurationManagement.java | 8 +- .../jpa/LocalArtifactRepository.java | 7 +- .../jpa/RolloutGroupRepository.java | 24 +- .../repository/jpa/RolloutRepository.java | 16 +- .../jpa/RolloutTargetGroupRepository.java | 4 +- .../jpa/SoftwareModuleMetadataRepository.java | 9 +- .../jpa/SoftwareModuleRepository.java | 27 +- .../jpa/SoftwareModuleTypeRepository.java | 7 +- .../jpa/TargetFilterQueryRepository.java | 7 +- .../repository/jpa/TargetInfoRepository.java | 5 +- .../repository/jpa/TargetRepository.java | 46 +- .../repository/jpa/TargetTagRepository.java | 9 +- .../jpa/TenantConfigurationRepository.java | 7 +- .../jpa/TenantMetaDataRepository.java | 5 +- .../model/DistributionSetTypeElement.java | 12 +- ...istributionSetTypeElementCompositeKey.java | 4 +- .../model/DsMetadataCompositeKey.java | 4 +- .../repository/jpa/model/JpaAction.java | 274 ++++++++++ .../repository/jpa/model/JpaActionStatus.java | 154 ++++++ .../repository/jpa/model/JpaArtifact.java | 63 +++ .../repository/jpa/model/JpaBaseEntity.java | 184 +++++++ .../jpa/model/JpaDistributionSet.java | 326 +++++++++++ .../jpa/model/JpaDistributionSetMetadata.java | 85 +++ .../jpa/model/JpaDistributionSetTag.java | 90 ++++ .../jpa/model/JpaDistributionSetType.java | 310 +++++++++++ .../jpa/model/JpaExternalArtifact.java | 142 +++++ .../model/JpaExternalArtifactProvider.java | 83 +++ .../jpa/model/JpaLocalArtifact.java | 118 ++++ .../repository/jpa/model/JpaMetaData.java | 102 ++++ .../repository/jpa/model/JpaNamedEntity.java | 70 +++ .../jpa/model/JpaNamedVersionedEntity.java | 55 ++ .../repository/jpa/model/JpaRollout.java | 260 +++++++++ .../repository/jpa/model/JpaRolloutGroup.java | 509 ++++++++++++++++++ .../jpa/model/JpaSoftwareModule.java | 266 +++++++++ .../jpa/model/JpaSoftwareModuleMetadata.java | 85 +++ .../jpa/model/JpaSoftwareModuleType.java | 125 +++++ .../hawkbit/repository/jpa/model/JpaTag.java | 61 +++ .../repository/jpa/model/JpaTarget.java | 237 ++++++++ .../jpa/model/JpaTargetFilterQuery.java | 64 +++ .../repository/jpa/model/JpaTargetInfo.java | 372 +++++++++++++ .../repository/jpa/model/JpaTargetTag.java | 91 ++++ .../jpa/model/JpaTenantAwareBaseEntity.java | 115 ++++ .../jpa/model/JpaTenantConfiguration.java | 75 +++ .../jpa/model/JpaTenantMetaData.java | 107 ++++ .../{ => jpa}/model/RolloutTargetGroup.java | 19 +- .../{ => jpa}/model/RolloutTargetGroupId.java | 5 +- .../model/SwMetadataCompositeKey.java | 4 +- .../specifications/ActionSpecifications.java | 31 +- .../DistributionSetSpecification.java | 93 ++-- .../DistributionSetTypeSpecification.java | 22 +- .../SoftwareModuleSpecification.java | 28 +- .../specifications/SpecificationsBuilder.java | 2 +- .../TargetFilterQuerySpecification.java | 9 +- .../specifications/TargetSpecifications.java | 84 +-- .../hawkbit/repository/model/Action.java | 199 +------ .../repository/model/ActionStatus.java | 124 +---- .../model/ActionWithStatusCount.java | 6 +- .../hawkbit/repository/model/Artifact.java | 47 +- .../hawkbit/repository/model/BaseEntity.java | 167 +----- .../repository/model/DistributionSet.java | 251 +-------- .../model/DistributionSetMetadata.java | 71 +-- .../repository/model/DistributionSetTag.java | 75 +-- .../repository/model/DistributionSetType.java | 189 +------ .../repository/model/ExternalArtifact.java | 119 +--- .../model/ExternalArtifactProvider.java | 67 +-- .../repository/model/LocalArtifact.java | 104 +--- .../hawkbit/repository/model/MetaData.java | 87 +-- .../hawkbit/repository/model/NamedEntity.java | 54 +- .../model/NamedVersionedEntity.java | 41 +- .../hawkbit/repository/model/Rollout.java | 222 +------- .../repository/model/RolloutGroup.java | 467 ++-------------- .../repository/model/SoftwareModule.java | 193 +------ .../model/SoftwareModuleMetadata.java | 71 +-- .../repository/model/SoftwareModuleType.java | 108 +--- .../eclipse/hawkbit/repository/model/Tag.java | 50 +- .../hawkbit/repository/model/Target.java | 192 +------ .../repository/model/TargetFilterQuery.java | 49 +- .../hawkbit/repository/model/TargetInfo.java | 338 +----------- .../hawkbit/repository/model/TargetTag.java | 76 +-- .../model/TargetWithActionStatus.java | 2 +- .../model/TenantAwareBaseEntity.java | 104 +--- .../repository/model/TenantConfiguration.java | 62 +-- .../repository/model/TenantMetaData.java | 91 +--- .../condition/PauseRolloutGroupAction.java | 18 +- ...artNextGroupRolloutGroupSuccessAction.java | 9 +- .../ThresholdRolloutGroupErrorCondition.java | 5 +- .../org/eclipse/hawkbit/TestDataUtil.java | 60 ++- .../hawkbit/repository/ActionTest.java | 3 +- .../ArtifactManagementNoMongoDbTest.java | 4 +- .../repository/ArtifactManagementTest.java | 103 ++-- .../repository/ControllerManagementTest.java | 16 +- .../repository/DeploymentManagementTest.java | 133 ++--- .../DistributionSetManagementTest.java | 108 ++-- .../repository/ReportManagementTest.java | 65 +-- .../repository/RolloutManagementTest.java | 63 +-- .../repository/SoftwareManagementTest.java | 236 ++++---- .../repository/SystemManagementTest.java | 4 +- .../hawkbit/repository/TagManagementTest.java | 109 ++-- .../TargetFilterQueryManagenmentTest.java | 11 +- .../TargetManagementSearchTest.java | 163 ++---- .../repository/TargetManagementTest.java | 76 +-- .../model/ModelEqualsHashcodeTest.java | 44 +- .../repository/rsql/RSQLActionFieldsTest.java | 16 +- .../rsql/RSQLDistributionSetFieldTest.java | 20 +- ...RSQLDistributionSetMetadataFieldsTest.java | 6 +- .../rsql/RSQLRolloutGroupFields.java | 11 +- .../rsql/RSQLSoftwareModuleFieldTest.java | 22 +- .../RSQLSoftwareModuleMetadataFieldsTest.java | 9 +- .../RSQLSoftwareModuleTypeFieldsTest.java | 4 +- .../repository/rsql/RSQLTagFieldsTest.java | 13 +- .../repository/rsql/RSQLTargetFieldTest.java | 28 +- .../utils/RepositoryDataGenerator.java | 33 +- .../tenancy/MultiTenancyEntityTest.java | 10 +- .../controller/ArtifactStoreController.java | 2 +- .../hawkbit/controller/RootController.java | 9 +- .../resource/DistributionSetResource.java | 2 +- .../resource/DistributionSetTypeResource.java | 2 +- .../rest/resource/RolloutResource.java | 2 +- .../resource/DistributionSetResourceTest.java | 4 +- .../rest/resource/TargetResourceTest.java | 7 +- 154 files changed, 6730 insertions(+), 4950 deletions(-) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/{ => jpa}/model/DistributionSetTypeElement.java (86%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/{ => jpa}/model/DistributionSetTypeElementCompositeKey.java (89%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/{ => jpa}/model/DsMetadataCompositeKey.java (95%) create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaAction.java create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaActionStatus.java create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaArtifact.java create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaBaseEntity.java create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSet.java create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetMetadata.java create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetTag.java create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetType.java create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaExternalArtifact.java create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaExternalArtifactProvider.java create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaLocalArtifact.java create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaMetaData.java create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaNamedEntity.java create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaNamedVersionedEntity.java create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRollout.java create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRolloutGroup.java create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModule.java create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModuleMetadata.java create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModuleType.java create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTag.java create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTarget.java create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetFilterQuery.java create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetInfo.java create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetTag.java create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTenantAwareBaseEntity.java create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTenantConfiguration.java create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTenantMetaData.java rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/{ => jpa}/model/RolloutTargetGroup.java (77%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/{ => jpa}/model/RolloutTargetGroupId.java (88%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/{ => jpa}/model/SwMetadataCompositeKey.java (96%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/{ => jpa}/specifications/ActionSpecifications.java (55%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/{ => jpa}/specifications/DistributionSetSpecification.java (58%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/{ => jpa}/specifications/DistributionSetTypeSpecification.java (75%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/{ => jpa}/specifications/SoftwareModuleSpecification.java (63%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/{ => jpa}/specifications/SpecificationsBuilder.java (95%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/{ => jpa}/specifications/TargetFilterQuerySpecification.java (67%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/{ => jpa}/specifications/TargetSpecifications.java (59%) diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/EntityChangeEventListener.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/EntityChangeEventListener.java index 2f63a3122..0c33435d2 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/EntityChangeEventListener.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/EntityChangeEventListener.java @@ -20,6 +20,7 @@ import org.eclipse.hawkbit.eventbus.event.TargetDeletedEvent; import org.eclipse.hawkbit.eventbus.event.TargetInfoUpdateEvent; import org.eclipse.hawkbit.executor.AfterTransactionCommitExecutor; import org.eclipse.hawkbit.repository.jpa.TargetRepository; +import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetInfo; import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity; @@ -147,7 +148,7 @@ public class EntityChangeEventListener { } private static boolean isTargetInfoNew(final Object targetInfo) { - return ((TargetInfo) targetInfo).isNew(); + return ((JpaTargetInfo) targetInfo).isNew(); } } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java index 4ee3b1275..47ff3c49f 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java @@ -31,8 +31,6 @@ import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; import org.hibernate.validator.constraints.NotEmpty; import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.transaction.annotation.Isolation; -import org.springframework.transaction.annotation.Transactional; /** * Service layer for all operations of the DDI API (with access permissions only @@ -248,7 +246,6 @@ public interface ControllerManagement { * */ @PreAuthorize(SpringEvalExpressions.IS_CONTROLLER) - @Transactional(isolation = Isolation.READ_UNCOMMITTED) TargetInfo updateLastTargetQuery(@NotNull TargetInfo target, @NotNull URI address); /** @@ -271,4 +268,11 @@ public interface ControllerManagement { TargetInfo updateTargetStatus(@NotNull TargetInfo targetInfo, TargetUpdateStatus status, Long lastTargetQuery, URI address); + /** + * Generates an empty {@link ActionStatus} without persisting it. + * + * @return {@link ActionStatus} object + */ + ActionStatus generateActionStatus(); + } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java index 754d66b65..070594d4e 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java @@ -31,7 +31,6 @@ import org.hibernate.validator.constraints.NotEmpty; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; -import org.springframework.data.jpa.domain.Specification; import org.springframework.security.access.prepost.PreAuthorize; /** @@ -179,7 +178,7 @@ public interface DeploymentManagement { * @return the count value of found actions associated to the target */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - Long countActionsByTarget(@NotNull Specification spec, @NotNull Target target); + Long countActionsByTarget(@NotNull String rsqlParam, @NotNull Target target); /** * counts all actions associated to a specific target. @@ -281,9 +280,9 @@ public interface DeploymentManagement { * @return a slice of actions assigned to the specific target and the * specification */ + // TODO fix this @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - Slice findActionsByTarget(@NotNull Specification specifiction, @NotNull Target target, - @NotNull Pageable pageable); + Slice findActionsByTarget(@NotNull String rsqlParam, @NotNull Target target, @NotNull Pageable pageable); /** * Retrieves all {@link Action}s of a specific target ordered by action ID. @@ -440,4 +439,10 @@ public interface DeploymentManagement { + SpringEvalExpressions.IS_SYSTEM_CODE) Action startScheduledAction(@NotNull Action action); + /** + * Generates an empty {@link Action} without persisting it. + * + * @return {@link Action} object + */ + Action generateAction(); } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetAssignmentResult.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetAssignmentResult.java index ad947879a..1393504ab 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetAssignmentResult.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetAssignmentResult.java @@ -51,7 +51,7 @@ public class DistributionSetAssignmentResult extends AssignmentResult { this.actions = actions; this.targetManagement = targetManagement; } - + /** * @return the actionIds */ @@ -59,9 +59,10 @@ public class DistributionSetAssignmentResult extends AssignmentResult { return actions; } + @SuppressWarnings("unchecked") @Override public List getAssignedEntity() { - return targetManagement.findTargetByControllerID(assignedTargets); + return (List) targetManagement.findTargetByControllerID(assignedTargets); } } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java index db737df4a..2574230b3 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java @@ -21,14 +21,14 @@ import org.eclipse.hawkbit.repository.exception.DistributionSetCreationFailedMis import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.exception.EntityReadOnlyException; +import org.eclipse.hawkbit.repository.jpa.model.DistributionSetTypeElement; +import org.eclipse.hawkbit.repository.jpa.model.DsMetadataCompositeKey; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetMetadata; import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult; import org.eclipse.hawkbit.repository.model.DistributionSetType; -import org.eclipse.hawkbit.repository.model.DistributionSetTypeElement; -import org.eclipse.hawkbit.repository.model.DsMetadataCompositeKey; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.repository.model.Tag; @@ -36,7 +36,6 @@ import org.eclipse.hawkbit.repository.model.Target; import org.hibernate.validator.constraints.NotEmpty; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; -import org.springframework.data.jpa.domain.Specification; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.transaction.annotation.Isolation; import org.springframework.transaction.annotation.Transactional; @@ -274,18 +273,7 @@ public interface DistributionSetManagement { * @return the found {@link DistributionSet}s */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Iterable findDistributionSetList(Collection dist); - - /** - * Retrieves {@link DistributionSet} List including details information, - * i.e. @link BaseSoftwareModule}s and {@link DistributionSetTag}s. - * - * @param distributionIdSet - * List of {@link DistributionSet} IDs to be found - * @return the found {@link DistributionSet}s - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - List findDistributionSetListWithDetails(Collection distributionIdSet); + List findDistributionSetsAll(Collection dist); /** * finds all meta data by the given distribution set id. @@ -315,7 +303,7 @@ public interface DistributionSetManagement { */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) Page findDistributionSetMetadataByDistributionSetId(@NotNull Long distributionSetId, - @NotNull Specification spec, @NotNull Pageable pageable); + @NotNull String rsqlParam, @NotNull Pageable pageable); // TODO discuss: use enum instead of the true,false,null switch ? /** @@ -357,8 +345,8 @@ public interface DistributionSetManagement { * @return all found {@link DistributionSet}s */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Page findDistributionSetsAll(@NotNull Specification spec, - @NotNull Pageable pageReq, Boolean deleted); + Page findDistributionSetsAll(@NotNull String rsqlParam, @NotNull Pageable pageReq, + Boolean deleted); /** * method retrieves all {@link DistributionSet}s from the repository in the @@ -442,8 +430,7 @@ public interface DistributionSetManagement { * @return the found {@link SoftwareModuleType}s */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Page findDistributionSetTypesAll(@NotNull Specification spec, - @NotNull Pageable pageable); + Page findDistributionSetTypesAll(@NotNull String rsqlParam, @NotNull Pageable pageable); /** * finds a single distribution set meta data by its id. @@ -580,4 +567,17 @@ public interface DistributionSetManagement { @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) DistributionSetType updateDistributionSetType(@NotNull DistributionSetType dsType); + /** + * Generates an empty {@link DistributionSetType} without persisting it. + * + * @return {@link DistributionSetType} object + */ + DistributionSetType generateDistributionSetType(); + + /** + * Generates an empty {@link DistributionSet} without persisting it. + * + * @return {@link DistributionSet} object + */ + DistributionSet generateDistributionSet(); } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupManagement.java index baff4586c..efad0100c 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupManagement.java @@ -84,8 +84,8 @@ public interface RolloutGroupManagement { * @return a page of found {@link RolloutGroup}s */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - Page findRolloutGroupsAll(@NotNull Rollout rollout, - @NotNull Specification specification, @NotNull Pageable page); + Page findRolloutGroupsAll(@NotNull Rollout rollout, @NotNull String rsqlParam, + @NotNull Pageable page); /** * Retrieves a page of {@link RolloutGroup}s filtered by a given @@ -128,8 +128,8 @@ public interface RolloutGroupManagement { * @return Page list of targets of a rollout group */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - Page findRolloutGroupTargets(@NotNull RolloutGroup rolloutGroup, - @NotNull Specification specification, @NotNull Pageable page); + Page findRolloutGroupTargets(@NotNull RolloutGroup rolloutGroup, @NotNull String rsqlParam, + @NotNull Pageable page); /** * Get count of targets in different status in rollout group. @@ -141,4 +141,10 @@ public interface RolloutGroupManagement { @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) RolloutGroup findRolloutGroupWithDetailedStatus(@NotNull Long rolloutGroupId); + /** + * Generates an empty {@link RolloutGroup} without persisting it. + * + * @return {@link RolloutGroup} object + */ + RolloutGroup generateRolloutGroup(); } \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java index 118be12fa..140273439 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java @@ -13,16 +13,15 @@ import javax.validation.constraints.NotNull; import org.eclipse.hawkbit.eventbus.event.RolloutGroupCreatedEvent; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; import org.eclipse.hawkbit.repository.exception.RolloutIllegalStateException; +import org.eclipse.hawkbit.repository.jpa.model.JpaRollout.RolloutStatus; +import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup.RolloutGroupConditions; +import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup.RolloutGroupStatus; import org.eclipse.hawkbit.repository.model.Rollout; -import org.eclipse.hawkbit.repository.model.Rollout.RolloutStatus; import org.eclipse.hawkbit.repository.model.RolloutGroup; -import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupConditions; -import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupStatus; import org.hibernate.validator.constraints.NotEmpty; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; -import org.springframework.data.jpa.domain.Specification; import org.springframework.security.access.prepost.PreAuthorize; /** @@ -179,8 +178,7 @@ public interface RolloutManagement { * @return a page of found rollouts */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - Page findAllWithDetailedStatusByPredicate(@NotNull Specification specification, - @NotNull Pageable page); + Page findAllWithDetailedStatusByPredicate(@NotNull String rsqlParam, @NotNull Pageable page); /** * Finds rollouts by given text in name or description. @@ -335,4 +333,11 @@ public interface RolloutManagement { @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_WRITE) Rollout updateRollout(@NotNull Rollout rollout); + /** + * Generates an empty {@link Rollout} without persisting it. + * + * @return {@link Rollout} object + */ + Rollout generateRollout(); + } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java index b3b9e7380..1802b1dcc 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java @@ -17,17 +17,16 @@ import javax.validation.constraints.NotNull; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; +import org.eclipse.hawkbit.repository.jpa.model.SwMetadataCompositeKey; import org.eclipse.hawkbit.repository.model.CustomSoftwareModule; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; -import org.eclipse.hawkbit.repository.model.SwMetadataCompositeKey; import org.hibernate.validator.constraints.NotEmpty; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; -import org.springframework.data.jpa.domain.Specification; import org.springframework.security.access.prepost.PreAuthorize; /** @@ -290,7 +289,7 @@ public interface SoftwareManagement { */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) Page findSoftwareModuleMetadataBySoftwareModuleId(@NotNull Long softwareModuleId, - @NotNull Specification spec, @NotNull Pageable pageable); + @NotNull String rsqlParam, @NotNull Pageable pageable); /** * Filter {@link SoftwareModule}s with given @@ -347,8 +346,7 @@ public interface SoftwareManagement { * @return the found {@link SoftwareModule}s */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Page findSoftwareModulesByPredicate(@NotNull Specification spec, - @NotNull Pageable pageable); + Page findSoftwareModulesByPredicate(@NotNull String rsqlParam, @NotNull Pageable pageable); /** * retrieves the {@link SoftwareModule}s by their {@link SoftwareModuleType} @@ -411,8 +409,7 @@ public interface SoftwareManagement { * @return the found {@link SoftwareModuleType}s */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Page findSoftwareModuleTypesByPredicate(@NotNull Specification spec, - @NotNull Pageable pageable); + Page findSoftwareModuleTypesByPredicate(@NotNull String rsqlParam, @NotNull Pageable pageable); /** * Retrieves software module including details ( @@ -468,4 +465,17 @@ public interface SoftwareManagement { @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) SoftwareModuleType updateSoftwareModuleType(@NotNull SoftwareModuleType sm); + /** + * Generates an empty {@link SoftwareModuleType} without persisting it. + * + * @return {@link SoftwareModuleType} object + */ + SoftwareModuleType generateSoftwareModuleType(); + + /** + * Generates an empty {@link SoftwareModule} without persisting it. + * + * @return {@link SoftwareModule} object + */ + SoftwareModule generateSoftwareModule(); } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TagManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TagManagement.java index 929bd745c..fa38e318b 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TagManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TagManagement.java @@ -23,7 +23,6 @@ import org.eclipse.hawkbit.repository.model.TargetTag; import org.hibernate.validator.constraints.NotEmpty; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; -import org.springframework.data.jpa.domain.Specification; import org.springframework.security.access.prepost.PreAuthorize; /** @@ -90,7 +89,7 @@ public interface TagManagement { * if given object has already an ID. */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_TARGET) - List createTargetTags(@NotNull Iterable targetTags); + List createTargetTags(@NotNull Collection targetTags); /** * Deletes {@link DistributionSetTag} by given @@ -138,8 +137,7 @@ public interface TagManagement { * @return the found {@link DistributionSetTag}s, never {@code null} */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Page findAllDistributionSetTags(@NotNull Specification spec, - @NotNull Pageable pageable); + Page findAllDistributionSetTags(@NotNull String rsqlParam, @NotNull Pageable pageable); /** * @return all {@link TargetTag}s @@ -168,7 +166,7 @@ public interface TagManagement { * @return the found {@link Target}s, never {@code null} */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - Page findAllTargetTags(@NotNull Specification spec, @NotNull Pageable pageable); + Page findAllTargetTags(@NotNull String rsqlParam, @NotNull Pageable pageable); /** * Find {@link DistributionSet} based on given name. @@ -233,4 +231,18 @@ public interface TagManagement { @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET) TargetTag updateTargetTag(@NotNull TargetTag targetTag); + /** + * Generates an empty {@link TargetTag} without persisting it. + * + * @return {@link TargetTag} object + */ + TargetTag generateTargetTag(); + + /** + * Generates an empty {@link DistributionSetTag} without persisting it. + * + * @return {@link DistributionSetTag} object + */ + DistributionSetTag generateDistributionSetTag(); + } \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java index ae7724e31..f8e5e8a91 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java @@ -30,7 +30,6 @@ import org.hibernate.validator.constraints.NotEmpty; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; -import org.springframework.data.jpa.domain.Specification; import org.springframework.security.access.prepost.PreAuthorize; /** @@ -290,8 +289,8 @@ public interface TargetManagement { * @return the found {@link Target}s, never {@code null} */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_READ_TARGET) - Page findTargetByAssignedDistributionSet(@NotNull Long distributionSetID, - @NotNull Specification spec, @NotNull Pageable pageReq); + Page findTargetByAssignedDistributionSet(@NotNull Long distributionSetID, @NotNull String rsqlParam, + @NotNull Pageable pageReq); /** * Find {@link Target} based on given ID returns found Target without @@ -390,8 +389,8 @@ public interface TargetManagement { * @return the found {@link Target}s, never {@code null} */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_READ_TARGET) - Page findTargetByInstalledDistributionSet(@NotNull Long distributionSetId, - @NotNull Specification spec, @NotNull Pageable pageable); + Page findTargetByInstalledDistributionSet(@NotNull Long distributionSetId, @NotNull String rsqlParam, + @NotNull Pageable pageable); /** * Retrieves the {@link Target} which have a certain @@ -418,18 +417,6 @@ public interface TargetManagement { @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) Slice findTargetsAll(@NotNull Pageable pageable); - /** - * Retrieves all targets based on the given specification. - * - * @param spec - * the specification for the query - * @param pageable - * pagination parameter - * @return the found {@link Target}s, never {@code null} - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - Page findTargetsAll(@NotNull Specification spec, @NotNull Pageable pageable); - /** * Retrieves all targets without details, i.e. NO {@link Target#getTags()} * and {@link Target#getActions()} possible based on @@ -442,7 +429,7 @@ public interface TargetManagement { * @return the found {@link Target}s, never {@code null} */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - Slice findTargetsAll(@NotNull String targetFilterQuery, @NotNull Pageable pageable); + Page findTargetsAll(@NotNull String targetFilterQuery, @NotNull Pageable pageable); /** * Retrieves all targets without details, i.e. NO {@link Target#getTags()} @@ -599,6 +586,16 @@ public interface TargetManagement { */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET + SpringEvalExpressions.HAS_AUTH_OR + SpringEvalExpressions.IS_CONTROLLER) - List updateTargets(@NotNull Iterable targets); + List updateTargets(@NotNull Collection targets); + + /** + * Generates an empty {@link Target} without persisting it. + * + * @param controllerID + * of the {@link Target} + * + * @return {@link Target} object + */ + Target generateTarget(@NotEmpty String controllerID); } \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantConfigurationManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantConfigurationManagement.java index d9647e610..9937084eb 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantConfigurationManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantConfigurationManagement.java @@ -142,5 +142,4 @@ public interface TenantConfigurationManagement { @PreAuthorize(value = SpringEvalExpressions.HAS_AUTH_TENANT_CONFIGURATION + SpringEvalExpressions.HAS_AUTH_OR + SpringEvalExpressions.IS_SYSTEM_CODE) T getGlobalConfigurationValue(TenantConfigurationKey configurationKey, Class propertyType); - } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/ActionRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/ActionRepository.java index 56ade85ff..0eebbced1 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/ActionRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/ActionRepository.java @@ -11,6 +11,12 @@ package org.eclipse.hawkbit.repository.jpa; import java.util.Collection; import java.util.List; +import org.eclipse.hawkbit.repository.jpa.model.JpaAction; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; +import org.eclipse.hawkbit.repository.jpa.model.JpaRollout; +import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup; +import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; +import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.DistributionSet; @@ -37,7 +43,7 @@ import org.springframework.transaction.annotation.Transactional; * */ @Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) -public interface ActionRepository extends BaseEntityRepository, JpaSpecificationExecutor { +public interface ActionRepository extends BaseEntityRepository, JpaSpecificationExecutor { /** * Retrieves an Action with all lazy attributes. * @@ -46,7 +52,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp * @return the found {@link Action} */ @EntityGraph(value = "Action.all", type = EntityGraphType.LOAD) - Action findById(Long actionId); + JpaAction findById(Long actionId); /** * Retrieves all {@link Action}s which are referring the given @@ -58,7 +64,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp * the {@link DistributionSet} on which will be filtered * @return the found {@link Action}s */ - Page findByDistributionSet(final Pageable pageable, final DistributionSet ds); + Page findByDistributionSet(final Pageable pageable, final JpaDistributionSet ds); /** * Retrieves all {@link Action}s which are referring the given @@ -70,7 +76,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp * the target to find assigned actions * @return the found {@link Action}s */ - Slice findByTarget(Pageable pageable, Target target); + Slice findByTarget(Pageable pageable, JpaTarget target); /** * Retrieves all {@link Action}s which are active and referring the given @@ -86,7 +92,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp * @return the found {@link Action}s */ @EntityGraph(value = "Action.ds", type = EntityGraphType.LOAD) - List findByTargetAndActiveOrderByIdAsc(final Target target, boolean active); + List findByTargetAndActiveOrderByIdAsc(final JpaTarget target, boolean active); /** * Retrieves latest {@link UpdateAction} for given target and @@ -99,9 +105,9 @@ public interface ActionRepository extends BaseEntityRepository, Jp * @return action if there is one with assigned target and module is part of * assigned {@link DistributionSet}. */ - @Query("Select a from Action a join a.distributionSet ds join ds.modules modul where a.target.controllerId = :target and modul = :module order by a.id desc") + @Query("Select a from JpaAction a join a.distributionSet ds join ds.modules modul where a.target.controllerId = :target and modul = :module order by a.id desc") List findActionByTargetAndSoftwareModule(@Param("target") final String targetId, - @Param("module") SoftwareModule module); + @Param("module") JpaSoftwareModule module); /** * Retrieves all {@link UpdateAction}s which are referring the given @@ -115,9 +121,9 @@ public interface ActionRepository extends BaseEntityRepository, Jp * the {@link DistributionSet} on which will be filtered * @return the found {@link UpdateAction}s */ - @Query("Select a from Action a where a.target = :target and a.distributionSet = :ds order by a.id") - Page findByTargetAndDistributionSet(final Pageable pageable, @Param("target") final Target target, - @Param("ds") DistributionSet ds); + @Query("Select a from JpaAction a where a.target = :target and a.distributionSet = :ds order by a.id") + Page findByTargetAndDistributionSet(final Pageable pageable, @Param("target") final JpaTarget target, + @Param("ds") JpaDistributionSet ds); /** * Retrieves all {@link Action}s of a specific target, without pagination @@ -127,8 +133,8 @@ public interface ActionRepository extends BaseEntityRepository, Jp * to search for * @return a list of actions according to the searched target */ - @Query("Select a from Action a where a.target = :target order by a.id") - List findByTarget(@Param("target") final Target target); + @Query("Select a from JpaAction a where a.target = :target order by a.id") + List findByTarget(@Param("target") final JpaTarget target); /** * Retrieves all {@link Action}s of a specific target and given active flag @@ -143,8 +149,8 @@ public interface ActionRepository extends BaseEntityRepository, Jp * {@code false} for inactive * @return a paged list of actions ordered by action ID */ - @Query("Select a from Action a where a.target = :target and a.active= :active order by a.id") - Page findByActiveAndTarget(Pageable pageable, @Param("target") Target target, + @Query("Select a from JpaAction a where a.target = :target and a.active= :active order by a.id") + Page findByActiveAndTarget(Pageable pageable, @Param("target") JpaTarget target, @Param("active") boolean active); /** @@ -160,8 +166,8 @@ public interface ActionRepository extends BaseEntityRepository, Jp * @return a list of actions ordered by action ID */ @EntityGraph(value = "Action.ds", type = EntityGraphType.LOAD) - @Query("Select a from Action a where a.target = :target and a.active= :active order by a.id") - List findByActiveAndTarget(@Param("target") Target target, @Param("active") boolean active); + @Query("Select a from JpaAction a where a.target = :target and a.active= :active order by a.id") + List findByActiveAndTarget(@Param("target") JpaTarget target, @Param("active") boolean active); /** * Updates all {@link Action} to inactive for all targets with given ID. @@ -174,8 +180,8 @@ public interface ActionRepository extends BaseEntityRepository, Jp */ @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @Query("UPDATE Action a SET a.active = false WHERE a IN :keySet AND a.target IN :targetsIds") - void setToInactive(@Param("keySet") List keySet, @Param("targetsIds") List targetsIds); + @Query("UPDATE JpaAction a SET a.active = false WHERE a IN :keySet AND a.target IN :targetsIds") + void setToInactive(@Param("keySet") List keySet, @Param("targetsIds") List targetsIds); /** * Switches the status of actions from one specific status into another, @@ -193,7 +199,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp */ @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @Query("UPDATE Action a SET a.status = :statusToSet WHERE a.target IN :targetsIds AND a.active = :active AND a.status = :currentStatus AND a.distributionSet.requiredMigrationStep = false") + @Query("UPDATE JpaAction a SET a.status = :statusToSet WHERE a.target IN :targetsIds AND a.active = :active AND a.status = :currentStatus AND a.distributionSet.requiredMigrationStep = false") void switchStatus(@Param("statusToSet") Action.Status statusToSet, @Param("targetsIds") List targetIds, @Param("active") boolean active, @Param("currentStatus") Action.Status currentStatus); @@ -213,8 +219,8 @@ public interface ActionRepository extends BaseEntityRepository, Jp */ @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @Query("UPDATE Action a SET a.status = :statusToSet WHERE a.rollout = :rollout AND a.active = :active AND a.status = :currentStatus") - void switchStatus(@Param("statusToSet") Action.Status statusToSet, @Param("rollout") Rollout rollout, + @Query("UPDATE JpaAction a SET a.status = :statusToSet WHERE a.rollout = :rollout AND a.active = :active AND a.status = :currentStatus") + void switchStatus(@Param("statusToSet") Action.Status statusToSet, @Param("rollout") JpaRollout rollout, @Param("active") boolean active, @Param("currentStatus") Action.Status currentStatus); /** @@ -228,8 +234,8 @@ public interface ActionRepository extends BaseEntityRepository, Jp * the status which the actions should not have * @return the found list of {@link Action}s */ - @Query("SELECT a FROM Action a WHERE a.active = true AND a.distributionSet.requiredMigrationStep = false AND a.target IN ?1 AND a.status != ?2") - List findByActiveAndTargetIdInAndActionStatusNotEqualToAndDistributionSetRequiredMigrationStep( + @Query("SELECT a FROM JpaAction a WHERE a.active = true AND a.distributionSet.requiredMigrationStep = false AND a.target IN ?1 AND a.status != ?2") + List findByActiveAndTargetIdInAndActionStatusNotEqualToAndDistributionSetRequiredMigrationStep( Collection targetIds, Action.Status notStatus); /** @@ -239,15 +245,15 @@ public interface ActionRepository extends BaseEntityRepository, Jp * the target to count the {@link Action}s * @return the count of actions referring to the given target */ - Long countByTarget(Target target); + Long countByTarget(JpaTarget target); @Override @CacheEvict(value = "feedbackReceivedOverTime", allEntries = true) - List save(Iterable entities); + List save(Iterable entities); @Override @CacheEvict(value = "feedbackReceivedOverTime", allEntries = true) - S save(S entity); + S save(S entity); /** * Counts all {@link Action}s referring to the given DistributionSet. @@ -256,7 +262,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp * DistributionSet to count the {@link Action}s from * @return the count of actions referring to the given distributionSet */ - Long countByDistributionSet(DistributionSet distributionSet); + Long countByDistributionSet(JpaDistributionSet distributionSet); /** * Counts all {@link Action}s referring to the given rollout. @@ -265,7 +271,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp * the rollout to count the {@link Action}s from * @return the count of actions referring to the given rollout */ - Long countByRollout(Rollout rollout); + Long countByRollout(JpaRollout rollout); /** * Counts all actions referring to a given rollout and rolloutgroup which @@ -286,8 +292,8 @@ public interface ActionRepository extends BaseEntityRepository, Jp * @return the count of actions referring the rollout and rolloutgroup and * are not in given states */ - Long countByRolloutAndRolloutGroupAndStatusNotAndStatusNotAndStatusNot(Rollout rollout, RolloutGroup rolloutGroup, - Status notStatus1, Status notStatus2, Status notStatus3); + Long countByRolloutAndRolloutGroupAndStatusNotAndStatusNotAndStatusNot(JpaRollout rollout, + JpaRolloutGroup rolloutGroup, Status notStatus1, Status notStatus2, Status notStatus3); /** * Counts all actions referring to a given rollout and rolloutgroup. @@ -298,7 +304,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp * the rolloutgroup the actions belong to * @return the count of actions referring to a rollout and rolloutgroup */ - Long countByRolloutAndRolloutGroup(Rollout rollout, RolloutGroup rolloutGroup); + Long countByRolloutAndRolloutGroup(JpaRollout rollout, JpaRolloutGroup rolloutGroup); /** * Counts all actions referring to a given rollout, rolloutgroup and status. @@ -329,7 +335,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp * @return the actions referring a specific rollout and a specific parent * rolloutgroup in a specific status */ - List findByRolloutAndRolloutGroupParentAndStatus(Rollout rollout, RolloutGroup rolloutGroupParent, + List findByRolloutAndRolloutGroupParentAndStatus(JpaRollout rollout, JpaRolloutGroup rolloutGroupParent, Status actionStatus); /** @@ -341,7 +347,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp * the status of the actions * @return the actions referring a specific rollout an in a specific status */ - List findByRolloutAndStatus(Rollout rollout, Status actionStatus); + List findByRolloutAndStatus(JpaRollout rollout, Status actionStatus); /** * Get list of objects which has details of status and count of targets in @@ -351,7 +357,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp * id of {@link Rollout} * @return list of objects with status and target count */ - @Query("SELECT NEW org.eclipse.hawkbit.repository.model.TotalTargetCountActionStatus( a.rollout.id, a.status , COUNT(a.target)) FROM Action a WHERE a.rollout.id IN ?1 GROUP BY a.rollout.id,a.status") + @Query("SELECT NEW org.eclipse.hawkbit.repository.model.TotalTargetCountActionStatus( a.rollout.id, a.status , COUNT(a.target)) FROM JpaAction a WHERE a.rollout.id IN ?1 GROUP BY a.rollout.id,a.status") List getStatusCountByRolloutId(List rolloutId); /** @@ -362,7 +368,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp * id of {@link Rollout} * @return list of objects with status and target count */ - @Query("SELECT NEW org.eclipse.hawkbit.repository.model.TotalTargetCountActionStatus( a.rollout.id, a.status , COUNT(a.target)) FROM Action a WHERE a.rollout.id = ?1 GROUP BY a.rollout.id,a.status") + @Query("SELECT NEW org.eclipse.hawkbit.repository.model.TotalTargetCountActionStatus( a.rollout.id, a.status , COUNT(a.target)) FROM JpaAction a WHERE a.rollout.id = ?1 GROUP BY a.rollout.id,a.status") List getStatusCountByRolloutId(Long rolloutId); /** @@ -373,7 +379,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp * id of {@link RolloutGroup} * @return list of objects with status and target count */ - @Query("SELECT NEW org.eclipse.hawkbit.repository.model.TotalTargetCountActionStatus(a.rolloutGroup.id, a.status , COUNT(a.target)) FROM Action a WHERE a.rolloutGroup.id = ?1 GROUP BY a.rolloutGroup.id, a.status") + @Query("SELECT NEW org.eclipse.hawkbit.repository.model.TotalTargetCountActionStatus(a.rolloutGroup.id, a.status , COUNT(a.target)) FROM JpaAction a WHERE a.rolloutGroup.id = ?1 GROUP BY a.rolloutGroup.id, a.status") List getStatusCountByRolloutGroupId(Long rolloutGroupId); /** @@ -384,7 +390,7 @@ public interface ActionRepository extends BaseEntityRepository, Jp * list of id of {@link RolloutGroup} * @return list of objects with status and target count */ - @Query("SELECT NEW org.eclipse.hawkbit.repository.model.TotalTargetCountActionStatus(a.rolloutGroup.id, a.status , COUNT(a.target)) FROM Action a WHERE a.rolloutGroup.id IN ?1 GROUP BY a.rolloutGroup.id, a.status") + @Query("SELECT NEW org.eclipse.hawkbit.repository.model.TotalTargetCountActionStatus(a.rolloutGroup.id, a.status , COUNT(a.target)) FROM JpaAction a WHERE a.rolloutGroup.id IN ?1 GROUP BY a.rolloutGroup.id, a.status") List getStatusCountByRolloutGroupId(List rolloutGroupId); } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/ActionStatusRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/ActionStatusRepository.java index 61d95e15e..7a2c574df 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/ActionStatusRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/ActionStatusRepository.java @@ -8,6 +8,8 @@ */ package org.eclipse.hawkbit.repository.jpa; +import org.eclipse.hawkbit.repository.jpa.model.JpaAction; +import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; @@ -25,7 +27,7 @@ import org.springframework.transaction.annotation.Transactional; */ @Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) public interface ActionStatusRepository - extends BaseEntityRepository, JpaSpecificationExecutor { + extends BaseEntityRepository, JpaSpecificationExecutor { /** * Counts {@link ActionStatus} entries of given {@link Action} in @@ -35,7 +37,7 @@ public interface ActionStatusRepository * to count status entries * @return number of actions in repository */ - Long countByAction(Action action); + Long countByAction(JpaAction action); /** * Counts {@link ActionStatus} entries of given {@link Action} with given @@ -47,7 +49,7 @@ public interface ActionStatusRepository * to filter for * @return number of actions in repository */ - Long countByActionAndStatus(Action action, Status status); + Long countByActionAndStatus(JpaAction action, Status status); /** * Retrieves all {@link ActionStatus} entries from repository of given @@ -59,7 +61,7 @@ public interface ActionStatusRepository * of the status entries * @return pages list of {@link ActionStatus} entries */ - Page findByAction(Pageable pageReq, Action action); + Page findByAction(Pageable pageReq, JpaAction action); /** * Finds all status updates for the defined action and target including @@ -74,6 +76,6 @@ public interface ActionStatusRepository * @return Page with found targets */ @EntityGraph(value = "ActionStatus.withMessages", type = EntityGraphType.LOAD) - Page getByAction(Pageable pageReq, Action action); + Page getByAction(Pageable pageReq, JpaAction action); } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/BaseEntityRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/BaseEntityRepository.java index 693827803..92bec68a2 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/BaseEntityRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/BaseEntityRepository.java @@ -10,6 +10,7 @@ package org.eclipse.hawkbit.repository.jpa; import java.io.Serializable; +import org.eclipse.hawkbit.repository.jpa.model.JpaTenantAwareBaseEntity; import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.repository.NoRepositoryBean; @@ -27,7 +28,7 @@ import org.springframework.transaction.annotation.Transactional; */ @NoRepositoryBean @Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) -public interface BaseEntityRepository +public interface BaseEntityRepository extends PagingAndSortingRepository { /** diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/DeploymentHelper.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/DeploymentHelper.java index f5123c792..f5d00862b 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/DeploymentHelper.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/DeploymentHelper.java @@ -15,10 +15,11 @@ import javax.persistence.EntityManager; import javax.validation.constraints.NotNull; import org.eclipse.hawkbit.repository.TargetManagement; +import org.eclipse.hawkbit.repository.jpa.model.JpaAction; +import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; +import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; -import org.eclipse.hawkbit.repository.model.Target; -import org.eclipse.hawkbit.repository.model.TargetInfo; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; /** @@ -48,10 +49,10 @@ public final class DeploymentHelper { * * @return updated target */ - static Target updateTargetInfo(@NotNull final Target target, @NotNull final TargetUpdateStatus status, + static JpaTarget updateTargetInfo(@NotNull final JpaTarget target, @NotNull final TargetUpdateStatus status, final boolean setInstalledDate, final TargetInfoRepository targetInfoRepository, final EntityManager entityManager) { - final TargetInfo ts = target.getTargetInfo(); + final JpaTargetInfo ts = (JpaTargetInfo) target.getTargetInfo(); ts.setUpdateStatus(status); if (setInstalledDate) { @@ -77,7 +78,7 @@ public final class DeploymentHelper { * @param targetInfoRepository * for the operation */ - static void successCancellation(final Action action, final ActionRepository actionRepository, + static void successCancellation(final JpaAction action, final ActionRepository actionRepository, final TargetManagement targetManagement, final TargetInfoRepository targetInfoRepository, final EntityManager entityManager) { @@ -85,7 +86,7 @@ public final class DeploymentHelper { action.setActive(false); action.setStatus(Status.CANCELED); - final Target target = action.getTarget(); + final JpaTarget target = (JpaTarget) action.getTarget(); final List nextActiveActions = actionRepository.findByTargetAndActiveOrderByIdAsc(target, true).stream() .filter(a -> !a.getId().equals(action.getId())).collect(Collectors.toList()); diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetMetadataRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetMetadataRepository.java index 68cd380e5..7b8b1b20f 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetMetadataRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetMetadataRepository.java @@ -8,8 +8,9 @@ */ package org.eclipse.hawkbit.repository.jpa; +import org.eclipse.hawkbit.repository.jpa.model.DsMetadataCompositeKey; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetMetadata; import org.eclipse.hawkbit.repository.model.DistributionSetMetadata; -import org.eclipse.hawkbit.repository.model.DsMetadataCompositeKey; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.transaction.annotation.Isolation; @@ -17,13 +18,10 @@ import org.springframework.transaction.annotation.Transactional; /** * {@link DistributionSetMetadata} repository. - * - * - * */ @Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) public interface DistributionSetMetadataRepository - extends PagingAndSortingRepository, - JpaSpecificationExecutor { + extends PagingAndSortingRepository, + JpaSpecificationExecutor { } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetRepository.java index c7ab44145..1ab6cbe08 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetRepository.java @@ -11,10 +11,12 @@ package org.eclipse.hawkbit.repository.jpa; import java.util.Collection; import java.util.List; -import org.eclipse.hawkbit.repository.model.Action; +import org.eclipse.hawkbit.repository.jpa.model.JpaAction; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType; +import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; import org.eclipse.hawkbit.repository.model.DistributionSet; -import org.eclipse.hawkbit.repository.model.DistributionSetTag; -import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.Tag; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; @@ -30,7 +32,7 @@ import org.springframework.transaction.annotation.Transactional; */ @Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) public interface DistributionSetRepository - extends BaseEntityRepository, JpaSpecificationExecutor { + extends BaseEntityRepository, JpaSpecificationExecutor { /** * Finds {@link DistributionSet}s by assigned {@link Tag}. @@ -39,8 +41,8 @@ public interface DistributionSetRepository * to be found * @return list of found {@link DistributionSet}s */ - @Query(value = "Select Distinct ds from DistributionSet ds join ds.tags dst where dst = :tag") - List findByTag(@Param("tag") final DistributionSetTag tag); + @Query(value = "Select Distinct ds from JpaDistributionSet ds join ds.tags dst where dst = :tag") + List findByTag(@Param("tag") final JpaDistributionSetTag tag); /** * deletes the {@link DistributionSet}s with the given IDs. @@ -50,9 +52,12 @@ public interface DistributionSetRepository */ @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @Query("update DistributionSet d set d.deleted = 1 where d.id in :ids") + @Query("update JpaDistributionSet d set d.deleted = 1 where d.id in :ids") void deleteDistributionSet(@Param("ids") Long... ids); + @Override + List findAll(Iterable ids); + /** * deletes {@link DistributionSet}s by the given IDs. * @@ -63,7 +68,7 @@ public interface DistributionSetRepository @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) // Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=349477 - @Query("DELETE FROM DistributionSet d WHERE d.id IN ?1") + @Query("DELETE FROM JpaDistributionSet d WHERE d.id IN ?1") int deleteByIdIn(Collection ids); /** @@ -74,7 +79,7 @@ public interface DistributionSetRepository * to search for * @return {@link List} of found {@link DistributionSet}s */ - List findByModules(SoftwareModule module); + List findByModules(JpaSoftwareModule module); /** * Finds {@link DistributionSet}s based on given ID if they are not assigned @@ -84,7 +89,7 @@ public interface DistributionSetRepository * to search for * @return */ - @Query("select ac.distributionSet.id from Action ac where ac.distributionSet.id in :ids") + @Query("select ac.distributionSet.id from JpaAction ac where ac.distributionSet.id in :ids") List findAssignedDistributionSetsById(@Param("ids") Long... ids); /** @@ -98,7 +103,7 @@ public interface DistributionSetRepository * @see org.springframework.data.repository.CrudRepository#save(java.lang.Iterable) */ @Override - List save(Iterable entities); + List save(Iterable entities); /** * Finds the distribution set for a specific action. @@ -107,8 +112,8 @@ public interface DistributionSetRepository * the action associated with the distribution set to find * @return the distribution set associated with the given action */ - @Query("select DISTINCT d from DistributionSet d join fetch d.modules m join d.actions a where a = :action") - DistributionSet findByAction(@Param("action") Action action); + @Query("select DISTINCT d from JpaDistributionSet d join fetch d.modules m join d.actions a where a = :action") + JpaDistributionSet findByAction(@Param("action") JpaAction action); /** * Counts {@link DistributionSet} instances of given type in the repository. @@ -117,7 +122,7 @@ public interface DistributionSetRepository * to search for * @return number of found {@link DistributionSet}s */ - long countByType(DistributionSetType type); + long countByType(JpaDistributionSetType type); /** * Counts {@link DistributionSet} with given diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetTagRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetTagRepository.java index 9e55a305b..d13316b91 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetTagRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetTagRepository.java @@ -10,6 +10,7 @@ package org.eclipse.hawkbit.repository.jpa; import java.util.List; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.TargetTag; @@ -24,7 +25,7 @@ import org.springframework.transaction.annotation.Transactional; */ @Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) public interface DistributionSetTagRepository - extends BaseEntityRepository, JpaSpecificationExecutor { + extends BaseEntityRepository, JpaSpecificationExecutor { /** * deletes the {@link DistributionSet} with the given name. * @@ -43,7 +44,7 @@ public interface DistributionSetTagRepository * to filter on * @return the {@link DistributionSetTag} if found, otherwise null */ - DistributionSetTag findByNameEquals(final String tagName); + JpaDistributionSetTag findByNameEquals(final String tagName); /** * Returns all instances of the type. @@ -51,8 +52,8 @@ public interface DistributionSetTagRepository * @return all entities */ @Override - List findAll(); + List findAll(); @Override - List save(Iterable entities); + List save(Iterable entities); } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetTypeRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetTypeRepository.java index 7c0d39b58..82754d7f8 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetTypeRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetTypeRepository.java @@ -8,8 +8,9 @@ */ package org.eclipse.hawkbit.repository.jpa; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType; +import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType; import org.eclipse.hawkbit.repository.model.DistributionSetType; -import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; @@ -23,7 +24,7 @@ import org.springframework.transaction.annotation.Transactional; */ @Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) public interface DistributionSetTypeRepository - extends BaseEntityRepository, JpaSpecificationExecutor { + extends BaseEntityRepository, JpaSpecificationExecutor { /** * @@ -34,7 +35,7 @@ public interface DistributionSetTypeRepository * false if undeleted ones * @return list of found {@link DistributionSetType}s */ - Page findByDeleted(Pageable pageable, boolean isDeleted); + Page findByDeleted(Pageable pageable, boolean isDeleted); /** * @param isDeleted @@ -54,5 +55,5 @@ public interface DistributionSetTypeRepository * @return the number of {@link DistributionSetType}s in the repository * assigned to the given software module type */ - Long countByElementsSmType(SoftwareModuleType softwareModuleType); + Long countByElementsSmType(JpaSoftwareModuleType softwareModuleType); } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/EclipseLinkTargetInfoRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/EclipseLinkTargetInfoRepository.java index ca124f81c..93b861092 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/EclipseLinkTargetInfoRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/EclipseLinkTargetInfoRepository.java @@ -14,7 +14,7 @@ import java.util.List; import javax.persistence.EntityManager; import javax.persistence.Query; -import org.eclipse.hawkbit.repository.model.TargetInfo; +import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheEvict; @@ -40,7 +40,7 @@ public class EclipseLinkTargetInfoRepository implements TargetInfoRepository { @Transactional(isolation = Isolation.READ_UNCOMMITTED) public void setTargetUpdateStatus(final TargetUpdateStatus status, final List targets) { final Query query = entityManager.createQuery( - "update TargetInfo ti set ti.updateStatus = :status where ti.targetId in :targets and ti.updateStatus != :status"); + "update JpaTargetInfo ti set ti.updateStatus = :status where ti.targetId in :targets and ti.updateStatus != :status"); query.setParameter("targets", targets); query.setParameter("status", status); @@ -50,7 +50,7 @@ public class EclipseLinkTargetInfoRepository implements TargetInfoRepository { @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) @CacheEvict(value = { "targetStatus", "distributionUsageInstalled", "targetsLastPoll" }, allEntries = true) - public S save(final S entity) { + public S save(final S entity) { if (entity.isNew()) { entityManager.persist(entity); @@ -66,7 +66,7 @@ public class EclipseLinkTargetInfoRepository implements TargetInfoRepository { @CacheEvict(value = { "targetStatus", "distributionUsageInstalled", "targetsLastPoll" }, allEntries = true) public void deleteByTargetIdIn(final Collection targetIDs) { final javax.persistence.Query query = entityManager - .createQuery("DELETE FROM TargetInfo ti where ti.targetId IN :target"); + .createQuery("DELETE FROM JpaTargetInfo ti where ti.targetId IN :target"); query.setParameter("target", targetIDs); } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/ExternalArtifactProviderRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/ExternalArtifactProviderRepository.java index 4a29afc4b..039c4917e 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/ExternalArtifactProviderRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/ExternalArtifactProviderRepository.java @@ -8,6 +8,7 @@ */ package org.eclipse.hawkbit.repository.jpa; +import org.eclipse.hawkbit.repository.jpa.model.JpaExternalArtifactProvider; import org.eclipse.hawkbit.repository.model.ExternalArtifactProvider; import org.springframework.transaction.annotation.Isolation; import org.springframework.transaction.annotation.Transactional; @@ -17,6 +18,6 @@ import org.springframework.transaction.annotation.Transactional; * */ @Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) -public interface ExternalArtifactProviderRepository extends BaseEntityRepository { +public interface ExternalArtifactProviderRepository extends BaseEntityRepository { } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/ExternalArtifactRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/ExternalArtifactRepository.java index dfc8105dd..5845afbee 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/ExternalArtifactRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/ExternalArtifactRepository.java @@ -8,6 +8,7 @@ */ package org.eclipse.hawkbit.repository.jpa; +import org.eclipse.hawkbit.repository.jpa.model.JpaExternalArtifact; import org.eclipse.hawkbit.repository.model.ExternalArtifact; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -19,7 +20,7 @@ import org.springframework.transaction.annotation.Transactional; * */ @Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) -public interface ExternalArtifactRepository extends BaseEntityRepository { +public interface ExternalArtifactRepository extends BaseEntityRepository { /** * Searches for external artifact for a base software module. @@ -31,6 +32,6 @@ public interface ExternalArtifactRepository extends BaseEntityRepository */ - Page findBySoftwareModuleId(Pageable pageReq, final Long swId); + Page findBySoftwareModuleId(Pageable pageReq, final Long swId); } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaArtifactManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaArtifactManagement.java index 7bae73a8b..93e0afc00 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaArtifactManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaArtifactManagement.java @@ -24,12 +24,16 @@ import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.exception.GridFSDBFileNotFoundException; import org.eclipse.hawkbit.repository.exception.InvalidMD5HashException; import org.eclipse.hawkbit.repository.exception.InvalidSHA1HashException; +import org.eclipse.hawkbit.repository.jpa.model.JpaExternalArtifact; +import org.eclipse.hawkbit.repository.jpa.model.JpaExternalArtifactProvider; +import org.eclipse.hawkbit.repository.jpa.model.JpaLocalArtifact; +import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; +import org.eclipse.hawkbit.repository.jpa.specifications.SoftwareModuleSpecification; import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.ExternalArtifact; import org.eclipse.hawkbit.repository.model.ExternalArtifactProvider; import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; -import org.eclipse.hawkbit.repository.specifications.SoftwareModuleSpecification; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -88,7 +92,7 @@ public class JpaArtifactManagement implements ArtifactManagement { final String urlSuffix, final Long moduleId) { final SoftwareModule module = getModuleAndThrowExceptionIfThatFails(moduleId); - return externalArtifactRepository.save(new ExternalArtifact(externalRepository, urlSuffix, module)); + return externalArtifactRepository.save(new JpaExternalArtifact(externalRepository, urlSuffix, module)); } @Override @@ -97,7 +101,7 @@ public class JpaArtifactManagement implements ArtifactManagement { public ExternalArtifactProvider createExternalArtifactProvider(final String name, final String description, final String basePath, final String defaultUrlSuffix) { return externalArtifactProviderRepository - .save(new ExternalArtifactProvider(name, description, basePath, defaultUrlSuffix)); + .save(new JpaExternalArtifactProvider(name, description, basePath, defaultUrlSuffix)); } @Override @@ -142,7 +146,7 @@ public class JpaArtifactManagement implements ArtifactManagement { } existing.getSoftwareModule().removeArtifact(existing); - softwareModuleRepository.save(existing.getSoftwareModule()); + softwareModuleRepository.save((JpaSoftwareModule) existing.getSoftwareModule()); externalArtifactRepository.delete(id); } @@ -156,7 +160,7 @@ public class JpaArtifactManagement implements ArtifactManagement { boolean artifactIsOnlyUsedByOneSoftwareModule = true; for (final LocalArtifact lArtifact : localArtifactRepository - .findByGridFsFileName(existing.getGridFsFileName())) { + .findByGridFsFileName(((JpaLocalArtifact) existing).getGridFsFileName())) { if (!lArtifact.getSoftwareModule().isDeleted() && Long.compare(lArtifact.getSoftwareModule().getId(), existing.getSoftwareModule().getId()) != 0) { artifactIsOnlyUsedByOneSoftwareModule = false; @@ -166,8 +170,8 @@ public class JpaArtifactManagement implements ArtifactManagement { if (artifactIsOnlyUsedByOneSoftwareModule) { try { - LOG.debug("deleting artifact from repository {}", existing.getGridFsFileName()); - artifactRepository.deleteBySha1(existing.getGridFsFileName()); + LOG.debug("deleting artifact from repository {}", ((JpaLocalArtifact) existing).getGridFsFileName()); + artifactRepository.deleteBySha1(((JpaLocalArtifact) existing).getGridFsFileName()); } catch (final ArtifactStoreException e) { throw new ArtifactDeleteFailedException(e); } @@ -178,7 +182,7 @@ public class JpaArtifactManagement implements ArtifactManagement { @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) public void deleteLocalArtifact(final Long id) { - final LocalArtifact existing = localArtifactRepository.findOne(id); + final JpaLocalArtifact existing = localArtifactRepository.findOne(id); if (null == existing) { return; @@ -187,7 +191,7 @@ public class JpaArtifactManagement implements ArtifactManagement { deleteLocalArtifact(existing); existing.getSoftwareModule().removeArtifact(existing); - softwareModuleRepository.save(existing.getSoftwareModule()); + softwareModuleRepository.save((JpaSoftwareModule) existing.getSoftwareModule()); localArtifactRepository.delete(id); } @@ -219,7 +223,7 @@ public class JpaArtifactManagement implements ArtifactManagement { @Override public SoftwareModule findSoftwareModuleById(final Long id) { - final Specification spec = SoftwareModuleSpecification.byId(id); + final Specification spec = SoftwareModuleSpecification.byId(id); return softwareModuleRepository.findOne(spec); } @@ -246,9 +250,10 @@ public class JpaArtifactManagement implements ArtifactManagement { @Override public DbArtifact loadLocalArtifactBinary(final LocalArtifact artifact) { - final DbArtifact result = artifactRepository.getArtifactBySha1(artifact.getGridFsFileName()); + final DbArtifact result = artifactRepository + .getArtifactBySha1(((JpaLocalArtifact) artifact).getGridFsFileName()); if (result == null) { - throw new GridFSDBFileNotFoundException(artifact.getGridFsFileName()); + throw new GridFSDBFileNotFoundException(((JpaLocalArtifact) artifact).getGridFsFileName()); } return result; @@ -256,9 +261,9 @@ public class JpaArtifactManagement implements ArtifactManagement { private LocalArtifact storeArtifactMetadata(final SoftwareModule softwareModule, final String providedFilename, final DbArtifact result, final LocalArtifact existing) { - LocalArtifact artifact = existing; + JpaLocalArtifact artifact = (JpaLocalArtifact) existing; if (existing == null) { - artifact = new LocalArtifact(result.getHashes().getSha1(), providedFilename, softwareModule); + artifact = new JpaLocalArtifact(result.getHashes().getSha1(), providedFilename, softwareModule); } artifact.setMd5Hash(result.getHashes().getMd5()); artifact.setSha1Hash(result.getHashes().getSha1()); diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java index a7706440d..c7a229bf0 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java @@ -9,6 +9,7 @@ package org.eclipse.hawkbit.repository.jpa; import java.net.URI; +import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -24,19 +25,25 @@ import org.eclipse.hawkbit.repository.TenantConfigurationManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.exception.ToManyAttributeEntriesException; import org.eclipse.hawkbit.repository.exception.ToManyStatusEntriesException; +import org.eclipse.hawkbit.repository.jpa.model.JpaAction; +import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus; +import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus_; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; +import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; +import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; +import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo; +import org.eclipse.hawkbit.repository.jpa.model.JpaTarget_; +import org.eclipse.hawkbit.repository.jpa.specifications.ActionSpecifications; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; -import org.eclipse.hawkbit.repository.model.ActionStatus_; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetInfo; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; -import org.eclipse.hawkbit.repository.model.Target_; import org.eclipse.hawkbit.repository.model.TenantConfiguration; -import org.eclipse.hawkbit.repository.specifications.ActionSpecifications; import org.eclipse.hawkbit.security.HawkbitSecurityProperties; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; import org.slf4j.Logger; @@ -46,6 +53,7 @@ import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.repository.Modifying; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Isolation; +import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; @@ -116,7 +124,8 @@ public class JpaControllerManagement implements ControllerManagement { @Override public Action getActionForDownloadByTargetAndSoftwareModule(final String controllerId, final SoftwareModule module) { - final List action = actionRepository.findActionByTargetAndSoftwareModule(controllerId, module); + final List action = actionRepository.findActionByTargetAndSoftwareModule(controllerId, + (JpaSoftwareModule) module); if (action.isEmpty() || action.get(0).isCancelingOrCanceled()) { throw new EntityNotFoundException( @@ -137,12 +146,12 @@ public class JpaControllerManagement implements ControllerManagement { @Override public List findActionByTargetAndActive(final Target target) { - return actionRepository.findByTargetAndActiveOrderByIdAsc(target, true); + return actionRepository.findByTargetAndActiveOrderByIdAsc((JpaTarget) target, true); } @Override public List findSoftwareModulesByDistributionSet(final DistributionSet distributionSet) { - return softwareModuleRepository.findByAssignedTo(distributionSet); + return new ArrayList<>(softwareModuleRepository.findByAssignedTo((JpaDistributionSet) distributionSet)); } @Override @@ -154,13 +163,13 @@ public class JpaControllerManagement implements ControllerManagement { @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) public Target findOrRegisterTargetIfItDoesNotexist(final String controllerId, final URI address) { - final Specification spec = (targetRoot, query, cb) -> cb.equal(targetRoot.get(Target_.controllerId), - controllerId); + final Specification spec = (targetRoot, query, cb) -> cb + .equal(targetRoot.get(JpaTarget_.controllerId), controllerId); - Target target = targetRepository.findOne(spec); + JpaTarget target = targetRepository.findOne(spec); if (target == null) { - target = new Target(controllerId); + target = new JpaTarget(controllerId); target.setDescription("Plug and Play target: " + controllerId); target.setName(controllerId); return targetManagement.createTarget(target, TargetUpdateStatus.REGISTERED, System.currentTimeMillis(), @@ -175,7 +184,7 @@ public class JpaControllerManagement implements ControllerManagement { @Transactional(isolation = Isolation.READ_UNCOMMITTED) public TargetInfo updateTargetStatus(final TargetInfo targetInfo, final TargetUpdateStatus status, final Long lastTargetQuery, final URI address) { - final TargetInfo mtargetInfo = entityManager.merge(targetInfo); + final JpaTargetInfo mtargetInfo = (JpaTargetInfo) entityManager.merge(targetInfo); if (status != null) { mtargetInfo.setUpdateStatus(status); } @@ -192,7 +201,7 @@ public class JpaControllerManagement implements ControllerManagement { @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) public Action addCancelActionStatus(final ActionStatus actionStatus) { - final Action action = actionStatus.getAction(); + final JpaAction action = (JpaAction) actionStatus.getAction(); checkForToManyStatusEntries(action); action.setStatus(actionStatus.getStatus()); @@ -217,7 +226,7 @@ public class JpaControllerManagement implements ControllerManagement { default: } actionRepository.save(action); - actionStatusRepository.save(actionStatus); + actionStatusRepository.save((JpaActionStatus) actionStatus); return action; } @@ -226,14 +235,14 @@ public class JpaControllerManagement implements ControllerManagement { @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) public Action addUpdateActionStatus(@NotNull final ActionStatus actionStatus) { - final Action action = actionStatus.getAction(); + final JpaAction action = (JpaAction) actionStatus.getAction(); if (!action.isActive()) { LOG.debug("Update of actionStatus {} for action {} not possible since action not active anymore.", actionStatus.getId(), action.getId()); return action; } - return handleAddUpdateActionStatus(actionStatus, action); + return handleAddUpdateActionStatus((JpaActionStatus) actionStatus, action); } /** @@ -243,11 +252,11 @@ public class JpaControllerManagement implements ControllerManagement { * @param action * @return */ - private Action handleAddUpdateActionStatus(final ActionStatus actionStatus, final Action action) { + private Action handleAddUpdateActionStatus(final JpaActionStatus actionStatus, final JpaAction action) { LOG.debug("addUpdateActionStatus for action {}", action.getId()); - final Action mergedAction = entityManager.merge(action); - Target mergedTarget = mergedAction.getTarget(); + final JpaAction mergedAction = entityManager.merge(action); + JpaTarget mergedTarget = (JpaTarget) mergedAction.getTarget(); // check for a potential DOS attack checkForToManyStatusEntries(action); @@ -284,7 +293,7 @@ public class JpaControllerManagement implements ControllerManagement { targetManagement.updateTarget(mergedTarget); } - private void checkForToManyStatusEntries(final Action action) { + private void checkForToManyStatusEntries(final JpaAction action) { if (securityProperties.getDos().getMaxStatusEntriesPerAction() > 0) { final Long statusCount = actionStatusRepository.countByAction(action); @@ -299,11 +308,11 @@ public class JpaControllerManagement implements ControllerManagement { } } - private void handleFinishedAndStoreInTargetStatus(final Target target, final Action action) { + private void handleFinishedAndStoreInTargetStatus(final JpaTarget target, final JpaAction action) { action.setActive(false); action.setStatus(Status.FINISHED); - final TargetInfo targetInfo = target.getTargetInfo(); - final DistributionSet ds = entityManager.merge(action.getDistributionSet()); + final JpaTargetInfo targetInfo = (JpaTargetInfo) target.getTargetInfo(); + final JpaDistributionSet ds = (JpaDistributionSet) entityManager.merge(action.getDistributionSet()); targetInfo.setInstalledDistributionSet(ds); if (target.getAssignedDistributionSet() != null && targetInfo.getInstalledDistributionSet() != null && target .getAssignedDistributionSet().getId().equals(targetInfo.getInstalledDistributionSet().getId())) { @@ -321,15 +330,16 @@ public class JpaControllerManagement implements ControllerManagement { @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) public Target updateControllerAttributes(final String controllerId, final Map data) { - final Target target = targetRepository.findByControllerId(controllerId); + final JpaTarget target = targetRepository.findByControllerId(controllerId); if (target == null) { throw new EntityNotFoundException(controllerId); } - target.getTargetInfo().getControllerAttributes().putAll(data); + final JpaTargetInfo targetInfo = (JpaTargetInfo) target.getTargetInfo(); + targetInfo.getControllerAttributes().putAll(data); - if (target.getTargetInfo().getControllerAttributes().size() > securityProperties.getDos() + if (targetInfo.getControllerAttributes().size() > securityProperties.getDos() .getMaxAttributeEntriesPerTarget()) { LOG_DOS.info("Target tries to insert more than the allowed number of entries ({}). DOS attack anticipated!", securityProperties.getDos().getMaxAttributeEntriesPerTarget()); @@ -337,8 +347,8 @@ public class JpaControllerManagement implements ControllerManagement { String.valueOf(securityProperties.getDos().getMaxAttributeEntriesPerTarget())); } - target.getTargetInfo().setLastTargetQuery(System.currentTimeMillis()); - target.getTargetInfo().setRequestControllerAttributes(false); + targetInfo.setLastTargetQuery(System.currentTimeMillis()); + targetInfo.setRequestControllerAttributes(false); return targetRepository.save(target); } @@ -346,7 +356,7 @@ public class JpaControllerManagement implements ControllerManagement { @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) public Action registerRetrieved(final Action action, final String message) { - return handleRegisterRetrieved(action, message); + return handleRegisterRetrieved((JpaAction) action, message); } /** @@ -360,7 +370,7 @@ public class JpaControllerManagement implements ControllerManagement { * @return the updated action in case the status has been changed to * {@link Status#RETRIEVED} */ - private Action handleRegisterRetrieved(final Action action, final String message) { + private Action handleRegisterRetrieved(final JpaAction action, final String message) { // do a manual query with CriteriaBuilder to avoid unnecessary field // queries and an extra // count query made by spring-data when using pageable requests, we @@ -369,11 +379,11 @@ public class JpaControllerManagement implements ControllerManagement { // or not. final CriteriaBuilder cb = entityManager.getCriteriaBuilder(); final CriteriaQuery queryActionStatus = cb.createQuery(Object[].class); - final Root actionStatusRoot = queryActionStatus.from(ActionStatus.class); + final Root actionStatusRoot = queryActionStatus.from(JpaActionStatus.class); final CriteriaQuery query = queryActionStatus - .multiselect(actionStatusRoot.get(ActionStatus_.id), actionStatusRoot.get(ActionStatus_.status)) - .where(cb.equal(actionStatusRoot.get(ActionStatus_.action), action)) - .orderBy(cb.desc(actionStatusRoot.get(ActionStatus_.id))); + .multiselect(actionStatusRoot.get(JpaActionStatus_.id), actionStatusRoot.get(JpaActionStatus_.status)) + .where(cb.equal(actionStatusRoot.get(JpaActionStatus_.action), action)) + .orderBy(cb.desc(actionStatusRoot.get(JpaActionStatus_.id))); final List resultList = entityManager.createQuery(query).setFirstResult(0).setMaxResults(1) .getResultList(); @@ -387,14 +397,14 @@ public class JpaControllerManagement implements ControllerManagement { if (resultList.isEmpty() || resultList.get(0)[1] != Status.RETRIEVED) { // document that the status has been retrieved actionStatusRepository - .save(new ActionStatus(action, Status.RETRIEVED, System.currentTimeMillis(), message)); + .save(new JpaActionStatus(action, Status.RETRIEVED, System.currentTimeMillis(), message)); // don't change the action status itself in case the action is in // canceling state otherwise // we modify the action status and the controller won't get the // cancel job anymore. if (!action.isCancelingOrCanceled()) { - final Action actionMerge = entityManager.merge(action); + final JpaAction actionMerge = entityManager.merge(action); actionMerge.setStatus(Status.RETRIEVED); return actionRepository.save(actionMerge); } @@ -406,7 +416,7 @@ public class JpaControllerManagement implements ControllerManagement { @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) public void addInformationalActionStatus(final ActionStatus statusMessage) { - actionStatusRepository.save(statusMessage); + actionStatusRepository.save((JpaActionStatus) statusMessage); } @Override @@ -421,4 +431,10 @@ public class JpaControllerManagement implements ControllerManagement { public TargetInfo updateLastTargetQuery(final TargetInfo target, final URI address) { return updateTargetStatus(target, null, System.currentTimeMillis(), address); } + + @Override + @Transactional(propagation = Propagation.SUPPORTS) + public ActionStatus generateActionStatus() { + return new JpaActionStatus(); + } } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java index 0c5df3b3f..3dea0e549 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java @@ -8,6 +8,7 @@ */ package org.eclipse.hawkbit.repository.jpa; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -32,6 +33,7 @@ import org.eclipse.hawkbit.eventbus.event.CancelTargetAssignmentEvent; import org.eclipse.hawkbit.eventbus.event.TargetAssignDistributionSetEvent; import org.eclipse.hawkbit.eventbus.event.TargetInfoUpdateEvent; import org.eclipse.hawkbit.executor.AfterTransactionCommitExecutor; +import org.eclipse.hawkbit.repository.ActionFields; import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.DistributionSetAssignmentResult; import org.eclipse.hawkbit.repository.TargetManagement; @@ -39,24 +41,32 @@ import org.eclipse.hawkbit.repository.exception.CancelActionNotAllowedException; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.exception.ForceQuitActionNotAllowedException; import org.eclipse.hawkbit.repository.exception.IncompleteDistributionSetException; +import org.eclipse.hawkbit.repository.jpa.model.JpaAction; +import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus; +import org.eclipse.hawkbit.repository.jpa.model.JpaAction_; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet_; +import org.eclipse.hawkbit.repository.jpa.model.JpaRollout; +import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup; +import org.eclipse.hawkbit.repository.jpa.model.JpaRollout_; +import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; +import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; +import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo; +import org.eclipse.hawkbit.repository.jpa.specifications.TargetSpecifications; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.ActionType; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; import org.eclipse.hawkbit.repository.model.ActionWithStatusCount; -import org.eclipse.hawkbit.repository.model.Action_; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetType; -import org.eclipse.hawkbit.repository.model.DistributionSet_; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.RolloutGroup; -import org.eclipse.hawkbit.repository.model.Rollout_; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.repository.model.Target; -import org.eclipse.hawkbit.repository.model.TargetInfo; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; -import org.eclipse.hawkbit.repository.specifications.TargetSpecifications; +import org.eclipse.hawkbit.repository.rsql.RSQLUtility; import org.hibernate.validator.constraints.NotEmpty; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -64,12 +74,14 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheEvict; import org.springframework.data.domain.AuditorAware; import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.repository.Modifying; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Isolation; +import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; @@ -126,7 +138,7 @@ public class JpaDeploymentManagement implements DeploymentManagement { public DistributionSetAssignmentResult assignDistributionSet(final DistributionSet pset, final List targets) { - return assignDistributionSetByTargetId(pset, + return assignDistributionSetByTargetId((JpaDistributionSet) pset, targets.stream().map(target -> target.getControllerId()).collect(Collectors.toList()), ActionType.FORCED, Action.NO_FORCE_TIME); @@ -159,7 +171,7 @@ public class JpaDeploymentManagement implements DeploymentManagement { @CacheEvict(value = { "distributionUsageAssigned" }, allEntries = true) public DistributionSetAssignmentResult assignDistributionSet(final Long dsID, final Collection targets) { - final DistributionSet set = distributoinSetRepository.findOne(dsID); + final JpaDistributionSet set = distributoinSetRepository.findOne(dsID); if (set == null) { throw new EntityNotFoundException( String.format("no %s with id %d found", DistributionSet.class.getSimpleName(), dsID)); @@ -174,13 +186,13 @@ public class JpaDeploymentManagement implements DeploymentManagement { @CacheEvict(value = { "distributionUsageAssigned" }, allEntries = true) public DistributionSetAssignmentResult assignDistributionSet(final Long dsID, final Collection targets, final Rollout rollout, final RolloutGroup rolloutGroup) { - final DistributionSet set = distributoinSetRepository.findOne(dsID); + final JpaDistributionSet set = distributoinSetRepository.findOne(dsID); if (set == null) { throw new EntityNotFoundException( String.format("no %s with id %d found", DistributionSet.class.getSimpleName(), dsID)); } - return assignDistributionSetToTargets(set, targets, rollout, rolloutGroup); + return assignDistributionSetToTargets(set, targets, (JpaRollout) rollout, (JpaRolloutGroup) rolloutGroup); } /** @@ -201,9 +213,9 @@ public class JpaDeploymentManagement implements DeploymentManagement { * {@link SoftwareModuleType} are not assigned as define by the * {@link DistributionSetType}. */ - private DistributionSetAssignmentResult assignDistributionSetToTargets(@NotNull final DistributionSet set, - final Collection targetsWithActionType, final Rollout rollout, - final RolloutGroup rolloutGroup) { + private DistributionSetAssignmentResult assignDistributionSetToTargets(@NotNull final JpaDistributionSet set, + final Collection targetsWithActionType, final JpaRollout rollout, + final JpaRolloutGroup rolloutGroup) { if (!set.isComplete()) { throw new IncompleteDistributionSetException( @@ -223,7 +235,7 @@ public class JpaDeploymentManagement implements DeploymentManagement { // maximum 1000 elements, so we need to split the entries here and // execute multiple statements we take the target only into account if // the requested operation is no duplicate of a previous one - final List targets = Lists.partition(controllerIDs, Constants.MAX_ENTRIES_IN_STATEMENT).stream() + final List targets = Lists.partition(controllerIDs, Constants.MAX_ENTRIES_IN_STATEMENT).stream() .map(ids -> targetRepository .findAll(TargetSpecifications.hasControllerIdAndAssignedDistributionSetIdNot(ids, set.getId()))) .flatMap(t -> t.stream()).collect(Collectors.toList()); @@ -262,7 +274,7 @@ public class JpaDeploymentManagement implements DeploymentManagement { targetIds.forEach(tIds -> targetRepository.setAssignedDistributionSet(set, System.currentTimeMillis(), currentUser, tIds)); targetIds.forEach(tIds -> targetInfoRepository.setTargetUpdateStatus(TargetUpdateStatus.PENDING, tIds)); - final Map targetIdsToActions = actionRepository + final Map targetIdsToActions = actionRepository .save(targets.stream().map(t -> createTargetAction(targetsWithActionMap, t, set, rollout, rolloutGroup)) .collect(Collectors.toList())) .stream().collect(Collectors.toMap(a -> a.getTarget().getControllerId(), Function.identity())); @@ -272,7 +284,7 @@ public class JpaDeploymentManagement implements DeploymentManagement { // of the action itself and with this action status we have a nicer // action history. targetIdsToActions.values().forEach(action -> { - final ActionStatus actionStatus = new ActionStatus(); + final JpaActionStatus actionStatus = new JpaActionStatus(); actionStatus.setAction(action); actionStatus.setOccurredAt(action.getCreatedAt()); actionStatus.setStatus(Status.RUNNING); @@ -289,7 +301,7 @@ public class JpaDeploymentManagement implements DeploymentManagement { LOG.debug("assignDistribution({}) finished {}", set, result); - final List softwareModules = softwareModuleRepository.findByAssignedTo(set); + final List softwareModules = softwareModuleRepository.findByAssignedTo(set); // detaching as it is not necessary to persist the set itself entityManager.detach(set); @@ -299,16 +311,17 @@ public class JpaDeploymentManagement implements DeploymentManagement { return result; } - private void sendDistributionSetAssignmentEvent(final List targets, final Set targetIdsCancellList, - final Map targetIdsToActions, final List softwareModules) { + private void sendDistributionSetAssignmentEvent(final List targets, final Set targetIdsCancellList, + final Map targetIdsToActions, final List softwareModules) { targets.stream().filter(t -> !!!targetIdsCancellList.contains(t.getId())) .forEach(t -> assignDistributionSetEvent(t, targetIdsToActions.get(t.getControllerId()).getId(), softwareModules)); } - private static Action createTargetAction(final Map targetsWithActionMap, - final Target target, final DistributionSet set, final Rollout rollout, final RolloutGroup rolloutGroup) { - final Action actionForTarget = new Action(); + private static JpaAction createTargetAction(final Map targetsWithActionMap, + final JpaTarget target, final JpaDistributionSet set, final JpaRollout rollout, + final JpaRolloutGroup rolloutGroup) { + final JpaAction actionForTarget = new JpaAction(); final TargetWithActionType targetWithActionType = targetsWithActionMap.get(target.getControllerId()); actionForTarget.setActionType(targetWithActionType.getActionType()); actionForTarget.setForcedTime(targetWithActionType.getForceTime()); @@ -332,9 +345,12 @@ public class JpaDeploymentManagement implements DeploymentManagement { * @param softwareModules * the software modules which have been assigned */ - private void assignDistributionSetEvent(final Target target, final Long actionId, - final List softwareModules) { - target.getTargetInfo().setUpdateStatus(TargetUpdateStatus.PENDING); + private void assignDistributionSetEvent(final JpaTarget target, final Long actionId, + final List modules) { + ((JpaTargetInfo) target.getTargetInfo()).setUpdateStatus(TargetUpdateStatus.PENDING); + + @SuppressWarnings({ "unchecked", "rawtypes" }) + final Collection softwareModules = (Collection) modules; afterCommit.afterCommit(() -> { eventBus.post(new TargetInfoUpdateEvent(target.getTargetInfo())); eventBus.post(new TargetAssignDistributionSetEvent(target.getOptLockRevision(), target.getTenant(), @@ -357,14 +373,14 @@ public class JpaDeploymentManagement implements DeploymentManagement { // Figure out if there are potential target/action combinations that // need to be considered // for cancelation - final List activeActions = actionRepository + final List activeActions = actionRepository .findByActiveAndTargetIdInAndActionStatusNotEqualToAndDistributionSetRequiredMigrationStep(targetsIds, Action.Status.CANCELING); activeActions.forEach(action -> { action.setStatus(Status.CANCELING); // document that the status has been retrieved - actionStatusRepository.save(new ActionStatus(action, Status.CANCELING, System.currentTimeMillis(), + actionStatusRepository.save(new JpaActionStatus(action, Status.CANCELING, System.currentTimeMillis(), "manual cancelation requested")); cancelAssignDistributionSetEvent(action.getTarget(), action.getId()); @@ -378,7 +394,7 @@ public class JpaDeploymentManagement implements DeploymentManagement { } - private DistributionSetAssignmentResult assignDistributionSetByTargetId(@NotNull final DistributionSet set, + private DistributionSetAssignmentResult assignDistributionSetByTargetId(@NotNull final JpaDistributionSet set, @NotEmpty final List tIDs, final ActionType actionType, final long forcedTime) { return assignDistributionSetToTargets(set, tIDs.stream() @@ -394,14 +410,14 @@ public class JpaDeploymentManagement implements DeploymentManagement { if (action.isCancelingOrCanceled()) { throw new CancelActionNotAllowedException("Actions in canceling or canceled state cannot be canceled"); } - final Action myAction = entityManager.merge(action); + final JpaAction myAction = (JpaAction) entityManager.merge(action); if (myAction.isActive()) { LOG.debug("action ({}) was still active. Change to {}.", action, Status.CANCELING); myAction.setStatus(Status.CANCELING); // document that the status has been retrieved - actionStatusRepository.save(new ActionStatus(myAction, Status.CANCELING, System.currentTimeMillis(), + actionStatusRepository.save(new JpaActionStatus(myAction, Status.CANCELING, System.currentTimeMillis(), "manual cancelation requested")); final Action saveAction = actionRepository.save(myAction); cancelAssignDistributionSetEvent(target, myAction.getId()); @@ -431,7 +447,7 @@ public class JpaDeploymentManagement implements DeploymentManagement { @Modifying @Transactional(isolation = Isolation.READ_COMMITTED) public Action forceQuitAction(final Action action) { - final Action mergedAction = entityManager.merge(action); + final JpaAction mergedAction = (JpaAction) entityManager.merge(action); if (!mergedAction.isCancelingOrCanceled()) { throw new ForceQuitActionNotAllowedException( @@ -446,7 +462,7 @@ public class JpaDeploymentManagement implements DeploymentManagement { LOG.warn("action ({}) was still activ and has been force quite.", action); // document that the status has been retrieved - actionStatusRepository.save(new ActionStatus(mergedAction, Status.CANCELED, System.currentTimeMillis(), + actionStatusRepository.save(new JpaActionStatus(mergedAction, Status.CANCELED, System.currentTimeMillis(), "A force quit has been performed.")); DeploymentHelper.successCancellation(mergedAction, actionRepository, targetManagement, targetInfoRepository, @@ -468,7 +484,7 @@ public class JpaDeploymentManagement implements DeploymentManagement { final List targetIds = targets.stream().map(t -> t.getId()).collect(Collectors.toList()); actionRepository.switchStatus(Action.Status.CANCELED, targetIds, false, Action.Status.SCHEDULED); targets.forEach(target -> { - final Action action = new Action(); + final JpaAction action = new JpaAction(); action.setTarget(target); action.setActive(false); action.setDistributionSet(distributionSet); @@ -486,8 +502,8 @@ public class JpaDeploymentManagement implements DeploymentManagement { @Transactional(isolation = Isolation.READ_COMMITTED) public Action startScheduledAction(final Action action) { - final Action mergedAction = entityManager.merge(action); - final Target mergedTarget = entityManager.merge(action.getTarget()); + final JpaAction mergedAction = (JpaAction) entityManager.merge(action); + final JpaTarget mergedTarget = (JpaTarget) entityManager.merge(action.getTarget()); // check if we need to override running update actions final Set overrideObsoleteUpdateActions = overrideObsoleteUpdateActions( @@ -509,14 +525,14 @@ public class JpaDeploymentManagement implements DeploymentManagement { mergedAction.setStatus(Status.RUNNING); final Action savedAction = actionRepository.save(mergedAction); - final ActionStatus actionStatus = new ActionStatus(); + final JpaActionStatus actionStatus = new JpaActionStatus(); actionStatus.setAction(action); actionStatus.setOccurredAt(action.getCreatedAt()); actionStatus.setStatus(Status.RUNNING); actionStatusRepository.save(actionStatus); mergedTarget.setAssignedDistributionSet(action.getDistributionSet()); - final TargetInfo targetInfo = mergedTarget.getTargetInfo(); + final JpaTargetInfo targetInfo = (JpaTargetInfo) mergedTarget.getTargetInfo(); targetInfo.setUpdateStatus(TargetUpdateStatus.PENDING); targetRepository.save(mergedTarget); targetInfoRepository.save(targetInfo); @@ -524,11 +540,11 @@ public class JpaDeploymentManagement implements DeploymentManagement { // in case we canceled an action before for this target, then don't fire // assignment event if (!overrideObsoleteUpdateActions.contains(savedAction.getId())) { - final List softwareModules = softwareModuleRepository - .findByAssignedTo(action.getDistributionSet()); + final List softwareModules = softwareModuleRepository + .findByAssignedTo((JpaDistributionSet) action.getDistributionSet()); // send distribution set assignment event - assignDistributionSetEvent(mergedAction.getTarget(), mergedAction.getId(), softwareModules); + assignDistributionSetEvent((JpaTarget) mergedAction.getTarget(), mergedAction.getId(), softwareModules); } return savedAction; } @@ -545,84 +561,93 @@ public class JpaDeploymentManagement implements DeploymentManagement { @Override public Slice findActionsByTarget(final Pageable pageable, final Target target) { - return actionRepository.findByTarget(pageable, target); + return actionRepository.findByTarget(pageable, (JpaTarget) target); } @Override public List findActionsByTarget(final Target target) { - return actionRepository.findByTarget(target); + return actionRepository.findByTarget((JpaTarget) target); } @Override public List findActionsWithStatusCountByTargetOrderByIdDesc(final Target target) { final CriteriaBuilder cb = entityManager.getCriteriaBuilder(); final CriteriaQuery query = cb.createQuery(ActionWithStatusCount.class); - final Root actionRoot = query.from(Action.class); - final ListJoin actionStatusJoin = actionRoot.join(Action_.actionStatus, JoinType.LEFT); - final Join actionDsJoin = actionRoot.join(Action_.distributionSet); - final Join actionRolloutJoin = actionRoot.join(Action_.rollout, JoinType.LEFT); + final Root actionRoot = query.from(JpaAction.class); + final ListJoin actionStatusJoin = actionRoot.join(JpaAction_.actionStatus, + JoinType.LEFT); + final Join actionDsJoin = actionRoot.join(JpaAction_.distributionSet); + final Join actionRolloutJoin = actionRoot.join(JpaAction_.rollout, JoinType.LEFT); final CriteriaQuery multiselect = query.distinct(true).multiselect( - actionRoot.get(Action_.id), actionRoot.get(Action_.actionType), actionRoot.get(Action_.active), - actionRoot.get(Action_.forcedTime), actionRoot.get(Action_.status), actionRoot.get(Action_.createdAt), - actionRoot.get(Action_.lastModifiedAt), actionDsJoin.get(DistributionSet_.id), - actionDsJoin.get(DistributionSet_.name), actionDsJoin.get(DistributionSet_.version), - cb.count(actionStatusJoin), actionRolloutJoin.get(Rollout_.name)); - multiselect.where(cb.equal(actionRoot.get(Action_.target), target)); - multiselect.orderBy(cb.desc(actionRoot.get(Action_.id))); - multiselect.groupBy(actionRoot.get(Action_.id)); + actionRoot.get(JpaAction_.id), actionRoot.get(JpaAction_.actionType), actionRoot.get(JpaAction_.active), + actionRoot.get(JpaAction_.forcedTime), actionRoot.get(JpaAction_.status), + actionRoot.get(JpaAction_.createdAt), actionRoot.get(JpaAction_.lastModifiedAt), + actionDsJoin.get(JpaDistributionSet_.id), actionDsJoin.get(JpaDistributionSet_.name), + actionDsJoin.get(JpaDistributionSet_.version), cb.count(actionStatusJoin), + actionRolloutJoin.get(JpaRollout_.name)); + multiselect.where(cb.equal(actionRoot.get(JpaAction_.target), target)); + multiselect.orderBy(cb.desc(actionRoot.get(JpaAction_.id))); + multiselect.groupBy(actionRoot.get(JpaAction_.id)); return entityManager.createQuery(multiselect).getResultList(); } @Override - public Slice findActionsByTarget(final Specification specifiction, final Target target, - final Pageable pageable) { + public Page findActionsByTarget(final String rsqlParam, final Target target, final Pageable pageable) { + final Specification specification = RSQLUtility.parse(rsqlParam, ActionFields.class); - return actionRepository.findAll((Specification) (root, query, cb) -> cb - .and(specifiction.toPredicate(root, query, cb), cb.equal(root.get(Action_.target), target)), pageable); + return convertAcPage(actionRepository.findAll((Specification) (root, query, cb) -> cb + .and(specification.toPredicate(root, query, cb), cb.equal(root.get(JpaAction_.target), target)), + pageable)); + } + + private static Page convertAcPage(final Page findAll) { + return new PageImpl<>(new ArrayList<>(findAll.getContent())); } @Override public Slice findActionsByTarget(final Target foundTarget, final Pageable pageable) { - return actionRepository.findByTarget(pageable, foundTarget); + return actionRepository.findByTarget(pageable, (JpaTarget) foundTarget); } @Override public Page findActiveActionsByTarget(final Pageable pageable, final Target target) { - return actionRepository.findByActiveAndTarget(pageable, target, true); + return actionRepository.findByActiveAndTarget(pageable, (JpaTarget) target, true); } @Override public List findActiveActionsByTarget(final Target target) { - return actionRepository.findByActiveAndTarget(target, true); + return actionRepository.findByActiveAndTarget((JpaTarget) target, true); } @Override public List findInActiveActionsByTarget(final Target target) { - return actionRepository.findByActiveAndTarget(target, false); + return actionRepository.findByActiveAndTarget((JpaTarget) target, false); } @Override public Page findInActiveActionsByTarget(final Pageable pageable, final Target target) { - return actionRepository.findByActiveAndTarget(pageable, target, false); + return actionRepository.findByActiveAndTarget(pageable, (JpaTarget) target, false); } @Override public Long countActionsByTarget(final Target target) { - return actionRepository.countByTarget(target); + return actionRepository.countByTarget((JpaTarget) target); } @Override - public Long countActionsByTarget(final Specification spec, final Target target) { + public Long countActionsByTarget(final String rsqlParam, final Target target) { + final Specification spec = RSQLUtility.parse(rsqlParam, ActionFields.class); + return actionRepository.count((root, query, cb) -> cb.and(spec.toPredicate(root, query, cb), - cb.equal(root.get(Action_.target), target))); + cb.equal(root.get(JpaAction_.target), target))); } @Override @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) public Action forceTargetAction(final Long actionId) { - final Action action = actionRepository.findOne(actionId); + final JpaAction action = actionRepository.findOne(actionId); if (action != null && !action.isForced()) { action.setActionType(ActionType.FORCED); return actionRepository.save(action); @@ -634,20 +659,27 @@ public class JpaDeploymentManagement implements DeploymentManagement { public Page findActionStatusByAction(final Pageable pageReq, final Action action, final boolean withMessages) { if (withMessages) { - return actionStatusRepository.getByAction(pageReq, action); + return actionStatusRepository.getByAction(pageReq, (JpaAction) action); } else { - return actionStatusRepository.findByAction(pageReq, action); + return actionStatusRepository.findByAction(pageReq, (JpaAction) action); } } @Override public List findActionsByRolloutGroupParentAndStatus(final Rollout rollout, final RolloutGroup rolloutGroupParent, final Action.Status actionStatus) { - return actionRepository.findByRolloutAndRolloutGroupParentAndStatus(rollout, rolloutGroupParent, actionStatus); + return actionRepository.findByRolloutAndRolloutGroupParentAndStatus((JpaRollout) rollout, + (JpaRolloutGroup) rolloutGroupParent, actionStatus); } @Override public List findActionsByRolloutAndStatus(final Rollout rollout, final Action.Status actionStatus) { - return actionRepository.findByRolloutAndStatus(rollout, actionStatus); + return actionRepository.findByRolloutAndStatus((JpaRollout) rollout, actionStatus); + } + + @Override + @Transactional(propagation = Propagation.SUPPORTS) + public Action generateAction() { + return new JpaAction(); } } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java index da999e7cb..4e33d4960 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java @@ -24,28 +24,36 @@ import javax.persistence.EntityManager; import org.eclipse.hawkbit.eventbus.event.DistributionSetTagAssigmentResultEvent; import org.eclipse.hawkbit.executor.AfterTransactionCommitExecutor; +import org.eclipse.hawkbit.repository.DistributionSetFields; import org.eclipse.hawkbit.repository.DistributionSetFilter; import org.eclipse.hawkbit.repository.DistributionSetFilter.DistributionSetFilterBuilder; import org.eclipse.hawkbit.repository.DistributionSetManagement; +import org.eclipse.hawkbit.repository.DistributionSetMetadataFields; +import org.eclipse.hawkbit.repository.DistributionSetTypeFields; import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.exception.EntityLockedException; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.exception.EntityReadOnlyException; +import org.eclipse.hawkbit.repository.jpa.model.DsMetadataCompositeKey; +import org.eclipse.hawkbit.repository.jpa.model.JpaAction; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetMetadata; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetMetadata_; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet_; +import org.eclipse.hawkbit.repository.jpa.specifications.DistributionSetSpecification; +import org.eclipse.hawkbit.repository.jpa.specifications.DistributionSetTypeSpecification; +import org.eclipse.hawkbit.repository.jpa.specifications.SpecificationsBuilder; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetMetadata; -import org.eclipse.hawkbit.repository.model.DistributionSetMetadata_; import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult; import org.eclipse.hawkbit.repository.model.DistributionSetType; -import org.eclipse.hawkbit.repository.model.DistributionSet_; -import org.eclipse.hawkbit.repository.model.DsMetadataCompositeKey; import org.eclipse.hawkbit.repository.model.SoftwareModule; -import org.eclipse.hawkbit.repository.specifications.DistributionSetSpecification; -import org.eclipse.hawkbit.repository.specifications.DistributionSetTypeSpecification; -import org.eclipse.hawkbit.repository.specifications.SpecificationsBuilder; +import org.eclipse.hawkbit.repository.rsql.RSQLUtility; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; @@ -54,6 +62,7 @@ import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.repository.Modifying; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Isolation; +import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; @@ -111,12 +120,12 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { @Transactional(isolation = Isolation.READ_UNCOMMITTED) public DistributionSetTagAssignmentResult toggleTagAssignment(final Collection dsIds, final String tagName) { - final Iterable sets = findDistributionSetListWithDetails(dsIds); + final List sets = findDistributionSetListWithDetails(dsIds); final DistributionSetTag myTag = tagManagement.findDistributionSetTag(tagName); DistributionSetTagAssignmentResult result; - final List toBeChangedDSs = new ArrayList<>(); - for (final DistributionSet set : sets) { + final List toBeChangedDSs = new ArrayList<>(); + for (final JpaDistributionSet set : sets) { if (set.getTags().add(myTag)) { toBeChangedDSs.add(set); } @@ -124,17 +133,17 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { // un-assignment case if (toBeChangedDSs.isEmpty()) { - for (final DistributionSet set : sets) { + for (final JpaDistributionSet set : sets) { if (set.getTags().remove(myTag)) { toBeChangedDSs.add(set); } } result = new DistributionSetTagAssignmentResult(dsIds.size() - toBeChangedDSs.size(), 0, - toBeChangedDSs.size(), Collections.emptyList(), distributionSetRepository.save(toBeChangedDSs), - myTag); + toBeChangedDSs.size(), Collections.emptyList(), + new ArrayList<>(distributionSetRepository.save(toBeChangedDSs)), myTag); } else { result = new DistributionSetTagAssignmentResult(dsIds.size() - toBeChangedDSs.size(), toBeChangedDSs.size(), - 0, distributionSetRepository.save(toBeChangedDSs), Collections.emptyList(), myTag); + 0, new ArrayList<>(distributionSetRepository.save(toBeChangedDSs)), Collections.emptyList(), myTag); } final DistributionSetTagAssignmentResult resultAssignment = result; @@ -145,8 +154,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { return result; } - @Override - public List findDistributionSetListWithDetails(final Collection distributionIdSet) { + private List findDistributionSetListWithDetails(final Collection distributionIdSet) { return distributionSetRepository.findAll(DistributionSetSpecification.byIds(distributionIdSet)); } @@ -156,8 +164,8 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { public DistributionSet updateDistributionSet(final DistributionSet ds) { checkNotNull(ds.getId()); final DistributionSet persisted = findDistributionSetByIdWithDetails(ds.getId()); - checkDistributionSetSoftwareModulesIsAllowedToModify(ds, persisted.getModules()); - return distributionSetRepository.save(ds); + checkDistributionSetSoftwareModulesIsAllowedToModify((JpaDistributionSet) ds, persisted.getModules()); + return distributionSetRepository.save((JpaDistributionSet) ds); } @Override @@ -196,7 +204,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { if (dSet.getType() == null) { dSet.setType(systemManagement.getTenantMetadata().getDefaultDsType()); } - return distributionSetRepository.save(dSet); + return distributionSetRepository.save((JpaDistributionSet) dSet); } private void prepareDsSave(final DistributionSet dSet) { @@ -220,18 +228,22 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { ds.setType(systemManagement.getTenantMetadata().getDefaultDsType()); } } - return distributionSetRepository.save(distributionSets); + + @SuppressWarnings({ "unchecked", "rawtypes" }) + final Collection toSave = (Collection) distributionSets; + + return new ArrayList<>(distributionSetRepository.save(toSave)); } @Override @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) public DistributionSet assignSoftwareModules(final DistributionSet ds, final Set softwareModules) { - checkDistributionSetSoftwareModulesIsAllowedToModify(ds, softwareModules); + checkDistributionSetSoftwareModulesIsAllowedToModify((JpaDistributionSet) ds, softwareModules); for (final SoftwareModule softwareModule : softwareModules) { ds.addModule(softwareModule); } - return distributionSetRepository.save(ds); + return distributionSetRepository.save((JpaDistributionSet) ds); } @Override @@ -241,8 +253,8 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { final Set softwareModules = new HashSet<>(); softwareModules.add(softwareModule); ds.removeModule(softwareModule); - checkDistributionSetSoftwareModulesIsAllowedToModify(ds, softwareModules); - return distributionSetRepository.save(ds); + checkDistributionSetSoftwareModulesIsAllowedToModify((JpaDistributionSet) ds, softwareModules); + return distributionSetRepository.save((JpaDistributionSet) ds); } @Override @@ -251,7 +263,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { public DistributionSetType updateDistributionSetType(final DistributionSetType dsType) { checkNotNull(dsType.getId()); - final DistributionSetType persisted = distributionSetTypeRepository.findOne(dsType.getId()); + final JpaDistributionSetType persisted = distributionSetTypeRepository.findOne(dsType.getId()); // throw exception if user tries to update a DS type that is already in // use @@ -261,25 +273,36 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { dsType.getName())); } - return distributionSetTypeRepository.save(dsType); + return distributionSetTypeRepository.save((JpaDistributionSetType) dsType); } @Override - public Page findDistributionSetTypesAll(final Specification spec, - final Pageable pageable) { - return distributionSetTypeRepository.findAll(spec, pageable); + public Page findDistributionSetTypesAll(final String rsqlParam, final Pageable pageable) { + final Specification spec = RSQLUtility.parse(rsqlParam, + DistributionSetTypeFields.class); + + return convertDsTPage(distributionSetTypeRepository.findAll(spec, pageable)); + } + + private static Page convertDsTPage(final Page findAll) { + return new PageImpl<>(new ArrayList<>(findAll.getContent())); } @Override public Page findDistributionSetTypesAll(final Pageable pageable) { - return distributionSetTypeRepository.findByDeleted(pageable, false); + return convertDsTPage(distributionSetTypeRepository.findByDeleted(pageable, false)); } @Override public Page findDistributionSetsByFilters(final Pageable pageable, final DistributionSetFilter distributionSetFilter) { - final List> specList = buildDistributionSetSpecifications(distributionSetFilter); - return findByCriteriaAPI(pageable, specList); + final List> specList = buildDistributionSetSpecifications( + distributionSetFilter); + return convertDsPage(findByCriteriaAPI(pageable, specList)); + } + + private static Page convertDsPage(final Page findAll) { + return new PageImpl<>(new ArrayList<>(findAll.getContent())); } /** @@ -291,7 +314,8 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { */ private DistributionSet findDistributionSetsByFiltersAndInstalledOrAssignedTarget( final DistributionSetFilter distributionSetFilter) { - final List> specList = buildDistributionSetSpecifications(distributionSetFilter); + final List> specList = buildDistributionSetSpecifications( + distributionSetFilter); if (specList == null || specList.isEmpty()) { return null; } @@ -301,30 +325,33 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { @Override public Page findDistributionSetsAll(final Pageable pageReq, final Boolean deleted, final Boolean complete) { - final List> specList = new ArrayList<>(); + final List> specList = new ArrayList<>(); if (deleted != null) { - final Specification spec = DistributionSetSpecification.isDeleted(deleted); + final Specification spec = DistributionSetSpecification.isDeleted(deleted); specList.add(spec); } if (complete != null) { - final Specification spec = DistributionSetSpecification.isCompleted(complete); + final Specification spec = DistributionSetSpecification.isCompleted(complete); specList.add(spec); } - return findByCriteriaAPI(pageReq, specList); + return convertDsPage(findByCriteriaAPI(pageReq, specList)); } @Override - public Page findDistributionSetsAll(final Specification spec, - final Pageable pageReq, final Boolean deleted) { - final List> specList = new ArrayList<>(); + public Page findDistributionSetsAll(final String rsqlParam, final Pageable pageReq, + final Boolean deleted) { + + final Specification spec = RSQLUtility.parse(rsqlParam, DistributionSetFields.class); + + final List> specList = new ArrayList<>(); if (deleted != null) { specList.add(DistributionSetSpecification.isDeleted(deleted)); } specList.add(spec); - return findByCriteriaAPI(pageReq, specList); + return convertDsPage(findByCriteriaAPI(pageReq, specList)); } @Override @@ -371,23 +398,23 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { @Override public DistributionSet findDistributionSetByNameAndVersion(final String distributionName, final String version) { - final Specification spec = DistributionSetSpecification + final Specification spec = DistributionSetSpecification .equalsNameAndVersionIgnoreCase(distributionName, version); return distributionSetRepository.findOne(spec); } @Override - public Iterable findDistributionSetList(final Collection dist) { - return distributionSetRepository.findAll(dist); + public List findDistributionSetsAll(final Collection dist) { + return new ArrayList<>(distributionSetRepository.findAll(DistributionSetSpecification.byIds(dist))); } @Override public Long countDistributionSetsAll() { - final List> specList = new ArrayList<>(); + final List> specList = new LinkedList<>(); - final Specification spec = DistributionSetSpecification.isDeleted(Boolean.FALSE); + final Specification spec = DistributionSetSpecification.isDeleted(Boolean.FALSE); specList.add(spec); return distributionSetRepository.count(SpecificationsBuilder.combineWithAnd(specList)); @@ -421,16 +448,17 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { throw new EntityAlreadyExistsException("Given type contains an Id!"); } - return distributionSetTypeRepository.save(type); + return distributionSetTypeRepository.save((JpaDistributionSetType) type); } @Override @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) - public void deleteDistributionSetType(final DistributionSetType type) { + public void deleteDistributionSetType(final DistributionSetType ty) { + final JpaDistributionSetType type = (JpaDistributionSetType) ty; if (distributionSetRepository.countByType(type) > 0) { - final DistributionSetType toDelete = entityManager.merge(type); + final JpaDistributionSetType toDelete = entityManager.merge(type); toDelete.setDeleted(true); distributionSetTypeRepository.save(toDelete); } else { @@ -441,7 +469,9 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { @Override @Transactional(isolation = Isolation.READ_UNCOMMITTED) @Modifying - public DistributionSetMetadata createDistributionSetMetadata(final DistributionSetMetadata metadata) { + public DistributionSetMetadata createDistributionSetMetadata(final DistributionSetMetadata md) { + final JpaDistributionSetMetadata metadata = (JpaDistributionSetMetadata) md; + if (distributionSetMetadataRepository.exists(metadata.getId())) { throwMetadataKeyAlreadyExists(metadata.getId().getKey()); } @@ -449,31 +479,38 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { // log written because // modifying metadata is modifying the base distribution set itself for // auditing purposes. - entityManager.merge(metadata.getDistributionSet()).setLastModifiedAt(0L); + entityManager.merge((JpaDistributionSet) metadata.getDistributionSet()).setLastModifiedAt(0L); return distributionSetMetadataRepository.save(metadata); } @Override @Transactional(isolation = Isolation.READ_UNCOMMITTED) @Modifying - public List createDistributionSetMetadata( - final Collection metadata) { - for (final DistributionSetMetadata distributionSetMetadata : metadata) { + public List createDistributionSetMetadata(final Collection md) { + + @SuppressWarnings({ "rawtypes", "unchecked" }) + final Collection metadata = (Collection) md; + + for (final JpaDistributionSetMetadata distributionSetMetadata : metadata) { checkAndThrowAlreadyIfDistributionSetMetadataExists(distributionSetMetadata.getId()); } - metadata.forEach(m -> entityManager.merge(m.getDistributionSet()).setLastModifiedAt(-1L)); - return (List) distributionSetMetadataRepository.save(metadata); + metadata.forEach(m -> entityManager.merge((JpaDistributionSet) m.getDistributionSet()).setLastModifiedAt(0L)); + + return new ArrayList( + (Collection) distributionSetMetadataRepository.save(metadata)); } @Override @Transactional(isolation = Isolation.READ_UNCOMMITTED) @Modifying - public DistributionSetMetadata updateDistributionSetMetadata(final DistributionSetMetadata metadata) { + public DistributionSetMetadata updateDistributionSetMetadata(final DistributionSetMetadata md) { + final JpaDistributionSetMetadata metadata = (JpaDistributionSetMetadata) md; + // check if exists otherwise throw entity not found exception findOne(metadata.getId()); // touch it to update the lock revision because we are modifying the // DS indirectly - entityManager.merge(metadata.getDistributionSet()).setLastModifiedAt(0L); + entityManager.merge((JpaDistributionSet) metadata.getDistributionSet()).setLastModifiedAt(0L); return distributionSetMetadataRepository.save(metadata); } @@ -488,23 +525,29 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { public Page findDistributionSetMetadataByDistributionSetId(final Long distributionSetId, final Pageable pageable) { - return distributionSetMetadataRepository.findAll( - (Specification) (root, query, cb) -> cb.equal( - root.get(DistributionSetMetadata_.distributionSet).get(DistributionSet_.id), distributionSetId), - pageable); + return convertMdPage(distributionSetMetadataRepository + .findAll((Specification) (root, query, cb) -> cb.equal( + root.get(JpaDistributionSetMetadata_.distributionSet).get(JpaDistributionSet_.id), + distributionSetId), pageable)); } @Override public Page findDistributionSetMetadataByDistributionSetId(final Long distributionSetId, - final Specification spec, final Pageable pageable) { - return distributionSetMetadataRepository - .findAll( - (Specification) (root, query, - cb) -> cb.and( - cb.equal(root.get(DistributionSetMetadata_.distributionSet) - .get(DistributionSet_.id), distributionSetId), - spec.toPredicate(root, query, cb)), - pageable); + final String rsqlParam, final Pageable pageable) { + + final Specification spec = RSQLUtility.parse(rsqlParam, + DistributionSetMetadataFields.class); + + return convertMdPage( + distributionSetMetadataRepository + .findAll((Specification) (root, query, cb) -> cb.and( + cb.equal(root.get(JpaDistributionSetMetadata_.distributionSet) + .get(JpaDistributionSet_.id), distributionSetId), + spec.toPredicate(root, query, cb)), pageable)); + } + + private static Page convertMdPage(final Page findAll) { + return new PageImpl<>(new ArrayList<>(findAll.getContent())); } @Override @@ -518,19 +561,19 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { @Override public DistributionSet findDistributionSetByAction(final Action action) { - return distributionSetRepository.findByAction(action); + return distributionSetRepository.findByAction((JpaAction) action); } @Override public boolean isDistributionSetInUse(final DistributionSet distributionSet) { - return actionRepository.countByDistributionSet(distributionSet) > 0; + return actionRepository.countByDistributionSet((JpaDistributionSet) distributionSet) > 0; } - private static List> buildDistributionSetSpecifications( + private static List> buildDistributionSetSpecifications( final DistributionSetFilter distributionSetFilter) { - final List> specList = new ArrayList<>(); + final List> specList = new ArrayList<>(); - Specification spec; + Specification spec; if (null != distributionSetFilter.getIsComplete()) { spec = DistributionSetSpecification.isCompleted(distributionSetFilter.getIsComplete()); @@ -568,7 +611,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { return specList; } - private void checkDistributionSetSoftwareModulesIsAllowedToModify(final DistributionSet distributionSet, + private void checkDistributionSetSoftwareModulesIsAllowedToModify(final JpaDistributionSet distributionSet, final Set softwareModules) { if (!new HashSet(distributionSet.getModules()).equals(softwareModules) && actionRepository.countByDistributionSet(distributionSet) > 0) { @@ -602,8 +645,8 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { * list of @link {@link Specification} * @return the page with the found {@link DistributionSet} */ - private Page findByCriteriaAPI(final Pageable pageable, - final List> specList) { + private Page findByCriteriaAPI(final Pageable pageable, + final List> specList) { if (specList == null || specList.isEmpty()) { return distributionSetRepository.findAll(pageable); @@ -627,10 +670,11 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) public List assignTag(final Collection dsIds, final DistributionSetTag tag) { - final List allDs = findDistributionSetListWithDetails(dsIds); + final List allDs = findDistributionSetListWithDetails(dsIds); allDs.forEach(ds -> ds.getTags().add(tag)); - final List save = distributionSetRepository.save(allDs); + + final List save = new ArrayList<>(distributionSetRepository.save(allDs)); afterCommit.afterCommit(() -> { @@ -646,19 +690,23 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) public List unAssignAllDistributionSetsByTag(final DistributionSetTag tag) { - return unAssignTag(tag.getAssignedToDistributionSet(), tag); + + @SuppressWarnings({ "unchecked", "rawtypes" }) + final Collection distributionSets = (Collection) tag.getAssignedToDistributionSet(); + + return new ArrayList<>(unAssignTag(distributionSets, tag)); } @Override @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) public DistributionSet unAssignTag(final Long dsId, final DistributionSetTag distributionSetTag) { - final List allDs = findDistributionSetListWithDetails(Arrays.asList(dsId)); - final List unAssignTag = unAssignTag(allDs, distributionSetTag); + final List allDs = findDistributionSetListWithDetails(Arrays.asList(dsId)); + final List unAssignTag = unAssignTag(allDs, distributionSetTag); return unAssignTag.isEmpty() ? null : unAssignTag.get(0); } - private List unAssignTag(final Collection distributionSets, + private List unAssignTag(final Collection distributionSets, final DistributionSetTag tag) { distributionSets.forEach(ds -> ds.getTags().remove(tag)); return distributionSetRepository.save(distributionSets); @@ -685,4 +733,16 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { final DistributionSetTag tag) { return toggleTagAssignment(sets.stream().map(ds -> ds.getId()).collect(Collectors.toList()), tag.getName()); } + + @Override + @Transactional(propagation = Propagation.SUPPORTS) + public DistributionSetType generateDistributionSetType() { + return new JpaDistributionSetType(); + } + + @Override + @Transactional(propagation = Propagation.SUPPORTS) + public DistributionSet generateDistributionSet() { + return new JpaDistributionSet(); + } } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaReportManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaReportManagement.java index 523f91374..bada97a7b 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaReportManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaReportManagement.java @@ -34,13 +34,13 @@ import org.eclipse.hawkbit.report.model.DataReportSeriesItem; import org.eclipse.hawkbit.report.model.InnerOuterDataReportSeries; import org.eclipse.hawkbit.report.model.SeriesTime; import org.eclipse.hawkbit.repository.ReportManagement; -import org.eclipse.hawkbit.repository.model.DistributionSet; -import org.eclipse.hawkbit.repository.model.DistributionSet_; -import org.eclipse.hawkbit.repository.model.Target; -import org.eclipse.hawkbit.repository.model.TargetInfo; -import org.eclipse.hawkbit.repository.model.TargetInfo_; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet_; +import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; +import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo; +import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo_; +import org.eclipse.hawkbit.repository.jpa.model.JpaTarget_; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; -import org.eclipse.hawkbit.repository.model.Target_; import org.eclipse.hawkbit.tenancy.TenantAware; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -88,13 +88,13 @@ public class JpaReportManagement implements ReportManagement { final CriteriaBuilder cb = entityManager.getCriteriaBuilder(); final CriteriaQuery query = cb.createQuery(Object[].class); - final Root targetRoot = query.from(Target.class); - final Join targetInfo = targetRoot.join(Target_.targetInfo); - final Expression countColumn = cb.count(targetInfo.get(TargetInfo_.targetId)); + final Root targetRoot = query.from(JpaTarget.class); + final Join targetInfo = targetRoot.join(JpaTarget_.targetInfo); + final Expression countColumn = cb.count(targetInfo.get(JpaTargetInfo_.targetId)); final CriteriaQuery multiselect = query - .multiselect(targetInfo.get(TargetInfo_.updateStatus), countColumn) - .groupBy(targetInfo.get(TargetInfo_.updateStatus)) - .orderBy(cb.desc(targetInfo.get(TargetInfo_.updateStatus))); + .multiselect(targetInfo.get(JpaTargetInfo_.updateStatus), countColumn) + .groupBy(targetInfo.get(JpaTargetInfo_.updateStatus)) + .orderBy(cb.desc(targetInfo.get(JpaTargetInfo_.updateStatus))); // | col1 | col2 | // | U_STATUS | COUNT | @@ -114,16 +114,17 @@ public class JpaReportManagement implements ReportManagement { // top X entries distribution usage final CriteriaBuilder cbTopX = entityManager.getCriteriaBuilder(); final CriteriaQuery queryTopX = cbTopX.createQuery(Object[].class); - final Root rootTopX = queryTopX.from(DistributionSet.class); - final ListJoin joinTopX = rootTopX.join(DistributionSet_.assignedToTargets, + final Root rootTopX = queryTopX.from(JpaDistributionSet.class); + final ListJoin joinTopX = rootTopX.join(JpaDistributionSet_.assignedToTargets, JoinType.LEFT); final Expression countColumn = cbTopX.count(joinTopX); // top x usage query final CriteriaQuery groupBy = queryTopX - .multiselect(rootTopX.get(DistributionSet_.name), rootTopX.get(DistributionSet_.version), countColumn) - .where(cbTopX.equal(rootTopX.get(DistributionSet_.deleted), false)) - .groupBy(rootTopX.get(DistributionSet_.name), rootTopX.get(DistributionSet_.version)) - .orderBy(cbTopX.desc(countColumn), cbTopX.asc(rootTopX.get(DistributionSet_.name))); + .multiselect(rootTopX.get(JpaDistributionSet_.name), rootTopX.get(JpaDistributionSet_.version), + countColumn) + .where(cbTopX.equal(rootTopX.get(JpaDistributionSet_.deleted), false)) + .groupBy(rootTopX.get(JpaDistributionSet_.name), rootTopX.get(JpaDistributionSet_.version)) + .orderBy(cbTopX.desc(countColumn), cbTopX.asc(rootTopX.get(JpaDistributionSet_.name))); // | col1 | col2 | col3 | // | NAME | VER | COUNT | final List resultListTop = entityManager.createQuery(groupBy).getResultList(); @@ -138,16 +139,17 @@ public class JpaReportManagement implements ReportManagement { // top X entries distribution usage final CriteriaBuilder cbTopX = entityManager.getCriteriaBuilder(); final CriteriaQuery queryTopX = cbTopX.createQuery(Object[].class); - final Root rootTopX = queryTopX.from(DistributionSet.class); - final ListJoin joinTopX = rootTopX.join(DistributionSet_.installedAtTargets, - JoinType.LEFT); + final Root rootTopX = queryTopX.from(JpaDistributionSet.class); + final ListJoin joinTopX = rootTopX + .join(JpaDistributionSet_.installedAtTargets, JoinType.LEFT); final Expression countColumn = cbTopX.count(joinTopX); // top x usage query final CriteriaQuery groupBy = queryTopX - .multiselect(rootTopX.get(DistributionSet_.name), rootTopX.get(DistributionSet_.version), countColumn) - .where(cbTopX.equal(rootTopX.get(DistributionSet_.deleted), false)) - .groupBy(rootTopX.get(DistributionSet_.name), rootTopX.get(DistributionSet_.version)) - .orderBy(cbTopX.desc(countColumn), cbTopX.asc(rootTopX.get(DistributionSet_.name))); + .multiselect(rootTopX.get(JpaDistributionSet_.name), rootTopX.get(JpaDistributionSet_.version), + countColumn) + .where(cbTopX.equal(rootTopX.get(JpaDistributionSet_.deleted), false)) + .groupBy(rootTopX.get(JpaDistributionSet_.name), rootTopX.get(JpaDistributionSet_.version)) + .orderBy(cbTopX.desc(countColumn), cbTopX.asc(rootTopX.get(JpaDistributionSet_.name))); // | col1 | col2 | col3 | // | NAME | VER | COUNT | final List resultListTop = entityManager.createQuery(groupBy).getResultList(); @@ -213,6 +215,7 @@ public class JpaReportManagement implements ReportManagement { final LocalDateTime from, final LocalDateTime to) { final Query createNativeQuery = entityManager .createNativeQuery(getFeedbackReceivedQueryTemplate(dateType, from, to)); + @SuppressWarnings("unchecked") final List resultList = createNativeQuery.getResultList(); final List> reportItems = resultList.stream() @@ -275,15 +278,15 @@ public class JpaReportManagement implements ReportManagement { // count select statement final CriteriaQuery countSelect = cb.createQuery(Long.class); - final Root countSelectRoot = countSelect.from(Target.class); - final Join targetInfoJoin = countSelectRoot.join(Target_.targetInfo); + final Root countSelectRoot = countSelect.from(JpaTarget.class); + final Join targetInfoJoin = countSelectRoot.join(JpaTarget_.targetInfo); countSelect.select(cb.count(countSelectRoot)); if (start != null && end != null) { - countSelect.where(cb.between(targetInfoJoin.get(TargetInfo_.lastTargetQuery), start, end)); + countSelect.where(cb.between(targetInfoJoin.get(JpaTargetInfo_.lastTargetQuery), start, end)); } else if (from == null && to != null) { - countSelect.where(cb.lessThanOrEqualTo(targetInfoJoin.get(TargetInfo_.lastTargetQuery), end)); + countSelect.where(cb.lessThanOrEqualTo(targetInfoJoin.get(JpaTargetInfo_.lastTargetQuery), end)); } else { - countSelect.where(cb.isNull(targetInfoJoin.get(TargetInfo_.lastTargetQuery))); + countSelect.where(cb.isNull(targetInfoJoin.get(JpaTargetInfo_.lastTargetQuery))); } return countSelect; } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutGroupManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutGroupManagement.java index b7ced5511..b3ea8fb74 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutGroupManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutGroupManagement.java @@ -8,6 +8,7 @@ */ package org.eclipse.hawkbit.repository.jpa; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -20,28 +21,36 @@ import javax.persistence.criteria.JoinType; import javax.persistence.criteria.ListJoin; import javax.persistence.criteria.Root; +import org.eclipse.hawkbit.repository.RolloutGroupFields; import org.eclipse.hawkbit.repository.RolloutGroupManagement; +import org.eclipse.hawkbit.repository.TargetFields; +import org.eclipse.hawkbit.repository.jpa.model.JpaAction; +import org.eclipse.hawkbit.repository.jpa.model.JpaAction_; +import org.eclipse.hawkbit.repository.jpa.model.JpaRollout.RolloutStatus; +import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup; +import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup_; +import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; +import org.eclipse.hawkbit.repository.jpa.model.JpaTarget_; +import org.eclipse.hawkbit.repository.jpa.model.RolloutTargetGroup; +import org.eclipse.hawkbit.repository.jpa.model.RolloutTargetGroup_; import org.eclipse.hawkbit.repository.model.Action; -import org.eclipse.hawkbit.repository.model.Action_; import org.eclipse.hawkbit.repository.model.Rollout; -import org.eclipse.hawkbit.repository.model.Rollout.RolloutStatus; import org.eclipse.hawkbit.repository.model.RolloutGroup; -import org.eclipse.hawkbit.repository.model.RolloutGroup_; -import org.eclipse.hawkbit.repository.model.RolloutTargetGroup; -import org.eclipse.hawkbit.repository.model.RolloutTargetGroup_; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetWithActionStatus; -import org.eclipse.hawkbit.repository.model.Target_; import org.eclipse.hawkbit.repository.model.TotalTargetCountActionStatus; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; +import org.eclipse.hawkbit.repository.rsql.RSQLUtility; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Isolation; +import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; @@ -72,20 +81,34 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement { @Override public Page findRolloutGroupsByRolloutId(final Long rolloutId, final Pageable page) { - return rolloutGroupRepository.findByRolloutId(rolloutId, page); + return convertPage(rolloutGroupRepository.findByRolloutId(rolloutId, page)); + } + + private static Page convertPage(final Slice findAll) { + return new PageImpl<>(new ArrayList<>(findAll.getContent())); + } + + private static Page convertTPage(final Page findAll) { + return new PageImpl<>(new ArrayList<>(findAll.getContent())); } @Override - public Page findRolloutGroupsAll(final Rollout rollout, - final Specification specification, final Pageable page) { - return rolloutGroupRepository.findAll((root, query, criteriaBuilder) -> criteriaBuilder.and( - criteriaBuilder.equal(root.get(RolloutGroup_.rollout), rollout), - specification.toPredicate(root, query, criteriaBuilder)), page); + public Page findRolloutGroupsAll(final Rollout rollout, final String rsqlParam, final Pageable page) { + + final Specification specification = RSQLUtility.parse(rsqlParam, RolloutGroupFields.class); + + return convertPage( + rolloutGroupRepository + .findAll( + (root, query, criteriaBuilder) -> criteriaBuilder.and( + criteriaBuilder.equal(root.get(JpaRolloutGroup_.rollout), rollout), + specification.toPredicate(root, query, criteriaBuilder)), + page)); } @Override public Page findAllRolloutGroupsWithDetailedStatus(final Long rolloutId, final Pageable page) { - final Page rolloutGroups = rolloutGroupRepository.findByRolloutId(rolloutId, page); + final Page rolloutGroups = rolloutGroupRepository.findByRolloutId(rolloutId, page); final List rolloutGroupIds = rolloutGroups.getContent().stream().map(rollout -> rollout.getId()) .collect(Collectors.toList()); final Map> allStatesForRollout = getStatusCountItemForRolloutGroup( @@ -97,7 +120,7 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement { rolloutGroup.setTotalTargetCountStatus(totalTargetCountStatus); } - return rolloutGroups; + return convertPage(rolloutGroups); } @Override @@ -121,13 +144,16 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement { } @Override - public Page findRolloutGroupTargets(final RolloutGroup rolloutGroup, - final Specification specification, final Pageable page) { - return targetRepository.findAll((root, query, criteriaBuilder) -> { - final ListJoin rolloutTargetJoin = root.join(Target_.rolloutTargetGroup); - return criteriaBuilder.and(specification.toPredicate(root, query, criteriaBuilder), + public Page findRolloutGroupTargets(final RolloutGroup rolloutGroup, final String rsqlParam, + final Pageable page) { + + final Specification rsqlSpecification = RSQLUtility.parse(rsqlParam, TargetFields.class); + + return convertTPage(targetRepository.findAll((root, query, criteriaBuilder) -> { + final ListJoin rolloutTargetJoin = root.join(JpaTarget_.rolloutTargetGroup); + return criteriaBuilder.and(rsqlSpecification.toPredicate(root, query, criteriaBuilder), criteriaBuilder.equal(rolloutTargetJoin.get(RolloutTargetGroup_.rolloutGroup), rolloutGroup)); - }, page); + }, page)); } @Override @@ -138,7 +164,7 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement { // stored in the #TargetRolloutGroup. return targetRepository.findByRolloutTargetGroupRolloutGroupId(rolloutGroup.getId(), page); } - return targetRepository.findByActionsRolloutGroup(rolloutGroup, page); + return targetRepository.findByActionsRolloutGroup((JpaRolloutGroup) rolloutGroup, page); } private static boolean isRolloutStatusReady(final RolloutGroup rolloutGroup) { @@ -154,8 +180,8 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement { final CriteriaQuery countQuery = cb.createQuery(Long.class); final Root targetRoot = query.distinct(true).from(RolloutTargetGroup.class); - final Join targetJoin = targetRoot.join(RolloutTargetGroup_.target); - final ListJoin actionJoin = targetRoot.join(RolloutTargetGroup_.actions, + final Join targetJoin = targetRoot.join(RolloutTargetGroup_.target); + final ListJoin actionJoin = targetRoot.join(RolloutTargetGroup_.actions, JoinType.LEFT); final Root countQueryFrom = countQuery.distinct(true).from(RolloutTargetGroup.class); @@ -165,7 +191,7 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement { .where(cb.equal(countQueryFrom.get(RolloutTargetGroup_.rolloutGroup), rolloutGroup)); final Long totalCount = entityManager.createQuery(countQuery).getSingleResult(); - final CriteriaQuery multiselect = query.multiselect(targetJoin, actionJoin.get(Action_.status)) + final CriteriaQuery multiselect = query.multiselect(targetJoin, actionJoin.get(JpaAction_.status)) .where(cb.equal(targetRoot.get(RolloutTargetGroup_.rolloutGroup), rolloutGroup)); final List targetWithActionStatus = entityManager.createQuery(multiselect) .setFirstResult(pageRequest.getOffset()).setMaxResults(pageRequest.getPageSize()).getResultList() @@ -173,4 +199,10 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement { .collect(Collectors.toList()); return new PageImpl<>(targetWithActionStatus, pageRequest, totalCount); } + + @Override + @Transactional(propagation = Propagation.SUPPORTS) + public RolloutGroup generateRolloutGroup() { + return new JpaRolloutGroup(); + } } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java index e4636f890..ec13c4f29 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java @@ -8,6 +8,7 @@ */ package org.eclipse.hawkbit.repository.jpa; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Set; @@ -19,24 +20,28 @@ import javax.persistence.EntityManager; import org.eclipse.hawkbit.cache.CacheWriteNotify; import org.eclipse.hawkbit.repository.DeploymentManagement; +import org.eclipse.hawkbit.repository.RolloutFields; import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.exception.RolloutIllegalStateException; +import org.eclipse.hawkbit.repository.jpa.model.JpaRollout; +import org.eclipse.hawkbit.repository.jpa.model.JpaRollout.RolloutStatus; +import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup; +import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup.RolloutGroupConditions; +import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup.RolloutGroupErrorCondition; +import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup.RolloutGroupStatus; +import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup.RolloutGroupSuccessCondition; +import org.eclipse.hawkbit.repository.jpa.model.JpaRollout_; +import org.eclipse.hawkbit.repository.jpa.model.RolloutTargetGroup; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.ActionType; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Rollout; -import org.eclipse.hawkbit.repository.model.Rollout.RolloutStatus; import org.eclipse.hawkbit.repository.model.RolloutGroup; -import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupConditions; -import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupErrorCondition; -import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupStatus; -import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupSuccessCondition; -import org.eclipse.hawkbit.repository.model.RolloutTargetGroup; -import org.eclipse.hawkbit.repository.model.Rollout_; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TotalTargetCountActionStatus; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; +import org.eclipse.hawkbit.repository.rsql.RSQLUtility; import org.eclipse.hawkbit.rollout.condition.RolloutGroupActionEvaluator; import org.eclipse.hawkbit.rollout.condition.RolloutGroupConditionEvaluator; import org.slf4j.Logger; @@ -46,6 +51,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.ApplicationContext; import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; import org.springframework.data.domain.Sort; @@ -132,15 +138,21 @@ public class JpaRolloutManagement implements RolloutManagement { @Override public Page findAll(final Pageable page) { - return rolloutRepository.findAll(page); + return convertPage(rolloutRepository.findAll(page)); + } + + private static Page convertPage(final Slice findAll) { + return new PageImpl<>(new ArrayList<>(findAll.getContent())); } @Override - public Page findAllWithDetailedStatusByPredicate(final Specification specification, - final Pageable page) { - final Page findAll = rolloutRepository.findAll(specification, page); + public Page findAllWithDetailedStatusByPredicate(final String rsqlParam, final Pageable page) { + + final Specification specification = RSQLUtility.parse(rsqlParam, RolloutFields.class); + + final Page findAll = rolloutRepository.findAll(specification, page); setRolloutStatusDetails(findAll); - return findAll; + return convertPage(findAll); } @Override @@ -153,7 +165,7 @@ public class JpaRolloutManagement implements RolloutManagement { @Modifying public Rollout createRollout(final Rollout rollout, final int amountGroup, final RolloutGroupConditions conditions) { - final Rollout savedRollout = createRollout(rollout, amountGroup); + final JpaRollout savedRollout = createRollout((JpaRollout) rollout, amountGroup); return createRolloutGroups(amountGroup, conditions, savedRollout); } @@ -162,7 +174,7 @@ public class JpaRolloutManagement implements RolloutManagement { @Modifying public Rollout createRolloutAsync(final Rollout rollout, final int amountGroup, final RolloutGroupConditions conditions) { - final Rollout savedRollout = createRollout(rollout, amountGroup); + final JpaRollout savedRollout = createRollout((JpaRollout) rollout, amountGroup); creatingRollouts.add(savedRollout.getName()); // need to flush the entity manager here to get the ID of the rollout, // because entity manager is set to FlushMode#Auto, entitymanager will @@ -182,7 +194,7 @@ public class JpaRolloutManagement implements RolloutManagement { return savedRollout; } - private Rollout createRollout(final Rollout rollout, final int amountGroup) { + private JpaRollout createRollout(final JpaRollout rollout, final int amountGroup) { verifyRolloutGroupParameter(amountGroup); final Long totalTargets = targetManagement.countTargetByTargetFilterQuery(rollout.getTargetFilterQuery()); rollout.setTotalTargets(totalTargets.longValue()); @@ -198,7 +210,7 @@ public class JpaRolloutManagement implements RolloutManagement { } private Rollout createRolloutGroupsInNewTransaction(final int amountOfGroups, - final RolloutGroupConditions conditions, final Rollout savedRollout) { + final RolloutGroupConditions conditions, final JpaRollout savedRollout) { final DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("creatingRollout"); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); @@ -221,7 +233,7 @@ public class JpaRolloutManagement implements RolloutManagement { * @return the rollout with created groups */ private Rollout createRolloutGroups(final int amountOfGroups, final RolloutGroupConditions conditions, - final Rollout savedRollout) { + final JpaRollout savedRollout) { int pageIndex = 0; int groupIndex = 0; final Long totalCount = savedRollout.getTotalTargets(); @@ -237,7 +249,7 @@ public class JpaRolloutManagement implements RolloutManagement { while (pageIndex < totalCount) { groupIndex++; final String nameAndDesc = "group-" + groupIndex; - final RolloutGroup group = new RolloutGroup(); + final JpaRolloutGroup group = new JpaRolloutGroup(); group.setName(nameAndDesc); group.setDescription(nameAndDesc); group.setRollout(savedRollout); @@ -272,7 +284,7 @@ public class JpaRolloutManagement implements RolloutManagement { @Transactional(isolation = Isolation.READ_UNCOMMITTED) @Modifying public Rollout startRollout(final Rollout rollout) { - final Rollout mergedRollout = entityManager.merge(rollout); + final JpaRollout mergedRollout = entityManager.merge((JpaRollout) rollout); checkIfRolloutCanStarted(rollout, mergedRollout); return doStartRollout(mergedRollout); } @@ -281,10 +293,10 @@ public class JpaRolloutManagement implements RolloutManagement { @Transactional(isolation = Isolation.READ_UNCOMMITTED) @Modifying public Rollout startRolloutAsync(final Rollout rollout) { - final Rollout mergedRollout = entityManager.merge(rollout); + final JpaRollout mergedRollout = entityManager.merge((JpaRollout) rollout); checkIfRolloutCanStarted(rollout, mergedRollout); mergedRollout.setStatus(RolloutStatus.STARTING); - final Rollout updatedRollout = rolloutRepository.save(mergedRollout); + final JpaRollout updatedRollout = rolloutRepository.save(mergedRollout); startingRollouts.add(updatedRollout.getName()); executor.execute(() -> { try { @@ -303,13 +315,13 @@ public class JpaRolloutManagement implements RolloutManagement { } - private Rollout doStartRollout(final Rollout rollout) { + private Rollout doStartRollout(final JpaRollout rollout) { final DistributionSet distributionSet = rollout.getDistributionSet(); final ActionType actionType = rollout.getActionType(); final long forceTime = rollout.getForcedTime(); - final List rolloutGroups = rolloutGroupRepository.findByRolloutOrderByIdAsc(rollout); + final List rolloutGroups = rolloutGroupRepository.findByRolloutOrderByIdAsc(rollout); for (int iGroup = 0; iGroup < rolloutGroups.size(); iGroup++) { - final RolloutGroup rolloutGroup = rolloutGroups.get(iGroup); + final JpaRolloutGroup rolloutGroup = rolloutGroups.get(iGroup); final List targetGroup = targetRepository.findByRolloutTargetGroupRolloutGroup(rolloutGroup); // firstgroup can already be started if (iGroup == 0) { @@ -336,7 +348,7 @@ public class JpaRolloutManagement implements RolloutManagement { @Transactional(isolation = Isolation.READ_UNCOMMITTED) @Modifying public void pauseRollout(final Rollout rollout) { - final Rollout mergedRollout = entityManager.merge(rollout); + final JpaRollout mergedRollout = entityManager.merge((JpaRollout) rollout); if (mergedRollout.getStatus() != RolloutStatus.RUNNING) { throw new RolloutIllegalStateException("Rollout can only be paused in state running but current state is " + rollout.getStatus().name().toLowerCase()); @@ -354,7 +366,7 @@ public class JpaRolloutManagement implements RolloutManagement { @Transactional(isolation = Isolation.READ_UNCOMMITTED) @Modifying public void resumeRollout(final Rollout rollout) { - final Rollout mergedRollout = entityManager.merge(rollout); + final JpaRollout mergedRollout = entityManager.merge((JpaRollout) rollout); if (!(RolloutStatus.PAUSED.equals(mergedRollout.getStatus()))) { throw new RolloutIllegalStateException("Rollout can only be resumed in state paused but current state is " + rollout.getStatus().name().toLowerCase()); @@ -379,13 +391,13 @@ public class JpaRolloutManagement implements RolloutManagement { return; } - final List rolloutsToCheck = rolloutRepository.findByLastCheckAndStatus(lastCheck, + final List rolloutsToCheck = rolloutRepository.findByLastCheckAndStatus(lastCheck, RolloutStatus.RUNNING); LOGGER.info("Found {} running rollouts to check", rolloutsToCheck.size()); - for (final Rollout rollout : rolloutsToCheck) { + for (final JpaRollout rollout : rolloutsToCheck) { LOGGER.debug("Checking rollout {}", rollout); - final List rolloutGroups = rolloutGroupRepository.findByRolloutAndStatus(rollout, + final List rolloutGroups = rolloutGroupRepository.findByRolloutAndStatus(rollout, RolloutGroupStatus.RUNNING); if (rolloutGroups.isEmpty()) { @@ -415,7 +427,7 @@ public class JpaRolloutManagement implements RolloutManagement { * In case this happens, set the rollout to error state. */ private void verifyStuckedRollouts() { - final List rolloutsInCreatingState = rolloutRepository.findByStatus(RolloutStatus.CREATING); + final List rolloutsInCreatingState = rolloutRepository.findByStatus(RolloutStatus.CREATING); rolloutsInCreatingState.stream().filter(rollout -> !creatingRollouts.contains(rollout.getName())) .forEach(rollout -> { LOGGER.warn( @@ -425,7 +437,7 @@ public class JpaRolloutManagement implements RolloutManagement { rolloutRepository.save(rollout); }); - final List rolloutsInStartingState = rolloutRepository.findByStatus(RolloutStatus.STARTING); + final List rolloutsInStartingState = rolloutRepository.findByStatus(RolloutStatus.STARTING); rolloutsInStartingState.stream().filter(rollout -> !startingRollouts.contains(rollout.getName())) .forEach(rollout -> { LOGGER.warn( @@ -437,8 +449,8 @@ public class JpaRolloutManagement implements RolloutManagement { } - private void executeRolloutGroups(final Rollout rollout, final List rolloutGroups) { - for (final RolloutGroup rolloutGroup : rolloutGroups) { + private void executeRolloutGroups(final JpaRollout rollout, final List rolloutGroups) { + for (final JpaRolloutGroup rolloutGroup : rolloutGroups) { // error state check, do we need to stop the whole // rollout because of error? final RolloutGroupErrorCondition errorCondition = rolloutGroup.getErrorCondition(); @@ -459,8 +471,8 @@ public class JpaRolloutManagement implements RolloutManagement { } } - private void executeLatestRolloutGroup(final Rollout rollout) { - final List latestRolloutGroup = rolloutGroupRepository + private void executeLatestRolloutGroup(final JpaRollout rollout) { + final List latestRolloutGroup = rolloutGroupRepository .findByRolloutAndStatusNotOrderByIdDesc(rollout, RolloutGroupStatus.SCHEDULED); if (latestRolloutGroup.isEmpty()) { return; @@ -478,13 +490,13 @@ public class JpaRolloutManagement implements RolloutManagement { } } - private boolean isRolloutComplete(final Rollout rollout) { + private boolean isRolloutComplete(final JpaRollout rollout) { final Long groupsActiveLeft = rolloutGroupRepository.countByRolloutAndStatusOrStatus(rollout, RolloutGroupStatus.RUNNING, RolloutGroupStatus.SCHEDULED); return groupsActiveLeft == 0; } - private boolean isRolloutGroupComplete(final Rollout rollout, final RolloutGroup rolloutGroup) { + private boolean isRolloutGroupComplete(final JpaRollout rollout, final JpaRolloutGroup rolloutGroup) { final Long actionsLeftForRollout = actionRepository .countByRolloutAndRolloutGroupAndStatusNotAndStatusNotAndStatusNot(rollout, rolloutGroup, Action.Status.ERROR, Action.Status.FINISHED, Action.Status.CANCELED); @@ -543,22 +555,22 @@ public class JpaRolloutManagement implements RolloutManagement { return rolloutRepository.count(likeNameOrDescription(searchText)); } - private static Specification likeNameOrDescription(final String searchText) { + private static Specification likeNameOrDescription(final String searchText) { return (rolloutRoot, query, criteriaBuilder) -> { final String searchTextToLower = searchText.toLowerCase(); return criteriaBuilder.or( - criteriaBuilder.like(criteriaBuilder.lower(rolloutRoot.get(Rollout_.name)), searchTextToLower), - criteriaBuilder.like(criteriaBuilder.lower(rolloutRoot.get(Rollout_.description)), + criteriaBuilder.like(criteriaBuilder.lower(rolloutRoot.get(JpaRollout_.name)), searchTextToLower), + criteriaBuilder.like(criteriaBuilder.lower(rolloutRoot.get(JpaRollout_.description)), searchTextToLower)); }; } @Override public Slice findRolloutByFilters(final Pageable pageable, final String searchText) { - final Specification specs = likeNameOrDescription(searchText); - final Slice findAll = criteriaNoCountDao.findAll(specs, pageable, Rollout.class); + final Specification specs = likeNameOrDescription(searchText); + final Slice findAll = criteriaNoCountDao.findAll(specs, pageable, JpaRollout.class); setRolloutStatusDetails(findAll); - return findAll; + return convertPage(findAll); } @Override @@ -579,7 +591,7 @@ public class JpaRolloutManagement implements RolloutManagement { @Modifying public Rollout updateRollout(final Rollout rollout) { Assert.notNull(rollout.getId()); - return rolloutRepository.save(rollout); + return rolloutRepository.save((JpaRollout) rollout); } /** @@ -593,9 +605,9 @@ public class JpaRolloutManagement implements RolloutManagement { */ @Override public Page findAllRolloutsWithDetailedStatus(final Pageable page) { - final Page rollouts = findAll(page); + final Page rollouts = rolloutRepository.findAll(page); setRolloutStatusDetails(rollouts); - return rollouts; + return convertPage(rollouts); } @@ -615,7 +627,7 @@ public class JpaRolloutManagement implements RolloutManagement { return resultList.stream().collect(Collectors.groupingBy(TotalTargetCountActionStatus::getId)); } - private void setRolloutStatusDetails(final Slice rollouts) { + private void setRolloutStatusDetails(final Slice rollouts) { final List rolloutIds = rollouts.getContent().stream().map(rollout -> rollout.getId()) .collect(Collectors.toList()); final Map> allStatesForRollout = getStatusCountItemForRollout( @@ -648,4 +660,10 @@ public class JpaRolloutManagement implements RolloutManagement { // calculate threshold return ((float) finished / (float) totalGroup) * 100; } + + @Override + @Transactional(propagation = Propagation.SUPPORTS) + public Rollout generateRollout() { + return new JpaRollout(); + } } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java index 3f25dff29..7ea7e46be 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java @@ -13,6 +13,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; +import java.util.LinkedList; import java.util.List; import java.util.Set; import java.util.stream.Collectors; @@ -27,23 +28,32 @@ import javax.persistence.criteria.Root; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; import org.eclipse.hawkbit.repository.ArtifactManagement; import org.eclipse.hawkbit.repository.SoftwareManagement; +import org.eclipse.hawkbit.repository.SoftwareModuleFields; +import org.eclipse.hawkbit.repository.SoftwareModuleMetadataFields; +import org.eclipse.hawkbit.repository.SoftwareModuleTypeFields; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet_; +import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; +import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleMetadata; +import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleMetadata_; +import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType; +import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule_; +import org.eclipse.hawkbit.repository.jpa.model.SwMetadataCompositeKey; +import org.eclipse.hawkbit.repository.jpa.specifications.SoftwareModuleSpecification; +import org.eclipse.hawkbit.repository.jpa.specifications.SpecificationsBuilder; import org.eclipse.hawkbit.repository.model.CustomSoftwareModule; import org.eclipse.hawkbit.repository.model.DistributionSet; -import org.eclipse.hawkbit.repository.model.DistributionSet_; import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata; -import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata_; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; -import org.eclipse.hawkbit.repository.model.SoftwareModule_; -import org.eclipse.hawkbit.repository.model.SwMetadataCompositeKey; -import org.eclipse.hawkbit.repository.specifications.SoftwareModuleSpecification; -import org.eclipse.hawkbit.repository.specifications.SpecificationsBuilder; +import org.eclipse.hawkbit.repository.rsql.RSQLUtility; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.AuditorAware; import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; import org.springframework.data.domain.SliceImpl; @@ -52,6 +62,7 @@ import org.springframework.data.jpa.repository.Modifying; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Isolation; +import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; @@ -100,7 +111,7 @@ public class JpaSoftwareManagement implements SoftwareManagement { public SoftwareModule updateSoftwareModule(final SoftwareModule sm) { checkNotNull(sm.getId()); - final SoftwareModule module = softwareModuleRepository.findOne(sm.getId()); + final JpaSoftwareModule module = softwareModuleRepository.findOne(sm.getId()); boolean updated = false; if (null == sm.getDescription() || !sm.getDescription().equals(module.getDescription())) { @@ -121,7 +132,7 @@ public class JpaSoftwareManagement implements SoftwareManagement { public SoftwareModuleType updateSoftwareModuleType(final SoftwareModuleType sm) { checkNotNull(sm.getId()); - final SoftwareModuleType type = softwareModuleTypeRepository.findOne(sm.getId()); + final JpaSoftwareModuleType type = softwareModuleTypeRepository.findOne(sm.getId()); boolean updated = false; if (sm.getDescription() != null && !sm.getDescription().equals(type.getDescription())) { @@ -142,7 +153,7 @@ public class JpaSoftwareManagement implements SoftwareManagement { if (null != swModule.getId()) { throw new EntityAlreadyExistsException(); } - return softwareModuleRepository.save(swModule); + return softwareModuleRepository.save((JpaSoftwareModule) swModule); } @Override @@ -155,30 +166,40 @@ public class JpaSoftwareManagement implements SoftwareManagement { } }); - return softwareModuleRepository.save(swModules); + @SuppressWarnings({ "unchecked", "rawtypes" }) + final Collection jpaCast = (Collection) swModules; + return new ArrayList<>(softwareModuleRepository.save(jpaCast)); } @Override public Slice findSoftwareModulesByType(final Pageable pageable, final SoftwareModuleType type) { - final List> specList = new ArrayList<>(); + final List> specList = new LinkedList<>(); - Specification spec = SoftwareModuleSpecification.equalType(type); + Specification spec = SoftwareModuleSpecification.equalType((JpaSoftwareModuleType) type); specList.add(spec); spec = SoftwareModuleSpecification.isDeletedFalse(); specList.add(spec); - return findSwModuleByCriteriaAPI(pageable, specList); + return convertSmPage(findSwModuleByCriteriaAPI(pageable, specList)); + } + + private static Page convertSmPage(final Slice findAll) { + return new PageImpl<>(new ArrayList<>(findAll.getContent())); + } + + private static Page convertSmMdPage(final Slice findAll) { + return new PageImpl<>(new ArrayList<>(findAll.getContent())); } @Override public Long countSoftwareModulesByType(final SoftwareModuleType type) { - final List> specList = new ArrayList<>(); + final List> specList = new ArrayList<>(); - Specification spec = SoftwareModuleSpecification.equalType(type); + Specification spec = SoftwareModuleSpecification.equalType((JpaSoftwareModuleType) type); specList.add(spec); spec = SoftwareModuleSpecification.isDeletedFalse(); @@ -196,24 +217,24 @@ public class JpaSoftwareManagement implements SoftwareManagement { public SoftwareModule findSoftwareModuleByNameAndVersion(final String name, final String version, final SoftwareModuleType type) { - return softwareModuleRepository.findOneByNameAndVersionAndType(name, version, type); + return softwareModuleRepository.findOneByNameAndVersionAndType(name, version, (JpaSoftwareModuleType) type); } - private boolean isUnassigned(final SoftwareModule bsmMerged) { + private boolean isUnassigned(final JpaSoftwareModule bsmMerged) { return distributionSetRepository.findByModules(bsmMerged).isEmpty(); } - private Slice findSwModuleByCriteriaAPI(final Pageable pageable, - final List> specList) { + private Slice findSwModuleByCriteriaAPI(final Pageable pageable, + final List> specList) { return criteriaNoCountDao.findAll(SpecificationsBuilder.combineWithAnd(specList), pageable, - SoftwareModule.class); + JpaSoftwareModule.class); } - private Long countSwModuleByCriteriaAPI(final List> specList) { + private Long countSwModuleByCriteriaAPI(final List> specList) { return softwareModuleRepository.count(SpecificationsBuilder.combineWithAnd(specList)); } - private void deleteGridFsArtifacts(final SoftwareModule swModule) { + private void deleteGridFsArtifacts(final JpaSoftwareModule swModule) { for (final LocalArtifact localArtifact : swModule.getLocalArtifacts()) { artifactManagement.deleteLocalArtifact(localArtifact); } @@ -223,7 +244,7 @@ public class JpaSoftwareManagement implements SoftwareManagement { @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) public void deleteSoftwareModules(final Collection ids) { - final List swModulesToDelete = softwareModuleRepository.findByIdIn(ids); + final List swModulesToDelete = softwareModuleRepository.findByIdIn(ids); final Set assignedModuleIds = new HashSet<>(); swModulesToDelete.forEach(swModule -> { @@ -253,29 +274,29 @@ public class JpaSoftwareManagement implements SoftwareManagement { @Override public Slice findSoftwareModulesAll(final Pageable pageable) { - final List> specList = new ArrayList<>(); + final List> specList = new ArrayList<>(); - Specification spec = SoftwareModuleSpecification.isDeletedFalse(); + Specification spec = SoftwareModuleSpecification.isDeletedFalse(); specList.add(spec); spec = (root, query, cb) -> { if (!query.getResultType().isAssignableFrom(Long.class)) { - root.fetch(SoftwareModule_.type); + root.fetch(JpaSoftwareModule_.type); } return cb.conjunction(); }; specList.add(spec); - return findSwModuleByCriteriaAPI(pageable, specList); + return convertSmPage(findSwModuleByCriteriaAPI(pageable, specList)); } @Override public Long countSoftwareModulesAll() { - final List> specList = new ArrayList<>(); + final List> specList = new ArrayList<>(); - final Specification spec = SoftwareModuleSpecification.isDeletedFalse(); + final Specification spec = SoftwareModuleSpecification.isDeletedFalse(); specList.add(spec); return countSwModuleByCriteriaAPI(specList); @@ -287,30 +308,38 @@ public class JpaSoftwareManagement implements SoftwareManagement { } @Override - public Page findSoftwareModulesByPredicate(final Specification spec, - final Pageable pageable) { - return softwareModuleRepository.findAll(spec, pageable); + public Page findSoftwareModulesByPredicate(final String rsqlParam, final Pageable pageable) { + final Specification spec = RSQLUtility.parse(rsqlParam, SoftwareModuleFields.class); + + return convertSmPage(softwareModuleRepository.findAll(spec, pageable)); } @Override - public Page findSoftwareModuleTypesByPredicate(final Specification spec, + public Page findSoftwareModuleTypesByPredicate(final String rsqlParam, final Pageable pageable) { - return softwareModuleTypeRepository.findAll(spec, pageable); + + final Specification spec = RSQLUtility.parse(rsqlParam, SoftwareModuleTypeFields.class); + + return convertSmTPage(softwareModuleTypeRepository.findAll(spec, pageable)); + } + + private static Page convertSmTPage(final Slice findAll) { + return new PageImpl<>(new ArrayList<>(findAll.getContent())); } @Override @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) public List findSoftwareModulesById(final Collection ids) { - return softwareModuleRepository.findByIdIn(ids); + return new ArrayList<>(softwareModuleRepository.findByIdIn(ids)); } @Override public Slice findSoftwareModuleByFilters(final Pageable pageable, final String searchText, final SoftwareModuleType type) { - final List> specList = new ArrayList<>(); + final List> specList = new ArrayList<>(); - Specification spec = SoftwareModuleSpecification.isDeletedFalse(); + Specification spec = SoftwareModuleSpecification.isDeletedFalse(); specList.add(spec); if (!Strings.isNullOrEmpty(searchText)) { @@ -319,50 +348,53 @@ public class JpaSoftwareManagement implements SoftwareManagement { } if (null != type) { - spec = SoftwareModuleSpecification.equalType(type); + spec = SoftwareModuleSpecification.equalType((JpaSoftwareModuleType) type); specList.add(spec); } spec = (root, query, cb) -> { if (!query.getResultType().isAssignableFrom(Long.class)) { - root.fetch(SoftwareModule_.type); + root.fetch(JpaSoftwareModule_.type); } return cb.conjunction(); }; specList.add(spec); - return findSwModuleByCriteriaAPI(pageable, specList); + return convertSmPage(findSwModuleByCriteriaAPI(pageable, specList)); } @Override public Slice findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc( final Pageable pageable, final Long orderByDistributionId, final String searchText, - final SoftwareModuleType type) { + final SoftwareModuleType ty) { + final JpaSoftwareModuleType type = (JpaSoftwareModuleType) ty; final List resultList = new ArrayList<>(); final int pageSize = pageable.getPageSize(); final CriteriaBuilder cb = entityManager.getCriteriaBuilder(); // get the assigned software modules - final CriteriaQuery assignedQuery = cb.createQuery(SoftwareModule.class); - final Root assignedRoot = assignedQuery.from(SoftwareModule.class); + final CriteriaQuery assignedQuery = cb.createQuery(JpaSoftwareModule.class); + final Root assignedRoot = assignedQuery.from(JpaSoftwareModule.class); assignedQuery.distinct(true); - final ListJoin assignedDsJoin = assignedRoot.join(SoftwareModule_.assignedTo); + final ListJoin assignedDsJoin = assignedRoot + .join(JpaSoftwareModule_.assignedTo); // build the specifications and then to predicates necessary by the // given filters final Predicate[] specPredicate = specificationsToPredicate(buildSpecificationList(searchText, type), assignedRoot, assignedQuery, cb, - cb.equal(assignedDsJoin.get(DistributionSet_.id), orderByDistributionId)); + cb.equal(assignedDsJoin.get(JpaDistributionSet_.id), orderByDistributionId)); // if we have some predicates then add it to the where clause of the // multi select assignedQuery.where(specPredicate); - assignedQuery.orderBy(cb.asc(assignedRoot.get(SoftwareModule_.name)), - cb.asc(assignedRoot.get(SoftwareModule_.version))); + assignedQuery.orderBy(cb.asc(assignedRoot.get(JpaSoftwareModule_.name)), + cb.asc(assignedRoot.get(JpaSoftwareModule_.version))); // don't page the assigned query on database, we need all assigned // software modules to filter // them out in the unassigned query - final List assignedSoftwareModules = entityManager.createQuery(assignedQuery).getResultList(); + final List assignedSoftwareModules = entityManager.createQuery(assignedQuery) + .getResultList(); // map result if (pageable.getOffset() < assignedSoftwareModules.size()) { assignedSoftwareModules @@ -375,14 +407,14 @@ public class JpaSoftwareManagement implements SoftwareManagement { } // get the unassigned software modules - final CriteriaQuery unassignedQuery = cb.createQuery(SoftwareModule.class); + final CriteriaQuery unassignedQuery = cb.createQuery(JpaSoftwareModule.class); unassignedQuery.distinct(true); - final Root unassignedRoot = unassignedQuery.from(SoftwareModule.class); + final Root unassignedRoot = unassignedQuery.from(JpaSoftwareModule.class); Predicate[] unassignedSpec; if (!assignedSoftwareModules.isEmpty()) { unassignedSpec = specificationsToPredicate(buildSpecificationList(searchText, type), unassignedRoot, - unassignedQuery, cb, cb.not(unassignedRoot.get(SoftwareModule_.id) + unassignedQuery, cb, cb.not(unassignedRoot.get(JpaSoftwareModule_.id) .in(assignedSoftwareModules.stream().map(sw -> sw.getId()).collect(Collectors.toList())))); } else { unassignedSpec = specificationsToPredicate(buildSpecificationList(searchText, type), unassignedRoot, @@ -390,9 +422,9 @@ public class JpaSoftwareManagement implements SoftwareManagement { } unassignedQuery.where(unassignedSpec); - unassignedQuery.orderBy(cb.asc(unassignedRoot.get(SoftwareModule_.name)), - cb.asc(unassignedRoot.get(SoftwareModule_.version))); - final List unassignedSoftwareModules = entityManager.createQuery(unassignedQuery) + unassignedQuery.orderBy(cb.asc(unassignedRoot.get(JpaSoftwareModule_.name)), + cb.asc(unassignedRoot.get(JpaSoftwareModule_.version))); + final List unassignedSoftwareModules = entityManager.createQuery(unassignedQuery) .setFirstResult(Math.max(0, pageable.getOffset() - assignedSoftwareModules.size())) .setMaxResults(pageSize).getResultList(); // map result @@ -401,9 +433,9 @@ public class JpaSoftwareManagement implements SoftwareManagement { return new SliceImpl<>(resultList); } - private static List> buildSpecificationList(final String searchText, - final SoftwareModuleType type) { - final List> specList = new ArrayList<>(); + private static List> buildSpecificationList(final String searchText, + final JpaSoftwareModuleType type) { + final List> specList = new ArrayList<>(); if (!Strings.isNullOrEmpty(searchText)) { specList.add(SoftwareModuleSpecification.likeNameOrVersion(searchText)); } @@ -414,8 +446,8 @@ public class JpaSoftwareManagement implements SoftwareManagement { return specList; } - private Predicate[] specificationsToPredicate(final List> specifications, - final Root root, final CriteriaQuery query, final CriteriaBuilder cb, + private Predicate[] specificationsToPredicate(final List> specifications, + final Root root, final CriteriaQuery query, final CriteriaBuilder cb, final Predicate... additionalPredicates) { final List predicates = new ArrayList<>(); specifications.forEach(spec -> predicates.add(spec.toPredicate(root, query, cb))); @@ -428,9 +460,9 @@ public class JpaSoftwareManagement implements SoftwareManagement { @Override public Long countSoftwareModuleByFilters(final String searchText, final SoftwareModuleType type) { - final List> specList = new ArrayList<>(); + final List> specList = new ArrayList<>(); - Specification spec = SoftwareModuleSpecification.isDeletedFalse(); + Specification spec = SoftwareModuleSpecification.isDeletedFalse(); specList.add(spec); if (!Strings.isNullOrEmpty(searchText)) { @@ -439,7 +471,7 @@ public class JpaSoftwareManagement implements SoftwareManagement { } if (null != type) { - spec = SoftwareModuleSpecification.equalType(type); + spec = SoftwareModuleSpecification.equalType((JpaSoftwareModuleType) type); specList.add(spec); } @@ -479,17 +511,18 @@ public class JpaSoftwareManagement implements SoftwareManagement { throw new EntityAlreadyExistsException("Given type contains an Id!"); } - return softwareModuleTypeRepository.save(type); + return softwareModuleTypeRepository.save((JpaSoftwareModuleType) type); } @Override @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) - public void deleteSoftwareModuleType(final SoftwareModuleType type) { + public void deleteSoftwareModuleType(final SoftwareModuleType ty) { + final JpaSoftwareModuleType type = (JpaSoftwareModuleType) ty; if (softwareModuleRepository.countByType(type) > 0 || distributionSetTypeRepository.countByElementsSmType(type) > 0) { - final SoftwareModuleType toDelete = entityManager.merge(type); + final JpaSoftwareModuleType toDelete = entityManager.merge(type); toDelete.setDeleted(true); softwareModuleTypeRepository.save(toDelete); } else { @@ -499,19 +532,22 @@ public class JpaSoftwareManagement implements SoftwareManagement { @Override public Page findSoftwareModuleByAssignedTo(final Pageable pageable, final DistributionSet set) { - return softwareModuleRepository.findByAssignedTo(pageable, set); + return softwareModuleRepository.findByAssignedTo(pageable, (JpaDistributionSet) set); } @Override public Page findSoftwareModuleByAssignedToAndType(final Pageable pageable, final DistributionSet set, final SoftwareModuleType type) { - return softwareModuleRepository.findByAssignedToAndType(pageable, set, type); + return softwareModuleRepository.findByAssignedToAndType(pageable, (JpaDistributionSet) set, + (JpaSoftwareModuleType) type); } @Override @Transactional(isolation = Isolation.READ_UNCOMMITTED) @Modifying - public SoftwareModuleMetadata createSoftwareModuleMetadata(final SoftwareModuleMetadata metadata) { + public SoftwareModuleMetadata createSoftwareModuleMetadata(final SoftwareModuleMetadata md) { + final JpaSoftwareModuleMetadata metadata = (JpaSoftwareModuleMetadata) md; + if (softwareModuleMetadataRepository.exists(metadata.getId())) { throwMetadataKeyAlreadyExists(metadata.getId().getKey()); } @@ -519,32 +555,36 @@ public class JpaSoftwareManagement implements SoftwareManagement { // log written because // modifying metadata is modifying the base software module itself for // auditing purposes. - entityManager.merge(metadata.getSoftwareModule()).setLastModifiedAt(-1L); + entityManager.merge((JpaSoftwareModule) metadata.getSoftwareModule()).setLastModifiedAt(-1L); return softwareModuleMetadataRepository.save(metadata); } @Override @Transactional(isolation = Isolation.READ_UNCOMMITTED) @Modifying - public List createSoftwareModuleMetadata( - final Collection metadata) { - for (final SoftwareModuleMetadata softwareModuleMetadata : metadata) { + public List createSoftwareModuleMetadata(final Collection md) { + @SuppressWarnings({ "unchecked", "rawtypes" }) + final Collection metadata = (Collection) md; + + for (final JpaSoftwareModuleMetadata softwareModuleMetadata : metadata) { checkAndThrowAlreadyExistsIfSoftwareModuleMetadataExists(softwareModuleMetadata.getId()); } - metadata.forEach(m -> entityManager.merge(m.getSoftwareModule()).setLastModifiedAt(-1L)); - return softwareModuleMetadataRepository.save(metadata); + metadata.forEach(m -> entityManager.merge((JpaSoftwareModule) m.getSoftwareModule()).setLastModifiedAt(-1L)); + return new ArrayList<>(softwareModuleMetadataRepository.save(metadata)); } @Override @Transactional(isolation = Isolation.READ_UNCOMMITTED) @Modifying - public SoftwareModuleMetadata updateSoftwareModuleMetadata(final SoftwareModuleMetadata metadata) { + public SoftwareModuleMetadata updateSoftwareModuleMetadata(final SoftwareModuleMetadata md) { + final JpaSoftwareModuleMetadata metadata = (JpaSoftwareModuleMetadata) md; + // check if exists otherwise throw entity not found exception findSoftwareModuleMetadata(metadata.getId()); // touch it to update the lock revision because we are modifying the // software module // indirectly - entityManager.merge(metadata.getSoftwareModule()).setLastModifiedAt(-1L); + entityManager.merge((JpaSoftwareModule) metadata.getSoftwareModule()).setLastModifiedAt(-1L); return softwareModuleMetadataRepository.save(metadata); } @@ -563,15 +603,18 @@ public class JpaSoftwareManagement implements SoftwareManagement { @Override public Page findSoftwareModuleMetadataBySoftwareModuleId(final Long softwareModuleId, - final Specification spec, final Pageable pageable) { - return softwareModuleMetadataRepository - .findAll( - (Specification) (root, query, - cb) -> cb.and( - cb.equal(root.get(SoftwareModuleMetadata_.softwareModule) - .get(SoftwareModule_.id), softwareModuleId), + final String rsqlParam, final Pageable pageable) { + + final Specification spec = RSQLUtility.parse(rsqlParam, + SoftwareModuleMetadataFields.class); + return convertSmMdPage( + softwareModuleMetadataRepository + .findAll( + (Specification) (root, query, cb) -> cb.and( + cb.equal(root.get(JpaSoftwareModuleMetadata_.softwareModule) + .get(JpaSoftwareModule_.id), softwareModuleId), spec.toPredicate(root, query, cb)), - pageable); + pageable)); } @Override @@ -609,4 +652,16 @@ public class JpaSoftwareManagement implements SoftwareManagement { return types.stream().map(this::createSoftwareModuleType).collect(Collectors.toList()); } + @Override + @Transactional(propagation = Propagation.SUPPORTS) + public SoftwareModuleType generateSoftwareModuleType() { + return new JpaSoftwareModuleType(); + } + + @Override + @Transactional(propagation = Propagation.SUPPORTS) + public SoftwareModule generateSoftwareModule() { + return new JpaSoftwareModule(); + } + } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java index b7a08fc2e..1acbd0f1b 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java @@ -20,6 +20,9 @@ import org.eclipse.hawkbit.report.model.SystemUsageReport; import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.repository.TenantStatsManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType; +import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType; +import org.eclipse.hawkbit.repository.jpa.model.JpaTenantMetaData; import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.repository.model.TenantMetaData; @@ -167,7 +170,7 @@ public class JpaSystemManagement implements SystemManagement { try { createInitialTenant.set(tenant); cacheManager.getCache("currentTenant").evict(currentTenantKeyGenerator().generate(null, null)); - return tenantMetaDataRepository.save(new TenantMetaData(createStandardSoftwareDataSetup(), tenant)); + return tenantMetaDataRepository.save(new JpaTenantMetaData(createStandardSoftwareDataSetup(), tenant)); } finally { createInitialTenant.remove(); } @@ -253,27 +256,26 @@ public class JpaSystemManagement implements SystemManagement { throw new EntityNotFoundException("Metadata does not exist: " + metaData.getId()); } - return tenantMetaDataRepository.save(metaData); + return tenantMetaDataRepository.save((JpaTenantMetaData) metaData); } private DistributionSetType createStandardSoftwareDataSetup() { - final SoftwareModuleType eclApp = softwareModuleTypeRepository.save(new SoftwareModuleType("application", + final SoftwareModuleType eclApp = softwareModuleTypeRepository.save(new JpaSoftwareModuleType("application", "ECL Application", "Edge Controller Linux base application type", 1)); - final SoftwareModuleType eclOs = softwareModuleTypeRepository - .save(new SoftwareModuleType("os", "ECL OS", "Edge Controller Linux operation system image type", 1)); + final SoftwareModuleType eclOs = softwareModuleTypeRepository.save( + new JpaSoftwareModuleType("os", "ECL OS", "Edge Controller Linux operation system image type", 1)); final SoftwareModuleType eclJvm = softwareModuleTypeRepository.save( - new SoftwareModuleType("runtime", "ECL JVM", "Edge Controller Linux java virtual machine type.", 1)); + new JpaSoftwareModuleType("runtime", "ECL JVM", "Edge Controller Linux java virtual machine type.", 1)); - distributionSetTypeRepository.save( - new DistributionSetType("ecl_os", "OS only", "Standard Edge Controller Linux distribution set type.") - .addMandatoryModuleType(eclOs)); + distributionSetTypeRepository.save((JpaDistributionSetType) new JpaDistributionSetType("ecl_os", "OS only", + "Standard Edge Controller Linux distribution set type.").addMandatoryModuleType(eclOs)); - distributionSetTypeRepository.save(new DistributionSetType("ecl_os_app", "OS with optional app", - "Standard Edge Controller Linux distribution set type. OS only.").addMandatoryModuleType(eclOs) - .addOptionalModuleType(eclApp)); + distributionSetTypeRepository.save((JpaDistributionSetType) new JpaDistributionSetType("ecl_os_app", + "OS with optional app", "Standard Edge Controller Linux distribution set type. OS only.") + .addMandatoryModuleType(eclOs).addOptionalModuleType(eclApp)); - return distributionSetTypeRepository - .save(new DistributionSetType("ecl_os_app_jvm", "OS with optional app and jvm", + return distributionSetTypeRepository.save( + (JpaDistributionSetType) new JpaDistributionSetType("ecl_os_app_jvm", "OS with optional app and jvm", "Standard Edge Controller Linux distribution set type. OS with optional application.") .addMandatoryModuleType(eclOs).addOptionalModuleType(eclApp) .addOptionalModuleType(eclJvm)); diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTagManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTagManagement.java index f1b885b13..4ff9c6e2b 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTagManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTagManagement.java @@ -10,6 +10,7 @@ package org.eclipse.hawkbit.repository.jpa; import static com.google.common.base.Preconditions.checkNotNull; +import java.util.ArrayList; import java.util.Collection; import java.util.LinkedList; import java.util.List; @@ -21,20 +22,26 @@ import org.eclipse.hawkbit.eventbus.event.TargetTagCreatedBulkEvent; import org.eclipse.hawkbit.eventbus.event.TargetTagDeletedEvent; import org.eclipse.hawkbit.eventbus.event.TargetTagUpdateEvent; import org.eclipse.hawkbit.executor.AfterTransactionCommitExecutor; +import org.eclipse.hawkbit.repository.TagFields; import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; -import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag; +import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; +import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag; import org.eclipse.hawkbit.repository.model.DistributionSetTag; -import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetTag; +import org.eclipse.hawkbit.repository.rsql.RSQLUtility; import org.eclipse.hawkbit.tenancy.TenantAware; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.repository.Modifying; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Isolation; +import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; @@ -86,7 +93,7 @@ public class JpaTagManagement implements TagManagement { throw new EntityAlreadyExistsException(); } - final TargetTag save = targetTagRepository.save(targetTag); + final TargetTag save = targetTagRepository.save((JpaTargetTag) targetTag); afterCommit .afterCommit(() -> eventBus.post(new TargetTagCreatedBulkEvent(tenantAware.getCurrentTenant(), save))); @@ -97,13 +104,17 @@ public class JpaTagManagement implements TagManagement { @Override @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) - public List createTargetTags(final Iterable targetTags) { + public List createTargetTags(final Collection tt) { + @SuppressWarnings({ "unchecked", "rawtypes" }) + final Collection targetTags = (Collection) tt; + targetTags.forEach(tag -> { if (tag.getId() != null) { throw new EntityAlreadyExistsException(); } }); - final List save = targetTagRepository.save(targetTags); + + final List save = new ArrayList<>(targetTagRepository.save(targetTags)); afterCommit .afterCommit(() -> eventBus.post(new TargetTagCreatedBulkEvent(tenantAware.getCurrentTenant(), save))); return save; @@ -113,10 +124,10 @@ public class JpaTagManagement implements TagManagement { @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) public void deleteTargetTag(final String targetTagName) { - final TargetTag tag = targetTagRepository.findByNameEquals(targetTagName); + final JpaTargetTag tag = targetTagRepository.findByNameEquals(targetTagName); - final List changed = new LinkedList<>(); - for (final Target target : targetRepository.findByTag(tag)) { + final List changed = new LinkedList<>(); + for (final JpaTarget target : targetRepository.findByTag(tag)) { target.getTags().remove(tag); changed.add(target); } @@ -133,12 +144,22 @@ public class JpaTagManagement implements TagManagement { @Override public List findAllTargetTags() { - return targetTagRepository.findAll(); + return new ArrayList<>(targetTagRepository.findAll()); } @Override - public Page findAllTargetTags(final Specification spec, final Pageable pageable) { - return targetTagRepository.findAll(spec, pageable); + public Page findAllTargetTags(final String rsqlParam, final Pageable pageable) { + + final Specification spec = RSQLUtility.parse(rsqlParam, TagFields.class); + return convertTPage(targetTagRepository.findAll(spec, pageable)); + } + + private static Page convertTPage(final Page findAll) { + return new PageImpl<>(new ArrayList<>(findAll.getContent())); + } + + private static Page convertDsPage(final Page findAll) { + return new PageImpl<>(new ArrayList<>(findAll.getContent())); } @Override @@ -152,7 +173,7 @@ public class JpaTagManagement implements TagManagement { public TargetTag updateTargetTag(final TargetTag targetTag) { checkNotNull(targetTag.getName()); checkNotNull(targetTag.getId()); - final TargetTag save = targetTagRepository.save(targetTag); + final TargetTag save = targetTagRepository.save((JpaTargetTag) targetTag); afterCommit.afterCommit(() -> eventBus.post(new TargetTagUpdateEvent(save))); return save; } @@ -174,7 +195,7 @@ public class JpaTagManagement implements TagManagement { throw new EntityAlreadyExistsException(); } - final DistributionSetTag save = distributionSetTagRepository.save(distributionSetTag); + final DistributionSetTag save = distributionSetTagRepository.save((JpaDistributionSetTag) distributionSetTag); afterCommit.afterCommit( () -> eventBus.post(new DistributionSetTagCreatedBulkEvent(tenantAware.getCurrentTenant(), save))); @@ -184,14 +205,17 @@ public class JpaTagManagement implements TagManagement { @Override @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) - public List createDistributionSetTags( - final Collection distributionSetTags) { + public List createDistributionSetTags(final Collection dst) { + + @SuppressWarnings({ "rawtypes", "unchecked" }) + final Collection distributionSetTags = (Collection) dst; + for (final DistributionSetTag dsTag : distributionSetTags) { if (dsTag.getId() != null) { throw new EntityAlreadyExistsException(); } } - final List save = distributionSetTagRepository.save(distributionSetTags); + final List save = new ArrayList<>(distributionSetTagRepository.save(distributionSetTags)); afterCommit.afterCommit( () -> eventBus.post(new DistributionSetTagCreatedBulkEvent(tenantAware.getCurrentTenant(), save))); @@ -202,10 +226,10 @@ public class JpaTagManagement implements TagManagement { @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) public void deleteDistributionSetTag(final String tagName) { - final DistributionSetTag tag = distributionSetTagRepository.findByNameEquals(tagName); + final JpaDistributionSetTag tag = distributionSetTagRepository.findByNameEquals(tagName); - final List changed = new LinkedList<>(); - for (final DistributionSet set : distributionSetRepository.findByTag(tag)) { + final List changed = new LinkedList<>(); + for (final JpaDistributionSet set : distributionSetRepository.findByTag(tag)) { set.getTags().remove(tag); changed.add(set); } @@ -224,7 +248,7 @@ public class JpaTagManagement implements TagManagement { public DistributionSetTag updateDistributionSetTag(final DistributionSetTag distributionSetTag) { checkNotNull(distributionSetTag.getName()); checkNotNull(distributionSetTag.getId()); - final DistributionSetTag save = distributionSetTagRepository.save(distributionSetTag); + final DistributionSetTag save = distributionSetTagRepository.save((JpaDistributionSetTag) distributionSetTag); afterCommit.afterCommit(() -> eventBus.post(new DistributionSetTagUpdateEvent(save))); return save; @@ -232,7 +256,7 @@ public class JpaTagManagement implements TagManagement { @Override public List findAllDistributionSetTags() { - return distributionSetTagRepository.findAll(); + return new ArrayList<>(distributionSetTagRepository.findAll()); } @Override @@ -247,18 +271,31 @@ public class JpaTagManagement implements TagManagement { @Override public Page findAllTargetTags(final Pageable pageReq) { - return targetTagRepository.findAll(pageReq); + return convertTPage(targetTagRepository.findAll(pageReq)); } @Override public Page findAllDistributionSetTags(final Pageable pageReq) { - return distributionSetTagRepository.findAll(pageReq); + return convertDsPage(distributionSetTagRepository.findAll(pageReq)); } @Override - public Page findAllDistributionSetTags(final Specification spec, - final Pageable pageable) { - return distributionSetTagRepository.findAll(spec, pageable); + public Page findAllDistributionSetTags(final String rsqlParam, final Pageable pageable) { + final Specification spec = RSQLUtility.parse(rsqlParam, TagFields.class); + + return convertDsPage(distributionSetTagRepository.findAll(spec, pageable)); + } + + @Override + @Transactional(propagation = Propagation.SUPPORTS) + public TargetTag generateTargetTag() { + return new JpaTargetTag(); + } + + @Override + @Transactional(propagation = Propagation.SUPPORTS) + public DistributionSetTag generateDistributionSetTag() { + return new JpaDistributionSetTag(); } } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetFilterQueryManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetFilterQueryManagement.java index a8c6b014f..5dd33b762 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetFilterQueryManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetFilterQueryManagement.java @@ -13,11 +13,13 @@ import java.util.List; import org.eclipse.hawkbit.repository.TargetFilterQueryManagement; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; +import org.eclipse.hawkbit.repository.jpa.model.JpaTargetFilterQuery; +import org.eclipse.hawkbit.repository.jpa.specifications.SpecificationsBuilder; +import org.eclipse.hawkbit.repository.jpa.specifications.TargetFilterQuerySpecification; import org.eclipse.hawkbit.repository.model.TargetFilterQuery; -import org.eclipse.hawkbit.repository.specifications.SpecificationsBuilder; -import org.eclipse.hawkbit.repository.specifications.TargetFilterQuerySpecification; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.domain.Specifications; @@ -50,7 +52,7 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme if (targetFilterQueryRepository.findByName(customTargetFilter.getName()) != null) { throw new EntityAlreadyExistsException(customTargetFilter.getName()); } - return targetFilterQueryRepository.save(customTargetFilter); + return targetFilterQueryRepository.save((JpaTargetFilterQuery) customTargetFilter); } @Override @@ -62,25 +64,29 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme @Override public Page findAllTargetFilterQuery(final Pageable pageable) { - return targetFilterQueryRepository.findAll(pageable); + return convertPage(targetFilterQueryRepository.findAll(pageable)); + } + + private static Page convertPage(final Page findAll) { + return new PageImpl<>(new ArrayList<>(findAll.getContent())); } @Override public Page findTargetFilterQueryByFilters(final Pageable pageable, final String name) { - final List> specList = new ArrayList<>(); + final List> specList = new ArrayList<>(); if (!Strings.isNullOrEmpty(name)) { specList.add(TargetFilterQuerySpecification.likeName(name)); } - return findTargetFilterQueryByCriteriaAPI(pageable, specList); + return convertPage(findTargetFilterQueryByCriteriaAPI(pageable, specList)); } - private Page findTargetFilterQueryByCriteriaAPI(final Pageable pageable, - final List> specList) { + private Page findTargetFilterQueryByCriteriaAPI(final Pageable pageable, + final List> specList) { if (specList == null || specList.isEmpty()) { return targetFilterQueryRepository.findAll(pageable); } - final Specifications specs = SpecificationsBuilder.combineWithAnd(specList); + final Specifications specs = SpecificationsBuilder.combineWithAnd(specList); return targetFilterQueryRepository.findAll(specs, pageable); } @@ -99,7 +105,7 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme @Transactional(isolation = Isolation.READ_UNCOMMITTED) public TargetFilterQuery updateTargetFilterQuery(final TargetFilterQuery targetFilterQuery) { Assert.notNull(targetFilterQuery.getId()); - return targetFilterQueryRepository.save(targetFilterQuery); + return targetFilterQueryRepository.save((JpaTargetFilterQuery) targetFilterQuery); } } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetManagement.java index 513d5b52c..0e900e655 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetManagement.java @@ -33,22 +33,25 @@ import org.eclipse.hawkbit.executor.AfterTransactionCommitExecutor; import org.eclipse.hawkbit.repository.TargetFields; import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; -import org.eclipse.hawkbit.repository.model.DistributionSet_; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet_; +import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; +import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo; +import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo_; +import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag; +import org.eclipse.hawkbit.repository.jpa.model.JpaTarget_; +import org.eclipse.hawkbit.repository.jpa.specifications.SpecificationsBuilder; +import org.eclipse.hawkbit.repository.jpa.specifications.TargetSpecifications; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetFilterQuery; import org.eclipse.hawkbit.repository.model.TargetIdName; -import org.eclipse.hawkbit.repository.model.TargetInfo; -import org.eclipse.hawkbit.repository.model.TargetInfo_; import org.eclipse.hawkbit.repository.model.TargetTag; import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; -import org.eclipse.hawkbit.repository.model.Target_; import org.eclipse.hawkbit.repository.rsql.RSQLUtility; -import org.eclipse.hawkbit.repository.specifications.SpecificationsBuilder; -import org.eclipse.hawkbit.repository.specifications.TargetSpecifications; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheEvict; import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; import org.springframework.data.domain.SliceImpl; @@ -58,6 +61,7 @@ import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.repository.Modifying; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Isolation; +import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.Assert; import org.springframework.validation.annotation.Validated; @@ -121,7 +125,8 @@ public class JpaTargetManagement implements TargetManagement { @Override public List findTargetByControllerID(final Collection controllerIDs) { - return targetRepository.findAll(TargetSpecifications.byControllerIdWithStatusAndAssignedInJoin(controllerIDs)); + return new ArrayList<>(targetRepository + .findAll(TargetSpecifications.byControllerIdWithStatusAndAssignedInJoin(controllerIDs))); } @Override @@ -134,28 +139,27 @@ public class JpaTargetManagement implements TargetManagement { // workarround - no join fetch allowed that is why we need specification // instead of query for // count() of Pageable - final Specification spec = (root, query, cb) -> { + final Specification spec = (root, query, cb) -> { if (!query.getResultType().isAssignableFrom(Long.class)) { - root.fetch(Target_.targetInfo); + root.fetch(JpaTarget_.targetInfo); } return cb.conjunction(); }; - return criteriaNoCountDao.findAll(spec, pageable, Target.class); + return convertPage(criteriaNoCountDao.findAll(spec, pageable, JpaTarget.class)); } @Override public Slice findTargetsAll(final TargetFilterQuery targetFilterQuery, final Pageable pageable) { - return findTargetsAll(RSQLUtility.parse(targetFilterQuery.getQuery(), TargetFields.class), pageable); + return findTargetsBySpec(RSQLUtility.parse(targetFilterQuery.getQuery(), TargetFields.class), pageable); } @Override - public Slice findTargetsAll(final String targetFilterQuery, final Pageable pageable) { - return findTargetsAll(RSQLUtility.parse(targetFilterQuery, TargetFields.class), pageable); + public Page findTargetsAll(final String targetFilterQuery, final Pageable pageable) { + return findTargetsBySpec(RSQLUtility.parse(targetFilterQuery, TargetFields.class), pageable); } - @Override - public Page findTargetsAll(final Specification spec, final Pageable pageable) { - return targetRepository.findAll(spec, pageable); + private Page findTargetsBySpec(final Specification spec, final Pageable pageable) { + return convertPage(targetRepository.findAll(spec, pageable)); } @Override @@ -171,16 +175,23 @@ public class JpaTargetManagement implements TargetManagement { @Transactional(isolation = Isolation.READ_UNCOMMITTED) public Target updateTarget(final Target target) { Assert.notNull(target.getId()); - target.setNew(false); - return targetRepository.save(target); + + final JpaTarget toUpdate = (JpaTarget) target; + toUpdate.setNew(false); + return targetRepository.save(toUpdate); } @Override @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) - public List updateTargets(final Iterable targets) { - targets.forEach(target -> target.setNew(false)); - return targetRepository.save(targets); + public List updateTargets(final Collection targets) { + + @SuppressWarnings({ "unchecked", "rawtypes" }) + final Collection toUpdate = (Collection) targets; + + toUpdate.forEach(target -> target.setNew(false)); + + return new ArrayList<>(targetRepository.save(toUpdate)); } @Override @@ -206,11 +217,22 @@ public class JpaTargetManagement implements TargetManagement { } @Override - public Page findTargetByAssignedDistributionSet(final Long distributionSetID, - final Specification spec, final Pageable pageReq) { - return targetRepository.findAll((Specification) (root, query, cb) -> cb.and( + public Page findTargetByAssignedDistributionSet(final Long distributionSetID, final String rsqlParam, + final Pageable pageReq) { + + final Specification spec = RSQLUtility.parse(rsqlParam, TargetFields.class); + + return convertPage(targetRepository.findAll((Specification) (root, query, cb) -> cb.and( TargetSpecifications.hasAssignedDistributionSet(distributionSetID).toPredicate(root, query, cb), - spec.toPredicate(root, query, cb)), pageReq); + spec.toPredicate(root, query, cb)), pageReq)); + } + + private static Page convertPage(final Page findAll) { + return new PageImpl<>(new ArrayList<>(findAll.getContent())); + } + + private static Slice convertPage(final Slice findAll) { + return new PageImpl<>(new ArrayList<>(findAll.getContent())); } @Override @@ -219,11 +241,14 @@ public class JpaTargetManagement implements TargetManagement { } @Override - public Page findTargetByInstalledDistributionSet(final Long distributionSetId, - final Specification spec, final Pageable pageable) { - return targetRepository.findAll((Specification) (root, query, cb) -> cb.and( + public Page findTargetByInstalledDistributionSet(final Long distributionSetId, final String rsqlParam, + final Pageable pageable) { + + final Specification spec = RSQLUtility.parse(rsqlParam, TargetFields.class); + + return convertPage(targetRepository.findAll((Specification) (root, query, cb) -> cb.and( TargetSpecifications.hasInstalledDistributionSet(distributionSetId).toPredicate(root, query, cb), - spec.toPredicate(root, query, cb)), pageable); + spec.toPredicate(root, query, cb)), pageable)); } @Override @@ -235,7 +260,7 @@ public class JpaTargetManagement implements TargetManagement { public Slice findTargetByFilters(final Pageable pageable, final Collection status, final String searchText, final Long installedOrAssignedDistributionSetId, final Boolean selectTargetWithNoTag, final String... tagNames) { - final List> specList = buildSpecificationList(status, searchText, + final List> specList = buildSpecificationList(status, searchText, installedOrAssignedDistributionSetId, selectTargetWithNoTag, true, tagNames); return findByCriteriaAPI(pageable, specList); } @@ -244,15 +269,15 @@ public class JpaTargetManagement implements TargetManagement { public Long countTargetByFilters(final Collection status, final String searchText, final Long installedOrAssignedDistributionSetId, final Boolean selectTargetWithNoTag, final String... tagNames) { - final List> specList = buildSpecificationList(status, searchText, + final List> specList = buildSpecificationList(status, searchText, installedOrAssignedDistributionSetId, selectTargetWithNoTag, true, tagNames); return countByCriteriaAPI(specList); } - private static List> buildSpecificationList(final Collection status, + private static List> buildSpecificationList(final Collection status, final String searchText, final Long installedOrAssignedDistributionSetId, final Boolean selectTargetWithNoTag, final boolean fetch, final String... tagNames) { - final List> specList = new ArrayList<>(); + final List> specList = new ArrayList<>(); if (status != null && !status.isEmpty()) { specList.add(TargetSpecifications.hasTargetUpdateStatus(status, fetch)); } @@ -269,14 +294,15 @@ public class JpaTargetManagement implements TargetManagement { return specList; } - private Slice findByCriteriaAPI(final Pageable pageable, final List> specList) { + private Slice findByCriteriaAPI(final Pageable pageable, final List> specList) { if (specList == null || specList.isEmpty()) { - return criteriaNoCountDao.findAll(pageable, Target.class); + return convertPage(criteriaNoCountDao.findAll(pageable, JpaTarget.class)); } - return criteriaNoCountDao.findAll(SpecificationsBuilder.combineWithAnd(specList), pageable, Target.class); + return convertPage( + criteriaNoCountDao.findAll(SpecificationsBuilder.combineWithAnd(specList), pageable, JpaTarget.class)); } - private Long countByCriteriaAPI(final List> specList) { + private Long countByCriteriaAPI(final List> specList) { if (specList == null || specList.isEmpty()) { return targetRepository.count(); } @@ -298,7 +324,7 @@ public class JpaTargetManagement implements TargetManagement { public TargetTagAssignmentResult toggleTagAssignment(final Collection targetIds, final String tagName) { final TargetTag tag = targetTagRepository.findByNameEquals(tagName); final List alreadyAssignedTargets = targetRepository.findByTagNameAndControllerIdIn(tagName, targetIds); - final List allTargets = targetRepository + final List allTargets = targetRepository .findAll(TargetSpecifications.byControllerIdWithStatusAndTagsInJoin(targetIds)); // all are already assigned -> unassign @@ -315,7 +341,7 @@ public class JpaTargetManagement implements TargetManagement { // some or none are assigned -> assign allTargets.forEach(target -> target.getTags().add(tag)); final TargetTagAssignmentResult result = new TargetTagAssignmentResult(alreadyAssignedTargets.size(), - allTargets.size(), 0, targetRepository.save(allTargets), Collections.emptyList(), tag); + allTargets.size(), 0, new ArrayList<>(targetRepository.save(allTargets)), Collections.emptyList(), tag); afterCommit.afterCommit(() -> eventBus.post(new TargetTagAssigmentResultEvent(result))); @@ -328,11 +354,11 @@ public class JpaTargetManagement implements TargetManagement { @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) public List assignTag(final Collection targetIds, final TargetTag tag) { - final List allTargets = targetRepository + final List allTargets = targetRepository .findAll(TargetSpecifications.byControllerIdWithStatusAndTagsInJoin(targetIds)); allTargets.forEach(target -> target.getTags().add(tag)); - final List save = targetRepository.save(allTargets); + final List save = new ArrayList<>(targetRepository.save(allTargets)); afterCommit.afterCommit(() -> { final TargetTagAssignmentResult assigmentResult = new TargetTagAssignmentResult(0, save.size(), 0, save, @@ -344,9 +370,11 @@ public class JpaTargetManagement implements TargetManagement { } private List unAssignTag(final Collection targets, final TargetTag tag) { - targets.forEach(target -> target.getTags().remove(tag)); + final Collection toUnassign = (Collection) targets; - final List save = targetRepository.save(targets); + toUnassign.forEach(target -> target.getTags().remove(tag)); + + final List save = new ArrayList<>(targetRepository.save(toUnassign)); afterCommit.afterCommit(() -> { final TargetTagAssignmentResult assigmentResult = new TargetTagAssignmentResult(0, 0, save.size(), Collections.emptyList(), save, tag); @@ -366,8 +394,9 @@ public class JpaTargetManagement implements TargetManagement { @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) public Target unAssignTag(final String controllerID, final TargetTag targetTag) { - final List allTargets = targetRepository - .findAll(TargetSpecifications.byControllerIdWithStatusAndTagsInJoin(Arrays.asList(controllerID))); + // TODO : optimize this, findone? + final List allTargets = new ArrayList<>(targetRepository + .findAll(TargetSpecifications.byControllerIdWithStatusAndTagsInJoin(Arrays.asList(controllerID)))); final List unAssignTag = unAssignTag(allTargets, targetTag); return unAssignTag.isEmpty() ? null : unAssignTag.get(0); } @@ -378,20 +407,20 @@ public class JpaTargetManagement implements TargetManagement { final Collection filterByStatus, final String filterBySearchText, final Boolean selectTargetWithNoTag, final String... filterByTagNames) { final CriteriaBuilder cb = entityManager.getCriteriaBuilder(); - final CriteriaQuery query = cb.createQuery(Target.class); - final Root targetRoot = query.from(Target.class); + final CriteriaQuery query = cb.createQuery(JpaTarget.class); + final Root targetRoot = query.from(JpaTarget.class); // necessary joins for the select - final Join targetInfo = (Join) targetRoot.fetch(Target_.targetInfo, - JoinType.LEFT); + final Join targetInfo = (Join) targetRoot + .fetch(JpaTarget_.targetInfo, JoinType.LEFT); // select case expression to retrieve the case value as a column to be // able to order based on // this column, installed first,... final Expression selectCase = cb.selectCase() - .when(cb.equal(targetInfo.get(TargetInfo_.installedDistributionSet).get(DistributionSet_.id), + .when(cb.equal(targetInfo.get(JpaTargetInfo_.installedDistributionSet).get(JpaDistributionSet_.id), orderByDistributionId), 1) - .when(cb.equal(targetRoot.get(Target_.assignedDistributionSet).get(DistributionSet_.id), + .when(cb.equal(targetRoot.get(JpaTarget_.assignedDistributionSet).get(JpaDistributionSet_.id), orderByDistributionId), 2) .otherwise(100); // multiselect statement order by the select case and controllerId @@ -409,7 +438,7 @@ public class JpaTargetManagement implements TargetManagement { query.where(specificationsForMultiSelect); } // add the order to the multi select first based on the selectCase - query.orderBy(cb.asc(selectCase), cb.desc(targetRoot.get(Target_.id))); + query.orderBy(cb.asc(selectCase), cb.desc(targetRoot.get(JpaTarget_.id))); // the result is a Object[] due the fact that the selectCase is an extra // column, so it cannot // be mapped directly to a Target entity because the selectCase is not a @@ -419,14 +448,14 @@ public class JpaTargetManagement implements TargetManagement { // multiselect order) of the array and // the 2nd contains the selectCase int value. final int pageSize = pageable.getPageSize(); - final List resultList = entityManager.createQuery(query).setFirstResult(pageable.getOffset()) + final List resultList = entityManager.createQuery(query).setFirstResult(pageable.getOffset()) .setMaxResults(pageSize + 1).getResultList(); final boolean hasNext = resultList.size() > pageSize; - return new SliceImpl<>(resultList, pageable, hasNext); + return new SliceImpl<>(new ArrayList<>(resultList), pageable, hasNext); } - private static Predicate[] specificationsToPredicate(final List> specifications, - final Root root, final CriteriaQuery query, final CriteriaBuilder cb) { + private static Predicate[] specificationsToPredicate(final List> specifications, + final Root root, final CriteriaQuery query, final CriteriaBuilder cb) { final Predicate[] predicates = new Predicate[specifications.size()]; for (int index = 0; index < predicates.length; index++) { predicates[index] = specifications.get(index).toPredicate(root, query, cb); @@ -448,9 +477,9 @@ public class JpaTargetManagement implements TargetManagement { public List findAllTargetIds() { final CriteriaBuilder cb = entityManager.getCriteriaBuilder(); final CriteriaQuery query = cb.createQuery(TargetIdName.class); - final Root targetRoot = query.from(Target.class); - return entityManager.createQuery(query.multiselect(targetRoot.get(Target_.id), - targetRoot.get(Target_.controllerId), targetRoot.get(Target_.name))).getResultList(); + final Root targetRoot = query.from(JpaTarget.class); + return entityManager.createQuery(query.multiselect(targetRoot.get(JpaTarget_.id), + targetRoot.get(JpaTarget_.controllerId), targetRoot.get(JpaTarget_.name))).getResultList(); } @@ -461,16 +490,16 @@ public class JpaTargetManagement implements TargetManagement { final String... filterByTagNames) { final CriteriaBuilder cb = entityManager.getCriteriaBuilder(); final CriteriaQuery query = cb.createQuery(Object[].class); - final Root targetRoot = query.from(Target.class); + final Root targetRoot = query.from(JpaTarget.class); List resultList; - String sortProperty = Target_.id.getName(); + String sortProperty = JpaTarget_.id.getName(); if (pageRequest.getSort() != null && pageRequest.getSort().iterator().hasNext()) { sortProperty = pageRequest.getSort().iterator().next().getProperty(); } - final CriteriaQuery multiselect = query.multiselect(targetRoot.get(Target_.id), - targetRoot.get(Target_.controllerId), targetRoot.get(Target_.name), targetRoot.get(sortProperty)); + final CriteriaQuery multiselect = query.multiselect(targetRoot.get(JpaTarget_.id), + targetRoot.get(JpaTarget_.controllerId), targetRoot.get(JpaTarget_.name), targetRoot.get(sortProperty)); final Predicate[] specificationsForMultiSelect = specificationsToPredicate( buildSpecificationList(filterByStatus, filterBySearchText, installedOrAssignedDistributionSetId, @@ -493,18 +522,18 @@ public class JpaTargetManagement implements TargetManagement { final TargetFilterQuery targetFilterQuery) { final CriteriaBuilder cb = entityManager.getCriteriaBuilder(); final CriteriaQuery query = cb.createQuery(Object[].class); - final Root targetRoot = query.from(Target.class); + final Root targetRoot = query.from(JpaTarget.class); - String sortProperty = Target_.id.getName(); + String sortProperty = JpaTarget_.id.getName(); if (pageRequest.getSort() != null && pageRequest.getSort().iterator().hasNext()) { sortProperty = pageRequest.getSort().iterator().next().getProperty(); } - final CriteriaQuery multiselect = query.multiselect(targetRoot.get(Target_.id), - targetRoot.get(Target_.controllerId), targetRoot.get(Target_.name), targetRoot.get(sortProperty)); + final CriteriaQuery multiselect = query.multiselect(targetRoot.get(JpaTarget_.id), + targetRoot.get(JpaTarget_.controllerId), targetRoot.get(JpaTarget_.name), targetRoot.get(sortProperty)); - final Specification spec = RSQLUtility.parse(targetFilterQuery.getQuery(), TargetFields.class); - final List> specList = new ArrayList<>(); + final Specification spec = RSQLUtility.parse(targetFilterQuery.getQuery(), TargetFields.class); + final List> specList = new ArrayList<>(); specList.add(spec); final Predicate[] specificationsForMultiSelect = specificationsToPredicate(specList, targetRoot, multiselect, @@ -529,16 +558,17 @@ public class JpaTargetManagement implements TargetManagement { @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) @CacheEvict(value = { "targetsCreatedOverPeriod" }, allEntries = true) - public Target createTarget(final Target target, final TargetUpdateStatus status, final Long lastTargetQuery, + public Target createTarget(final Target t, final TargetUpdateStatus status, final Long lastTargetQuery, final URI address) { + final JpaTarget target = (JpaTarget) t; if (targetRepository.findByControllerId(target.getControllerId()) != null) { throw new EntityAlreadyExistsException(target.getControllerId()); } target.setNew(true); - final Target savedTarget = targetRepository.save(target); - final TargetInfo targetInfo = savedTarget.getTargetInfo(); + final JpaTarget savedTarget = targetRepository.save(target); + final JpaTargetInfo targetInfo = (JpaTargetInfo) savedTarget.getTargetInfo(); targetInfo.setUpdateStatus(status); if (lastTargetQuery != null) { targetInfo.setLastTargetQuery(lastTargetQuery); @@ -596,24 +626,24 @@ public class JpaTargetManagement implements TargetManagement { @Override public List findTargetsByTag(final String tagName) { - final TargetTag tag = targetTagRepository.findByNameEquals(tagName); - return targetRepository.findByTag(tag); + final JpaTargetTag tag = targetTagRepository.findByNameEquals(tagName); + return new ArrayList<>(targetRepository.findByTag(tag)); } @Override public Long countTargetByTargetFilterQuery(final TargetFilterQuery targetFilterQuery) { - final Specification specs = RSQLUtility.parse(targetFilterQuery.getQuery(), TargetFields.class); + final Specification specs = RSQLUtility.parse(targetFilterQuery.getQuery(), TargetFields.class); return targetRepository.count(specs); } @Override public Long countTargetByTargetFilterQuery(final String targetFilterQuery) { - final Specification specs = RSQLUtility.parse(targetFilterQuery, TargetFields.class); + final Specification specs = RSQLUtility.parse(targetFilterQuery, TargetFields.class); return targetRepository.count(specs); } private List getTargetIdNameResultSet(final Pageable pageRequest, final CriteriaBuilder cb, - final Root targetRoot, final CriteriaQuery multiselect) { + final Root targetRoot, final CriteriaQuery multiselect) { List resultList; if (pageRequest.getSort() != null) { final List orders = new ArrayList<>(); @@ -633,4 +663,10 @@ public class JpaTargetManagement implements TargetManagement { } return resultList; } + + @Override + @Transactional(propagation = Propagation.SUPPORTS) + public Target generateTarget(final String controllerId) { + return new JpaTarget(controllerId); + } } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTenantConfigurationManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTenantConfigurationManagement.java index 5cc27d75c..c9781a2a4 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTenantConfigurationManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTenantConfigurationManagement.java @@ -9,6 +9,7 @@ package org.eclipse.hawkbit.repository.jpa; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; +import org.eclipse.hawkbit.repository.jpa.model.JpaTenantConfiguration; import org.eclipse.hawkbit.repository.model.TenantConfiguration; import org.eclipse.hawkbit.repository.model.TenantConfigurationValue; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; @@ -134,16 +135,17 @@ public class JpaTenantConfigurationManagement implements EnvironmentAware, Tenan configurationKey.validate(applicationContext, value); - TenantConfiguration tenantConfiguration = tenantConfigurationRepository + JpaTenantConfiguration tenantConfiguration = tenantConfigurationRepository .findByKey(configurationKey.getKeyName()); if (tenantConfiguration == null) { - tenantConfiguration = new TenantConfiguration(configurationKey.getKeyName(), value.toString()); + tenantConfiguration = new JpaTenantConfiguration(configurationKey.getKeyName(), value.toString()); } else { tenantConfiguration.setValue(value.toString()); } - final TenantConfiguration updatedTenantConfiguration = tenantConfigurationRepository.save(tenantConfiguration); + final JpaTenantConfiguration updatedTenantConfiguration = tenantConfigurationRepository + .save(tenantConfiguration); final Class clazzT = (Class) value.getClass(); diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/LocalArtifactRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/LocalArtifactRepository.java index fcad668d2..e6eb62a27 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/LocalArtifactRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/LocalArtifactRepository.java @@ -11,6 +11,7 @@ package org.eclipse.hawkbit.repository.jpa; import java.util.List; import java.util.Optional; +import org.eclipse.hawkbit.repository.jpa.model.JpaLocalArtifact; import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -23,7 +24,7 @@ import org.springframework.transaction.annotation.Transactional; * */ @Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) -public interface LocalArtifactRepository extends BaseEntityRepository { +public interface LocalArtifactRepository extends BaseEntityRepository { /** * Counts artifacts size where the related software module is not @@ -31,7 +32,7 @@ public interface LocalArtifactRepository extends BaseEntityRepository getSumOfUndeletedArtifactSize(); /** @@ -60,7 +61,7 @@ public interface LocalArtifactRepository extends BaseEntityRepository, JpaSpecificationExecutor { + extends BaseEntityRepository, JpaSpecificationExecutor { /** * Retrieves all {@link RolloutGroup} referring a specific rollout in the @@ -36,7 +38,7 @@ public interface RolloutGroupRepository * the rollout the rolloutgroups belong to * @return the rollout groups belonging to a rollout ordered by ID ASC. */ - List findByRolloutOrderByIdAsc(final Rollout rollout); + List findByRolloutOrderByIdAsc(final JpaRollout rollout); /** * Retrieves all {@link RolloutGroup} referring a specific rollout in a @@ -48,7 +50,7 @@ public interface RolloutGroupRepository * the status of the rollout groups * @return the rollout groups belonging to a rollout in a specific status */ - List findByRolloutAndStatus(final Rollout rollout, final RolloutGroupStatus status); + List findByRolloutAndStatus(final Rollout rollout, final RolloutGroupStatus status); /** * Counts all {@link RolloutGroup} referring a specific rollout. @@ -57,7 +59,7 @@ public interface RolloutGroupRepository * the rollout the rolloutgroup belong to * @return the count of the rollout groups for a specific rollout */ - Long countByRollout(final Rollout rollout); + Long countByRollout(final JpaRollout rollout); /** * Counts all {@link RolloutGroup} referring a specific rollout in a @@ -70,7 +72,7 @@ public interface RolloutGroupRepository * @return the count of rollout groups belonging to a rollout in a specific * status */ - Long countByRolloutAndStatus(Rollout rollout, RolloutGroupStatus rolloutGroupStatus); + Long countByRolloutAndStatus(JpaRollout rollout, RolloutGroupStatus rolloutGroupStatus); /** * Counts all {@link RolloutGroup} referring a specific rollout in specific @@ -88,8 +90,8 @@ public interface RolloutGroupRepository * @return the count of rollout groups belonging to a rollout in specific * status */ - @Query("SELECT COUNT(r.id) FROM RolloutGroup r WHERE r.rollout = :rollout and (r.status = :status1 or r.status = :status2)") - Long countByRolloutAndStatusOrStatus(@Param("rollout") Rollout rollout, + @Query("SELECT COUNT(r.id) FROM JpaRolloutGroup r WHERE r.rollout = :rollout and (r.status = :status1 or r.status = :status2)") + Long countByRolloutAndStatusOrStatus(@Param("rollout") JpaRollout rollout, @Param("status1") RolloutGroupStatus rolloutGroupStatus1, @Param("status2") RolloutGroupStatus rolloutGroupStatus2); @@ -103,7 +105,7 @@ public interface RolloutGroupRepository * the status of the rolloutgroups * @return The child {@link RolloutGroup}s in a specific status */ - List findByParentAndStatus(RolloutGroup rolloutGroup, RolloutGroupStatus status); + List findByParentAndStatus(JpaRolloutGroup rolloutGroup, RolloutGroupStatus status); /** * Retrieves all {@link RolloutGroup} for a specific rollout and status not @@ -116,7 +118,7 @@ public interface RolloutGroupRepository * @return rolloutgroup referring to a rollout and not having a specific * status ordered by ID DESC. */ - List findByRolloutAndStatusNotOrderByIdDesc(Rollout rollout, RolloutGroupStatus notStatus); + List findByRolloutAndStatusNotOrderByIdDesc(JpaRollout rollout, RolloutGroupStatus notStatus); /** * Retrieves all {@link RolloutGroup} for a specific rollout. @@ -127,6 +129,6 @@ public interface RolloutGroupRepository * the page request to sort, limit the result * @return a page of found {@link RolloutGroup} or {@code empty}. */ - Page findByRolloutId(final Long rolloutId, Pageable page); + Page findByRolloutId(final Long rolloutId, Pageable page); } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/RolloutRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/RolloutRepository.java index 212672419..e73c12952 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/RolloutRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/RolloutRepository.java @@ -10,8 +10,9 @@ package org.eclipse.hawkbit.repository.jpa; import java.util.List; +import org.eclipse.hawkbit.repository.jpa.model.JpaRollout; +import org.eclipse.hawkbit.repository.jpa.model.JpaRollout.RolloutStatus; import org.eclipse.hawkbit.repository.model.Rollout; -import org.eclipse.hawkbit.repository.model.Rollout.RolloutStatus; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; @@ -25,7 +26,8 @@ import org.springframework.transaction.annotation.Transactional; * The repository interface for the {@link Rollout} model. */ @Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) -public interface RolloutRepository extends BaseEntityRepository, JpaSpecificationExecutor { +public interface RolloutRepository + extends BaseEntityRepository, JpaSpecificationExecutor { /** * Updates the {@code lastCheck} field of the {@link Rollout} for rollouts @@ -42,7 +44,7 @@ public interface RolloutRepository extends BaseEntityRepository, */ @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @Query("UPDATE Rollout r SET r.lastCheck = :lastCheck WHERE r.lastCheck < (:lastCheck - :delay) AND r.status=:status") + @Query("UPDATE JpaRollout r SET r.lastCheck = :lastCheck WHERE r.lastCheck < (:lastCheck - :delay) AND r.status=:status") int updateLastCheck(@Param("lastCheck") final long lastCheck, @Param("delay") final long delay, @Param("status") final RolloutStatus status); @@ -57,7 +59,7 @@ public interface RolloutRepository extends BaseEntityRepository, * @return the list of {@link Rollout} for specific lastCheck time and * status */ - List findByLastCheckAndStatus(long lastCheck, RolloutStatus status); + List findByLastCheckAndStatus(long lastCheck, RolloutStatus status); /** * Retrieves all {@link Rollout} for a specific {@code name} @@ -66,7 +68,7 @@ public interface RolloutRepository extends BaseEntityRepository, * the rollout name * @return {@link Rollout} for specific name */ - Page findByName(final Pageable pageable, String name); + Page findByName(final Pageable pageable, String name); /** * Retrieves all {@link Rollout} for a specific {@code name} @@ -75,7 +77,7 @@ public interface RolloutRepository extends BaseEntityRepository, * the rollout name * @return {@link Rollout} for specific name */ - Rollout findByName(String name); + JpaRollout findByName(String name); /** * Retrieves all {@link Rollout} for a specific status. @@ -84,5 +86,5 @@ public interface RolloutRepository extends BaseEntityRepository, * the status of the rollouts to retrieve * @return a list of {@link Rollout} having the given status */ - List findByStatus(final RolloutStatus status); + List findByStatus(final RolloutStatus status); } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/RolloutTargetGroupRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/RolloutTargetGroupRepository.java index 2e7eac55d..8cb267c69 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/RolloutTargetGroupRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/RolloutTargetGroupRepository.java @@ -8,8 +8,8 @@ */ package org.eclipse.hawkbit.repository.jpa; -import org.eclipse.hawkbit.repository.model.RolloutTargetGroup; -import org.eclipse.hawkbit.repository.model.RolloutTargetGroupId; +import org.eclipse.hawkbit.repository.jpa.model.RolloutTargetGroup; +import org.eclipse.hawkbit.repository.jpa.model.RolloutTargetGroupId; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.repository.CrudRepository; import org.springframework.transaction.annotation.Isolation; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleMetadataRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleMetadataRepository.java index 8023a9361..c962b31ec 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleMetadataRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleMetadataRepository.java @@ -10,8 +10,9 @@ package org.eclipse.hawkbit.repository.jpa; import java.util.List; +import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleMetadata; +import org.eclipse.hawkbit.repository.jpa.model.SwMetadataCompositeKey; import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata; -import org.eclipse.hawkbit.repository.model.SwMetadataCompositeKey; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; @@ -25,8 +26,8 @@ import org.springframework.transaction.annotation.Transactional; */ @Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) public interface SoftwareModuleMetadataRepository - extends PagingAndSortingRepository, - JpaSpecificationExecutor { + extends PagingAndSortingRepository, + JpaSpecificationExecutor { /** * Saves all given entities. @@ -37,7 +38,7 @@ public interface SoftwareModuleMetadataRepository * in case the given entity is (@literal null}. */ @Override - List save(Iterable entities); + List save(Iterable entities); /** * finds all software module meta data of the given software module id. diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleRepository.java index e03b3e084..08c84b349 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleRepository.java @@ -10,6 +10,9 @@ package org.eclipse.hawkbit.repository.jpa; import java.util.List; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; +import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; +import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; @@ -30,7 +33,7 @@ import org.springframework.transaction.annotation.Transactional; */ @Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) public interface SoftwareModuleRepository - extends BaseEntityRepository, JpaSpecificationExecutor { + extends BaseEntityRepository, JpaSpecificationExecutor { /** * Counts all {@link SoftwareModule}s based on the given {@link Type}. @@ -39,7 +42,7 @@ public interface SoftwareModuleRepository * to count for * @return number of {@link SoftwareModule}s */ - Long countByType(SoftwareModuleType type); + Long countByType(JpaSoftwareModuleType type); /** * Retrieves {@link SoftwareModule} by filtering on name AND version AND @@ -54,7 +57,7 @@ public interface SoftwareModuleRepository * @return the found {@link SoftwareModule} with the given name AND version * AND type */ - SoftwareModule findOneByNameAndVersionAndType(String name, String version, SoftwareModuleType type); + JpaSoftwareModule findOneByNameAndVersionAndType(String name, String version, JpaSoftwareModuleType type); /** * deletes the {@link SoftwareModule}s with the given IDs. @@ -69,7 +72,7 @@ public interface SoftwareModuleRepository */ @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @Query("UPDATE SoftwareModule b SET b.deleted = 1, b.lastModifiedAt = :lastModifiedAt, b.lastModifiedBy = :lastModifiedBy WHERE b.id IN :ids") + @Query("UPDATE JpaSoftwareModule b SET b.deleted = 1, b.lastModifiedAt = :lastModifiedAt, b.lastModifiedBy = :lastModifiedBy WHERE b.id IN :ids") void deleteSoftwareModule(@Param("lastModifiedAt") Long modifiedAt, @Param("lastModifiedBy") String modifiedBy, @Param("ids") final Long... ids); @@ -81,7 +84,7 @@ public interface SoftwareModuleRepository * @return all {@link SoftwareModule}s that are assigned to given * {@link DistributionSet}. */ - Page findByAssignedTo(Pageable pageable, DistributionSet set); + Page findByAssignedTo(Pageable pageable, JpaDistributionSet set); /** * @@ -92,7 +95,7 @@ public interface SoftwareModuleRepository * {@link DistributionSet} */ @EntityGraph(value = "SoftwareModule.artifacts", type = EntityGraphType.LOAD) - List findByAssignedTo(DistributionSet set); + List findByAssignedTo(JpaDistributionSet set); /** * @param pageable @@ -104,7 +107,7 @@ public interface SoftwareModuleRepository * @return all {@link SoftwareModule}s that are assigned to given * {@link DistributionSet} filtered by {@link SoftwareModuleType}. */ - Page findByAssignedToAndType(Pageable pageable, DistributionSet set, SoftwareModuleType type); + Page findByAssignedToAndType(Pageable pageable, JpaDistributionSet set, JpaSoftwareModuleType type); /** * retrieves all software modules with a given {@link SoftwareModuleType} @@ -117,11 +120,11 @@ public interface SoftwareModuleRepository * @return {@link List} of found {@link SoftwareModule}s */ // Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=349477 - @Query("SELECT sm FROM SoftwareModule sm WHERE sm.id IN ?1 and sm.type = ?2") - List findByIdInAndType(Iterable ids, SoftwareModuleType type); + @Query("SELECT sm FROM JpaSoftwareModule sm WHERE sm.id IN ?1 and sm.type = ?2") + List findByIdInAndType(Iterable ids, JpaSoftwareModuleType type); @Override - List save(Iterable entities); + List save(Iterable entities); /** * retrieves all software modules with a given @@ -132,6 +135,6 @@ public interface SoftwareModuleRepository * @return {@link List} of found {@link SoftwareModule}s */ // Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=349477 - @Query("SELECT sm FROM SoftwareModule sm WHERE sm.id IN ?1") - List findByIdIn(Iterable ids); + @Query("SELECT sm FROM JpaSoftwareModule sm WHERE sm.id IN ?1") + List findByIdIn(Iterable ids); } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleTypeRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleTypeRepository.java index fe2cfadf4..c4ecfbd74 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleTypeRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleTypeRepository.java @@ -8,6 +8,7 @@ */ package org.eclipse.hawkbit.repository.jpa; +import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -21,7 +22,7 @@ import org.springframework.transaction.annotation.Transactional; */ @Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) public interface SoftwareModuleTypeRepository - extends BaseEntityRepository, JpaSpecificationExecutor { + extends BaseEntityRepository, JpaSpecificationExecutor { /** * @param pageable @@ -47,7 +48,7 @@ public interface SoftwareModuleTypeRepository * @return all {@link SoftwareModuleType}s in the repository with given * {@link SoftwareModuleType#getKey()} */ - SoftwareModuleType findByKey(String key); + JpaSoftwareModuleType findByKey(String key); /** * @@ -56,5 +57,5 @@ public interface SoftwareModuleTypeRepository * @return all {@link SoftwareModuleType}s in the repository with given * {@link SoftwareModuleType#getName()} */ - SoftwareModuleType findByName(String name); + JpaSoftwareModuleType findByName(String name); } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetFilterQueryRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetFilterQueryRepository.java index 346fe2ec2..1f2fec8d8 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetFilterQueryRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetFilterQueryRepository.java @@ -8,6 +8,7 @@ */ package org.eclipse.hawkbit.repository.jpa; +import org.eclipse.hawkbit.repository.jpa.model.JpaTargetFilterQuery; import org.eclipse.hawkbit.repository.model.TargetFilterQuery; import org.springframework.data.domain.Page; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; @@ -21,7 +22,7 @@ import org.springframework.transaction.annotation.Transactional; */ @Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) public interface TargetFilterQueryRepository - extends BaseEntityRepository, JpaSpecificationExecutor { + extends BaseEntityRepository, JpaSpecificationExecutor { /** * Find customer target filter by name @@ -35,11 +36,11 @@ public interface TargetFilterQueryRepository * Find list of all custom target filters. */ @Override - Page findAll(); + Page findAll(); @Override @Modifying @Transactional - S save(S entity); + S save(S entity); } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetInfoRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetInfoRepository.java index 1c3378bba..815fa3961 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetInfoRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetInfoRepository.java @@ -13,6 +13,7 @@ import java.util.List; import javax.persistence.Entity; +import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo; import org.eclipse.hawkbit.repository.model.TargetInfo; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; import org.springframework.cache.annotation.CacheEvict; @@ -42,7 +43,7 @@ public interface TargetInfoRepository { */ @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @Query("update TargetInfo ti set ti.updateStatus = :status where ti.targetId in :targets and ti.updateStatus != :status") + @Query("update JpaTargetInfo ti set ti.updateStatus = :status where ti.targetId in :targets and ti.updateStatus != :status") void setTargetUpdateStatus(@Param("status") TargetUpdateStatus status, @Param("targets") List targets); /** @@ -54,7 +55,7 @@ public interface TargetInfoRepository { * @return persisted or updated {@link Entity} */ @CacheEvict(value = { "targetStatus", "distributionUsageInstalled", "targetsLastPoll" }, allEntries = true) - S save(S entity); + S save(S entity); /** * Deletes info entries by ID. diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetRepository.java index b3d390016..0d84a3cad 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetRepository.java @@ -11,11 +11,13 @@ package org.eclipse.hawkbit.repository.jpa; import java.util.Collection; import java.util.List; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; +import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup; +import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; +import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag; import org.eclipse.hawkbit.repository.model.DistributionSet; -import org.eclipse.hawkbit.repository.model.RolloutGroup; import org.eclipse.hawkbit.repository.model.Tag; import org.eclipse.hawkbit.repository.model.Target; -import org.eclipse.hawkbit.repository.model.TargetTag; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; import org.eclipse.hawkbit.repository.model.TargetWithActionStatus; import org.springframework.cache.annotation.CacheEvict; @@ -35,7 +37,7 @@ import org.springframework.transaction.annotation.Transactional; * */ @Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) -public interface TargetRepository extends BaseEntityRepository, JpaSpecificationExecutor { +public interface TargetRepository extends BaseEntityRepository, JpaSpecificationExecutor { /** * Loads {@link Target} including details {@link EntityGraph} by given ID. @@ -45,7 +47,7 @@ public interface TargetRepository extends BaseEntityRepository, Jp * @return found {@link Target} or null if not found. */ @EntityGraph(value = "Target.detail", type = EntityGraphType.LOAD) - Target findByControllerId(String controllerID); + JpaTarget findByControllerId(String controllerID); /** * Finds targets by given list of {@link Target#getControllerId()}s. @@ -65,7 +67,7 @@ public interface TargetRepository extends BaseEntityRepository, Jp @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) // Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=349477 - @Query("DELETE FROM Target t WHERE t.id IN ?1") + @Query("DELETE FROM JpaTarget t WHERE t.id IN ?1") void deleteByIdIn(final Collection targetIDs); /** @@ -75,8 +77,8 @@ public interface TargetRepository extends BaseEntityRepository, Jp * to be found * @return list of found targets */ - @Query(value = "SELECT DISTINCT t FROM Target t JOIN t.tags tt WHERE tt = :tag") - List findByTag(@Param("tag") final TargetTag tag); + @Query(value = "SELECT DISTINCT t FROM JpaTarget t JOIN t.tags tt WHERE tt = :tag") + List findByTag(@Param("tag") final JpaTargetTag tag); /** * Finds all {@link Target}s based on given {@link Target#getControllerId()} @@ -88,7 +90,7 @@ public interface TargetRepository extends BaseEntityRepository, Jp * to search for * @return {@link List} of found {@link Target}s. */ - @Query(value = "SELECT DISTINCT t from Target t JOIN t.tags tt WHERE tt.name = :tagname AND t.controllerId IN :targets") + @Query(value = "SELECT DISTINCT t from JpaTarget t JOIN t.tags tt WHERE tt.name = :tagname AND t.controllerId IN :targets") List findByTagNameAndControllerIdIn(@Param("tagname") final String tag, @Param("targets") final Collection controllerIds); @@ -114,7 +116,7 @@ public interface TargetRepository extends BaseEntityRepository, Jp * * @return found targets */ - Page findByTargetInfoInstalledDistributionSet(final Pageable pageable, final DistributionSet set); + Page findByTargetInfoInstalledDistributionSet(final Pageable pageable, final JpaDistributionSet set); /** * retrieves the {@link Target}s which has the {@link DistributionSet} @@ -138,7 +140,7 @@ public interface TargetRepository extends BaseEntityRepository, Jp * * @return found targets */ - Page findByAssignedDistributionSet(final Pageable pageable, final DistributionSet set); + Page findByAssignedDistributionSet(final Pageable pageable, final JpaDistributionSet set); /** * Saves all given {@link Target}s. @@ -154,7 +156,7 @@ public interface TargetRepository extends BaseEntityRepository, Jp @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) @CacheEvict(value = { "targetStatus", "distributionUsageInstalled", "targetsLastPoll" }, allEntries = true) - List save(Iterable entities); + List save(Iterable entities); /** * Saves a given entity. Use the returned instance for further operations as @@ -168,7 +170,7 @@ public interface TargetRepository extends BaseEntityRepository, Jp @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) @CacheEvict(value = { "targetStatus", "distributionUsageInstalled", "targetsLastPoll" }, allEntries = true) - S save(S entity); + S save(S entity); /** * Finds all targets that have defined {@link DistributionSet} assigned. @@ -199,7 +201,7 @@ public interface TargetRepository extends BaseEntityRepository, Jp * @return number of found {@link Target}s with given * {@link Target#getControllerId()}s */ - @Query("SELECT COUNT(t) FROM Target t WHERE t.controllerId IN ?1") + @Query("SELECT COUNT(t) FROM JpaTarget t WHERE t.controllerId IN ?1") Long countByControllerIdIn(final Collection ids); /** @@ -228,7 +230,7 @@ public interface TargetRepository extends BaseEntityRepository, Jp * @return found targets */ Page findByAssignedDistributionSetOrTargetInfoInstalledDistributionSet(final Pageable pageable, - final DistributionSet assigned, final DistributionSet installed); + final JpaDistributionSet assigned, final JpaDistributionSet installed); /** * Finds all targets that have defined {@link DistributionSet} assigned or @@ -255,12 +257,12 @@ public interface TargetRepository extends BaseEntityRepository, Jp * @see org.springframework.data.repository.CrudRepository#findAll() */ @Override - List findAll(); + List findAll(); @Override // Workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=349477 - @Query("SELECT t FROM Target t WHERE t.id IN ?1") - List findAll(Iterable ids); + @Query("SELECT t FROM JpaTarget t WHERE t.id IN ?1") + List findAll(Iterable ids); /** * Sets {@link Target#getAssignedDistributionSet()}. @@ -276,11 +278,11 @@ public interface TargetRepository extends BaseEntityRepository, Jp */ @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) - @Query("UPDATE Target t SET t.assignedDistributionSet = :set, t.lastModifiedAt = :lastModifiedAt, t.lastModifiedBy = :lastModifiedBy WHERE t.id IN :targets") - void setAssignedDistributionSet(@Param("set") DistributionSet set, @Param("lastModifiedAt") Long modifiedAt, + @Query("UPDATE JpaTarget t SET t.assignedDistributionSet = :set, t.lastModifiedAt = :lastModifiedAt, t.lastModifiedBy = :lastModifiedBy WHERE t.id IN :targets") + void setAssignedDistributionSet(@Param("set") JpaDistributionSet set, @Param("lastModifiedAt") Long modifiedAt, @Param("lastModifiedBy") String modifiedBy, @Param("targets") Collection targets); - List findByRolloutTargetGroupRolloutGroup(final RolloutGroup rolloutGroup); + List findByRolloutTargetGroupRolloutGroup(final JpaRolloutGroup rolloutGroup); /** * @@ -304,7 +306,7 @@ public interface TargetRepository extends BaseEntityRepository, Jp * the page request parameter * @return a page of all targets related to a rollout group */ - Page findByActionsRolloutGroup(RolloutGroup rolloutGroup, Pageable page); + Page findByActionsRolloutGroup(JpaRolloutGroup rolloutGroup, Pageable page); /** * Find all targets with action status for a specific group. @@ -315,7 +317,7 @@ public interface TargetRepository extends BaseEntityRepository, Jp * the ID of the rollout group * @return targets with action status */ - @Query("select DISTINCT NEW org.eclipse.hawkbit.repository.model.TargetWithActionStatus(a.target,a.status) from Action a inner join fetch a.target t where a.rolloutGroup.id = :rolloutGroupId") + @Query("select DISTINCT NEW org.eclipse.hawkbit.repository.model.TargetWithActionStatus(a.target,a.status) from JpaAction a inner join fetch a.target t where a.rolloutGroup.id = :rolloutGroupId") Page findTargetsWithActionStatusByRolloutGroupId(final Pageable pageable, @Param("rolloutGroupId") Long rolloutGroupId); } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetTagRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetTagRepository.java index 92f48d699..6b9e021b1 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetTagRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetTagRepository.java @@ -10,6 +10,7 @@ package org.eclipse.hawkbit.repository.jpa; import java.util.List; +import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag; import org.eclipse.hawkbit.repository.model.TargetTag; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.Modifying; @@ -22,7 +23,7 @@ import org.springframework.transaction.annotation.Transactional; */ @Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) public interface TargetTagRepository - extends BaseEntityRepository, JpaSpecificationExecutor { + extends BaseEntityRepository, JpaSpecificationExecutor { /** * deletes the {@link TargetTag}s with the given tag names. @@ -42,7 +43,7 @@ public interface TargetTagRepository * to filter on * @return the {@link TargetTag} if found, otherwise null */ - TargetTag findByNameEquals(final String tagName); + JpaTargetTag findByNameEquals(final String tagName); /** * Returns all instances of the type. @@ -50,8 +51,8 @@ public interface TargetTagRepository * @return all entities */ @Override - List findAll(); + List findAll(); @Override - List save(Iterable entities); + List save(Iterable entities); } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TenantConfigurationRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TenantConfigurationRepository.java index 6494aafea..bd99cb918 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TenantConfigurationRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TenantConfigurationRepository.java @@ -10,6 +10,7 @@ package org.eclipse.hawkbit.repository.jpa; import java.util.List; +import org.eclipse.hawkbit.repository.jpa.model.JpaTenantConfiguration; import org.eclipse.hawkbit.repository.model.TenantConfiguration; import org.springframework.transaction.annotation.Isolation; import org.springframework.transaction.annotation.Transactional; @@ -19,7 +20,7 @@ import org.springframework.transaction.annotation.Transactional; * */ @Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) -public interface TenantConfigurationRepository extends BaseEntityRepository { +public interface TenantConfigurationRepository extends BaseEntityRepository { /** * Finds a specific {@link TenantConfiguration} by the configuration key. @@ -28,10 +29,10 @@ public interface TenantConfigurationRepository extends BaseEntityRepository findAll(); + List findAll(); /** * Deletes a tenant configuration by tenant and key. diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TenantMetaDataRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TenantMetaDataRepository.java index 63c213d2c..353f6500b 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TenantMetaDataRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TenantMetaDataRepository.java @@ -10,6 +10,7 @@ package org.eclipse.hawkbit.repository.jpa; import java.util.List; +import org.eclipse.hawkbit.repository.jpa.model.JpaTenantMetaData; import org.eclipse.hawkbit.repository.model.TenantMetaData; import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.transaction.annotation.Isolation; @@ -20,7 +21,7 @@ import org.springframework.transaction.annotation.Transactional; * */ @Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) -public interface TenantMetaDataRepository extends PagingAndSortingRepository { +public interface TenantMetaDataRepository extends PagingAndSortingRepository { /** * Search {@link TenantMetaData} by tenant name. @@ -42,7 +43,7 @@ public interface TenantMetaDataRepository extends PagingAndSortingRepository findAll(); + List findAll(); /** * @param tenant diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTypeElement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/DistributionSetTypeElement.java similarity index 86% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTypeElement.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/DistributionSetTypeElement.java index 8414a6f1a..26a603078 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTypeElement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/DistributionSetTypeElement.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.model; +package org.eclipse.hawkbit.repository.jpa.model; import java.io.Serializable; @@ -21,6 +21,10 @@ import javax.persistence.ManyToOne; import javax.persistence.MapsId; import javax.persistence.Table; +import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.DistributionSetType; +import org.eclipse.hawkbit.repository.model.SoftwareModuleType; + /** * Relation element between a {@link DistributionSetType} and its * {@link SoftwareModuleType} elements. @@ -40,12 +44,12 @@ public class DistributionSetTypeElement implements Serializable { @MapsId("dsType") @ManyToOne(optional = false, fetch = FetchType.LAZY) @JoinColumn(name = "distribution_set_type", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_type_element_dstype")) - private DistributionSetType dsType; + private JpaDistributionSetType dsType; @MapsId("smType") @ManyToOne(optional = false, fetch = FetchType.LAZY) @JoinColumn(name = "software_module_type", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_type_element_smtype")) - private SoftwareModuleType smType; + private JpaSoftwareModuleType smType; public DistributionSetTypeElement() { // Default constructor for JPA @@ -62,7 +66,7 @@ public class DistributionSetTypeElement implements Serializable { * to true if the {@link SoftwareModuleType} if * mandatory element in the {@link DistributionSet}. */ - public DistributionSetTypeElement(final DistributionSetType dsType, final SoftwareModuleType smType, + public DistributionSetTypeElement(final JpaDistributionSetType dsType, final JpaSoftwareModuleType smType, final boolean mandatory) { super(); key = new DistributionSetTypeElementCompositeKey(dsType, smType); diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTypeElementCompositeKey.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/DistributionSetTypeElementCompositeKey.java similarity index 89% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTypeElementCompositeKey.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/DistributionSetTypeElementCompositeKey.java index 2ee1aba0d..f94a3784a 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTypeElementCompositeKey.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/DistributionSetTypeElementCompositeKey.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.model; +package org.eclipse.hawkbit.repository.jpa.model; import java.io.Serializable; @@ -40,7 +40,7 @@ public class DistributionSetTypeElementCompositeKey implements Serializable { * @param smType * in the key */ - DistributionSetTypeElementCompositeKey(final DistributionSetType dsType, final SoftwareModuleType smType) { + DistributionSetTypeElementCompositeKey(final JpaDistributionSetType dsType, final JpaSoftwareModuleType smType) { super(); this.dsType = dsType.getId(); this.smType = smType.getId(); diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DsMetadataCompositeKey.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/DsMetadataCompositeKey.java similarity index 95% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DsMetadataCompositeKey.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/DsMetadataCompositeKey.java index adc37d65a..52ad217c0 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DsMetadataCompositeKey.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/DsMetadataCompositeKey.java @@ -6,10 +6,12 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.model; +package org.eclipse.hawkbit.repository.jpa.model; import java.io.Serializable; +import org.eclipse.hawkbit.repository.model.DistributionSet; + /** * The DistributionSet Metadata composite key which contains the meta data key * and the ID of the DistributionSet itself. diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaAction.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaAction.java new file mode 100644 index 000000000..1080b35fd --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaAction.java @@ -0,0 +1,274 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.jpa.model; + +import java.util.List; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.ConstraintMode; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.FetchType; +import javax.persistence.ForeignKey; +import javax.persistence.Index; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.NamedAttributeNode; +import javax.persistence.NamedEntityGraph; +import javax.persistence.NamedEntityGraphs; +import javax.persistence.NamedSubgraph; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.Transient; + +import org.eclipse.hawkbit.cache.CacheField; +import org.eclipse.hawkbit.cache.CacheKeys; +import org.eclipse.hawkbit.repository.model.Action; +import org.eclipse.hawkbit.repository.model.ActionStatus; +import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.Rollout; +import org.eclipse.hawkbit.repository.model.RolloutGroup; +import org.eclipse.hawkbit.repository.model.SoftwareModule; +import org.eclipse.hawkbit.repository.model.Target; +import org.eclipse.persistence.annotations.CascadeOnDelete; + +/** + *

+ * Applicable transition changes of the {@link SoftwareModule}s state of a + * {@link Target}, e.g. install, uninstall, update and preparations for the + * transition change, i.e. download. + *

+ * + *

+ * Actions are managed by the SP server and applied to the targets by the + * client. + *

+ */ +@Table(name = "sp_action", indexes = { @Index(name = "sp_idx_action_01", columnList = "tenant,distribution_set"), + @Index(name = "sp_idx_action_02", columnList = "tenant,target,active"), + @Index(name = "sp_idx_action_prim", columnList = "tenant,id") }) +@NamedEntityGraphs({ @NamedEntityGraph(name = "Action.ds", attributeNodes = { @NamedAttributeNode("distributionSet") }), + @NamedEntityGraph(name = "Action.all", attributeNodes = { @NamedAttributeNode("distributionSet"), + @NamedAttributeNode(value = "target", subgraph = "target.ds") }, subgraphs = @NamedSubgraph(name = "target.ds", attributeNodes = @NamedAttributeNode("assignedDistributionSet"))) }) +@Entity +public class JpaAction extends JpaTenantAwareBaseEntity implements Action { + private static final long serialVersionUID = 1L; + + /** + * the {@link DistributionSet} which should be installed by this action. + */ + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "distribution_set", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_action_ds")) + private JpaDistributionSet distributionSet; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "target", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_action_target")) + private JpaTarget target; + + @Column(name = "active") + private boolean active; + + @Column(name = "action_type", nullable = false) + @Enumerated(EnumType.STRING) + private ActionType actionType; + + @Column(name = "forced_time") + private long forcedTime; + + @Column(name = "status") + private Status status; + + @CascadeOnDelete + @OneToMany(mappedBy = "action", targetEntity = JpaActionStatus.class, fetch = FetchType.LAZY, cascade = { + CascadeType.REMOVE }) + private List actionStatus; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "rolloutgroup", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_action_rolloutgroup")) + private JpaRolloutGroup rolloutGroup; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "rollout", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_action_rollout")) + private JpaRollout rollout; + + /** + * Note: filled only in {@link Status#DOWNLOAD}. + */ + @Transient + @CacheField(key = CacheKeys.DOWNLOAD_PROGRESS_PERCENT) + private int downloadProgressPercent; + + /** + * @return the distributionSet + */ + @Override + public DistributionSet getDistributionSet() { + return distributionSet; + } + + /** + * @param distributionSet + * the distributionSet to set + */ + @Override + public void setDistributionSet(final DistributionSet distributionSet) { + this.distributionSet = (JpaDistributionSet) distributionSet; + } + + /** + * @return true when action is in state {@link Status#CANCELING} or + * {@link Status#CANCELED}, false otherwise + */ + @Override + public boolean isCancelingOrCanceled() { + return status == Status.CANCELING || status == Status.CANCELED; + } + + @Override + public void setActive(final boolean active) { + this.active = active; + } + + @Override + public Status getStatus() { + return status; + } + + @Override + public void setStatus(final Status status) { + this.status = status; + } + + @Override + public int getDownloadProgressPercent() { + return downloadProgressPercent; + } + + @Override + public void setDownloadProgressPercent(final int downloadProgressPercent) { + this.downloadProgressPercent = downloadProgressPercent; + } + + @Override + public boolean isActive() { + return active; + } + + @Override + public void setActionType(final ActionType actionType) { + this.actionType = actionType; + } + + /** + * @return the actionType + */ + @Override + public ActionType getActionType() { + return actionType; + } + + @Override + public List getActionStatus() { + return actionStatus; + } + + @Override + public void setTarget(final Target target) { + this.target = (JpaTarget) target; + } + + @Override + public Target getTarget() { + return target; + } + + @Override + public long getForcedTime() { + return forcedTime; + } + + @Override + public void setForcedTime(final long forcedTime) { + this.forcedTime = forcedTime; + } + + @Override + public RolloutGroup getRolloutGroup() { + return rolloutGroup; + } + + @Override + public void setRolloutGroup(final RolloutGroup rolloutGroup) { + this.rolloutGroup = (JpaRolloutGroup) rolloutGroup; + } + + @Override + public Rollout getRollout() { + return rollout; + } + + @Override + public void setRollout(final Rollout rollout) { + this.rollout = (JpaRollout) rollout; + } + + /** + * checks if the {@link #forcedTime} is hit by the given + * {@code hitTimeMillis}, by means if the given milliseconds are greater + * than the forcedTime. + * + * @param hitTimeMillis + * the milliseconds, mostly the + * {@link System#currentTimeMillis()} + * @return {@code true} if this {@link #type} is in + * {@link ActionType#TIMEFORCED} and the given {@code hitTimeMillis} + * is greater than the {@link #forcedTime} otherwise {@code false} + */ + @Override + public boolean isHitAutoForceTime(final long hitTimeMillis) { + if (actionType == ActionType.TIMEFORCED) { + return hitTimeMillis >= forcedTime; + } + return false; + } + + /** + * @return {@code true} if either the {@link #type} is + * {@link ActionType#FORCED} or {@link ActionType#TIMEFORCED} but + * then if the {@link #forcedTime} has been exceeded otherwise + * always {@code false} + */ + @Override + public boolean isForce() { + switch (actionType) { + case FORCED: + return true; + case TIMEFORCED: + return isHitAutoForceTime(System.currentTimeMillis()); + default: + return false; + } + } + + /** + * @return true when action is forced, false otherwise + */ + @Override + public boolean isForced() { + return actionType == ActionType.FORCED; + } + + @Override + public String toString() { + return "Action [distributionSet=" + distributionSet + ", getId()=" + getId() + "]"; + } + +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaActionStatus.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaActionStatus.java new file mode 100644 index 000000000..94f76cae7 --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaActionStatus.java @@ -0,0 +1,154 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.jpa.model; + +import java.util.ArrayList; +import java.util.List; + +import javax.persistence.CollectionTable; +import javax.persistence.Column; +import javax.persistence.ConstraintMode; +import javax.persistence.ElementCollection; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.ForeignKey; +import javax.persistence.Index; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.NamedAttributeNode; +import javax.persistence.NamedEntityGraph; +import javax.persistence.Table; + +import org.eclipse.hawkbit.repository.model.Action; +import org.eclipse.hawkbit.repository.model.Action.Status; +import org.eclipse.hawkbit.repository.model.ActionStatus; +import org.eclipse.persistence.annotations.CascadeOnDelete; + +import com.google.common.base.Splitter; + +/** + * Entity to store the status for a specific action. + */ +@Table(name = "sp_action_status", indexes = { @Index(name = "sp_idx_action_status_01", columnList = "tenant,action"), + @Index(name = "sp_idx_action_status_02", columnList = "tenant,action,status"), + @Index(name = "sp_idx_action_status_prim", columnList = "tenant,id") }) +@NamedEntityGraph(name = "ActionStatus.withMessages", attributeNodes = { @NamedAttributeNode("messages") }) +@Entity +public class JpaActionStatus extends JpaTenantAwareBaseEntity implements ActionStatus { + private static final long serialVersionUID = 1L; + + @Column(name = "target_occurred_at") + private Long occurredAt; + + @ManyToOne(fetch = FetchType.LAZY, optional = false) + @JoinColumn(name = "action", nullable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_act_stat_action")) + private JpaAction action; + + @Column(name = "status") + private Status status; + + @CascadeOnDelete + @ElementCollection(fetch = FetchType.LAZY, targetClass = String.class) + @CollectionTable(name = "sp_action_status_messages", joinColumns = @JoinColumn(name = "action_status_id", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_stat_msg_act_stat")), indexes = { + @Index(name = "sp_idx_action_status_msgs_01", columnList = "action_status_id") }) + @Column(name = "detail_message", length = 512) + private final List messages = new ArrayList<>(); + + /** + * Creates a new {@link ActionStatus} object. + * + * @param action + * the action for this action status + * @param status + * the status for this action status + * @param occurredAt + * the occurred timestamp + */ + public JpaActionStatus(final Action action, final Status status, final Long occurredAt) { + this.action = (JpaAction) action; + this.status = status; + this.occurredAt = occurredAt; + } + + /** + * Creates a new {@link ActionStatus} object. + * + * @param action + * the action for this action status + * @param status + * the status for this action status + * @param occurredAt + * the occurred timestamp + * @param messages + * the messages which should be added to this action status + */ + public JpaActionStatus(final JpaAction action, final Status status, final Long occurredAt, + final String... messages) { + this.action = action; + this.status = status; + this.occurredAt = occurredAt; + for (final String msg : messages) { + addMessage(msg); + } + } + + /** + * JPA default constructor. + */ + public JpaActionStatus() { + // JPA default constructor. + } + + @Override + public Long getOccurredAt() { + return occurredAt; + } + + @Override + public void setOccurredAt(final Long occurredAt) { + this.occurredAt = occurredAt; + } + + /** + * Adds message including splitting in case it exceeds 512 length. + * + * @param message + * to add + */ + @Override + public final void addMessage(final String message) { + Splitter.fixedLength(512).split(message).forEach(messages::add); + } + + @Override + public List getMessages() { + return messages; + } + + @Override + public Action getAction() { + return action; + } + + @Override + public void setAction(final Action action) { + this.action = (JpaAction) action; + } + + @Override + public Status getStatus() { + return status; + } + + @Override + public void setStatus(final Status status) { + this.status = status; + } + +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaArtifact.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaArtifact.java new file mode 100644 index 000000000..be0b5e1ac --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaArtifact.java @@ -0,0 +1,63 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.jpa.model; + +import javax.persistence.Column; +import javax.persistence.MappedSuperclass; + +import org.eclipse.hawkbit.repository.model.Artifact; +import org.eclipse.hawkbit.repository.model.SoftwareModule; + +/** + * Tenant specific locally stored artifact representation that is used by + * {@link SoftwareModule}. + */ +@MappedSuperclass +public abstract class JpaArtifact extends JpaTenantAwareBaseEntity implements Artifact { + private static final long serialVersionUID = 1L; + + @Column(name = "sha1_hash", length = 40, nullable = true) + private String sha1Hash; + + @Column(name = "md5_hash", length = 32, nullable = true) + private String md5Hash; + + @Column(name = "file_size") + private Long size; + + @Override + public abstract SoftwareModule getSoftwareModule(); + + @Override + public String getMd5Hash() { + return md5Hash; + } + + @Override + public String getSha1Hash() { + return sha1Hash; + } + + public void setMd5Hash(final String md5Hash) { + this.md5Hash = md5Hash; + } + + public void setSha1Hash(final String sha1Hash) { + this.sha1Hash = sha1Hash; + } + + @Override + public Long getSize() { + return size; + } + + public void setSize(final Long size) { + this.size = size; + } +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaBaseEntity.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaBaseEntity.java new file mode 100644 index 000000000..cfe4ada52 --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaBaseEntity.java @@ -0,0 +1,184 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.jpa.model; + +import javax.persistence.Access; +import javax.persistence.AccessType; +import javax.persistence.Column; +import javax.persistence.EntityListeners; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.MappedSuperclass; +import javax.persistence.Version; + +import org.eclipse.hawkbit.eventbus.CacheFieldEntityListener; +import org.eclipse.hawkbit.eventbus.EntityPropertyChangeListener; +import org.eclipse.hawkbit.repository.model.BaseEntity; +import org.springframework.data.annotation.CreatedBy; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedBy; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +/** + * Holder of the base attributes common to all entities. + * + */ +@MappedSuperclass +@Access(AccessType.FIELD) +@EntityListeners({ AuditingEntityListener.class, CacheFieldEntityListener.class, EntityPropertyChangeListener.class }) +public abstract class JpaBaseEntity implements BaseEntity { + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + private Long id; + + private String createdBy; + private String lastModifiedBy; + private Long createdAt; + private Long lastModifiedAt; + + @Version + @Column(name = "optlock_revision") + private long optLockRevision; + + /** + * Default constructor needed for JPA entities. + */ + public JpaBaseEntity() { + // Default constructor needed for JPA entities. + } + + @Override + @Access(AccessType.PROPERTY) + @Column(name = "created_at", insertable = true, updatable = false) + public Long getCreatedAt() { + return createdAt; + } + + @Override + @Access(AccessType.PROPERTY) + @Column(name = "created_by", insertable = true, updatable = false, length = 40) + public String getCreatedBy() { + return createdBy; + } + + @Override + @Access(AccessType.PROPERTY) + @Column(name = "last_modified_at", insertable = false, updatable = true) + public Long getLastModifiedAt() { + return lastModifiedAt; + } + + @Override + @Access(AccessType.PROPERTY) + @Column(name = "last_modified_by", insertable = false, updatable = true, length = 40) + public String getLastModifiedBy() { + return lastModifiedBy; + } + + @CreatedBy + public void setCreatedBy(final String createdBy) { + this.createdBy = createdBy; + } + + @LastModifiedBy + public void setLastModifiedBy(final String lastModifiedBy) { + this.lastModifiedBy = lastModifiedBy; + } + + @CreatedDate + public void setCreatedAt(final Long createdAt) { + this.createdAt = createdAt; + } + + @LastModifiedDate + public void setLastModifiedAt(final Long lastModifiedAt) { + this.lastModifiedAt = lastModifiedAt; + } + + @Override + public long getOptLockRevision() { + return optLockRevision; + } + + public void setOptLockRevision(final long optLockRevision) { + this.optLockRevision = optLockRevision; + } + + @Override + public Long getId() { + return id; + } + + @Override + public String toString() { + return "BaseEntity [id=" + id + "]"; + } + + public void setId(final Long id) { + this.id = id; + } + + /** + * Defined equals/hashcode strategy for the repository in general is that an + * entity is equal if it has the same {@link #getId()} and + * {@link #getOptLockRevision()} and class. + * + * @see java.lang.Object#hashCode() + */ + @Override + // Exception squid:S864 - generated code + @SuppressWarnings({ "squid:S864" }) + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (id == null ? 0 : id.hashCode()); + result = prime * result + (int) (optLockRevision ^ optLockRevision >>> 32); + result = prime * result + this.getClass().getName().hashCode(); + return result; + } + + /** + * Defined equals/hashcode strategy for the repository in general is that an + * entity is equal if it has the same {@link #getId()} and + * {@link #getOptLockRevision()} and class. + * + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(final Object obj) { // NOSONAR - as this is generated + // code + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (!(this.getClass().isInstance(obj))) { + return false; + } + final JpaBaseEntity other = (JpaBaseEntity) obj; + if (id == null) { + if (other.id != null) { + return false; + } + } else if (!id.equals(other.id)) { + return false; + } + if (optLockRevision != other.optLockRevision) { + return false; + } + return true; + } + +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSet.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSet.java new file mode 100644 index 000000000..201d4d657 --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSet.java @@ -0,0 +1,326 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.jpa.model; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Optional; +import java.util.Set; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.ConstraintMode; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.ForeignKey; +import javax.persistence.Index; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.ManyToMany; +import javax.persistence.ManyToOne; +import javax.persistence.NamedAttributeNode; +import javax.persistence.NamedEntityGraph; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.UniqueConstraint; + +import org.eclipse.hawkbit.repository.exception.DistributionSetTypeUndefinedException; +import org.eclipse.hawkbit.repository.exception.UnsupportedSoftwareModuleForThisDistributionSetException; +import org.eclipse.hawkbit.repository.model.Action; +import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.DistributionSetIdName; +import org.eclipse.hawkbit.repository.model.DistributionSetMetadata; +import org.eclipse.hawkbit.repository.model.DistributionSetTag; +import org.eclipse.hawkbit.repository.model.DistributionSetType; +import org.eclipse.hawkbit.repository.model.SoftwareModule; +import org.eclipse.hawkbit.repository.model.SoftwareModuleType; +import org.eclipse.hawkbit.repository.model.Target; +import org.eclipse.hawkbit.repository.model.TargetInfo; +import org.eclipse.persistence.annotations.CascadeOnDelete; + +/** + *

+ * The {@link DistributionSet} is defined in the SP repository and contains at + * least an OS and an Agent Hub. + *

+ * + *

+ * A {@link Target} has exactly one target {@link DistributionSet} assigned. + *

+ * + */ +@Entity +@Table(name = "sp_distribution_set", uniqueConstraints = { + @UniqueConstraint(columnNames = { "name", "version", "tenant" }, name = "uk_distrib_set") }, indexes = { + @Index(name = "sp_idx_distribution_set_01", columnList = "tenant,deleted,name,complete"), + @Index(name = "sp_idx_distribution_set_02", columnList = "tenant,required_migration_step"), + @Index(name = "sp_idx_distribution_set_prim", columnList = "tenant,id") }) +@NamedEntityGraph(name = "DistributionSet.detail", attributeNodes = { @NamedAttributeNode("modules"), + @NamedAttributeNode("tags"), @NamedAttributeNode("type") }) +public class JpaDistributionSet extends JpaNamedVersionedEntity implements DistributionSet { + private static final long serialVersionUID = 1L; + + @Column(name = "required_migration_step") + private boolean requiredMigrationStep = false; + + @ManyToMany(targetEntity = JpaSoftwareModule.class, fetch = FetchType.LAZY) + @JoinTable(name = "sp_ds_module", joinColumns = { + @JoinColumn(name = "ds_id", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_module_ds")) }, inverseJoinColumns = { + @JoinColumn(name = "module_id", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_module_module")) }) + private final Set modules = new HashSet<>(); + + @ManyToMany(targetEntity = JpaDistributionSetTag.class) + @JoinTable(name = "sp_ds_dstag", joinColumns = { + @JoinColumn(name = "ds", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_dstag_ds")) }, inverseJoinColumns = { + @JoinColumn(name = "TAG", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_dstag_tag")) }) + private Set tags = new HashSet<>(); + + @Column(name = "deleted") + private boolean deleted = false; + + @OneToMany(mappedBy = "assignedDistributionSet", targetEntity = JpaTarget.class, fetch = FetchType.LAZY) + private List assignedToTargets; + + @OneToMany(mappedBy = "installedDistributionSet", targetEntity = JpaTargetInfo.class, fetch = FetchType.LAZY) + private List installedAtTargets; + + @OneToMany(mappedBy = "distributionSet", targetEntity = JpaAction.class, fetch = FetchType.LAZY) + private List actions; + + @CascadeOnDelete + @OneToMany(fetch = FetchType.LAZY, targetEntity = JpaDistributionSetMetadata.class, cascade = { + CascadeType.REMOVE }) + @JoinColumn(name = "ds_id", insertable = false, updatable = false) + private final List metadata = new ArrayList<>(); + + @ManyToOne(fetch = FetchType.LAZY, targetEntity = JpaDistributionSetType.class) + @JoinColumn(name = "ds_id", nullable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_dstype_ds")) + private DistributionSetType type; + + @Column(name = "complete") + private boolean complete = false; + + /** + * Default constructor. + */ + public JpaDistributionSet() { + super(); + } + + /** + * Parameterized constructor. + * + * @param name + * of the {@link DistributionSet} + * @param version + * of the {@link DistributionSet} + * @param description + * of the {@link DistributionSet} + * @param type + * of the {@link DistributionSet} + * @param moduleList + * {@link SoftwareModule}s of the {@link DistributionSet} + */ + public JpaDistributionSet(final String name, final String version, final String description, + final DistributionSetType type, final Iterable moduleList) { + super(name, version, description); + + this.type = type; + if (moduleList != null) { + moduleList.forEach(this::addModule); + } + if (this.type != null) { + complete = this.type.checkComplete(this); + } + } + + @Override + public Set getTags() { + return tags; + } + + @Override + public boolean isDeleted() { + return deleted; + } + + /** + * @return immutable list of meta data elements. + */ + @Override + public List getMetadata() { + return Collections.unmodifiableList(metadata); + } + + @Override + public List getActions() { + return actions; + } + + @Override + public boolean isRequiredMigrationStep() { + return requiredMigrationStep; + } + + @Override + public DistributionSet setDeleted(final boolean deleted) { + this.deleted = deleted; + return this; + } + + @Override + public DistributionSet setRequiredMigrationStep(final boolean isRequiredMigrationStep) { + requiredMigrationStep = isRequiredMigrationStep; + return this; + } + + @Override + public DistributionSet setTags(final Set tags) { + this.tags = tags; + return this; + } + + /** + * @return the assignedTargets + */ + @Override + public List getAssignedTargets() { + return assignedToTargets; + } + + /** + * @return the installedTargets + */ + @Override + public List getInstalledTargets() { + return installedAtTargets; + } + + @Override + public String toString() { + return "DistributionSet [getName()=" + getName() + ", getOptLockRevision()=" + getOptLockRevision() + + ", getId()=" + getId() + "]"; + } + + /** + * + * @return unmodifiableSet of {@link SoftwareModule}. + */ + @Override + public Set getModules() { + return Collections.unmodifiableSet(modules); + } + + @Override + public DistributionSetIdName getDistributionSetIdName() { + return new DistributionSetIdName(getId(), getName(), getVersion()); + } + + /** + * @param softwareModule + * @return true if the module was added and false + * if it already existed in the set + * + */ + @Override + public boolean addModule(final SoftwareModule softwareModule) { + + // we cannot allow that modules are added without a type defined + if (type == null) { + throw new DistributionSetTypeUndefinedException(); + } + + // check if it is allowed to such a module to this DS type + if (!type.containsModuleType(softwareModule.getType())) { + throw new UnsupportedSoftwareModuleForThisDistributionSetException(); + } + + final Optional found = modules.stream() + .filter(module -> module.getId().equals(softwareModule.getId())).findFirst(); + + if (found.isPresent()) { + return false; + } + + final long allready = modules.stream() + .filter(module -> module.getType().getKey().equals(softwareModule.getType().getKey())).count(); + + if (allready >= softwareModule.getType().getMaxAssignments()) { + final Optional sameKey = modules.stream() + .filter(module -> module.getType().getKey().equals(softwareModule.getType().getKey())).findFirst(); + modules.remove(sameKey.get()); + } + + if (modules.add(softwareModule)) { + complete = type.checkComplete(this); + return true; + } + + return false; + } + + /** + * Removed given {@link SoftwareModule} from this DS instance. + * + * @param softwareModule + * to remove + * @return true if element was found and removed + */ + @Override + public boolean removeModule(final SoftwareModule softwareModule) { + final Optional found = modules.stream() + .filter(module -> module.getId().equals(softwareModule.getId())).findFirst(); + + if (found.isPresent()) { + modules.remove(found.get()); + complete = type.checkComplete(this); + return true; + } + + return false; + + } + + /** + * Searches through modules for the given type. + * + * @param type + * to search for + * @return SoftwareModule of given type or null if not in the + * list. + */ + @Override + public SoftwareModule findFirstModuleByType(final SoftwareModuleType type) { + final Optional result = modules.stream().filter(module -> module.getType().equals(type)) + .findFirst(); + + if (result.isPresent()) { + return result.get(); + } + + return null; + } + + @Override + public DistributionSetType getType() { + return type; + } + + @Override + public void setType(final DistributionSetType type) { + this.type = type; + } + + @Override + public boolean isComplete() { + return complete; + } +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetMetadata.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetMetadata.java new file mode 100644 index 000000000..b73e3c72e --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetMetadata.java @@ -0,0 +1,85 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.jpa.model; + +import javax.persistence.ConstraintMode; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.ForeignKey; +import javax.persistence.Id; +import javax.persistence.IdClass; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; + +import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.DistributionSetMetadata; + +/** + * Meta data for {@link DistributionSet}. + * + */ +@IdClass(DsMetadataCompositeKey.class) +@Entity +@Table(name = "sp_ds_metadata") +public class JpaDistributionSetMetadata extends JpaMetaData implements DistributionSetMetadata { + private static final long serialVersionUID = 1L; + + @Id + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "ds_id", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_metadata_ds")) + private JpaDistributionSet distributionSet; + + public JpaDistributionSetMetadata() { + // default public constructor for JPA + } + + public JpaDistributionSetMetadata(final String key, final DistributionSet distributionSet, final String value) { + super(key, value); + this.distributionSet = (JpaDistributionSet) distributionSet; + } + + public DsMetadataCompositeKey getId() { + return new DsMetadataCompositeKey(distributionSet, getKey()); + } + + @Override + public void setDistributionSet(final DistributionSet distributionSet) { + this.distributionSet = (JpaDistributionSet) distributionSet; + } + + @Override + public DistributionSet getDistributionSet() { + return distributionSet; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((distributionSet == null) ? 0 : distributionSet.hashCode()); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (!super.equals(obj)) { + return false; + } + final JpaDistributionSetMetadata other = (JpaDistributionSetMetadata) obj; + if (distributionSet == null) { + if (other.distributionSet != null) { + return false; + } + } else if (!distributionSet.equals(other.distributionSet)) { + return false; + } + return true; + } +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetTag.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetTag.java new file mode 100644 index 000000000..4b6e67135 --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetTag.java @@ -0,0 +1,90 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.jpa.model; + +import java.util.List; + +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.Index; +import javax.persistence.ManyToMany; +import javax.persistence.Table; +import javax.persistence.UniqueConstraint; + +import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.DistributionSetTag; + +/** + * A {@link DistributionSetTag} is used to describe DistributionSet attributes + * and use them also for filtering the DistributionSet list. + * + */ +@Entity +@Table(name = "sp_distributionset_tag", indexes = { + @Index(name = "sp_idx_distribution_set_tag_prim", columnList = "tenant,id") }, uniqueConstraints = @UniqueConstraint(columnNames = { + "name", "tenant" }, name = "uk_ds_tag")) +public class JpaDistributionSetTag extends JpaTag implements DistributionSetTag { + private static final long serialVersionUID = 1L; + + @ManyToMany(mappedBy = "tags", targetEntity = JpaDistributionSet.class, fetch = FetchType.LAZY) + private List assignedToDistributionSet; + + /** + * Public constructor. + * + * @param name + * of the {@link DistributionSetTag} + **/ + public JpaDistributionSetTag(final String name) { + super(name, null, null); + } + + /** + * Public constructor. + * + * @param name + * of the {@link DistributionSetTag} + * @param description + * of the {@link DistributionSetTag} + * @param colour + * of tag in UI + */ + public JpaDistributionSetTag(final String name, final String description, final String colour) { + super(name, description, colour); + } + + public JpaDistributionSetTag() { + super(); + } + + @Override + public List getAssignedToDistributionSet() { + return assignedToDistributionSet; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + this.getClass().getName().hashCode(); + return result; + } + + @Override + public boolean equals(final Object obj) { // NOSONAR - as this is generated + if (!super.equals(obj)) { + return false; + } + if (!(obj instanceof DistributionSetTag)) { + return false; + } + + return true; + } +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetType.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetType.java new file mode 100644 index 000000000..d8edd4dcc --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetType.java @@ -0,0 +1,310 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.jpa.model; + +import java.util.HashSet; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.Index; +import javax.persistence.JoinColumn; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.UniqueConstraint; + +import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.DistributionSetType; +import org.eclipse.hawkbit.repository.model.SoftwareModuleType; + +/** + * A distribution set type defines which software module types can or have to be + * {@link DistributionSet}. + * + */ +@Entity +@Table(name = "sp_distribution_set_type", indexes = { + @Index(name = "sp_idx_distribution_set_type_01", columnList = "tenant,deleted"), + @Index(name = "sp_idx_distribution_set_type_prim", columnList = "tenant,id") }, uniqueConstraints = { + @UniqueConstraint(columnNames = { "name", "tenant" }, name = "uk_dst_name"), + @UniqueConstraint(columnNames = { "type_key", "tenant" }, name = "uk_dst_key") }) +public class JpaDistributionSetType extends JpaNamedEntity implements DistributionSetType { + private static final long serialVersionUID = 1L; + + @OneToMany(targetEntity = DistributionSetTypeElement.class, cascade = { + CascadeType.ALL }, fetch = FetchType.EAGER, orphanRemoval = true) + @JoinColumn(name = "distribution_set_type", insertable = false, updatable = false) + private final Set elements = new HashSet<>(); + + @Column(name = "type_key", nullable = false, length = 64) + private String key; + + @Column(name = "colour", nullable = true, length = 16) + private String colour; + + @Column(name = "deleted") + private boolean deleted = false; + + public JpaDistributionSetType() { + // default public constructor for JPA + } + + /** + * Standard constructor. + * + * @param key + * of the type (unique) + * @param name + * of the type (unique) + * @param description + * of the type + */ + public JpaDistributionSetType(final String key, final String name, final String description) { + this(key, name, description, null); + } + + /** + * Constructor. + * + * @param key + * of the type + * @param name + * of the type + * @param description + * of the type + * @param color + * of the type. It will be null by default + */ + public JpaDistributionSetType(final String key, final String name, final String description, final String color) { + super(name, description); + this.key = key; + colour = color; + } + + /** + * @return the deleted + */ + @Override + public boolean isDeleted() { + return deleted; + } + + /** + * @param deleted + * the deleted to set + */ + @Override + public void setDeleted(final boolean deleted) { + this.deleted = deleted; + } + + @Override + public Set getMandatoryModuleTypes() { + return elements.stream().filter(element -> element.isMandatory()).map(element -> element.getSmType()) + .collect(Collectors.toSet()); + } + + @Override + public Set getOptionalModuleTypes() { + return elements.stream().filter(element -> !element.isMandatory()).map(element -> element.getSmType()) + .collect(Collectors.toSet()); + } + + /** + * Checks if the given {@link SoftwareModuleType} is in this + * {@link DistributionSetType}. + * + * @param softwareModuleType + * search for + * @return true if found + */ + @Override + public boolean containsModuleType(final SoftwareModuleType softwareModuleType) { + for (final DistributionSetTypeElement distributionSetTypeElement : elements) { + if (distributionSetTypeElement.getSmType().equals(softwareModuleType)) { + return true; + } + + } + return false; + } + + /** + * Checks if the given {@link SoftwareModuleType} is in this + * {@link DistributionSetType} and defined as + * {@link DistributionSetTypeElement#isMandatory()}. + * + * @param softwareModuleType + * search for + * @return true if found + */ + @Override + public boolean containsMandatoryModuleType(final SoftwareModuleType softwareModuleType) { + return elements.stream().filter(element -> element.isMandatory()) + .filter(element -> element.getSmType().equals(softwareModuleType)).findFirst().isPresent(); + + } + + /** + * Checks if the given {@link SoftwareModuleType} is in this + * {@link DistributionSetType} and defined as + * {@link DistributionSetTypeElement#isMandatory()}. + * + * @param softwareModuleType + * search for by {@link SoftwareModuleType#getId()} + * @return true if found + */ + @Override + public boolean containsMandatoryModuleType(final Long softwareModuleTypeId) { + return elements.stream().filter(element -> element.isMandatory()) + .filter(element -> element.getSmType().getId().equals(softwareModuleTypeId)).findFirst().isPresent(); + + } + + /** + * Checks if the given {@link SoftwareModuleType} is in this + * {@link DistributionSetType} and NOT defined as + * {@link DistributionSetTypeElement#isMandatory()}. + * + * @param softwareModuleType + * search for + * @return true if found + */ + @Override + public boolean containsOptionalModuleType(final SoftwareModuleType softwareModuleType) { + return elements.stream().filter(element -> !element.isMandatory()) + .filter(element -> element.getSmType().equals(softwareModuleType)).findFirst().isPresent(); + + } + + /** + * Checks if the given {@link SoftwareModuleType} is in this + * {@link DistributionSetType} and NOT defined as + * {@link DistributionSetTypeElement#isMandatory()}. + * + * @param softwareModuleTypeId + * search by {@link SoftwareModuleType#getId()} + * @return true if found + */ + @Override + public boolean containsOptionalModuleType(final Long softwareModuleTypeId) { + return elements.stream().filter(element -> !element.isMandatory()) + .filter(element -> element.getSmType().getId().equals(softwareModuleTypeId)).findFirst().isPresent(); + + } + + /** + * Compares the modules of this {@link DistributionSetType} and the given + * one. + * + * @param dsType + * to compare with + * @return true if the lists are identical. + */ + @Override + public boolean areModuleEntriesIdentical(final DistributionSetType dsType) { + return new HashSet(((JpaDistributionSetType) dsType).elements).equals(elements); + } + + /** + * Adds {@link SoftwareModuleType} that is optional for the + * {@link DistributionSet}. + * + * @param smType + * to add + * @return updated instance + */ + @Override + public DistributionSetType addOptionalModuleType(final SoftwareModuleType smType) { + elements.add(new DistributionSetTypeElement(this, (JpaSoftwareModuleType) smType, false)); + + return this; + } + + /** + * Adds {@link SoftwareModuleType} that is mandatory for the + * {@link DistributionSet}. + * + * @param smType + * to add + * @return updated instance + */ + @Override + public DistributionSetType addMandatoryModuleType(final SoftwareModuleType smType) { + elements.add(new DistributionSetTypeElement(this, (JpaSoftwareModuleType) smType, true)); + + return this; + } + + /** + * Removes {@link SoftwareModuleType} from the list. + * + * @param smTypeId + * to remove + * @return updated instance + */ + @Override + public DistributionSetType removeModuleType(final Long smTypeId) { + // we search by id (standard equals compares also revison) + final Optional found = elements.stream() + .filter(element -> element.getSmType().getId().equals(smTypeId)).findFirst(); + + if (found.isPresent()) { + elements.remove(found.get()); + } + + return this; + } + + @Override + public String getKey() { + return key; + } + + @Override + public void setKey(final String key) { + this.key = key; + } + + /** + * @param distributionSet + * to check for completeness + * @return true if the all mandatory software module types are + * in the system. + */ + @Override + public boolean checkComplete(final DistributionSet distributionSet) { + return distributionSet.getModules().stream().map(module -> module.getType()).collect(Collectors.toList()) + .containsAll(getMandatoryModuleTypes()); + } + + @Override + public String getColour() { + return colour; + } + + @Override + public void setColour(final String colour) { + this.colour = colour; + } + + public Set getElements() { + return elements; + } + + @Override + public String toString() { + return "DistributionSetType [key=" + key + ", isDeleted()=" + isDeleted() + ", getId()=" + getId() + "]"; + } + +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaExternalArtifact.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaExternalArtifact.java new file mode 100644 index 000000000..ab55bf307 --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaExternalArtifact.java @@ -0,0 +1,142 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.jpa.model; + +import java.net.URL; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.ConstraintMode; +import javax.persistence.Entity; +import javax.persistence.ForeignKey; +import javax.persistence.Index; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; +import javax.validation.constraints.NotNull; + +import org.eclipse.hawkbit.repository.model.ExternalArtifact; +import org.eclipse.hawkbit.repository.model.ExternalArtifactProvider; +import org.eclipse.hawkbit.repository.model.SoftwareModule; + +/** + * External artifact representation with all the necessary information to + * generate an artifact {@link URL} at runtime. + * + */ +@Table(name = "sp_external_artifact", indexes = { + @Index(name = "sp_idx_external_artifact_prim", columnList = "id,tenant") }) +@Entity +public class JpaExternalArtifact extends JpaArtifact implements ExternalArtifact { + private static final long serialVersionUID = 1L; + + @ManyToOne + @JoinColumn(name = "provider", nullable = false, updatable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_art_to_ext_provider")) + private JpaExternalArtifactProvider externalArtifactProvider; + + @Column(name = "url_suffix", length = 512) + private String urlSuffix; + + // CascadeType.PERSIST as we register ourself at the BSM + @ManyToOne(optional = false, cascade = { CascadeType.PERSIST }) + @JoinColumn(name = "software_module", nullable = false, updatable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_external_assigned_sm")) + private JpaSoftwareModule softwareModule; + + /** + * Default constructor. + */ + public JpaExternalArtifact() { + super(); + } + + /** + * Constructs {@link ExternalArtifact}. + * + * @param externalArtifactProvider + * of the artifact + * @param urlSuffix + * of the artifact + * @param softwareModule + * of the artifact + */ + public JpaExternalArtifact(@NotNull final ExternalArtifactProvider externalArtifactProvider, final String urlSuffix, + final SoftwareModule softwareModule) { + setSoftwareModule(softwareModule); + this.externalArtifactProvider = (JpaExternalArtifactProvider) externalArtifactProvider; + + if (urlSuffix != null) { + this.urlSuffix = urlSuffix; + } else { + this.urlSuffix = externalArtifactProvider.getDefaultSuffix(); + } + } + + /** + * @return the softwareModule + */ + @Override + public SoftwareModule getSoftwareModule() { + return softwareModule; + } + + @Override + public final void setSoftwareModule(final SoftwareModule softwareModule) { + this.softwareModule = (JpaSoftwareModule) softwareModule; + this.softwareModule.addArtifact(this); + } + + @Override + public ExternalArtifactProvider getExternalArtifactProvider() { + return externalArtifactProvider; + } + + @Override + public String getUrl() { + return new StringBuilder().append(externalArtifactProvider.getBasePath()).append(urlSuffix).toString(); + } + + @Override + public String getUrlSuffix() { + return urlSuffix; + } + + @Override + public void setExternalArtifactProvider(final ExternalArtifactProvider externalArtifactProvider) { + this.externalArtifactProvider = (JpaExternalArtifactProvider) externalArtifactProvider; + } + + /** + * @param urlSuffix + * the urlSuffix to set + */ + @Override + public void setUrlSuffix(final String urlSuffix) { + this.urlSuffix = urlSuffix; + } + + @Override + public int hashCode() { // NOSONAR - as this is generated + final int prime = 31; + int result = super.hashCode(); + result = prime * result + this.getClass().getName().hashCode(); + return result; + } + + @Override + public boolean equals(final Object obj) { // NOSONAR - as this is generated + if (!super.equals(obj)) { + return false; + } + if (!(obj instanceof JpaExternalArtifact)) { + return false; + } + + return true; + } +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaExternalArtifactProvider.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaExternalArtifactProvider.java new file mode 100644 index 000000000..527a90510 --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaExternalArtifactProvider.java @@ -0,0 +1,83 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.jpa.model; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Index; +import javax.persistence.Table; + +import org.eclipse.hawkbit.repository.model.ExternalArtifact; +import org.eclipse.hawkbit.repository.model.ExternalArtifactProvider; + +/** + * External repositories for artifact storage. The SP server provides URLs for + * the targets to download from these external resources but does not access + * them itself. + * + */ +@Table(name = "sp_external_provider", indexes = { + @Index(name = "sp_idx_external_provider_prim", columnList = "tenant,id") }) +@Entity +public class JpaExternalArtifactProvider extends JpaNamedEntity implements ExternalArtifactProvider { + private static final long serialVersionUID = 1L; + + @Column(name = "base_url", length = 512, nullable = false) + private String basePath; + + @Column(name = "default_url_suffix", length = 512, nullable = true) + private String defaultSuffix; + + /** + * Constructs {@link ExternalArtifactProvider} based on given properties. + * + * @param name + * of the provided + * @param description + * which is optional + * @param baseURL + * of all {@link ExternalArtifact}s of the provider + * @param defaultUrlSuffix + * that is used if {@link ExternalArtifact#getUrlSuffix()} is + * empty. + */ + public JpaExternalArtifactProvider(final String name, final String description, final String baseURL, + final String defaultUrlSuffix) { + super(name, description); + basePath = baseURL; + defaultSuffix = defaultUrlSuffix; + } + + JpaExternalArtifactProvider() { + super(); + defaultSuffix = ""; + basePath = ""; + } + + @Override + public String getBasePath() { + return basePath; + } + + @Override + public String getDefaultSuffix() { + return defaultSuffix; + } + + @Override + public void setBasePath(final String basePath) { + this.basePath = basePath; + } + + @Override + public void setDefaultSuffix(final String defaultSuffix) { + this.defaultSuffix = defaultSuffix; + } + +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaLocalArtifact.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaLocalArtifact.java new file mode 100644 index 000000000..7c6de6c0d --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaLocalArtifact.java @@ -0,0 +1,118 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.jpa.model; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.ConstraintMode; +import javax.persistence.Entity; +import javax.persistence.ForeignKey; +import javax.persistence.Index; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; +import javax.validation.constraints.NotNull; + +import org.eclipse.hawkbit.repository.model.LocalArtifact; +import org.eclipse.hawkbit.repository.model.SoftwareModule; + +import com.mongodb.gridfs.GridFS; +import com.mongodb.gridfs.GridFSFile; + +/** + * Tenant specific locally stored artifact representation that is used by + * {@link SoftwareModule} . It contains all information that is provided by the + * user while all SP server generated information related to the artifact (hash, + * length) is stored directly with the binary itself. + * + * + * + */ +@Table(name = "sp_artifact", indexes = { @Index(name = "sp_idx_artifact_01", columnList = "tenant,software_module"), + @Index(name = "sp_idx_artifact_prim", columnList = "tenant,id") }) +@Entity +public class JpaLocalArtifact extends JpaArtifact implements LocalArtifact { + private static final long serialVersionUID = 1L; + + @NotNull + @Column(name = "gridfs_file_name", length = 40) + private String gridFsFileName; + + @NotNull + @Column(name = "provided_file_name", length = 256) + private String filename; + + @ManyToOne(optional = false, cascade = { CascadeType.PERSIST }) + @JoinColumn(name = "software_module", nullable = false, updatable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_assigned_sm")) + private JpaSoftwareModule softwareModule; + + /** + * Default constructor. + */ + public JpaLocalArtifact() { + super(); + } + + /** + * Constructs artifact. + * + * @param gridFsFileName + * that is the link to the {@link GridFS} entity. + * @param filename + * that is used by {@link GridFSFile} store. + * @param softwareModule + * of this artifact + */ + public JpaLocalArtifact(@NotNull final String gridFsFileName, @NotNull final String filename, + final SoftwareModule softwareModule) { + setSoftwareModule(softwareModule); + this.gridFsFileName = gridFsFileName; + this.filename = filename; + } + + @Override + public int hashCode() { // NOSONAR - as this is generated + final int prime = 31; + int result = super.hashCode(); + result = prime * result + this.getClass().getName().hashCode(); + return result; + } + + @Override + public boolean equals(final Object obj) { // NOSONAR - as this is generated + if (!super.equals(obj)) { + return false; + } + if (!(obj instanceof LocalArtifact)) { + return false; + } + + return true; + } + + @Override + public SoftwareModule getSoftwareModule() { + return softwareModule; + } + + @Override + public final void setSoftwareModule(final SoftwareModule softwareModule) { + this.softwareModule = (JpaSoftwareModule) softwareModule; + this.softwareModule.addArtifact(this); + } + + public String getGridFsFileName() { + return gridFsFileName; + } + + @Override + public String getFilename() { + return filename; + } +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaMetaData.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaMetaData.java new file mode 100644 index 000000000..f2d905d89 --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaMetaData.java @@ -0,0 +1,102 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.jpa.model; + +import javax.persistence.Basic; +import javax.persistence.Column; +import javax.persistence.Id; +import javax.persistence.MappedSuperclass; + +import org.eclipse.hawkbit.repository.model.MetaData; + +/** + * Meta data for entities. + * + */ +@MappedSuperclass +public abstract class JpaMetaData implements MetaData { + private static final long serialVersionUID = 1L; + + @Id + @Column(name = "meta_key", length = 128) + private String key; + + @Column(name = "meta_value", length = 4000) + @Basic + private String value; + + public JpaMetaData(final String key, final String value) { + super(); + this.key = key; + this.value = value; + } + + public JpaMetaData() { + // Default constructor needed for JPA entities + } + + @Override + public String getKey() { + return key; + } + + @Override + public void setKey(final String key) { + this.key = key; + } + + @Override + public String getValue() { + return value; + } + + @Override + public void setValue(final String value) { + this.value = value; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((key == null) ? 0 : key.hashCode()); + result = prime * result + ((value == null) ? 0 : value.hashCode()); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (!(this.getClass().isInstance(obj))) { + return false; + } + final JpaMetaData other = (JpaMetaData) obj; + if (key == null) { + if (other.key != null) { + return false; + } + } else if (!key.equals(other.key)) { + return false; + } + if (value == null) { + if (other.value != null) { + return false; + } + } else if (!value.equals(other.value)) { + return false; + } + return true; + } + +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaNamedEntity.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaNamedEntity.java new file mode 100644 index 000000000..e4e48ac36 --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaNamedEntity.java @@ -0,0 +1,70 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.jpa.model; + +import javax.persistence.Column; +import javax.persistence.MappedSuperclass; + +import org.eclipse.hawkbit.repository.model.NamedEntity; +import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity; + +/** + * {@link TenantAwareBaseEntity} extension for all entities that are named in + * addition to their technical ID. + */ +@MappedSuperclass +public abstract class JpaNamedEntity extends JpaTenantAwareBaseEntity implements NamedEntity { + private static final long serialVersionUID = 1L; + + @Column(name = "name", nullable = false, length = 64) + private String name; + + @Column(name = "description", nullable = true, length = 512) + private String description; + + /** + * Default constructor. + */ + public JpaNamedEntity() { + super(); + } + + /** + * Parameterized constructor. + * + * @param name + * of the {@link NamedEntity} + * @param description + * of the {@link NamedEntity} + */ + public JpaNamedEntity(final String name, final String description) { + this.name = name; + this.description = description; + } + + @Override + public String getDescription() { + return description; + } + + @Override + public String getName() { + return name; + } + + @Override + public void setDescription(final String description) { + this.description = description; + } + + @Override + public void setName(final String name) { + this.name = name; + } +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaNamedVersionedEntity.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaNamedVersionedEntity.java new file mode 100644 index 000000000..33a7036d5 --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaNamedVersionedEntity.java @@ -0,0 +1,55 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.jpa.model; + +import javax.persistence.Column; +import javax.persistence.MappedSuperclass; + +import org.eclipse.hawkbit.repository.model.NamedEntity; +import org.eclipse.hawkbit.repository.model.NamedVersionedEntity; + +/** + * Extension for {@link NamedEntity} that are versioned. + * + */ +@MappedSuperclass +public abstract class JpaNamedVersionedEntity extends JpaNamedEntity implements NamedVersionedEntity { + private static final long serialVersionUID = 1L; + + @Column(name = "version", nullable = false, length = 64) + private String version; + + /** + * parameterized constructor. + * + * @param name + * of the entity + * @param version + * of the entity + * @param description + */ + public JpaNamedVersionedEntity(final String name, final String version, final String description) { + super(name, description); + this.version = version; + } + + JpaNamedVersionedEntity() { + super(); + } + + @Override + public String getVersion() { + return version; + } + + @Override + public void setVersion(final String version) { + this.version = version; + } +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRollout.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRollout.java new file mode 100644 index 000000000..25e1a3a93 --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRollout.java @@ -0,0 +1,260 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.jpa.model; + +import java.util.List; + +import javax.persistence.Column; +import javax.persistence.ConstraintMode; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.FetchType; +import javax.persistence.ForeignKey; +import javax.persistence.Index; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.Transient; +import javax.persistence.UniqueConstraint; + +import org.eclipse.hawkbit.cache.CacheField; +import org.eclipse.hawkbit.cache.CacheKeys; +import org.eclipse.hawkbit.repository.model.Action.ActionType; +import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.Rollout; +import org.eclipse.hawkbit.repository.model.RolloutGroup; +import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; + +/** + * @author Michael Hirsch + * + */ +@Entity +@Table(name = "sp_rollout", indexes = { + @Index(name = "sp_idx_rollout_01", columnList = "tenant,name") }, uniqueConstraints = @UniqueConstraint(columnNames = { + "name", "tenant" }, name = "uk_rollout")) +public class JpaRollout extends JpaNamedEntity implements Rollout { + + private static final long serialVersionUID = 1L; + + @OneToMany(targetEntity = JpaRolloutGroup.class) + @JoinColumn(name = "rollout", insertable = false, updatable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_rollout_rolloutgroup")) + private List rolloutGroups; + + @Column(name = "target_filter", length = 1024, nullable = false) + private String targetFilterQuery; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "distribution_set", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_rolltout_ds")) + private JpaDistributionSet distributionSet; + + @Column(name = "status") + private RolloutStatus status = RolloutStatus.CREATING; + + @Column(name = "last_check") + private long lastCheck = 0L; + + @Column(name = "action_type", nullable = false) + @Enumerated(EnumType.STRING) + private ActionType actionType = ActionType.FORCED; + + @Column(name = "forced_time") + private long forcedTime; + + @Column(name = "total_targets") + private long totalTargets; + + @Transient + @CacheField(key = CacheKeys.ROLLOUT_GROUP_TOTAL) + private int rolloutGroupsTotal = 0; + + @Transient + @CacheField(key = CacheKeys.ROLLOUT_GROUP_CREATED) + private int rolloutGroupsCreated = 0; + + @Transient + private transient TotalTargetCountStatus totalTargetCountStatus; + + @Override + public DistributionSet getDistributionSet() { + return distributionSet; + } + + @Override + public void setDistributionSet(final DistributionSet distributionSet) { + this.distributionSet = (JpaDistributionSet) distributionSet; + } + + @Override + public List getRolloutGroups() { + return rolloutGroups; + } + + @Override + public void setRolloutGroups(final List rolloutGroups) { + this.rolloutGroups = rolloutGroups; + } + + @Override + public String getTargetFilterQuery() { + return targetFilterQuery; + } + + @Override + public void setTargetFilterQuery(final String targetFilterQuery) { + this.targetFilterQuery = targetFilterQuery; + } + + @Override + public RolloutStatus getStatus() { + return status; + } + + @Override + public void setStatus(final RolloutStatus status) { + this.status = status; + } + + @Override + public long getLastCheck() { + return lastCheck; + } + + @Override + public void setLastCheck(final long lastCheck) { + this.lastCheck = lastCheck; + } + + @Override + public ActionType getActionType() { + return actionType; + } + + @Override + public void setActionType(final ActionType actionType) { + this.actionType = actionType; + } + + @Override + public long getForcedTime() { + return forcedTime; + } + + @Override + public void setForcedTime(final long forcedTime) { + this.forcedTime = forcedTime; + } + + @Override + public long getTotalTargets() { + return totalTargets; + } + + @Override + public void setTotalTargets(final long totalTargets) { + this.totalTargets = totalTargets; + } + + @Override + public int getRolloutGroupsTotal() { + return rolloutGroupsTotal; + } + + @Override + public void setRolloutGroupsTotal(final int rolloutGroupsTotal) { + this.rolloutGroupsTotal = rolloutGroupsTotal; + } + + @Override + public int getRolloutGroupsCreated() { + return rolloutGroupsCreated; + } + + @Override + public void setRolloutGroupsCreated(final int rolloutGroupsCreated) { + this.rolloutGroupsCreated = rolloutGroupsCreated; + } + + @Override + public TotalTargetCountStatus getTotalTargetCountStatus() { + if (totalTargetCountStatus == null) { + totalTargetCountStatus = new TotalTargetCountStatus(totalTargets); + } + return totalTargetCountStatus; + } + + @Override + public void setTotalTargetCountStatus(final TotalTargetCountStatus totalTargetCountStatus) { + this.totalTargetCountStatus = totalTargetCountStatus; + } + + @Override + public String toString() { + return "Rollout [rolloutGroups=" + rolloutGroups + ", targetFilterQuery=" + targetFilterQuery + + ", distributionSet=" + distributionSet + ", status=" + status + ", lastCheck=" + lastCheck + + ", getName()=" + getName() + ", getId()=" + getId() + "]"; + } + + /** + * + * State machine for rollout. + * + */ + public enum RolloutStatus { + + /** + * Rollouts is beeing created. + */ + CREATING, + + /** + * Rollout is ready to start. + */ + READY, + + /** + * Rollout is paused. + */ + PAUSED, + + /** + * Rollout is starting. + */ + STARTING, + + /** + * Rollout is stopped. + */ + STOPPED, + + /** + * Rollout is running. + */ + RUNNING, + + /** + * Rollout is finished. + */ + FINISHED, + + /** + * Rollout could not created due errors, might be database problem due + * asynchronous creating. + */ + ERROR_CREATING, + + /** + * Rollout could not started due errors, might be database problem due + * asynchronous starting. + */ + ERROR_STARTING; + } +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRolloutGroup.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRolloutGroup.java new file mode 100644 index 000000000..f167d89fd --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRolloutGroup.java @@ -0,0 +1,509 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.jpa.model; + +import java.util.ArrayList; +import java.util.List; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.ConstraintMode; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.ForeignKey; +import javax.persistence.Index; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.Transient; +import javax.persistence.UniqueConstraint; + +import org.eclipse.hawkbit.repository.model.Rollout; +import org.eclipse.hawkbit.repository.model.RolloutGroup; +import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; + +/** + * JPA entity definition of persisting a group of an rollout. + * + * @author Michael Hirsch + * + */ +@Entity +@Table(name = "sp_rolloutgroup", indexes = { + @Index(name = "sp_idx_rolloutgroup_01", columnList = "tenant,name") }, uniqueConstraints = @UniqueConstraint(columnNames = { + "name", "rollout", "tenant" }, name = "uk_rolloutgroup")) +public class JpaRolloutGroup extends JpaNamedEntity implements RolloutGroup { + + private static final long serialVersionUID = 1L; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "rollout", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_rolloutgroup_rollout")) + private JpaRollout rollout; + + @Column(name = "status") + private RolloutGroupStatus status = RolloutGroupStatus.READY; + + @OneToMany(fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST }, targetEntity = RolloutTargetGroup.class) + @JoinColumn(name = "rolloutGroup_Id", insertable = false, updatable = false) + private final List rolloutTargetGroup = new ArrayList<>(); + + @ManyToOne(fetch = FetchType.LAZY) + private JpaRolloutGroup parent; + + @Column(name = "success_condition", nullable = false) + private RolloutGroupSuccessCondition successCondition = RolloutGroupSuccessCondition.THRESHOLD; + + @Column(name = "success_condition_exp", length = 512, nullable = false) + private String successConditionExp = null; + + @Column(name = "success_action", nullable = false) + private RolloutGroupSuccessAction successAction = RolloutGroupSuccessAction.NEXTGROUP; + + @Column(name = "success_action_exp", length = 512, nullable = false) + private String successActionExp = null; + + @Column(name = "error_condition") + private RolloutGroupErrorCondition errorCondition = null; + + @Column(name = "error_condition_exp", length = 512) + private String errorConditionExp = null; + + @Column(name = "error_action") + private RolloutGroupErrorAction errorAction = null; + + @Column(name = "error_action_exp", length = 512) + private String errorActionExp = null; + + @Column(name = "total_targets") + private long totalTargets; + + @Transient + private transient TotalTargetCountStatus totalTargetCountStatus; + + @Override + public Rollout getRollout() { + return rollout; + } + + @Override + public void setRollout(final Rollout rollout) { + this.rollout = (JpaRollout) rollout; + } + + @Override + public RolloutGroupStatus getStatus() { + return status; + } + + @Override + public void setStatus(final RolloutGroupStatus status) { + this.status = status; + } + + public List getRolloutTargetGroup() { + return rolloutTargetGroup; + } + + @Override + public RolloutGroup getParent() { + return parent; + } + + @Override + public void setParent(final RolloutGroup parent) { + this.parent = (JpaRolloutGroup) parent; + } + + @Override + public RolloutGroupSuccessCondition getSuccessCondition() { + return successCondition; + } + + @Override + public void setSuccessCondition(final RolloutGroupSuccessCondition finishCondition) { + successCondition = finishCondition; + } + + @Override + public String getSuccessConditionExp() { + return successConditionExp; + } + + @Override + public void setSuccessConditionExp(final String finishExp) { + successConditionExp = finishExp; + } + + @Override + public RolloutGroupErrorCondition getErrorCondition() { + return errorCondition; + } + + @Override + public void setErrorCondition(final RolloutGroupErrorCondition errorCondition) { + this.errorCondition = errorCondition; + } + + @Override + public String getErrorConditionExp() { + return errorConditionExp; + } + + @Override + public void setErrorConditionExp(final String errorExp) { + errorConditionExp = errorExp; + } + + @Override + public RolloutGroupErrorAction getErrorAction() { + return errorAction; + } + + @Override + public void setErrorAction(final RolloutGroupErrorAction errorAction) { + this.errorAction = errorAction; + } + + @Override + public String getErrorActionExp() { + return errorActionExp; + } + + @Override + public void setErrorActionExp(final String errorActionExp) { + this.errorActionExp = errorActionExp; + } + + @Override + public RolloutGroupSuccessAction getSuccessAction() { + return successAction; + } + + @Override + public String getSuccessActionExp() { + return successActionExp; + } + + @Override + public long getTotalTargets() { + return totalTargets; + } + + @Override + public void setTotalTargets(final long totalTargets) { + this.totalTargets = totalTargets; + } + + @Override + public void setSuccessAction(final RolloutGroupSuccessAction successAction) { + this.successAction = successAction; + } + + @Override + public void setSuccessActionExp(final String successActionExp) { + this.successActionExp = successActionExp; + } + + /** + * @return the totalTargetCountStatus + */ + @Override + public TotalTargetCountStatus getTotalTargetCountStatus() { + if (totalTargetCountStatus == null) { + totalTargetCountStatus = new TotalTargetCountStatus(totalTargets); + } + return totalTargetCountStatus; + } + + /** + * @param totalTargetCountStatus + * the totalTargetCountStatus to set + */ + @Override + public void setTotalTargetCountStatus(final TotalTargetCountStatus totalTargetCountStatus) { + this.totalTargetCountStatus = totalTargetCountStatus; + } + + @Override + public String toString() { + return "RolloutGroup [rollout=" + rollout + ", status=" + status + ", rolloutTargetGroup=" + rolloutTargetGroup + + ", parent=" + parent + ", finishCondition=" + successCondition + ", finishExp=" + successConditionExp + + ", errorCondition=" + errorCondition + ", errorExp=" + errorConditionExp + ", getName()=" + getName() + + ", getId()=" + getId() + "]"; + } + + /** + * Rollout goup state machine. + * + */ + public enum RolloutGroupStatus { + + /** + * Ready to start the group. + */ + READY, + + /** + * Group is scheduled and started sometime, e.g. trigger of group + * before. + */ + SCHEDULED, + + /** + * Group is finished. + */ + FINISHED, + + /** + * Group is finished and has errors. + */ + ERROR, + + /** + * Group is running. + */ + RUNNING; + } + + /** + * The condition to evaluate if an group is success state. + */ + public enum RolloutGroupSuccessCondition { + THRESHOLD("thresholdRolloutGroupSuccessCondition"); + + private final String beanName; + + private RolloutGroupSuccessCondition(final String beanName) { + this.beanName = beanName; + } + + /** + * @return the beanName + */ + public String getBeanName() { + return beanName; + } + } + + /** + * The condition to evaluate if an group is in error state. + */ + public enum RolloutGroupErrorCondition { + THRESHOLD("thresholdRolloutGroupErrorCondition"); + + private final String beanName; + + private RolloutGroupErrorCondition(final String beanName) { + this.beanName = beanName; + } + + /** + * @return the beanName + */ + public String getBeanName() { + return beanName; + } + } + + /** + * The actions executed when the {@link RolloutGroup#errorCondition} is hit. + */ + public enum RolloutGroupErrorAction { + PAUSE("pauseRolloutGroupAction"); + + private final String beanName; + + private RolloutGroupErrorAction(final String beanName) { + this.beanName = beanName; + } + + /** + * @return the beanName + */ + public String getBeanName() { + return beanName; + } + } + + /** + * The actions executed when the {@link RolloutGroup#successCondition} is + * hit. + */ + public enum RolloutGroupSuccessAction { + NEXTGROUP("startNextRolloutGroupAction"); + + private final String beanName; + + private RolloutGroupSuccessAction(final String beanName) { + this.beanName = beanName; + } + + /** + * @return the beanName + */ + public String getBeanName() { + return beanName; + } + } + + /** + * Object which holds all {@link RolloutGroup} conditions together which can + * easily built. + */ + public static class RolloutGroupConditions { + private RolloutGroupSuccessCondition successCondition = null; + private String successConditionExp = null; + private RolloutGroupSuccessAction successAction = null; + private String successActionExp = null; + private RolloutGroupErrorCondition errorCondition = null; + private String errorConditionExp = null; + private RolloutGroupErrorAction errorAction = null; + private String errorActionExp = null; + + public RolloutGroupSuccessCondition getSuccessCondition() { + return successCondition; + } + + public void setSuccessCondition(final RolloutGroupSuccessCondition finishCondition) { + successCondition = finishCondition; + } + + public String getSuccessConditionExp() { + return successConditionExp; + } + + public void setSuccessConditionExp(final String finishConditionExp) { + successConditionExp = finishConditionExp; + } + + public RolloutGroupSuccessAction getSuccessAction() { + return successAction; + } + + public void setSuccessAction(final RolloutGroupSuccessAction successAction) { + this.successAction = successAction; + } + + public String getSuccessActionExp() { + return successActionExp; + } + + public void setSuccessActionExp(final String successActionExp) { + this.successActionExp = successActionExp; + } + + public RolloutGroupErrorCondition getErrorCondition() { + return errorCondition; + } + + public void setErrorCondition(final RolloutGroupErrorCondition errorCondition) { + this.errorCondition = errorCondition; + } + + public String getErrorConditionExp() { + return errorConditionExp; + } + + public void setErrorConditionExp(final String errorConditionExp) { + this.errorConditionExp = errorConditionExp; + } + + public RolloutGroupErrorAction getErrorAction() { + return errorAction; + } + + public void setErrorAction(final RolloutGroupErrorAction errorAction) { + this.errorAction = errorAction; + } + + public String getErrorActionExp() { + return errorActionExp; + } + + public void setErrorActionExp(final String errorActionExp) { + this.errorActionExp = errorActionExp; + } + } + + /** + * Builder to build easily the {@link RolloutGroupConditions}. + * + */ + public static class RolloutGroupConditionBuilder { + private final RolloutGroupConditions conditions = new RolloutGroupConditions(); + + public RolloutGroupConditions build() { + return conditions; + } + + /** + * Sets the finish condition and expression on the builder. + * + * @param condition + * the finish condition + * @param expression + * the finish expression + * @return the builder itself + */ + public RolloutGroupConditionBuilder successCondition(final RolloutGroupSuccessCondition condition, + final String expression) { + conditions.setSuccessCondition(condition); + conditions.setSuccessConditionExp(expression); + return this; + } + + /** + * Sets the success action and expression on the builder. + * + * @param action + * the success action + * @param expression + * the error expression + * @return the builder itself + */ + public RolloutGroupConditionBuilder successAction(final RolloutGroupSuccessAction action, + final String expression) { + conditions.setSuccessAction(action); + conditions.setSuccessActionExp(expression); + return this; + } + + /** + * Sets the error condition and expression on the builder. + * + * @param condition + * the error condition + * @param expression + * the error expression + * @return the builder itself + */ + public RolloutGroupConditionBuilder errorCondition(final RolloutGroupErrorCondition condition, + final String expression) { + conditions.setErrorCondition(condition); + conditions.setErrorConditionExp(expression); + return this; + } + + /** + * Sets the error action and expression on the builder. + * + * @param action + * the error action + * @param expression + * the error expression + * @return the builder itself + */ + public RolloutGroupConditionBuilder errorAction(final RolloutGroupErrorAction action, final String expression) { + conditions.setErrorAction(action); + conditions.setErrorActionExp(expression); + return this; + } + } +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModule.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModule.java new file mode 100644 index 000000000..306b6980b --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModule.java @@ -0,0 +1,266 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.jpa.model; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Optional; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.ConstraintMode; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.ForeignKey; +import javax.persistence.Index; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToMany; +import javax.persistence.ManyToOne; +import javax.persistence.NamedAttributeNode; +import javax.persistence.NamedEntityGraph; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import javax.persistence.UniqueConstraint; + +import org.eclipse.hawkbit.repository.model.Artifact; +import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.ExternalArtifact; +import org.eclipse.hawkbit.repository.model.LocalArtifact; +import org.eclipse.hawkbit.repository.model.SoftwareModule; +import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata; +import org.eclipse.hawkbit.repository.model.SoftwareModuleType; +import org.eclipse.persistence.annotations.CascadeOnDelete; + +/** + * Base Software Module that is supported by OS level provisioning mechanism on + * the edge controller, e.g. OS, JVM, AgentHub. + * + */ +@Entity +@Table(name = "sp_base_software_module", uniqueConstraints = @UniqueConstraint(columnNames = { "module_type", "name", + "version", "tenant" }, name = "uk_base_sw_mod"), indexes = { + @Index(name = "sp_idx_base_sw_module_01", columnList = "tenant,deleted,name,version"), + @Index(name = "sp_idx_base_sw_module_02", columnList = "tenant,deleted,module_type"), + @Index(name = "sp_idx_base_sw_module_prim", columnList = "tenant,id") }) +@NamedEntityGraph(name = "SoftwareModule.artifacts", attributeNodes = { @NamedAttributeNode("artifacts") }) +public class JpaSoftwareModule extends JpaNamedVersionedEntity implements SoftwareModule { + private static final long serialVersionUID = 1L; + + @ManyToOne + @JoinColumn(name = "module_type", nullable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_module_type")) + private JpaSoftwareModuleType type; + + @ManyToMany(mappedBy = "modules", targetEntity = JpaDistributionSet.class, fetch = FetchType.LAZY) + private final List assignedTo = new ArrayList<>(); + + @Column(name = "deleted") + private boolean deleted = false; + + @Column(name = "vendor", nullable = true, length = 256) + private String vendor; + + @OneToMany(mappedBy = "softwareModule", cascade = { CascadeType.ALL }, targetEntity = JpaLocalArtifact.class) + private List artifacts; + + @OneToMany(mappedBy = "softwareModule", cascade = { CascadeType.ALL }, targetEntity = JpaExternalArtifact.class) + private List externalArtifacts; + + @CascadeOnDelete + @OneToMany(fetch = FetchType.LAZY, cascade = { CascadeType.REMOVE }, targetEntity = JpaSoftwareModuleMetadata.class) + @JoinColumn(name = "sw_id", insertable = false, updatable = false) + private final List metadata = new ArrayList<>(); + + /** + * Default constructor. + */ + public JpaSoftwareModule() { + super(); + } + + /** + * parameterized constructor. + * + * @param type + * of the {@link SoftwareModule} + * @param name + * abstract name of the {@link SoftwareModule} + * @param version + * of the {@link SoftwareModule} + * @param description + * of the {@link SoftwareModule} + * @param vendor + * of the {@link SoftwareModule} + */ + public JpaSoftwareModule(final SoftwareModuleType type, final String name, final String version, + final String description, final String vendor) { + super(name, version, description); + this.vendor = vendor; + this.type = (JpaSoftwareModuleType) type; + } + + /** + * @param artifact + * is added to the assigned {@link Artifact}s. + */ + @Override + public void addArtifact(final LocalArtifact artifact) { + if (null == artifacts) { + artifacts = new ArrayList<>(4); + } + + if (!artifacts.contains(artifact)) { + artifacts.add(artifact); + } + } + + /** + * @param artifact + * is added to the assigned {@link Artifact}s. + */ + @Override + public void addArtifact(final ExternalArtifact artifact) { + if (null == externalArtifacts) { + externalArtifacts = new ArrayList<>(4); + } + + if (!externalArtifacts.contains(artifact)) { + externalArtifacts.add(artifact); + } + + } + + /** + * @param artifactId + * to look for + * @return found {@link Artifact} + */ + @Override + public Optional getLocalArtifact(final Long artifactId) { + if (null == artifacts) { + return Optional.empty(); + } + + return artifacts.stream().filter(artifact -> artifact.getId().equals(artifactId)).findFirst(); + } + + /** + * @param fileName + * to look for + * @return found {@link Artifact} + */ + @Override + public Optional getLocalArtifactByFilename(final String fileName) { + if (null == artifacts) { + return Optional.empty(); + } + + return artifacts.stream().filter(artifact -> artifact.getFilename().equalsIgnoreCase(fileName.trim())) + .findFirst(); + } + + /** + * @return the artifacts + */ + @Override + public List getArtifacts() { + final List result = new ArrayList<>(); + result.addAll(artifacts); + result.addAll(externalArtifacts); + + return result; + } + + /** + * @return local artifacts only + */ + @Override + public List getLocalArtifacts() { + if (artifacts == null) { + return Collections.emptyList(); + } + + return artifacts; + } + + @Override + public String getVendor() { + return vendor; + } + + /** + * @param artifact + * is removed from the assigned {@link LocalArtifact}s. + */ + @Override + public void removeArtifact(final LocalArtifact artifact) { + if (null != artifacts) { + artifacts.remove(artifact); + } + } + + /** + * @param artifact + * is removed from the assigned {@link ExternalArtifact}s. + */ + @Override + public void removeArtifact(final ExternalArtifact artifact) { + if (null != externalArtifacts) { + externalArtifacts.remove(artifact); + } + } + + @Override + public void setVendor(final String vendor) { + this.vendor = vendor; + } + + @Override + public SoftwareModuleType getType() { + return type; + } + + @Override + public boolean isDeleted() { + return deleted; + } + + @Override + public void setDeleted(final boolean deleted) { + this.deleted = deleted; + } + + @Override + public void setType(final SoftwareModuleType type) { + this.type = (JpaSoftwareModuleType) type; + } + + /** + * @return immutable list of meta data elements. + */ + @Override + public List getMetadata() { + return Collections.unmodifiableList(metadata); + } + + @Override + public String toString() { + return "SoftwareModule [deleted=" + deleted + ", name=" + getName() + ", version=" + getVersion() + + ", revision=" + getOptLockRevision() + ", Id=" + getId() + ", type=" + getType().getName() + "]"; + } + + /** + * @return the assignedTo + */ + @Override + public List getAssignedTo() { + return assignedTo; + } + +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModuleMetadata.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModuleMetadata.java new file mode 100644 index 000000000..aba08f0ed --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModuleMetadata.java @@ -0,0 +1,85 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.jpa.model; + +import javax.persistence.ConstraintMode; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.ForeignKey; +import javax.persistence.Id; +import javax.persistence.IdClass; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; + +import org.eclipse.hawkbit.repository.model.SoftwareModule; +import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata; + +/** + * Metadata for {@link SoftwareModule}. + * + */ +@IdClass(SwMetadataCompositeKey.class) +@Entity +@Table(name = "sp_sw_metadata") +public class JpaSoftwareModuleMetadata extends JpaMetaData implements SoftwareModuleMetadata { + private static final long serialVersionUID = 1L; + + @Id + @ManyToOne(targetEntity = JpaSoftwareModule.class, fetch = FetchType.LAZY) + @JoinColumn(name = "sw_id", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_metadata_sw")) + private SoftwareModule softwareModule; + + public JpaSoftwareModuleMetadata() { + // default public constructor for JPA + } + + public JpaSoftwareModuleMetadata(final String key, final SoftwareModule softwareModule, final String value) { + super(key, value); + this.softwareModule = softwareModule; + } + + public SwMetadataCompositeKey getId() { + return new SwMetadataCompositeKey(softwareModule, getKey()); + } + + @Override + public SoftwareModule getSoftwareModule() { + return softwareModule; + } + + @Override + public void setSoftwareModule(final SoftwareModule softwareModule) { + this.softwareModule = softwareModule; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((softwareModule == null) ? 0 : softwareModule.hashCode()); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (!super.equals(obj)) { + return false; + } + final JpaSoftwareModuleMetadata other = (JpaSoftwareModuleMetadata) obj; + if (softwareModule == null) { + if (other.softwareModule != null) { + return false; + } + } else if (!softwareModule.equals(other.softwareModule)) { + return false; + } + return true; + } +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModuleType.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModuleType.java new file mode 100644 index 000000000..9948a7cde --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModuleType.java @@ -0,0 +1,125 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.jpa.model; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Index; +import javax.persistence.Table; +import javax.persistence.UniqueConstraint; + +import org.eclipse.hawkbit.repository.model.SoftwareModuleType; + +/** + * Type of a software modules. + * + */ +@Entity +@Table(name = "sp_software_module_type", indexes = { + @Index(name = "sp_idx_software_module_type_01", columnList = "tenant,deleted"), + @Index(name = "sp_idx_software_module_type_prim", columnList = "tenant,id") }, uniqueConstraints = { + @UniqueConstraint(columnNames = { "type_key", "tenant" }, name = "uk_smt_type_key"), + @UniqueConstraint(columnNames = { "name", "tenant" }, name = "uk_smt_name") }) +public class JpaSoftwareModuleType extends JpaNamedEntity implements SoftwareModuleType { + private static final long serialVersionUID = 1L; + + @Column(name = "type_key", nullable = false, length = 64) + private String key; + + @Column(name = "max_ds_assignments", nullable = false) + private int maxAssignments; + + @Column(name = "colour", nullable = true, length = 16) + private String colour; + + @Column(name = "deleted") + private boolean deleted = false; + + /** + * Constructor. + * + * @param key + * of the type + * @param name + * of the type + * @param description + * of the type + * @param maxAssignments + * assignments to a DS + */ + public JpaSoftwareModuleType(final String key, final String name, final String description, final int maxAssignments) { + this(key, name, description, maxAssignments, null); + } + + /** + * Constructor. + * + * @param key + * of the type + * @param name + * of the type + * @param description + * of the type + * @param maxAssignments + * assignments to a DS + * @param colour + * of the type. It will be null by default + */ + public JpaSoftwareModuleType(final String key, final String name, final String description, final int maxAssignments, + final String colour) { + super(); + this.key = key; + this.maxAssignments = maxAssignments; + setDescription(description); + setName(name); + this.colour = colour; + } + + /** + * Default Constructor. + */ + public JpaSoftwareModuleType() { + super(); + } + + @Override + public String getKey() { + return key; + } + + @Override + public int getMaxAssignments() { + return maxAssignments; + } + + @Override + public boolean isDeleted() { + return deleted; + } + + @Override + public void setDeleted(final boolean deleted) { + this.deleted = deleted; + } + + @Override + public String getColour() { + return colour; + } + + @Override + public void setColour(final String colour) { + this.colour = colour; + } + + @Override + public String toString() { + return "SoftwareModuleType [key=" + key + ", getName()=" + getName() + ", getId()=" + getId() + "]"; + } +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTag.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTag.java new file mode 100644 index 000000000..ee4da0824 --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTag.java @@ -0,0 +1,61 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.jpa.model; + +import javax.persistence.Column; +import javax.persistence.MappedSuperclass; + +import org.eclipse.hawkbit.repository.model.Tag; + +/** + * A Tag can be used as describing and organizational meta information for any + * kind of entity. + * + */ +@MappedSuperclass +public abstract class JpaTag extends JpaNamedEntity implements Tag { + private static final long serialVersionUID = 1L; + + @Column(name = "colour", nullable = true, length = 16) + private String colour; + + protected JpaTag() { + super(); + } + + /** + * Public constructor. + * + * @param name + * of the {@link Tag} + * @param description + * of the {@link Tag} + * @param colour + * of tag in UI + */ + public JpaTag(final String name, final String description, final String colour) { + super(name, description); + this.colour = colour; + } + + @Override + public String getColour() { + return colour; + } + + @Override + public void setColour(final String colour) { + this.colour = colour; + } + + @Override + public String toString() { + return "Tag [getOptLockRevision()=" + getOptLockRevision() + ", getId()=" + getId() + "]"; + } +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTarget.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTarget.java new file mode 100644 index 000000000..08a66a9b3 --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTarget.java @@ -0,0 +1,237 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.jpa.model; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.ConstraintMode; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.ForeignKey; +import javax.persistence.Index; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.ManyToMany; +import javax.persistence.ManyToOne; +import javax.persistence.NamedAttributeNode; +import javax.persistence.NamedEntityGraph; +import javax.persistence.OneToMany; +import javax.persistence.OneToOne; +import javax.persistence.PrimaryKeyJoinColumn; +import javax.persistence.Table; +import javax.persistence.Transient; +import javax.persistence.UniqueConstraint; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; + +import org.eclipse.hawkbit.im.authentication.SpPermission; +import org.eclipse.hawkbit.repository.model.Action; +import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.Target; +import org.eclipse.hawkbit.repository.model.TargetIdName; +import org.eclipse.hawkbit.repository.model.TargetInfo; +import org.eclipse.hawkbit.repository.model.TargetTag; +import org.eclipse.hawkbit.repository.model.helper.SecurityChecker; +import org.eclipse.hawkbit.repository.model.helper.SecurityTokenGeneratorHolder; +import org.eclipse.persistence.annotations.CascadeOnDelete; +import org.springframework.data.domain.Persistable; + +/** + *

+ * The {@link Target} is the target of all provisioning operations. It contains + * the currently installed {@link DistributionSet} (i.e. current state). In + * addition it holds the target {@link DistributionSet} that has to be + * provisioned next (i.e. target state). + *

+ * + *

+ * {@link #getStatus()}s() shows if the {@link Target} is + * {@link TargetStatus#IN_SYNC} or a provisioning is + * {@link TargetStatus#PENDING} or the target is only + * {@link TargetStatus#REGISTERED}, i.e. a target {@link DistributionSet} . + *

+ * + */ +@Entity +@Table(name = "sp_target", indexes = { + @Index(name = "sp_idx_target_01", columnList = "tenant,name,assigned_distribution_set"), + @Index(name = "sp_idx_target_02", columnList = "tenant,name"), + @Index(name = "sp_idx_target_03", columnList = "tenant,controller_id,assigned_distribution_set"), + @Index(name = "sp_idx_target_04", columnList = "tenant,created_at"), + @Index(name = "sp_idx_target_prim", columnList = "tenant,id") }, uniqueConstraints = @UniqueConstraint(columnNames = { + "controller_id", "tenant" }, name = "uk_tenant_controller_id")) +@NamedEntityGraph(name = "Target.detail", attributeNodes = { @NamedAttributeNode("tags"), + @NamedAttributeNode(value = "assignedDistributionSet"), @NamedAttributeNode(value = "targetInfo") }) +public class JpaTarget extends JpaNamedEntity implements Persistable, Target { + private static final long serialVersionUID = 1L; + + @Column(name = "controller_id", length = 64) + @Size(min = 1) + @NotNull + private String controllerId; + + @Transient + private boolean entityNew = false; + + @ManyToMany(targetEntity = JpaTargetTag.class) + @JoinTable(name = "sp_target_target_tag", joinColumns = { + @JoinColumn(name = "target", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_targ_targtag_target")) }, inverseJoinColumns = { + @JoinColumn(name = "tag", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_targ_targtag_tag")) }) + private Set tags = new HashSet<>(); + + @CascadeOnDelete + @OneToMany(fetch = FetchType.LAZY, orphanRemoval = true, cascade = { + CascadeType.REMOVE }, targetEntity = JpaAction.class) + @JoinColumn(name = "target", insertable = false, updatable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_targ_act_hist_targ")) + private final List actions = new ArrayList<>(); + + @ManyToOne(optional = true, fetch = FetchType.LAZY, targetEntity = JpaDistributionSet.class) + @JoinColumn(name = "assigned_distribution_set", nullable = true, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_target_assign_ds")) + private JpaDistributionSet assignedDistributionSet; + + @CascadeOnDelete + @OneToOne(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, targetEntity = JpaTargetInfo.class) + @PrimaryKeyJoinColumn + private JpaTargetInfo targetInfo = null; + + /** + * the security token of the target which allows if enabled to authenticate + * with this security token. + */ + @Column(name = "sec_token", insertable = true, updatable = true, nullable = false, length = 128) + private String securityToken = null; + + @CascadeOnDelete + @OneToMany(fetch = FetchType.LAZY, cascade = { CascadeType.REMOVE, CascadeType.PERSIST }) + @JoinColumn(name = "target_Id", insertable = false, updatable = false) + private final List rolloutTargetGroup = new ArrayList<>(); + + /** + * Constructor. + * + * @param controllerId + * controller ID of the {@link Target} + */ + public JpaTarget(final String controllerId) { + this.controllerId = controllerId; + setName(controllerId); + securityToken = SecurityTokenGeneratorHolder.getInstance().generateToken(); + targetInfo = new JpaTargetInfo(this); + } + + /** + * empty constructor for JPA. + */ + JpaTarget() { + controllerId = null; + securityToken = null; + } + + @Override + public DistributionSet getAssignedDistributionSet() { + return assignedDistributionSet; + } + + @Override + public String getControllerId() { + return controllerId; + } + + @Override + public Set getTags() { + return tags; + } + + @Override + public void setAssignedDistributionSet(final DistributionSet assignedDistributionSet) { + this.assignedDistributionSet = (JpaDistributionSet) assignedDistributionSet; + } + + @Override + public void setControllerId(final String controllerId) { + this.controllerId = controllerId; + } + + @Override + public void setTags(final Set tags) { + this.tags = tags; + } + + @Override + public List getActions() { + return actions; + } + + @Override + public TargetIdName getTargetIdName() { + return new TargetIdName(getId(), getControllerId(), getName()); + } + + @Override + @Transient + public boolean isNew() { + return entityNew; + } + + /** + * @param isNew + * the isNew to set + */ + public void setNew(final boolean entityNew) { + this.entityNew = entityNew; + } + + /** + * @return the targetInfo + */ + @Override + public TargetInfo getTargetInfo() { + return targetInfo; + } + + /** + * @param targetInfo + * the targetInfo to set + */ + @Override + public void setTargetInfo(final TargetInfo targetInfo) { + this.targetInfo = (JpaTargetInfo) targetInfo; + } + + /** + * @return the securityToken + */ + @Override + public String getSecurityToken() { + if (SecurityChecker.hasPermission(SpPermission.READ_TARGET_SEC_TOKEN)) { + return securityToken; + } + return null; + } + + /** + * @param securityToken + * the securityToken to set + */ + @Override + public void setSecurityToken(final String securityToken) { + this.securityToken = securityToken; + } + + @Override + public String toString() { + return "Target [controllerId=" + controllerId + ", getId()=" + getId() + "]"; + } + +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetFilterQuery.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetFilterQuery.java new file mode 100644 index 000000000..1ad1b69b8 --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetFilterQuery.java @@ -0,0 +1,64 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.jpa.model; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Index; +import javax.persistence.Table; +import javax.persistence.UniqueConstraint; + +import org.eclipse.hawkbit.repository.model.TargetFilterQuery; + +/** + * Stored target filter. + * + */ +@Entity +@Table(name = "sp_target_filter_query", indexes = { + @Index(name = "sp_idx_target_filter_query_01", columnList = "tenant,name") }, uniqueConstraints = @UniqueConstraint(columnNames = { + "name", "tenant" }, name = "uk_tenant_custom_filter_name")) +public class JpaTargetFilterQuery extends JpaTenantAwareBaseEntity implements TargetFilterQuery { + private static final long serialVersionUID = 7493966984413479089L; + + @Column(name = "name", length = 64) + private String name; + + @Column(name = "query", length = 1024) + private String query; + + public JpaTargetFilterQuery() { + // Default constructor for JPA. + } + + public JpaTargetFilterQuery(final String name, final String query) { + this.name = name; + this.query = query; + } + + @Override + public String getName() { + return name; + } + + @Override + public void setName(final String name) { + this.name = name; + } + + @Override + public String getQuery() { + return query; + } + + @Override + public void setQuery(final String query) { + this.query = query; + } +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetInfo.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetInfo.java new file mode 100644 index 000000000..7b7b3e2e4 --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetInfo.java @@ -0,0 +1,372 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.jpa.model; + +import java.net.URI; +import java.time.Duration; +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import javax.persistence.CascadeType; +import javax.persistence.CollectionTable; +import javax.persistence.Column; +import javax.persistence.ConstraintMode; +import javax.persistence.ElementCollection; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.FetchType; +import javax.persistence.ForeignKey; +import javax.persistence.Id; +import javax.persistence.Index; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.MapKeyColumn; +import javax.persistence.MapsId; +import javax.persistence.OneToOne; +import javax.persistence.Table; +import javax.persistence.Transient; + +import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.Target; +import org.eclipse.hawkbit.repository.model.TargetInfo; +import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; +import org.eclipse.hawkbit.repository.model.helper.SystemSecurityContextHolder; +import org.eclipse.hawkbit.repository.model.helper.TenantConfigurationManagementHolder; +import org.eclipse.hawkbit.tenancy.configuration.DurationHelper; +import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; +import org.eclipse.persistence.annotations.CascadeOnDelete; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.data.domain.Persistable; + +/** + * A table which contains all the information inserted, updated by the + * controller itself. So this entity does not provide audit information because + * changes on this entity are mostly only done by controller requests. That's + * the reason that we store these information in a separated table so we don't + * modifying the {@link Target} itself when a controller reports it's + * {@link #lastTargetQuery} for example. + * + */ +@Table(name = "sp_target_info", indexes = { + @Index(name = "sp_idx_target_info_02", columnList = "target_id,update_status") }) +@Entity +public class JpaTargetInfo implements Persistable, TargetInfo { + private static final long serialVersionUID = 1L; + + private static final Logger LOG = LoggerFactory.getLogger(TargetInfo.class); + + @Id + private Long targetId; + + @Transient + private boolean entityNew = false; + + @CascadeOnDelete + @OneToOne(cascade = { CascadeType.MERGE, + CascadeType.REMOVE }, fetch = FetchType.LAZY, targetEntity = JpaTarget.class) + @JoinColumn(name = "target_id", nullable = false, updatable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_targ_stat_targ")) + @MapsId + private JpaTarget target; + + @Column(name = "address", length = 512) + private String address = null; + + @Column(name = "last_target_query") + private Long lastTargetQuery = null; + + @Column(name = "install_date") + private Long installationDate; + + @Column(name = "update_status", nullable = false, length = 255) + @Enumerated(EnumType.STRING) + private TargetUpdateStatus updateStatus = TargetUpdateStatus.UNKNOWN; + + @ManyToOne(optional = true, fetch = FetchType.LAZY) + @JoinColumn(name = "installed_distribution_set", nullable = true, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_target_inst_ds")) + private JpaDistributionSet installedDistributionSet; + + /** + * Read only on management API. Are commited by controller. + */ + @ElementCollection + @Column(name = "attribute_value", length = 128) + @MapKeyColumn(name = "attribute_key", nullable = false, length = 32) + @CollectionTable(name = "sp_target_attributes", joinColumns = { + @JoinColumn(name = "target_id") }, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_targ_attrib_target")) + + private final Map controllerAttributes = Collections.synchronizedMap(new HashMap()); + + // set default request controller attributes to true, because we want to + // request them the first + // time + @Column(name = "request_controller_attributes", nullable = false) + private boolean requestControllerAttributes = true; + + /** + * Constructor for {@link TargetStatus}. + * + * @param target + * related to this status. + */ + public JpaTargetInfo(final JpaTarget target) { + this.target = target; + targetId = target.getId(); + } + + JpaTargetInfo() { + target = null; + targetId = null; + } + + @Override + public Long getId() { + return targetId; + } + + @Override + @Transient + public boolean isNew() { + return entityNew; + } + + /** + * @param isNew + * the isNew to set + */ + public void setNew(final boolean entityNew) { + this.entityNew = entityNew; + } + + /** + * @return the ipAddress + */ + @Override + public URI getAddress() { + if (address == null) { + return null; + } + try { + return URI.create(address); + } catch (final IllegalArgumentException e) { + LOG.warn("Invalid address provided. Cloud not be configured to URI", e); + return null; + } + } + + /** + * @param address + * the ipAddress to set + * + * @throws IllegalArgumentException + * If the given string violates RFC 2396 + */ + public void setAddress(final String address) { + // check if this is a real URI + if (address != null) { + URI.create(address); + } + + this.address = address; + } + + public Long getTargetId() { + return targetId; + } + + public void setTargetId(final Long targetId) { + this.targetId = targetId; + } + + @Override + public Target getTarget() { + return target; + } + + public void setTarget(final JpaTarget target) { + this.target = target; + } + + @Override + public Long getLastTargetQuery() { + return lastTargetQuery; + } + + public void setLastTargetQuery(final Long lastTargetQuery) { + this.lastTargetQuery = lastTargetQuery; + } + + public void setRequestControllerAttributes(final boolean requestControllerAttributes) { + this.requestControllerAttributes = requestControllerAttributes; + } + + @Override + public Map getControllerAttributes() { + return controllerAttributes; + } + + public boolean isRequestControllerAttributes() { + return requestControllerAttributes; + } + + @Override + public Long getInstallationDate() { + return installationDate; + } + + public void setInstallationDate(final Long installationDate) { + this.installationDate = installationDate; + } + + @Override + public TargetUpdateStatus getUpdateStatus() { + return updateStatus; + } + + public void setUpdateStatus(final TargetUpdateStatus updateStatus) { + this.updateStatus = updateStatus; + } + + @Override + public DistributionSet getInstalledDistributionSet() { + return installedDistributionSet; + } + + public void setInstalledDistributionSet(final JpaDistributionSet installedDistributionSet) { + this.installedDistributionSet = installedDistributionSet; + } + + /** + * @return the poll time which holds the last poll time of the target, the + * next poll time and the overdue time. In case the + * {@link #lastTargetQuery} is not set e.g. the target never polled + * before this method returns {@code null} + */ + @Override + public PollStatus getPollStatus() { + if (lastTargetQuery == null) { + return null; + } + return SystemSecurityContextHolder.getInstance().getSystemSecurityContext().runAsSystem(() -> { + final Duration pollTime = DurationHelper.formattedStringToDuration(TenantConfigurationManagementHolder + .getInstance().getTenantConfigurationManagement() + .getConfigurationValue(TenantConfigurationKey.POLLING_TIME_INTERVAL, String.class).getValue()); + final Duration overdueTime = DurationHelper.formattedStringToDuration( + TenantConfigurationManagementHolder.getInstance().getTenantConfigurationManagement() + .getConfigurationValue(TenantConfigurationKey.POLLING_OVERDUE_TIME_INTERVAL, String.class) + .getValue()); + final LocalDateTime currentDate = LocalDateTime.now(); + final LocalDateTime lastPollDate = LocalDateTime.ofInstant(Instant.ofEpochMilli(lastTargetQuery), + ZoneId.systemDefault()); + final LocalDateTime nextPollDate = lastPollDate.plus(pollTime); + final LocalDateTime overdueDate = nextPollDate.plus(overdueTime); + return new PollStatus(lastPollDate, nextPollDate, overdueDate, currentDate); + }); + } + + /** + * The poll time object which holds all the necessary information around the + * target poll time, e.g. the last poll time, the next poll time and the + * overdue poll time. + * + */ + public static final class PollStatus { + private final LocalDateTime lastPollDate; + private final LocalDateTime nextPollDate; + private final LocalDateTime overdueDate; + private final LocalDateTime currentDate; + + private PollStatus(final LocalDateTime lastPollDate, final LocalDateTime nextPollDate, + final LocalDateTime overdueDate, final LocalDateTime currentDate) { + this.lastPollDate = lastPollDate; + this.nextPollDate = nextPollDate; + this.overdueDate = overdueDate; + this.currentDate = currentDate; + } + + /** + * calculates if the target poll time is overdue and the target has not + * been polled in the configured poll time interval. + * + * @return {@code true} if the current time is after the poll time + * overdue date otherwise {@code false}. + */ + public boolean isOverdue() { + return currentDate.isAfter(overdueDate); + } + + /** + * @return the lastPollDate + */ + public LocalDateTime getLastPollDate() { + return lastPollDate; + } + + public LocalDateTime getNextPollDate() { + return nextPollDate; + } + + public LocalDateTime getOverdueDate() { + return overdueDate; + } + + public LocalDateTime getCurrentDate() { + return currentDate; + } + + @Override + public String toString() { + return "PollTime [lastPollDate=" + lastPollDate + ", nextPollDate=" + nextPollDate + ", overdueDate=" + + overdueDate + ", currentDate=" + currentDate + "]"; + } + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((target == null) ? 0 : target.hashCode()); + result = prime * result + ((targetId == null) ? 0 : targetId.hashCode()); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (!(obj instanceof TargetInfo)) { + return false; + } + final JpaTargetInfo other = (JpaTargetInfo) obj; + if (target == null) { + if (other.target != null) { + return false; + } + } else if (!target.equals(other.target)) { + return false; + } + if (targetId == null) { + if (other.targetId != null) { + return false; + } + } else if (!targetId.equals(other.targetId)) { + return false; + } + return true; + } +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetTag.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetTag.java new file mode 100644 index 000000000..0d8f3a5d1 --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetTag.java @@ -0,0 +1,91 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.jpa.model; + +import java.util.List; + +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.Index; +import javax.persistence.ManyToMany; +import javax.persistence.Table; +import javax.persistence.UniqueConstraint; + +import org.eclipse.hawkbit.repository.model.Target; +import org.eclipse.hawkbit.repository.model.TargetTag; + +/** + * A {@link TargetTag} is used to describe Target attributes and use them also + * for filtering the target list. + * + */ +@Entity +@Table(name = "sp_target_tag", indexes = { + @Index(name = "sp_idx_target_tag_prim", columnList = "tenant,id") }, uniqueConstraints = @UniqueConstraint(columnNames = { + "name", "tenant" }, name = "uk_targ_tag")) +public class JpaTargetTag extends JpaTag implements TargetTag { + private static final long serialVersionUID = 1L; + + @ManyToMany(mappedBy = "tags", targetEntity = JpaTarget.class, fetch = FetchType.LAZY) + private List assignedToTargets; + + /** + * Constructor. + * + * @param name + * of {@link TargetTag} + * @param description + * of {@link TargetTag} + * @param colour + * of {@link TargetTag} + */ + public JpaTargetTag(final String name, final String description, final String colour) { + super(name, description, colour); + } + + /** + * Public constructor. + * + * @param name + * of the {@link TargetTag} + **/ + public JpaTargetTag(final String name) { + super(name, null, null); + } + + public JpaTargetTag() { + super(); + } + + @Override + public List getAssignedToTargets() { + return assignedToTargets; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + this.getClass().getName().hashCode(); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (!super.equals(obj)) { + return false; + } + if (!(obj instanceof TargetTag)) { + return false; + } + + return true; + } + +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTenantAwareBaseEntity.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTenantAwareBaseEntity.java new file mode 100644 index 000000000..e921e6915 --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTenantAwareBaseEntity.java @@ -0,0 +1,115 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.jpa.model; + +import javax.persistence.Column; +import javax.persistence.MappedSuperclass; +import javax.persistence.PrePersist; + +import org.eclipse.hawkbit.repository.exception.TenantNotExistException; +import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity; +import org.eclipse.hawkbit.repository.model.helper.SystemManagementHolder; +import org.eclipse.hawkbit.repository.model.helper.TenantAwareHolder; +import org.eclipse.persistence.annotations.Multitenant; +import org.eclipse.persistence.annotations.MultitenantType; +import org.eclipse.persistence.annotations.TenantDiscriminatorColumn; + +/** + * Holder of the base attributes common to all tenant aware entities. + * + */ +@MappedSuperclass +@TenantDiscriminatorColumn(name = "tenant", length = 40) +@Multitenant(MultitenantType.SINGLE_TABLE) +public abstract class JpaTenantAwareBaseEntity extends JpaBaseEntity implements TenantAwareBaseEntity { + private static final long serialVersionUID = 1L; + + @Column(name = "tenant", nullable = false, insertable = false, updatable = false, length = 40) + private String tenant; + + /** + * Default constructor needed for JPA entities. + */ + public JpaTenantAwareBaseEntity() { + // Default constructor needed for JPA entities. + } + + /** + * PrePersist listener method for all {@link TenantAwareBaseEntity} + * entities. + */ + @PrePersist + public void prePersist() { + // before persisting the entity check the current ID of the tenant by + // using the TenantAware + // service + final String currentTenant = SystemManagementHolder.getInstance().currentTenant(); + if (currentTenant == null) { + throw new TenantNotExistException("Tenant " + + TenantAwareHolder.getInstance().getTenantAware().getCurrentTenant() + + " does not exists, cannot create entity " + this.getClass() + " with id " + super.getId()); + } + setTenant(currentTenant.toUpperCase()); + } + + @Override + public String getTenant() { + return tenant; + } + + public void setTenant(final String tenant) { + this.tenant = tenant; + } + + @Override + public String toString() { + return "BaseEntity [id=" + super.getId() + "]"; + } + + /** + * Tenant aware entities extend the equals/hashcode strategy with the tenant + * name. That would allow for instance in a multi-schema based data + * separation setup to have the same primary key for different entities of + * different tenants. + * + * @see org.eclipse.hawkbit.repository.model.BaseEntity#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + (tenant == null ? 0 : tenant.hashCode()); + return result; + } + + /** + * Tenant aware entities extend the equals/hashcode strategy with the tenant + * name. That would allow for instance in a multi-schema based data + * separation setup to have the same primary key for different entities of + * different tenants. + * + * @see org.eclipse.hawkbit.repository.model.BaseEntity#equals(java.lang.Object) + */ + @Override + public boolean equals(final Object obj) { + if (!super.equals(obj)) { + return false; + } + final JpaTenantAwareBaseEntity other = (JpaTenantAwareBaseEntity) obj; + if (tenant == null) { + if (other.tenant != null) { + return false; + } + } else if (!tenant.equals(other.tenant)) { + return false; + } + return true; + } + +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTenantConfiguration.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTenantConfiguration.java new file mode 100644 index 000000000..2d1342b74 --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTenantConfiguration.java @@ -0,0 +1,75 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.jpa.model; + +import javax.persistence.Basic; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Table; +import javax.persistence.UniqueConstraint; + +import org.eclipse.hawkbit.repository.model.TenantConfiguration; + +/** + * A JPA entity which stores the tenant specific configuration. + * + */ +@Entity +@Table(name = "sp_tenant_configuration", uniqueConstraints = @UniqueConstraint(columnNames = { "conf_key", + "tenant" }, name = "uk_tenant_key")) +public class JpaTenantConfiguration extends JpaTenantAwareBaseEntity implements TenantConfiguration { + private static final long serialVersionUID = 1L; + + @Column(name = "conf_key", length = 128) + private String key; + + @Column(name = "conf_value", length = 512) + @Basic + private String value; + + /** + * JPA default constructor. + */ + public JpaTenantConfiguration() { + // JPA default constructor. + } + + /** + * @param key + * the key of this configuration + * @param value + * the value of this configuration + */ + public JpaTenantConfiguration(final String key, final String value) { + this.key = key; + this.value = value; + + } + + @Override + public String getKey() { + return key; + } + + @Override + public void setKey(final String key) { + this.key = key; + } + + @Override + public String getValue() { + return value; + } + + @Override + public void setValue(final String value) { + this.value = value; + } + +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTenantMetaData.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTenantMetaData.java new file mode 100644 index 000000000..7cb31b3c4 --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTenantMetaData.java @@ -0,0 +1,107 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.jpa.model; + +import javax.persistence.Column; +import javax.persistence.ConstraintMode; +import javax.persistence.Entity; +import javax.persistence.EntityManager; +import javax.persistence.FetchType; +import javax.persistence.ForeignKey; +import javax.persistence.Index; +import javax.persistence.JoinColumn; +import javax.persistence.OneToOne; +import javax.persistence.Table; +import javax.persistence.UniqueConstraint; + +import org.eclipse.hawkbit.repository.model.DistributionSetType; +import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity; +import org.eclipse.hawkbit.repository.model.TenantMetaData; + +/** + * Tenant entity with meta data that is configured globally for the entire + * tenant. This entity is not tenant aware to allow the system to access it + * through the {@link EntityManager} even before the actual tenant exists. + * + * Entities owned by the tenant are based on {@link TenantAwareBaseEntity}. + * + */ +@Table(name = "sp_tenant", indexes = { + @Index(name = "sp_idx_tenant_prim", columnList = "tenant,id") }, uniqueConstraints = { + @UniqueConstraint(columnNames = { "tenant" }, name = "uk_tenantmd_tenant") }) +@Entity +public class JpaTenantMetaData extends JpaBaseEntity implements TenantMetaData { + private static final long serialVersionUID = 1L; + + @Column(name = "tenant", nullable = false, length = 40) + private String tenant; + + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "default_ds_type", nullable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_tenant_md_default_ds_type")) + private JpaDistributionSetType defaultDsType; + + /** + * Default constructor needed for JPA entities. + */ + public JpaTenantMetaData() { + // Default constructor needed for JPA entities. + } + + /** + * Standard constructor. + * + * @param defaultDsType + * of this tenant + * @param tenant + */ + public JpaTenantMetaData(final DistributionSetType defaultDsType, final String tenant) { + super(); + this.defaultDsType = (JpaDistributionSetType) defaultDsType; + this.tenant = tenant; + } + + @Override + public DistributionSetType getDefaultDsType() { + return defaultDsType; + } + + @Override + public void setDefaultDsType(final DistributionSetType defaultDsType) { + this.defaultDsType = (JpaDistributionSetType) defaultDsType; + } + + @Override + public String getTenant() { + return tenant; + } + + public void setTenant(final String tenant) { + this.tenant = tenant; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + this.getClass().getName().hashCode(); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (!super.equals(obj)) { + return false; + } + if (!(obj instanceof TenantMetaData)) { + return false; + } + + return true; + } +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/RolloutTargetGroup.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/RolloutTargetGroup.java similarity index 77% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/RolloutTargetGroup.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/RolloutTargetGroup.java index 7a46b15b1..0bb969c7f 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/RolloutTargetGroup.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/RolloutTargetGroup.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.model; +package org.eclipse.hawkbit.repository.jpa.model; import java.io.Serializable; import java.util.List; @@ -24,6 +24,9 @@ import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.Table; +import org.eclipse.hawkbit.repository.model.Action; +import org.eclipse.hawkbit.repository.model.RolloutGroup; +import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.persistence.annotations.ExistenceChecking; import org.eclipse.persistence.annotations.ExistenceType; @@ -41,16 +44,16 @@ public class RolloutTargetGroup implements Serializable { private static final long serialVersionUID = 1L; @Id - @ManyToOne(targetEntity = RolloutGroup.class, fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST }) - @JoinColumn(name = "rolloutGroup_Id", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_rollouttargetgroup_group") ) + @ManyToOne(targetEntity = JpaRolloutGroup.class, fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST }) + @JoinColumn(name = "rolloutGroup_Id", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_rollouttargetgroup_group")) private RolloutGroup rolloutGroup; @Id - @ManyToOne(targetEntity = Target.class, fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST }) - @JoinColumn(name = "target_id", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_rollouttargetgroup_target") ) - private Target target; + @ManyToOne(targetEntity = JpaTarget.class, fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST }) + @JoinColumn(name = "target_id", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_rollouttargetgroup_target")) + private JpaTarget target; - @OneToMany(targetEntity = Action.class, fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST }) + @OneToMany(targetEntity = JpaAction.class, fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST }) @JoinColumns(value = { @JoinColumn(name = "rolloutgroup", referencedColumnName = "rolloutGroup_Id"), @JoinColumn(name = "target", referencedColumnName = "target_id") }) private List actions; @@ -64,7 +67,7 @@ public class RolloutTargetGroup implements Serializable { public RolloutTargetGroup(final RolloutGroup rolloutGroup, final Target target) { this.rolloutGroup = rolloutGroup; - this.target = target; + this.target = (JpaTarget) target; } public RolloutTargetGroupId getId() { diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/RolloutTargetGroupId.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/RolloutTargetGroupId.java similarity index 88% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/RolloutTargetGroupId.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/RolloutTargetGroupId.java index 88226142a..cc1c9cbe7 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/RolloutTargetGroupId.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/RolloutTargetGroupId.java @@ -6,10 +6,13 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.model; +package org.eclipse.hawkbit.repository.jpa.model; import java.io.Serializable; +import org.eclipse.hawkbit.repository.model.RolloutGroup; +import org.eclipse.hawkbit.repository.model.Target; + /** * Combined unique key of the table {@link RolloutTargetGroup}. * diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SwMetadataCompositeKey.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/SwMetadataCompositeKey.java similarity index 96% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SwMetadataCompositeKey.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/SwMetadataCompositeKey.java index 90b3779a1..e9c63b511 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SwMetadataCompositeKey.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/SwMetadataCompositeKey.java @@ -6,10 +6,12 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.model; +package org.eclipse.hawkbit.repository.jpa.model; import java.io.Serializable; +import org.eclipse.hawkbit.repository.model.SoftwareModule; + /** * The Software Module meta data composite key which contains the meta data key * and the ID of the software module itself. diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/ActionSpecifications.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/ActionSpecifications.java similarity index 55% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/ActionSpecifications.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/ActionSpecifications.java index 62e7167f1..54d529d6c 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/ActionSpecifications.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/ActionSpecifications.java @@ -6,20 +6,22 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.specifications; +package org.eclipse.hawkbit.repository.jpa.specifications; import javax.persistence.criteria.Join; import javax.persistence.criteria.ListJoin; import javax.persistence.criteria.SetJoin; +import org.eclipse.hawkbit.repository.jpa.model.JpaAction; +import org.eclipse.hawkbit.repository.jpa.model.JpaAction_; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet_; +import org.eclipse.hawkbit.repository.jpa.model.JpaLocalArtifact; +import org.eclipse.hawkbit.repository.jpa.model.JpaLocalArtifact_; +import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; +import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule_; import org.eclipse.hawkbit.repository.model.Action; -import org.eclipse.hawkbit.repository.model.Action_; -import org.eclipse.hawkbit.repository.model.DistributionSet; -import org.eclipse.hawkbit.repository.model.DistributionSet_; import org.eclipse.hawkbit.repository.model.LocalArtifact; -import org.eclipse.hawkbit.repository.model.LocalArtifact_; -import org.eclipse.hawkbit.repository.model.SoftwareModule; -import org.eclipse.hawkbit.repository.model.SoftwareModule_; import org.eclipse.hawkbit.repository.model.Target; import org.springframework.data.jpa.domain.Specification; @@ -28,7 +30,7 @@ import org.springframework.data.jpa.domain.Specification; * Spring Data JPQL Specifications. * */ -public class ActionSpecifications { +public final class ActionSpecifications { private ActionSpecifications() { // utility class @@ -47,15 +49,16 @@ public class ActionSpecifications { * assigned * @return a specification to use with spring JPA */ - public static Specification hasTargetAssignedArtifact(final Target target, + public static Specification hasTargetAssignedArtifact(final Target target, final LocalArtifact localArtifact) { return (actionRoot, query, criteriaBuilder) -> { - final Join dsJoin = actionRoot.join(Action_.distributionSet); - final SetJoin modulesJoin = dsJoin.join(DistributionSet_.modules); - final ListJoin artifactsJoin = modulesJoin.join(SoftwareModule_.artifacts); + final Join dsJoin = actionRoot.join(JpaAction_.distributionSet); + final SetJoin modulesJoin = dsJoin.join(JpaDistributionSet_.modules); + final ListJoin artifactsJoin = modulesJoin + .join(JpaSoftwareModule_.artifacts); return criteriaBuilder.and( - criteriaBuilder.equal(artifactsJoin.get(LocalArtifact_.filename), localArtifact.getFilename()), - criteriaBuilder.equal(actionRoot.get(Action_.target), target)); + criteriaBuilder.equal(artifactsJoin.get(JpaLocalArtifact_.filename), localArtifact.getFilename()), + criteriaBuilder.equal(actionRoot.get(JpaAction_.target), target)); }; } } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/DistributionSetSpecification.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/DistributionSetSpecification.java similarity index 58% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/DistributionSetSpecification.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/DistributionSetSpecification.java index b95f0b8e7..4ee849bcc 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/DistributionSetSpecification.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/DistributionSetSpecification.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.specifications; +package org.eclipse.hawkbit.repository.jpa.specifications; import java.util.Collection; @@ -18,15 +18,17 @@ import javax.persistence.criteria.Path; import javax.persistence.criteria.Predicate; import javax.persistence.criteria.SetJoin; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag_; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet_; +import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; +import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo; +import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo_; +import org.eclipse.hawkbit.repository.jpa.model.JpaTarget_; import org.eclipse.hawkbit.repository.model.DistributionSet; -import org.eclipse.hawkbit.repository.model.DistributionSetTag; -import org.eclipse.hawkbit.repository.model.DistributionSetTag_; import org.eclipse.hawkbit.repository.model.DistributionSetType; -import org.eclipse.hawkbit.repository.model.DistributionSet_; -import org.eclipse.hawkbit.repository.model.Target; -import org.eclipse.hawkbit.repository.model.TargetInfo; -import org.eclipse.hawkbit.repository.model.TargetInfo_; -import org.eclipse.hawkbit.repository.model.Target_; import org.springframework.data.jpa.domain.Specification; /** @@ -48,8 +50,8 @@ public final class DistributionSetSpecification { * attribute is ignored * @return the {@link DistributionSet} {@link Specification} */ - public static Specification isDeleted(final Boolean isDeleted) { - return (targetRoot, query, cb) -> cb.equal(targetRoot. get(DistributionSet_.deleted), isDeleted); + public static Specification isDeleted(final Boolean isDeleted) { + return (targetRoot, query, cb) -> cb.equal(targetRoot. get(JpaDistributionSet_.deleted), isDeleted); } @@ -62,8 +64,8 @@ public final class DistributionSetSpecification { * the attribute is ignored * @return the {@link DistributionSet} {@link Specification} */ - public static Specification isCompleted(final Boolean isCompleted) { - return (targetRoot, query, cb) -> cb.equal(targetRoot. get(DistributionSet_.complete), isCompleted); + public static Specification isCompleted(final Boolean isCompleted) { + return (targetRoot, query, cb) -> cb.equal(targetRoot. get(JpaDistributionSet_.complete), isCompleted); } @@ -75,12 +77,12 @@ public final class DistributionSetSpecification { * to search * @return the {@link DistributionSet} {@link Specification} */ - public static Specification byId(final Long distid) { + public static Specification byId(final Long distid) { return (targetRoot, query, cb) -> { - final Predicate predicate = cb.equal(targetRoot. get(DistributionSet_.id), distid); - targetRoot.fetch(DistributionSet_.modules, JoinType.LEFT); - targetRoot.fetch(DistributionSet_.tags, JoinType.LEFT); - targetRoot.fetch(DistributionSet_.type, JoinType.LEFT); + final Predicate predicate = cb.equal(targetRoot. get(JpaDistributionSet_.id), distid); + targetRoot.fetch(JpaDistributionSet_.modules, JoinType.LEFT); + targetRoot.fetch(JpaDistributionSet_.tags, JoinType.LEFT); + targetRoot.fetch(JpaDistributionSet_.type, JoinType.LEFT); query.distinct(true); return predicate; @@ -95,12 +97,12 @@ public final class DistributionSetSpecification { * to search * @return the {@link DistributionSet} {@link Specification} */ - public static Specification byIds(final Collection distids) { + public static Specification byIds(final Collection distids) { return (targetRoot, query, cb) -> { - final Predicate predicate = targetRoot. get(DistributionSet_.id).in(distids); - targetRoot.fetch(DistributionSet_.modules, JoinType.LEFT); - targetRoot.fetch(DistributionSet_.tags, JoinType.LEFT); - targetRoot.fetch(DistributionSet_.type, JoinType.LEFT); + final Predicate predicate = targetRoot. get(JpaDistributionSet_.id).in(distids); + targetRoot.fetch(JpaDistributionSet_.modules, JoinType.LEFT); + targetRoot.fetch(JpaDistributionSet_.tags, JoinType.LEFT); + targetRoot.fetch(JpaDistributionSet_.type, JoinType.LEFT); query.distinct(true); return predicate; }; @@ -114,11 +116,11 @@ public final class DistributionSetSpecification { * to be filtered on * @return the {@link DistributionSet} {@link Specification} */ - public static Specification likeNameOrDescriptionOrVersion(final String subString) { + public static Specification likeNameOrDescriptionOrVersion(final String subString) { return (targetRoot, query, cb) -> cb.or( - cb.like(cb.lower(targetRoot. get(DistributionSet_.name)), subString.toLowerCase()), - cb.like(cb.lower(targetRoot. get(DistributionSet_.version)), subString.toLowerCase()), - cb.like(cb.lower(targetRoot. get(DistributionSet_.description)), subString.toLowerCase())); + cb.like(cb.lower(targetRoot. get(JpaDistributionSet_.name)), subString.toLowerCase()), + cb.like(cb.lower(targetRoot. get(JpaDistributionSet_.version)), subString.toLowerCase()), + cb.like(cb.lower(targetRoot. get(JpaDistributionSet_.description)), subString.toLowerCase())); } /** @@ -131,10 +133,10 @@ public final class DistributionSetSpecification { * flag to select distribution sets with no tag * @return the {@link DistributionSet} {@link Specification} */ - public static Specification hasTags(final Collection tagNames, + public static Specification hasTags(final Collection tagNames, final Boolean selectDSWithNoTag) { return (targetRoot, query, cb) -> { - final SetJoin tags = targetRoot.join(DistributionSet_.tags, + final SetJoin tags = targetRoot.join(JpaDistributionSet_.tags, JoinType.LEFT); final Predicate predicate = getPredicate(tags, tagNames, selectDSWithNoTag, cb); query.distinct(true); @@ -142,10 +144,10 @@ public final class DistributionSetSpecification { }; } - private static Predicate getPredicate(final SetJoin tags, + private static Predicate getPredicate(final SetJoin tags, final Collection tagNames, final Boolean selectDSWithNoTag, final CriteriaBuilder cb) { - tags.get(DistributionSetTag_.name); - final Path exp = tags.get(DistributionSetTag_.name); + tags.get(JpaDistributionSetTag_.name); + final Path exp = tags.get(JpaDistributionSetTag_.name); if (selectDSWithNoTag != null && selectDSWithNoTag) { if (tagNames != null) { return cb.or(exp.isNull(), exp.in(tagNames)); @@ -167,11 +169,11 @@ public final class DistributionSetSpecification { * to be filtered on * @return the {@link Specification} */ - public static Specification equalsNameAndVersionIgnoreCase(final String name, + public static Specification equalsNameAndVersionIgnoreCase(final String name, final String version) { return (targetRoot, query, cb) -> cb.and( - cb.equal(cb.lower(targetRoot. get(DistributionSet_.name)), name.toLowerCase()), - cb.equal(cb.lower(targetRoot. get(DistributionSet_.version)), version.toLowerCase())); + cb.equal(cb.lower(targetRoot. get(JpaDistributionSet_.name)), name.toLowerCase()), + cb.equal(cb.lower(targetRoot. get(JpaDistributionSet_.version)), version.toLowerCase())); } @@ -183,8 +185,9 @@ public final class DistributionSetSpecification { * to search * @return the {@link DistributionSet} {@link Specification} */ - public static Specification byType(final DistributionSetType type) { - return (targetRoot, query, cb) -> cb.equal(targetRoot. get(DistributionSet_.type), type); + public static Specification byType(final DistributionSetType type) { + return (targetRoot, query, cb) -> cb.equal(targetRoot. get(JpaDistributionSet_.type), + type); } @@ -195,12 +198,12 @@ public final class DistributionSetSpecification { * @return the specification to search for a distribution set which is * installed to the given targetId */ - public static Specification installedTarget(final String installedTargetId) { + public static Specification installedTarget(final String installedTargetId) { return (dsRoot, query, cb) -> { - final ListJoin installedTargetJoin = dsRoot - .join(DistributionSet_.installedAtTargets, JoinType.INNER); - final Join targetJoin = installedTargetJoin.join(TargetInfo_.target); - return cb.equal(targetJoin.get(Target_.controllerId), installedTargetId); + final ListJoin installedTargetJoin = dsRoot + .join(JpaDistributionSet_.installedAtTargets, JoinType.INNER); + final Join targetJoin = installedTargetJoin.join(JpaTargetInfo_.target); + return cb.equal(targetJoin.get(JpaTarget_.controllerId), installedTargetId); }; } @@ -211,11 +214,11 @@ public final class DistributionSetSpecification { * @return the specification to search for a distribution set which is * assigned to the given targetId */ - public static Specification assignedTarget(final String assignedTargetId) { + public static Specification assignedTarget(final String assignedTargetId) { return (dsRoot, query, cb) -> { - final ListJoin assignedTargetJoin = dsRoot.join(DistributionSet_.assignedToTargets, - JoinType.INNER); - return cb.equal(assignedTargetJoin.get(Target_.controllerId), assignedTargetId); + final ListJoin assignedTargetJoin = dsRoot + .join(JpaDistributionSet_.assignedToTargets, JoinType.INNER); + return cb.equal(assignedTargetJoin.get(JpaTarget_.controllerId), assignedTargetId); }; } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/DistributionSetTypeSpecification.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/DistributionSetTypeSpecification.java similarity index 75% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/DistributionSetTypeSpecification.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/DistributionSetTypeSpecification.java index 13776deb0..0a8306faa 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/DistributionSetTypeSpecification.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/DistributionSetTypeSpecification.java @@ -6,11 +6,12 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.specifications; +package org.eclipse.hawkbit.repository.jpa.specifications; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType_; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetType; -import org.eclipse.hawkbit.repository.model.DistributionSetType_; import org.springframework.data.jpa.domain.Specification; /** @@ -31,8 +32,9 @@ public final class DistributionSetTypeSpecification { * attribute is ignored * @return the {@link DistributionSetType} {@link Specification} */ - public static Specification isDeleted(final Boolean isDeleted) { - return (targetRoot, query, cb) -> cb.equal(targetRoot. get(DistributionSetType_.deleted), isDeleted); + public static Specification isDeleted(final Boolean isDeleted) { + return (targetRoot, query, cb) -> cb.equal(targetRoot. get(JpaDistributionSetType_.deleted), + isDeleted); } /** @@ -44,8 +46,8 @@ public final class DistributionSetTypeSpecification { * to search * @return the {@link DistributionSet} {@link Specification} */ - public static Specification byId(final Long distid) { - return (targetRoot, query, cb) -> cb.equal(targetRoot. get(DistributionSetType_.id), distid); + public static Specification byId(final Long distid) { + return (targetRoot, query, cb) -> cb.equal(targetRoot. get(JpaDistributionSetType_.id), distid); } /** @@ -57,8 +59,8 @@ public final class DistributionSetTypeSpecification { * to search * @return the {@link DistributionSet} {@link Specification} */ - public static Specification byName(final String name) { - return (targetRoot, query, cb) -> cb.equal(targetRoot. get(DistributionSetType_.name), name); + public static Specification byName(final String name) { + return (targetRoot, query, cb) -> cb.equal(targetRoot. get(JpaDistributionSetType_.name), name); } /** @@ -70,8 +72,8 @@ public final class DistributionSetTypeSpecification { * to search * @return the {@link DistributionSet} {@link Specification} */ - public static Specification byKey(final String key) { - return (targetRoot, query, cb) -> cb.equal(targetRoot. get(DistributionSetType_.key), key); + public static Specification byKey(final String key) { + return (targetRoot, query, cb) -> cb.equal(targetRoot. get(JpaDistributionSetType_.key), key); } } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/SoftwareModuleSpecification.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/SoftwareModuleSpecification.java similarity index 63% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/SoftwareModuleSpecification.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/SoftwareModuleSpecification.java index 680f97778..feba50ac8 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/SoftwareModuleSpecification.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/SoftwareModuleSpecification.java @@ -6,13 +6,14 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.specifications; +package org.eclipse.hawkbit.repository.jpa.specifications; import javax.persistence.criteria.Predicate; +import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; +import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType; +import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule_; import org.eclipse.hawkbit.repository.model.SoftwareModule; -import org.eclipse.hawkbit.repository.model.SoftwareModuleType; -import org.eclipse.hawkbit.repository.model.SoftwareModule_; import org.springframework.data.jpa.domain.Specification; /** @@ -33,10 +34,10 @@ public final class SoftwareModuleSpecification { * to search for * @return the {@link SoftwareModule} {@link Specification} */ - public static Specification byId(final Long moduleId) { + public static Specification byId(final Long moduleId) { return (targetRoot, query, cb) -> { - final Predicate predicate = cb.equal(targetRoot. get(SoftwareModule_.id), moduleId); - targetRoot.fetch(SoftwareModule_.type); + final Predicate predicate = cb.equal(targetRoot. get(JpaSoftwareModule_.id), moduleId); + targetRoot.fetch(JpaSoftwareModule_.type); return predicate; }; } @@ -47,8 +48,8 @@ public final class SoftwareModuleSpecification { * * @return the {@link SoftwareModule} {@link Specification} */ - public static Specification isDeletedFalse() { - return (swRoot, query, cb) -> cb.equal(swRoot. get(SoftwareModule_.deleted), Boolean.FALSE); + public static Specification isDeletedFalse() { + return (swRoot, query, cb) -> cb.equal(swRoot. get(JpaSoftwareModule_.deleted), Boolean.FALSE); } /** @@ -59,10 +60,10 @@ public final class SoftwareModuleSpecification { * to be filtered on * @return the {@link SoftwareModule} {@link Specification} */ - public static Specification likeNameOrVersion(final String subString) { + public static Specification likeNameOrVersion(final String subString) { return (targetRoot, query, cb) -> cb.or( - cb.like(cb.lower(targetRoot. get(SoftwareModule_.name)), subString.toLowerCase()), - cb.like(cb.lower(targetRoot. get(SoftwareModule_.version)), subString.toLowerCase())); + cb.like(cb.lower(targetRoot. get(JpaSoftwareModule_.name)), subString.toLowerCase()), + cb.like(cb.lower(targetRoot. get(JpaSoftwareModule_.version)), subString.toLowerCase())); } /** @@ -73,8 +74,9 @@ public final class SoftwareModuleSpecification { * to be filtered on * @return the {@link SoftwareModule} {@link Specification} */ - public static Specification equalType(final SoftwareModuleType type) { - return (targetRoot, query, cb) -> cb.equal(targetRoot. get(SoftwareModule_.type), type); + public static Specification equalType(final JpaSoftwareModuleType type) { + return (targetRoot, query, cb) -> cb.equal(targetRoot. get(JpaSoftwareModule_.type), + type); } } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/SpecificationsBuilder.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/SpecificationsBuilder.java similarity index 95% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/SpecificationsBuilder.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/SpecificationsBuilder.java index 83a4c6f8b..005942719 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/SpecificationsBuilder.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/SpecificationsBuilder.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.specifications; +package org.eclipse.hawkbit.repository.jpa.specifications; import java.util.List; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/TargetFilterQuerySpecification.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/TargetFilterQuerySpecification.java similarity index 67% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/TargetFilterQuerySpecification.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/TargetFilterQuerySpecification.java index 0b600c849..cb3b775ac 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/TargetFilterQuerySpecification.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/TargetFilterQuerySpecification.java @@ -6,10 +6,11 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.specifications; +package org.eclipse.hawkbit.repository.jpa.specifications; +import org.eclipse.hawkbit.repository.jpa.model.JpaTargetFilterQuery; +import org.eclipse.hawkbit.repository.jpa.model.JpaTargetFilterQuery_; import org.eclipse.hawkbit.repository.model.TargetFilterQuery; -import org.eclipse.hawkbit.repository.model.TargetFilterQuery_; import org.springframework.data.jpa.domain.Specification; /** @@ -22,10 +23,10 @@ public class TargetFilterQuerySpecification { // utility class } - public static Specification likeName(final String searchText) { + public static Specification likeName(final String searchText) { return (targetFilterQueryRoot, query, cb) -> { final String searchTextToLower = searchText.toLowerCase(); - return cb.like(cb.lower(targetFilterQueryRoot.get(TargetFilterQuery_.name)), searchTextToLower); + return cb.like(cb.lower(targetFilterQueryRoot.get(JpaTargetFilterQuery_.name)), searchTextToLower); }; } } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/TargetSpecifications.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/TargetSpecifications.java similarity index 59% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/TargetSpecifications.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/TargetSpecifications.java index de894d3a3..6571f8668 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/specifications/TargetSpecifications.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/TargetSpecifications.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.specifications; +package org.eclipse.hawkbit.repository.jpa.specifications; import java.util.Collection; import java.util.List; @@ -20,15 +20,19 @@ import javax.persistence.criteria.Root; import javax.persistence.criteria.SetJoin; import javax.validation.constraints.NotNull; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet_; +import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; +import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo; +import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo_; +import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag; +import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag_; +import org.eclipse.hawkbit.repository.jpa.model.JpaTarget_; import org.eclipse.hawkbit.repository.model.DistributionSet; -import org.eclipse.hawkbit.repository.model.DistributionSet_; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetInfo; -import org.eclipse.hawkbit.repository.model.TargetInfo_; import org.eclipse.hawkbit.repository.model.TargetTag; -import org.eclipse.hawkbit.repository.model.TargetTag_; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; -import org.eclipse.hawkbit.repository.model.Target_; import org.springframework.data.jpa.domain.Specification; /** @@ -50,10 +54,11 @@ public final class TargetSpecifications { * * @return the {@link Target} {@link Specification} */ - public static Specification byControllerIdWithStatusAndTagsInJoin(final Collection controllerIDs) { + public static Specification byControllerIdWithStatusAndTagsInJoin( + final Collection controllerIDs) { return (targetRoot, query, cb) -> { - final Predicate predicate = targetRoot.get(Target_.controllerId).in(controllerIDs); - targetRoot.fetch(Target_.tags, JoinType.LEFT); + final Predicate predicate = targetRoot.get(JpaTarget_.controllerId).in(controllerIDs); + targetRoot.fetch(JpaTarget_.tags, JoinType.LEFT); query.distinct(true); return predicate; }; @@ -68,12 +73,12 @@ public final class TargetSpecifications { * * @return the {@link Target} {@link Specification} */ - public static Specification byControllerIdWithStatusAndAssignedInJoin( + public static Specification byControllerIdWithStatusAndAssignedInJoin( final Collection controllerIDs) { return (targetRoot, query, cb) -> { - final Predicate predicate = targetRoot.get(Target_.controllerId).in(controllerIDs); - targetRoot.fetch(Target_.assignedDistributionSet); + final Predicate predicate = targetRoot.get(JpaTarget_.controllerId).in(controllerIDs); + targetRoot.fetch(JpaTarget_.assignedDistributionSet); return predicate; }; } @@ -89,19 +94,19 @@ public final class TargetSpecifications { * join it. * @return the {@link Target} {@link Specification} */ - public static Specification hasTargetUpdateStatus(final Collection updateStatus, + public static Specification hasTargetUpdateStatus(final Collection updateStatus, final boolean fetch) { return (targetRoot, query, cb) -> { if (!query.getResultType().isAssignableFrom(Long.class)) { if (fetch) { - targetRoot.fetch(Target_.targetInfo); + targetRoot.fetch(JpaTarget_.targetInfo); } else { - targetRoot.join(Target_.targetInfo); + targetRoot.join(JpaTarget_.targetInfo); } - return targetRoot.get(Target_.targetInfo).get(TargetInfo_.updateStatus).in(updateStatus); + return targetRoot.get(JpaTarget_.targetInfo).get(JpaTargetInfo_.updateStatus).in(updateStatus); } - final Join targetInfoJoin = targetRoot.join(Target_.targetInfo); - return targetInfoJoin.get(TargetInfo_.updateStatus).in(updateStatus); + final Join targetInfoJoin = targetRoot.join(JpaTarget_.targetInfo); + return targetInfoJoin.get(JpaTargetInfo_.updateStatus).in(updateStatus); }; } @@ -113,11 +118,11 @@ public final class TargetSpecifications { * to be filtered on * @return the {@link Target} {@link Specification} */ - public static Specification likeNameOrDescriptionOrIp(final String searchText) { + public static Specification likeNameOrDescriptionOrIp(final String searchText) { return (targetRoot, query, cb) -> { final String searchTextToLower = searchText.toLowerCase(); - return cb.or(cb.like(cb.lower(targetRoot.get(Target_.name)), searchTextToLower), - cb.like(cb.lower(targetRoot.get(Target_.description)), searchTextToLower)); + return cb.or(cb.like(cb.lower(targetRoot.get(JpaTarget_.name)), searchTextToLower), + cb.like(cb.lower(targetRoot.get(JpaTarget_.description)), searchTextToLower)); }; } @@ -129,14 +134,14 @@ public final class TargetSpecifications { * to be filtered on * @return the {@link Target} {@link Specification} */ - public static Specification hasInstalledOrAssignedDistributionSet(@NotNull final Long distributionId) { + public static Specification hasInstalledOrAssignedDistributionSet(@NotNull final Long distributionId) { return (targetRoot, query, cb) -> { - final Join targetInfoJoin = targetRoot.join(Target_.targetInfo); + final Join targetInfoJoin = targetRoot.join(JpaTarget_.targetInfo); return cb.or( - cb.equal(targetInfoJoin.get(TargetInfo_.installedDistributionSet).get(DistributionSet_.id), + cb.equal(targetInfoJoin.get(JpaTargetInfo_.installedDistributionSet).get(JpaDistributionSet_.id), distributionId), - cb.equal(targetRoot. get(Target_.assignedDistributionSet).get(DistributionSet_.id), - distributionId)); + cb.equal(targetRoot. get(JpaTarget_.assignedDistributionSet) + .get(JpaDistributionSet_.id), distributionId)); }; } @@ -150,13 +155,12 @@ public final class TargetSpecifications { * set that is not yet assigned * @return the {@link Target} {@link Specification} */ - public static Specification hasControllerIdAndAssignedDistributionSetIdNot(final List tIDs, + public static Specification hasControllerIdAndAssignedDistributionSetIdNot(final List tIDs, @NotNull final Long distributionId) { - return (targetRoot, query, cb) -> cb - .and(targetRoot.get(Target_.controllerId).in(tIDs), - cb.or(cb.notEqual(targetRoot. get(Target_.assignedDistributionSet) - .get(DistributionSet_.id), distributionId), - cb.isNull(targetRoot. get(Target_.assignedDistributionSet)))); + return (targetRoot, query, cb) -> cb.and(targetRoot.get(JpaTarget_.controllerId).in(tIDs), + cb.or(cb.notEqual(targetRoot. get(JpaTarget_.assignedDistributionSet) + .get(JpaDistributionSet_.id), distributionId), + cb.isNull(targetRoot. get(JpaTarget_.assignedDistributionSet)))); } /** @@ -169,7 +173,7 @@ public final class TargetSpecifications { * flag to get targets with no tag assigned * @return the {@link Target} {@link Specification} */ - public static Specification hasTags(final String[] tagNames, final Boolean selectTargetWithNoTag) { + public static Specification hasTags(final String[] tagNames, final Boolean selectTargetWithNoTag) { return (targetRoot, query, cb) -> { final Predicate predicate = getPredicate(targetRoot, cb, selectTargetWithNoTag, tagNames); query.distinct(true); @@ -177,10 +181,10 @@ public final class TargetSpecifications { }; } - private static Predicate getPredicate(final Root targetRoot, final CriteriaBuilder cb, + private static Predicate getPredicate(final Root targetRoot, final CriteriaBuilder cb, final Boolean selectTargetWithNoTag, final String[] tagNames) { - final SetJoin tags = targetRoot.join(Target_.tags, JoinType.LEFT); - final Path exp = tags.get(TargetTag_.name); + final SetJoin tags = targetRoot.join(JpaTarget_.tags, JoinType.LEFT); + final Path exp = tags.get(JpaTargetTag_.name); if (selectTargetWithNoTag) { if (tagNames != null) { return cb.or(exp.isNull(), exp.in(tagNames)); @@ -200,9 +204,9 @@ public final class TargetSpecifications { * the ID of the distribution set which must be assigned * @return the {@link Target} {@link Specification} */ - public static Specification hasAssignedDistributionSet(final Long distributionSetId) { + public static Specification hasAssignedDistributionSet(final Long distributionSetId) { return (targetRoot, query, cb) -> cb.equal( - targetRoot. get(Target_.assignedDistributionSet).get(DistributionSet_.id), + targetRoot. get(JpaTarget_.assignedDistributionSet).get(JpaDistributionSet_.id), distributionSetId); } @@ -214,10 +218,10 @@ public final class TargetSpecifications { * the ID of the distribution set which must be assigned * @return the {@link Target} {@link Specification} */ - public static Specification hasInstalledDistributionSet(final Long distributionSetId) { + public static Specification hasInstalledDistributionSet(final Long distributionSetId) { return (targetRoot, query, cb) -> { - final Join targetInfoJoin = targetRoot.join(Target_.targetInfo); - return cb.equal(targetInfoJoin.get(TargetInfo_.installedDistributionSet).get(DistributionSet_.id), + final Join targetInfoJoin = targetRoot.join(JpaTarget_.targetInfo); + return cb.equal(targetInfoJoin.get(JpaTargetInfo_.installedDistributionSet).get(JpaDistributionSet_.id), distributionSetId); }; } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Action.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Action.java index eedb36037..51b57bb17 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Action.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Action.java @@ -10,193 +10,66 @@ package org.eclipse.hawkbit.repository.model; import java.util.List; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.ConstraintMode; -import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; -import javax.persistence.FetchType; -import javax.persistence.ForeignKey; -import javax.persistence.Index; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.NamedAttributeNode; -import javax.persistence.NamedEntityGraph; -import javax.persistence.NamedEntityGraphs; -import javax.persistence.NamedSubgraph; -import javax.persistence.OneToMany; -import javax.persistence.Table; -import javax.persistence.Transient; - -import org.eclipse.hawkbit.cache.CacheField; -import org.eclipse.hawkbit.cache.CacheKeys; -import org.eclipse.persistence.annotations.CascadeOnDelete; - -/** - *

- * Applicable transition changes of the {@link SoftwareModule}s state of a - * {@link Target}, e.g. install, uninstall, update and preparations for the - * transition change, i.e. download. - *

- * - *

- * Actions are managed by the SP server and applied to the targets by the - * client. - *

- */ -@Table(name = "sp_action", indexes = { @Index(name = "sp_idx_action_01", columnList = "tenant,distribution_set"), - @Index(name = "sp_idx_action_02", columnList = "tenant,target,active"), - @Index(name = "sp_idx_action_prim", columnList = "tenant,id") }) -@NamedEntityGraphs({ @NamedEntityGraph(name = "Action.ds", attributeNodes = { @NamedAttributeNode("distributionSet") }), - @NamedEntityGraph(name = "Action.all", attributeNodes = { @NamedAttributeNode("distributionSet"), - @NamedAttributeNode(value = "target", subgraph = "target.ds") }, subgraphs = @NamedSubgraph(name = "target.ds", attributeNodes = @NamedAttributeNode("assignedDistributionSet"))) }) -@Entity -public class Action extends TenantAwareBaseEntity { - private static final long serialVersionUID = 1L; +public interface Action extends TenantAwareBaseEntity { /** * indicating that target action has no force time {@link #hasForcedTime()}. */ public static final long NO_FORCE_TIME = 0L; - /** - * the {@link DistributionSet} which should be installed by this action. - */ - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "distribution_set", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_action_ds")) - private DistributionSet distributionSet; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "target", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_action_target")) - private Target target; - - @Column(name = "active") - private boolean active; - - @Column(name = "action_type", nullable = false) - @Enumerated(EnumType.STRING) - private ActionType actionType; - - @Column(name = "forced_time") - private long forcedTime; - - @Column(name = "status") - private Status status; - - @CascadeOnDelete - @OneToMany(mappedBy = "action", targetEntity = ActionStatus.class, fetch = FetchType.LAZY, cascade = { - CascadeType.REMOVE }) - private List actionStatus; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "rolloutgroup", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_action_rolloutgroup")) - private RolloutGroup rolloutGroup; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "rollout", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_action_rollout")) - private Rollout rollout; - - /** - * Note: filled only in {@link Status#DOWNLOAD}. - */ - @Transient - @CacheField(key = CacheKeys.DOWNLOAD_PROGRESS_PERCENT) - private int downloadProgressPercent; - /** * @return the distributionSet */ - public DistributionSet getDistributionSet() { - return distributionSet; - } + DistributionSet getDistributionSet(); /** * @param distributionSet * the distributionSet to set */ - public void setDistributionSet(final DistributionSet distributionSet) { - this.distributionSet = distributionSet; - } + void setDistributionSet(DistributionSet distributionSet); /** * @return true when action is in state {@link Status#CANCELING} or * {@link Status#CANCELED}, false otherwise */ - public boolean isCancelingOrCanceled() { - return status == Status.CANCELING || status == Status.CANCELED; - } + boolean isCancelingOrCanceled(); - public void setActive(final boolean active) { - this.active = active; - } + void setActive(boolean active); - public Status getStatus() { - return status; - } + Status getStatus(); - public void setStatus(final Status status) { - this.status = status; - } + void setStatus(Status status); - public int getDownloadProgressPercent() { - return downloadProgressPercent; - } + int getDownloadProgressPercent(); - public void setDownloadProgressPercent(final int downloadProgressPercent) { - this.downloadProgressPercent = downloadProgressPercent; - } + void setDownloadProgressPercent(int downloadProgressPercent); - public boolean isActive() { - return active; - } + boolean isActive(); - public void setActionType(final ActionType actionType) { - this.actionType = actionType; - } + void setActionType(ActionType actionType); /** * @return the actionType */ - public ActionType getActionType() { - return actionType; - } + ActionType getActionType(); - public List getActionStatus() { - return actionStatus; - } + List getActionStatus(); - public void setTarget(final Target target) { - this.target = target; - } + void setTarget(Target target); - public Target getTarget() { - return target; - } + Target getTarget(); - public long getForcedTime() { - return forcedTime; - } + long getForcedTime(); - public void setForcedTime(final long forcedTime) { - this.forcedTime = forcedTime; - } + void setForcedTime(long forcedTime); - public RolloutGroup getRolloutGroup() { - return rolloutGroup; - } + RolloutGroup getRolloutGroup(); - public void setRolloutGroup(final RolloutGroup rolloutGroup) { - this.rolloutGroup = rolloutGroup; - } + void setRolloutGroup(RolloutGroup rolloutGroup); - public Rollout getRollout() { - return rollout; - } + Rollout getRollout(); - public void setRollout(final Rollout rollout) { - this.rollout = rollout; - } + void setRollout(Rollout rollout); /** * checks if the {@link #forcedTime} is hit by the given @@ -210,12 +83,7 @@ public class Action extends TenantAwareBaseEntity { * {@link ActionType#TIMEFORCED} and the given {@code hitTimeMillis} * is greater than the {@link #forcedTime} otherwise {@code false} */ - public boolean isHitAutoForceTime(final long hitTimeMillis) { - if (actionType == ActionType.TIMEFORCED) { - return hitTimeMillis >= forcedTime; - } - return false; - } + boolean isHitAutoForceTime(long hitTimeMillis); /** * @return {@code true} if either the {@link #type} is @@ -223,28 +91,12 @@ public class Action extends TenantAwareBaseEntity { * then if the {@link #forcedTime} has been exceeded otherwise * always {@code false} */ - public boolean isForce() { - switch (actionType) { - case FORCED: - return true; - case TIMEFORCED: - return isHitAutoForceTime(System.currentTimeMillis()); - default: - return false; - } - } + boolean isForce(); /** * @return true when action is forced, false otherwise */ - public boolean isForced() { - return actionType == ActionType.FORCED; - } - - @Override - public String toString() { - return "Action [distributionSet=" + distributionSet + ", getId()=" + getId() + "]"; - } + boolean isForced(); /** * Action status as reported by the controller. @@ -309,4 +161,5 @@ public class Action extends TenantAwareBaseEntity { public enum ActionType { FORCED, SOFT, TIMEFORCED; } -} + +} \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ActionStatus.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ActionStatus.java index c8d320abd..05f6966d8 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ActionStatus.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ActionStatus.java @@ -8,107 +8,15 @@ */ package org.eclipse.hawkbit.repository.model; -import java.util.ArrayList; import java.util.List; -import javax.persistence.CollectionTable; -import javax.persistence.Column; -import javax.persistence.ConstraintMode; -import javax.persistence.ElementCollection; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.ForeignKey; -import javax.persistence.Index; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.NamedAttributeNode; -import javax.persistence.NamedEntityGraph; -import javax.persistence.Table; - import org.eclipse.hawkbit.repository.model.Action.Status; -import org.eclipse.persistence.annotations.CascadeOnDelete; -import com.google.common.base.Splitter; +public interface ActionStatus extends TenantAwareBaseEntity { -/** - * Entity to store the status for a specific action. - */ -@Table(name = "sp_action_status", indexes = { @Index(name = "sp_idx_action_status_01", columnList = "tenant,action"), - @Index(name = "sp_idx_action_status_02", columnList = "tenant,action,status"), - @Index(name = "sp_idx_action_status_prim", columnList = "tenant,id") }) -@NamedEntityGraph(name = "ActionStatus.withMessages", attributeNodes = { @NamedAttributeNode("messages") }) -@Entity -public class ActionStatus extends TenantAwareBaseEntity { - private static final long serialVersionUID = 1L; + Long getOccurredAt(); - @Column(name = "target_occurred_at") - private Long occurredAt; - - @ManyToOne(fetch = FetchType.LAZY, optional = false) - @JoinColumn(name = "action", nullable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_act_stat_action")) - private Action action; - - @Column(name = "status") - private Status status; - - @CascadeOnDelete - @ElementCollection(fetch = FetchType.LAZY, targetClass = String.class) - @CollectionTable(name = "sp_action_status_messages", joinColumns = @JoinColumn(name = "action_status_id", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_stat_msg_act_stat")), indexes = { - @Index(name = "sp_idx_action_status_msgs_01", columnList = "action_status_id") }) - @Column(name = "detail_message", length = 512) - private final List messages = new ArrayList<>(); - - /** - * Creates a new {@link ActionStatus} object. - * - * @param action - * the action for this action status - * @param status - * the status for this action status - * @param occurredAt - * the occurred timestamp - */ - public ActionStatus(final Action action, final Status status, final Long occurredAt) { - this.action = action; - this.status = status; - this.occurredAt = occurredAt; - } - - /** - * Creates a new {@link ActionStatus} object. - * - * @param action - * the action for this action status - * @param status - * the status for this action status - * @param occurredAt - * the occurred timestamp - * @param messages - * the messages which should be added to this action status - */ - public ActionStatus(final Action action, final Status status, final Long occurredAt, final String... messages) { - this.action = action; - this.status = status; - this.occurredAt = occurredAt; - for (final String msg : messages) { - addMessage(msg); - } - } - - /** - * JPA default constructor. - */ - public ActionStatus() { - // JPA default constructor. - } - - public Long getOccurredAt() { - return occurredAt; - } - - public void setOccurredAt(final Long occurredAt) { - this.occurredAt = occurredAt; - } + void setOccurredAt(Long occurredAt); /** * Adds message including splitting in case it exceeds 512 length. @@ -116,28 +24,16 @@ public class ActionStatus extends TenantAwareBaseEntity { * @param message * to add */ - public final void addMessage(final String message) { - Splitter.fixedLength(512).split(message).forEach(messages::add); - } + void addMessage(String message); - public List getMessages() { - return messages; - } + List getMessages(); - public Action getAction() { - return action; - } + Action getAction(); - public void setAction(final Action action) { - this.action = action; - } + void setAction(Action action); - public Status getStatus() { - return status; - } + Status getStatus(); - public void setStatus(final Status status) { - this.status = status; - } + void setStatus(Status status); -} +} \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ActionWithStatusCount.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ActionWithStatusCount.java index 73eab32f9..4b81320e8 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ActionWithStatusCount.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ActionWithStatusCount.java @@ -8,6 +8,7 @@ */ package org.eclipse.hawkbit.repository.model; +import org.eclipse.hawkbit.repository.jpa.model.JpaAction; import org.eclipse.hawkbit.repository.model.Action.ActionType; import org.eclipse.hawkbit.repository.model.Action.Status; @@ -16,6 +17,7 @@ import org.eclipse.hawkbit.repository.model.Action.Status; * action's {@link ActionStatus}. * */ +// TODO: create interface public class ActionWithStatusCount { private final Long actionStatusCount; private final Long actionId; @@ -28,7 +30,7 @@ public class ActionWithStatusCount { private final Long dsId; private final String dsName; private final String dsVersion; - private final Action action; + private final JpaAction action; private final String rolloutName; /** @@ -78,7 +80,7 @@ public class ActionWithStatusCount { this.actionStatusCount = actionStatusCount; this.rolloutName = rolloutName; - action = new Action(); + action = new JpaAction(); action.setActionType(actionType); action.setActive(actionActive); action.setForcedTime(actionForceTime); diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Artifact.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Artifact.java index b384a3100..a4db06d25 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Artifact.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Artifact.java @@ -8,49 +8,16 @@ */ package org.eclipse.hawkbit.repository.model; -import javax.persistence.Column; -import javax.persistence.MappedSuperclass; +public interface Artifact extends TenantAwareBaseEntity { -/** - * Tenant specific locally stored artifact representation that is used by - * {@link SoftwareModule}. - */ -@MappedSuperclass -public abstract class Artifact extends TenantAwareBaseEntity { - private static final long serialVersionUID = 1L; + SoftwareModule getSoftwareModule(); - @Column(name = "sha1_hash", length = 40, nullable = true) - private String sha1Hash; + void setSoftwareModule(SoftwareModule softwareModule); - @Column(name = "md5_hash", length = 32, nullable = true) - private String md5Hash; + String getMd5Hash(); - @Column(name = "file_size") - private Long size; + String getSha1Hash(); - public abstract SoftwareModule getSoftwareModule(); + Long getSize(); - public String getMd5Hash() { - return md5Hash; - } - - public String getSha1Hash() { - return sha1Hash; - } - - public void setMd5Hash(final String md5Hash) { - this.md5Hash = md5Hash; - } - - public void setSha1Hash(final String sha1Hash) { - this.sha1Hash = sha1Hash; - } - - public Long getSize() { - return size; - } - - public void setSize(final Long size) { - this.size = size; - } -} +} \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/BaseEntity.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/BaseEntity.java index 65300c6c4..0b8a8c5ee 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/BaseEntity.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/BaseEntity.java @@ -10,171 +10,18 @@ package org.eclipse.hawkbit.repository.model; import java.io.Serializable; -import javax.persistence.Access; -import javax.persistence.AccessType; -import javax.persistence.Column; -import javax.persistence.EntityListeners; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.MappedSuperclass; -import javax.persistence.Version; - -import org.eclipse.hawkbit.eventbus.CacheFieldEntityListener; -import org.eclipse.hawkbit.eventbus.EntityPropertyChangeListener; -import org.springframework.data.annotation.CreatedBy; -import org.springframework.data.annotation.CreatedDate; -import org.springframework.data.annotation.LastModifiedBy; -import org.springframework.data.annotation.LastModifiedDate; -import org.springframework.data.jpa.domain.support.AuditingEntityListener; import org.springframework.hateoas.Identifiable; -/** - * Holder of the base attributes common to all entities. - * - */ -@MappedSuperclass -@Access(AccessType.FIELD) -@EntityListeners({ AuditingEntityListener.class, CacheFieldEntityListener.class, EntityPropertyChangeListener.class }) -public abstract class BaseEntity implements Serializable, Identifiable { - private static final long serialVersionUID = 1L; +public interface BaseEntity extends Serializable, Identifiable { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "id") - private Long id; + Long getCreatedAt(); - private String createdBy; - private String lastModifiedBy; - private Long createdAt; - private Long lastModifiedAt; + String getCreatedBy(); - @Version - @Column(name = "optlock_revision") - private long optLockRevision; + Long getLastModifiedAt(); - /** - * Default constructor needed for JPA entities. - */ - public BaseEntity() { - // Default constructor needed for JPA entities. - } + String getLastModifiedBy(); - @Access(AccessType.PROPERTY) - @Column(name = "created_at", insertable = true, updatable = false) - public Long getCreatedAt() { - return createdAt; - } + long getOptLockRevision(); - @Access(AccessType.PROPERTY) - @Column(name = "created_by", insertable = true, updatable = false, length = 40) - public String getCreatedBy() { - return createdBy; - } - - @Access(AccessType.PROPERTY) - @Column(name = "last_modified_at", insertable = false, updatable = true) - public Long getLastModifiedAt() { - return lastModifiedAt; - } - - @Access(AccessType.PROPERTY) - @Column(name = "last_modified_by", insertable = false, updatable = true, length = 40) - public String getLastModifiedBy() { - return lastModifiedBy; - } - - @CreatedBy - public void setCreatedBy(final String createdBy) { - this.createdBy = createdBy; - } - - @LastModifiedBy - public void setLastModifiedBy(final String lastModifiedBy) { - this.lastModifiedBy = lastModifiedBy; - } - - @CreatedDate - public void setCreatedAt(final Long createdAt) { - this.createdAt = createdAt; - } - - @LastModifiedDate - public void setLastModifiedAt(final Long lastModifiedAt) { - this.lastModifiedAt = lastModifiedAt; - } - - public long getOptLockRevision() { - return optLockRevision; - } - - // for test purposes only - void setOptLockRevision(final long optLockRevision) { - this.optLockRevision = optLockRevision; - } - - @Override - public Long getId() { - return id; - } - - @Override - public String toString() { - return "BaseEntity [id=" + id + "]"; - } - - public void setId(final Long id) { - this.id = id; - } - - /** - * Defined equals/hashcode strategy for the repository in general is that an - * entity is equal if it has the same {@link #getId()} and - * {@link #getOptLockRevision()} and class. - * - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { // NOSONAR - as this is generated code - final int prime = 31; - int result = 1; - result = prime * result + (id == null ? 0 : id.hashCode()); - result = prime * result + (int) (optLockRevision ^ optLockRevision >>> 32); - result = prime * result + this.getClass().getName().hashCode(); - return result; - } - - /** - * Defined equals/hashcode strategy for the repository in general is that an - * entity is equal if it has the same {@link #getId()} and - * {@link #getOptLockRevision()} and class. - * - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals(final Object obj) { // NOSONAR - as this is generated - // code - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (!(this.getClass().isInstance(obj))) { - return false; - } - final BaseEntity other = (BaseEntity) obj; - if (id == null) { - if (other.id != null) { - return false; - } - } else if (!id.equals(other.id)) { - return false; - } - if (optLockRevision != other.optLockRevision) { - return false; - } - return true; - } - -} +} \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSet.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSet.java index a9d390284..41b1e5f5d 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSet.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSet.java @@ -8,198 +8,47 @@ */ package org.eclipse.hawkbit.repository.model; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; import java.util.List; -import java.util.Optional; import java.util.Set; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.ConstraintMode; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.ForeignKey; -import javax.persistence.Index; -import javax.persistence.JoinColumn; -import javax.persistence.JoinTable; -import javax.persistence.ManyToMany; -import javax.persistence.ManyToOne; -import javax.persistence.NamedAttributeNode; -import javax.persistence.NamedEntityGraph; -import javax.persistence.OneToMany; -import javax.persistence.Table; -import javax.persistence.UniqueConstraint; +public interface DistributionSet extends NamedVersionedEntity { -import org.eclipse.hawkbit.repository.exception.DistributionSetTypeUndefinedException; -import org.eclipse.hawkbit.repository.exception.UnsupportedSoftwareModuleForThisDistributionSetException; -import org.eclipse.persistence.annotations.CascadeOnDelete; + Set getTags(); -/** - *

- * The {@link DistributionSet} is defined in the SP repository and contains at - * least an OS and an Agent Hub. - *

- * - *

- * A {@link Target} has exactly one target {@link DistributionSet} assigned. - *

- * - */ -@Entity -@Table(name = "sp_distribution_set", uniqueConstraints = { - @UniqueConstraint(columnNames = { "name", "version", "tenant" }, name = "uk_distrib_set") }, indexes = { - @Index(name = "sp_idx_distribution_set_01", columnList = "tenant,deleted,name,complete"), - @Index(name = "sp_idx_distribution_set_02", columnList = "tenant,required_migration_step"), - @Index(name = "sp_idx_distribution_set_prim", columnList = "tenant,id") }) -@NamedEntityGraph(name = "DistributionSet.detail", attributeNodes = { @NamedAttributeNode("modules"), - @NamedAttributeNode("tags"), @NamedAttributeNode("type") }) -public class DistributionSet extends NamedVersionedEntity { - private static final long serialVersionUID = 1L; - - @Column(name = "required_migration_step") - private boolean requiredMigrationStep = false; - - @ManyToMany(targetEntity = SoftwareModule.class, fetch = FetchType.LAZY) - @JoinTable(name = "sp_ds_module", joinColumns = { - @JoinColumn(name = "ds_id", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_module_ds")) }, inverseJoinColumns = { - @JoinColumn(name = "module_id", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_module_module")) }) - private final Set modules = new HashSet<>(); - - @ManyToMany(targetEntity = DistributionSetTag.class) - @JoinTable(name = "sp_ds_dstag", joinColumns = { - @JoinColumn(name = "ds", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_dstag_ds")) }, inverseJoinColumns = { - @JoinColumn(name = "TAG", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_dstag_tag")) }) - private Set tags = new HashSet<>(); - - @Column(name = "deleted") - private boolean deleted = false; - - @OneToMany(mappedBy = "assignedDistributionSet", targetEntity = Target.class, fetch = FetchType.LAZY) - private List assignedToTargets; - - @OneToMany(mappedBy = "installedDistributionSet", targetEntity = TargetInfo.class, fetch = FetchType.LAZY) - private List installedAtTargets; - - @OneToMany(mappedBy = "distributionSet", targetEntity = Action.class, fetch = FetchType.LAZY) - private List actions; - - @CascadeOnDelete - @OneToMany(fetch = FetchType.LAZY, cascade = { CascadeType.REMOVE }) - @JoinColumn(name = "ds_id", insertable = false, updatable = false) - private final List metadata = new ArrayList<>(); - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "ds_id", nullable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_dstype_ds")) - private DistributionSetType type; - - @Column(name = "complete") - private boolean complete = false; - - /** - * Default constructor. - */ - public DistributionSet() { - super(); - } - - /** - * Parameterized constructor. - * - * @param name - * of the {@link DistributionSet} - * @param version - * of the {@link DistributionSet} - * @param description - * of the {@link DistributionSet} - * @param type - * of the {@link DistributionSet} - * @param moduleList - * {@link SoftwareModule}s of the {@link DistributionSet} - */ - public DistributionSet(final String name, final String version, final String description, - final DistributionSetType type, final Iterable moduleList) { - super(name, version, description); - - this.type = type; - if (moduleList != null) { - moduleList.forEach(this::addModule); - } - if (this.type != null) { - complete = this.type.checkComplete(this); - } - } - - public Set getTags() { - return tags; - } - - public boolean isDeleted() { - return deleted; - } + boolean isDeleted(); /** * @return immutable list of meta data elements. */ - public List getMetadata() { - return Collections.unmodifiableList(metadata); - } + List getMetadata(); - public List getActions() { - return actions; - } + List getActions(); - public boolean isRequiredMigrationStep() { - return requiredMigrationStep; - } + boolean isRequiredMigrationStep(); - public DistributionSet setDeleted(final boolean deleted) { - this.deleted = deleted; - return this; - } + DistributionSet setDeleted(boolean deleted); - public DistributionSet setRequiredMigrationStep(final boolean isRequiredMigrationStep) { - requiredMigrationStep = isRequiredMigrationStep; - return this; - } + DistributionSet setRequiredMigrationStep(boolean isRequiredMigrationStep); - public DistributionSet setTags(final Set tags) { - this.tags = tags; - return this; - } + DistributionSet setTags(Set tags); /** * @return the assignedTargets */ - public List getAssignedTargets() { - return assignedToTargets; - } + List getAssignedTargets(); /** * @return the installedTargets */ - public List getInstalledTargets() { - return installedAtTargets; - } - - @Override - public String toString() { - return "DistributionSet [getName()=" + getName() + ", getOptLockRevision()=" + getOptLockRevision() - + ", getId()=" + getId() + "]"; - } + List getInstalledTargets(); /** * * @return unmodifiableSet of {@link SoftwareModule}. */ - public Set getModules() { - return Collections.unmodifiableSet(modules); - } + Set getModules(); - public DistributionSetIdName getDistributionSetIdName() { - return new DistributionSetIdName(getId(), getName(), getVersion()); - } + DistributionSetIdName getDistributionSetIdName(); /** * @param softwareModule @@ -207,41 +56,7 @@ public class DistributionSet extends NamedVersionedEntity { * if it already existed in the set * */ - public boolean addModule(final SoftwareModule softwareModule) { - - // we cannot allow that modules are added without a type defined - if (type == null) { - throw new DistributionSetTypeUndefinedException(); - } - - // check if it is allowed to such a module to this DS type - if (!type.containsModuleType(softwareModule.getType())) { - throw new UnsupportedSoftwareModuleForThisDistributionSetException(); - } - - final Optional found = modules.stream() - .filter(module -> module.getId().equals(softwareModule.getId())).findFirst(); - - if (found.isPresent()) { - return false; - } - - final long allready = modules.stream() - .filter(module -> module.getType().getKey().equals(softwareModule.getType().getKey())).count(); - - if (allready >= softwareModule.getType().getMaxAssignments()) { - final Optional sameKey = modules.stream() - .filter(module -> module.getType().getKey().equals(softwareModule.getType().getKey())).findFirst(); - modules.remove(sameKey.get()); - } - - if (modules.add(softwareModule)) { - complete = type.checkComplete(this); - return true; - } - - return false; - } + boolean addModule(SoftwareModule softwareModule); /** * Removed given {@link SoftwareModule} from this DS instance. @@ -250,19 +65,7 @@ public class DistributionSet extends NamedVersionedEntity { * to remove * @return true if element was found and removed */ - public boolean removeModule(final SoftwareModule softwareModule) { - final Optional found = modules.stream() - .filter(module -> module.getId().equals(softwareModule.getId())).findFirst(); - - if (found.isPresent()) { - modules.remove(found.get()); - complete = type.checkComplete(this); - return true; - } - - return false; - - } + boolean removeModule(SoftwareModule softwareModule); /** * Searches through modules for the given type. @@ -272,26 +75,12 @@ public class DistributionSet extends NamedVersionedEntity { * @return SoftwareModule of given type or null if not in the * list. */ - public SoftwareModule findFirstModuleByType(final SoftwareModuleType type) { - final Optional result = modules.stream().filter(module -> module.getType().equals(type)) - .findFirst(); + SoftwareModule findFirstModuleByType(SoftwareModuleType type); - if (result.isPresent()) { - return result.get(); - } + DistributionSetType getType(); - return null; - } + void setType(DistributionSetType type); - public DistributionSetType getType() { - return type; - } + boolean isComplete(); - public void setType(final DistributionSetType type) { - this.type = type; - } - - public boolean isComplete() { - return complete; - } -} +} \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetMetadata.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetMetadata.java index 67a99506c..187b04e81 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetMetadata.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetMetadata.java @@ -8,73 +8,10 @@ */ package org.eclipse.hawkbit.repository.model; -import javax.persistence.ConstraintMode; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.ForeignKey; -import javax.persistence.Id; -import javax.persistence.IdClass; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.Table; +public interface DistributionSetMetadata extends MetaData { -/** - * Meta data for {@link DistributionSet}. - * - */ -@IdClass(DsMetadataCompositeKey.class) -@Entity -@Table(name = "sp_ds_metadata") -public class DistributionSetMetadata extends MetaData { - private static final long serialVersionUID = 1L; + void setDistributionSet(DistributionSet distributionSet); - @Id - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "ds_id", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_metadata_ds")) - private DistributionSet distributionSet; + DistributionSet getDistributionSet(); - public DistributionSetMetadata() { - // default public constructor for JPA - } - - public DistributionSetMetadata(final String key, final DistributionSet distributionSet, final String value) { - super(key, value); - this.distributionSet = distributionSet; - } - - public DsMetadataCompositeKey getId() { - return new DsMetadataCompositeKey(distributionSet, getKey()); - } - - public void setDistributionSet(final DistributionSet distributionSet) { - this.distributionSet = distributionSet; - } - - public DistributionSet getDistributionSet() { - return distributionSet; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = prime * result + ((distributionSet == null) ? 0 : distributionSet.hashCode()); - return result; - } - - @Override - public boolean equals(final Object obj) { - if (!super.equals(obj)) { - return false; - } - final DistributionSetMetadata other = (DistributionSetMetadata) obj; - if (distributionSet == null) { - if (other.distributionSet != null) { - return false; - } - } else if (!distributionSet.equals(other.distributionSet)) { - return false; - } - return true; - } -} +} \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTag.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTag.java index 137fde5b9..cd5ded232 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTag.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTag.java @@ -10,77 +10,8 @@ package org.eclipse.hawkbit.repository.model; import java.util.List; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.Index; -import javax.persistence.ManyToMany; -import javax.persistence.Table; -import javax.persistence.UniqueConstraint; +public interface DistributionSetTag extends Tag { -/** - * A {@link DistributionSetTag} is used to describe DistributionSet attributes - * and use them also for filtering the DistributionSet list. - * - */ -@Entity -@Table(name = "sp_distributionset_tag", indexes = { - @Index(name = "sp_idx_distribution_set_tag_prim", columnList = "tenant,id") }, uniqueConstraints = @UniqueConstraint(columnNames = { - "name", "tenant" }, name = "uk_ds_tag")) -public class DistributionSetTag extends Tag { - private static final long serialVersionUID = 1L; + List getAssignedToDistributionSet(); - @ManyToMany(mappedBy = "tags", targetEntity = DistributionSet.class, fetch = FetchType.LAZY) - private List assignedToDistributionSet; - - /** - * Public constructor. - * - * @param name - * of the {@link DistributionSetTag} - **/ - public DistributionSetTag(final String name) { - super(name, null, null); - } - - /** - * Public constructor. - * - * @param name - * of the {@link DistributionSetTag} - * @param description - * of the {@link DistributionSetTag} - * @param colour - * of tag in UI - */ - public DistributionSetTag(final String name, final String description, final String colour) { - super(name, description, colour); - } - - DistributionSetTag() { - super(); - } - - public List getAssignedToDistributionSet() { - return assignedToDistributionSet; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = prime * result + this.getClass().getName().hashCode(); - return result; - } - - @Override - public boolean equals(final Object obj) { // NOSONAR - as this is generated - if (!super.equals(obj)) { - return false; - } - if (!(obj instanceof DistributionSetTag)) { - return false; - } - - return true; - } -} +} \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetType.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetType.java index 61d2fc58c..f540428a9 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetType.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetType.java @@ -8,109 +8,26 @@ */ package org.eclipse.hawkbit.repository.model; -import java.util.HashSet; -import java.util.Optional; import java.util.Set; -import java.util.stream.Collectors; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.Index; -import javax.persistence.JoinColumn; -import javax.persistence.OneToMany; -import javax.persistence.Table; -import javax.persistence.UniqueConstraint; +import org.eclipse.hawkbit.repository.jpa.model.DistributionSetTypeElement; -/** - * A distribution set type defines which software module types can or have to be - * {@link DistributionSet}. - * - */ -@Entity -@Table(name = "sp_distribution_set_type", indexes = { - @Index(name = "sp_idx_distribution_set_type_01", columnList = "tenant,deleted"), - @Index(name = "sp_idx_distribution_set_type_prim", columnList = "tenant,id") }, uniqueConstraints = { - @UniqueConstraint(columnNames = { "name", "tenant" }, name = "uk_dst_name"), - @UniqueConstraint(columnNames = { "type_key", "tenant" }, name = "uk_dst_key") }) -public class DistributionSetType extends NamedEntity { - private static final long serialVersionUID = 1L; - - @OneToMany(targetEntity = DistributionSetTypeElement.class, cascade = { - CascadeType.ALL }, fetch = FetchType.EAGER, orphanRemoval = true) - @JoinColumn(name = "distribution_set_type", insertable = false, updatable = false) - private final Set elements = new HashSet<>(); - - @Column(name = "type_key", nullable = false, length = 64) - private String key; - - @Column(name = "colour", nullable = true, length = 16) - private String colour; - - @Column(name = "deleted") - private boolean deleted = false; - - public DistributionSetType() { - // default public constructor for JPA - } - - /** - * Standard constructor. - * - * @param key - * of the type (unique) - * @param name - * of the type (unique) - * @param description - * of the type - */ - public DistributionSetType(final String key, final String name, final String description) { - this(key, name, description, null); - } - - /** - * Constructor. - * - * @param key - * of the type - * @param name - * of the type - * @param description - * of the type - * @param color - * of the type. It will be null by default - */ - public DistributionSetType(final String key, final String name, final String description, final String color) { - super(name, description); - this.key = key; - colour = color; - } +public interface DistributionSetType extends NamedEntity { /** * @return the deleted */ - public boolean isDeleted() { - return deleted; - } + boolean isDeleted(); /** * @param deleted * the deleted to set */ - public void setDeleted(final boolean deleted) { - this.deleted = deleted; - } + void setDeleted(boolean deleted); - public Set getMandatoryModuleTypes() { - return elements.stream().filter(element -> element.isMandatory()).map(element -> element.getSmType()) - .collect(Collectors.toSet()); - } + Set getMandatoryModuleTypes(); - public Set getOptionalModuleTypes() { - return elements.stream().filter(element -> !element.isMandatory()).map(element -> element.getSmType()) - .collect(Collectors.toSet()); - } + Set getOptionalModuleTypes(); /** * Checks if the given {@link SoftwareModuleType} is in this @@ -120,15 +37,7 @@ public class DistributionSetType extends NamedEntity { * search for * @return true if found */ - public boolean containsModuleType(final SoftwareModuleType softwareModuleType) { - for (final DistributionSetTypeElement distributionSetTypeElement : elements) { - if (distributionSetTypeElement.getSmType().equals(softwareModuleType)) { - return true; - } - - } - return false; - } + boolean containsModuleType(SoftwareModuleType softwareModuleType); /** * Checks if the given {@link SoftwareModuleType} is in this @@ -139,11 +48,7 @@ public class DistributionSetType extends NamedEntity { * search for * @return true if found */ - public boolean containsMandatoryModuleType(final SoftwareModuleType softwareModuleType) { - return elements.stream().filter(element -> element.isMandatory()) - .filter(element -> element.getSmType().equals(softwareModuleType)).findFirst().isPresent(); - - } + boolean containsMandatoryModuleType(SoftwareModuleType softwareModuleType); /** * Checks if the given {@link SoftwareModuleType} is in this @@ -154,11 +59,7 @@ public class DistributionSetType extends NamedEntity { * search for by {@link SoftwareModuleType#getId()} * @return true if found */ - public boolean containsMandatoryModuleType(final Long softwareModuleTypeId) { - return elements.stream().filter(element -> element.isMandatory()) - .filter(element -> element.getSmType().getId().equals(softwareModuleTypeId)).findFirst().isPresent(); - - } + boolean containsMandatoryModuleType(Long softwareModuleTypeId); /** * Checks if the given {@link SoftwareModuleType} is in this @@ -169,11 +70,7 @@ public class DistributionSetType extends NamedEntity { * search for * @return true if found */ - public boolean containsOptionalModuleType(final SoftwareModuleType softwareModuleType) { - return elements.stream().filter(element -> !element.isMandatory()) - .filter(element -> element.getSmType().equals(softwareModuleType)).findFirst().isPresent(); - - } + boolean containsOptionalModuleType(SoftwareModuleType softwareModuleType); /** * Checks if the given {@link SoftwareModuleType} is in this @@ -184,11 +81,7 @@ public class DistributionSetType extends NamedEntity { * search by {@link SoftwareModuleType#getId()} * @return true if found */ - public boolean containsOptionalModuleType(final Long softwareModuleTypeId) { - return elements.stream().filter(element -> !element.isMandatory()) - .filter(element -> element.getSmType().getId().equals(softwareModuleTypeId)).findFirst().isPresent(); - - } + boolean containsOptionalModuleType(Long softwareModuleTypeId); /** * Compares the modules of this {@link DistributionSetType} and the given @@ -198,9 +91,7 @@ public class DistributionSetType extends NamedEntity { * to compare with * @return true if the lists are identical. */ - public boolean areModuleEntriesIdentical(final DistributionSetType dsType) { - return new HashSet(dsType.elements).equals(elements); - } + boolean areModuleEntriesIdentical(DistributionSetType dsType); /** * Adds {@link SoftwareModuleType} that is optional for the @@ -210,11 +101,7 @@ public class DistributionSetType extends NamedEntity { * to add * @return updated instance */ - public DistributionSetType addOptionalModuleType(final SoftwareModuleType smType) { - elements.add(new DistributionSetTypeElement(this, smType, false)); - - return this; - } + DistributionSetType addOptionalModuleType(SoftwareModuleType smType); /** * Adds {@link SoftwareModuleType} that is mandatory for the @@ -224,11 +111,7 @@ public class DistributionSetType extends NamedEntity { * to add * @return updated instance */ - public DistributionSetType addMandatoryModuleType(final SoftwareModuleType smType) { - elements.add(new DistributionSetTypeElement(this, smType, true)); - - return this; - } + DistributionSetType addMandatoryModuleType(SoftwareModuleType smType); /** * Removes {@link SoftwareModuleType} from the list. @@ -237,25 +120,11 @@ public class DistributionSetType extends NamedEntity { * to remove * @return updated instance */ - public DistributionSetType removeModuleType(final Long smTypeId) { - // we search by id (standard equals compares also revison) - final Optional found = elements.stream() - .filter(element -> element.getSmType().getId().equals(smTypeId)).findFirst(); + DistributionSetType removeModuleType(Long smTypeId); - if (found.isPresent()) { - elements.remove(found.get()); - } + String getKey(); - return this; - } - - public String getKey() { - return key; - } - - public void setKey(final String key) { - this.key = key; - } + void setKey(String key); /** * @param distributionSet @@ -263,26 +132,10 @@ public class DistributionSetType extends NamedEntity { * @return true if the all mandatory software module types are * in the system. */ - public boolean checkComplete(final DistributionSet distributionSet) { - return distributionSet.getModules().stream().map(module -> module.getType()).collect(Collectors.toList()) - .containsAll(getMandatoryModuleTypes()); - } + boolean checkComplete(DistributionSet distributionSet); - public String getColour() { - return colour; - } + String getColour(); - public void setColour(final String colour) { - this.colour = colour; - } + void setColour(final String colour); - public Set getElements() { - return elements; - } - - @Override - public String toString() { - return "DistributionSetType [key=" + key + ", isDeleted()=" + isDeleted() + ", getId()=" + getId() + "]"; - } - -} +} \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifact.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifact.java index 898c685a5..daf0d1ae5 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifact.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifact.java @@ -8,125 +8,20 @@ */ package org.eclipse.hawkbit.repository.model; -import java.net.URL; +public interface ExternalArtifact extends Artifact { -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.ConstraintMode; -import javax.persistence.Entity; -import javax.persistence.ForeignKey; -import javax.persistence.Index; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.Table; -import javax.validation.constraints.NotNull; + ExternalArtifactProvider getExternalArtifactProvider(); -/** - * External artifact representation with all the necessary information to - * generate an artifact {@link URL} at runtime. - * - */ -@Table(name = "sp_external_artifact", indexes = { - @Index(name = "sp_idx_external_artifact_prim", columnList = "id,tenant") }) -@Entity -public class ExternalArtifact extends Artifact { - private static final long serialVersionUID = 1L; + String getUrl(); - @ManyToOne - @JoinColumn(name = "provider", nullable = false, updatable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_art_to_ext_provider")) - private ExternalArtifactProvider externalArtifactProvider; + String getUrlSuffix(); - @Column(name = "url_suffix", length = 512) - private String urlSuffix; - - // CascadeType.PERSIST as we register ourself at the BSM - @ManyToOne(optional = false, cascade = { CascadeType.PERSIST }) - @JoinColumn(name = "software_module", nullable = false, updatable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_external_assigned_sm")) - private SoftwareModule softwareModule; - - /** - * Default constructor. - */ - public ExternalArtifact() { - super(); - } - - /** - * Constructs {@link ExternalArtifact}. - * - * @param externalArtifactProvider - * of the artifact - * @param urlSuffix - * of the artifact - * @param softwareModule - * of the artifact - */ - public ExternalArtifact(@NotNull final ExternalArtifactProvider externalArtifactProvider, final String urlSuffix, - final SoftwareModule softwareModule) { - setSoftwareModule(softwareModule); - this.externalArtifactProvider = externalArtifactProvider; - - if (urlSuffix != null) { - this.urlSuffix = urlSuffix; - } else { - this.urlSuffix = externalArtifactProvider.getDefaultSuffix(); - } - } - - /** - * @return the softwareModule - */ - @Override - public SoftwareModule getSoftwareModule() { - return softwareModule; - } - - public final void setSoftwareModule(final SoftwareModule softwareModule) { - this.softwareModule = softwareModule; - this.softwareModule.addArtifact(this); - } - - public ExternalArtifactProvider getExternalArtifactProvider() { - return externalArtifactProvider; - } - - public String getUrl() { - return new StringBuilder().append(externalArtifactProvider.getBasePath()).append(urlSuffix).toString(); - } - - public String getUrlSuffix() { - return urlSuffix; - } - - public void setExternalArtifactProvider(final ExternalArtifactProvider externalArtifactProvider) { - this.externalArtifactProvider = externalArtifactProvider; - } + void setExternalArtifactProvider(ExternalArtifactProvider externalArtifactProvider); /** * @param urlSuffix * the urlSuffix to set */ - public void setUrlSuffix(final String urlSuffix) { - this.urlSuffix = urlSuffix; - } + void setUrlSuffix(String urlSuffix); - @Override - public int hashCode() { // NOSONAR - as this is generated - final int prime = 31; - int result = super.hashCode(); - result = prime * result + this.getClass().getName().hashCode(); - return result; - } - - @Override - public boolean equals(final Object obj) { // NOSONAR - as this is generated - if (!super.equals(obj)) { - return false; - } - if (!(obj instanceof ExternalArtifact)) { - return false; - } - - return true; - } -} +} \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifactProvider.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifactProvider.java index 9fa8714ac..bb9f2fbea 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifactProvider.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifactProvider.java @@ -8,69 +8,14 @@ */ package org.eclipse.hawkbit.repository.model; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Index; -import javax.persistence.Table; +public interface ExternalArtifactProvider extends NamedEntity { -/** - * External repositories for artifact storage. The SP server provides URLs for - * the targets to download from these external resources but does not access - * them itself. - * - */ -@Table(name = "sp_external_provider", indexes = { - @Index(name = "sp_idx_external_provider_prim", columnList = "tenant,id") }) -@Entity -public class ExternalArtifactProvider extends NamedEntity { - private static final long serialVersionUID = 1L; + String getBasePath(); - @Column(name = "base_url", length = 512, nullable = false) - private String basePath; + String getDefaultSuffix(); - @Column(name = "default_url_suffix", length = 512, nullable = true) - private String defaultSuffix; + void setBasePath(String basePath); - /** - * Constructs {@link ExternalArtifactProvider} based on given properties. - * - * @param name - * of the provided - * @param description - * which is optional - * @param baseURL - * of all {@link ExternalArtifact}s of the provider - * @param defaultUrlSuffix - * that is used if {@link ExternalArtifact#getUrlSuffix()} is - * empty. - */ - public ExternalArtifactProvider(final String name, final String description, final String baseURL, - final String defaultUrlSuffix) { - super(name, description); - basePath = baseURL; - defaultSuffix = defaultUrlSuffix; - } + void setDefaultSuffix(String defaultSuffix); - ExternalArtifactProvider() { - super(); - defaultSuffix = ""; - basePath = ""; - } - - public String getBasePath() { - return basePath; - } - - public String getDefaultSuffix() { - return defaultSuffix; - } - - public void setBasePath(final String basePath) { - this.basePath = basePath; - } - - public void setDefaultSuffix(final String defaultSuffix) { - this.defaultSuffix = defaultSuffix; - } - -} +} \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/LocalArtifact.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/LocalArtifact.java index 8afcdc168..0f3a22c41 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/LocalArtifact.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/LocalArtifact.java @@ -8,106 +8,8 @@ */ package org.eclipse.hawkbit.repository.model; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.ConstraintMode; -import javax.persistence.Entity; -import javax.persistence.ForeignKey; -import javax.persistence.Index; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.Table; -import javax.validation.constraints.NotNull; +public interface LocalArtifact extends Artifact { -import com.mongodb.gridfs.GridFS; -import com.mongodb.gridfs.GridFSFile; + String getFilename(); -/** - * Tenant specific locally stored artifact representation that is used by - * {@link SoftwareModule} . It contains all information that is provided by the - * user while all SP server generated information related to the artifact (hash, - * length) is stored directly with the binary itself. - * - * - * - */ -@Table(name = "sp_artifact", indexes = { @Index(name = "sp_idx_artifact_01", columnList = "tenant,software_module"), - @Index(name = "sp_idx_artifact_prim", columnList = "tenant,id") }) -@Entity -public class LocalArtifact extends Artifact { - private static final long serialVersionUID = 1L; - - @NotNull - @Column(name = "gridfs_file_name", length = 40) - private String gridFsFileName; - - @NotNull - @Column(name = "provided_file_name", length = 256) - private String filename; - - @ManyToOne(optional = false, cascade = { CascadeType.PERSIST }) - @JoinColumn(name = "software_module", nullable = false, updatable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_assigned_sm")) - private SoftwareModule softwareModule; - - /** - * Default constructor. - */ - public LocalArtifact() { - super(); - } - - /** - * Constructs artifact. - * - * @param gridFsFileName - * that is the link to the {@link GridFS} entity. - * @param filename - * that is used by {@link GridFSFile} store. - * @param softwareModule - * of this artifact - */ - public LocalArtifact(@NotNull final String gridFsFileName, @NotNull final String filename, - final SoftwareModule softwareModule) { - setSoftwareModule(softwareModule); - this.gridFsFileName = gridFsFileName; - this.filename = filename; - } - - @Override - public int hashCode() { // NOSONAR - as this is generated - final int prime = 31; - int result = super.hashCode(); - result = prime * result + this.getClass().getName().hashCode(); - return result; - } - - @Override - public boolean equals(final Object obj) { // NOSONAR - as this is generated - if (!super.equals(obj)) { - return false; - } - if (!(obj instanceof LocalArtifact)) { - return false; - } - - return true; - } - - @Override - public SoftwareModule getSoftwareModule() { - return softwareModule; - } - - public final void setSoftwareModule(final SoftwareModule softwareModule) { - this.softwareModule = softwareModule; - this.softwareModule.addArtifact(this); - } - - public String getGridFsFileName() { - return gridFsFileName; - } - - public String getFilename() { - return filename; - } -} +} \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/MetaData.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/MetaData.java index c41a0e8c9..8d6e6eed6 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/MetaData.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/MetaData.java @@ -10,89 +10,14 @@ package org.eclipse.hawkbit.repository.model; import java.io.Serializable; -import javax.persistence.Basic; -import javax.persistence.Column; -import javax.persistence.Id; -import javax.persistence.MappedSuperclass; +public interface MetaData extends Serializable { -/** - * Meta data for entities. - * - */ -@MappedSuperclass -public abstract class MetaData implements Serializable { - private static final long serialVersionUID = 1L; + String getKey(); - @Id - @Column(name = "meta_key", length = 128) - private String key; + void setKey(String key); - @Column(name = "meta_value", length = 4000) - @Basic - private String value; + String getValue(); - public MetaData(final String key, final String value) { - super(); - this.key = key; - this.value = value; - } + void setValue(String value); - public MetaData() { - // Default constructor needed for JPA entities - } - - public String getKey() { - return key; - } - - public void setKey(final String key) { - this.key = key; - } - - public String getValue() { - return value; - } - - public void setValue(final String value) { - this.value = value; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((key == null) ? 0 : key.hashCode()); - result = prime * result + ((value == null) ? 0 : value.hashCode()); - return result; - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (!(this.getClass().isInstance(obj))) { - return false; - } - final MetaData other = (MetaData) obj; - if (key == null) { - if (other.key != null) { - return false; - } - } else if (!key.equals(other.key)) { - return false; - } - if (value == null) { - if (other.value != null) { - return false; - } - } else if (!value.equals(other.value)) { - return false; - } - return true; - } - -} +} \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/NamedEntity.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/NamedEntity.java index e14d88161..1cc84bf8f 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/NamedEntity.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/NamedEntity.java @@ -8,56 +8,14 @@ */ package org.eclipse.hawkbit.repository.model; -import javax.persistence.Column; -import javax.persistence.MappedSuperclass; +public interface NamedEntity extends TenantAwareBaseEntity { -/** - * {@link TenantAwareBaseEntity} extension for all entities that are named in - * addition to their technical ID. - */ -@MappedSuperclass -public abstract class NamedEntity extends TenantAwareBaseEntity { - private static final long serialVersionUID = 1L; + String getDescription(); - @Column(name = "name", nullable = false, length = 64) - private String name; + String getName(); - @Column(name = "description", nullable = true, length = 512) - private String description; + void setDescription(String description); - /** - * Default constructor. - */ - public NamedEntity() { - super(); - } + void setName(String name); - /** - * Parameterized constructor. - * - * @param name - * of the {@link NamedEntity} - * @param description - * of the {@link NamedEntity} - */ - public NamedEntity(final String name, final String description) { - this.name = name; - this.description = description; - } - - public String getDescription() { - return description; - } - - public String getName() { - return name; - } - - public void setDescription(final String description) { - this.description = description; - } - - public void setName(final String name) { - this.name = name; - } -} +} \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/NamedVersionedEntity.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/NamedVersionedEntity.java index fa56da197..710980f13 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/NamedVersionedEntity.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/NamedVersionedEntity.java @@ -8,43 +8,10 @@ */ package org.eclipse.hawkbit.repository.model; -import javax.persistence.Column; -import javax.persistence.MappedSuperclass; +public interface NamedVersionedEntity extends NamedEntity { -/** - * Extension for {@link NamedEntity} that are versioned. - * - */ -@MappedSuperclass -public abstract class NamedVersionedEntity extends NamedEntity { - private static final long serialVersionUID = 1L; + String getVersion(); - @Column(name = "version", nullable = false, length = 64) - private String version; + void setVersion(String version); - /** - * parameterized constructor. - * - * @param name - * of the entity - * @param version - * of the entity - * @param description - */ - public NamedVersionedEntity(final String name, final String version, final String description) { - super(name, description); - this.version = version; - } - - NamedVersionedEntity() { - super(); - } - - public String getVersion() { - return version; - } - - public void setVersion(final String version) { - this.version = version; - } -} +} \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Rollout.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Rollout.java index a7f9b10cb..bf696d2fd 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Rollout.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Rollout.java @@ -10,225 +10,53 @@ package org.eclipse.hawkbit.repository.model; import java.util.List; -import javax.persistence.Column; -import javax.persistence.ConstraintMode; -import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; -import javax.persistence.FetchType; -import javax.persistence.ForeignKey; -import javax.persistence.Index; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.OneToMany; -import javax.persistence.Table; -import javax.persistence.Transient; -import javax.persistence.UniqueConstraint; - -import org.eclipse.hawkbit.cache.CacheField; -import org.eclipse.hawkbit.cache.CacheKeys; +import org.eclipse.hawkbit.repository.jpa.model.JpaRollout.RolloutStatus; import org.eclipse.hawkbit.repository.model.Action.ActionType; -/** - * @author Michael Hirsch - * - */ -@Entity -@Table(name = "sp_rollout", indexes = { - @Index(name = "sp_idx_rollout_01", columnList = "tenant,name") }, uniqueConstraints = @UniqueConstraint(columnNames = { - "name", "tenant" }, name = "uk_rollout")) -public class Rollout extends NamedEntity { +public interface Rollout extends NamedEntity { - private static final long serialVersionUID = 1L; + DistributionSet getDistributionSet(); - @OneToMany(targetEntity = RolloutGroup.class) - @JoinColumn(name = "rollout", insertable = false, updatable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_rollout_rolloutgroup")) - private List rolloutGroups; + void setDistributionSet(DistributionSet distributionSet); - @Column(name = "target_filter", length = 1024, nullable = false) - private String targetFilterQuery; + List getRolloutGroups(); - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "distribution_set", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_rolltout_ds")) - private DistributionSet distributionSet; + void setRolloutGroups(List rolloutGroups); - @Column(name = "status") - private RolloutStatus status = RolloutStatus.CREATING; + String getTargetFilterQuery(); - @Column(name = "last_check") - private long lastCheck = 0L; + void setTargetFilterQuery(String targetFilterQuery); - @Column(name = "action_type", nullable = false) - @Enumerated(EnumType.STRING) - private ActionType actionType = ActionType.FORCED; + RolloutStatus getStatus(); - @Column(name = "forced_time") - private long forcedTime; + void setStatus(RolloutStatus status); - @Column(name = "total_targets") - private long totalTargets; + long getLastCheck(); - @Transient - @CacheField(key = CacheKeys.ROLLOUT_GROUP_TOTAL) - private int rolloutGroupsTotal = 0; + void setLastCheck(long lastCheck); - @Transient - @CacheField(key = CacheKeys.ROLLOUT_GROUP_CREATED) - private int rolloutGroupsCreated = 0; + ActionType getActionType(); - @Transient - private transient TotalTargetCountStatus totalTargetCountStatus; + void setActionType(ActionType actionType); - public DistributionSet getDistributionSet() { - return distributionSet; - } + long getForcedTime(); - public void setDistributionSet(final DistributionSet distributionSet) { - this.distributionSet = distributionSet; - } + void setForcedTime(long forcedTime); - public List getRolloutGroups() { - return rolloutGroups; - } + long getTotalTargets(); - public void setRolloutGroups(final List rolloutGroups) { - this.rolloutGroups = rolloutGroups; - } + void setTotalTargets(long totalTargets); - public String getTargetFilterQuery() { - return targetFilterQuery; - } + int getRolloutGroupsTotal(); - public void setTargetFilterQuery(final String targetFilterQuery) { - this.targetFilterQuery = targetFilterQuery; - } + void setRolloutGroupsTotal(int rolloutGroupsTotal); - public RolloutStatus getStatus() { - return status; - } + int getRolloutGroupsCreated(); - public void setStatus(final RolloutStatus status) { - this.status = status; - } + void setRolloutGroupsCreated(int rolloutGroupsCreated); - public long getLastCheck() { - return lastCheck; - } + TotalTargetCountStatus getTotalTargetCountStatus(); - public void setLastCheck(final long lastCheck) { - this.lastCheck = lastCheck; - } + void setTotalTargetCountStatus(TotalTargetCountStatus totalTargetCountStatus); - public ActionType getActionType() { - return actionType; - } - - public void setActionType(final ActionType actionType) { - this.actionType = actionType; - } - - public long getForcedTime() { - return forcedTime; - } - - public void setForcedTime(final long forcedTime) { - this.forcedTime = forcedTime; - } - - public long getTotalTargets() { - return totalTargets; - } - - public void setTotalTargets(final long totalTargets) { - this.totalTargets = totalTargets; - } - - public int getRolloutGroupsTotal() { - return rolloutGroupsTotal; - } - - public void setRolloutGroupsTotal(final int rolloutGroupsTotal) { - this.rolloutGroupsTotal = rolloutGroupsTotal; - } - - public int getRolloutGroupsCreated() { - return rolloutGroupsCreated; - } - - public void setRolloutGroupsCreated(final int rolloutGroupsCreated) { - this.rolloutGroupsCreated = rolloutGroupsCreated; - } - - public TotalTargetCountStatus getTotalTargetCountStatus() { - if (totalTargetCountStatus == null) { - totalTargetCountStatus = new TotalTargetCountStatus(totalTargets); - } - return totalTargetCountStatus; - } - - public void setTotalTargetCountStatus(final TotalTargetCountStatus totalTargetCountStatus) { - this.totalTargetCountStatus = totalTargetCountStatus; - } - - @Override - public String toString() { - return "Rollout [rolloutGroups=" + rolloutGroups + ", targetFilterQuery=" + targetFilterQuery - + ", distributionSet=" + distributionSet + ", status=" + status + ", lastCheck=" + lastCheck - + ", getName()=" + getName() + ", getId()=" + getId() + "]"; - } - - /** - * - * State machine for rollout. - * - */ - public enum RolloutStatus { - - /** - * Rollouts is beeing created. - */ - CREATING, - - /** - * Rollout is ready to start. - */ - READY, - - /** - * Rollout is paused. - */ - PAUSED, - - /** - * Rollout is starting. - */ - STARTING, - - /** - * Rollout is stopped. - */ - STOPPED, - - /** - * Rollout is running. - */ - RUNNING, - - /** - * Rollout is finished. - */ - FINISHED, - - /** - * Rollout could not created due errors, might be database problem due - * asynchronous creating. - */ - ERROR_CREATING, - - /** - * Rollout could not started due errors, might be database problem due - * asynchronous starting. - */ - ERROR_STARTING; - } -} +} \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/RolloutGroup.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/RolloutGroup.java index 5aa30126c..647278b78 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/RolloutGroup.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/RolloutGroup.java @@ -8,472 +8,71 @@ */ package org.eclipse.hawkbit.repository.model; -import java.util.ArrayList; -import java.util.List; +import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup.RolloutGroupErrorAction; +import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup.RolloutGroupErrorCondition; +import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup.RolloutGroupStatus; +import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup.RolloutGroupSuccessAction; +import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup.RolloutGroupSuccessCondition; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.ConstraintMode; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.ForeignKey; -import javax.persistence.Index; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.OneToMany; -import javax.persistence.Table; -import javax.persistence.Transient; -import javax.persistence.UniqueConstraint; +public interface RolloutGroup extends NamedEntity { -/** - * JPA entity definition of persisting a group of an rollout. - * - * @author Michael Hirsch - * - */ -@Entity -@Table(name = "sp_rolloutgroup", indexes = { - @Index(name = "sp_idx_rolloutgroup_01", columnList = "tenant,name") }, uniqueConstraints = @UniqueConstraint(columnNames = { - "name", "rollout", "tenant" }, name = "uk_rolloutgroup")) -public class RolloutGroup extends NamedEntity { + Rollout getRollout(); - private static final long serialVersionUID = 1L; + void setRollout(Rollout rollout); - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "rollout", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_rolloutgroup_rollout")) - private Rollout rollout; + RolloutGroupStatus getStatus(); - @Column(name = "status") - private RolloutGroupStatus status = RolloutGroupStatus.READY; + void setStatus(RolloutGroupStatus status); - @OneToMany(fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST }) - @JoinColumn(name = "rolloutGroup_Id", insertable = false, updatable = false) - private final List rolloutTargetGroup = new ArrayList<>(); + RolloutGroup getParent(); - @ManyToOne(fetch = FetchType.LAZY) - private RolloutGroup parent; + void setParent(RolloutGroup parent); - @Column(name = "success_condition", nullable = false) - private RolloutGroupSuccessCondition successCondition = RolloutGroupSuccessCondition.THRESHOLD; + RolloutGroupSuccessCondition getSuccessCondition(); - @Column(name = "success_condition_exp", length = 512, nullable = false) - private String successConditionExp = null; + void setSuccessCondition(RolloutGroupSuccessCondition finishCondition); - @Column(name = "success_action", nullable = false) - private RolloutGroupSuccessAction successAction = RolloutGroupSuccessAction.NEXTGROUP; + String getSuccessConditionExp(); - @Column(name = "success_action_exp", length = 512, nullable = false) - private String successActionExp = null; + void setSuccessConditionExp(String finishExp); - @Column(name = "error_condition") - private RolloutGroupErrorCondition errorCondition = null; + RolloutGroupErrorCondition getErrorCondition(); - @Column(name = "error_condition_exp", length = 512) - private String errorConditionExp = null; + void setErrorCondition(RolloutGroupErrorCondition errorCondition); - @Column(name = "error_action") - private RolloutGroupErrorAction errorAction = null; + String getErrorConditionExp(); - @Column(name = "error_action_exp", length = 512) - private String errorActionExp = null; + void setErrorConditionExp(String errorExp); - @Column(name = "total_targets") - private long totalTargets; + RolloutGroupErrorAction getErrorAction(); - @Transient - private transient TotalTargetCountStatus totalTargetCountStatus; + void setErrorAction(RolloutGroupErrorAction errorAction); - public Rollout getRollout() { - return rollout; - } + String getErrorActionExp(); - public void setRollout(final Rollout rollout) { - this.rollout = rollout; - } + void setErrorActionExp(String errorActionExp); - public RolloutGroupStatus getStatus() { - return status; - } + RolloutGroupSuccessAction getSuccessAction(); - public void setStatus(final RolloutGroupStatus status) { - this.status = status; - } + String getSuccessActionExp(); - public List getRolloutTargetGroup() { - return rolloutTargetGroup; - } + long getTotalTargets(); - public RolloutGroup getParent() { - return parent; - } + void setTotalTargets(long totalTargets); - public void setParent(final RolloutGroup parent) { - this.parent = parent; - } + void setSuccessAction(RolloutGroupSuccessAction successAction); - public RolloutGroupSuccessCondition getSuccessCondition() { - return successCondition; - } - - public void setSuccessCondition(final RolloutGroupSuccessCondition finishCondition) { - successCondition = finishCondition; - } - - public String getSuccessConditionExp() { - return successConditionExp; - } - - public void setSuccessConditionExp(final String finishExp) { - successConditionExp = finishExp; - } - - public RolloutGroupErrorCondition getErrorCondition() { - return errorCondition; - } - - public void setErrorCondition(final RolloutGroupErrorCondition errorCondition) { - this.errorCondition = errorCondition; - } - - public String getErrorConditionExp() { - return errorConditionExp; - } - - public void setErrorConditionExp(final String errorExp) { - errorConditionExp = errorExp; - } - - public RolloutGroupErrorAction getErrorAction() { - return errorAction; - } - - public void setErrorAction(final RolloutGroupErrorAction errorAction) { - this.errorAction = errorAction; - } - - public String getErrorActionExp() { - return errorActionExp; - } - - public void setErrorActionExp(final String errorActionExp) { - this.errorActionExp = errorActionExp; - } - - public RolloutGroupSuccessAction getSuccessAction() { - return successAction; - } - - public String getSuccessActionExp() { - return successActionExp; - } - - public long getTotalTargets() { - return totalTargets; - } - - public void setTotalTargets(final long totalTargets) { - this.totalTargets = totalTargets; - } - - public void setSuccessAction(final RolloutGroupSuccessAction successAction) { - this.successAction = successAction; - } - - public void setSuccessActionExp(final String successActionExp) { - this.successActionExp = successActionExp; - } + void setSuccessActionExp(String successActionExp); /** * @return the totalTargetCountStatus */ - public TotalTargetCountStatus getTotalTargetCountStatus() { - if (totalTargetCountStatus == null) { - totalTargetCountStatus = new TotalTargetCountStatus(totalTargets); - } - return totalTargetCountStatus; - } + TotalTargetCountStatus getTotalTargetCountStatus(); /** * @param totalTargetCountStatus * the totalTargetCountStatus to set */ - public void setTotalTargetCountStatus(final TotalTargetCountStatus totalTargetCountStatus) { - this.totalTargetCountStatus = totalTargetCountStatus; - } + void setTotalTargetCountStatus(TotalTargetCountStatus totalTargetCountStatus); - @Override - public String toString() { - return "RolloutGroup [rollout=" + rollout + ", status=" + status + ", rolloutTargetGroup=" + rolloutTargetGroup - + ", parent=" + parent + ", finishCondition=" + successCondition + ", finishExp=" + successConditionExp - + ", errorCondition=" + errorCondition + ", errorExp=" + errorConditionExp + ", getName()=" + getName() - + ", getId()=" + getId() + "]"; - } - - /** - * Rollout goup state machine. - * - */ - public enum RolloutGroupStatus { - - /** - * Ready to start the group. - */ - READY, - - /** - * Group is scheduled and started sometime, e.g. trigger of group - * before. - */ - SCHEDULED, - - /** - * Group is finished. - */ - FINISHED, - - /** - * Group is finished and has errors. - */ - ERROR, - - /** - * Group is running. - */ - RUNNING; - } - - /** - * The condition to evaluate if an group is success state. - */ - public enum RolloutGroupSuccessCondition { - THRESHOLD("thresholdRolloutGroupSuccessCondition"); - - private final String beanName; - - private RolloutGroupSuccessCondition(final String beanName) { - this.beanName = beanName; - } - - /** - * @return the beanName - */ - public String getBeanName() { - return beanName; - } - } - - /** - * The condition to evaluate if an group is in error state. - */ - public enum RolloutGroupErrorCondition { - THRESHOLD("thresholdRolloutGroupErrorCondition"); - - private final String beanName; - - private RolloutGroupErrorCondition(final String beanName) { - this.beanName = beanName; - } - - /** - * @return the beanName - */ - public String getBeanName() { - return beanName; - } - } - - /** - * The actions executed when the {@link RolloutGroup#errorCondition} is hit. - */ - public enum RolloutGroupErrorAction { - PAUSE("pauseRolloutGroupAction"); - - private final String beanName; - - private RolloutGroupErrorAction(final String beanName) { - this.beanName = beanName; - } - - /** - * @return the beanName - */ - public String getBeanName() { - return beanName; - } - } - - /** - * The actions executed when the {@link RolloutGroup#successCondition} is - * hit. - */ - public enum RolloutGroupSuccessAction { - NEXTGROUP("startNextRolloutGroupAction"); - - private final String beanName; - - private RolloutGroupSuccessAction(final String beanName) { - this.beanName = beanName; - } - - /** - * @return the beanName - */ - public String getBeanName() { - return beanName; - } - } - - /** - * Object which holds all {@link RolloutGroup} conditions together which can - * easily built. - */ - public static class RolloutGroupConditions { - private RolloutGroupSuccessCondition successCondition = null; - private String successConditionExp = null; - private RolloutGroupSuccessAction successAction = null; - private String successActionExp = null; - private RolloutGroupErrorCondition errorCondition = null; - private String errorConditionExp = null; - private RolloutGroupErrorAction errorAction = null; - private String errorActionExp = null; - - public RolloutGroupSuccessCondition getSuccessCondition() { - return successCondition; - } - - public void setSuccessCondition(final RolloutGroupSuccessCondition finishCondition) { - successCondition = finishCondition; - } - - public String getSuccessConditionExp() { - return successConditionExp; - } - - public void setSuccessConditionExp(final String finishConditionExp) { - successConditionExp = finishConditionExp; - } - - public RolloutGroupSuccessAction getSuccessAction() { - return successAction; - } - - public void setSuccessAction(final RolloutGroupSuccessAction successAction) { - this.successAction = successAction; - } - - public String getSuccessActionExp() { - return successActionExp; - } - - public void setSuccessActionExp(final String successActionExp) { - this.successActionExp = successActionExp; - } - - public RolloutGroupErrorCondition getErrorCondition() { - return errorCondition; - } - - public void setErrorCondition(final RolloutGroupErrorCondition errorCondition) { - this.errorCondition = errorCondition; - } - - public String getErrorConditionExp() { - return errorConditionExp; - } - - public void setErrorConditionExp(final String errorConditionExp) { - this.errorConditionExp = errorConditionExp; - } - - public RolloutGroupErrorAction getErrorAction() { - return errorAction; - } - - public void setErrorAction(final RolloutGroupErrorAction errorAction) { - this.errorAction = errorAction; - } - - public String getErrorActionExp() { - return errorActionExp; - } - - public void setErrorActionExp(final String errorActionExp) { - this.errorActionExp = errorActionExp; - } - } - - /** - * Builder to build easily the {@link RolloutGroupConditions}. - * - */ - public static class RolloutGroupConditionBuilder { - private final RolloutGroupConditions conditions = new RolloutGroupConditions(); - - public RolloutGroupConditions build() { - return conditions; - } - - /** - * Sets the finish condition and expression on the builder. - * - * @param condition - * the finish condition - * @param expression - * the finish expression - * @return the builder itself - */ - public RolloutGroupConditionBuilder successCondition(final RolloutGroupSuccessCondition condition, - final String expression) { - conditions.setSuccessCondition(condition); - conditions.setSuccessConditionExp(expression); - return this; - } - - /** - * Sets the success action and expression on the builder. - * - * @param action - * the success action - * @param expression - * the error expression - * @return the builder itself - */ - public RolloutGroupConditionBuilder successAction(final RolloutGroupSuccessAction action, - final String expression) { - conditions.setSuccessAction(action); - conditions.setSuccessActionExp(expression); - return this; - } - - /** - * Sets the error condition and expression on the builder. - * - * @param condition - * the error condition - * @param expression - * the error expression - * @return the builder itself - */ - public RolloutGroupConditionBuilder errorCondition(final RolloutGroupErrorCondition condition, - final String expression) { - conditions.setErrorCondition(condition); - conditions.setErrorConditionExp(expression); - return this; - } - - /** - * Sets the error action and expression on the builder. - * - * @param action - * the error action - * @param expression - * the error expression - * @return the builder itself - */ - public RolloutGroupConditionBuilder errorAction(final RolloutGroupErrorAction action, final String expression) { - conditions.setErrorAction(action); - conditions.setErrorActionExp(expression); - return this; - } - } -} +} \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModule.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModule.java index 327bff3db..67e1027a1 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModule.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModule.java @@ -8,236 +8,79 @@ */ package org.eclipse.hawkbit.repository.model; -import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Optional; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.ConstraintMode; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.ForeignKey; -import javax.persistence.Index; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToMany; -import javax.persistence.ManyToOne; -import javax.persistence.NamedAttributeNode; -import javax.persistence.NamedEntityGraph; -import javax.persistence.OneToMany; -import javax.persistence.Table; -import javax.persistence.UniqueConstraint; - -import org.eclipse.persistence.annotations.CascadeOnDelete; - -/** - * Base Software Module that is supported by OS level provisioning mechanism on - * the edge controller, e.g. OS, JVM, AgentHub. - * - */ -@Entity -@Table(name = "sp_base_software_module", uniqueConstraints = @UniqueConstraint(columnNames = { "module_type", "name", - "version", "tenant" }, name = "uk_base_sw_mod"), indexes = { - @Index(name = "sp_idx_base_sw_module_01", columnList = "tenant,deleted,name,version"), - @Index(name = "sp_idx_base_sw_module_02", columnList = "tenant,deleted,module_type"), - @Index(name = "sp_idx_base_sw_module_prim", columnList = "tenant,id") }) -@NamedEntityGraph(name = "SoftwareModule.artifacts", attributeNodes = { @NamedAttributeNode("artifacts") }) -public class SoftwareModule extends NamedVersionedEntity { - private static final long serialVersionUID = 1L; - - @ManyToOne - @JoinColumn(name = "module_type", nullable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_module_type")) - private SoftwareModuleType type; - - @ManyToMany(mappedBy = "modules", targetEntity = DistributionSet.class, fetch = FetchType.LAZY) - private final List assignedTo = new ArrayList<>(); - - @Column(name = "deleted") - private boolean deleted = false; - - @Column(name = "vendor", nullable = true, length = 256) - private String vendor; - - @OneToMany(mappedBy = "softwareModule", cascade = { CascadeType.ALL }, targetEntity = LocalArtifact.class) - private List artifacts; - - @OneToMany(mappedBy = "softwareModule", cascade = { CascadeType.ALL }, targetEntity = ExternalArtifact.class) - private List externalArtifacts; - - @CascadeOnDelete - @OneToMany(fetch = FetchType.LAZY, cascade = { CascadeType.REMOVE }) - @JoinColumn(name = "sw_id", insertable = false, updatable = false) - private final List metadata = new ArrayList<>(); - - /** - * Default constructor. - */ - public SoftwareModule() { - super(); - } - - /** - * parameterized constructor. - * - * @param type - * of the {@link SoftwareModule} - * @param name - * abstract name of the {@link SoftwareModule} - * @param version - * of the {@link SoftwareModule} - * @param description - * of the {@link SoftwareModule} - * @param vendor - * of the {@link SoftwareModule} - */ - public SoftwareModule(final SoftwareModuleType type, final String name, final String version, - final String description, final String vendor) { - super(name, version, description); - this.vendor = vendor; - this.type = type; - } +public interface SoftwareModule extends NamedVersionedEntity { /** * @param artifact * is added to the assigned {@link Artifact}s. */ - public void addArtifact(final LocalArtifact artifact) { - if (null == artifacts) { - artifacts = new ArrayList<>(4); - } - - if (!artifacts.contains(artifact)) { - artifacts.add(artifact); - } - } + void addArtifact(LocalArtifact artifact); /** * @param artifact * is added to the assigned {@link Artifact}s. */ - public void addArtifact(final ExternalArtifact artifact) { - if (null == externalArtifacts) { - externalArtifacts = new ArrayList<>(4); - } - - if (!externalArtifacts.contains(artifact)) { - externalArtifacts.add(artifact); - } - - } + void addArtifact(ExternalArtifact artifact); /** * @param artifactId * to look for * @return found {@link Artifact} */ - public Optional getLocalArtifact(final Long artifactId) { - if (null == artifacts) { - return Optional.empty(); - } - - return artifacts.stream().filter(artifact -> artifact.getId().equals(artifactId)).findFirst(); - } + Optional getLocalArtifact(Long artifactId); /** * @param fileName * to look for * @return found {@link Artifact} */ - public Optional getLocalArtifactByFilename(final String fileName) { - if (null == artifacts) { - return Optional.empty(); - } - - return artifacts.stream().filter(artifact -> artifact.getFilename().equalsIgnoreCase(fileName.trim())) - .findFirst(); - } + Optional getLocalArtifactByFilename(String fileName); /** * @return the artifacts */ - public List getArtifacts() { - final List result = new ArrayList<>(); - result.addAll(artifacts); - result.addAll(externalArtifacts); - - return result; - } + List getArtifacts(); /** * @return local artifacts only */ - public List getLocalArtifacts() { - if (artifacts == null) { - return Collections.emptyList(); - } + List getLocalArtifacts(); - return artifacts; - } - - public String getVendor() { - return vendor; - } + String getVendor(); /** * @param artifact * is removed from the assigned {@link LocalArtifact}s. */ - public void removeArtifact(final LocalArtifact artifact) { - if (null != artifacts) { - artifacts.remove(artifact); - } - } + void removeArtifact(LocalArtifact artifact); /** * @param artifact * is removed from the assigned {@link ExternalArtifact}s. */ - public void removeArtifact(final ExternalArtifact artifact) { - if (null != externalArtifacts) { - externalArtifacts.remove(artifact); - } - } + void removeArtifact(ExternalArtifact artifact); - public void setVendor(final String vendor) { - this.vendor = vendor; - } + void setVendor(String vendor); - public SoftwareModuleType getType() { - return type; - } + SoftwareModuleType getType(); - public boolean isDeleted() { - return deleted; - } + boolean isDeleted(); - public void setDeleted(final boolean deleted) { - this.deleted = deleted; - } + void setDeleted(boolean deleted); - public void setType(final SoftwareModuleType type) { - this.type = type; - } + void setType(SoftwareModuleType type); /** * @return immutable list of meta data elements. */ - public List getMetadata() { - return Collections.unmodifiableList(metadata); - } - - @Override - public String toString() { - return "SoftwareModule [deleted=" + deleted + ", name=" + getName() + ", version=" + getVersion() - + ", revision=" + getOptLockRevision() + ", Id=" + getId() + ", type=" + getType().getName() + "]"; - } + List getMetadata(); /** * @return the assignedTo */ - public List getAssignedTo() { - return assignedTo; - } + List getAssignedTo(); -} +} \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleMetadata.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleMetadata.java index 5ddd273d3..8cece2a39 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleMetadata.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleMetadata.java @@ -8,73 +8,10 @@ */ package org.eclipse.hawkbit.repository.model; -import javax.persistence.ConstraintMode; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.ForeignKey; -import javax.persistence.Id; -import javax.persistence.IdClass; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.Table; +public interface SoftwareModuleMetadata extends MetaData { -/** - * Metadata for {@link SoftwareModule}. - * - */ -@IdClass(SwMetadataCompositeKey.class) -@Entity -@Table(name = "sp_sw_metadata") -public class SoftwareModuleMetadata extends MetaData { - private static final long serialVersionUID = 1L; + SoftwareModule getSoftwareModule(); - @Id - @ManyToOne(targetEntity = SoftwareModule.class, fetch = FetchType.LAZY) - @JoinColumn(name = "sw_id", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_metadata_sw")) - private SoftwareModule softwareModule; + void setSoftwareModule(SoftwareModule softwareModule); - public SoftwareModuleMetadata() { - // default public constructor for JPA - } - - public SoftwareModuleMetadata(final String key, final SoftwareModule softwareModule, final String value) { - super(key, value); - this.softwareModule = softwareModule; - } - - public SwMetadataCompositeKey getId() { - return new SwMetadataCompositeKey(softwareModule, getKey()); - } - - public SoftwareModule getSoftwareModule() { - return softwareModule; - } - - public void setSoftwareModule(final SoftwareModule softwareModule) { - this.softwareModule = softwareModule; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = prime * result + ((softwareModule == null) ? 0 : softwareModule.hashCode()); - return result; - } - - @Override - public boolean equals(final Object obj) { - if (!super.equals(obj)) { - return false; - } - final SoftwareModuleMetadata other = (SoftwareModuleMetadata) obj; - if (softwareModule == null) { - if (other.softwareModule != null) { - return false; - } - } else if (!softwareModule.equals(other.softwareModule)) { - return false; - } - return true; - } -} +} \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleType.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleType.java index f31b74ff6..534d45fa3 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleType.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleType.java @@ -8,110 +8,18 @@ */ package org.eclipse.hawkbit.repository.model; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Index; -import javax.persistence.Table; -import javax.persistence.UniqueConstraint; +public interface SoftwareModuleType extends NamedEntity { -/** - * Type of a software modules. - * - */ -@Entity -@Table(name = "sp_software_module_type", indexes = { - @Index(name = "sp_idx_software_module_type_01", columnList = "tenant,deleted"), - @Index(name = "sp_idx_software_module_type_prim", columnList = "tenant,id") }, uniqueConstraints = { - @UniqueConstraint(columnNames = { "type_key", "tenant" }, name = "uk_smt_type_key"), - @UniqueConstraint(columnNames = { "name", "tenant" }, name = "uk_smt_name") }) -public class SoftwareModuleType extends NamedEntity { - private static final long serialVersionUID = 1L; + String getKey(); - @Column(name = "type_key", nullable = false, length = 64) - private String key; + int getMaxAssignments(); - @Column(name = "max_ds_assignments", nullable = false) - private int maxAssignments; + boolean isDeleted(); - @Column(name = "colour", nullable = true, length = 16) - private String colour; + void setDeleted(boolean deleted); - @Column(name = "deleted") - private boolean deleted = false; + String getColour(); - /** - * Constructor. - * - * @param key - * of the type - * @param name - * of the type - * @param description - * of the type - * @param maxAssignments - * assignments to a DS - */ - public SoftwareModuleType(final String key, final String name, final String description, final int maxAssignments) { - this(key, name, description, maxAssignments, null); - } + void setColour(String colour); - /** - * Constructor. - * - * @param key - * of the type - * @param name - * of the type - * @param description - * of the type - * @param maxAssignments - * assignments to a DS - * @param colour - * of the type. It will be null by default - */ - public SoftwareModuleType(final String key, final String name, final String description, final int maxAssignments, - final String colour) { - super(); - this.key = key; - this.maxAssignments = maxAssignments; - setDescription(description); - setName(name); - this.colour = colour; - } - - /** - * Default Constructor. - */ - public SoftwareModuleType() { - super(); - } - - public String getKey() { - return key; - } - - public int getMaxAssignments() { - return maxAssignments; - } - - public boolean isDeleted() { - return deleted; - } - - public void setDeleted(final boolean deleted) { - this.deleted = deleted; - } - - public String getColour() { - return colour; - } - - public void setColour(final String colour) { - this.colour = colour; - } - - @Override - public String toString() { - return "SoftwareModuleType [key=" + key + ", getName()=" + getName() + ", getId()=" + getId() + "]"; - } -} +} \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Tag.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Tag.java index 23489ea12..236ff2d3d 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Tag.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Tag.java @@ -8,52 +8,10 @@ */ package org.eclipse.hawkbit.repository.model; -import javax.persistence.Column; -import javax.persistence.MappedSuperclass; +public interface Tag extends NamedEntity { -import org.springframework.hateoas.Identifiable; + String getColour(); -/** - * A Tag can be used as describing and organizational meta information for any - * kind of entity. - * - */ -@MappedSuperclass -public abstract class Tag extends NamedEntity implements Identifiable { - private static final long serialVersionUID = 1L; + void setColour(String colour); - @Column(name = "colour", nullable = true, length = 16) - private String colour; - - protected Tag() { - super(); - } - - /** - * Public constructor. - * - * @param name - * of the {@link Tag} - * @param description - * of the {@link Tag} - * @param colour - * of tag in UI - */ - public Tag(final String name, final String description, final String colour) { - super(name, description); - this.colour = colour; - } - - public String getColour() { - return colour; - } - - public void setColour(final String colour) { - this.colour = colour; - } - - @Override - public String toString() { - return "Tag [getOptLockRevision()=" + getOptLockRevision() + ", getId()=" + getId() + "]"; - } -} +} \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Target.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Target.java index 5f37fb653..ba6f8c42c 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Target.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Target.java @@ -8,211 +8,47 @@ */ package org.eclipse.hawkbit.repository.model; -import java.util.ArrayList; -import java.util.HashSet; import java.util.List; import java.util.Set; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.ConstraintMode; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.ForeignKey; -import javax.persistence.Index; -import javax.persistence.JoinColumn; -import javax.persistence.JoinTable; -import javax.persistence.ManyToMany; -import javax.persistence.ManyToOne; -import javax.persistence.NamedAttributeNode; -import javax.persistence.NamedEntityGraph; -import javax.persistence.OneToMany; -import javax.persistence.OneToOne; -import javax.persistence.PrimaryKeyJoinColumn; -import javax.persistence.Table; -import javax.persistence.Transient; -import javax.persistence.UniqueConstraint; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; +public interface Target extends NamedEntity { -import org.eclipse.hawkbit.im.authentication.SpPermission; -import org.eclipse.hawkbit.repository.model.helper.SecurityChecker; -import org.eclipse.hawkbit.repository.model.helper.SecurityTokenGeneratorHolder; -import org.eclipse.persistence.annotations.CascadeOnDelete; -import org.springframework.data.domain.Persistable; + DistributionSet getAssignedDistributionSet(); -/** - *

- * The {@link Target} is the target of all provisioning operations. It contains - * the currently installed {@link DistributionSet} (i.e. current state). In - * addition it holds the target {@link DistributionSet} that has to be - * provisioned next (i.e. target state). - *

- * - *

- * {@link #getStatus()}s() shows if the {@link Target} is - * {@link TargetStatus#IN_SYNC} or a provisioning is - * {@link TargetStatus#PENDING} or the target is only - * {@link TargetStatus#REGISTERED}, i.e. a target {@link DistributionSet} . - *

- * - */ -@Entity -@Table(name = "sp_target", indexes = { - @Index(name = "sp_idx_target_01", columnList = "tenant,name,assigned_distribution_set"), - @Index(name = "sp_idx_target_02", columnList = "tenant,name"), - @Index(name = "sp_idx_target_03", columnList = "tenant,controller_id,assigned_distribution_set"), - @Index(name = "sp_idx_target_04", columnList = "tenant,created_at"), - @Index(name = "sp_idx_target_prim", columnList = "tenant,id") }, uniqueConstraints = @UniqueConstraint(columnNames = { - "controller_id", "tenant" }, name = "uk_tenant_controller_id")) -@NamedEntityGraph(name = "Target.detail", attributeNodes = { @NamedAttributeNode("tags"), - @NamedAttributeNode(value = "assignedDistributionSet"), @NamedAttributeNode(value = "targetInfo") }) -public class Target extends NamedEntity implements Persistable { - private static final long serialVersionUID = 1L; + String getControllerId(); - @Column(name = "controller_id", length = 64) - @Size(min = 1) - @NotNull - private String controllerId; + Set getTags(); - @Transient - private boolean entityNew = false; + void setAssignedDistributionSet(DistributionSet assignedDistributionSet); - @ManyToMany(targetEntity = TargetTag.class) - @JoinTable(name = "sp_target_target_tag", joinColumns = { - @JoinColumn(name = "target", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_targ_targtag_target")) }, inverseJoinColumns = { - @JoinColumn(name = "tag", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_targ_targtag_tag")) }) - private Set tags = new HashSet<>(); + void setControllerId(String controllerId); - @CascadeOnDelete - @OneToMany(fetch = FetchType.LAZY, orphanRemoval = true, cascade = { CascadeType.REMOVE }) - @JoinColumn(name = "target", insertable = false, updatable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_targ_act_hist_targ")) - private final List actions = new ArrayList<>(); + void setTags(Set tags); - @ManyToOne(optional = true, fetch = FetchType.LAZY, targetEntity = DistributionSet.class) - @JoinColumn(name = "assigned_distribution_set", nullable = true, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_target_assign_ds")) - private DistributionSet assignedDistributionSet; + List getActions(); - @CascadeOnDelete - @OneToOne(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, targetEntity = TargetInfo.class) - @PrimaryKeyJoinColumn - private TargetInfo targetInfo = null; - - /** - * the security token of the target which allows if enabled to authenticate - * with this security token. - */ - @Column(name = "sec_token", insertable = true, updatable = true, nullable = false, length = 128) - private String securityToken = null; - - @CascadeOnDelete - @OneToMany(fetch = FetchType.LAZY, cascade = { CascadeType.REMOVE, CascadeType.PERSIST }) - @JoinColumn(name = "target_Id", insertable = false, updatable = false) - private final List rolloutTargetGroup = new ArrayList<>(); - - /** - * Constructor. - * - * @param controllerId - * controller ID of the {@link Target} - */ - public Target(final String controllerId) { - this.controllerId = controllerId; - setName(controllerId); - securityToken = SecurityTokenGeneratorHolder.getInstance().generateToken(); - targetInfo = new TargetInfo(this); - } - - /** - * empty constructor for JPA. - */ - Target() { - controllerId = null; - securityToken = null; - } - - public DistributionSet getAssignedDistributionSet() { - return assignedDistributionSet; - } - - public String getControllerId() { - return controllerId; - } - - public Set getTags() { - return tags; - } - - public void setAssignedDistributionSet(final DistributionSet assignedDistributionSet) { - this.assignedDistributionSet = assignedDistributionSet; - } - - public void setControllerId(final String controllerId) { - this.controllerId = controllerId; - } - - public void setTags(final Set tags) { - this.tags = tags; - } - - public List getActions() { - return actions; - } - - public TargetIdName getTargetIdName() { - return new TargetIdName(getId(), getControllerId(), getName()); - } - - @Override - @Transient - public boolean isNew() { - return entityNew; - } - - /** - * @param isNew - * the isNew to set - */ - public void setNew(final boolean entityNew) { - this.entityNew = entityNew; - } + TargetIdName getTargetIdName(); /** * @return the targetInfo */ - public TargetInfo getTargetInfo() { - return targetInfo; - } + TargetInfo getTargetInfo(); /** * @param targetInfo * the targetInfo to set */ - public void setTargetInfo(final TargetInfo targetInfo) { - this.targetInfo = targetInfo; - } + void setTargetInfo(TargetInfo targetInfo); /** * @return the securityToken */ - public String getSecurityToken() { - if (SecurityChecker.hasPermission(SpPermission.READ_TARGET_SEC_TOKEN)) { - return securityToken; - } - return null; - } + String getSecurityToken(); /** * @param securityToken * the securityToken to set */ - public void setSecurityToken(final String securityToken) { - this.securityToken = securityToken; - } + void setSecurityToken(String securityToken); - @Override - public String toString() { - return "Target [controllerId=" + controllerId + ", getId()=" + getId() + "]"; - } - -} +} \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetFilterQuery.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetFilterQuery.java index 021b9ca7f..03508555a 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetFilterQuery.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetFilterQuery.java @@ -8,51 +8,14 @@ */ package org.eclipse.hawkbit.repository.model; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Index; -import javax.persistence.Table; -import javax.persistence.UniqueConstraint; +public interface TargetFilterQuery extends TenantAwareBaseEntity { -/** - * Stored target filter. - * - */ -@Entity -@Table(name = "sp_target_filter_query", indexes = { - @Index(name = "sp_idx_target_filter_query_01", columnList = "tenant,name") }, uniqueConstraints = @UniqueConstraint(columnNames = { - "name", "tenant" }, name = "uk_tenant_custom_filter_name")) -public class TargetFilterQuery extends TenantAwareBaseEntity { - private static final long serialVersionUID = 7493966984413479089L; + String getName(); - @Column(name = "name", length = 64) - private String name; + void setName(String name); - @Column(name = "query", length = 1024) - private String query; + String getQuery(); - public TargetFilterQuery() { - // Default constructor for JPA. - } + void setQuery(String query); - public TargetFilterQuery(final String name, final String query) { - this.name = name; - this.query = query; - } - - public String getName() { - return name; - } - - public void setName(final String name) { - this.name = name; - } - - public String getQuery() { - return query; - } - - public void setQuery(final String query) { - this.query = query; - } -} +} \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetInfo.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetInfo.java index 00a501540..657b95c41 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetInfo.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetInfo.java @@ -10,231 +10,30 @@ package org.eclipse.hawkbit.repository.model; import java.io.Serializable; import java.net.URI; -import java.time.Duration; -import java.time.Instant; -import java.time.LocalDateTime; -import java.time.ZoneId; -import java.util.Collections; -import java.util.HashMap; import java.util.Map; -import javax.persistence.CascadeType; -import javax.persistence.CollectionTable; -import javax.persistence.Column; -import javax.persistence.ConstraintMode; -import javax.persistence.ElementCollection; -import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; -import javax.persistence.FetchType; -import javax.persistence.ForeignKey; -import javax.persistence.Id; -import javax.persistence.Index; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.MapKeyColumn; -import javax.persistence.MapsId; -import javax.persistence.OneToOne; -import javax.persistence.Table; -import javax.persistence.Transient; +import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo.PollStatus; -import org.eclipse.hawkbit.repository.model.helper.SystemSecurityContextHolder; -import org.eclipse.hawkbit.repository.model.helper.TenantConfigurationManagementHolder; -import org.eclipse.hawkbit.tenancy.configuration.DurationHelper; -import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; -import org.eclipse.persistence.annotations.CascadeOnDelete; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.data.domain.Persistable; +public interface TargetInfo extends Serializable { -/** - * A table which contains all the information inserted, updated by the - * controller itself. So this entity does not provide audit information because - * changes on this entity are mostly only done by controller requests. That's - * the reason that we store these information in a separated table so we don't - * modifying the {@link Target} itself when a controller reports it's - * {@link #lastTargetQuery} for example. - * - */ -@Table(name = "sp_target_info", indexes = { - @Index(name = "sp_idx_target_info_02", columnList = "target_id,update_status") }) -@Entity -public class TargetInfo implements Persistable, Serializable { - private static final long serialVersionUID = 1L; - - private static final Logger LOG = LoggerFactory.getLogger(TargetInfo.class); - - @Id - private Long targetId; - - @Transient - private boolean entityNew = false; - - @CascadeOnDelete - @OneToOne(cascade = { CascadeType.MERGE, CascadeType.REMOVE }, fetch = FetchType.LAZY, targetEntity = Target.class) - @JoinColumn(name = "target_id", nullable = false, updatable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_targ_stat_targ")) - @MapsId - private Target target; - - @Column(name = "address", length = 512) - private String address = null; - - @Column(name = "last_target_query") - private Long lastTargetQuery = null; - - @Column(name = "install_date") - private Long installationDate; - - @Column(name = "update_status", nullable = false, length = 255) - @Enumerated(EnumType.STRING) - private TargetUpdateStatus updateStatus = TargetUpdateStatus.UNKNOWN; - - @ManyToOne(optional = true, fetch = FetchType.LAZY) - @JoinColumn(name = "installed_distribution_set", nullable = true, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_target_inst_ds")) - private DistributionSet installedDistributionSet; - - /** - * Read only on management API. Are commited by controller. - */ - @ElementCollection - @Column(name = "attribute_value", length = 128) - @MapKeyColumn(name = "attribute_key", nullable = false, length = 32) - @CollectionTable(name = "sp_target_attributes", joinColumns = { - @JoinColumn(name = "target_id") }, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_targ_attrib_target")) - - private final Map controllerAttributes = Collections.synchronizedMap(new HashMap()); - - // set default request controller attributes to true, because we want to - // request them the first - // time - @Column(name = "request_controller_attributes", nullable = false) - private boolean requestControllerAttributes = true; - - /** - * Constructor for {@link TargetStatus}. - * - * @param target - * related to this status. - */ - public TargetInfo(final Target target) { - this.target = target; - targetId = target.getId(); - } - - TargetInfo() { - target = null; - targetId = null; - } - - @Override - public Long getId() { - return targetId; - } - - @Override - @Transient - public boolean isNew() { - return entityNew; - } - - /** - * @param isNew - * the isNew to set - */ - public void setNew(final boolean entityNew) { - this.entityNew = entityNew; - } + Long getId(); /** * @return the ipAddress */ - public URI getAddress() { - if (address == null) { - return null; - } - try { - return URI.create(address); - } catch (final IllegalArgumentException e) { - LOG.warn("Invalid address provided. Cloud not be configured to URI", e); - return null; - } - } + URI getAddress(); - /** - * @param address - * the ipAddress to set - * - * @throws IllegalArgumentException - * If the given string violates RFC 2396 - */ - public void setAddress(final String address) { - // check if this is a real URI - if (address != null) { - URI.create(address); - } + Target getTarget(); - this.address = address; - } + Long getLastTargetQuery(); - public Long getTargetId() { - return targetId; - } + Map getControllerAttributes(); - public void setTargetId(final Long targetId) { - this.targetId = targetId; - } + Long getInstallationDate(); - public Target getTarget() { - return target; - } + TargetUpdateStatus getUpdateStatus(); - public void setTarget(final Target target) { - this.target = target; - } - - public Long getLastTargetQuery() { - return lastTargetQuery; - } - - public void setLastTargetQuery(final Long lastTargetQuery) { - this.lastTargetQuery = lastTargetQuery; - } - - public void setRequestControllerAttributes(final boolean requestControllerAttributes) { - this.requestControllerAttributes = requestControllerAttributes; - } - - public Map getControllerAttributes() { - return controllerAttributes; - } - - public boolean isRequestControllerAttributes() { - return requestControllerAttributes; - } - - public Long getInstallationDate() { - return installationDate; - } - - public void setInstallationDate(final Long installationDate) { - this.installationDate = installationDate; - } - - public TargetUpdateStatus getUpdateStatus() { - return updateStatus; - } - - public void setUpdateStatus(final TargetUpdateStatus updateStatus) { - this.updateStatus = updateStatus; - } - - public DistributionSet getInstalledDistributionSet() { - return installedDistributionSet; - } - - public void setInstalledDistributionSet(final DistributionSet installedDistributionSet) { - this.installedDistributionSet = installedDistributionSet; - } + DistributionSet getInstalledDistributionSet(); /** * @return the poll time which holds the last poll time of the target, the @@ -242,119 +41,6 @@ public class TargetInfo implements Persistable, Serializable { * {@link #lastTargetQuery} is not set e.g. the target never polled * before this method returns {@code null} */ - public PollStatus getPollStatus() { - if (lastTargetQuery == null) { - return null; - } - return SystemSecurityContextHolder.getInstance().getSystemSecurityContext().runAsSystem(() -> { - final Duration pollTime = DurationHelper.formattedStringToDuration(TenantConfigurationManagementHolder - .getInstance().getTenantConfigurationManagement() - .getConfigurationValue(TenantConfigurationKey.POLLING_TIME_INTERVAL, String.class).getValue()); - final Duration overdueTime = DurationHelper.formattedStringToDuration( - TenantConfigurationManagementHolder.getInstance().getTenantConfigurationManagement() - .getConfigurationValue(TenantConfigurationKey.POLLING_OVERDUE_TIME_INTERVAL, String.class) - .getValue()); - final LocalDateTime currentDate = LocalDateTime.now(); - final LocalDateTime lastPollDate = LocalDateTime.ofInstant(Instant.ofEpochMilli(lastTargetQuery), - ZoneId.systemDefault()); - final LocalDateTime nextPollDate = lastPollDate.plus(pollTime); - final LocalDateTime overdueDate = nextPollDate.plus(overdueTime); - return new PollStatus(lastPollDate, nextPollDate, overdueDate, currentDate); - }); - } + PollStatus getPollStatus(); - /** - * The poll time object which holds all the necessary information around the - * target poll time, e.g. the last poll time, the next poll time and the - * overdue poll time. - * - */ - public static final class PollStatus { - private final LocalDateTime lastPollDate; - private final LocalDateTime nextPollDate; - private final LocalDateTime overdueDate; - private final LocalDateTime currentDate; - - private PollStatus(final LocalDateTime lastPollDate, final LocalDateTime nextPollDate, - final LocalDateTime overdueDate, final LocalDateTime currentDate) { - this.lastPollDate = lastPollDate; - this.nextPollDate = nextPollDate; - this.overdueDate = overdueDate; - this.currentDate = currentDate; - } - - /** - * calculates if the target poll time is overdue and the target has not - * been polled in the configured poll time interval. - * - * @return {@code true} if the current time is after the poll time - * overdue date otherwise {@code false}. - */ - public boolean isOverdue() { - return currentDate.isAfter(overdueDate); - } - - /** - * @return the lastPollDate - */ - public LocalDateTime getLastPollDate() { - return lastPollDate; - } - - public LocalDateTime getNextPollDate() { - return nextPollDate; - } - - public LocalDateTime getOverdueDate() { - return overdueDate; - } - - public LocalDateTime getCurrentDate() { - return currentDate; - } - - @Override - public String toString() { - return "PollTime [lastPollDate=" + lastPollDate + ", nextPollDate=" + nextPollDate + ", overdueDate=" - + overdueDate + ", currentDate=" + currentDate + "]"; - } - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((target == null) ? 0 : target.hashCode()); - result = prime * result + ((targetId == null) ? 0 : targetId.hashCode()); - return result; - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (!(obj instanceof TargetInfo)) { - return false; - } - final TargetInfo other = (TargetInfo) obj; - if (target == null) { - if (other.target != null) { - return false; - } - } else if (!target.equals(other.target)) { - return false; - } - if (targetId == null) { - if (other.targetId != null) { - return false; - } - } else if (!targetId.equals(other.targetId)) { - return false; - } - return true; - } -} +} \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetTag.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetTag.java index 5a5a310d0..3abe3cdd5 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetTag.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetTag.java @@ -10,78 +10,8 @@ package org.eclipse.hawkbit.repository.model; import java.util.List; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.Index; -import javax.persistence.ManyToMany; -import javax.persistence.Table; -import javax.persistence.UniqueConstraint; +public interface TargetTag extends Tag { -/** - * A {@link TargetTag} is used to describe Target attributes and use them also - * for filtering the target list. - * - */ -@Entity -@Table(name = "sp_target_tag", indexes = { - @Index(name = "sp_idx_target_tag_prim", columnList = "tenant,id") }, uniqueConstraints = @UniqueConstraint(columnNames = { - "name", "tenant" }, name = "uk_targ_tag")) -public class TargetTag extends Tag { - private static final long serialVersionUID = 1L; + List getAssignedToTargets(); - @ManyToMany(mappedBy = "tags", targetEntity = Target.class, fetch = FetchType.LAZY) - private List assignedToTargets; - - /** - * Constructor. - * - * @param name - * of {@link TargetTag} - * @param description - * of {@link TargetTag} - * @param colour - * of {@link TargetTag} - */ - public TargetTag(final String name, final String description, final String colour) { - super(name, description, colour); - } - - /** - * Public constructor. - * - * @param name - * of the {@link TargetTag} - **/ - public TargetTag(final String name) { - super(name, null, null); - } - - TargetTag() { - super(); - } - - public List getAssignedToTargets() { - return assignedToTargets; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = prime * result + this.getClass().getName().hashCode(); - return result; - } - - @Override - public boolean equals(final Object obj) { - if (!super.equals(obj)) { - return false; - } - if (!(obj instanceof TargetTag)) { - return false; - } - - return true; - } - -} +} \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetWithActionStatus.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetWithActionStatus.java index ec09da3d5..987b993e1 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetWithActionStatus.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetWithActionStatus.java @@ -19,7 +19,7 @@ public class TargetWithActionStatus { private Target target; - private Status status = null;; + private Status status = null; public TargetWithActionStatus(final Target target) { this.target = target; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TenantAwareBaseEntity.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TenantAwareBaseEntity.java index d03a4938a..4b7bf861e 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TenantAwareBaseEntity.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TenantAwareBaseEntity.java @@ -8,106 +8,8 @@ */ package org.eclipse.hawkbit.repository.model; -import javax.persistence.Column; -import javax.persistence.MappedSuperclass; -import javax.persistence.PrePersist; +public interface TenantAwareBaseEntity extends BaseEntity { -import org.eclipse.hawkbit.repository.exception.TenantNotExistException; -import org.eclipse.hawkbit.repository.model.helper.SystemManagementHolder; -import org.eclipse.hawkbit.repository.model.helper.TenantAwareHolder; -import org.eclipse.persistence.annotations.Multitenant; -import org.eclipse.persistence.annotations.MultitenantType; -import org.eclipse.persistence.annotations.TenantDiscriminatorColumn; + String getTenant(); -/** - * Holder of the base attributes common to all tenant aware entities. - * - */ -@MappedSuperclass -@TenantDiscriminatorColumn(name = "tenant", length = 40) -@Multitenant(MultitenantType.SINGLE_TABLE) -public abstract class TenantAwareBaseEntity extends BaseEntity { - private static final long serialVersionUID = 1L; - - @Column(name = "tenant", nullable = false, insertable = false, updatable = false, length = 40) - private String tenant; - - /** - * Default constructor needed for JPA entities. - */ - public TenantAwareBaseEntity() { - // Default constructor needed for JPA entities. - } - - /** - * PrePersist listener method for all {@link TenantAwareBaseEntity} - * entities. - */ - @PrePersist - public void prePersist() { - // before persisting the entity check the current ID of the tenant by - // using the TenantAware - // service - final String currentTenant = SystemManagementHolder.getInstance().currentTenant(); - if (currentTenant == null) { - throw new TenantNotExistException("Tenant " - + TenantAwareHolder.getInstance().getTenantAware().getCurrentTenant() - + " does not exists, cannot create entity " + this.getClass() + " with id " + super.getId()); - } - setTenant(currentTenant.toUpperCase()); - } - - public String getTenant() { - return tenant; - } - - public void setTenant(final String tenant) { - this.tenant = tenant; - } - - @Override - public String toString() { - return "BaseEntity [id=" + super.getId() + "]"; - } - - /** - * Tenant aware entities extend the equals/hashcode strategy with the tenant - * name. That would allow for instance in a multi-schema based data - * separation setup to have the same primary key for different entities of - * different tenants. - * - * @see org.eclipse.hawkbit.repository.model.BaseEntity#hashCode() - */ - @Override - public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = prime * result + (tenant == null ? 0 : tenant.hashCode()); - return result; - } - - /** - * Tenant aware entities extend the equals/hashcode strategy with the tenant - * name. That would allow for instance in a multi-schema based data - * separation setup to have the same primary key for different entities of - * different tenants. - * - * @see org.eclipse.hawkbit.repository.model.BaseEntity#equals(java.lang.Object) - */ - @Override - public boolean equals(final Object obj) { - if (!super.equals(obj)) { - return false; - } - final TenantAwareBaseEntity other = (TenantAwareBaseEntity) obj; - if (tenant == null) { - if (other.tenant != null) { - return false; - } - } else if (!tenant.equals(other.tenant)) { - return false; - } - return true; - } - -} +} \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TenantConfiguration.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TenantConfiguration.java index 5a938563b..78201410b 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TenantConfiguration.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TenantConfiguration.java @@ -8,64 +8,14 @@ */ package org.eclipse.hawkbit.repository.model; -import java.io.Serializable; +public interface TenantConfiguration extends TenantAwareBaseEntity { -import javax.persistence.Basic; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Table; -import javax.persistence.UniqueConstraint; + String getKey(); -/** - * A JPA entity which stores the tenant specific configuration. - * - */ -@Entity -@Table(name = "sp_tenant_configuration", uniqueConstraints = @UniqueConstraint(columnNames = { "conf_key", - "tenant" }, name = "uk_tenant_key")) -public class TenantConfiguration extends TenantAwareBaseEntity implements Serializable { - private static final long serialVersionUID = 1L; + void setKey(String key); - @Column(name = "conf_key", length = 128) - private String key; + String getValue(); - @Column(name = "conf_value", length = 512) - @Basic - private String value; + void setValue(String value); - /** - * JPA default constructor. - */ - public TenantConfiguration() { - // JPA default constructor. - } - - /** - * @param key - * the key of this configuration - * @param value - * the value of this configuration - */ - public TenantConfiguration(final String key, final String value) { - this.key = key; - this.value = value; - - } - - public String getKey() { - return key; - } - - public void setKey(final String key) { - this.key = key; - } - - public String getValue() { - return value; - } - - public void setValue(final String value) { - this.value = value; - } - -} +} \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TenantMetaData.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TenantMetaData.java index a9572c21c..38f9ddbb3 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TenantMetaData.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TenantMetaData.java @@ -8,93 +8,12 @@ */ package org.eclipse.hawkbit.repository.model; -import javax.persistence.Column; -import javax.persistence.ConstraintMode; -import javax.persistence.Entity; -import javax.persistence.EntityManager; -import javax.persistence.FetchType; -import javax.persistence.ForeignKey; -import javax.persistence.Index; -import javax.persistence.JoinColumn; -import javax.persistence.OneToOne; -import javax.persistence.Table; -import javax.persistence.UniqueConstraint; +public interface TenantMetaData extends BaseEntity { -/** - * Tenant entity with meta data that is configured globally for the entire - * tenant. This entity is not tenant aware to allow the system to access it - * through the {@link EntityManager} even before the actual tenant exists. - * - * Entities owned by the tenant are based on {@link TenantAwareBaseEntity}. - * - */ -@Table(name = "sp_tenant", indexes = { - @Index(name = "sp_idx_tenant_prim", columnList = "tenant,id") }, uniqueConstraints = { - @UniqueConstraint(columnNames = { "tenant" }, name = "uk_tenantmd_tenant") }) -@Entity -public class TenantMetaData extends BaseEntity { - private static final long serialVersionUID = 1L; + DistributionSetType getDefaultDsType(); - @Column(name = "tenant", nullable = false, length = 40) - private String tenant; + void setDefaultDsType(DistributionSetType defaultDsType); - @OneToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "default_ds_type", nullable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_tenant_md_default_ds_type")) - private DistributionSetType defaultDsType; + String getTenant(); - /** - * Default constructor needed for JPA entities. - */ - public TenantMetaData() { - // Default constructor needed for JPA entities. - } - - /** - * Standard constructor. - * - * @param defaultDsType - * of this tenant - * @param tenant - */ - public TenantMetaData(final DistributionSetType defaultDsType, final String tenant) { - super(); - this.defaultDsType = defaultDsType; - this.tenant = tenant; - } - - public DistributionSetType getDefaultDsType() { - return defaultDsType; - } - - public void setDefaultDsType(final DistributionSetType defaultDsType) { - this.defaultDsType = defaultDsType; - } - - public String getTenant() { - return tenant; - } - - public void setTenant(final String tenant) { - this.tenant = tenant; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = prime * result + this.getClass().getName().hashCode(); - return result; - } - - @Override - public boolean equals(final Object obj) { - if (!super.equals(obj)) { - return false; - } - if (!(obj instanceof TenantMetaData)) { - return false; - } - - return true; - } -} +} \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/rollout/condition/PauseRolloutGroupAction.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/rollout/condition/PauseRolloutGroupAction.java index 3af269819..d80fc5a7b 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/rollout/condition/PauseRolloutGroupAction.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/rollout/condition/PauseRolloutGroupAction.java @@ -8,13 +8,12 @@ */ package org.eclipse.hawkbit.rollout.condition; -import java.util.concurrent.Callable; - import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.jpa.RolloutGroupRepository; +import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup; +import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup.RolloutGroupStatus; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.RolloutGroup; -import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupStatus; import org.eclipse.hawkbit.security.SystemSecurityContext; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -42,14 +41,11 @@ public class PauseRolloutGroupAction implements RolloutGroupActionEvaluator { @Override public void eval(final Rollout rollout, final RolloutGroup rolloutGroup, final String expression) { - systemSecurityContext.runAsSystem(new Callable() { - @Override - public Void call() throws Exception { - rolloutGroup.setStatus(RolloutGroupStatus.ERROR); - rolloutGroupRepository.save(rolloutGroup); - rolloutManagement.pauseRollout(rollout); - return null; - } + systemSecurityContext.runAsSystem(() -> { + rolloutGroup.setStatus(RolloutGroupStatus.ERROR); + rolloutGroupRepository.save((JpaRolloutGroup) rolloutGroup); + rolloutManagement.pauseRollout(rollout); + return null; }); } } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/rollout/condition/StartNextGroupRolloutGroupSuccessAction.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/rollout/condition/StartNextGroupRolloutGroupSuccessAction.java index 224901053..223f20125 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/rollout/condition/StartNextGroupRolloutGroupSuccessAction.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/rollout/condition/StartNextGroupRolloutGroupSuccessAction.java @@ -12,10 +12,11 @@ import java.util.List; import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.jpa.RolloutGroupRepository; +import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup; +import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup.RolloutGroupStatus; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.RolloutGroup; -import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupStatus; import org.eclipse.hawkbit.security.SystemSecurityContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -68,7 +69,7 @@ public class StartNextGroupRolloutGroupSuccessAction implements RolloutGroupActi final RolloutGroup nextGroup = action.getRolloutGroup(); logger.debug("Rolloutgroup {} is now running", nextGroup); nextGroup.setStatus(RolloutGroupStatus.RUNNING); - rolloutGroupRepository.save(nextGroup); + rolloutGroupRepository.save((JpaRolloutGroup) nextGroup); }); } else { logger.info("No actions to start for next rolloutgroup of parent {}", rolloutGroup); @@ -76,8 +77,8 @@ public class StartNextGroupRolloutGroupSuccessAction implements RolloutGroupActi // e.g. if targets has been deleted after the group has been // scheduled. If the group is empty now, we just finish the group if // there are not actions available for this group. - final List findByRolloutGroupParent = rolloutGroupRepository - .findByParentAndStatus(rolloutGroup, RolloutGroupStatus.SCHEDULED); + final List findByRolloutGroupParent = rolloutGroupRepository + .findByParentAndStatus((JpaRolloutGroup) rolloutGroup, RolloutGroupStatus.SCHEDULED); findByRolloutGroupParent.forEach(nextGroup -> { logger.debug("Rolloutgroup {} is finished, starting next group", nextGroup); nextGroup.setStatus(RolloutGroupStatus.FINISHED); diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/rollout/condition/ThresholdRolloutGroupErrorCondition.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/rollout/condition/ThresholdRolloutGroupErrorCondition.java index e38cb0f16..32e9725f8 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/rollout/condition/ThresholdRolloutGroupErrorCondition.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/rollout/condition/ThresholdRolloutGroupErrorCondition.java @@ -9,6 +9,8 @@ package org.eclipse.hawkbit.rollout.condition; import org.eclipse.hawkbit.repository.jpa.ActionRepository; +import org.eclipse.hawkbit.repository.jpa.model.JpaRollout; +import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.RolloutGroup; @@ -30,7 +32,8 @@ public class ThresholdRolloutGroupErrorCondition implements RolloutGroupConditio @Override public boolean eval(final Rollout rollout, final RolloutGroup rolloutGroup, final String expression) { - final Long totalGroup = actionRepository.countByRolloutAndRolloutGroup(rollout, rolloutGroup); + final Long totalGroup = actionRepository.countByRolloutAndRolloutGroup((JpaRollout) rollout, + (JpaRolloutGroup) rolloutGroup); final Long error = actionRepository.countByRolloutIdAndRolloutGroupIdAndStatus(rollout.getId(), rolloutGroup.getId(), Action.Status.ERROR); try { diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/TestDataUtil.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/TestDataUtil.java index 1787d29e4..09959790f 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/TestDataUtil.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/TestDataUtil.java @@ -20,6 +20,14 @@ import org.eclipse.hawkbit.repository.ArtifactManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.TargetManagement; +import org.eclipse.hawkbit.repository.jpa.model.JpaArtifact; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType; +import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; +import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType; +import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; +import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.DistributionSetType; @@ -42,10 +50,10 @@ import net._01001111.text.LoremIpsum; public class TestDataUtil { private static final LoremIpsum LOREM = new LoremIpsum(); - public static List generateDistributionSets(final String suffix, final int number, + public static List generateDistributionSets(final String suffix, final int number, final SoftwareManagement softwareManagement, final DistributionSetManagement distributionSetManagement) { - final List sets = new ArrayList(); + final List sets = new ArrayList<>(); for (int i = 0; i < number; i++) { sets.add(generateDistributionSet(suffix, "v1." + i, softwareManagement, distributionSetManagement, false)); } @@ -56,32 +64,32 @@ public class TestDataUtil { public static DistributionSet generateDistributionSetWithNoSoftwareModules(final String name, final String version, final DistributionSetManagement distributionSetManagement) { - final DistributionSet dis = new DistributionSet(); + final DistributionSet dis = new JpaDistributionSet(); dis.setName(name); dis.setVersion(version); dis.setDescription("Test describtion for " + name); return distributionSetManagement.createDistributionSet(dis); } - public static List generateDistributionSets(final int number, + public static List generateDistributionSets(final int number, final SoftwareManagement softwareManagement, final DistributionSetManagement distributionSetManagement) { return generateDistributionSets("", number, softwareManagement, distributionSetManagement); } - public static DistributionSet generateDistributionSet(final String suffix, final String version, + public static JpaDistributionSet generateDistributionSet(final String suffix, final String version, final SoftwareManagement softwareManagement, final DistributionSetManagement distributionSetManagement, final boolean isRequiredMigrationStep) { - final SoftwareModule ah = softwareManagement.createSoftwareModule(new SoftwareModule( + final SoftwareModule ah = softwareManagement.createSoftwareModule(new JpaSoftwareModule( findOrCreateSoftwareModuleType(softwareManagement, "application"), suffix + "application", version + "." + new Random().nextInt(100), LOREM.words(20), suffix + " vendor Limited, California")); - final SoftwareModule jvm = softwareManagement - .createSoftwareModule(new SoftwareModule(findOrCreateSoftwareModuleType(softwareManagement, "runtime"), + final SoftwareModule jvm = softwareManagement.createSoftwareModule( + new JpaSoftwareModule(findOrCreateSoftwareModuleType(softwareManagement, "runtime"), suffix + "app runtime", version + "." + new Random().nextInt(100), LOREM.words(20), suffix + " vendor GmbH, Stuttgart, Germany")); final SoftwareModule os = softwareManagement - .createSoftwareModule(new SoftwareModule(findOrCreateSoftwareModuleType(softwareManagement, "os"), + .createSoftwareModule(new JpaSoftwareModule(findOrCreateSoftwareModuleType(softwareManagement, "os"), suffix + " Firmware", version + "." + new Random().nextInt(100), LOREM.words(20), suffix + " vendor Limited Inc, California")); @@ -92,7 +100,7 @@ public class TestDataUtil { opt.add(findOrCreateSoftwareModuleType(softwareManagement, "application")); opt.add(findOrCreateSoftwareModuleType(softwareManagement, "runtime")); - return distributionSetManagement.createDistributionSet( + return (JpaDistributionSet) distributionSetManagement.createDistributionSet( buildDistributionSet(suffix != null && suffix.length() > 0 ? suffix : "DS", version, findOrCreateDistributionSetType(distributionSetManagement, "ecl_os_app_jvm", "OS mandatory App/JVM optional", mand, opt), @@ -126,7 +134,7 @@ public class TestDataUtil { public static List generateTargets(final int start, final int number, final String prefix) { final List targets = new ArrayList<>(); for (int i = start; i < start + number; i++) { - targets.add(new Target(prefix + i)); + targets.add(new JpaTarget(prefix + i)); } return targets; @@ -136,7 +144,7 @@ public class TestDataUtil { final List result = new ArrayList<>(); for (int i = 0; i < number; i++) { - result.add(new TargetTag("tag" + i, "tagdesc" + i, "" + i)); + result.add(new JpaTargetTag("tag" + i, "tagdesc" + i, "" + i)); } return result; @@ -146,30 +154,31 @@ public class TestDataUtil { final List result = new ArrayList<>(); for (int i = 0; i < number; i++) { - result.add(new DistributionSetTag("tag" + i, "tagdesc" + i, "" + i)); + result.add(new JpaDistributionSetTag("tag" + i, "tagdesc" + i, "" + i)); } return result; } - public static DistributionSet generateDistributionSet(final String suffix, + public static JpaDistributionSet generateDistributionSet(final String suffix, final SoftwareManagement softwareManagement, final DistributionSetManagement distributionSetManagement, final boolean isRequiredMigrationStep) { return generateDistributionSet(suffix, "v1.0", softwareManagement, distributionSetManagement, isRequiredMigrationStep); } - public static DistributionSet generateDistributionSet(final String suffix, + public static JpaDistributionSet generateDistributionSet(final String suffix, final SoftwareManagement softwareManagement, final DistributionSetManagement distributionSetManagement) { return generateDistributionSet(suffix, "v1.0", softwareManagement, distributionSetManagement, false); } - public static List generateArtifacts( - final ArtifactManagement artifactManagement, final Long moduleId) { - final List artifacts = new ArrayList<>(); + public static List generateArtifacts(final ArtifactManagement artifactManagement, + final Long moduleId) { + final List artifacts = new ArrayList<>(); for (int i = 0; i < 3; i++) { final InputStream stubInputStream = IOUtils.toInputStream("some test data" + i); - artifacts.add(artifactManagement.createLocalArtifact(stubInputStream, moduleId, "filename" + i, false)); + artifacts.add((JpaArtifact) artifactManagement.createLocalArtifact(stubInputStream, moduleId, + "filename" + i, false)); } @@ -178,7 +187,7 @@ public class TestDataUtil { public static Target createTarget(final TargetManagement targetManagement) { final String targetExist = "targetExist"; - final Target target = new Target(targetExist); + final Target target = new JpaTarget(targetExist); targetManagement.createTarget(target); return target; } @@ -196,7 +205,7 @@ public class TestDataUtil { if (findSoftwareModuleTypeByKey != null) { return findSoftwareModuleTypeByKey; } - return softwareManagement.createSoftwareModuleType(new SoftwareModuleType(softwareModuleType, + return softwareManagement.createSoftwareModuleType(new JpaSoftwareModuleType(softwareModuleType, softwareModuleType, "Standard type " + softwareManagement, 1)); } @@ -210,7 +219,8 @@ public class TestDataUtil { return findDistributionSetTypeByname; } - final DistributionSetType type = new DistributionSetType(dsTypeKey, dsTypeName, "Standard type" + dsTypeName); + final DistributionSetType type = new JpaDistributionSetType(dsTypeKey, dsTypeName, + "Standard type" + dsTypeName); mandatory.forEach(entry -> type.addMandatoryModuleType(entry)); optional.forEach(entry -> type.addOptionalModuleType(entry)); @@ -280,7 +290,7 @@ public class TestDataUtil { * @return the created {@link Target} */ public static Target buildTargetFixture(final String ctrlID, final String description, final TargetTag[] tags) { - final Target target = new Target(ctrlID); + final Target target = new JpaTarget(ctrlID); target.setName("Prov.Target ".concat(ctrlID)); target.setDescription(description); if (tags != null && tags.length > 0) { @@ -322,7 +332,7 @@ public class TestDataUtil { public static DistributionSet buildDistributionSet(final String name, final String version, final DistributionSetType type, final SoftwareModule os, final SoftwareModule jvm, final SoftwareModule agentHub) { - final DistributionSet distributionSet = new DistributionSet(name, version, null, type, + final DistributionSet distributionSet = new JpaDistributionSet(name, version, null, type, Lists.newArrayList(os, jvm, agentHub)); distributionSet.setDescription( String.format("description of DistributionSet; name = '%s', version = '%s'", name, version)); @@ -361,6 +371,6 @@ public class TestDataUtil { * @return the {@link TargetTag} */ public static TargetTag buildTargetTagFixture(final String tagName) { - return new TargetTag(tagName); + return new JpaTargetTag(tagName); } } diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ActionTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ActionTest.java index 937a544a7..4fbd46a5c 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ActionTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ActionTest.java @@ -10,6 +10,7 @@ package org.eclipse.hawkbit.repository; import static org.fest.assertions.api.Assertions.assertThat; +import org.eclipse.hawkbit.repository.jpa.model.JpaAction; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.ActionType; import org.junit.Test; @@ -30,7 +31,7 @@ public class ActionTest { // current time + 1 seconds final long sleepTime = 1000; final long timeForceTimeAt = System.currentTimeMillis() + sleepTime; - final Action timeforcedAction = new Action(); + final Action timeforcedAction = new JpaAction(); timeforcedAction.setActionType(ActionType.TIMEFORCED); timeforcedAction.setForcedTime(timeForceTimeAt); assertThat(timeforcedAction.isForce()).isFalse(); diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ArtifactManagementNoMongoDbTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ArtifactManagementNoMongoDbTest.java index 30f4093c2..ee1cb3acd 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ArtifactManagementNoMongoDbTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ArtifactManagementNoMongoDbTest.java @@ -16,7 +16,7 @@ import java.io.IOException; import org.apache.commons.lang3.RandomStringUtils; import org.eclipse.hawkbit.AbstractIntegrationTest; import org.eclipse.hawkbit.repository.exception.ArtifactUploadFailedException; -import org.eclipse.hawkbit.repository.model.SoftwareModule; +import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; import org.junit.BeforeClass; import org.junit.Test; @@ -42,7 +42,7 @@ public class ArtifactManagementNoMongoDbTest extends AbstractIntegrationTest { @Test @Description("Checks if the expected ArtifactUploadFailedException is thrown in case of MongoDB down") public void createLocalArtifactWithMongoDbDown() throws IOException { - SoftwareModule sm = new SoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1", + JpaSoftwareModule sm = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1", "version 1", null, null); sm = softwareModuleRepository.save(sm); diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ArtifactManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ArtifactManagementTest.java index 7c801a571..7b704af12 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ArtifactManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ArtifactManagementTest.java @@ -27,8 +27,11 @@ import org.eclipse.hawkbit.WithUser; import org.eclipse.hawkbit.im.authentication.SpPermission; import org.eclipse.hawkbit.repository.exception.ArtifactDeleteFailedException; import org.eclipse.hawkbit.repository.exception.InsufficientPermissionException; +import org.eclipse.hawkbit.repository.jpa.model.JpaExternalArtifact; +import org.eclipse.hawkbit.repository.jpa.model.JpaExternalArtifactProvider; +import org.eclipse.hawkbit.repository.jpa.model.JpaLocalArtifact; +import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; import org.eclipse.hawkbit.repository.model.Artifact; -import org.eclipse.hawkbit.repository.model.ExternalArtifact; import org.eclipse.hawkbit.repository.model.ExternalArtifactProvider; import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; @@ -70,15 +73,15 @@ public class ArtifactManagementTest extends AbstractIntegrationTestWithMongoDB { assertThat(softwareModuleRepository.findAll()).hasSize(0); assertThat(artifactRepository.findAll()).hasSize(0); - SoftwareModule sm = new SoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1", + JpaSoftwareModule sm = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1", "version 1", null, null); sm = softwareModuleRepository.save(sm); - SoftwareModule sm2 = new SoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 2", + JpaSoftwareModule sm2 = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 2", "version 2", null, null); sm2 = softwareModuleRepository.save(sm2); - SoftwareModule sm3 = new SoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 3", + JpaSoftwareModule sm3 = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 3", "version 3", null, null); sm3 = softwareModuleRepository.save(sm3); @@ -96,11 +99,11 @@ public class ArtifactManagementTest extends AbstractIntegrationTestWithMongoDB { assertThat(result).isInstanceOf(LocalArtifact.class); assertThat(result.getSoftwareModule().getId()).isEqualTo(sm.getId()); assertThat(result2.getSoftwareModule().getId()).isEqualTo(sm2.getId()); - assertThat(((LocalArtifact) result).getFilename()).isEqualTo("file1"); - assertThat(((LocalArtifact) result).getGridFsFileName()).isNotNull(); + assertThat(((JpaLocalArtifact) result).getFilename()).isEqualTo("file1"); + assertThat(((JpaLocalArtifact) result).getGridFsFileName()).isNotNull(); assertThat(result).isNotEqualTo(result2); - assertThat(((LocalArtifact) result).getGridFsFileName()) - .isEqualTo(((LocalArtifact) result2).getGridFsFileName()); + assertThat(((JpaLocalArtifact) result).getGridFsFileName()) + .isEqualTo(((JpaLocalArtifact) result2).getGridFsFileName()); assertThat(artifactManagement.findLocalArtifactByFilename("file1").get(0).getSha1Hash()) .isEqualTo(HashGeneratorUtils.generateSHA1(random)); @@ -116,7 +119,7 @@ public class ArtifactManagementTest extends AbstractIntegrationTestWithMongoDB { @Test @Description("Tests hard delete directly on repository.") public void hardDeleteSoftwareModule() throws NoSuchAlgorithmException, IOException { - SoftwareModule sm = new SoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1", + JpaSoftwareModule sm = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1", "version 1", null, null); sm = softwareModuleRepository.save(sm); @@ -137,18 +140,19 @@ public class ArtifactManagementTest extends AbstractIntegrationTestWithMongoDB { @Test @Description("Tests the creation of an external artifact metadata element.") public void createExternalArtifact() { - SoftwareModule sm = new SoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1", + JpaSoftwareModule sm = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1", "version 1", null, null); sm = softwareModuleRepository.save(sm); - SoftwareModule sm2 = new SoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 2", + JpaSoftwareModule sm2 = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 2", "version 2", null, null); sm2 = softwareModuleRepository.save(sm2); final ExternalArtifactProvider provider = artifactManagement.createExternalArtifactProvider("provider X", null, "https://fhghdfjgh", "/{version}/"); - ExternalArtifact result = artifactManagement.createExternalArtifact(provider, null, sm.getId()); + JpaExternalArtifact result = (JpaExternalArtifact) artifactManagement.createExternalArtifact(provider, null, + sm.getId()); assertNotNull("The result of an external artifact should not be null", result); assertThat(externalArtifactRepository.findAll()).contains(result).hasSize(1); @@ -156,7 +160,7 @@ public class ArtifactManagementTest extends AbstractIntegrationTestWithMongoDB { assertThat(result.getUrl()).isEqualTo("https://fhghdfjgh/{version}/"); assertThat(result.getExternalArtifactProvider()).isEqualTo(provider); - result = artifactManagement.createExternalArtifact(provider, "/test", sm2.getId()); + result = (JpaExternalArtifact) artifactManagement.createExternalArtifact(provider, "/test", sm2.getId()); assertNotNull("The newly created external artifact should not be null", result); assertThat(externalArtifactRepository.findAll()).contains(result).hasSize(2); assertThat(result.getUrl()).isEqualTo("https://fhghdfjgh/test"); @@ -168,14 +172,15 @@ public class ArtifactManagementTest extends AbstractIntegrationTestWithMongoDB { public void deleteExternalArtifact() { assertThat(artifactRepository.findAll()).isEmpty(); - SoftwareModule sm = new SoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1", + JpaSoftwareModule sm = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1", "version 1", null, null); sm = softwareModuleRepository.save(sm); - final ExternalArtifactProvider provider = artifactManagement.createExternalArtifactProvider("provider X", null, - "https://fhghdfjgh", "/{version}/"); + final JpaExternalArtifactProvider provider = (JpaExternalArtifactProvider) artifactManagement + .createExternalArtifactProvider("provider X", null, "https://fhghdfjgh", "/{version}/"); - final ExternalArtifact result = artifactManagement.createExternalArtifact(provider, null, sm.getId()); + final JpaExternalArtifact result = (JpaExternalArtifact) artifactManagement.createExternalArtifact(provider, + null, sm.getId()); assertNotNull("The newly created external artifact should not be null", result); assertThat(externalArtifactRepository.findAll()).contains(result).hasSize(1); @@ -194,11 +199,11 @@ public class ArtifactManagementTest extends AbstractIntegrationTestWithMongoDB { @Test @Description("Tests the deletion of a local artifact including metadata.") public void deleteLocalArtifact() throws NoSuchAlgorithmException, IOException { - SoftwareModule sm = new SoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1", + JpaSoftwareModule sm = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1", "version 1", null, null); sm = softwareModuleRepository.save(sm); - SoftwareModule sm2 = new SoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 2", + JpaSoftwareModule sm2 = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 2", "version 2", null, null); sm2 = softwareModuleRepository.save(sm2); @@ -213,26 +218,25 @@ public class ArtifactManagementTest extends AbstractIntegrationTestWithMongoDB { assertThat(result.getId()).isNotNull(); assertThat(result2.getId()).isNotNull(); - assertThat(((LocalArtifact) result).getGridFsFileName()) - .isNotEqualTo(((LocalArtifact) result2).getGridFsFileName()); - assertThat(operations.findOne( - new Query().addCriteria(Criteria.where("filename").is(((LocalArtifact) result).getGridFsFileName())))) + assertThat(((JpaLocalArtifact) result).getGridFsFileName()) + .isNotEqualTo(((JpaLocalArtifact) result2).getGridFsFileName()); + assertThat(operations.findOne(new Query() + .addCriteria(Criteria.where("filename").is(((JpaLocalArtifact) result).getGridFsFileName())))) .isNotNull(); - assertThat(operations.findOne( - new Query().addCriteria(Criteria.where("filename").is(((LocalArtifact) result2).getGridFsFileName())))) + assertThat(operations.findOne(new Query() + .addCriteria(Criteria.where("filename").is(((JpaLocalArtifact) result2).getGridFsFileName())))) .isNotNull(); artifactManagement.deleteLocalArtifact(result.getId()); - assertThat(operations.findOne( - new Query().addCriteria(Criteria.where("filename").is(((LocalArtifact) result).getGridFsFileName())))) - .isNull(); - assertThat(operations.findOne( - new Query().addCriteria(Criteria.where("filename").is(((LocalArtifact) result2).getGridFsFileName())))) + assertThat(operations.findOne(new Query() + .addCriteria(Criteria.where("filename").is(((JpaLocalArtifact) result).getGridFsFileName())))).isNull(); + assertThat(operations.findOne(new Query() + .addCriteria(Criteria.where("filename").is(((JpaLocalArtifact) result2).getGridFsFileName())))) .isNotNull(); artifactManagement.deleteLocalArtifact(result2.getId()); - assertThat(operations.findOne( - new Query().addCriteria(Criteria.where("filename").is(((LocalArtifact) result2).getGridFsFileName())))) + assertThat(operations.findOne(new Query() + .addCriteria(Criteria.where("filename").is(((JpaLocalArtifact) result2).getGridFsFileName())))) .isNull(); assertThat(artifactRepository.findAll()).hasSize(0); @@ -245,7 +249,7 @@ public class ArtifactManagementTest extends AbstractIntegrationTestWithMongoDB { assertThat(artifactRepository.findAll()).isEmpty(); // prepare test - SoftwareModule sm = new SoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1", + JpaSoftwareModule sm = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1", "version 1", null, null); sm = softwareModuleRepository.save(sm); @@ -272,11 +276,11 @@ public class ArtifactManagementTest extends AbstractIntegrationTestWithMongoDB { @Description("Test the deletion of an artifact metadata where the binary is still linked to another " + "metadata element. The expected result is that the metadata is deleted but the binary kept.") public void deleteDuplicateArtifacts() throws NoSuchAlgorithmException, IOException { - SoftwareModule sm = new SoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1", + JpaSoftwareModule sm = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1", "version 1", null, null); sm = softwareModuleRepository.save(sm); - SoftwareModule sm2 = new SoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 2", + JpaSoftwareModule sm2 = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 2", "version 2", null, null); sm2 = softwareModuleRepository.save(sm2); @@ -290,21 +294,20 @@ public class ArtifactManagementTest extends AbstractIntegrationTestWithMongoDB { assertThat(artifactRepository.findAll()).hasSize(2); assertThat(result.getId()).isNotNull(); assertThat(result2.getId()).isNotNull(); - assertThat(((LocalArtifact) result).getGridFsFileName()) - .isEqualTo(((LocalArtifact) result2).getGridFsFileName()); + assertThat(((JpaLocalArtifact) result).getGridFsFileName()) + .isEqualTo(((JpaLocalArtifact) result2).getGridFsFileName()); - assertThat(operations.findOne( - new Query().addCriteria(Criteria.where("filename").is(((LocalArtifact) result).getGridFsFileName())))) + assertThat(operations.findOne(new Query() + .addCriteria(Criteria.where("filename").is(((JpaLocalArtifact) result).getGridFsFileName())))) .isNotNull(); artifactManagement.deleteLocalArtifact(result.getId()); - assertThat(operations.findOne( - new Query().addCriteria(Criteria.where("filename").is(((LocalArtifact) result).getGridFsFileName())))) + assertThat(operations.findOne(new Query() + .addCriteria(Criteria.where("filename").is(((JpaLocalArtifact) result).getGridFsFileName())))) .isNotNull(); artifactManagement.deleteLocalArtifact(result2.getId()); - assertThat(operations.findOne( - new Query().addCriteria(Criteria.where("filename").is(((LocalArtifact) result).getGridFsFileName())))) - .isNull(); + assertThat(operations.findOne(new Query() + .addCriteria(Criteria.where("filename").is(((JpaLocalArtifact) result).getGridFsFileName())))).isNull(); } /** @@ -318,7 +321,7 @@ public class ArtifactManagementTest extends AbstractIntegrationTestWithMongoDB { @Test @Description("Loads an artifact based on given ID.") public void findArtifact() throws NoSuchAlgorithmException, IOException { - SoftwareModule sm = new SoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1", + SoftwareModule sm = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1", "version 1", null, null); sm = softwareManagement.createSoftwareModule(sm); @@ -339,7 +342,7 @@ public class ArtifactManagementTest extends AbstractIntegrationTestWithMongoDB { @Test @Description("Loads an artifact binary based on given ID.") public void loadStreamOfLocalArtifact() throws NoSuchAlgorithmException, IOException { - SoftwareModule sm = new SoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1", + SoftwareModule sm = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1", "version 1", null, null); sm = softwareManagement.createSoftwareModule(sm); @@ -357,7 +360,7 @@ public class ArtifactManagementTest extends AbstractIntegrationTestWithMongoDB { @Description("Trys and fails to load an artifact without required permission. Checks if expected InsufficientPermissionException is thrown.") public void loadLocalArtifactBinaryWithoutDownloadArtifactThrowsPermissionDenied() { try { - artifactManagement.loadLocalArtifactBinary(new LocalArtifact()); + artifactManagement.loadLocalArtifactBinary(new JpaLocalArtifact()); fail("Should not have worked with missing permission."); } catch (final InsufficientPermissionException e) { @@ -367,10 +370,10 @@ public class ArtifactManagementTest extends AbstractIntegrationTestWithMongoDB { @Test @Description("Searches an artifact through the relations of a software module.") public void findLocalArtifactBySoftwareModule() { - SoftwareModule sm = new SoftwareModule(osType, "name 1", "version 1", null, null); + SoftwareModule sm = new JpaSoftwareModule(osType, "name 1", "version 1", null, null); sm = softwareManagement.createSoftwareModule(sm); - SoftwareModule sm2 = new SoftwareModule(osType, "name 2", "version 2", null, null); + SoftwareModule sm2 = new JpaSoftwareModule(osType, "name 2", "version 2", null, null); sm2 = softwareManagement.createSoftwareModule(sm2); assertThat(artifactManagement.findLocalArtifactBySoftwareModule(pageReq, sm.getId())).isEmpty(); @@ -384,7 +387,7 @@ public class ArtifactManagementTest extends AbstractIntegrationTestWithMongoDB { @Test @Description("Searches an artifact through the relations of a software module and the filename.") public void findByFilenameAndSoftwareModule() { - SoftwareModule sm = new SoftwareModule(osType, "name 1", "version 1", null, null); + SoftwareModule sm = new JpaSoftwareModule(osType, "name 1", "version 1", null, null); sm = softwareManagement.createSoftwareModule(sm); assertThat(artifactManagement.findByFilenameAndSoftwareModule("file1", sm.getId())).isEmpty(); diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ControllerManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ControllerManagementTest.java index 4c0bc1c19..76286d217 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ControllerManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ControllerManagementTest.java @@ -19,6 +19,8 @@ import javax.validation.ConstraintViolationException; import org.apache.commons.lang3.RandomStringUtils; import org.eclipse.hawkbit.AbstractIntegrationTest; import org.eclipse.hawkbit.TestDataUtil; +import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus; +import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; @@ -38,7 +40,7 @@ public class ControllerManagementTest extends AbstractIntegrationTest { @Test @Description("Controller adds a new action status.") public void controllerAddsActionStatus() { - final Target target = new Target("4712"); + final Target target = new JpaTarget("4712"); final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement, distributionSetManagement); Target savedTarget = targetManagement.createTarget(target); @@ -54,7 +56,7 @@ public class ControllerManagementTest extends AbstractIntegrationTest { assertThat(targetManagement.findTargetByControllerID(savedTarget.getControllerId()).getTargetInfo() .getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING); - ActionStatus actionStatusMessage = new ActionStatus(savedAction, Action.Status.RUNNING, + ActionStatus actionStatusMessage = new JpaActionStatus(savedAction, Action.Status.RUNNING, System.currentTimeMillis()); actionStatusMessage.addMessage("foobar"); savedAction.setStatus(Status.RUNNING); @@ -62,7 +64,7 @@ public class ControllerManagementTest extends AbstractIntegrationTest { assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus()) .isEqualTo(TargetUpdateStatus.PENDING); - actionStatusMessage = new ActionStatus(savedAction, Action.Status.FINISHED, System.currentTimeMillis()); + actionStatusMessage = new JpaActionStatus(savedAction, Action.Status.FINISHED, System.currentTimeMillis()); actionStatusMessage.addMessage(RandomStringUtils.randomAscii(512)); savedAction.setStatus(Status.FINISHED); controllerManagament.addUpdateActionStatus(actionStatusMessage); @@ -98,7 +100,7 @@ public class ControllerManagementTest extends AbstractIntegrationTest { public void tryToFinishUpdateProcessMoreThenOnce() { // mock - final Target target = new Target("Rabbit"); + final Target target = new JpaTarget("Rabbit"); final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement, distributionSetManagement); Target savedTarget = targetManagement.createTarget(target); @@ -108,21 +110,21 @@ public class ControllerManagementTest extends AbstractIntegrationTest { Action savedAction = deploymentManagement.findActiveActionsByTarget(savedTarget).get(0); // test and verify - final ActionStatus actionStatusMessage = new ActionStatus(savedAction, Action.Status.RUNNING, + final ActionStatus actionStatusMessage = new JpaActionStatus(savedAction, Action.Status.RUNNING, System.currentTimeMillis()); actionStatusMessage.addMessage("running"); savedAction = controllerManagament.addUpdateActionStatus(actionStatusMessage); assertThat(targetManagement.findTargetByControllerID("Rabbit").getTargetInfo().getUpdateStatus()) .isEqualTo(TargetUpdateStatus.PENDING); - final ActionStatus actionStatusMessage2 = new ActionStatus(savedAction, Action.Status.ERROR, + final ActionStatus actionStatusMessage2 = new JpaActionStatus(savedAction, Action.Status.ERROR, System.currentTimeMillis()); actionStatusMessage2.addMessage("error"); savedAction = controllerManagament.addUpdateActionStatus(actionStatusMessage2); assertThat(targetManagement.findTargetByControllerID("Rabbit").getTargetInfo().getUpdateStatus()) .isEqualTo(TargetUpdateStatus.ERROR); - final ActionStatus actionStatusMessage3 = new ActionStatus(savedAction, Action.Status.FINISHED, + final ActionStatus actionStatusMessage3 = new JpaActionStatus(savedAction, Action.Status.FINISHED, System.currentTimeMillis()); actionStatusMessage3.addMessage("finish"); controllerManagament.addUpdateActionStatus(actionStatusMessage3); diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DeploymentManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DeploymentManagementTest.java index 6a6d92bf0..50b929622 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DeploymentManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DeploymentManagementTest.java @@ -13,6 +13,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.LinkedList; import java.util.List; @@ -28,6 +29,13 @@ import org.eclipse.hawkbit.eventbus.event.TargetAssignDistributionSetEvent; import org.eclipse.hawkbit.repository.exception.ForceQuitActionNotAllowedException; import org.eclipse.hawkbit.repository.exception.IncompleteDistributionSetException; import org.eclipse.hawkbit.repository.jpa.TargetRepository; +import org.eclipse.hawkbit.repository.jpa.model.JpaAction; +import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag; +import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; +import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; +import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.ActionType; import org.eclipse.hawkbit.repository.model.Action.Status; @@ -91,8 +99,8 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { final Action action = deploymentManagement.findActionWithDetails( deploymentManagement.assignDistributionSet(testDs, testTarget).getActions().get(0)); // save 2 action status - actionStatusRepository.save(new ActionStatus(action, Status.RETRIEVED, System.currentTimeMillis())); - actionStatusRepository.save(new ActionStatus(action, Status.RUNNING, System.currentTimeMillis())); + actionStatusRepository.save(new JpaActionStatus(action, Status.RETRIEVED, System.currentTimeMillis())); + actionStatusRepository.save(new JpaActionStatus(action, Status.RUNNING, System.currentTimeMillis())); final List findActionsWithStatusCountByTarget = deploymentManagement .findActionsWithStatusCountByTargetOrderByIdDesc(testTarget.get(0)); @@ -112,7 +120,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { } // not exists assignDS.add(Long.valueOf(100)); - final DistributionSetTag tag = tagManagement.createDistributionSetTag(new DistributionSetTag("Tag1")); + final DistributionSetTag tag = tagManagement.createDistributionSetTag(new JpaDistributionSetTag("Tag1")); final List assignedDS = distributionSetManagement.assignTag(assignDS, tag); assertThat(assignedDS.size()).as("assigned ds has wrong size").isEqualTo(4); @@ -171,17 +179,17 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { + "actions after canceling the second active action the first one is still running as it is not touched by the cancelation. After canceling the first one " + "also the target goes back to IN_SYNC as no open action is left.") public void manualCancelWithMultipleAssignmentsCancelLastOneFirst() { - Target target = new Target("4712"); - final DistributionSet dsFirst = TestDataUtil.generateDistributionSet("", softwareManagement, + JpaTarget target = new JpaTarget("4712"); + final JpaDistributionSet dsFirst = TestDataUtil.generateDistributionSet("", softwareManagement, distributionSetManagement, true); dsFirst.setRequiredMigrationStep(true); - final DistributionSet dsSecond = TestDataUtil.generateDistributionSet("2", softwareManagement, + final JpaDistributionSet dsSecond = TestDataUtil.generateDistributionSet("2", softwareManagement, distributionSetManagement, true); - final DistributionSet dsInstalled = TestDataUtil.generateDistributionSet("installed", softwareManagement, + final JpaDistributionSet dsInstalled = TestDataUtil.generateDistributionSet("installed", softwareManagement, distributionSetManagement, true); - target.getTargetInfo().setInstalledDistributionSet(dsInstalled); - target = targetManagement.createTarget(target); + ((JpaTargetInfo) target.getTargetInfo()).setInstalledDistributionSet(dsInstalled); + target = (JpaTarget) targetManagement.createTarget(target); // check initial status assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus()) @@ -201,7 +209,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { // confirm cancellation secondAction.setStatus(Status.CANCELED); controllerManagement - .addCancelActionStatus(new ActionStatus(secondAction, Status.CANCELED, System.currentTimeMillis())); + .addCancelActionStatus(new JpaActionStatus(secondAction, Status.CANCELED, System.currentTimeMillis())); assertThat(actionStatusRepository.findAll()).as("wrong size of actions status").hasSize(4); assertThat(targetManagement.findTargetByControllerID("4712").getAssignedDistributionSet()).as("wrong ds") .isEqualTo(dsFirst); @@ -215,7 +223,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { // confirm cancellation firstAction.setStatus(Status.CANCELED); controllerManagement - .addCancelActionStatus(new ActionStatus(firstAction, Status.CANCELED, System.currentTimeMillis())); + .addCancelActionStatus(new JpaActionStatus(firstAction, Status.CANCELED, System.currentTimeMillis())); assertThat(actionStatusRepository.findAll()).as("wrong size of action status").hasSize(6); assertThat(targetManagement.findTargetByControllerID("4712").getAssignedDistributionSet()) .as("wrong assigned ds").isEqualTo(dsInstalled); @@ -228,17 +236,17 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { + "actions after canceling the first active action the system switched to second one. After canceling this one " + "also the target goes back to IN_SYNC as no open action is left.") public void manualCancelWithMultipleAssignmentsCancelMiddleOneFirst() { - Target target = new Target("4712"); - final DistributionSet dsFirst = TestDataUtil.generateDistributionSet("", softwareManagement, + JpaTarget target = new JpaTarget("4712"); + final JpaDistributionSet dsFirst = TestDataUtil.generateDistributionSet("", softwareManagement, distributionSetManagement, true); dsFirst.setRequiredMigrationStep(true); - final DistributionSet dsSecond = TestDataUtil.generateDistributionSet("2", softwareManagement, + final JpaDistributionSet dsSecond = TestDataUtil.generateDistributionSet("2", softwareManagement, distributionSetManagement, true); - final DistributionSet dsInstalled = TestDataUtil.generateDistributionSet("installed", softwareManagement, + final JpaDistributionSet dsInstalled = TestDataUtil.generateDistributionSet("installed", softwareManagement, distributionSetManagement, true); - target.getTargetInfo().setInstalledDistributionSet(dsInstalled); - target = targetManagement.createTarget(target); + ((JpaTargetInfo) target.getTargetInfo()).setInstalledDistributionSet(dsInstalled); + target = (JpaTarget) targetManagement.createTarget(target); // check initial status assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus()) @@ -258,7 +266,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { firstAction = deploymentManagement.findActionWithDetails(firstAction.getId()); firstAction.setStatus(Status.CANCELED); controllerManagement - .addCancelActionStatus(new ActionStatus(firstAction, Status.CANCELED, System.currentTimeMillis())); + .addCancelActionStatus(new JpaActionStatus(firstAction, Status.CANCELED, System.currentTimeMillis())); assertThat(actionStatusRepository.findAll()).as("wrong size of action status").hasSize(4); assertThat(targetManagement.findTargetByControllerID("4712").getAssignedDistributionSet()) .as("wrong assigned ds").isEqualTo(dsSecond); @@ -275,7 +283,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { // confirm cancellation secondAction.setStatus(Status.CANCELED); controllerManagement - .addCancelActionStatus(new ActionStatus(secondAction, Status.CANCELED, System.currentTimeMillis())); + .addCancelActionStatus(new JpaActionStatus(secondAction, Status.CANCELED, System.currentTimeMillis())); // cancelled success -> back to dsInstalled assertThat(targetManagement.findTargetByControllerID("4712").getAssignedDistributionSet()) .as("wrong installed ds").isEqualTo(dsInstalled); @@ -287,15 +295,15 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { @Description("Force Quit an Assignment. Expected behaviour is that the action is canceled and is marked as deleted. The assigned Software module") public void forceQuitSetActionToInactive() throws InterruptedException { - Target target = new Target("4712"); - final DistributionSet dsInstalled = TestDataUtil.generateDistributionSet("installed", softwareManagement, + JpaTarget target = new JpaTarget("4712"); + final JpaDistributionSet dsInstalled = TestDataUtil.generateDistributionSet("installed", softwareManagement, distributionSetManagement, true); - target.getTargetInfo().setInstalledDistributionSet(dsInstalled); - target = targetManagement.createTarget(target); + ((JpaTargetInfo) target.getTargetInfo()).setInstalledDistributionSet(dsInstalled); + target = (JpaTarget) targetManagement.createTarget(target); - final DistributionSet ds = TestDataUtil - .generateDistributionSet("newDS", softwareManagement, distributionSetManagement, true) - .setRequiredMigrationStep(true); + final JpaDistributionSet ds = TestDataUtil.generateDistributionSet("newDS", softwareManagement, + distributionSetManagement, true); + ds.setRequiredMigrationStep(true); // verify initial status assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus()) @@ -307,7 +315,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { assertThat(actionRepository.findAll()).as("wrong size of action").hasSize(1); assertThat(actionStatusRepository.findAll()).as("wrong size of action status").hasSize(1); - target = targetManagement.findTargetByControllerID(target.getControllerId()); + target = (JpaTarget) targetManagement.findTargetByControllerID(target.getControllerId()); // force quit assignment deploymentManagement.cancelAction(assigningAction, target); @@ -329,15 +337,15 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { @Description("Force Quit an not canceled Assignment. Expected behaviour is that the action can not be force quit and there is thrown an exception.") public void forceQuitNotAllowedThrowsException() { - Target target = new Target("4712"); - final DistributionSet dsInstalled = TestDataUtil.generateDistributionSet("installed", softwareManagement, + JpaTarget target = new JpaTarget("4712"); + final JpaDistributionSet dsInstalled = TestDataUtil.generateDistributionSet("installed", softwareManagement, distributionSetManagement, true); - target.getTargetInfo().setInstalledDistributionSet(dsInstalled); - target = targetManagement.createTarget(target); + ((JpaTargetInfo) target.getTargetInfo()).setInstalledDistributionSet(dsInstalled); + target = (JpaTarget) targetManagement.createTarget(target); - final DistributionSet ds = TestDataUtil - .generateDistributionSet("newDS", softwareManagement, distributionSetManagement, true) - .setRequiredMigrationStep(true); + final JpaDistributionSet ds = TestDataUtil.generateDistributionSet("newDS", softwareManagement, + distributionSetManagement, true); + ds.setRequiredMigrationStep(true); // verify initial status assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus()) @@ -357,7 +365,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { } } - private Action assignSet(final Target target, final DistributionSet ds) { + private Action assignSet(final JpaTarget target, final JpaDistributionSet ds) { deploymentManagement.assignDistributionSet(ds.getId(), new String[] { target.getControllerId() }); assertThat( targetManagement.findTargetByControllerID(target.getControllerId()).getTargetInfo().getUpdateStatus()) @@ -442,14 +450,14 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { final List targets = targetManagement.createTargets(TestDataUtil.generateTargets(10)); final SoftwareModule ah = softwareManagement - .createSoftwareModule(new SoftwareModule(appType, "agent-hub", "1.0.1", null, "")); + .createSoftwareModule(new JpaSoftwareModule(appType, "agent-hub", "1.0.1", null, "")); final SoftwareModule jvm = softwareManagement - .createSoftwareModule(new SoftwareModule(runtimeType, "oracle-jre", "1.7.2", null, "")); + .createSoftwareModule(new JpaSoftwareModule(runtimeType, "oracle-jre", "1.7.2", null, "")); final SoftwareModule os = softwareManagement - .createSoftwareModule(new SoftwareModule(osType, "poky", "3.0.2", null, "")); + .createSoftwareModule(new JpaSoftwareModule(osType, "poky", "3.0.2", null, "")); final DistributionSet incomplete = distributionSetManagement.createDistributionSet( - new DistributionSet("incomplete", "v1", "", standardDsType, Lists.newArrayList(ah, jvm))); + new JpaDistributionSet("incomplete", "v1", "", standardDsType, Lists.newArrayList(ah, jvm))); try { deploymentManagement.assignDistributionSet(incomplete, targets); @@ -507,7 +515,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { final List savedDeployedTargets = deploymentResult.getDeployedTargets(); // retrieving all Actions created by the assignDistributionSet call - final Page page = actionRepository.findAll(pageReq); + final Page page = actionRepository.findAll(pageReq); // and verify the number assertThat(page.getTotalElements()).as("wrong size of actions") .isEqualTo(noOfDeployedTargets * noOfDistributionSets); @@ -515,10 +523,10 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { // only records retrieved from the DB can be evaluated to be sure that // all fields are // populated; - final Iterable allFoundTargets = targetRepository.findAll(); + final Iterable allFoundTargets = targetRepository.findAll(); - final Iterable deployedTargetsFromDB = targetRepository.findAll(deployedTargetIDs); - final Iterable undeployedTargetsFromDB = targetRepository.findAll(undeployedTargetIDs); + final Iterable deployedTargetsFromDB = targetRepository.findAll(deployedTargetIDs); + final Iterable undeployedTargetsFromDB = targetRepository.findAll(undeployedTargetIDs); // test that number of Targets assertThat(allFoundTargets.spliterator().getExactSizeIfKnown()).as("number of target is wrong") @@ -532,10 +540,12 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { // test the content of different lists assertThat(allFoundTargets).as("content of founded target is wrong").containsAll(deployedTargetsFromDB) .containsAll(undeployedTargetsFromDB); - assertThat(deployedTargetsFromDB).as("content of deployed target is wrong").containsAll(savedDeployedTargets) - .doesNotContain(Iterables.toArray(undeployedTargetsFromDB, Target.class)); - assertThat(undeployedTargetsFromDB).as("content of undeployed target is wrong").containsAll(savedNakedTargets) - .doesNotContain(Iterables.toArray(deployedTargetsFromDB, Target.class)); + assertThat(deployedTargetsFromDB).as("content of deployed target is wrong") + .containsAll((Iterable) savedDeployedTargets) + .doesNotContain(Iterables.toArray(undeployedTargetsFromDB, JpaTarget.class)); + assertThat(undeployedTargetsFromDB).as("content of undeployed target is wrong") + .containsAll((Iterable) savedNakedTargets) + .doesNotContain(Iterables.toArray(deployedTargetsFromDB, JpaTarget.class)); // For each of the 4 targets 1 distribution sets gets assigned eventHandlerMock.getEvents(10, TimeUnit.SECONDS); @@ -557,9 +567,9 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { final DeploymentResult deployResWithDsC = prepareComplexRepo("undep-C-T", 4, "dep-C-T", 6, 1, "dsC"); // keep a reference to the created DistributionSets - final DistributionSet dsA = deployResWithDsA.getDistributionSets().get(0); - final DistributionSet dsB = deployResWithDsB.getDistributionSets().get(0); - final DistributionSet dsC = deployResWithDsC.getDistributionSets().get(0); + final JpaDistributionSet dsA = (JpaDistributionSet) deployResWithDsA.getDistributionSets().get(0); + final JpaDistributionSet dsB = (JpaDistributionSet) deployResWithDsB.getDistributionSets().get(0); + final JpaDistributionSet dsC = (JpaDistributionSet) deployResWithDsC.getDistributionSets().get(0); // retrieving the UpdateActions created by the assignments actionRepository.findByDistributionSet(pageRequest, dsA).getContent().get(0); @@ -722,9 +732,9 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { private List sendUpdateActionStatusToTargets(final DistributionSet dsA, final Iterable targs, final Status status, final String... msgs) { - final List result = new ArrayList(); + final List result = new ArrayList<>(); for (final Target t : targs) { - final List findByTarget = actionRepository.findByTarget(t); + final List findByTarget = actionRepository.findByTarget((JpaTarget) t); for (final Action action : findByTarget) { result.add(sendUpdateActionStatusToTarget(status, action, t, msgs)); } @@ -736,7 +746,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { final String... msgs) { updActA.setStatus(status); - final ActionStatus statusMessages = new ActionStatus(); + final ActionStatus statusMessages = new JpaActionStatus(); statusMessages.setAction(updActA); statusMessages.setOccurredAt(System.currentTimeMillis()); statusMessages.setStatus(status); @@ -751,14 +761,14 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { @Description("Testing if changing target and the status without refreshing the entities from the DB (e.g. concurrent changes from UI and from controller) works") public void alternatingAssignmentAndAddUpdateActionStatus() { - final DistributionSet dsA = TestDataUtil.generateDistributionSet("a", softwareManagement, + final JpaDistributionSet dsA = TestDataUtil.generateDistributionSet("a", softwareManagement, distributionSetManagement); - final DistributionSet dsB = TestDataUtil.generateDistributionSet("b", softwareManagement, + final JpaDistributionSet dsB = TestDataUtil.generateDistributionSet("b", softwareManagement, distributionSetManagement); Target targ = targetManagement .createTarget(TestDataUtil.buildTargetFixture("target-id-A", "first description")); - List targs = new ArrayList(); + List targs = new ArrayList<>(); targs.add(targ); // doing the assignment @@ -786,7 +796,8 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { final Page updAct = actionRepository.findByDistributionSet(pageReq, dsA); final Action action = updAct.getContent().get(0); action.setStatus(Status.FINISHED); - final ActionStatus statusMessage = new ActionStatus(action, Status.FINISHED, System.currentTimeMillis(), ""); + final ActionStatus statusMessage = new JpaActionStatus((JpaAction) action, Status.FINISHED, + System.currentTimeMillis(), ""); controllerManagament.addUpdateActionStatus(statusMessage); targ = targetManagement.findTargetByControllerID(targ.getControllerId()); @@ -842,7 +853,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { @Description("Tests the switch from a soft to hard update by API") public void forceSoftAction() { // prepare - final Target target = targetManagement.createTarget(new Target("knownControllerId")); + final Target target = targetManagement.createTarget(new JpaTarget("knownControllerId")); final DistributionSet ds = TestDataUtil.generateDistributionSet("a", softwareManagement, distributionSetManagement); // assign ds to create an action @@ -865,7 +876,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { @Description("Tests the switch from a hard to hard update by API, e.g. which in fact should not change anything.") public void forceAlreadyForcedActionNothingChanges() { // prepare - final Target target = targetManagement.createTarget(new Target("knownControllerId")); + final Target target = targetManagement.createTarget(new JpaTarget("knownControllerId")); final DistributionSet ds = TestDataUtil.generateDistributionSet("a", softwareManagement, distributionSetManagement); // assign ds to create an action @@ -919,8 +930,8 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { TestDataUtil.buildTargetFixtures(noOfDeployedTargets, deployedTargetPrefix, "first description")); // creating 10 DistributionSets - final List dsList = TestDataUtil.generateDistributionSets(distributionSetPrefix, - noOfDistributionSets, softwareManagement, distributionSetManagement); + final Collection dsList = (Collection) TestDataUtil.generateDistributionSets( + distributionSetPrefix, noOfDistributionSets, softwareManagement, distributionSetManagement); String time = String.valueOf(System.currentTimeMillis()); time = time.substring(time.length() - 5); diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DistributionSetManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DistributionSetManagementTest.java index 8faae175e..3ed4e703e 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DistributionSetManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DistributionSetManagementTest.java @@ -12,6 +12,7 @@ import static org.fest.assertions.api.Assertions.assertThat; import static org.junit.Assert.fail; import java.util.ArrayList; +import java.util.Collection; import java.util.Iterator; import java.util.List; @@ -24,6 +25,13 @@ import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.exception.EntityLockedException; import org.eclipse.hawkbit.repository.exception.EntityReadOnlyException; import org.eclipse.hawkbit.repository.exception.UnsupportedSoftwareModuleForThisDistributionSetException; +import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetMetadata; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType; +import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; +import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; @@ -56,7 +64,7 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest { @Description("Tests the successfull module update of unused distribution set type which is in fact allowed.") public void updateUnassignedDistributionSetTypeModules() { DistributionSetType updatableType = distributionSetManagement - .createDistributionSetType(new DistributionSetType("updatableType", "to be deleted", "")); + .createDistributionSetType(new JpaDistributionSetType("updatableType", "to be deleted", "")); assertThat(distributionSetManagement.findDistributionSetTypeByKey("updatableType").getMandatoryModuleTypes()) .isEmpty(); @@ -83,11 +91,11 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest { @Description("Tests the successfull update of used distribution set type meta data hich is in fact allowed.") public void updateAssignedDistributionSetTypeMetaData() { final DistributionSetType nonUpdatableType = distributionSetManagement - .createDistributionSetType(new DistributionSetType("updatableType", "to be deletd", "")); + .createDistributionSetType(new JpaDistributionSetType("updatableType", "to be deletd", "")); assertThat(distributionSetManagement.findDistributionSetTypeByKey("updatableType").getMandatoryModuleTypes()) .isEmpty(); distributionSetManagement - .createDistributionSet(new DistributionSet("newtypesoft", "1", "", nonUpdatableType, null)); + .createDistributionSet(new JpaDistributionSet("newtypesoft", "1", "", nonUpdatableType, null)); nonUpdatableType.setDescription("a new description"); nonUpdatableType.setColour("test123"); @@ -104,11 +112,11 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest { @Description("Tests the unsuccessfull update of used distribution set type (module addition).") public void addModuleToAssignedDistributionSetTypeFails() { final DistributionSetType nonUpdatableType = distributionSetManagement - .createDistributionSetType(new DistributionSetType("updatableType", "to be deletd", "")); + .createDistributionSetType(new JpaDistributionSetType("updatableType", "to be deletd", "")); assertThat(distributionSetManagement.findDistributionSetTypeByKey("updatableType").getMandatoryModuleTypes()) .isEmpty(); distributionSetManagement - .createDistributionSet(new DistributionSet("newtypesoft", "1", "", nonUpdatableType, null)); + .createDistributionSet(new JpaDistributionSet("newtypesoft", "1", "", nonUpdatableType, null)); nonUpdatableType.addMandatoryModuleType(osType); @@ -125,14 +133,14 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest { @Description("Tests the unsuccessfull update of used distribution set type (module removal).") public void removeModuleToAssignedDistributionSetTypeFails() { DistributionSetType nonUpdatableType = distributionSetManagement - .createDistributionSetType(new DistributionSetType("updatableType", "to be deletd", "")); + .createDistributionSetType(new JpaDistributionSetType("updatableType", "to be deletd", "")); assertThat(distributionSetManagement.findDistributionSetTypeByKey("updatableType").getMandatoryModuleTypes()) .isEmpty(); nonUpdatableType.addMandatoryModuleType(osType); nonUpdatableType = distributionSetManagement.updateDistributionSetType(nonUpdatableType); distributionSetManagement - .createDistributionSet(new DistributionSet("newtypesoft", "1", "", nonUpdatableType, null)); + .createDistributionSet(new JpaDistributionSet("newtypesoft", "1", "", nonUpdatableType, null)); nonUpdatableType.removeModuleType(osType.getId()); try { @@ -146,8 +154,8 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest { @Test @Description("Tests the successfull deletion of unused (hard delete) distribution set types.") public void deleteUnassignedDistributionSetType() { - final DistributionSetType hardDelete = distributionSetManagement - .createDistributionSetType(new DistributionSetType("deleted", "to be deleted", "")); + final JpaDistributionSetType hardDelete = (JpaDistributionSetType) distributionSetManagement + .createDistributionSetType(new JpaDistributionSetType("deleted", "to be deleted", "")); assertThat(distributionSetTypeRepository.findAll()).contains(hardDelete); distributionSetManagement.deleteDistributionSetType(hardDelete); @@ -158,11 +166,12 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest { @Test @Description("Tests the successfull deletion of used (soft delete) distribution set types.") public void deleteAssignedDistributionSetType() { - final DistributionSetType softDelete = distributionSetManagement - .createDistributionSetType(new DistributionSetType("softdeleted", "to be deletd", "")); + final JpaDistributionSetType softDelete = (JpaDistributionSetType) distributionSetManagement + .createDistributionSetType(new JpaDistributionSetType("softdeleted", "to be deletd", "")); assertThat(distributionSetTypeRepository.findAll()).contains(softDelete); - distributionSetManagement.createDistributionSet(new DistributionSet("newtypesoft", "1", "", softDelete, null)); + distributionSetManagement + .createDistributionSet(new JpaDistributionSet("newtypesoft", "1", "", softDelete, null)); distributionSetManagement.deleteDistributionSetType(softDelete); assertThat(distributionSetManagement.findDistributionSetTypeByKey("softdeleted").isDeleted()).isEqualTo(true); @@ -185,7 +194,7 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest { @Description("Verfies that a DS is of default type if not specified explicitly at creation time.") public void createDistributionSetWithImplicitType() { final DistributionSet set = distributionSetManagement - .createDistributionSet(new DistributionSet("newtypesoft", "1", "", null, null)); + .createDistributionSet(new JpaDistributionSet("newtypesoft", "1", "", null, null)); assertThat(set.getType()).as("Type should be equal to default type of tenant") .isEqualTo(systemManagement.getTenantMetadata().getDefaultDsType()); @@ -198,7 +207,7 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest { List sets = new ArrayList<>(); for (int i = 0; i < 10; i++) { - sets.add(new DistributionSet("another DS" + i, "X" + i, "", null, null)); + sets.add(new JpaDistributionSet("another DS" + i, "X" + i, "", null, null)); } sets = distributionSetManagement.createDistributionSets(sets); @@ -216,7 +225,7 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest { @Description("Verfies that a DS entity cannot be used for creation.") public void createDistributionSetFailsOnExistingEntity() { final DistributionSet set = distributionSetManagement - .createDistributionSet(new DistributionSet("newtypesoft", "1", "", null, null)); + .createDistributionSet(new JpaDistributionSet("newtypesoft", "1", "", null, null)); try { distributionSetManagement.createDistributionSet(set); @@ -235,8 +244,8 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest { final DistributionSet ds = TestDataUtil.generateDistributionSet("testDs", softwareManagement, distributionSetManagement); - final DistributionSetMetadata metadata = new DistributionSetMetadata(knownKey, ds, knownValue); - final DistributionSetMetadata createdMetadata = distributionSetManagement + final DistributionSetMetadata metadata = new JpaDistributionSetMetadata(knownKey, ds, knownValue); + final JpaDistributionSetMetadata createdMetadata = (JpaDistributionSetMetadata) distributionSetManagement .createDistributionSetMetadata(metadata); assertThat(createdMetadata).isNotNull(); @@ -249,11 +258,11 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest { @Description("Ensures that updates concerning the internal software structure of a DS are not possible if the DS is already assigned.") public void updateDistributionSetForbiddedWithIllegalUpdate() { // prepare data - Target target = new Target("4711"); + Target target = new JpaTarget("4711"); target = targetManagement.createTarget(target); - SoftwareModule ah2 = new SoftwareModule(appType, "agent-hub2", "1.0.5", null, ""); - SoftwareModule os2 = new SoftwareModule(osType, "poky2", "3.0.3", null, ""); + SoftwareModule ah2 = new JpaSoftwareModule(appType, "agent-hub2", "1.0.5", null, ""); + SoftwareModule os2 = new JpaSoftwareModule(osType, "poky2", "3.0.3", null, ""); DistributionSet ds = TestDataUtil.generateDistributionSet("ds-1", softwareManagement, distributionSetManagement); @@ -303,8 +312,8 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest { @Test @Description("Ensures that it is not possible to add a software module to a set that has no type defined.") public void updateDistributionSetModuleWithUndefinedTypeFails() { - final DistributionSet testSet = new DistributionSet(); - final SoftwareModule module = new SoftwareModule(appType, "agent-hub2", "1.0.5", null, ""); + final DistributionSet testSet = new JpaDistributionSet(); + final SoftwareModule module = new JpaSoftwareModule(appType, "agent-hub2", "1.0.5", null, ""); // update data try { @@ -318,9 +327,9 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest { @Test @Description("Ensures that it is not possible to add a software module that is not defined of the DS's type.") public void updateDistributionSetUnsupportedModuleFails() { - final DistributionSet set = new DistributionSet("agent-hub2", "1.0.5", "desc", - new DistributionSetType("test", "test", "test").addMandatoryModuleType(osType), null); - final SoftwareModule module = new SoftwareModule(appType, "agent-hub2", "1.0.5", null, ""); + final DistributionSet set = new JpaDistributionSet("agent-hub2", "1.0.5", "desc", + new JpaDistributionSetType("test", "test", "test").addMandatoryModuleType(osType), null); + final SoftwareModule module = new JpaSoftwareModule(appType, "agent-hub2", "1.0.5", null, ""); // update data try { @@ -335,11 +344,11 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest { @Description("Legal updates of a DS, e.g. name or description and module addition, removal while still unassigned.") public void updateDistributionSet() { // prepare data - Target target = new Target("4711"); + Target target = new JpaTarget("4711"); target = targetManagement.createTarget(target); - SoftwareModule os2 = new SoftwareModule(osType, "poky2", "3.0.3", null, ""); - final SoftwareModule app2 = new SoftwareModule(appType, "app2", "3.0.3", null, ""); + SoftwareModule os2 = new JpaSoftwareModule(osType, "poky2", "3.0.3", null, ""); + final SoftwareModule app2 = new JpaSoftwareModule(appType, "app2", "3.0.3", null, ""); DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement, distributionSetManagement); @@ -387,7 +396,7 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest { // create an DS meta data entry final DistributionSetMetadata dsMetadata = distributionSetManagement - .createDistributionSetMetadata(new DistributionSetMetadata(knownKey, ds, knownValue)); + .createDistributionSetMetadata(new JpaDistributionSetMetadata(knownKey, ds, knownValue)); DistributionSet changedLockRevisionDS = distributionSetManagement.findDistributionSetById(ds.getId()); assertThat(changedLockRevisionDS.getOptLockRevision()).isEqualTo(2L); @@ -400,7 +409,8 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest { Thread.sleep(100); // update the DS metadata - final DistributionSetMetadata updated = distributionSetManagement.updateDistributionSetMetadata(dsMetadata); + final JpaDistributionSetMetadata updated = (JpaDistributionSetMetadata) distributionSetManagement + .updateDistributionSetMetadata(dsMetadata); // we are updating the sw meta data so also modifying the base software // module so opt lock // revision must be three @@ -419,13 +429,13 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest { @Description("Tests that a DS queue is possible where the result is ordered by the target assignment, i.e. assigned first in the list.") public void findDistributionSetsAllOrderedByLinkTarget() { - final List buildDistributionSets = TestDataUtil.generateDistributionSets("dsOrder", 10, + final List buildDistributionSets = TestDataUtil.generateDistributionSets("dsOrder", 10, softwareManagement, distributionSetManagement); final List buildTargetFixtures = targetManagement .createTargets(TestDataUtil.buildTargetFixtures(5, "tOrder", "someDesc")); - final Iterator dsIterator = buildDistributionSets.iterator(); + final Iterator dsIterator = buildDistributionSets.iterator(); final Iterator tIterator = buildTargetFixtures.iterator(); final DistributionSet dsFirst = dsIterator.next(); final DistributionSet dsSecond = dsIterator.next(); @@ -466,29 +476,29 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest { @Description("searches for distribution sets based on the various filter options, e.g. name, version, desc., tags.") public void searchDistributionSetsOnFilters() { DistributionSetTag dsTagA = tagManagement - .createDistributionSetTag(new DistributionSetTag("DistributionSetTag-A")); + .createDistributionSetTag(new JpaDistributionSetTag("DistributionSetTag-A")); final DistributionSetTag dsTagB = tagManagement - .createDistributionSetTag(new DistributionSetTag("DistributionSetTag-B")); + .createDistributionSetTag(new JpaDistributionSetTag("DistributionSetTag-B")); final DistributionSetTag dsTagC = tagManagement - .createDistributionSetTag(new DistributionSetTag("DistributionSetTag-C")); + .createDistributionSetTag(new JpaDistributionSetTag("DistributionSetTag-C")); final DistributionSetTag dsTagD = tagManagement - .createDistributionSetTag(new DistributionSetTag("DistributionSetTag-D")); + .createDistributionSetTag(new JpaDistributionSetTag("DistributionSetTag-D")); - List ds100Group1 = TestDataUtil.generateDistributionSets("", 100, softwareManagement, - distributionSetManagement); - List ds100Group2 = TestDataUtil.generateDistributionSets("test2", 100, softwareManagement, - distributionSetManagement); + Collection ds100Group1 = (Collection) TestDataUtil.generateDistributionSets("", 100, + softwareManagement, distributionSetManagement); + Collection ds100Group2 = (Collection) TestDataUtil.generateDistributionSets("test2", 100, + softwareManagement, distributionSetManagement); DistributionSet dsDeleted = TestDataUtil.generateDistributionSet("deleted", softwareManagement, distributionSetManagement); final DistributionSet dsInComplete = distributionSetManagement - .createDistributionSet(new DistributionSet("notcomplete", "1", "", standardDsType, null)); + .createDistributionSet(new JpaDistributionSet("notcomplete", "1", "", standardDsType, null)); - final DistributionSetType newType = distributionSetManagement - .createDistributionSetType(new DistributionSetType("foo", "bar", "test").addMandatoryModuleType(osType) + final DistributionSetType newType = distributionSetManagement.createDistributionSetType( + new JpaDistributionSetType("foo", "bar", "test").addMandatoryModuleType(osType) .addOptionalModuleType(appType).addOptionalModuleType(runtimeType)); final DistributionSet dsNewType = distributionSetManagement - .createDistributionSet(new DistributionSet("newtype", "1", "", newType, dsDeleted.getModules())); + .createDistributionSet(new JpaDistributionSet("newtype", "1", "", newType, dsDeleted.getModules())); deploymentManagement.assignDistributionSet(dsDeleted, targetManagement.createTargets(Lists.newArrayList(TestDataUtil.generateTargets(5)))); @@ -705,7 +715,7 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest { final Status status, final String... msgs) { final List result = new ArrayList<>(); for (final Target t : targs) { - final List findByTarget = actionRepository.findByTarget(t); + final List findByTarget = actionRepository.findByTarget((JpaTarget) t); for (final Action action : findByTarget) { result.add(sendUpdateActionStatusToTarget(status, action, t, msgs)); } @@ -753,14 +763,14 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest { for (int index = 0; index < 10; index++) { ds1 = distributionSetManagement - .createDistributionSetMetadata(new DistributionSetMetadata("key" + index, ds1, "value" + index)) + .createDistributionSetMetadata(new JpaDistributionSetMetadata("key" + index, ds1, "value" + index)) .getDistributionSet(); } for (int index = 0; index < 20; index++) { ds2 = distributionSetManagement - .createDistributionSetMetadata(new DistributionSetMetadata("key" + index, ds2, "value" + index)) + .createDistributionSetMetadata(new JpaDistributionSetMetadata("key" + index, ds2, "value" + index)) .getDistributionSet(); } @@ -794,7 +804,7 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest { // create assigned DS dsAssigned = distributionSetManagement.findDistributionSetByNameAndVersion(dsAssigned.getName(), dsAssigned.getVersion()); - final Target target = new Target("4712"); + final Target target = new JpaTarget("4712"); final Target savedTarget = targetManagement.createTarget(target); final List toAssign = new ArrayList<>(); toAssign.add(savedTarget); @@ -814,7 +824,7 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest { final String... msgs) { updActA.setStatus(status); - final ActionStatus statusMessages = new ActionStatus(); + final ActionStatus statusMessages = new JpaActionStatus(); statusMessages.setAction(updActA); statusMessages.setOccurredAt(System.currentTimeMillis()); statusMessages.setStatus(status); diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ReportManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ReportManagementTest.java index e41491962..0a18c0b03 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ReportManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ReportManagementTest.java @@ -29,13 +29,16 @@ import org.eclipse.hawkbit.report.model.DataReportSeriesItem; import org.eclipse.hawkbit.report.model.InnerOuterDataReportSeries; import org.eclipse.hawkbit.report.model.SeriesTime; import org.eclipse.hawkbit.repository.ReportManagement.DateTypes; +import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus; +import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; +import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; +import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.Target; -import org.eclipse.hawkbit.repository.model.TargetInfo; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; import org.junit.After; import org.junit.Test; @@ -83,7 +86,7 @@ public class ReportManagementTest extends AbstractIntegrationTest { for (int month = 0; month < maxMonthBackAmountCreateTargets; month++) { dynamicDateTimeProvider.nowMinusMonths(month); - targetManagement.createTarget(new Target("t" + month)); + targetManagement.createTarget(new JpaTarget("t" + month)); } final LocalDateTime to = LocalDateTime.now(); @@ -105,7 +108,7 @@ public class ReportManagementTest extends AbstractIntegrationTest { // check cache evict for (int month = 0; month < maxMonthBackAmountCreateTargets; month++) { dynamicDateTimeProvider.nowMinusMonths(month); - targetManagement.createTarget(new Target("t2" + month)); + targetManagement.createTarget(new JpaTarget("t2" + month)); } targetsCreatedOverPeriod = reportManagement.targetsCreatedOverPeriod(DateTypes.perMonth(), from, to); for (final DataReportSeriesItem reportItem : targetsCreatedOverPeriod.getData()) { @@ -135,7 +138,7 @@ public class ReportManagementTest extends AbstractIntegrationTest { for (int month = 0; month < maxMonthBackAmountCreateTargets; month++) { dynamicDateTimeProvider.nowMinusMonths(month); - final Target createTarget = targetManagement.createTarget(new Target("t" + month)); + final Target createTarget = targetManagement.createTarget(new JpaTarget("t" + month)); final DistributionSetAssignmentResult result = deploymentManagement.assignDistributionSet(distributionSet, Lists.newArrayList(createTarget)); controllerManagament.registerRetrieved( @@ -157,7 +160,7 @@ public class ReportManagementTest extends AbstractIntegrationTest { // check cache evict for (int month = 0; month < maxMonthBackAmountCreateTargets; month++) { dynamicDateTimeProvider.nowMinusMonths(month); - final Target createTarget = targetManagement.createTarget(new Target("t2" + month)); + final Target createTarget = targetManagement.createTarget(new JpaTarget("t2" + month)); final DistributionSetAssignmentResult result = deploymentManagement.assignDistributionSet(distributionSet, Lists.newArrayList(createTarget)); controllerManagament.registerRetrieved( @@ -174,18 +177,18 @@ public class ReportManagementTest extends AbstractIntegrationTest { @Test @Description("Tests correct statistics calculation including a correct cache evict.") public void distributionUsageInstalled() { - final Target knownTarget1 = targetManagement.createTarget(new Target("t1")); - final Target knownTarget2 = targetManagement.createTarget(new Target("t2")); - final Target knownTarget3 = targetManagement.createTarget(new Target("t3")); - final Target knownTarget4 = targetManagement.createTarget(new Target("t4")); - final Target knownTarget5 = targetManagement.createTarget(new Target("t5")); + final Target knownTarget1 = targetManagement.createTarget(new JpaTarget("t1")); + final Target knownTarget2 = targetManagement.createTarget(new JpaTarget("t2")); + final Target knownTarget3 = targetManagement.createTarget(new JpaTarget("t3")); + final Target knownTarget4 = targetManagement.createTarget(new JpaTarget("t4")); + final Target knownTarget5 = targetManagement.createTarget(new JpaTarget("t5")); final SoftwareModule ah = softwareManagement - .createSoftwareModule(new SoftwareModule(appType, "agent-hub", "1.0.1", null, "")); + .createSoftwareModule(new JpaSoftwareModule(appType, "agent-hub", "1.0.1", null, "")); final SoftwareModule jvm = softwareManagement - .createSoftwareModule(new SoftwareModule(runtimeType, "oracle-jre", "1.7.2", null, "")); + .createSoftwareModule(new JpaSoftwareModule(runtimeType, "oracle-jre", "1.7.2", null, "")); final SoftwareModule os = softwareManagement - .createSoftwareModule(new SoftwareModule(osType, "poky", "3.0.2", null, "")); + .createSoftwareModule(new JpaSoftwareModule(osType, "poky", "3.0.2", null, "")); final DistributionSet distributionSet1 = distributionSetManagement .createDistributionSet(TestDataUtil.buildDistributionSet("ds1", "0.0.0", standardDsType, os, jvm, ah)); @@ -250,7 +253,7 @@ public class ReportManagementTest extends AbstractIntegrationTest { } // Test cache evict - final Target knownTarget6 = targetManagement.createTarget(new Target("t6")); + final Target knownTarget6 = targetManagement.createTarget(new JpaTarget("t6")); deploymentManagement.assignDistributionSet(distributionSet1.getId(), knownTarget6.getControllerId()); sendUpdateActionStatusToTargets(distributionSet1, Lists.newArrayList(knownTarget6), Status.FINISHED, "some message"); @@ -349,17 +352,17 @@ public class ReportManagementTest extends AbstractIntegrationTest { @Description("Tests correct statistics calculation including a correct cache evict.") public void topXDistributionUsage() { - final Target knownTarget1 = targetManagement.createTarget(new Target("t1")); - final Target knownTarget2 = targetManagement.createTarget(new Target("t2")); - final Target knownTarget3 = targetManagement.createTarget(new Target("t3")); - final Target knownTarget4 = targetManagement.createTarget(new Target("t4")); + final Target knownTarget1 = targetManagement.createTarget(new JpaTarget("t1")); + final Target knownTarget2 = targetManagement.createTarget(new JpaTarget("t2")); + final Target knownTarget3 = targetManagement.createTarget(new JpaTarget("t3")); + final Target knownTarget4 = targetManagement.createTarget(new JpaTarget("t4")); final SoftwareModule ah = softwareManagement - .createSoftwareModule(new SoftwareModule(appType, "agent-hub", "1.0.1", null, "")); + .createSoftwareModule(new JpaSoftwareModule(appType, "agent-hub", "1.0.1", null, "")); final SoftwareModule jvm = softwareManagement - .createSoftwareModule(new SoftwareModule(runtimeType, "oracle-jre", "1.7.2", null, "")); + .createSoftwareModule(new JpaSoftwareModule(runtimeType, "oracle-jre", "1.7.2", null, "")); final SoftwareModule os = softwareManagement - .createSoftwareModule(new SoftwareModule(osType, "poky", "3.0.2", null, "")); + .createSoftwareModule(new JpaSoftwareModule(osType, "poky", "3.0.2", null, "")); final DistributionSet distributionSet1 = distributionSetManagement .createDistributionSet(TestDataUtil.buildDistributionSet("ds1", "0.0.0", standardDsType, os, jvm, ah)); @@ -419,7 +422,7 @@ public class ReportManagementTest extends AbstractIntegrationTest { } // test cache evict - final Target knownTarget5 = targetManagement.createTarget(new Target("t5")); + final Target knownTarget5 = targetManagement.createTarget(new JpaTarget("t5")); deploymentManagement.assignDistributionSet(distributionSet1.getId(), knownTarget5.getControllerId()); distributionUsage = reportManagement.distributionUsageAssigned(100); for (final InnerOuterDataReportSeries innerOuterDataReportSeries : distributionUsage) { @@ -490,7 +493,7 @@ public class ReportManagementTest extends AbstractIntegrationTest { // create targets for another tenant securityRule.runAs(WithSpringAuthorityRule.withUserAndTenant("user", "anotherTenant"), () -> { for (int index = 0; index < targetCreateAmount; index++) { - targetManagement.createTarget(new Target("t" + index)); + targetManagement.createTarget(new JpaTarget("t" + index)); } return null; }); @@ -513,10 +516,10 @@ public class ReportManagementTest extends AbstractIntegrationTest { private void createTargets(final String prefix, final int amount, final LocalDateTime lastTargetQuery) { for (int index = 0; index < amount; index++) { - final Target target = new Target(prefix + index); - final Target createTarget = targetManagement.createTarget(target); + final Target target = new JpaTarget(prefix + index); + final JpaTarget createTarget = (JpaTarget) targetManagement.createTarget(target); if (lastTargetQuery != null) { - final TargetInfo targetInfo = createTarget.getTargetInfo(); + final JpaTargetInfo targetInfo = (JpaTargetInfo) createTarget.getTargetInfo(); targetInfo.setNew(false); targetInfo .setLastTargetQuery(lastTargetQuery.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()); @@ -527,9 +530,9 @@ public class ReportManagementTest extends AbstractIntegrationTest { private void createTargetsWithStatus(final String prefix, final long amount, final TargetUpdateStatus status) { for (int index = 0; index < amount; index++) { - final Target target = new Target(prefix + index); + final JpaTarget target = new JpaTarget(prefix + index); final Target sTarget = targetRepository.save(target); - final TargetInfo targetInfo = sTarget.getTargetInfo(); + final JpaTargetInfo targetInfo = (JpaTargetInfo) sTarget.getTargetInfo(); targetInfo.setUpdateStatus(status); targetInfoRepository.save(targetInfo); } @@ -537,9 +540,9 @@ public class ReportManagementTest extends AbstractIntegrationTest { private List sendUpdateActionStatusToTargets(final DistributionSet dsA, final Iterable targs, final Status status, final String... msgs) { - final List result = new ArrayList(); + final List result = new ArrayList<>(); for (final Target t : targs) { - final List findByTarget = actionRepository.findByTarget(t); + final List findByTarget = actionRepository.findByTarget((JpaTarget) t); for (final Action action : findByTarget) { result.add(sendUpdateActionStatusToTarget(status, action, t, msgs)); } @@ -551,7 +554,7 @@ public class ReportManagementTest extends AbstractIntegrationTest { final String... msgs) { updActA.setStatus(status); - final ActionStatus statusMessages = new ActionStatus(); + final ActionStatus statusMessages = new JpaActionStatus(); statusMessages.setAction(updActA); statusMessages.setOccurredAt(System.currentTimeMillis()); statusMessages.setStatus(status); diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/RolloutManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/RolloutManagementTest.java index 88bb26616..e56ce6cd5 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/RolloutManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/RolloutManagementTest.java @@ -19,23 +19,26 @@ import java.util.concurrent.Callable; import org.eclipse.hawkbit.AbstractIntegrationTest; import org.eclipse.hawkbit.TestDataUtil; import org.eclipse.hawkbit.repository.jpa.OffsetBasedPageRequest; +import org.eclipse.hawkbit.repository.jpa.model.JpaAction; +import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus; +import org.eclipse.hawkbit.repository.jpa.model.JpaRollout; +import org.eclipse.hawkbit.repository.jpa.model.JpaRollout.RolloutStatus; +import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup; +import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup.RolloutGroupConditions; +import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup.RolloutGroupErrorAction; +import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup.RolloutGroupErrorCondition; +import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup.RolloutGroupStatus; +import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup.RolloutGroupSuccessCondition; +import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; -import org.eclipse.hawkbit.repository.model.ActionStatus; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Rollout; -import org.eclipse.hawkbit.repository.model.Rollout.RolloutStatus; import org.eclipse.hawkbit.repository.model.RolloutGroup; -import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupConditions; -import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupErrorAction; -import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupErrorCondition; -import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupStatus; -import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupSuccessCondition; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; -import org.eclipse.hawkbit.repository.rsql.RSQLUtility; import org.eclipse.hawkbit.repository.utils.MultipleInvokeHelper; import org.eclipse.hawkbit.repository.utils.SuccessCondition; import org.junit.Test; @@ -45,7 +48,6 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Slice; import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort.Direction; -import org.springframework.data.jpa.domain.Specification; import ru.yandex.qatools.allure.annotations.Features; import ru.yandex.qatools.allure.annotations.Stories; @@ -135,10 +137,10 @@ public class RolloutManagementTest extends AbstractIntegrationTest { Status.RUNNING); // finish one action should be sufficient due the finish condition is at // 50% - final Action action = runningActions.get(0); + final JpaAction action = (JpaAction) runningActions.get(0); action.setStatus(Status.FINISHED); controllerManagament - .addUpdateActionStatus(new ActionStatus(action, Status.FINISHED, System.currentTimeMillis(), "")); + .addUpdateActionStatus(new JpaActionStatus(action, Status.FINISHED, System.currentTimeMillis(), "")); // check running rollouts again, now the finish condition should be hit // and should start the next group @@ -179,8 +181,8 @@ public class RolloutManagementTest extends AbstractIntegrationTest { // finish actions with error for (final Action action : runningActions) { action.setStatus(Status.ERROR); - controllerManagament - .addUpdateActionStatus(new ActionStatus(action, Status.ERROR, System.currentTimeMillis(), "")); + controllerManagament.addUpdateActionStatus( + new JpaActionStatus((JpaAction) action, Status.ERROR, System.currentTimeMillis(), "")); } // check running rollouts again, now the error condition should be hit @@ -221,8 +223,8 @@ public class RolloutManagementTest extends AbstractIntegrationTest { // finish actions with error for (final Action action : runningActions) { action.setStatus(Status.ERROR); - controllerManagament - .addUpdateActionStatus(new ActionStatus(action, Status.ERROR, System.currentTimeMillis(), "")); + controllerManagament.addUpdateActionStatus( + new JpaActionStatus((JpaAction) action, Status.ERROR, System.currentTimeMillis(), "")); } // check running rollouts again, now the error condition should be hit @@ -835,25 +837,24 @@ public class RolloutManagementTest extends AbstractIntegrationTest { targetManagement.createTargets(TestDataUtil.buildTargetFixtures(amountOtherTargets, "others-", "rollout")); final String rsqlParam = "controllerId==*MyRoll*"; - final Specification rsqlSpecification = RSQLUtility.parse(rsqlParam, TargetFields.class); rolloutManagement.startRollout(myRollout); myRollout = rolloutManagement.findRolloutById(myRollout.getId()); final List rolloutGroups = myRollout.getRolloutGroups(); - Page targetPage = rolloutGroupManagement.findRolloutGroupTargets(rolloutGroups.get(0), - rsqlSpecification, new OffsetBasedPageRequest(0, 100, new Sort(Direction.ASC, "controllerId"))); + Page targetPage = rolloutGroupManagement.findRolloutGroupTargets(rolloutGroups.get(0), rsqlParam, + new OffsetBasedPageRequest(0, 100, new Sort(Direction.ASC, "controllerId"))); final List targetlistGroup1 = targetPage.getContent(); assertThat(targetlistGroup1.size()).isEqualTo(5); assertThat(targetlistGroup1.get(0).getControllerId()).isEqualTo("MyRollout--00000"); - targetPage = rolloutGroupManagement.findRolloutGroupTargets(rolloutGroups.get(1), rsqlSpecification, + targetPage = rolloutGroupManagement.findRolloutGroupTargets(rolloutGroups.get(1), rsqlParam, new OffsetBasedPageRequest(0, 100, new Sort(Direction.DESC, "controllerId"))); final List targetlistGroup2 = targetPage.getContent(); assertThat(targetlistGroup2.size()).isEqualTo(5); assertThat(targetlistGroup2.get(0).getControllerId()).isEqualTo("MyRollout--00009"); - targetPage = rolloutGroupManagement.findRolloutGroupTargets(rolloutGroups.get(2), rsqlSpecification, + targetPage = rolloutGroupManagement.findRolloutGroupTargets(rolloutGroups.get(2), rsqlParam, new OffsetBasedPageRequest(0, 100, new Sort(Direction.ASC, "controllerId"))); final List targetlistGroup3 = targetPage.getContent(); assertThat(targetlistGroup3.size()).isEqualTo(5); @@ -875,11 +876,11 @@ public class RolloutManagementTest extends AbstractIntegrationTest { softwareManagement, distributionSetManagement); targetManagement.createTargets( TestDataUtil.buildTargetFixtures(amountTargetsForRollout, targetPrefixName + "-", targetPrefixName)); - final RolloutGroupConditions conditions = new RolloutGroup.RolloutGroupConditionBuilder() + final RolloutGroupConditions conditions = new JpaRolloutGroup.RolloutGroupConditionBuilder() .successCondition(RolloutGroupSuccessCondition.THRESHOLD, successCondition) .errorCondition(RolloutGroupErrorCondition.THRESHOLD, errorCondition) .errorAction(RolloutGroupErrorAction.PAUSE, null).build(); - Rollout myRollout = new Rollout(); + Rollout myRollout = new JpaRollout(); myRollout.setName(rolloutName); myRollout.setDescription("This is a test description for the rollout"); myRollout.setTargetFilterQuery("controllerId==" + targetPrefixName + "-*"); @@ -933,11 +934,11 @@ public class RolloutManagementTest extends AbstractIntegrationTest { final int amountOtherTargets, final int groupSize, final String successCondition, final String errorCondition) { final SoftwareModule ah = softwareManagement - .createSoftwareModule(new SoftwareModule(appType, "agent-hub", "1.0.1", null, "")); + .createSoftwareModule(new JpaSoftwareModule(appType, "agent-hub", "1.0.1", null, "")); final SoftwareModule jvm = softwareManagement - .createSoftwareModule(new SoftwareModule(runtimeType, "oracle-jre", "1.7.2", null, "")); + .createSoftwareModule(new JpaSoftwareModule(runtimeType, "oracle-jre", "1.7.2", null, "")); final SoftwareModule os = softwareManagement - .createSoftwareModule(new SoftwareModule(osType, "poky", "3.0.2", null, "")); + .createSoftwareModule(new JpaSoftwareModule(osType, "poky", "3.0.2", null, "")); final DistributionSet rolloutDS = distributionSetManagement.createDistributionSet( TestDataUtil.buildDistributionSet("rolloutDS", "0.0.0", standardDsType, os, jvm, ah)); targetManagement @@ -962,11 +963,11 @@ public class RolloutManagementTest extends AbstractIntegrationTest { private Rollout createRolloutByVariables(final String rolloutName, final String rolloutDescription, final int groupSize, final String filterQuery, final DistributionSet distributionSet, final String successCondition, final String errorCondition) { - final RolloutGroupConditions conditions = new RolloutGroup.RolloutGroupConditionBuilder() + final RolloutGroupConditions conditions = new JpaRolloutGroup.RolloutGroupConditionBuilder() .successCondition(RolloutGroupSuccessCondition.THRESHOLD, successCondition) .errorCondition(RolloutGroupErrorCondition.THRESHOLD, errorCondition) .errorAction(RolloutGroupErrorAction.PAUSE, null).build(); - final Rollout rolloutToCreate = new Rollout(); + final Rollout rolloutToCreate = new JpaRollout(); rolloutToCreate.setName(rolloutName); rolloutToCreate.setDescription(rolloutDescription); rolloutToCreate.setTargetFilterQuery(filterQuery); @@ -978,8 +979,8 @@ public class RolloutManagementTest extends AbstractIntegrationTest { final List runningActions = deploymentManagement.findActionsByRolloutAndStatus(rollout, Status.RUNNING); for (final Action action : runningActions) { action.setStatus(status); - controllerManagament - .addUpdateActionStatus(new ActionStatus(action, status, System.currentTimeMillis(), "")); + controllerManagament.addUpdateActionStatus( + new JpaActionStatus((JpaAction) action, status, System.currentTimeMillis(), "")); } return runningActions.size(); } @@ -990,12 +991,12 @@ public class RolloutManagementTest extends AbstractIntegrationTest { assertThat(runningActions.size()).isGreaterThanOrEqualTo(amountOfTargetsToGetChanged); for (int i = 0; i < amountOfTargetsToGetChanged; i++) { controllerManagament.addUpdateActionStatus( - new ActionStatus(runningActions.get(i), status, System.currentTimeMillis(), "")); + new JpaActionStatus((JpaAction) runningActions.get(i), status, System.currentTimeMillis(), "")); } return runningActions.size(); } - private Map createInitStatusMap() { + private static Map createInitStatusMap() { final Map map = new HashMap<>(); for (final TotalTargetCountStatus.Status status : TotalTargetCountStatus.Status.values()) { map.put(status, 0L); diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/SoftwareManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/SoftwareManagementTest.java index 04eccb13e..300fe78dc 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/SoftwareManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/SoftwareManagementTest.java @@ -26,16 +26,22 @@ import org.eclipse.hawkbit.TestDataUtil; import org.eclipse.hawkbit.WithUser; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType; +import org.eclipse.hawkbit.repository.jpa.model.JpaLocalArtifact; +import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; +import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleMetadata; +import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType; +import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; +import org.eclipse.hawkbit.repository.jpa.model.SwMetadataCompositeKey; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.CustomSoftwareModule; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetType; -import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; -import org.eclipse.hawkbit.repository.model.SwMetadataCompositeKey; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; import org.junit.Test; @@ -59,7 +65,7 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { @Description("Try to update non updatable fields results in repository doing nothing.") public void updateTypeNonUpdateableFieldsFails() { final SoftwareModuleType created = softwareManagement - .createSoftwareModuleType(new SoftwareModuleType("test-key", "test-name", "test-desc", 1)); + .createSoftwareModuleType(new JpaSoftwareModuleType("test-key", "test-name", "test-desc", 1)); created.setName("a new name"); final SoftwareModuleType updated = softwareManagement.updateSoftwareModuleType(created); @@ -73,7 +79,7 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { @Description("Calling update without changing fields results in no recorded change in the repository including unchanged audit fields.") public void updateNothingResultsInUnchangedRepositoryForType() { final SoftwareModuleType created = softwareManagement - .createSoftwareModuleType(new SoftwareModuleType("test-key", "test-name", "test-desc", 1)); + .createSoftwareModuleType(new JpaSoftwareModuleType("test-key", "test-name", "test-desc", 1)); final SoftwareModuleType updated = softwareManagement.updateSoftwareModuleType(created); @@ -86,7 +92,7 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { @Description("Calling update for changed fields results in change in the repository.") public void updateSoftareModuleTypeFieldsToNewValue() { final SoftwareModuleType created = softwareManagement - .createSoftwareModuleType(new SoftwareModuleType("test-key", "test-name", "test-desc", 1)); + .createSoftwareModuleType(new JpaSoftwareModuleType("test-key", "test-name", "test-desc", 1)); created.setDescription("changed"); created.setColour("changed"); @@ -103,7 +109,7 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { @Description("Try to update non updatable fields results in repository doing nothing.") public void updateNonUpdateableFieldsFails() { final SoftwareModule ah = softwareManagement - .createSoftwareModule(new SoftwareModule(appType, "agent-hub", "1.0.1", null, "")); + .createSoftwareModule(new JpaSoftwareModule(appType, "agent-hub", "1.0.1", null, "")); ah.setName("a new name"); final SoftwareModule updated = softwareManagement.updateSoftwareModule(ah); @@ -117,7 +123,7 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { @Description("Calling update without changing fields results in no recorded change in the repository including unchanged audit fields.") public void updateNothingResultsInUnchangedRepository() { final SoftwareModule ah = softwareManagement - .createSoftwareModule(new SoftwareModule(appType, "agent-hub", "1.0.1", null, "")); + .createSoftwareModule(new JpaSoftwareModule(appType, "agent-hub", "1.0.1", null, "")); final SoftwareModule updated = softwareManagement.updateSoftwareModule(ah); @@ -130,7 +136,7 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { @Description("Calling update for changed fields results in change in the repository.") public void updateSoftareModuleFieldsToNewValue() { final SoftwareModule ah = softwareManagement - .createSoftwareModule(new SoftwareModule(appType, "agent-hub", "1.0.1", "test desc", "test vendor")); + .createSoftwareModule(new JpaSoftwareModule(appType, "agent-hub", "1.0.1", "test desc", "test vendor")); ah.setDescription("changed"); ah.setVendor("changed"); @@ -146,7 +152,7 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { @Description("Create Software Module call fails when called for existing entity.") public void createModuleCallFailsForExistingModule() { final SoftwareModule ah = softwareManagement - .createSoftwareModule(new SoftwareModule(appType, "agent-hub", "1.0.1", "test desc", "test vendor")); + .createSoftwareModule(new JpaSoftwareModule(appType, "agent-hub", "1.0.1", "test desc", "test vendor")); try { softwareManagement.createSoftwareModule(ah); fail("Should not have worked as module already exists."); @@ -159,8 +165,8 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { @Description("Create Software Modules call fails when called for existing entities.") public void createModulesCallFailsForExistingModule() { final List modules = softwareManagement.createSoftwareModule( - Lists.newArrayList(new SoftwareModule(appType, "agent-hub", "1.0.1", "test desc", "test vendor"), - new SoftwareModule(appType, "agent-hub", "1.0.2", "test desc", "test vendor"))); + Lists.newArrayList(new JpaSoftwareModule(appType, "agent-hub", "1.0.1", "test desc", "test vendor"), + new JpaSoftwareModule(appType, "agent-hub", "1.0.2", "test desc", "test vendor"))); try { softwareManagement.createSoftwareModule(modules); fail("Should not have worked as module already exists."); @@ -173,7 +179,7 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { @Description("Create Software Module Type call fails when called for existing entity.") public void createModuleTypeCallFailsForExistingType() { final SoftwareModuleType created = softwareManagement - .createSoftwareModuleType(new SoftwareModuleType("test-key", "test-name", "test-desc", 1)); + .createSoftwareModuleType(new JpaSoftwareModuleType("test-key", "test-name", "test-desc", 1)); try { softwareManagement.createSoftwareModuleType(created); @@ -187,8 +193,8 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { @Description("Create Software Module Types call fails when called for existing entities.") public void createModuleTypesCallFailsForExistingTypes() { final List created = softwareManagement.createSoftwareModuleType( - Lists.newArrayList(new SoftwareModuleType("test-key-bumlux", "test-name", "test-desc", 1), - new SoftwareModuleType("test-key-bumlux2", "test-name2", "test-desc", 1))); + Lists.newArrayList(new JpaSoftwareModuleType("test-key-bumlux", "test-name", "test-desc", 1), + new JpaSoftwareModuleType("test-key-bumlux2", "test-name2", "test-desc", 1))); try { softwareManagement.createSoftwareModuleType(created); @@ -202,7 +208,7 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { @Description("Calling update for changing fields to null results in change in the repository.") public void eraseSoftareModuleFields() { final SoftwareModule ah = softwareManagement - .createSoftwareModule(new SoftwareModule(appType, "agent-hub", "1.0.1", "test desc", "test vendor")); + .createSoftwareModule(new JpaSoftwareModule(appType, "agent-hub", "1.0.1", "test desc", "test vendor")); ah.setDescription(null); ah.setVendor(null); @@ -218,19 +224,19 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { @Description("searched for software modules based on the various filter options, e.g. name,desc,type, version.") public void findSoftwareModuleByFilters() { final SoftwareModule ah = softwareManagement - .createSoftwareModule(new SoftwareModule(appType, "agent-hub", "1.0.1", null, "")); + .createSoftwareModule(new JpaSoftwareModule(appType, "agent-hub", "1.0.1", null, "")); final SoftwareModule jvm = softwareManagement - .createSoftwareModule(new SoftwareModule(runtimeType, "oracle-jre", "1.7.2", null, "")); + .createSoftwareModule(new JpaSoftwareModule(runtimeType, "oracle-jre", "1.7.2", null, "")); final SoftwareModule os = softwareManagement - .createSoftwareModule(new SoftwareModule(osType, "poky", "3.0.2", null, "")); + .createSoftwareModule(new JpaSoftwareModule(osType, "poky", "3.0.2", null, "")); final SoftwareModule ah2 = softwareManagement - .createSoftwareModule(new SoftwareModule(appType, "agent-hub", "1.0.2", null, "")); - DistributionSet ds = distributionSetManagement.createDistributionSet( + .createSoftwareModule(new JpaSoftwareModule(appType, "agent-hub", "1.0.2", null, "")); + JpaDistributionSet ds = (JpaDistributionSet) distributionSetManagement.createDistributionSet( TestDataUtil.buildDistributionSet("ds-1", "1.0.1", standardDsType, os, jvm, ah2)); - final Target target = targetManagement.createTarget(new Target("test123")); - ds = assignSet(target, ds).getDistributionSet(); + final JpaTarget target = (JpaTarget) targetManagement.createTarget(new JpaTarget("test123")); + ds = (JpaDistributionSet) assignSet(target, ds).getDistributionSet(); // standard searches assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "poky", osType).getContent()).hasSize(1); @@ -254,7 +260,7 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { .isEqualTo(ah); } - private Action assignSet(final Target target, final DistributionSet ds) { + private Action assignSet(final JpaTarget target, final JpaDistributionSet ds) { deploymentManagement.assignDistributionSet(ds.getId(), new String[] { target.getControllerId() }); assertThat( targetManagement.findTargetByControllerID(target.getControllerId()).getTargetInfo().getUpdateStatus()) @@ -272,10 +278,10 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { final List modules = new ArrayList<>(); - modules.add(softwareManagement.createSoftwareModule(new SoftwareModule(osType, "poky-una", "3.0.2", null, "")) - .getId()); - modules.add(softwareManagement.createSoftwareModule(new SoftwareModule(osType, "poky-u2na", "3.0.3", null, "")) - .getId()); + modules.add(softwareManagement + .createSoftwareModule(new JpaSoftwareModule(osType, "poky-una", "3.0.2", null, "")).getId()); + modules.add(softwareManagement + .createSoftwareModule(new JpaSoftwareModule(osType, "poky-u2na", "3.0.3", null, "")).getId()); modules.add(624355263L); assertThat(softwareManagement.findSoftwareModulesById(modules)).hasSize(2); @@ -286,13 +292,13 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { public void findSoftwareModulesByType() { // found in test final SoftwareModule one = softwareManagement - .createSoftwareModule(new SoftwareModule(osType, "one", "one", null, "")); + .createSoftwareModule(new JpaSoftwareModule(osType, "one", "one", null, "")); final SoftwareModule two = softwareManagement - .createSoftwareModule(new SoftwareModule(osType, "two", "two", null, "")); + .createSoftwareModule(new JpaSoftwareModule(osType, "two", "two", null, "")); // ignored softwareManagement.deleteSoftwareModule( - softwareManagement.createSoftwareModule(new SoftwareModule(osType, "deleted", "deleted", null, ""))); - softwareManagement.createSoftwareModule(new SoftwareModule(appType, "three", "3.0.2", null, "")); + softwareManagement.createSoftwareModule(new JpaSoftwareModule(osType, "deleted", "deleted", null, ""))); + softwareManagement.createSoftwareModule(new JpaSoftwareModule(appType, "three", "3.0.2", null, "")); assertThat(softwareManagement.findSoftwareModulesByType(pageReq, osType).getContent()) .as("Expected to find the following number of modules:").hasSize(2).as("with the following elements") @@ -303,11 +309,11 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { @Description("Counts all software modules in the repsitory that are not marked as deleted.") public void countSoftwareModulesAll() { // found in test - softwareManagement.createSoftwareModule(new SoftwareModule(osType, "one", "one", null, "")); - softwareManagement.createSoftwareModule(new SoftwareModule(appType, "two", "two", null, "")); + softwareManagement.createSoftwareModule(new JpaSoftwareModule(osType, "one", "one", null, "")); + softwareManagement.createSoftwareModule(new JpaSoftwareModule(appType, "two", "two", null, "")); // ignored softwareManagement.deleteSoftwareModule( - softwareManagement.createSoftwareModule(new SoftwareModule(osType, "deleted", "deleted", null, ""))); + softwareManagement.createSoftwareModule(new JpaSoftwareModule(osType, "deleted", "deleted", null, ""))); assertThat(softwareManagement.countSoftwareModulesAll()).as("Expected to find the following number of modules:") .isEqualTo(2); @@ -317,13 +323,13 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { @Description("Counts for software modules by type.") public void countSoftwareModulesByType() { // found in test - softwareManagement.createSoftwareModule(new SoftwareModule(osType, "one", "one", null, "")); - softwareManagement.createSoftwareModule(new SoftwareModule(osType, "two", "two", null, "")); + softwareManagement.createSoftwareModule(new JpaSoftwareModule(osType, "one", "one", null, "")); + softwareManagement.createSoftwareModule(new JpaSoftwareModule(osType, "two", "two", null, "")); // ignored softwareManagement.deleteSoftwareModule( - softwareManagement.createSoftwareModule(new SoftwareModule(osType, "deleted", "deleted", null, ""))); - softwareManagement.createSoftwareModule(new SoftwareModule(appType, "three", "3.0.2", null, "")); + softwareManagement.createSoftwareModule(new JpaSoftwareModule(osType, "deleted", "deleted", null, ""))); + softwareManagement.createSoftwareModule(new JpaSoftwareModule(appType, "three", "3.0.2", null, "")); assertThat(softwareManagement.countSoftwareModulesByType(osType)) .as("Expected to find the following number of modules:").isEqualTo(2); @@ -336,7 +342,7 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { appType); SoftwareModuleType type = softwareManagement.createSoftwareModuleType( - new SoftwareModuleType("bundle", "OSGi Bundle", "fancy stuff", Integer.MAX_VALUE)); + new JpaSoftwareModuleType("bundle", "OSGi Bundle", "fancy stuff", Integer.MAX_VALUE)); assertThat(softwareManagement.findSoftwareModuleTypesAll(pageReq)).hasSize(4).contains(osType, runtimeType, appType, type); @@ -345,23 +351,25 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { softwareManagement.deleteSoftwareModuleType(type); assertThat(softwareManagement.findSoftwareModuleTypesAll(pageReq)).hasSize(3).contains(osType, runtimeType, appType); - assertThat(softwareModuleTypeRepository.findAll()).hasSize(3).contains(osType, runtimeType, appType); + assertThat(softwareModuleTypeRepository.findAll()).hasSize(3).contains((JpaSoftwareModuleType) osType, + (JpaSoftwareModuleType) runtimeType, (JpaSoftwareModuleType) appType); type = softwareManagement.createSoftwareModuleType( - new SoftwareModuleType("bundle2", "OSGi Bundle2", "fancy stuff", Integer.MAX_VALUE)); + new JpaSoftwareModuleType("bundle2", "OSGi Bundle2", "fancy stuff", Integer.MAX_VALUE)); assertThat(softwareManagement.findSoftwareModuleTypesAll(pageReq)).hasSize(4).contains(osType, runtimeType, appType, type); softwareManagement - .createSoftwareModule(new SoftwareModule(type, "Test SM", "1.0", "cool module", "from meeee")); + .createSoftwareModule(new JpaSoftwareModule(type, "Test SM", "1.0", "cool module", "from meeee")); // delete assigned softwareManagement.deleteSoftwareModuleType(type); assertThat(softwareManagement.findSoftwareModuleTypesAll(pageReq)).hasSize(3).contains(osType, runtimeType, appType); - assertThat(softwareModuleTypeRepository.findAll()).hasSize(4).contains(osType, runtimeType, appType, + assertThat(softwareModuleTypeRepository.findAll()).hasSize(4).contains((JpaSoftwareModuleType) osType, + (JpaSoftwareModuleType) runtimeType, (JpaSoftwareModuleType) appType, softwareModuleTypeRepository.findOne(type.getId())); } @@ -397,7 +405,7 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { // Init DistributionSet final DistributionSet disSet = distributionSetManagement - .createDistributionSet(new DistributionSet("ds1", "v1.0", "test ds", standardDsType, null)); + .createDistributionSet(new JpaDistributionSet("ds1", "v1.0", "test ds", standardDsType, null)); // [STEP1]: Create SoftwareModuleX with ArtifactX SoftwareModule assignedModule = createSoftwareModuleWithArtifacts(osType, "moduleX", "3.0.2", 2); @@ -431,9 +439,9 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { public void softDeleteOfHistoricalAssignedArtifact() { // Init target and DistributionSet - final Target target = targetManagement.createTarget(new Target("test123")); + final Target target = targetManagement.createTarget(new JpaTarget("test123")); final DistributionSet disSet = distributionSetManagement - .createDistributionSet(new DistributionSet("ds1", "v1.0", "test ds", standardDsType, null)); + .createDistributionSet(new JpaDistributionSet("ds1", "v1.0", "test ds", standardDsType, null)); // [STEP1]: Create SoftwareModuleX and include the new ArtifactX SoftwareModule assignedModule = createSoftwareModuleWithArtifacts(osType, "moduleX", "3.0.2", 2); @@ -525,11 +533,11 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { // Init artifact binary data, target and DistributionSets final byte[] source = RandomUtils.nextBytes(1024); - final Target target = targetManagement.createTarget(new Target("test123")); + final Target target = targetManagement.createTarget(new JpaTarget("test123")); final DistributionSet disSetX = distributionSetManagement - .createDistributionSet(new DistributionSet("dsX", "v1.0", "test dsX", standardDsType, null)); + .createDistributionSet(new JpaDistributionSet("dsX", "v1.0", "test dsX", standardDsType, null)); final DistributionSet disSetY = distributionSetManagement - .createDistributionSet(new DistributionSet("dsY", "v1.0", "test dsY", standardDsType, null)); + .createDistributionSet(new JpaDistributionSet("dsY", "v1.0", "test dsY", standardDsType, null)); // [STEP1]: Create SoftwareModuleX and add a new ArtifactX SoftwareModule moduleX = createSoftwareModuleWithArtifacts(osType, "modulex", "v1.0", 0); @@ -587,8 +595,8 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { final long countSoftwareModule = softwareModuleRepository.count(); // create SoftwareModule - SoftwareModule softwareModule = softwareManagement - .createSoftwareModule(new SoftwareModule(type, name, version, "description of artifact " + name, "")); + SoftwareModule softwareModule = softwareManagement.createSoftwareModule( + new JpaSoftwareModule(type, name, version, "description of artifact " + name, "")); for (int i = 0; i < numberArtifacts; i++) { artifactManagement.createLocalArtifact(new RandomGeneratedInputStream(5 * 1024), softwareModule.getId(), @@ -617,7 +625,7 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { for (final Artifact result : results) { assertThat(result.getId()).isNotNull(); assertThat(operations.findOne(new Query() - .addCriteria(Criteria.where("filename").is(((LocalArtifact) result).getGridFsFileName())))) + .addCriteria(Criteria.where("filename").is(((JpaLocalArtifact) result).getGridFsFileName())))) .isNotNull(); } } @@ -625,7 +633,7 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { private void assertArtfiactNull(final Artifact... results) { for (final Artifact result : results) { assertThat(operations.findOne(new Query() - .addCriteria(Criteria.where("filename").is(((LocalArtifact) result).getGridFsFileName())))) + .addCriteria(Criteria.where("filename").is(((JpaLocalArtifact) result).getGridFsFileName())))) .isNull(); } } @@ -635,28 +643,28 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { public void findSoftwareModuleOrderByDistributionModuleNameAscModuleVersionAsc() { // test meta data final SoftwareModuleType testType = softwareManagement - .createSoftwareModuleType(new SoftwareModuleType("thetype", "thename", "desc", 100)); + .createSoftwareModuleType(new JpaSoftwareModuleType("thetype", "thename", "desc", 100)); final DistributionSetType testDsType = distributionSetManagement - .createDistributionSetType(new DistributionSetType("key", "name", "desc").addMandatoryModuleType(osType) - .addOptionalModuleType(testType)); + .createDistributionSetType(new JpaDistributionSetType("key", "name", "desc") + .addMandatoryModuleType(osType).addOptionalModuleType(testType)); // found in test final SoftwareModule unassigned = softwareManagement - .createSoftwareModule(new SoftwareModule(testType, "asis", "found", null, "")); + .createSoftwareModule(new JpaSoftwareModule(testType, "asis", "found", null, "")); final SoftwareModule one = softwareManagement - .createSoftwareModule(new SoftwareModule(testType, "found", "b", null, "")); + .createSoftwareModule(new JpaSoftwareModule(testType, "found", "b", null, "")); final SoftwareModule two = softwareManagement - .createSoftwareModule(new SoftwareModule(testType, "found", "c", null, "")); + .createSoftwareModule(new JpaSoftwareModule(testType, "found", "c", null, "")); final SoftwareModule differentName = softwareManagement - .createSoftwareModule(new SoftwareModule(testType, "differentname", "d", null, "")); + .createSoftwareModule(new JpaSoftwareModule(testType, "differentname", "d", null, "")); // ignored final SoftwareModule deleted = softwareManagement - .createSoftwareModule(new SoftwareModule(testType, "deleted", "deleted", null, "")); + .createSoftwareModule(new JpaSoftwareModule(testType, "deleted", "deleted", null, "")); final SoftwareModule four = softwareManagement - .createSoftwareModule(new SoftwareModule(osType, "sdfjhsdj", "e", null, "")); + .createSoftwareModule(new JpaSoftwareModule(osType, "sdfjhsdj", "e", null, "")); - final DistributionSet set = distributionSetManagement.createDistributionSet(new DistributionSet("set", "1", + final DistributionSet set = distributionSetManagement.createDistributionSet(new JpaDistributionSet("set", "1", "desc", testDsType, Lists.newArrayList(one, two, deleted, four, differentName))); softwareManagement.deleteSoftwareModule(deleted); @@ -688,26 +696,26 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { // test meta data final SoftwareModuleType testType = softwareManagement - .createSoftwareModuleType(new SoftwareModuleType("thetype", "thename", "desc", 100)); + .createSoftwareModuleType(new JpaSoftwareModuleType("thetype", "thename", "desc", 100)); final DistributionSetType testDsType = distributionSetManagement - .createDistributionSetType(new DistributionSetType("key", "name", "desc").addMandatoryModuleType(osType) - .addOptionalModuleType(testType)); + .createDistributionSetType(new JpaDistributionSetType("key", "name", "desc") + .addMandatoryModuleType(osType).addOptionalModuleType(testType)); // test modules - softwareManagement.createSoftwareModule(new SoftwareModule(testType, "asis", "found", null, "")); + softwareManagement.createSoftwareModule(new JpaSoftwareModule(testType, "asis", "found", null, "")); final SoftwareModule one = softwareManagement - .createSoftwareModule(new SoftwareModule(testType, "found", "b", null, "")); + .createSoftwareModule(new JpaSoftwareModule(testType, "found", "b", null, "")); final SoftwareModule two = softwareManagement - .createSoftwareModule(new SoftwareModule(testType, "found", "c", null, "")); + .createSoftwareModule(new JpaSoftwareModule(testType, "found", "c", null, "")); final SoftwareModule differentName = softwareManagement - .createSoftwareModule(new SoftwareModule(testType, "differentname", "d", null, "")); + .createSoftwareModule(new JpaSoftwareModule(testType, "differentname", "d", null, "")); final SoftwareModule four = softwareManagement - .createSoftwareModule(new SoftwareModule(osType, "found", "3.0.2", null, "")); + .createSoftwareModule(new JpaSoftwareModule(osType, "found", "3.0.2", null, "")); // one soft deleted final SoftwareModule deleted = softwareManagement - .createSoftwareModule(new SoftwareModule(testType, "deleted", "deleted", null, "")); - distributionSetManagement.createDistributionSet(new DistributionSet("set", "1", "desc", testDsType, + .createSoftwareModule(new JpaSoftwareModule(testType, "deleted", "deleted", null, "")); + distributionSetManagement.createDistributionSet(new JpaDistributionSet("set", "1", "desc", testDsType, Lists.newArrayList(one, two, deleted, four, differentName))); softwareManagement.deleteSoftwareModule(deleted); @@ -724,18 +732,18 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { @Description("Verfies that all undeleted software modules are found in the repository.") public void countSoftwareModuleTypesAll() { final SoftwareModuleType testType = softwareManagement - .createSoftwareModuleType(new SoftwareModuleType("thetype", "thename", "desc", 100)); + .createSoftwareModuleType(new JpaSoftwareModuleType("thetype", "thename", "desc", 100)); final DistributionSetType testDsType = distributionSetManagement - .createDistributionSetType(new DistributionSetType("key", "name", "desc").addMandatoryModuleType(osType) - .addOptionalModuleType(testType)); + .createDistributionSetType(new JpaDistributionSetType("key", "name", "desc") + .addMandatoryModuleType(osType).addOptionalModuleType(testType)); final SoftwareModule four = softwareManagement - .createSoftwareModule(new SoftwareModule(osType, "found", "3.0.2", null, "")); + .createSoftwareModule(new JpaSoftwareModule(osType, "found", "3.0.2", null, "")); // one soft deleted final SoftwareModule deleted = softwareManagement - .createSoftwareModule(new SoftwareModule(testType, "deleted", "deleted", null, "")); + .createSoftwareModule(new JpaSoftwareModule(testType, "deleted", "deleted", null, "")); distributionSetManagement.createDistributionSet( - new DistributionSet("set", "1", "desc", testDsType, Lists.newArrayList(deleted, four))); + new JpaDistributionSet("set", "1", "desc", testDsType, Lists.newArrayList(deleted, four))); softwareManagement.deleteSoftwareModule(deleted); assertThat(softwareManagement.countSoftwareModulesAll()).as("Number of undeleted modules").isEqualTo(1); @@ -746,8 +754,8 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { @Description("Checks that software module typeis found based on given name.") public void findSoftwareModuleTypeByName() { final SoftwareModuleType found = softwareManagement - .createSoftwareModuleType(new SoftwareModuleType("thetype", "thename", "desc", 100)); - softwareManagement.createSoftwareModuleType(new SoftwareModuleType("thetype2", "anothername", "desc", 100)); + .createSoftwareModuleType(new JpaSoftwareModuleType("thetype", "thename", "desc", 100)); + softwareManagement.createSoftwareModuleType(new JpaSoftwareModuleType("thetype2", "anothername", "desc", 100)); assertThat(softwareManagement.findSoftwareModuleTypeByName("thename")).as("Type with given name") .isEqualTo(found); @@ -757,7 +765,7 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { @Description("Verfies that it is not possible to create a type that alrady exists.") public void createSoftwareModuleTypeFailsWithExistingEntity() { final SoftwareModuleType created = softwareManagement - .createSoftwareModuleType(new SoftwareModuleType("thetype", "thename", "desc", 100)); + .createSoftwareModuleType(new JpaSoftwareModuleType("thetype", "thename", "desc", 100)); try { softwareManagement.createSoftwareModuleType(created); fail("should not have worked as module type already exists"); @@ -771,10 +779,10 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { @Description("Verfies that it is not possible to create a list of types where one already exists.") public void createSoftwareModuleTypesFailsWithExistingEntity() { final SoftwareModuleType created = softwareManagement - .createSoftwareModuleType(new SoftwareModuleType("thetype", "thename", "desc", 100)); + .createSoftwareModuleType(new JpaSoftwareModuleType("thetype", "thename", "desc", 100)); try { softwareManagement.createSoftwareModuleType( - Lists.newArrayList(created, new SoftwareModuleType("anothertype", "anothername", "desc", 100))); + Lists.newArrayList(created, new JpaSoftwareModuleType("anothertype", "anothername", "desc", 100))); fail("should not have worked as module type already exists"); } catch (final EntityAlreadyExistsException e) { @@ -784,9 +792,9 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { @Test @Description("Verfies that multiple types are created as requested.") public void createMultipleoftwareModuleTypes() { - final List created = softwareManagement - .createSoftwareModuleType(Lists.newArrayList(new SoftwareModuleType("thetype", "thename", "desc", 100), - new SoftwareModuleType("thetype2", "thename2", "desc2", 100))); + final List created = softwareManagement.createSoftwareModuleType( + Lists.newArrayList(new JpaSoftwareModuleType("thetype", "thename", "desc", 100), + new JpaSoftwareModuleType("thetype2", "thename2", "desc2", 100))); assertThat(created.size()).as("Number of created types").isEqualTo(2); assertThat(softwareManagement.countSoftwareModuleTypesAll()).as("Number of types in repository").isEqualTo(5); @@ -797,23 +805,23 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { public void findSoftwareModuleByAssignedTo() { // test meta data final SoftwareModuleType testType = softwareManagement - .createSoftwareModuleType(new SoftwareModuleType("thetype", "thename", "desc", 100)); + .createSoftwareModuleType(new JpaSoftwareModuleType("thetype", "thename", "desc", 100)); final DistributionSetType testDsType = distributionSetManagement - .createDistributionSetType(new DistributionSetType("key", "name", "desc").addMandatoryModuleType(osType) - .addOptionalModuleType(testType)); + .createDistributionSetType(new JpaDistributionSetType("key", "name", "desc") + .addMandatoryModuleType(osType).addOptionalModuleType(testType)); // test modules - softwareManagement.createSoftwareModule(new SoftwareModule(testType, "asis", "found", null, "")); + softwareManagement.createSoftwareModule(new JpaSoftwareModule(testType, "asis", "found", null, "")); final SoftwareModule one = softwareManagement - .createSoftwareModule(new SoftwareModule(testType, "found", "b", null, "")); + .createSoftwareModule(new JpaSoftwareModule(testType, "found", "b", null, "")); final SoftwareModule two = softwareManagement - .createSoftwareModule(new SoftwareModule(testType, "found", "c", null, "")); + .createSoftwareModule(new JpaSoftwareModule(testType, "found", "c", null, "")); // one soft deleted final SoftwareModule deleted = softwareManagement - .createSoftwareModule(new SoftwareModule(testType, "deleted", "deleted", null, "")); + .createSoftwareModule(new JpaSoftwareModule(testType, "deleted", "deleted", null, "")); final DistributionSet set = distributionSetManagement.createDistributionSet( - new DistributionSet("set", "1", "desc", testDsType, Lists.newArrayList(one, deleted))); + new JpaDistributionSet("set", "1", "desc", testDsType, Lists.newArrayList(one, deleted))); softwareManagement.deleteSoftwareModule(deleted); assertThat(softwareManagement.findSoftwareModuleByAssignedTo(pageReq, set).getContent()) @@ -831,13 +839,13 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { final String knownValue2 = "myKnownValue2"; final SoftwareModule ah = softwareManagement - .createSoftwareModule(new SoftwareModule(appType, "agent-hub", "1.0.1", null, "")); + .createSoftwareModule(new JpaSoftwareModule(appType, "agent-hub", "1.0.1", null, "")); assertThat(ah.getOptLockRevision()).isEqualTo(1L); - final SoftwareModuleMetadata swMetadata1 = new SoftwareModuleMetadata(knownKey1, ah, knownValue1); + final SoftwareModuleMetadata swMetadata1 = new JpaSoftwareModuleMetadata(knownKey1, ah, knownValue1); - final SoftwareModuleMetadata swMetadata2 = new SoftwareModuleMetadata(knownKey2, ah, knownValue2); + final SoftwareModuleMetadata swMetadata2 = new JpaSoftwareModuleMetadata(knownKey2, ah, knownValue2); final List softwareModuleMetadata = softwareManagement .createSoftwareModuleMetadata(Lists.newArrayList(swMetadata1, swMetadata2)); @@ -848,7 +856,7 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { assertThat(softwareModuleMetadata).hasSize(2); assertThat(softwareModuleMetadata.get(0)).isNotNull(); assertThat(softwareModuleMetadata.get(0).getValue()).isEqualTo(knownValue1); - assertThat(softwareModuleMetadata.get(0).getId().getKey()).isEqualTo(knownKey1); + assertThat(((JpaSoftwareModuleMetadata) softwareModuleMetadata.get(0)).getId().getKey()).isEqualTo(knownKey1); assertThat(softwareModuleMetadata.get(0).getSoftwareModule().getId()).isEqualTo(ah.getId()); } @@ -861,12 +869,12 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { final String knownValue2 = "myKnownValue2"; final SoftwareModule ah = softwareManagement - .createSoftwareModule(new SoftwareModule(appType, "agent-hub", "1.0.1", null, "")); + .createSoftwareModule(new JpaSoftwareModule(appType, "agent-hub", "1.0.1", null, "")); - softwareManagement.createSoftwareModuleMetadata(new SoftwareModuleMetadata(knownKey1, ah, knownValue1)); + softwareManagement.createSoftwareModuleMetadata(new JpaSoftwareModuleMetadata(knownKey1, ah, knownValue1)); try { - softwareManagement.createSoftwareModuleMetadata(new SoftwareModuleMetadata(knownKey1, ah, knownValue2)); + softwareManagement.createSoftwareModuleMetadata(new JpaSoftwareModuleMetadata(knownKey1, ah, knownValue2)); fail("should not have worked as module metadata already exists"); } catch (final EntityAlreadyExistsException e) { @@ -883,13 +891,13 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { // create a base software module final SoftwareModule ah = softwareManagement - .createSoftwareModule(new SoftwareModule(appType, "agent-hub", "1.0.1", null, "")); + .createSoftwareModule(new JpaSoftwareModule(appType, "agent-hub", "1.0.1", null, "")); // initial opt lock revision must be 1 assertThat(ah.getOptLockRevision()).isEqualTo(1L); // create an software module meta data entry final List softwareModuleMetadata = softwareManagement.createSoftwareModuleMetadata( - Collections.singleton(new SoftwareModuleMetadata(knownKey, ah, knownValue))); + Collections.singleton(new JpaSoftwareModuleMetadata(knownKey, ah, knownValue))); assertThat(softwareModuleMetadata).hasSize(1); // base software module should have now the opt lock revision one // because we are modifying the @@ -915,7 +923,7 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { // verify updated meta data contains the updated value assertThat(updated).isNotNull(); assertThat(updated.getValue()).isEqualTo(knownUpdateValue); - assertThat(updated.getId().getKey()).isEqualTo(knownKey); + assertThat(((JpaSoftwareModuleMetadata) updated).getId().getKey()).isEqualTo(knownKey); assertThat(updated.getSoftwareModule().getId()).isEqualTo(ah.getId()); } @@ -926,14 +934,14 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { final String knownValue1 = "myKnownValue1"; SoftwareModule ah = softwareManagement - .createSoftwareModule(new SoftwareModule(appType, "agent-hub", "1.0.1", null, "")); + .createSoftwareModule(new JpaSoftwareModule(appType, "agent-hub", "1.0.1", null, "")); - ah = softwareManagement.createSoftwareModuleMetadata(new SoftwareModuleMetadata(knownKey1, ah, knownValue1)) + ah = softwareManagement.createSoftwareModuleMetadata(new JpaSoftwareModuleMetadata(knownKey1, ah, knownValue1)) .getSoftwareModule(); assertThat(softwareManagement.findSoftwareModuleById(ah.getId()).getMetadata()) .as("Contains the created metadata element") - .containsExactly(new SoftwareModuleMetadata(knownKey1, ah, knownValue1)); + .containsExactly(new JpaSoftwareModuleMetadata(knownKey1, ah, knownValue1)); softwareManagement.deleteSoftwareModuleMetadata(new SwMetadataCompositeKey(ah, knownKey1)); assertThat(softwareManagement.findSoftwareModuleById(ah.getId()).getMetadata()).as("Metadata elemenets are") @@ -947,9 +955,9 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { final String knownValue1 = "myKnownValue1"; SoftwareModule ah = softwareManagement - .createSoftwareModule(new SoftwareModule(appType, "agent-hub", "1.0.1", null, "")); + .createSoftwareModule(new JpaSoftwareModule(appType, "agent-hub", "1.0.1", null, "")); - ah = softwareManagement.createSoftwareModuleMetadata(new SoftwareModuleMetadata(knownKey1, ah, knownValue1)) + ah = softwareManagement.createSoftwareModuleMetadata(new JpaSoftwareModuleMetadata(knownKey1, ah, knownValue1)) .getSoftwareModule(); try { @@ -965,20 +973,20 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { public void findAllSoftwareModuleMetadataBySwId() { SoftwareModule sw1 = softwareManagement - .createSoftwareModule(new SoftwareModule(appType, "agent-hub", "1.0.1", null, "")); + .createSoftwareModule(new JpaSoftwareModule(appType, "agent-hub", "1.0.1", null, "")); SoftwareModule sw2 = softwareManagement - .createSoftwareModule(new SoftwareModule(osType, "os", "1.0.1", null, "")); + .createSoftwareModule(new JpaSoftwareModule(osType, "os", "1.0.1", null, "")); for (int index = 0; index < 10; index++) { sw1 = softwareManagement - .createSoftwareModuleMetadata(new SoftwareModuleMetadata("key" + index, sw1, "value" + index)) + .createSoftwareModuleMetadata(new JpaSoftwareModuleMetadata("key" + index, sw1, "value" + index)) .getSoftwareModule(); } for (int index = 0; index < 20; index++) { sw2 = softwareManagement - .createSoftwareModuleMetadata(new SoftwareModuleMetadata("key" + index, sw2, "value" + index)) + .createSoftwareModuleMetadata(new JpaSoftwareModuleMetadata("key" + index, sw2, "value" + index)) .getSoftwareModule(); } diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/SystemManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/SystemManagementTest.java index 1a1632d32..261b921c8 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/SystemManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/SystemManagementTest.java @@ -18,8 +18,8 @@ import org.eclipse.hawkbit.AbstractIntegrationTestWithMongoDB; import org.eclipse.hawkbit.TestDataUtil; import org.eclipse.hawkbit.WithSpringAuthorityRule; import org.eclipse.hawkbit.report.model.TenantUsage; +import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; import org.eclipse.hawkbit.repository.model.DistributionSet; -import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.Target; import org.junit.Test; @@ -132,7 +132,7 @@ public class SystemManagementTest extends AbstractIntegrationTestWithMongoDB { } private void createTestArtifact(final byte[] random) { - SoftwareModule sm = new SoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1", + JpaSoftwareModule sm = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1", "version 1", null, null); sm = softwareModuleRepository.save(sm); diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TagManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TagManagementTest.java index 4c6af0d83..66ea38e77 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TagManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TagManagementTest.java @@ -14,6 +14,7 @@ import static org.junit.Assert.fail; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.List; import java.util.stream.Collectors; @@ -21,6 +22,8 @@ import org.eclipse.hawkbit.AbstractIntegrationTest; import org.eclipse.hawkbit.TestDataUtil; import org.eclipse.hawkbit.repository.DistributionSetFilter.DistributionSetFilterBuilder; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag; +import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult; @@ -57,26 +60,26 @@ public class TagManagementTest extends AbstractIntegrationTest { @Test @Description("Full DS tag lifecycle tested. Create tags, assign them to sets and delete the tags.") public void createAndAssignAndDeleteDistributionSetTags() { - final List dsAs = TestDataUtil.generateDistributionSets("DS-A", 20, softwareManagement, - distributionSetManagement); - final List dsBs = TestDataUtil.generateDistributionSets("DS-B", 10, softwareManagement, - distributionSetManagement); - final List dsCs = TestDataUtil.generateDistributionSets("DS-C", 25, softwareManagement, - distributionSetManagement); - final List dsABs = TestDataUtil.generateDistributionSets("DS-AB", 5, softwareManagement, - distributionSetManagement); - final List dsACs = TestDataUtil.generateDistributionSets("DS-AC", 11, softwareManagement, - distributionSetManagement); - final List dsBCs = TestDataUtil.generateDistributionSets("DS-BC", 13, softwareManagement, - distributionSetManagement); - final List dsABCs = TestDataUtil.generateDistributionSets("DS-ABC", 9, softwareManagement, - distributionSetManagement); + final Collection dsAs = (Collection) TestDataUtil.generateDistributionSets("DS-A", 20, + softwareManagement, distributionSetManagement); + final Collection dsBs = (Collection) TestDataUtil.generateDistributionSets("DS-B", 10, + softwareManagement, distributionSetManagement); + final Collection dsCs = (Collection) TestDataUtil.generateDistributionSets("DS-C", 25, + softwareManagement, distributionSetManagement); + final Collection dsABs = (Collection) TestDataUtil.generateDistributionSets("DS-AB", 5, + softwareManagement, distributionSetManagement); + final Collection dsACs = (Collection) TestDataUtil.generateDistributionSets("DS-AC", 11, + softwareManagement, distributionSetManagement); + final Collection dsBCs = (Collection) TestDataUtil.generateDistributionSets("DS-BC", 13, + softwareManagement, distributionSetManagement); + final Collection dsABCs = (Collection) TestDataUtil.generateDistributionSets("DS-ABC", 9, + softwareManagement, distributionSetManagement); - final DistributionSetTag tagA = tagManagement.createDistributionSetTag(new DistributionSetTag("A")); - final DistributionSetTag tagB = tagManagement.createDistributionSetTag(new DistributionSetTag("B")); - final DistributionSetTag tagC = tagManagement.createDistributionSetTag(new DistributionSetTag("C")); - final DistributionSetTag tagX = tagManagement.createDistributionSetTag(new DistributionSetTag("X")); - final DistributionSetTag tagY = tagManagement.createDistributionSetTag(new DistributionSetTag("Y")); + final DistributionSetTag tagA = tagManagement.createDistributionSetTag(new JpaDistributionSetTag("A")); + final DistributionSetTag tagB = tagManagement.createDistributionSetTag(new JpaDistributionSetTag("B")); + final DistributionSetTag tagC = tagManagement.createDistributionSetTag(new JpaDistributionSetTag("C")); + final DistributionSetTag tagX = tagManagement.createDistributionSetTag(new JpaDistributionSetTag("X")); + final DistributionSetTag tagY = tagManagement.createDistributionSetTag(new JpaDistributionSetTag("Y")); distributionSetManagement.toggleTagAssignment(dsAs, tagA); distributionSetManagement.toggleTagAssignment(dsBs, tagB); @@ -167,20 +170,20 @@ public class TagManagementTest extends AbstractIntegrationTest { @Description("Verifies the toogle mechanism by means on assigning tag if at least on DS in the list does not have" + "the tag yet. Unassign if all of them have the tag already.") public void assignAndUnassignDistributionSetTags() { - final List groupA = TestDataUtil.generateDistributionSets(20, softwareManagement, - distributionSetManagement); - final List groupB = TestDataUtil.generateDistributionSets("unassigned", 20, softwareManagement, - distributionSetManagement); + final Collection groupA = (Collection) TestDataUtil.generateDistributionSets(20, + softwareManagement, distributionSetManagement); + final Collection groupB = (Collection) TestDataUtil.generateDistributionSets("unassigned", 20, + softwareManagement, distributionSetManagement); final DistributionSetTag tag = tagManagement - .createDistributionSetTag(new DistributionSetTag("tag1", "tagdesc1", "")); + .createDistributionSetTag(new JpaDistributionSetTag("tag1", "tagdesc1", "")); // toggle A only -> A is now assigned DistributionSetTagAssignmentResult result = distributionSetManagement.toggleTagAssignment(groupA, tag); assertThat(result.getAlreadyAssigned()).isEqualTo(0); assertThat(result.getAssigned()).isEqualTo(20); - assertThat(result.getAssignedEntity()).containsAll(distributionSetManagement.findDistributionSetListWithDetails( - groupA.stream().map(set -> set.getId()).collect(Collectors.toList()))); + assertThat(result.getAssignedEntity()).containsAll(distributionSetManagement + .findDistributionSetsAll(groupA.stream().map(set -> set.getId()).collect(Collectors.toList()))); assertThat(result.getUnassigned()).isEqualTo(0); assertThat(result.getUnassignedEntity()).isEmpty(); assertThat(result.getDistributionSetTag()).isEqualTo(tag); @@ -189,8 +192,8 @@ public class TagManagementTest extends AbstractIntegrationTest { result = distributionSetManagement.toggleTagAssignment(concat(groupA, groupB), tag); assertThat(result.getAlreadyAssigned()).isEqualTo(20); assertThat(result.getAssigned()).isEqualTo(20); - assertThat(result.getAssignedEntity()).containsAll(distributionSetManagement.findDistributionSetListWithDetails( - groupB.stream().map(set -> set.getId()).collect(Collectors.toList()))); + assertThat(result.getAssignedEntity()).containsAll(distributionSetManagement + .findDistributionSetsAll(groupB.stream().map(set -> set.getId()).collect(Collectors.toList()))); assertThat(result.getUnassigned()).isEqualTo(0); assertThat(result.getUnassignedEntity()).isEmpty(); assertThat(result.getDistributionSetTag()).isEqualTo(tag); @@ -201,7 +204,7 @@ public class TagManagementTest extends AbstractIntegrationTest { assertThat(result.getAssigned()).isEqualTo(0); assertThat(result.getAssignedEntity()).isEmpty(); assertThat(result.getUnassigned()).isEqualTo(40); - assertThat(result.getUnassignedEntity()).containsAll(distributionSetManagement.findDistributionSetListWithDetails( + assertThat(result.getUnassignedEntity()).containsAll(distributionSetManagement.findDistributionSetsAll( concat(groupB, groupA).stream().map(set -> set.getId()).collect(Collectors.toList()))); assertThat(result.getDistributionSetTag()).isEqualTo(tag); @@ -214,7 +217,7 @@ public class TagManagementTest extends AbstractIntegrationTest { final List groupA = targetManagement.createTargets(TestDataUtil.generateTargets(20, "")); final List groupB = targetManagement.createTargets(TestDataUtil.generateTargets(20, "groupb")); - final TargetTag tag = tagManagement.createTargetTag(new TargetTag("tag1", "tagdesc1", "")); + final TargetTag tag = tagManagement.createTargetTag(new JpaTargetTag("tag1", "tagdesc1", "")); // toggle A only -> A is now assigned TargetTagAssignmentResult result = targetManagement.toggleTagAssignment(groupA, tag); @@ -249,7 +252,7 @@ public class TagManagementTest extends AbstractIntegrationTest { } @SafeVarargs - private final List concat(final List... targets) { + private final Collection concat(final Collection... targets) { final List result = new ArrayList<>(); Arrays.asList(targets).forEach(result::addAll); return result; @@ -258,16 +261,16 @@ public class TagManagementTest extends AbstractIntegrationTest { @Test @Description("Ensures that all tags are retrieved through repository.") public void findAllTargetTags() { - final List tags = createTargetsWithTags(); + final List tags = createTargetsWithTags(); - assertThat(targetTagRepository.findAll()).isEqualTo(tagManagement.findAllTargetTags()).isEqualTo(tags) + assertThat(targetTagRepository.findAll()).isEqualTo(targetTagRepository.findAll()).isEqualTo(tags) .as("Wrong tag size").hasSize(20); } @Test @Description("Ensures that a created tag is persisted in the repository as defined.") public void createTargetTag() { - final Tag tag = tagManagement.createTargetTag(new TargetTag("kai1", "kai2", "colour")); + final Tag tag = tagManagement.createTargetTag(new JpaTargetTag("kai1", "kai2", "colour")); assertThat(targetTagRepository.findByNameEquals("kai1").getDescription()).as("wrong tag ed").isEqualTo("kai2"); assertThat(tagManagement.findTargetTag("kai1").getColour()).as("wrong tag found").isEqualTo("colour"); @@ -279,7 +282,7 @@ public class TagManagementTest extends AbstractIntegrationTest { public void deleteTargetTas() { // create test data - final Iterable tags = createTargetsWithTags(); + final Iterable tags = createTargetsWithTags(); final TargetTag toDelete = tags.iterator().next(); for (final Target target : targetRepository.findAll()) { @@ -296,13 +299,13 @@ public class TagManagementTest extends AbstractIntegrationTest { .doesNotContain(toDelete); } assertThat(targetTagRepository.findOne(toDelete.getId())).as("No tag should be found").isNull(); - assertThat(tagManagement.findAllTargetTags()).as("Wrong target tag size").hasSize(19); + assertThat(targetTagRepository.findAll()).as("Wrong target tag size").hasSize(19); } @Test @Description("Tests the name update of a target tag.") public void updateTargetTag() { - final List tags = createTargetsWithTags(); + final List tags = createTargetsWithTags(); // change data final TargetTag savedAssigned = tags.iterator().next(); @@ -312,7 +315,7 @@ public class TagManagementTest extends AbstractIntegrationTest { tagManagement.updateTargetTag(savedAssigned); // check data - assertThat(tagManagement.findAllTargetTags()).as("Wrong target tag size").hasSize(tags.size()); + assertThat(targetTagRepository.findAll()).as("Wrong target tag size").hasSize(tags.size()); assertThat(targetTagRepository.findOne(savedAssigned.getId()).getName()).as("wrong target tag is saved") .isEqualTo("test123"); assertThat(targetTagRepository.findOne(savedAssigned.getId()).getOptLockRevision()) @@ -322,7 +325,7 @@ public class TagManagementTest extends AbstractIntegrationTest { @Test @Description("Ensures that a created tag is persisted in the repository as defined.") public void createDistributionSetTag() { - final Tag tag = tagManagement.createDistributionSetTag(new DistributionSetTag("kai1", "kai2", "colour")); + final Tag tag = tagManagement.createDistributionSetTag(new JpaDistributionSetTag("kai1", "kai2", "colour")); assertThat(distributionSetTagRepository.findByNameEquals("kai1").getDescription()).as("wrong tag found") .isEqualTo("kai2"); @@ -366,10 +369,10 @@ public class TagManagementTest extends AbstractIntegrationTest { @Test @Description("Ensures that a tag cannot be created if one exists already with that name (ecpects EntityAlreadyExistsException).") public void failedDuplicateTargetTagNameException() { - tagManagement.createTargetTag(new TargetTag("A")); + tagManagement.createTargetTag(new JpaTargetTag("A")); try { - tagManagement.createTargetTag(new TargetTag("A")); + tagManagement.createTargetTag(new JpaTargetTag("A")); fail("should not have worked as tag already exists"); } catch (final EntityAlreadyExistsException e) { @@ -379,8 +382,8 @@ public class TagManagementTest extends AbstractIntegrationTest { @Test @Description("Ensures that a tag cannot be updated to a name that already exists on another tag (ecpects EntityAlreadyExistsException).") public void failedDuplicateTargetTagNameExceptionAfterUpdate() { - tagManagement.createTargetTag(new TargetTag("A")); - final TargetTag tag = tagManagement.createTargetTag(new TargetTag("B")); + tagManagement.createTargetTag(new JpaTargetTag("A")); + final TargetTag tag = tagManagement.createTargetTag(new JpaTargetTag("B")); tag.setName("A"); try { @@ -394,9 +397,9 @@ public class TagManagementTest extends AbstractIntegrationTest { @Test @Description("Ensures that a tag cannot be created if one exists already with that name (ecpects EntityAlreadyExistsException).") public void failedDuplicateDsTagNameException() { - tagManagement.createDistributionSetTag(new DistributionSetTag("A")); + tagManagement.createDistributionSetTag(new JpaDistributionSetTag("A")); try { - tagManagement.createDistributionSetTag(new DistributionSetTag("A")); + tagManagement.createDistributionSetTag(new JpaDistributionSetTag("A")); fail("should not have worked as tag already exists"); } catch (final EntityAlreadyExistsException e) { @@ -406,8 +409,8 @@ public class TagManagementTest extends AbstractIntegrationTest { @Test @Description("Ensures that a tag cannot be updated to a name that already exists on another tag (ecpects EntityAlreadyExistsException).") public void failedDuplicateDsTagNameExceptionAfterUpdate() { - tagManagement.createDistributionSetTag(new DistributionSetTag("A")); - final DistributionSetTag tag = tagManagement.createDistributionSetTag(new DistributionSetTag("B")); + tagManagement.createDistributionSetTag(new JpaDistributionSetTag("A")); + final DistributionSetTag tag = tagManagement.createDistributionSetTag(new JpaDistributionSetTag("B")); tag.setName("A"); try { @@ -448,19 +451,19 @@ public class TagManagementTest extends AbstractIntegrationTest { assertThat(distributionSetTagRepository.findAll()).as("Wrong size of tags").hasSize(20); } - private List createTargetsWithTags() { - targetManagement.createTargets(TestDataUtil.generateTargets(20)); + private List createTargetsWithTags() { + final List targets = targetManagement.createTargets(TestDataUtil.generateTargets(20)); final Iterable tags = tagManagement.createTargetTags(TestDataUtil.generateTargetTags(20)); - tags.forEach(tag -> targetManagement.toggleTagAssignment(targetRepository.findAll(), tag)); + tags.forEach(tag -> targetManagement.toggleTagAssignment(targets, tag)); - return tagManagement.findAllTargetTags(); + return targetTagRepository.findAll(); } private List createDsSetsWithTags() { - final List sets = TestDataUtil.generateDistributionSets(20, softwareManagement, - distributionSetManagement); + final Collection sets = (Collection) TestDataUtil.generateDistributionSets(20, + softwareManagement, distributionSetManagement); final Iterable tags = tagManagement .createDistributionSetTags(TestDataUtil.generateDistributionSetTags(20)); diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagenmentTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagenmentTest.java index 99e08f331..498364cf9 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagenmentTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagenmentTest.java @@ -13,6 +13,7 @@ import static org.junit.Assert.fail; import org.eclipse.hawkbit.AbstractIntegrationTest; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; +import org.eclipse.hawkbit.repository.jpa.model.JpaTargetFilterQuery; import org.eclipse.hawkbit.repository.model.TargetFilterQuery; import org.junit.Test; @@ -33,7 +34,7 @@ public class TargetFilterQueryManagenmentTest extends AbstractIntegrationTest { public void createTargetFilterQuery() { final String filterName = "new target filter"; final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement - .createTargetFilterQuery(new TargetFilterQuery(filterName, "name==PendingTargets001")); + .createTargetFilterQuery(new JpaTargetFilterQuery(filterName, "name==PendingTargets001")); assertEquals("Retrieved newly created custom target filter", targetFilterQuery, targetFilterQueryManagement.findTargetFilterQueryByName(filterName)); } @@ -43,11 +44,11 @@ public class TargetFilterQueryManagenmentTest extends AbstractIntegrationTest { public void createDuplicateTargetFilterQuery() { final String filterName = "new target filter duplicate"; targetFilterQueryManagement - .createTargetFilterQuery(new TargetFilterQuery(filterName, "name==PendingTargets001")); + .createTargetFilterQuery(new JpaTargetFilterQuery(filterName, "name==PendingTargets001")); try { targetFilterQueryManagement - .createTargetFilterQuery(new TargetFilterQuery(filterName, "name==PendingTargets001")); + .createTargetFilterQuery(new JpaTargetFilterQuery(filterName, "name==PendingTargets001")); fail("should not have worked as query already exists"); } catch (final EntityAlreadyExistsException e) { @@ -59,7 +60,7 @@ public class TargetFilterQueryManagenmentTest extends AbstractIntegrationTest { public void deleteTargetFilterQuery() { final String filterName = "delete_target_filter_query"; final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement - .createTargetFilterQuery(new TargetFilterQuery(filterName, "name==PendingTargets001")); + .createTargetFilterQuery(new JpaTargetFilterQuery(filterName, "name==PendingTargets001")); targetFilterQueryManagement.deleteTargetFilterQuery(targetFilterQuery.getId()); assertEquals("Returns null as the target filter is deleted", null, targetFilterQueryManagement.findTargetFilterQueryById(targetFilterQuery.getId())); @@ -71,7 +72,7 @@ public class TargetFilterQueryManagenmentTest extends AbstractIntegrationTest { public void updateTargetFilterQuery() { final String filterName = "target_filter_01"; final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement - .createTargetFilterQuery(new TargetFilterQuery(filterName, "name==PendingTargets001")); + .createTargetFilterQuery(new JpaTargetFilterQuery(filterName, "name==PendingTargets001")); final String newQuery = "status==UNKNOWN"; targetFilterQuery.setQuery(newQuery); diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetManagementSearchTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetManagementSearchTest.java index 6b509b257..4ff845e1a 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetManagementSearchTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetManagementSearchTest.java @@ -19,17 +19,20 @@ import java.util.stream.Collectors; import org.eclipse.hawkbit.AbstractIntegrationTest; import org.eclipse.hawkbit.TestDataUtil; +import org.eclipse.hawkbit.repository.jpa.model.JpaAction; +import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus; +import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; +import org.eclipse.hawkbit.repository.jpa.model.JpaTargetFilterQuery; +import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Target; -import org.eclipse.hawkbit.repository.model.TargetFilterQuery; import org.eclipse.hawkbit.repository.model.TargetIdName; import org.eclipse.hawkbit.repository.model.TargetTag; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity; -import org.eclipse.hawkbit.repository.specifications.TargetSpecifications; import org.junit.Test; import org.springframework.data.domain.Slice; @@ -50,10 +53,10 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest { + "That includes both the test itself, as a count operation with the same filters " + "and query definitions by RSQL (named and un-named).") public void targetSearchWithVariousFilterCombinations() { - final TargetTag targTagX = tagManagement.createTargetTag(new TargetTag("TargTag-X")); - final TargetTag targTagY = tagManagement.createTargetTag(new TargetTag("TargTag-Y")); - final TargetTag targTagZ = tagManagement.createTargetTag(new TargetTag("TargTag-Z")); - final TargetTag targTagW = tagManagement.createTargetTag(new TargetTag("TargTag-W")); + final TargetTag targTagX = tagManagement.createTargetTag(new JpaTargetTag("TargTag-X")); + final TargetTag targTagY = tagManagement.createTargetTag(new JpaTargetTag("TargTag-Y")); + final TargetTag targTagZ = tagManagement.createTargetTag(new JpaTargetTag("TargTag-Z")); + final TargetTag targTagW = tagManagement.createTargetTag(new JpaTargetTag("TargTag-W")); final DistributionSet setA = TestDataUtil.generateDistributionSet("", softwareManagement, distributionSetManagement); @@ -96,7 +99,7 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest { final Action action = deploymentManagement.findActionWithDetails(actionId); action.setStatus(Status.FINISHED); controllerManagament.addUpdateActionStatus( - new ActionStatus(action, Status.FINISHED, System.currentTimeMillis(), "message")); + new JpaActionStatus((JpaAction) action, Status.FINISHED, System.currentTimeMillis(), "message")); deploymentManagement.assignDistributionSet(setA.getId(), installedC); final List unknown = new ArrayList<>(); @@ -174,13 +177,13 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest { .as("and filter query returns the same result") .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()) .as("and NAMED filter query returns the same result").containsAll(targetManagement - .findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent()); + .findTargetsAll(new JpaTargetFilterQuery("test", query), pageReq).getContent()); assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, pending, null, installedSet.getId(), Boolean.FALSE, new String[0])).as("has number of elements").hasSize(1) .as("and contains the following elements").containsExactly(expectedIdName) .as("and NAMED filter query returns the same result").containsAll(targetManagement - .findAllTargetIdsByTargetFilterQuery(pageReq, new TargetFilterQuery("test", query))); + .findAllTargetIdsByTargetFilterQuery(pageReq, new JpaTargetFilterQuery("test", query))); } @@ -200,13 +203,13 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest { .as("and filter query returns the same result") .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()) .as("and NAMED filter query returns the same result").containsAll(targetManagement - .findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent()); + .findTargetsAll(new JpaTargetFilterQuery("test", query), pageReq).getContent()); assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, both, null, null, Boolean.FALSE, targTagW.getName())).as("has number of elements").hasSize(200).as("and contains the following elements") .containsAll(expectedIdNames).as("and NAMED filter query returns the same result") .containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq, - new TargetFilterQuery("test", query))); + new JpaTargetFilterQuery("test", query))); } private static List convertToIdNames(final List expected) { @@ -234,13 +237,13 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest { .as("and filter query returns the same result") .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()) .as("and NAMED filter query returns the same result").containsAll(targetManagement - .findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent()); + .findTargetsAll(new JpaTargetFilterQuery("test", query), pageReq).getContent()); assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, pending, null, null, Boolean.FALSE, targTagW.getName())).as("has number of elements").hasSize(2).as("and contains the following elements") .containsAll(expectedIdNames).as("and NAMED filter query returns the same result") .containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq, - new TargetFilterQuery("test", query))); + new JpaTargetFilterQuery("test", query))); } @Step @@ -260,13 +263,13 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest { .as("and filter query returns the same result") .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()) .as("and NAMED filter query returns the same result").containsAll(targetManagement - .findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent()); + .findTargetsAll(new JpaTargetFilterQuery("test", query), pageReq).getContent()); assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, pending, null, null, Boolean.FALSE, targTagW.getName())).as("has number of elements").hasSize(2).as("and contains the following elements") .containsAll(expectedIdNames).as("and NAMED filter query returns the same result") .containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq, - new TargetFilterQuery("test", query))); + new JpaTargetFilterQuery("test", query))); } @Step @@ -286,13 +289,13 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest { .as("and filter query returns the same result") .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()) .as("and NAMED filter query returns the same result").containsAll(targetManagement - .findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent()); + .findTargetsAll(new JpaTargetFilterQuery("test", query), pageReq).getContent()); assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, pending, "%targ-B%", setA.getId(), Boolean.FALSE, targTagW.getName())).as("has number of elements").hasSize(1).as("and contains the following elements") .containsExactly(expectedIdName).as("and NAMED filter query returns the same result") .containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq, - new TargetFilterQuery("test", query))); + new JpaTargetFilterQuery("test", query))); } @Step @@ -312,13 +315,13 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest { .as("and filter query returns the same result") .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()) .as("and NAMED filter query returns the same result").containsAll(targetManagement - .findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent()); + .findTargetsAll(new JpaTargetFilterQuery("test", query), pageReq).getContent()); assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, pending, "%targ-A%", setA.getId(), Boolean.FALSE, new String[0])).as("has number of elements").hasSize(1).as("and contains the following elements") .containsExactly(expectedIdName).as("and NAMED filter query returns the same result") .containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq, - new TargetFilterQuery("test", query))); + new JpaTargetFilterQuery("test", query))); } @Step @@ -337,13 +340,13 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest { .as("and filter query returns the same result") .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()) .as("and NAMED filter query returns the same result").containsAll(targetManagement - .findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent()); + .findTargetsAll(new JpaTargetFilterQuery("test", query), pageReq).getContent()); assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, pending, null, setA.getId(), Boolean.FALSE, new String[0])).as("has number of elements").hasSize(3).as("and contains the following elements") .containsAll(expectedIdNames).as("and NAMED filter query returns the same result") .containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq, - new TargetFilterQuery("test", query))); + new JpaTargetFilterQuery("test", query))); } @Step @@ -361,14 +364,14 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest { .as("and filter query returns the same result") .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()) .as("and NAMED filter query returns the same result").containsAll(targetManagement - .findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent()); + .findTargetsAll(new JpaTargetFilterQuery("test", query), pageReq).getContent()); assertThat( targetManagement.findAllTargetIdsByFilters(pageReq, pending, null, null, Boolean.FALSE, new String[0])) .as("has number of elements").hasSize(3).as("and contains the following elements") .containsAll(expectedIdNames).as("and NAMED filter query returns the same result") .containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq, - new TargetFilterQuery("test", query))); + new JpaTargetFilterQuery("test", query))); } @Step @@ -388,13 +391,13 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest { .as("and filter query returns the same result") .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()) .as("and NAMED filter query returns the same result").containsAll(targetManagement - .findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent()); + .findTargetsAll(new JpaTargetFilterQuery("test", query), pageReq).getContent()); assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, unknown, "%targ-B%", null, Boolean.FALSE, targTagW.getName())).as("has number of elements").hasSize(99).as("and contains the following elements") .containsAll(expectedIdNames).as("and NAMED filter query returns the same result") .containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq, - new TargetFilterQuery("test", query))); + new JpaTargetFilterQuery("test", query))); } @Step @@ -412,13 +415,13 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest { .as("and filter query returns the same result") .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()) .as("and NAMED filter query returns the same result").containsAll(targetManagement - .findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent()); + .findTargetsAll(new JpaTargetFilterQuery("test", query), pageReq).getContent()); assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, unknown, "%targ-A%", null, Boolean.FALSE, new String[0])).as("has number of elements").hasSize(99).as("and contains the following elements") .containsAll(expectedIdNames).as("and NAMED filter query returns the same result") .containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq, - new TargetFilterQuery("test", query))); + new JpaTargetFilterQuery("test", query))); } @Step @@ -435,12 +438,12 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest { .as("and filter query returns the same result") .hasSize(targetManagement.findTargetsAll(query, pageReq).getContent().size()) .as("and NAMED filter query returns the same result").hasSize(targetManagement - .findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent().size()); + .findTargetsAll(new JpaTargetFilterQuery("test", query), pageReq).getContent().size()); assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, unknown, null, setA.getId(), Boolean.FALSE, new String[0])).as("has number of elements").hasSize(0) .as("and NAMED filter query returns the same result").containsAll(targetManagement - .findAllTargetIdsByTargetFilterQuery(pageReq, new TargetFilterQuery("test", query))); + .findAllTargetIdsByTargetFilterQuery(pageReq, new JpaTargetFilterQuery("test", query))); } @Step @@ -459,13 +462,13 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest { .as("and filter query returns the same result") .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()) .as("and NAMED filter query returns the same result").containsAll(targetManagement - .findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent()); + .findTargetsAll(new JpaTargetFilterQuery("test", query), pageReq).getContent()); assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, unknown, null, null, Boolean.FALSE, targTagY.getName(), targTagW.getName())).as("has number of elements").hasSize(198) .as("and contains the following elements").containsAll(expectedIdNames) .as("and NAMED filter query returns the same result").containsAll(targetManagement - .findAllTargetIdsByTargetFilterQuery(pageReq, new TargetFilterQuery("test", query))); + .findAllTargetIdsByTargetFilterQuery(pageReq, new JpaTargetFilterQuery("test", query))); } @Step @@ -483,14 +486,14 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest { .as("and filter query returns the same result") .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()) .as("and NAMED filter query returns the same result").containsAll(targetManagement - .findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent()); + .findTargetsAll(new JpaTargetFilterQuery("test", query), pageReq).getContent()); assertThat( targetManagement.findAllTargetIdsByFilters(pageReq, unknown, null, null, Boolean.FALSE, new String[0])) .as("has number of elements").hasSize(397).as("and contains the following elements") .containsAll(expectedIdNames).as("and NAMED filter query returns the same result") .containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq, - new TargetFilterQuery("test", query))); + new JpaTargetFilterQuery("test", query))); } @Step @@ -509,13 +512,13 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest { .as("and filter query returns the same result") .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()) .as("and NAMED filter query returns the same result").containsAll(targetManagement - .findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent()); + .findTargetsAll(new JpaTargetFilterQuery("test", query), pageReq).getContent()); assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, null, "%targ-A%", setA.getId(), Boolean.FALSE, new String[0])).as("has number of elements").hasSize(1).as("and contains the following elements") .containsExactly(expectedIdName).as("and NAMED filter query returns the same result") .containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq, - new TargetFilterQuery("test", query))); + new JpaTargetFilterQuery("test", query))); } @Step @@ -532,13 +535,13 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest { .as("and filter query returns the same result") .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()) .as("and NAMED filter query returns the same result").containsAll(targetManagement - .findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent()); + .findTargetsAll(new JpaTargetFilterQuery("test", query), pageReq).getContent()); assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, null, null, setA.getId(), Boolean.FALSE, new String[0])).as("has number of elements").hasSize(3).as("and contains the following elements") .containsAll(expectedIdNames).as("and NAMED filter query returns the same result") .containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq, - new TargetFilterQuery("test", query))); + new JpaTargetFilterQuery("test", query))); } @Step @@ -554,12 +557,12 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest { .as("and filter query returns the same result") .hasSize(targetManagement.findTargetsAll(query, pageReq).getContent().size()) .as("and NAMED filter query returns the same result").hasSize(targetManagement - .findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent().size()); + .findTargetsAll(new JpaTargetFilterQuery("test", query), pageReq).getContent().size()); assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, null, "%targ-C%", setA.getId(), Boolean.FALSE, targTagX.getName())).as("has number of elements").hasSize(0) .as("and NAMED filter query returns the same result").containsAll(targetManagement - .findAllTargetIdsByTargetFilterQuery(pageReq, new TargetFilterQuery("test", query))); + .findAllTargetIdsByTargetFilterQuery(pageReq, new JpaTargetFilterQuery("test", query))); } @Step @@ -575,12 +578,12 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest { .as("and filter query returns the same result") .hasSize(targetManagement.findTargetsAll(query, pageReq).getContent().size()) .as("and NAMED filter query returns the same result").hasSize(targetManagement - .findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent().size()); + .findTargetsAll(new JpaTargetFilterQuery("test", query), pageReq).getContent().size()); assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, null, "%targ-A%", setA.getId(), Boolean.FALSE, targTagW.getName())).as("has number of elements").hasSize(0) .as("and NAMED filter query returns the same result").containsAll(targetManagement - .findAllTargetIdsByTargetFilterQuery(pageReq, new TargetFilterQuery("test", query))); + .findAllTargetIdsByTargetFilterQuery(pageReq, new JpaTargetFilterQuery("test", query))); } @Step @@ -599,13 +602,13 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest { .as("and filter query returns the same result") .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()) .as("and NAMED filter query returns the same result").containsAll(targetManagement - .findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent()); + .findTargetsAll(new JpaTargetFilterQuery("test", query), pageReq).getContent()); assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, null, "%targ-C%", setA.getId(), Boolean.FALSE, targTagW.getName())).as("has number of elements").hasSize(1).as("and contains the following elements") .containsExactly(expectedIdName).as("and NAMED filter query returns the same result") .containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq, - new TargetFilterQuery("test", query))); + new JpaTargetFilterQuery("test", query))); } @Step @@ -623,13 +626,13 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest { .as("and filter query returns the same result") .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()) .as("and NAMED filter query returns the same result").containsAll(targetManagement - .findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent()); + .findTargetsAll(new JpaTargetFilterQuery("test", query), pageReq).getContent()); assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, null, "%targ-B%", null, Boolean.FALSE, targTagY.getName(), targTagW.getName())).as("has number of elements").hasSize(100) .as("and contains the following elements").containsAll(expectedIdNames) .as("and NAMED filter query returns the same result").containsAll(targetManagement - .findAllTargetIdsByTargetFilterQuery(pageReq, new TargetFilterQuery("test", query))); + .findAllTargetIdsByTargetFilterQuery(pageReq, new JpaTargetFilterQuery("test", query))); } @@ -653,13 +656,13 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest { .as("and filter query returns the same result") .containsAll(targetManagement.findTargetsAll(query, pageReq).getContent()) .as("and NAMED filter query returns the same result").containsAll(targetManagement - .findTargetsAll(new TargetFilterQuery("test", query), pageReq).getContent()); + .findTargetsAll(new JpaTargetFilterQuery("test", query), pageReq).getContent()); assertThat(targetManagement.findAllTargetIdsByFilters(pageReq, null, null, null, Boolean.FALSE, targTagD.getName())).as("has number of elements").hasSize(200).as("and contains the following elements") .containsAll(expectedIdNames).as("and NAMED filter query returns the same result") .containsAll(targetManagement.findAllTargetIdsByTargetFilterQuery(pageReq, - new TargetFilterQuery("test", query))); + new JpaTargetFilterQuery("test", query))); } @@ -698,7 +701,7 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest { final Comparator byId = (e1, e2) -> Long.compare(e2.getId(), e1.getId()); assertThat(result.getNumberOfElements()).isEqualTo(9); - final List expected = new ArrayList(); + final List expected = new ArrayList<>(); Collections.sort(targInstalled, byId); Collections.sort(targAssigned, byId); Collections.sort(notAssigned, byId); @@ -730,34 +733,6 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest { } - @Test - @Description("Verfies that targets with given assigned DS and additonal specification are returned from repository.") - public void findTargetByAssignedDistributionSetWithAdditonalSpecification() { - final DistributionSet assignedSet = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); - final DistributionSet installedSet = TestDataUtil.generateDistributionSet("another", softwareManagement, - distributionSetManagement); - targetManagement.createTargets(TestDataUtil.generateTargets(10, "unassigned")); - List assignedtargets = targetManagement.createTargets(TestDataUtil.generateTargets(10, "assigned")); - - // set on installed and assign another one - deploymentManagement.assignDistributionSet(installedSet, assignedtargets).getActions().forEach(actionId -> { - final Action action = deploymentManagement.findActionWithDetails(actionId); - action.setStatus(Status.FINISHED); - controllerManagament.addUpdateActionStatus( - new ActionStatus(action, Status.FINISHED, System.currentTimeMillis(), "message")); - }); - deploymentManagement.assignDistributionSet(assignedSet, assignedtargets); - - assignedtargets = targetManagement.findTargetByControllerID( - assignedtargets.stream().map(target -> target.getControllerId()).collect(Collectors.toList())); - - assertThat(targetManagement.findTargetByAssignedDistributionSet(assignedSet.getId(), - TargetSpecifications.hasInstalledDistributionSet(installedSet.getId()), pageReq)) - .as("Contains the assigned targets").containsAll(assignedtargets) - .as("and that means the following expected amount").hasSize(10); - } - @Test @Description("Verfies that targets with given installed DS are returned from repository.") public void findTargetByInstalledDistributionSet() { @@ -773,7 +748,7 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest { final Action action = deploymentManagement.findActionWithDetails(actionId); action.setStatus(Status.FINISHED); controllerManagament.addUpdateActionStatus( - new ActionStatus(action, Status.FINISHED, System.currentTimeMillis(), "message")); + new JpaActionStatus((JpaAction) action, Status.FINISHED, System.currentTimeMillis(), "message")); }); deploymentManagement.assignDistributionSet(assignedSet, installedtargets); @@ -787,41 +762,11 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest { } - @Test - @Description("Verfies that targets with given installed DS and additonal specification are returned from repository.") - public void findTargetByInstalledDistributionSetWithAdditonalSpecification() { - final DistributionSet assignedSet = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); - final DistributionSet installedSet = TestDataUtil.generateDistributionSet("another", softwareManagement, - distributionSetManagement); - targetManagement.createTargets(TestDataUtil.generateTargets(10, "unassigned")); - List installedtargets = targetManagement.createTargets(TestDataUtil.generateTargets(10, "assigned")); - - // set on installed and assign another one - deploymentManagement.assignDistributionSet(installedSet, installedtargets).getActions().forEach(actionId -> { - final Action action = deploymentManagement.findActionWithDetails(actionId); - action.setStatus(Status.FINISHED); - controllerManagament.addUpdateActionStatus( - new ActionStatus(action, Status.FINISHED, System.currentTimeMillis(), "message")); - }); - deploymentManagement.assignDistributionSet(assignedSet, installedtargets); - - // get final updated version of targets - installedtargets = targetManagement.findTargetByControllerID( - installedtargets.stream().map(target -> target.getControllerId()).collect(Collectors.toList())); - - assertThat(targetManagement.findTargetByInstalledDistributionSet(installedSet.getId(), - TargetSpecifications.hasAssignedDistributionSet(assignedSet.getId()), pageReq)) - .as("Contains the assigned targets").containsAll(installedtargets) - .as("and that means the following expected amount").hasSize(10); - - } - private List sendUpdateActionStatusToTargets(final DistributionSet dsA, final Iterable targs, final Status status, final String... msgs) { final List result = new ArrayList(); for (final Target t : targs) { - final List findByTarget = actionRepository.findByTarget(t); + final List findByTarget = actionRepository.findByTarget((JpaTarget) t); for (final Action action : findByTarget) { result.add(sendUpdateActionStatusToTarget(status, action, t, msgs)); } @@ -833,7 +778,7 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest { final String... msgs) { updActA.setStatus(status); - final ActionStatus statusMessages = new ActionStatus(); + final ActionStatus statusMessages = new JpaActionStatus(); statusMessages.setAction(updActA); statusMessages.setOccurredAt(System.currentTimeMillis()); statusMessages.setStatus(status); diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetManagementTest.java index ae4447fc6..c2d7a0a4f 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetManagementTest.java @@ -34,14 +34,16 @@ import org.eclipse.hawkbit.WithSpringAuthorityRule; import org.eclipse.hawkbit.WithUser; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.exception.TenantNotExistException; -import org.eclipse.hawkbit.repository.model.Action; +import org.eclipse.hawkbit.repository.jpa.model.JpaAction; +import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus; +import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; +import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo; +import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag; import org.eclipse.hawkbit.repository.model.Action.Status; -import org.eclipse.hawkbit.repository.model.ActionStatus; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Tag; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetIdName; -import org.eclipse.hawkbit.repository.model.TargetInfo; import org.eclipse.hawkbit.repository.model.TargetTag; import org.junit.Test; import org.springframework.data.domain.PageRequest; @@ -61,7 +63,7 @@ public class TargetManagementTest extends AbstractIntegrationTest { @WithUser(tenantId = "tenantWhichDoesNotExists", allSpPermissions = true, autoCreateTenant = false) public void createTargetForTenantWhichDoesNotExistThrowsTenantNotExistException() { try { - targetManagement.createTarget(new Target("targetId123")); + targetManagement.createTarget(new JpaTarget("targetId123")); fail("should not be possible as the tenant does not exist"); } catch (final TenantNotExistException e) { // ok @@ -72,14 +74,14 @@ public class TargetManagementTest extends AbstractIntegrationTest { @Description("Verify that a target with empty controller id cannot be created") public void createTargetWithNoControllerId() { try { - targetManagement.createTarget(new Target("")); + targetManagement.createTarget(new JpaTarget("")); fail("target with empty controller id should not be created"); } catch (final ConstraintViolationException e) { // ok } try { - targetManagement.createTarget(new Target(null)); + targetManagement.createTarget(new JpaTarget(null)); fail("target with empty controller id should not be created"); } catch (final ConstraintViolationException e) { // ok @@ -90,13 +92,13 @@ public class TargetManagementTest extends AbstractIntegrationTest { @Description("Ensures that targets can assigned and unassigned to a target tag. Not exists target will be ignored for the assignment.") public void assignAndUnassignTargetsToTag() { final List assignTarget = new ArrayList(); - assignTarget.add(targetManagement.createTarget(new Target("targetId123")).getControllerId()); - assignTarget.add(targetManagement.createTarget(new Target("targetId1234")).getControllerId()); - assignTarget.add(targetManagement.createTarget(new Target("targetId1235")).getControllerId()); - assignTarget.add(targetManagement.createTarget(new Target("targetId1236")).getControllerId()); + assignTarget.add(targetManagement.createTarget(new JpaTarget("targetId123")).getControllerId()); + assignTarget.add(targetManagement.createTarget(new JpaTarget("targetId1234")).getControllerId()); + assignTarget.add(targetManagement.createTarget(new JpaTarget("targetId1235")).getControllerId()); + assignTarget.add(targetManagement.createTarget(new JpaTarget("targetId1236")).getControllerId()); assignTarget.add("NotExist"); - final TargetTag targetTag = tagManagement.createTargetTag(new TargetTag("Tag1")); + final TargetTag targetTag = tagManagement.createTargetTag(new JpaTargetTag("Tag1")); final List assignedTargets = targetManagement.assignTag(assignTarget, targetTag); assertThat(assignedTargets.size()).as("Assigned targets are wrong").isEqualTo(4); @@ -125,7 +127,7 @@ public class TargetManagementTest extends AbstractIntegrationTest { @Test @Description("Ensures that targets can deleted e.g. test all cascades") public void deleteAndCreateTargets() { - Target target = targetManagement.createTarget(new Target("targetId123")); + Target target = targetManagement.createTarget(new JpaTarget("targetId123")); assertThat(targetManagement.countTargetsAll()).as("target count is wrong").isEqualTo(1); targetManagement.deleteTargets(target.getId()); assertThat(targetManagement.countTargetsAll()).as("target count is wrong").isEqualTo(0); @@ -137,7 +139,7 @@ public class TargetManagementTest extends AbstractIntegrationTest { final List targets = new ArrayList(); for (int i = 0; i < 5; i++) { - target = targetManagement.createTarget(new Target("" + i)); + target = targetManagement.createTarget(new JpaTarget("" + i)); targets.add(target.getId()); targets.add(createTargetWithAttributes("" + (i * i + 1000)).getId()); } @@ -147,7 +149,7 @@ public class TargetManagementTest extends AbstractIntegrationTest { } private Target createTargetWithAttributes(final String controllerId) { - Target target = new Target(controllerId); + Target target = new JpaTarget(controllerId); final Map testData = new HashMap<>(); testData.put("test1", "testdata1"); @@ -184,10 +186,10 @@ public class TargetManagementTest extends AbstractIntegrationTest { final DistributionSetAssignmentResult result = deploymentManagement.assignDistributionSet(set.getId(), "4711"); - final Action action = deploymentManagement.findActionWithDetails(result.getActions().get(0)); + final JpaAction action = (JpaAction) deploymentManagement.findActionWithDetails(result.getActions().get(0)); action.setStatus(Status.FINISHED); controllerManagament.addUpdateActionStatus( - new ActionStatus(action, Status.FINISHED, System.currentTimeMillis(), "message")); + new JpaActionStatus(action, Status.FINISHED, System.currentTimeMillis(), "message")); deploymentManagement.assignDistributionSet(set2.getId(), "4711"); target = targetManagement.findTargetByControllerIDWithDetails("4711"); @@ -231,9 +233,9 @@ public class TargetManagementTest extends AbstractIntegrationTest { @Test @Description("Checks if the EntityAlreadyExistsException is thrown if a single target with the same controller ID are created twice.") public void createTargetDuplicate() { - targetManagement.createTarget(new Target("4711")); + targetManagement.createTarget(new JpaTarget("4711")); try { - targetManagement.createTarget(new Target("4711")); + targetManagement.createTarget(new JpaTarget("4711")); fail("Target already exists"); } catch (final EntityAlreadyExistsException e) { } @@ -338,7 +340,7 @@ public class TargetManagementTest extends AbstractIntegrationTest { final Target savedExtra = targetManagement.createTarget(extra); - Iterable allFound = targetRepository.findAll(); + final Iterable allFound = targetRepository.findAll(); assertThat(Long.valueOf(firstList.size())).as("List size of targets") .isEqualTo(firstSaved.spliterator().getExactSizeIfKnown()); @@ -391,11 +393,11 @@ public class TargetManagementTest extends AbstractIntegrationTest { targetManagement.deleteTargets(deletedTargetIDs); - allFound = targetManagement.findTargetsAll(new PageRequest(0, 200)).getContent(); + final List found = targetManagement.findTargetsAll(new PageRequest(0, 200)).getContent(); assertThat(firstSaved.spliterator().getExactSizeIfKnown() - nr2Del).as("Size of splited list") - .isEqualTo(allFound.spliterator().getExactSizeIfKnown()); + .isEqualTo(found.spliterator().getExactSizeIfKnown()); - assertThat(allFound).as("Not all undeleted found").doesNotContain(deletedTargets); + assertThat(found).as("Not all undeleted found").doesNotContain(deletedTargets); } @Test @@ -404,18 +406,18 @@ public class TargetManagementTest extends AbstractIntegrationTest { Iterable ts = targetManagement .createTargets(TestDataUtil.buildTargetFixtures(100, "myCtrlID", "first description")); - final Map attribs = new HashMap(); + final Map attribs = new HashMap<>(); attribs.put("a.b.c", "abc"); attribs.put("x.y.z", ""); attribs.put("1.2.3", "123"); attribs.put("1.2.3.4", "1234"); attribs.put("1.2.3.4.5", "12345"); - final Set attribs2Del = new HashSet(); + final Set attribs2Del = new HashSet<>(); attribs2Del.add("x.y.z"); attribs2Del.add("1.2.3"); for (final Target t : ts) { - TargetInfo targetInfo = t.getTargetInfo(); + JpaTargetInfo targetInfo = (JpaTargetInfo) t.getTargetInfo(); targetInfo.setNew(false); for (final Entry attrib : attribs.entrySet()) { final String key = attrib.getKey(); @@ -460,7 +462,7 @@ public class TargetManagementTest extends AbstractIntegrationTest { for (final Target ta : ts2DelAllAttribs) { final Target t = targetManagement.findTargetByControllerIDWithDetails(ta.getControllerId()); - final TargetInfo targetStatus = t.getTargetInfo(); + final JpaTargetInfo targetStatus = (JpaTargetInfo) t.getTargetInfo(); targetStatus.getControllerAttributes().clear(); targetInfoRepository.save(targetStatus); } @@ -468,7 +470,7 @@ public class TargetManagementTest extends AbstractIntegrationTest { for (final Target ta : ts2DelAttribs) { final Target t = targetManagement.findTargetByControllerIDWithDetails(ta.getControllerId()); - final TargetInfo targetStatus = t.getTargetInfo(); + final JpaTargetInfo targetStatus = (JpaTargetInfo) t.getTargetInfo(); for (final String attribKey : attribs2Del) { targetStatus.getControllerAttributes().remove(attribKey); } @@ -477,7 +479,7 @@ public class TargetManagementTest extends AbstractIntegrationTest { // only the number of the remaining targets and controller attributes // are checked - final Iterable restTS = targetRepository.findAll(); + final Iterable restTS = targetRepository.findAll(); restTarget_: for (final Target targetl : restTS) { final Target target = targetManagement.findTargetByControllerIDWithDetails(targetl.getControllerId()); @@ -552,10 +554,10 @@ public class TargetManagementTest extends AbstractIntegrationTest { final List tagABCTargets = targetManagement .createTargets(TestDataUtil.buildTargetFixtures(10, "tagABCTargets", "first description")); - final TargetTag tagA = tagManagement.createTargetTag(new TargetTag("A")); - final TargetTag tagB = tagManagement.createTargetTag(new TargetTag("B")); - final TargetTag tagC = tagManagement.createTargetTag(new TargetTag("C")); - tagManagement.createTargetTag(new TargetTag("X")); + final TargetTag tagA = tagManagement.createTargetTag(new JpaTargetTag("A")); + final TargetTag tagB = tagManagement.createTargetTag(new JpaTargetTag("B")); + final TargetTag tagC = tagManagement.createTargetTag(new JpaTargetTag("C")); + tagManagement.createTargetTag(new JpaTargetTag("X")); // doing different assignments targetManagement.toggleTagAssignment(tagATargets, tagA); @@ -610,9 +612,9 @@ public class TargetManagementTest extends AbstractIntegrationTest { @Test @Description("Tests the unassigment of tags to multiple targets.") public void targetTagBulkUnassignments() { - final TargetTag targTagA = tagManagement.createTargetTag(new TargetTag("Targ-A-Tag")); - final TargetTag targTagB = tagManagement.createTargetTag(new TargetTag("Targ-B-Tag")); - final TargetTag targTagC = tagManagement.createTargetTag(new TargetTag("Targ-C-Tag")); + final TargetTag targTagA = tagManagement.createTargetTag(new JpaTargetTag("Targ-A-Tag")); + final TargetTag targTagB = tagManagement.createTargetTag(new JpaTargetTag("Targ-B-Tag")); + final TargetTag targTagC = tagManagement.createTargetTag(new JpaTargetTag("Targ-C-Tag")); final List targAs = targetManagement .createTargets(TestDataUtil.buildTargetFixtures(25, "target-id-A", "first description")); @@ -673,7 +675,7 @@ public class TargetManagementTest extends AbstractIntegrationTest { @Test @Description("Retrieves targets by ID with lazy loading of the tags. Checks the successfull load.") public void findTargetsByControllerIDsWithTags() { - final TargetTag targTagA = tagManagement.createTargetTag(new TargetTag("Targ-A-Tag")); + final TargetTag targTagA = tagManagement.createTargetTag(new JpaTargetTag("Targ-A-Tag")); final List targAs = targetManagement .createTargets(TestDataUtil.buildTargetFixtures(25, "target-id-A", "first description")); @@ -711,7 +713,7 @@ public class TargetManagementTest extends AbstractIntegrationTest { @Description("Test that NO TAG functionality which gives all targets with no tag assigned.") public void findTargetsWithNoTag() { - final TargetTag targTagA = tagManagement.createTargetTag(new TargetTag("Targ-A-Tag")); + final TargetTag targTagA = tagManagement.createTargetTag(new JpaTargetTag("Targ-A-Tag")); final List targAs = targetManagement .createTargets(TestDataUtil.buildTargetFixtures(25, "target-id-A", "first description")); targetManagement.toggleTagAssignment(targAs, targTagA); diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/model/ModelEqualsHashcodeTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/model/ModelEqualsHashcodeTest.java index 45e56167a..c8f34cd48 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/model/ModelEqualsHashcodeTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/model/ModelEqualsHashcodeTest.java @@ -11,6 +11,12 @@ package org.eclipse.hawkbit.repository.model; import static org.fest.assertions.api.Assertions.assertThat; import org.eclipse.hawkbit.AbstractIntegrationTest; +import org.eclipse.hawkbit.repository.jpa.model.JpaAction; +import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType; +import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; +import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType; import org.junit.Test; import ru.yandex.qatools.allure.annotations.Description; @@ -25,29 +31,29 @@ public class ModelEqualsHashcodeTest extends AbstractIntegrationTest { @Description("Verfies that different objects even with identical primary key, version and tenant " + "return different hash codes.") public void differentEntitiesReturnDifferentHashCodes() { - assertThat(new Action().hashCode()).as("action should have different hashcode than action status") - .isNotEqualTo(new ActionStatus().hashCode()); - assertThat(new DistributionSet().hashCode()) + assertThat(new JpaAction().hashCode()).as("action should have different hashcode than action status") + .isNotEqualTo(new JpaActionStatus().hashCode()); + assertThat(new JpaDistributionSet().hashCode()) .as("Distribution set should have different hashcode than software module") - .isNotEqualTo(new SoftwareModule().hashCode()); - assertThat(new DistributionSet().hashCode()) + .isNotEqualTo(new JpaSoftwareModule().hashCode()); + assertThat(new JpaDistributionSet().hashCode()) .as("Distribution set should have different hashcode than action status") - .isNotEqualTo(new ActionStatus().hashCode()); - assertThat(new DistributionSetType().hashCode()) + .isNotEqualTo(new JpaActionStatus().hashCode()); + assertThat(new JpaDistributionSetType().hashCode()) .as("Distribution set type should have different hashcode than action status") - .isNotEqualTo(new ActionStatus().hashCode()); + .isNotEqualTo(new JpaActionStatus().hashCode()); } @Test @Description("Verfies that different object even with identical primary key, version and tenant " + "are not equal.") public void differentEntitiesAreNotEqual() { - assertThat(new Action().equals(new ActionStatus())).as("action equals action status").isFalse(); - assertThat(new DistributionSet().equals(new SoftwareModule())).as("Distribution set equals software module") + assertThat(new JpaAction().equals(new JpaActionStatus())).as("action equals action status").isFalse(); + assertThat(new JpaDistributionSet().equals(new JpaSoftwareModule())) + .as("Distribution set equals software module").isFalse(); + assertThat(new JpaDistributionSet().equals(new JpaActionStatus())).as("Distribution set equals action status") .isFalse(); - assertThat(new DistributionSet().equals(new ActionStatus())).as("Distribution set equals action status") - .isFalse(); - assertThat(new DistributionSetType().equals(new ActionStatus())) + assertThat(new JpaDistributionSetType().equals(new JpaActionStatus())) .as("Distribution set type equals action status").isFalse(); } @@ -55,9 +61,9 @@ public class ModelEqualsHashcodeTest extends AbstractIntegrationTest { @Description("Verfies that updated entities are not equal.") public void changedEntitiesAreNotEqual() { final SoftwareModuleType type = softwareManagement - .createSoftwareModuleType(new SoftwareModuleType("test", "test", "test", 1)); + .createSoftwareModuleType(new JpaSoftwareModuleType("test", "test", "test", 1)); assertThat(type).as("persited entity is not equal to regular object") - .isNotEqualTo(new SoftwareModuleType("test", "test", "test", 1)); + .isNotEqualTo(new JpaSoftwareModuleType("test", "test", "test", 1)); type.setDescription("another"); final SoftwareModuleType updated = softwareManagement.updateSoftwareModuleType(type); @@ -68,9 +74,9 @@ public class ModelEqualsHashcodeTest extends AbstractIntegrationTest { @Description("Verify that no proxy of the entity manager has an influence on the equals or hashcode result.") public void managedEntityIsEqualToUnamangedObjectWithSameKey() { final SoftwareModuleType type = softwareManagement - .createSoftwareModuleType(new SoftwareModuleType("test", "test", "test", 1)); + .createSoftwareModuleType(new JpaSoftwareModuleType("test", "test", "test", 1)); - final SoftwareModuleType mock = new SoftwareModuleType("test", "test", "test", 1); + final JpaSoftwareModuleType mock = new JpaSoftwareModuleType("test", "test", "test", 1); mock.setId(type.getId()); mock.setOptLockRevision(type.getOptLockRevision()); mock.setTenant(type.getTenant()); @@ -84,9 +90,9 @@ public class ModelEqualsHashcodeTest extends AbstractIntegrationTest { @Description("Verfies that updated entities do not have the same hashcode.") public void updatedEntitiesHaveDifferentHashcodes() { final SoftwareModuleType type = softwareManagement - .createSoftwareModuleType(new SoftwareModuleType("test", "test", "test", 1)); + .createSoftwareModuleType(new JpaSoftwareModuleType("test", "test", "test", 1)); assertThat(type.hashCode()).as("persited entity does not have same hashcode as regular object") - .isNotEqualTo(new SoftwareModuleType("test", "test", "test", 1).hashCode()); + .isNotEqualTo(new JpaSoftwareModuleType("test", "test", "test", 1).hashCode()); final int beforeChange = type.hashCode(); type.setDescription("another"); diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLActionFieldsTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLActionFieldsTest.java index 8b20af27d..b37d70a33 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLActionFieldsTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLActionFieldsTest.java @@ -13,6 +13,8 @@ import static org.junit.Assert.fail; import org.eclipse.hawkbit.AbstractIntegrationTest; import org.eclipse.hawkbit.repository.ActionFields; +import org.eclipse.hawkbit.repository.jpa.model.JpaAction; +import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.ActionType; import org.eclipse.hawkbit.repository.model.Target; @@ -20,7 +22,6 @@ import org.junit.Before; import org.junit.Test; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Slice; -import org.springframework.data.jpa.domain.Specification; import ru.yandex.qatools.allure.annotations.Description; import ru.yandex.qatools.allure.annotations.Features; @@ -31,20 +32,20 @@ import ru.yandex.qatools.allure.annotations.Stories; public class RSQLActionFieldsTest extends AbstractIntegrationTest { private Target target; - private Action action; + private JpaAction action; @Before public void setupBeforeTest() { - target = new Target("targetId123"); + target = new JpaTarget("targetId123"); target.setDescription("targetId123"); targetManagement.createTarget(target); - action = new Action(); + action = new JpaAction(); action.setActionType(ActionType.SOFT); target.getActions().add(action); action.setTarget(target); actionRepository.save(action); for (int i = 0; i < 10; i++) { - final Action newAction = new Action(); + final JpaAction newAction = new JpaAction(); newAction.setActionType(ActionType.SOFT); newAction.setActive(i % 2 == 0); newAction.setTarget(target); @@ -79,10 +80,9 @@ public class RSQLActionFieldsTest extends AbstractIntegrationTest { private void assertRSQLQuery(final String rsqlParam, final long expectedEntities) { - final Specification parse = RSQLUtility.parse(rsqlParam, ActionFields.class); - final Slice findEnitity = deploymentManagement.findActionsByTarget(parse, target, + final Slice findEnitity = deploymentManagement.findActionsByTarget(rsqlParam, target, new PageRequest(0, 100)); - final long countAllEntities = deploymentManagement.countActionsByTarget(parse, target); + final long countAllEntities = deploymentManagement.countActionsByTarget(rsqlParam, target); assertThat(findEnitity).isNotNull(); assertThat(countAllEntities).isEqualTo(expectedEntities); } diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLDistributionSetFieldTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLDistributionSetFieldTest.java index 6b1682820..bd46ed387 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLDistributionSetFieldTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLDistributionSetFieldTest.java @@ -16,8 +16,9 @@ import java.util.Arrays; import org.eclipse.hawkbit.AbstractIntegrationTest; import org.eclipse.hawkbit.TestDataUtil; import org.eclipse.hawkbit.repository.DistributionSetFields; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetMetadata; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag; import org.eclipse.hawkbit.repository.model.DistributionSet; -import org.eclipse.hawkbit.repository.model.DistributionSetMetadata; import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.junit.Before; import org.junit.Test; @@ -39,19 +40,20 @@ public class RSQLDistributionSetFieldTest extends AbstractIntegrationTest { ds.setDescription("DS"); ds = distributionSetManagement.updateDistributionSet(ds); distributionSetManagement - .createDistributionSetMetadata(new DistributionSetMetadata("metaKey", ds, "metaValue")); + .createDistributionSetMetadata(new JpaDistributionSetMetadata("metaKey", ds, "metaValue")); DistributionSet ds2 = TestDataUtil .generateDistributionSets("NewDS", 3, softwareManagement, distributionSetManagement).get(0); ds2.setDescription("DS%"); ds2 = distributionSetManagement.updateDistributionSet(ds2); - distributionSetManagement.createDistributionSetMetadata(new DistributionSetMetadata("metaKey", ds2, "value")); + distributionSetManagement + .createDistributionSetMetadata(new JpaDistributionSetMetadata("metaKey", ds2, "value")); - final DistributionSetTag targetTag = tagManagement.createDistributionSetTag(new DistributionSetTag("Tag1")); - tagManagement.createDistributionSetTag(new DistributionSetTag("Tag2")); - tagManagement.createDistributionSetTag(new DistributionSetTag("Tag3")); - tagManagement.createDistributionSetTag(new DistributionSetTag("Tag4")); + final DistributionSetTag targetTag = tagManagement.createDistributionSetTag(new JpaDistributionSetTag("Tag1")); + tagManagement.createDistributionSetTag(new JpaDistributionSetTag("Tag2")); + tagManagement.createDistributionSetTag(new JpaDistributionSetTag("Tag3")); + tagManagement.createDistributionSetTag(new JpaDistributionSetTag("Tag4")); distributionSetManagement.assignTag(Arrays.asList(ds.getId(), ds2.getId()), targetTag); } @@ -137,8 +139,8 @@ public class RSQLDistributionSetFieldTest extends AbstractIntegrationTest { } private void assertRSQLQuery(final String rsqlParam, final long excpectedEntity) { - final Page find = distributionSetManagement.findDistributionSetsAll( - RSQLUtility.parse(rsqlParam, DistributionSetFields.class), new PageRequest(0, 100), false); + final Page find = distributionSetManagement.findDistributionSetsAll(rsqlParam, + new PageRequest(0, 100), false); final long countAll = find.getTotalElements(); assertThat(find).as("Founded entity is should not be null").isNotNull(); assertThat(countAll).as("Founded entity size is wrong").isEqualTo(excpectedEntity); diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLDistributionSetMetadataFieldsTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLDistributionSetMetadataFieldsTest.java index 755e5a61f..09c1e8dd0 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLDistributionSetMetadataFieldsTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLDistributionSetMetadataFieldsTest.java @@ -16,6 +16,7 @@ import java.util.List; import org.eclipse.hawkbit.AbstractIntegrationTest; import org.eclipse.hawkbit.TestDataUtil; import org.eclipse.hawkbit.repository.DistributionSetMetadataFields; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetMetadata; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetMetadata; import org.junit.Before; @@ -41,7 +42,7 @@ public class RSQLDistributionSetMetadataFieldsTest extends AbstractIntegrationTe final List metadata = new ArrayList<>(); for (int i = 0; i < 5; i++) { - metadata.add(new DistributionSetMetadata("" + i, distributionSet, "" + i)); + metadata.add(new JpaDistributionSetMetadata("" + i, distributionSet, "" + i)); } distributionSetManagement.createDistributionSetMetadata(metadata); @@ -68,8 +69,7 @@ public class RSQLDistributionSetMetadataFieldsTest extends AbstractIntegrationTe private void assertRSQLQuery(final String rsqlParam, final long expectedEntities) { final Page findEnitity = distributionSetManagement - .findDistributionSetMetadataByDistributionSetId(distributionSetId, - RSQLUtility.parse(rsqlParam, DistributionSetMetadataFields.class), new PageRequest(0, 100)); + .findDistributionSetMetadataByDistributionSetId(distributionSetId, rsqlParam, new PageRequest(0, 100)); final long countAllEntities = findEnitity.getTotalElements(); assertThat(findEnitity).isNotNull(); assertThat(countAllEntities).isEqualTo(expectedEntities); diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLRolloutGroupFields.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLRolloutGroupFields.java index 18da430c7..83c31b31a 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLRolloutGroupFields.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLRolloutGroupFields.java @@ -13,11 +13,12 @@ import static org.fest.assertions.api.Assertions.assertThat; import org.eclipse.hawkbit.AbstractIntegrationTest; import org.eclipse.hawkbit.TestDataUtil; import org.eclipse.hawkbit.repository.RolloutGroupFields; +import org.eclipse.hawkbit.repository.jpa.model.JpaRollout; +import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup.RolloutGroupConditionBuilder; +import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup.RolloutGroupSuccessCondition; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.RolloutGroup; -import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupConditionBuilder; -import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupSuccessCondition; import org.junit.Before; import org.junit.Test; import org.springframework.data.domain.Page; @@ -75,8 +76,8 @@ public class RSQLRolloutGroupFields extends AbstractIntegrationTest { } private void assertRSQLQuery(final String rsqlParam, final long expcetedTargets) { - final Page findTargetPage = rolloutGroupManagement.findRolloutGroupsAll(rollout, - RSQLUtility.parse(rsqlParam, RolloutGroupFields.class), new PageRequest(0, 100)); + final Page findTargetPage = rolloutGroupManagement.findRolloutGroupsAll(rollout, rsqlParam, + new PageRequest(0, 100)); final long countTargetsAll = findTargetPage.getTotalElements(); assertThat(findTargetPage).isNotNull(); assertThat(countTargetsAll).isEqualTo(expcetedTargets); @@ -84,7 +85,7 @@ public class RSQLRolloutGroupFields extends AbstractIntegrationTest { private Rollout createRollout(final String name, final int amountGroups, final long distributionSetId, final String targetFilterQuery) { - final Rollout rollout = new Rollout(); + final Rollout rollout = new JpaRollout(); rollout.setDistributionSet(distributionSetManagement.findDistributionSetById(distributionSetId)); rollout.setName(name); rollout.setTargetFilterQuery(targetFilterQuery); diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLSoftwareModuleFieldTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLSoftwareModuleFieldTest.java index 0c113fd2b..b049daa0c 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLSoftwareModuleFieldTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLSoftwareModuleFieldTest.java @@ -12,6 +12,8 @@ import static org.fest.assertions.api.Assertions.assertThat; import org.eclipse.hawkbit.AbstractIntegrationTest; import org.eclipse.hawkbit.repository.SoftwareModuleFields; +import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; +import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleMetadata; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata; import org.junit.Before; @@ -29,18 +31,18 @@ public class RSQLSoftwareModuleFieldTest extends AbstractIntegrationTest { @Before public void setupBeforeTest() { - final SoftwareModule ah = softwareManagement - .createSoftwareModule(new SoftwareModule(appType, "agent-hub", "1.0.1", "agent-hub", "")); - softwareManagement.createSoftwareModule(new SoftwareModule(runtimeType, "oracle-jre", "1.7.2", "aa", "")); - softwareManagement.createSoftwareModule(new SoftwareModule(osType, "poky", "3.0.2", "aa", "")); + final JpaSoftwareModule ah = (JpaSoftwareModule) softwareManagement + .createSoftwareModule(new JpaSoftwareModule(appType, "agent-hub", "1.0.1", "agent-hub", "")); + softwareManagement.createSoftwareModule(new JpaSoftwareModule(runtimeType, "oracle-jre", "1.7.2", "aa", "")); + softwareManagement.createSoftwareModule(new JpaSoftwareModule(osType, "poky", "3.0.2", "aa", "")); - final SoftwareModule ah2 = softwareManagement - .createSoftwareModule(new SoftwareModule(appType, "agent-hub2", "1.0.1", "agent-hub2", "")); + final JpaSoftwareModule ah2 = (JpaSoftwareModule) softwareManagement + .createSoftwareModule(new JpaSoftwareModule(appType, "agent-hub2", "1.0.1", "agent-hub2", "")); - final SoftwareModuleMetadata softwareModuleMetadata = new SoftwareModuleMetadata("metaKey", ah, "metaValue"); + final SoftwareModuleMetadata softwareModuleMetadata = new JpaSoftwareModuleMetadata("metaKey", ah, "metaValue"); softwareManagement.createSoftwareModuleMetadata(softwareModuleMetadata); - final SoftwareModuleMetadata softwareModuleMetadata2 = new SoftwareModuleMetadata("metaKey", ah2, "value"); + final SoftwareModuleMetadata softwareModuleMetadata2 = new JpaSoftwareModuleMetadata("metaKey", ah2, "value"); softwareManagement.createSoftwareModuleMetadata(softwareModuleMetadata2); } @@ -101,8 +103,8 @@ public class RSQLSoftwareModuleFieldTest extends AbstractIntegrationTest { } private void assertRSQLQuery(final String rsqlParam, final long excpectedEntity) { - final Page find = softwareManagement.findSoftwareModulesByPredicate( - RSQLUtility.parse(rsqlParam, SoftwareModuleFields.class), new PageRequest(0, 100)); + final Page find = softwareManagement.findSoftwareModulesByPredicate(rsqlParam, + new PageRequest(0, 100)); final long countAll = find.getTotalElements(); assertThat(find).isNotNull(); assertThat(countAll).isEqualTo(excpectedEntity); diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLSoftwareModuleMetadataFieldsTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLSoftwareModuleMetadataFieldsTest.java index 44fa3e3cd..362428887 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLSoftwareModuleMetadataFieldsTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLSoftwareModuleMetadataFieldsTest.java @@ -16,6 +16,8 @@ import java.util.List; import org.eclipse.hawkbit.AbstractIntegrationTest; import org.eclipse.hawkbit.TestDataUtil; import org.eclipse.hawkbit.repository.SoftwareModuleMetadataFields; +import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; +import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleMetadata; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata; import org.junit.Before; @@ -36,13 +38,13 @@ public class RSQLSoftwareModuleMetadataFieldsTest extends AbstractIntegrationTes @Before public void setupBeforeTest() { final SoftwareModule softwareModule = softwareManagement.createSoftwareModule( - new SoftwareModule(TestDataUtil.findOrCreateSoftwareModuleType(softwareManagement, "application"), + new JpaSoftwareModule(TestDataUtil.findOrCreateSoftwareModuleType(softwareManagement, "application"), "application", "1.0.0", "Desc", "vendor Limited, California")); softwareModuleId = softwareModule.getId(); final List metadata = new ArrayList<>(); for (int i = 0; i < 5; i++) { - metadata.add(new SoftwareModuleMetadata("" + i, softwareModule, "" + i)); + metadata.add(new JpaSoftwareModuleMetadata("" + i, softwareModule, "" + i)); } softwareManagement.createSoftwareModuleMetadata(metadata); @@ -70,8 +72,7 @@ public class RSQLSoftwareModuleMetadataFieldsTest extends AbstractIntegrationTes private void assertRSQLQuery(final String rsqlParam, final long expectedEntities) { final Page findEnitity = softwareManagement - .findSoftwareModuleMetadataBySoftwareModuleId(softwareModuleId, - RSQLUtility.parse(rsqlParam, SoftwareModuleMetadataFields.class), new PageRequest(0, 100)); + .findSoftwareModuleMetadataBySoftwareModuleId(softwareModuleId, rsqlParam, new PageRequest(0, 100)); final long countAllEntities = findEnitity.getTotalElements(); assertThat(findEnitity).isNotNull(); assertThat(countAllEntities).isEqualTo(expectedEntities); diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLSoftwareModuleTypeFieldsTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLSoftwareModuleTypeFieldsTest.java index 268bddf50..37a501a3f 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLSoftwareModuleTypeFieldsTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLSoftwareModuleTypeFieldsTest.java @@ -59,8 +59,8 @@ public class RSQLSoftwareModuleTypeFieldsTest extends AbstractIntegrationTest { } private void assertRSQLQuery(final String rsqlParam, final long excpectedEntity) { - final Page find = softwareManagement.findSoftwareModuleTypesByPredicate( - RSQLUtility.parse(rsqlParam, SoftwareModuleTypeFields.class), new PageRequest(0, 100)); + final Page find = softwareManagement.findSoftwareModuleTypesByPredicate(rsqlParam, + new PageRequest(0, 100)); final long countAll = find.getTotalElements(); assertThat(find).isNotNull(); assertThat(countAll).isEqualTo(excpectedEntity); diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLTagFieldsTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLTagFieldsTest.java index b35ed13d1..85474e70e 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLTagFieldsTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLTagFieldsTest.java @@ -12,6 +12,8 @@ import static org.fest.assertions.api.Assertions.assertThat; import org.eclipse.hawkbit.AbstractIntegrationTest; import org.eclipse.hawkbit.repository.TagFields; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag; +import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag; import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.TargetTag; import org.junit.Before; @@ -31,9 +33,9 @@ public class RSQLTagFieldsTest extends AbstractIntegrationTest { public void seuptBeforeTest() { for (int i = 0; i < 5; i++) { - final TargetTag targetTag = new TargetTag("" + i, "" + i, i % 2 == 0 ? "red" : "blue"); + final TargetTag targetTag = new JpaTargetTag("" + i, "" + i, i % 2 == 0 ? "red" : "blue"); tagManagement.createTargetTag(targetTag); - final DistributionSetTag distributionSetTag = new DistributionSetTag("" + i, "" + i, + final DistributionSetTag distributionSetTag = new JpaDistributionSetTag("" + i, "" + i, i % 2 == 0 ? "red" : "blue"); tagManagement.createDistributionSetTag(distributionSetTag); } @@ -101,8 +103,8 @@ public class RSQLTagFieldsTest extends AbstractIntegrationTest { private void assertRSQLQueryDistributionSet(final String rsqlParam, final long expectedEntities) { - final Page findEnitity = tagManagement - .findAllDistributionSetTags(RSQLUtility.parse(rsqlParam, TagFields.class), new PageRequest(0, 100)); + final Page findEnitity = tagManagement.findAllDistributionSetTags(rsqlParam, + new PageRequest(0, 100)); final long countAllEntities = findEnitity.getTotalElements(); assertThat(findEnitity).isNotNull(); assertThat(countAllEntities).isEqualTo(expectedEntities); @@ -110,8 +112,7 @@ public class RSQLTagFieldsTest extends AbstractIntegrationTest { private void assertRSQLQueryTarget(final String rsqlParam, final long expectedEntities) { - final Page findEnitity = tagManagement - .findAllTargetTags(RSQLUtility.parse(rsqlParam, TagFields.class), new PageRequest(0, 100)); + final Page findEnitity = tagManagement.findAllTargetTags(rsqlParam, new PageRequest(0, 100)); final long countAllEntities = findEnitity.getTotalElements(); assertThat(findEnitity).isNotNull(); assertThat(countAllEntities).isEqualTo(expectedEntities); diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLTargetFieldTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLTargetFieldTest.java index 54efab860..37fffec99 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLTargetFieldTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLTargetFieldTest.java @@ -16,6 +16,9 @@ import java.util.Arrays; import org.eclipse.hawkbit.AbstractIntegrationTest; import org.eclipse.hawkbit.TestDataUtil; import org.eclipse.hawkbit.repository.TargetFields; +import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; +import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo; +import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetInfo; @@ -40,27 +43,27 @@ public class RSQLTargetFieldTest extends AbstractIntegrationTest { final DistributionSet ds = TestDataUtil.generateDistributionSet("AssignedDs", softwareManagement, distributionSetManagement); - final Target target = new Target("targetId123"); + final JpaTarget target = new JpaTarget("targetId123"); target.setDescription("targetId123"); - final TargetInfo targetInfo = new TargetInfo(target); + final TargetInfo targetInfo = new JpaTargetInfo(target); targetInfo.getControllerAttributes().put("revision", "1.1"); target.setTargetInfo(targetInfo); - target.getTargetInfo().setUpdateStatus(TargetUpdateStatus.PENDING); + ((JpaTargetInfo) target.getTargetInfo()).setUpdateStatus(TargetUpdateStatus.PENDING); targetManagement.createTarget(target); - final Target target2 = new Target("targetId1234"); + final JpaTarget target2 = new JpaTarget("targetId1234"); target2.setDescription("targetId1234"); - final TargetInfo targetInfo2 = new TargetInfo(target2); + final TargetInfo targetInfo2 = new JpaTargetInfo(target2); targetInfo2.getControllerAttributes().put("revision", "1.2"); target2.setTargetInfo(targetInfo2); targetManagement.createTarget(target2); - targetManagement.createTarget(new Target("targetId1235")); - targetManagement.createTarget(new Target("targetId1236")); + targetManagement.createTarget(new JpaTarget("targetId1235")); + targetManagement.createTarget(new JpaTarget("targetId1236")); - final TargetTag targetTag = tagManagement.createTargetTag(new TargetTag("Tag1")); - tagManagement.createTargetTag(new TargetTag("Tag2")); - tagManagement.createTargetTag(new TargetTag("Tag3")); - tagManagement.createTargetTag(new TargetTag("Tag4")); + final TargetTag targetTag = tagManagement.createTargetTag(new JpaTargetTag("Tag1")); + tagManagement.createTargetTag(new JpaTargetTag("Tag2")); + tagManagement.createTargetTag(new JpaTargetTag("Tag3")); + tagManagement.createTargetTag(new JpaTargetTag("Tag4")); targetManagement.assignTag(Arrays.asList(target.getControllerId(), target2.getControllerId()), targetTag); @@ -163,8 +166,7 @@ public class RSQLTargetFieldTest extends AbstractIntegrationTest { } private void assertRSQLQuery(final String rsqlParam, final long expcetedTargets) { - final Page findTargetPage = targetManagement - .findTargetsAll(RSQLUtility.parse(rsqlParam, TargetFields.class), new PageRequest(0, 100)); + final Page findTargetPage = targetManagement.findTargetsAll(rsqlParam, new PageRequest(0, 100)); final long countTargetsAll = findTargetPage.getTotalElements(); assertThat(findTargetPage).isNotNull(); assertThat(countTargetsAll).isEqualTo(expcetedTargets); diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/utils/RepositoryDataGenerator.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/utils/RepositoryDataGenerator.java index 73958e6fa..9cacd9a82 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/utils/RepositoryDataGenerator.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/utils/RepositoryDataGenerator.java @@ -33,12 +33,17 @@ import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.TargetManagement; +import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag; +import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; +import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType; +import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; +import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetTag; -import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetTag; @@ -129,7 +134,7 @@ public final class RepositoryDataGenerator { public void generateTestTagetGroup(final String group, final int sizeMultiplikator) { final DistributionSetTag dsTag = tagManagement - .createDistributionSetTag(new DistributionSetTag("For " + group + "s")); + .createDistributionSetTag(new JpaDistributionSetTag("For " + group + "s")); auditingHandler.setDateTimeProvider(() -> { final Calendar instance = Calendar.getInstance(); @@ -203,14 +208,14 @@ public final class RepositoryDataGenerator { "Controller retrieved update action and should start now the download."); // download - final ActionStatus download = new ActionStatus(); + final ActionStatus download = new JpaActionStatus(); download.setAction(action); download.setStatus(Status.DOWNLOAD); download.addMessage("Controller started download."); action = controllerManagement.addUpdateActionStatus(download); // warning - final ActionStatus warning = new ActionStatus(); + final ActionStatus warning = new JpaActionStatus(); warning.setAction(action); warning.setStatus(Status.WARNING); warning.addMessage("Some warning: " + jlorem.words(new Random().nextInt(50))); @@ -218,13 +223,13 @@ public final class RepositoryDataGenerator { // garbage for (int i = 0; i < new Random().nextInt(10); i++) { - final ActionStatus running = new ActionStatus(); + final ActionStatus running = new JpaActionStatus(); running.setAction(action); running.setStatus(Status.RUNNING); running.addMessage("Still running: " + jlorem.words(new Random().nextInt(50))); action = controllerManagement.addUpdateActionStatus(running); for (int g = 0; g < new Random().nextInt(5); g++) { - final ActionStatus rand = new ActionStatus(); + final ActionStatus rand = new JpaActionStatus(); rand.setAction(action); rand.setStatus(Status.RUNNING); rand.addMessage(jlorem.words(new Random().nextInt(50))); @@ -233,7 +238,7 @@ public final class RepositoryDataGenerator { } // close - final ActionStatus close = new ActionStatus(); + final ActionStatus close = new JpaActionStatus(); close.setAction(action); // with error @@ -262,7 +267,7 @@ public final class RepositoryDataGenerator { "Controller retrieved update action and should start now the download."); // close - final ActionStatus close = new ActionStatus(); + final ActionStatus close = new JpaActionStatus(); close.setAction(action); close.setStatus(Status.FINISHED); close.addMessage("Controller reported CLOSED with OK!"); @@ -274,7 +279,7 @@ public final class RepositoryDataGenerator { private List createTargetTestGroup(final String group, final int targets) { LOG.debug("createTargetTestGroup: create group {}", group); - final TargetTag targTag = tagManagement.createTargetTag(new TargetTag(group)); + final TargetTag targTag = tagManagement.createTargetTag(new JpaTargetTag(group)); final List targAs = targetManagement.createTargets(buildTargets(targets, group), TargetUpdateStatus.REGISTERED, System.currentTimeMillis() - new Random().nextInt(50_000_000), @@ -291,7 +296,7 @@ public final class RepositoryDataGenerator { final List result = new ArrayList(noOfTgts); for (int i = 0; i < noOfTgts; i++) { - final Target target = new Target(UUID.randomUUID().toString()); + final Target target = new JpaTarget(UUID.randomUUID().toString()); final StringBuilder builder = new StringBuilder(); builder.append(descriptionPrefix); @@ -331,7 +336,7 @@ public final class RepositoryDataGenerator { final String[] modulesTypes = { "HeadUnit_FW", "EDC17_FW", "OSGi_Bundle" }; final DistributionSetTag depTag = tagManagement - .createDistributionSetTag(new DistributionSetTag("deprecated")); + .createDistributionSetTag(new JpaDistributionSetTag("deprecated")); Arrays.stream(targetTestGroups).forEach(group -> { generateTestTagetGroup(group, sizeMultiplikator); @@ -346,11 +351,11 @@ public final class RepositoryDataGenerator { LOG.debug("initDemoRepo - start now Extra Software Modules and types"); Arrays.stream(modulesTypes).forEach(typeName -> { final SoftwareModuleType smtype = softwareManagement.createSoftwareModuleType( - new SoftwareModuleType(typeName.toLowerCase().replaceAll("\\s+", ""), typeName, + new JpaSoftwareModuleType(typeName.toLowerCase().replaceAll("\\s+", ""), typeName, jlorem.words(5), Integer.MAX_VALUE)); for (int i1 = 0; i1 < sizeMultiplikator; i1++) { - softwareManagement.createSoftwareModule(new SoftwareModule(smtype, typeName + i1, "1.0." + i1, + softwareManagement.createSoftwareModule(new JpaSoftwareModule(smtype, typeName + i1, "1.0." + i1, jlorem.words(5), "the " + typeName + " vendor Inc.")); } @@ -371,7 +376,7 @@ public final class RepositoryDataGenerator { // pending final DistributionSetTag dsTag = tagManagement - .createDistributionSetTag(new DistributionSetTag("OnlyAssignedTag")); + .createDistributionSetTag(new JpaDistributionSetTag("OnlyAssignedTag")); final DistributionSet ds = TestDataUtil.generateDistributionSet("Pending DS", "v1.0", softwareManagement, distributionSetManagement, Arrays.asList(new DistributionSetTag[] { dsTag })); diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/tenancy/MultiTenancyEntityTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/tenancy/MultiTenancyEntityTest.java index 67b9b5a26..ca0ef3840 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/tenancy/MultiTenancyEntityTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/tenancy/MultiTenancyEntityTest.java @@ -13,8 +13,10 @@ import static org.fest.assertions.api.Assertions.assertThat; import org.eclipse.hawkbit.AbstractIntegrationTest; import org.eclipse.hawkbit.WithSpringAuthorityRule; import org.eclipse.hawkbit.WithUser; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType; +import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; import org.eclipse.hawkbit.repository.model.DistributionSet; -import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.Target; import org.junit.Test; import org.springframework.data.domain.Page; @@ -162,7 +164,7 @@ public class MultiTenancyEntityTest extends AbstractIntegrationTest { private Target createTargetForTenant(final String controllerId, final String tenant) throws Exception { return securityRule.runAs(WithSpringAuthorityRule.withUserAndTenant("user", tenant), - () -> targetManagement.createTarget(new Target(controllerId))); + () -> targetManagement.createTarget(new JpaTarget(controllerId))); } private Slice findTargetsForTenant(final String tenant) throws Exception { @@ -180,12 +182,12 @@ public class MultiTenancyEntityTest extends AbstractIntegrationTest { private DistributionSet createDistributionSetForTenant(final String name, final String version, final String tenant) throws Exception { return securityRule.runAs(WithSpringAuthorityRule.withUserAndTenant("user", tenant), () -> { - final DistributionSet ds = new DistributionSet(); + final JpaDistributionSet ds = new JpaDistributionSet(); ds.setName(name); ds.setTenant(tenant); ds.setVersion(version); ds.setType(distributionSetManagement - .createDistributionSetType(new DistributionSetType("typetest", "test", "foobar"))); + .createDistributionSetType(new JpaDistributionSetType("typetest", "test", "foobar"))); return distributionSetManagement.createDistributionSet(ds); }); } diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/ArtifactStoreController.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/ArtifactStoreController.java index d6e057edd..a36443024 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/ArtifactStoreController.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/ArtifactStoreController.java @@ -149,7 +149,7 @@ public class ArtifactStoreController { actionStatus.addMessage( ControllerManagement.SERVER_MESSAGE_PREFIX + "Target downloads: " + request.getRequestURI()); } - controllerManagement.addInformationalActionStatus(actionStatus); + controllerManagement.addActionStatusMessage(actionStatus); return action; } diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/RootController.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/RootController.java index db5efd37c..14383f30b 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/RootController.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/controller/RootController.java @@ -150,7 +150,7 @@ public class RootController { return new ResponseEntity<>( DataConversionHelper.fromTarget(target, controllerManagement.findActionByTargetAndActive(target), - controllerManagement.getPollingTime(), tenantAware), + controllerManagement.findPollingTime(), tenantAware), HttpStatus.OK); } @@ -222,7 +222,7 @@ public class RootController { statusMessage.addMessage( ControllerManagement.SERVER_MESSAGE_PREFIX + "Target downloads " + request.getRequestURI()); } - controllerManagement.addInformationalActionStatus(statusMessage); + controllerManagement.addActionStatusMessage(statusMessage); return action; } @@ -371,7 +371,8 @@ public class RootController { return new ResponseEntity<>(HttpStatus.GONE); } - controllerManagement.addUpdateActionStatus(generateUpdateStatus(feedback, targetid, feedback.getId(), action)); + controllerManagement.addUpdateActionStatus(generateUpdateStatus(feedback, targetid, feedback.getId(), action), + action); return new ResponseEntity<>(HttpStatus.OK); @@ -545,7 +546,7 @@ public class RootController { } controllerManagement - .addCancelActionStatus(generateActionCancelStatus(feedback, target, feedback.getId(), action)); + .addCancelActionStatus(generateActionCancelStatus(feedback, target, feedback.getId(), action), action); return new ResponseEntity<>(HttpStatus.OK); } diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetResource.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetResource.java index 1a766c8c4..27231308b 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetResource.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetResource.java @@ -22,8 +22,8 @@ import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.repository.TargetFields; import org.eclipse.hawkbit.repository.TargetManagement; +import org.eclipse.hawkbit.repository.TargetWithActionType; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; -import org.eclipse.hawkbit.repository.jpa.TargetWithActionType; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetMetadata; import org.eclipse.hawkbit.repository.model.DsMetadataCompositeKey; diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTypeResource.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTypeResource.java index 8798f0ec8..f7346a6ff 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTypeResource.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/DistributionSetTypeResource.java @@ -69,7 +69,7 @@ public class DistributionSetTypeResource implements DistributionSetTypeRestApi { final Slice findModuleTypessAll; Long countModulesAll; if (rsqlParam != null) { - findModuleTypessAll = distributionSetManagement.findDistributionSetTypesAll( + findModuleTypessAll = distributionSetManagement.findDistributionSetTypesByPredicate( RSQLUtility.parse(rsqlParam, DistributionSetTypeFields.class), pageable); countModulesAll = ((Page) findModuleTypessAll).getTotalElements(); } else { diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/RolloutResource.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/RolloutResource.java index d8821f113..78cfefa0d 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/RolloutResource.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/RolloutResource.java @@ -178,7 +178,7 @@ public class RolloutResource implements RolloutRestApi { final Page findRolloutGroupsAll; if (rsqlParam != null) { - findRolloutGroupsAll = this.rolloutGroupManagement.findRolloutGroupsAll(rollout, + findRolloutGroupsAll = this.rolloutGroupManagement.findRolloutGroupsByPredicate(rollout, RSQLUtility.parse(rsqlParam, RolloutGroupFields.class), pageable); } else { findRolloutGroupsAll = this.rolloutGroupManagement.findRolloutGroupsByRolloutId(rolloutId, pageable); diff --git a/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/DistributionSetResourceTest.java b/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/DistributionSetResourceTest.java index 3705e8da3..6254da992 100644 --- a/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/DistributionSetResourceTest.java +++ b/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/DistributionSetResourceTest.java @@ -30,12 +30,12 @@ import org.eclipse.hawkbit.AbstractIntegrationTest; import org.eclipse.hawkbit.MockMvcResultPrinter; import org.eclipse.hawkbit.TestDataUtil; import org.eclipse.hawkbit.WithUser; +import org.eclipse.hawkbit.repository.ActionRepository; import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; -import org.eclipse.hawkbit.repository.jpa.ActionRepository; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; @@ -890,7 +890,7 @@ public class DistributionSetResourceTest extends AbstractIntegrationTest { for (final String msg : msgs) { statusMessages.addMessage(msg); } - controllerManagament.addUpdateActionStatus(statusMessages); + controllerManagament.addUpdateActionStatus(statusMessages, updActA); return targetManagement.findTargetByControllerID(t.getControllerId()); } diff --git a/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/TargetResourceTest.java b/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/TargetResourceTest.java index 2d3a9707e..8d27d5114 100644 --- a/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/TargetResourceTest.java +++ b/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/TargetResourceTest.java @@ -108,7 +108,8 @@ public class TargetResourceTest extends AbstractIntegrationTest { final List actions = generateTargetWithTwoUpdatesWithOneOverride(knownTargetId); actions.get(0).setStatus(Status.FINISHED); controllerManagament.addUpdateActionStatus( - new ActionStatus(actions.get(0), Status.FINISHED, System.currentTimeMillis(), "testmessage")); + new ActionStatus(actions.get(0), Status.FINISHED, System.currentTimeMillis(), "testmessage"), + actions.get(0)); final PageRequest pageRequest = new PageRequest(0, 1000, Direction.ASC, ActionFields.ID.getFieldName()); final ActionStatus status = deploymentManagement @@ -1283,8 +1284,8 @@ public class TargetResourceTest extends AbstractIntegrationTest { final Pageable pageReq = new PageRequest(0, 100); final Action action = actionRepository.findByDistributionSet(pageReq, savedSet).getContent().get(0); - final ActionStatus actionStatus = new ActionStatus(action, Status.FINISHED, 0L); - controllerManagement.addUpdateActionStatus(actionStatus); + final ActionStatus actionStatus = new ActionStatus(action, Status.FINISHED, 0l); + controllerManagement.addUpdateActionStatus(actionStatus, action); } /** From f0a78369f2a1a3a93f043cd9d1951ce66f2f4516 Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Sat, 21 May 2016 21:01:23 +0200 Subject: [PATCH 17/54] Continued on the model API extraction. Merged rest api split branch. Signed-off-by: Kai Zimmermann --- .../eventbus/event/RolloutChangeEvent.java | 2 - .../repository/ControllerManagement.java | 8 + .../repository/DeploymentManagement.java | 9 +- .../repository/DistributionSetManagement.java | 74 ++-- .../{jpa => }/OffsetBasedPageRequest.java | 12 +- .../repository/RolloutGroupManagement.java | 16 +- .../hawkbit/repository/RolloutManagement.java | 18 +- .../repository/SoftwareManagement.java | 37 +- .../hawkbit/repository/TagManagement.java | 12 +- .../TargetFilterQueryManagement.java | 6 + .../repository/jpa/BaseEntityRepository.java | 4 +- .../jpa/JpaControllerManagement.java | 27 +- .../jpa/JpaDeploymentManagement.java | 29 +- .../jpa/JpaDistributionSetManagement.java | 58 +++- .../jpa/JpaRolloutGroupManagement.java | 31 +- .../repository/jpa/JpaRolloutManagement.java | 41 ++- .../repository/jpa/JpaSoftwareManagement.java | 69 +++- .../repository/jpa/JpaTagManagement.java | 46 ++- .../jpa/JpaTargetFilterQueryManagement.java | 14 +- .../repository/jpa/JpaTargetManagement.java | 37 +- .../jpa/RolloutGroupRepository.java | 2 +- .../repository/jpa/RolloutRepository.java | 2 +- ...Artifact.java => AbstractJpaArtifact.java} | 2 +- ...Entity.java => AbstractJpaBaseEntity.java} | 6 +- ...MetaData.java => AbstractJpaMetaData.java} | 8 +- ...ntity.java => AbstractJpaNamedEntity.java} | 6 +- ...a => AbstractJpaNamedVersionedEntity.java} | 6 +- .../{JpaTag.java => AbstractJpaTag.java} | 6 +- ... => AbstractJpaTenantAwareBaseEntity.java} | 6 +- .../repository/jpa/model/JpaAction.java | 88 +---- .../repository/jpa/model/JpaActionStatus.java | 19 +- .../jpa/model/JpaDistributionSet.java | 57 +-- .../jpa/model/JpaDistributionSetMetadata.java | 3 +- .../jpa/model/JpaDistributionSetTag.java | 2 +- .../jpa/model/JpaDistributionSetType.java | 93 +---- .../jpa/model/JpaExternalArtifact.java | 8 +- .../model/JpaExternalArtifactProvider.java | 6 +- .../jpa/model/JpaLocalArtifact.java | 10 +- .../repository/jpa/model/JpaRollout.java | 72 +--- .../repository/jpa/model/JpaRolloutGroup.java | 283 +-------------- .../jpa/model/JpaSoftwareModule.java | 4 +- .../jpa/model/JpaSoftwareModuleMetadata.java | 2 +- .../jpa/model/JpaSoftwareModuleType.java | 20 +- .../repository/jpa/model/JpaTarget.java | 8 +- .../jpa/model/JpaTargetFilterQuery.java | 2 +- .../repository/jpa/model/JpaTargetInfo.java | 65 +--- .../repository/jpa/model/JpaTargetTag.java | 2 +- .../jpa/model/JpaTenantConfiguration.java | 2 +- .../jpa/model/JpaTenantMetaData.java | 2 +- .../jpa/model/RolloutTargetGroupId.java | 2 +- .../hawkbit/repository/model/Action.java | 139 ++++++-- .../repository/model/ActionStatus.java | 41 ++- .../model/ActionWithStatusCount.java | 24 -- .../hawkbit/repository/model/Artifact.java | 23 +- .../hawkbit/repository/model/BaseEntity.java | 22 ++ .../repository/model/DistributionSet.java | 61 +++- .../model/DistributionSetMetadata.java | 9 +- .../repository/model/DistributionSetTag.java | 8 + .../repository/model/DistributionSetType.java | 38 +- .../repository/model/ExternalArtifact.java | 18 +- .../model/ExternalArtifactProvider.java | 22 +- .../repository/model/LocalArtifact.java | 15 +- .../hawkbit/repository/model/MetaData.java | 16 + .../hawkbit/repository/model/NamedEntity.java | 20 +- .../model/NamedVersionedEntity.java | 11 + .../hawkbit/repository/model/Rollout.java | 101 +++++- .../repository/model/RolloutGroup.java | 119 ++++++- .../repository/model/SoftwareModuleType.java | 4 + .../hawkbit/repository/model/TargetInfo.java | 4 +- .../condition/PauseRolloutGroupAction.java | 2 +- ...artNextGroupRolloutGroupSuccessAction.java | 2 +- .../org/eclipse/hawkbit/TestDataUtil.java | 10 +- .../hawkbit/repository/ActionTest.java | 5 +- .../repository/ControllerManagementTest.java | 2 +- .../repository/DeploymentManagementTest.java | 23 +- .../DistributionSetManagementTest.java | 15 +- .../repository/RolloutManagementTest.java | 19 +- .../repository/SoftwareManagementTest.java | 2 +- .../rsql/RSQLRolloutGroupFields.java | 4 +- .../RSQLSoftwareModuleTypeFieldsTest.java | 2 +- .../tenancy/MultiTenancyEntityTest.java | 2 +- .../hawkbit/rest/util/JsonBuilder.java | 2 +- .../artifacts/details/ArtifactBeanQuery.java | 5 +- .../smtable/BaseSwModuleBeanQuery.java | 2 +- .../smtable/ProxyBaseSoftwareModuleItem.java | 4 +- .../SoftwareModuleAddUpdateWindow.java | 6 +- .../CreateUpdateSoftwareTypeLayout.java | 6 +- .../common/DistributionSetTypeBeanQuery.java | 7 +- .../common/SoftwareModuleTypeBeanQuery.java | 4 +- .../ui/components/ProxyDistribution.java | 3 +- .../hawkbit/ui/components/ProxyTarget.java | 5 +- .../ui/components/ProxyTargetFilter.java | 4 +- .../CreateUpdateDistSetTypeLayout.java | 10 +- .../dstable/ManageDistBeanQuery.java | 6 +- .../smtable/SwModuleBeanQuery.java | 2 +- .../CreateOrUpdateFilterHeader.java | 2 +- .../actionhistory/ActionHistoryTable.java | 22 +- .../DistributionAddUpdateWindowLayout.java | 2 +- .../dstable/DistributionBeanQuery.java | 6 +- ...eateUpdateDistributionTagLayoutWindow.java | 9 +- .../dstag/DistributionTagBeanQuery.java | 2 +- .../dstag/DistributionTagButtons.java | 8 +- .../targettable/BulkUploadHandler.java | 2 +- .../TargetAddUpdateWindowLayout.java | 2 +- .../targettable/TargetBeanQuery.java | 2 +- .../management/targettable/TargetTable.java | 2 +- .../CreateUpdateTargetTagLayout.java | 2 +- .../targettag/TargetTagBeanQuery.java | 2 +- .../targettag/TargetTagFilterButtons.java | 8 +- .../rollout/AddUpdateRolloutWindowLayout.java | 7 +- .../ui/rollout/rollout/ProxyRollout.java | 14 +- .../rolloutgroup/ProxyRolloutGroup.java | 328 +++++++++--------- .../hawkbit/ui/utils/HawkbitCommonUtil.java | 8 +- 113 files changed, 1374 insertions(+), 1247 deletions(-) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/{jpa => }/OffsetBasedPageRequest.java (87%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/{JpaArtifact.java => AbstractJpaArtifact.java} (93%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/{JpaBaseEntity.java => AbstractJpaBaseEntity.java} (96%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/{JpaMetaData.java => AbstractJpaMetaData.java} (90%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/{JpaNamedEntity.java => AbstractJpaNamedEntity.java} (87%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/{JpaNamedVersionedEntity.java => AbstractJpaNamedVersionedEntity.java} (82%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/{JpaTag.java => AbstractJpaTag.java} (86%) rename hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/{JpaTenantAwareBaseEntity.java => AbstractJpaTenantAwareBaseEntity.java} (93%) diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/RolloutChangeEvent.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/RolloutChangeEvent.java index 8f15602b5..576a6b99c 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/RolloutChangeEvent.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/RolloutChangeEvent.java @@ -8,8 +8,6 @@ */ package org.eclipse.hawkbit.eventbus.event; -import org.eclipse.hawkbit.eventbus.event.AbstractEvent; - /** * Event declaration for the UI to notify the UI that a rollout has been * changed. diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java index 47ff3c49f..dd91ee07a 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java @@ -9,6 +9,7 @@ package org.eclipse.hawkbit.repository; import java.net.URI; +import java.util.Collection; import java.util.List; import java.util.Map; @@ -275,4 +276,11 @@ public interface ControllerManagement { */ ActionStatus generateActionStatus(); + ActionStatus generateActionStatus(Action action, Status status, Long occurredAt, final String message); + + ActionStatus generateActionStatus(Action action, final Status status, Long occurredAt, + final Collection messages); + + ActionStatus generateActionStatus(Action action, Status status, Long occurredAt); + } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java index 070594d4e..f58af4ca6 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java @@ -322,8 +322,10 @@ public interface DeploymentManagement { * @return the corresponding {@link Page} of {@link ActionStatus} */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - Page findActionStatusByAction(@NotNull Pageable pageReq, @NotNull Action action, - boolean withMessages); + Page findActionStatusByAction(@NotNull Pageable pageReq, @NotNull Action action); + + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + Page findActionStatusByActionWithMessages(@NotNull Pageable pageReq, @NotNull Action action); /** * Retrieves all {@link Action}s of a specific target ordered by action ID. @@ -445,4 +447,7 @@ public interface DeploymentManagement { * @return {@link Action} object */ Action generateAction(); + + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + Page findActionStatusAll(@NotNull Pageable pageable); } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java index 2574230b3..9b4dcb8c7 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java @@ -83,6 +83,15 @@ public interface DistributionSetManagement { @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) Long countDistributionSetsAll(); + /** + * Count all {@link DistributionSet}s in the repository that are not marked + * as deleted. + * + * @return number of {@link DistributionSet}s + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + Long countDistributionSetsByType(@NotNull DistributionSetType type); + /** * @return number of {@link DistributionSetType}s in the repository. */ @@ -261,20 +270,6 @@ public interface DistributionSetManagement { @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) DistributionSet findDistributionSetByNameAndVersion(@NotEmpty String distributionName, @NotEmpty String version); - /** - * Retrieves {@link DistributionSet} List for overview purposes (no - * {@link SoftwareModule}s and {@link DistributionSetTag}s). - * - * Please use {@link #findDistributionSetListWithDetails(Iterable)} if - * details are required. - * - * @param dist - * List of {@link DistributionSet} IDs to be found - * @return the found {@link DistributionSet}s - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - List findDistributionSetsAll(Collection dist); - /** * finds all meta data by the given distribution set id. * @@ -305,6 +300,20 @@ public interface DistributionSetManagement { Page findDistributionSetMetadataByDistributionSetId(@NotNull Long distributionSetId, @NotNull String rsqlParam, @NotNull Pageable pageable); + /** + * Retrieves {@link DistributionSet} List for overview purposes (no + * {@link SoftwareModule}s and {@link DistributionSetTag}s). + * + * Please use {@link #findDistributionSetListWithDetails(Iterable)} if + * details are required. + * + * @param dist + * List of {@link DistributionSet} IDs to be found + * @return the found {@link DistributionSet}s + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + List findDistributionSetsAll(Collection dist); + // TODO discuss: use enum instead of the true,false,null switch ? /** * finds all {@link DistributionSet}s. @@ -328,7 +337,8 @@ public interface DistributionSetManagement { * @return all found {@link DistributionSet}s */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Page findDistributionSetsAll(@NotNull Pageable pageReq, Boolean deleted, Boolean complete); + Page findDistributionSetsByDeletedAndOrCompleted(@NotNull Pageable pageReq, Boolean deleted, + Boolean complete); /** * finds all {@link DistributionSet}s. @@ -445,6 +455,26 @@ public interface DistributionSetManagement { @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) DistributionSetMetadata findOne(@NotNull DsMetadataCompositeKey id); + /** + * Generates an empty {@link DistributionSet} without persisting it. + * + * @return {@link DistributionSet} object + */ + DistributionSet generateDistributionSet(); + + DistributionSetMetadata generateDistributionSetMetadata(); + + DistributionSetMetadata generateDistributionSetMetadata(DistributionSet distributionSet, String key, String value); + + /** + * Generates an empty {@link DistributionSetType} without persisting it. + * + * @return {@link DistributionSetType} object + */ + DistributionSetType generateDistributionSetType(); + + DistributionSetType generateDistributionSetType(String key, String name, String description); + /** * Checks if a {@link DistributionSet} is currently in use by a target in * the repository. @@ -567,17 +597,7 @@ public interface DistributionSetManagement { @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) DistributionSetType updateDistributionSetType(@NotNull DistributionSetType dsType); - /** - * Generates an empty {@link DistributionSetType} without persisting it. - * - * @return {@link DistributionSetType} object - */ - DistributionSetType generateDistributionSetType(); + DistributionSet generateDistributionSet(String name, String version, String description, DistributionSetType type, + Collection moduleList); - /** - * Generates an empty {@link DistributionSet} without persisting it. - * - * @return {@link DistributionSet} object - */ - DistributionSet generateDistributionSet(); } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/OffsetBasedPageRequest.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/OffsetBasedPageRequest.java similarity index 87% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/OffsetBasedPageRequest.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/OffsetBasedPageRequest.java index 80bb85461..f28047666 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/OffsetBasedPageRequest.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/OffsetBasedPageRequest.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.jpa; +package org.eclipse.hawkbit.repository; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Sort; @@ -14,13 +14,9 @@ import org.springframework.data.domain.Sort; /** * An implementation of the {@link PageRequest} which is offset based by means * the offset is given and not the page number as in the original - * {@link PageRequest} implemntation where the offset is generated. Due that the - * REST-API is working with {@code offset} and {@code limit} parameter we need - * an offset based page request for JPA. - * - * @author Michael Hirsch - * @since 0.2.2 - * + * {@link PageRequest} implementation where the offset is generated. Due that + * the REST-API is working with {@code offset} and {@code limit} parameter we + * need an offset based page request. */ public final class OffsetBasedPageRequest extends PageRequest { diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupManagement.java index efad0100c..bf58e3053 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupManagement.java @@ -33,12 +33,12 @@ public interface RolloutGroupManagement { * * @param rolloutId * the ID of the rollout to filter the {@link RolloutGroup}s - * @param page + * @param pageable * the page request to sort and limit the result * @return a page of found {@link RolloutGroup}s */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - Page findAllRolloutGroupsWithDetailedStatus(@NotNull Long rolloutId, @NotNull Pageable page); + Page findAllRolloutGroupsWithDetailedStatus(@NotNull Long rolloutId, @NotNull Pageable pageable); // TODO discuss: target read perm missing? /** @@ -79,13 +79,13 @@ public interface RolloutGroupManagement { * @param specification * the specification to filter the result set based on attributes * of the {@link RolloutGroup} - * @param page + * @param pageable * the page request to sort and limit the result * @return a page of found {@link RolloutGroup}s */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) Page findRolloutGroupsAll(@NotNull Rollout rollout, @NotNull String rsqlParam, - @NotNull Pageable page); + @NotNull Pageable pageable); /** * Retrieves a page of {@link RolloutGroup}s filtered by a given @@ -93,12 +93,12 @@ public interface RolloutGroupManagement { * * @param rolloutId * the ID of the rollout to filter the {@link RolloutGroup}s - * @param page + * @param pageable * the page request to sort and limit the result * @return a page of found {@link RolloutGroup}s */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - Page findRolloutGroupsByRolloutId(@NotNull Long rolloutId, @NotNull Pageable page); + Page findRolloutGroupsByRolloutId(@NotNull Long rolloutId, @NotNull Pageable pageable); // TODO discuss: target read perm missing? /** @@ -122,14 +122,14 @@ public interface RolloutGroupManagement { * rollout group * @param specification * the specification for filtering the targets of a rollout group - * @param page + * @param pageable * the page request to sort and limit the result * * @return Page list of targets of a rollout group */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) Page findRolloutGroupTargets(@NotNull RolloutGroup rolloutGroup, @NotNull String rsqlParam, - @NotNull Pageable page); + @NotNull Pageable pageable); /** * Get count of targets in different status in rollout group. diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java index 140273439..f75ff545b 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java @@ -13,11 +13,11 @@ import javax.validation.constraints.NotNull; import org.eclipse.hawkbit.eventbus.event.RolloutGroupCreatedEvent; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; import org.eclipse.hawkbit.repository.exception.RolloutIllegalStateException; -import org.eclipse.hawkbit.repository.jpa.model.JpaRollout.RolloutStatus; -import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup.RolloutGroupConditions; -import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup.RolloutGroupStatus; import org.eclipse.hawkbit.repository.model.Rollout; +import org.eclipse.hawkbit.repository.model.Rollout.RolloutStatus; import org.eclipse.hawkbit.repository.model.RolloutGroup; +import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupStatus; +import org.eclipse.hawkbit.repository.model.RolloutGroupConditions; import org.hibernate.validator.constraints.NotEmpty; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -149,36 +149,36 @@ public interface RolloutManagement { /** * Retrieves all rollouts. * - * @param page + * @param pageable * the page request to sort and limit the result * @return a page of found rollouts */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - Page findAll(@NotNull Pageable page); + Page findAll(@NotNull Pageable pageable); /** * Get count of targets in different status in rollout. * - * @param page + * @param pageable * the page request to sort and limit the result * @return a list of rollouts with details of targets count for different * statuses * */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - Page findAllRolloutsWithDetailedStatus(@NotNull Pageable page); + Page findAllRolloutsWithDetailedStatus(@NotNull Pageable pageable); /** * Retrieves all rollouts found by the given specification. * * @param specification * the specification to filter rollouts - * @param page + * @param pageable * the page request to sort and limit the result * @return a page of found rollouts */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) - Page findAllWithDetailedStatusByPredicate(@NotNull String rsqlParam, @NotNull Pageable page); + Page findAllWithDetailedStatusByPredicate(@NotNull String rsqlParam, @NotNull Pageable pageable); /** * Finds rollouts by given text in name or description. diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java index 1802b1dcc..a586c0bfb 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java @@ -259,7 +259,7 @@ public interface SoftwareManagement { * in case the meta data does not exists for the given key */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - SoftwareModuleMetadata findSoftwareModuleMetadata(@NotNull SwMetadataCompositeKey id); + SoftwareModuleMetadata findSoftwareModuleMetadata(@NotNull SoftwareModule softwareModule, @NotEmpty String key); /** * finds all meta data by the given software module id. @@ -409,7 +409,7 @@ public interface SoftwareManagement { * @return the found {@link SoftwareModuleType}s */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Page findSoftwareModuleTypesByPredicate(@NotNull String rsqlParam, @NotNull Pageable pageable); + Page findSoftwareModuleTypesAll(@NotNull String rsqlParam, @NotNull Pageable pageable); /** * Retrieves software module including details ( @@ -478,4 +478,37 @@ public interface SoftwareManagement { * @return {@link SoftwareModule} object */ SoftwareModule generateSoftwareModule(); + + /** + * Generates a {@link SoftwareModule} without persisting it. + * + * @param type + * of the {@link SoftwareModule} + * @param name + * abstract name of the {@link SoftwareModule} + * @param version + * of the {@link SoftwareModule} + * @param description + * of the {@link SoftwareModule} + * @param vendor + * of the {@link SoftwareModule} + * + * @return {@link SoftwareModule} object + */ + SoftwareModule generateSoftwareModule(SoftwareModuleType type, String name, String version, String description, + String vendor); + + /** + * Generates an empty {@link SoftwareModuleMetadata} pair without persisting + * it. + * + * @return {@link SoftwareModuleMetadata} object + */ + SoftwareModuleMetadata generateSoftwareModuleMetadata(); + + SoftwareModuleMetadata generateSoftwareModuleMetadata(SoftwareModule softwareModule, String key, String value); + + SoftwareModuleType generateSoftwareModuleType(final String key, final String name, final String description, + final int maxAssignments); + } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TagManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TagManagement.java index fa38e318b..786308e70 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TagManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TagManagement.java @@ -148,13 +148,13 @@ public interface TagManagement { /** * returns all {@link TargetTag}s. * - * @param pageReq + * @param pageable * page parameter * * @return all {@link TargetTag}s */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - Page findAllTargetTags(@NotNull Pageable pageReq); + Page findAllTargetTags(@NotNull Pageable pageable); /** * Retrieves all target tags based on the given specification. @@ -245,4 +245,12 @@ public interface TagManagement { */ DistributionSetTag generateDistributionSetTag(); + TargetTag generateTargetTag(String name, String description, String colour); + + TargetTag generateTargetTag(String name); + + DistributionSetTag generateDistributionSetTag(String name, String description, String colour); + + DistributionSetTag generateDistributionSetTag(String name); + } \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagement.java index caf045c93..127e22e63 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagement.java @@ -96,4 +96,10 @@ public interface TargetFilterQueryManagement { @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET) TargetFilterQuery updateTargetFilterQuery(@NotNull TargetFilterQuery targetFilterQuery); + /** + * Generates an empty {@link TargetFilterQuery} without persisting it. + * + * @return {@link TargetFilterQuery} object + */ + TargetFilterQuery generateTargetFilterQuery(); } \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/BaseEntityRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/BaseEntityRepository.java index 92bec68a2..0d9f72b37 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/BaseEntityRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/BaseEntityRepository.java @@ -10,7 +10,7 @@ package org.eclipse.hawkbit.repository.jpa; import java.io.Serializable; -import org.eclipse.hawkbit.repository.jpa.model.JpaTenantAwareBaseEntity; +import org.eclipse.hawkbit.repository.jpa.model.AbstractJpaTenantAwareBaseEntity; import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.repository.NoRepositoryBean; @@ -28,7 +28,7 @@ import org.springframework.transaction.annotation.Transactional; */ @NoRepositoryBean @Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) -public interface BaseEntityRepository +public interface BaseEntityRepository extends PagingAndSortingRepository { /** diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java index c7a229bf0..09283f67c 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java @@ -10,6 +10,7 @@ package org.eclipse.hawkbit.repository.jpa; import java.net.URI; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.Map; @@ -286,7 +287,7 @@ public class JpaControllerManagement implements ControllerManagement { return actionRepository.save(mergedAction); } - private void handleErrorOnAction(final Action mergedAction, final Target mergedTarget) { + private void handleErrorOnAction(final JpaAction mergedAction, final Target mergedTarget) { mergedAction.setActive(false); mergedAction.setStatus(Status.ERROR); mergedTarget.setAssignedDistributionSet(null); @@ -437,4 +438,28 @@ public class JpaControllerManagement implements ControllerManagement { public ActionStatus generateActionStatus() { return new JpaActionStatus(); } + + @Override + @Transactional(propagation = Propagation.SUPPORTS) + public ActionStatus generateActionStatus(final Action action, final Status status, final Long occurredAt, + final String message) { + return new JpaActionStatus((JpaAction) action, status, occurredAt, message); + } + + @Override + @Transactional(propagation = Propagation.SUPPORTS) + public ActionStatus generateActionStatus(final Action action, final Status status, final Long occurredAt, + final Collection messages) { + + final ActionStatus result = new JpaActionStatus((JpaAction) action, status, occurredAt, null); + messages.forEach(result::addMessage); + + return result; + } + + @Override + @Transactional(propagation = Propagation.SUPPORTS) + public ActionStatus generateActionStatus(final Action action, final Status status, final Long occurredAt) { + return new JpaActionStatus(action, status, occurredAt); + } } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java index 3dea0e549..e0ace822d 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java @@ -598,11 +598,11 @@ public class JpaDeploymentManagement implements DeploymentManagement { return convertAcPage(actionRepository.findAll((Specification) (root, query, cb) -> cb .and(specification.toPredicate(root, query, cb), cb.equal(root.get(JpaAction_.target), target)), - pageable)); + pageable), pageable); } - private static Page convertAcPage(final Page findAll) { - return new PageImpl<>(new ArrayList<>(findAll.getContent())); + private static Page convertAcPage(final Page findAll, final Pageable pageable) { + return new PageImpl<>(new ArrayList<>(findAll.getContent()), pageable, findAll.getTotalElements()); } @Override @@ -656,13 +656,13 @@ public class JpaDeploymentManagement implements DeploymentManagement { } @Override - public Page findActionStatusByAction(final Pageable pageReq, final Action action, - final boolean withMessages) { - if (withMessages) { - return actionStatusRepository.getByAction(pageReq, (JpaAction) action); - } else { - return actionStatusRepository.findByAction(pageReq, (JpaAction) action); - } + public Page findActionStatusByAction(final Pageable pageReq, final Action action) { + return actionStatusRepository.findByAction(pageReq, (JpaAction) action); + } + + @Override + public Page findActionStatusByActionWithMessages(final Pageable pageReq, final Action action) { + return actionStatusRepository.getByAction(pageReq, (JpaAction) action); } @Override @@ -682,4 +682,13 @@ public class JpaDeploymentManagement implements DeploymentManagement { public Action generateAction() { return new JpaAction(); } + + @Override + public Page findActionStatusAll(final Pageable pageable) { + return convertAcSPage(actionStatusRepository.findAll(pageable), pageable); + } + + private static Page convertAcSPage(final Page findAll, final Pageable pageable) { + return new PageImpl<>(new ArrayList<>(findAll.getContent()), pageable, findAll.getTotalElements()); + } } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java index 4e33d4960..e17c737e7 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java @@ -298,11 +298,12 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { final DistributionSetFilter distributionSetFilter) { final List> specList = buildDistributionSetSpecifications( distributionSetFilter); - return convertDsPage(findByCriteriaAPI(pageable, specList)); + return convertDsPage(findByCriteriaAPI(pageable, specList), pageable); } - private static Page convertDsPage(final Page findAll) { - return new PageImpl<>(new ArrayList<>(findAll.getContent())); + private static Page convertDsPage(final Page findAll, + final Pageable pageable) { + return new PageImpl<>(new ArrayList<>(findAll.getContent()), pageable, findAll.getTotalElements()); } /** @@ -323,8 +324,8 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { } @Override - public Page findDistributionSetsAll(final Pageable pageReq, final Boolean deleted, - final Boolean complete) { + public Page findDistributionSetsByDeletedAndOrCompleted(final Pageable pageReq, + final Boolean deleted, final Boolean complete) { final List> specList = new ArrayList<>(); if (deleted != null) { @@ -337,7 +338,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { specList.add(spec); } - return convertDsPage(findByCriteriaAPI(pageReq, specList)); + return convertDsPage(findByCriteriaAPI(pageReq, specList), pageReq); } @Override @@ -351,7 +352,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { specList.add(DistributionSetSpecification.isDeleted(deleted)); } specList.add(spec); - return convertDsPage(findByCriteriaAPI(pageReq, specList)); + return convertDsPage(findByCriteriaAPI(pageReq, specList), pageReq); } @Override @@ -528,7 +529,8 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { return convertMdPage(distributionSetMetadataRepository .findAll((Specification) (root, query, cb) -> cb.equal( root.get(JpaDistributionSetMetadata_.distributionSet).get(JpaDistributionSet_.id), - distributionSetId), pageable)); + distributionSetId), pageable), + pageable); } @Override @@ -543,11 +545,13 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { .findAll((Specification) (root, query, cb) -> cb.and( cb.equal(root.get(JpaDistributionSetMetadata_.distributionSet) .get(JpaDistributionSet_.id), distributionSetId), - spec.toPredicate(root, query, cb)), pageable)); + spec.toPredicate(root, query, cb)), pageable), + pageable); } - private static Page convertMdPage(final Page findAll) { - return new PageImpl<>(new ArrayList<>(findAll.getContent())); + private static Page convertMdPage(final Page findAll, + final Pageable pageable) { + return new PageImpl<>(new ArrayList<>(findAll.getContent()), pageable, findAll.getTotalElements()); } @Override @@ -745,4 +749,36 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { public DistributionSet generateDistributionSet() { return new JpaDistributionSet(); } + + @Override + @Transactional(propagation = Propagation.SUPPORTS) + public DistributionSetMetadata generateDistributionSetMetadata() { + return new JpaDistributionSetMetadata(); + } + + @Override + @Transactional(propagation = Propagation.SUPPORTS) + public DistributionSetMetadata generateDistributionSetMetadata(final DistributionSet distributionSet, + final String key, final String value) { + return new JpaDistributionSetMetadata(key, distributionSet, value); + } + + @Override + @Transactional(propagation = Propagation.SUPPORTS) + public DistributionSetType generateDistributionSetType(final String key, final String name, + final String description) { + return new JpaDistributionSetType(key, name, description); + } + + @Override + @Transactional(propagation = Propagation.SUPPORTS) + public DistributionSet generateDistributionSet(final String name, final String version, final String description, + final DistributionSetType type, final Collection moduleList) { + return new JpaDistributionSet(name, version, description, type, moduleList); + } + + @Override + public Long countDistributionSetsByType(final DistributionSetType type) { + return distributionSetRepository.countByType((JpaDistributionSetType) type); + } } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutGroupManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutGroupManagement.java index b3ea8fb74..cde2a0a15 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutGroupManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutGroupManagement.java @@ -26,7 +26,6 @@ import org.eclipse.hawkbit.repository.RolloutGroupManagement; import org.eclipse.hawkbit.repository.TargetFields; import org.eclipse.hawkbit.repository.jpa.model.JpaAction; import org.eclipse.hawkbit.repository.jpa.model.JpaAction_; -import org.eclipse.hawkbit.repository.jpa.model.JpaRollout.RolloutStatus; import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup; import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup_; import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; @@ -35,6 +34,7 @@ import org.eclipse.hawkbit.repository.jpa.model.RolloutTargetGroup; import org.eclipse.hawkbit.repository.jpa.model.RolloutTargetGroup_; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Rollout; +import org.eclipse.hawkbit.repository.model.Rollout.RolloutStatus; import org.eclipse.hawkbit.repository.model.RolloutGroup; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetWithActionStatus; @@ -46,7 +46,6 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Slice; import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Isolation; @@ -80,20 +79,21 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement { } @Override - public Page findRolloutGroupsByRolloutId(final Long rolloutId, final Pageable page) { - return convertPage(rolloutGroupRepository.findByRolloutId(rolloutId, page)); + public Page findRolloutGroupsByRolloutId(final Long rolloutId, final Pageable pageable) { + return convertPage(rolloutGroupRepository.findByRolloutId(rolloutId, pageable), pageable); } - private static Page convertPage(final Slice findAll) { - return new PageImpl<>(new ArrayList<>(findAll.getContent())); + private static Page convertPage(final Page findAll, final Pageable pageable) { + return new PageImpl<>(new ArrayList<>(findAll.getContent()), pageable, findAll.getTotalElements()); } - private static Page convertTPage(final Page findAll) { - return new PageImpl<>(new ArrayList<>(findAll.getContent())); + private static Page convertTPage(final Page findAll, final Pageable pageable) { + return new PageImpl<>(new ArrayList<>(findAll.getContent()), pageable, findAll.getTotalElements()); } @Override - public Page findRolloutGroupsAll(final Rollout rollout, final String rsqlParam, final Pageable page) { + public Page findRolloutGroupsAll(final Rollout rollout, final String rsqlParam, + final Pageable pageable) { final Specification specification = RSQLUtility.parse(rsqlParam, RolloutGroupFields.class); @@ -103,12 +103,13 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement { (root, query, criteriaBuilder) -> criteriaBuilder.and( criteriaBuilder.equal(root.get(JpaRolloutGroup_.rollout), rollout), specification.toPredicate(root, query, criteriaBuilder)), - page)); + pageable), + pageable); } @Override - public Page findAllRolloutGroupsWithDetailedStatus(final Long rolloutId, final Pageable page) { - final Page rolloutGroups = rolloutGroupRepository.findByRolloutId(rolloutId, page); + public Page findAllRolloutGroupsWithDetailedStatus(final Long rolloutId, final Pageable pageable) { + final Page rolloutGroups = rolloutGroupRepository.findByRolloutId(rolloutId, pageable); final List rolloutGroupIds = rolloutGroups.getContent().stream().map(rollout -> rollout.getId()) .collect(Collectors.toList()); final Map> allStatesForRollout = getStatusCountItemForRolloutGroup( @@ -120,7 +121,7 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement { rolloutGroup.setTotalTargetCountStatus(totalTargetCountStatus); } - return convertPage(rolloutGroups); + return convertPage(rolloutGroups, pageable); } @Override @@ -145,7 +146,7 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement { @Override public Page findRolloutGroupTargets(final RolloutGroup rolloutGroup, final String rsqlParam, - final Pageable page) { + final Pageable pageable) { final Specification rsqlSpecification = RSQLUtility.parse(rsqlParam, TargetFields.class); @@ -153,7 +154,7 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement { final ListJoin rolloutTargetJoin = root.join(JpaTarget_.rolloutTargetGroup); return criteriaBuilder.and(rsqlSpecification.toPredicate(root, query, criteriaBuilder), criteriaBuilder.equal(rolloutTargetJoin.get(RolloutTargetGroup_.rolloutGroup), rolloutGroup)); - }, page)); + }, pageable), pageable); } @Override diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java index ec13c4f29..744c863ba 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java @@ -20,24 +20,25 @@ import javax.persistence.EntityManager; import org.eclipse.hawkbit.cache.CacheWriteNotify; import org.eclipse.hawkbit.repository.DeploymentManagement; +import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.RolloutFields; import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.exception.RolloutIllegalStateException; import org.eclipse.hawkbit.repository.jpa.model.JpaRollout; -import org.eclipse.hawkbit.repository.jpa.model.JpaRollout.RolloutStatus; import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup; -import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup.RolloutGroupConditions; -import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup.RolloutGroupErrorCondition; -import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup.RolloutGroupStatus; -import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup.RolloutGroupSuccessCondition; import org.eclipse.hawkbit.repository.jpa.model.JpaRollout_; import org.eclipse.hawkbit.repository.jpa.model.RolloutTargetGroup; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.ActionType; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Rollout; +import org.eclipse.hawkbit.repository.model.Rollout.RolloutStatus; import org.eclipse.hawkbit.repository.model.RolloutGroup; +import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupErrorCondition; +import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupStatus; +import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupSuccessCondition; +import org.eclipse.hawkbit.repository.model.RolloutGroupConditions; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TotalTargetCountActionStatus; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; @@ -137,22 +138,26 @@ public class JpaRolloutManagement implements RolloutManagement { private static final Set startingRollouts = ConcurrentHashMap.newKeySet(); @Override - public Page findAll(final Pageable page) { - return convertPage(rolloutRepository.findAll(page)); + public Page findAll(final Pageable pageable) { + return convertPage(rolloutRepository.findAll(pageable), pageable); } - private static Page convertPage(final Slice findAll) { - return new PageImpl<>(new ArrayList<>(findAll.getContent())); + private static Page convertPage(final Page findAll, final Pageable pageable) { + return new PageImpl<>(new ArrayList<>(findAll.getContent()), pageable, findAll.getTotalElements()); + } + + private static Slice convertPage(final Slice findAll, final Pageable pageable) { + return new PageImpl<>(new ArrayList<>(findAll.getContent()), pageable, 0); } @Override - public Page findAllWithDetailedStatusByPredicate(final String rsqlParam, final Pageable page) { + public Page findAllWithDetailedStatusByPredicate(final String rsqlParam, final Pageable pageable) { final Specification specification = RSQLUtility.parse(rsqlParam, RolloutFields.class); - final Page findAll = rolloutRepository.findAll(specification, page); + final Page findAll = rolloutRepository.findAll(specification, pageable); setRolloutStatusDetails(findAll); - return convertPage(findAll); + return convertPage(findAll, pageable); } @Override @@ -570,7 +575,7 @@ public class JpaRolloutManagement implements RolloutManagement { final Specification specs = likeNameOrDescription(searchText); final Slice findAll = criteriaNoCountDao.findAll(specs, pageable, JpaRollout.class); setRolloutStatusDetails(findAll); - return convertPage(findAll); + return convertPage(findAll, pageable); } @Override @@ -604,10 +609,10 @@ public class JpaRolloutManagement implements RolloutManagement { * */ @Override - public Page findAllRolloutsWithDetailedStatus(final Pageable page) { - final Page rollouts = rolloutRepository.findAll(page); + public Page findAllRolloutsWithDetailedStatus(final Pageable pageable) { + final Page rollouts = rolloutRepository.findAll(pageable); setRolloutStatusDetails(rollouts); - return convertPage(rollouts); + return convertPage(rollouts, pageable); } @@ -618,7 +623,7 @@ public class JpaRolloutManagement implements RolloutManagement { .getStatusCountByRolloutId(rolloutId); final TotalTargetCountStatus totalTargetCountStatus = new TotalTargetCountStatus(rolloutStatusCountItems, rollout.getTotalTargets()); - rollout.setTotalTargetCountStatus(totalTargetCountStatus); + ((JpaRollout) rollout).setTotalTargetCountStatus(totalTargetCountStatus); return rollout; } @@ -636,7 +641,7 @@ public class JpaRolloutManagement implements RolloutManagement { for (final Rollout rollout : rollouts) { final TotalTargetCountStatus totalTargetCountStatus = new TotalTargetCountStatus( allStatesForRollout.get(rollout.getId()), rollout.getTotalTargets()); - rollout.setTotalTargetCountStatus(totalTargetCountStatus); + ((JpaRollout) rollout).setTotalTargetCountStatus(totalTargetCountStatus); } } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java index 7ea7e46be..b98ff0754 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java @@ -183,15 +183,21 @@ public class JpaSoftwareManagement implements SoftwareManagement { spec = SoftwareModuleSpecification.isDeletedFalse(); specList.add(spec); - return convertSmPage(findSwModuleByCriteriaAPI(pageable, specList)); + return convertSmPage(findSwModuleByCriteriaAPI(pageable, specList), pageable); } - private static Page convertSmPage(final Slice findAll) { - return new PageImpl<>(new ArrayList<>(findAll.getContent())); + private static Slice convertSmPage(final Slice findAll, + final Pageable pageable) { + return new PageImpl<>(new ArrayList<>(findAll.getContent()), pageable, 0); } - private static Page convertSmMdPage(final Slice findAll) { - return new PageImpl<>(new ArrayList<>(findAll.getContent())); + private static Page convertSmPage(final Page findAll, final Pageable pageable) { + return new PageImpl<>(new ArrayList<>(findAll.getContent()), pageable, findAll.getTotalElements()); + } + + private static Page convertSmMdPage(final Page findAll, + final Pageable pageable) { + return new PageImpl<>(new ArrayList<>(findAll.getContent()), pageable, findAll.getTotalElements()); } @Override @@ -288,7 +294,7 @@ public class JpaSoftwareManagement implements SoftwareManagement { specList.add(spec); - return convertSmPage(findSwModuleByCriteriaAPI(pageable, specList)); + return convertSmPage(findSwModuleByCriteriaAPI(pageable, specList), pageable); } @Override @@ -311,20 +317,20 @@ public class JpaSoftwareManagement implements SoftwareManagement { public Page findSoftwareModulesByPredicate(final String rsqlParam, final Pageable pageable) { final Specification spec = RSQLUtility.parse(rsqlParam, SoftwareModuleFields.class); - return convertSmPage(softwareModuleRepository.findAll(spec, pageable)); + return convertSmPage(softwareModuleRepository.findAll(spec, pageable), pageable); } @Override - public Page findSoftwareModuleTypesByPredicate(final String rsqlParam, - final Pageable pageable) { + public Page findSoftwareModuleTypesAll(final String rsqlParam, final Pageable pageable) { final Specification spec = RSQLUtility.parse(rsqlParam, SoftwareModuleTypeFields.class); - return convertSmTPage(softwareModuleTypeRepository.findAll(spec, pageable)); + return convertSmTPage(softwareModuleTypeRepository.findAll(spec, pageable), pageable); } - private static Page convertSmTPage(final Slice findAll) { - return new PageImpl<>(new ArrayList<>(findAll.getContent())); + private static Page convertSmTPage(final Page findAll, + final Pageable pageable) { + return new PageImpl<>(new ArrayList<>(findAll.getContent()), pageable, findAll.getTotalElements()); } @Override @@ -361,7 +367,7 @@ public class JpaSoftwareManagement implements SoftwareManagement { specList.add(spec); - return convertSmPage(findSwModuleByCriteriaAPI(pageable, specList)); + return convertSmPage(findSwModuleByCriteriaAPI(pageable, specList), pageable); } @Override @@ -614,11 +620,16 @@ public class JpaSoftwareManagement implements SoftwareManagement { cb.equal(root.get(JpaSoftwareModuleMetadata_.softwareModule) .get(JpaSoftwareModule_.id), softwareModuleId), spec.toPredicate(root, query, cb)), - pageable)); + pageable), + pageable); } @Override - public SoftwareModuleMetadata findSoftwareModuleMetadata(final SwMetadataCompositeKey id) { + public SoftwareModuleMetadata findSoftwareModuleMetadata(final SoftwareModule softwareModule, final String key) { + return findSoftwareModuleMetadata(new SwMetadataCompositeKey(softwareModule, key)); + } + + private SoftwareModuleMetadata findSoftwareModuleMetadata(final SwMetadataCompositeKey id) { final SoftwareModuleMetadata findOne = softwareModuleMetadataRepository.findOne(id); if (findOne == null) { throw new EntityNotFoundException("Metadata with key '" + id.getKey() + "' does not exist"); @@ -664,4 +675,32 @@ public class JpaSoftwareManagement implements SoftwareManagement { return new JpaSoftwareModule(); } + @Override + @Transactional(propagation = Propagation.SUPPORTS) + public SoftwareModule generateSoftwareModule(final SoftwareModuleType type, final String name, final String version, + final String description, final String vendor) { + + return new JpaSoftwareModule(type, name, version, description, vendor); + } + + @Override + @Transactional(propagation = Propagation.SUPPORTS) + public SoftwareModuleMetadata generateSoftwareModuleMetadata() { + return new JpaSoftwareModuleMetadata(); + } + + @Override + @Transactional(propagation = Propagation.SUPPORTS) + public SoftwareModuleMetadata generateSoftwareModuleMetadata(final SoftwareModule softwareModule, final String key, + final String value) { + return new JpaSoftwareModuleMetadata(key, softwareModule, value); + } + + @Override + @Transactional(propagation = Propagation.SUPPORTS) + public SoftwareModuleType generateSoftwareModuleType(final String key, final String name, final String description, + final int maxAssignments) { + return new JpaSoftwareModuleType(key, name, description, maxAssignments); + } + } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTagManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTagManagement.java index 4ff9c6e2b..c8358b7ec 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTagManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTagManagement.java @@ -151,15 +151,16 @@ public class JpaTagManagement implements TagManagement { public Page findAllTargetTags(final String rsqlParam, final Pageable pageable) { final Specification spec = RSQLUtility.parse(rsqlParam, TagFields.class); - return convertTPage(targetTagRepository.findAll(spec, pageable)); + return convertTPage(targetTagRepository.findAll(spec, pageable), pageable); } - private static Page convertTPage(final Page findAll) { - return new PageImpl<>(new ArrayList<>(findAll.getContent())); + private static Page convertTPage(final Page findAll, final Pageable pageable) { + return new PageImpl<>(new ArrayList<>(findAll.getContent()), pageable, findAll.getTotalElements()); } - private static Page convertDsPage(final Page findAll) { - return new PageImpl<>(new ArrayList<>(findAll.getContent())); + private static Page convertDsPage(final Page findAll, + final Pageable pageable) { + return new PageImpl<>(new ArrayList<>(findAll.getContent()), pageable, findAll.getTotalElements()); } @Override @@ -270,20 +271,20 @@ public class JpaTagManagement implements TagManagement { } @Override - public Page findAllTargetTags(final Pageable pageReq) { - return convertTPage(targetTagRepository.findAll(pageReq)); + public Page findAllTargetTags(final Pageable pageable) { + return convertTPage(targetTagRepository.findAll(pageable), pageable); } @Override - public Page findAllDistributionSetTags(final Pageable pageReq) { - return convertDsPage(distributionSetTagRepository.findAll(pageReq)); + public Page findAllDistributionSetTags(final Pageable pageable) { + return convertDsPage(distributionSetTagRepository.findAll(pageable), pageable); } @Override public Page findAllDistributionSetTags(final String rsqlParam, final Pageable pageable) { final Specification spec = RSQLUtility.parse(rsqlParam, TagFields.class); - return convertDsPage(distributionSetTagRepository.findAll(spec, pageable)); + return convertDsPage(distributionSetTagRepository.findAll(spec, pageable), pageable); } @Override @@ -298,4 +299,29 @@ public class JpaTagManagement implements TagManagement { return new JpaDistributionSetTag(); } + @Override + @Transactional(propagation = Propagation.SUPPORTS) + public TargetTag generateTargetTag(final String name, final String description, final String colour) { + return new JpaTargetTag(name, description, colour); + } + + @Override + @Transactional(propagation = Propagation.SUPPORTS) + public DistributionSetTag generateDistributionSetTag(final String name, final String description, + final String colour) { + return new JpaDistributionSetTag(name, description, colour); + } + + @Override + @Transactional(propagation = Propagation.SUPPORTS) + public TargetTag generateTargetTag(final String name) { + return new JpaTargetTag(name); + } + + @Override + @Transactional(propagation = Propagation.SUPPORTS) + public DistributionSetTag generateDistributionSetTag(final String name) { + return new JpaDistributionSetTag(name); + } + } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetFilterQueryManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetFilterQueryManagement.java index 5dd33b762..8bc4a0833 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetFilterQueryManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetFilterQueryManagement.java @@ -64,11 +64,12 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme @Override public Page findAllTargetFilterQuery(final Pageable pageable) { - return convertPage(targetFilterQueryRepository.findAll(pageable)); + return convertPage(targetFilterQueryRepository.findAll(pageable), pageable); } - private static Page convertPage(final Page findAll) { - return new PageImpl<>(new ArrayList<>(findAll.getContent())); + private static Page convertPage(final Page findAll, + final Pageable pageable) { + return new PageImpl<>(new ArrayList<>(findAll.getContent()), pageable, findAll.getTotalElements()); } @Override @@ -77,7 +78,7 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme if (!Strings.isNullOrEmpty(name)) { specList.add(TargetFilterQuerySpecification.likeName(name)); } - return convertPage(findTargetFilterQueryByCriteriaAPI(pageable, specList)); + return convertPage(findTargetFilterQueryByCriteriaAPI(pageable, specList), pageable); } private Page findTargetFilterQueryByCriteriaAPI(final Pageable pageable, @@ -108,4 +109,9 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme return targetFilterQueryRepository.save((JpaTargetFilterQuery) targetFilterQuery); } + @Override + public TargetFilterQuery generateTargetFilterQuery() { + return new JpaTargetFilterQuery(); + } + } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetManagement.java index 0e900e655..d73a9ae5f 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetManagement.java @@ -145,7 +145,7 @@ public class JpaTargetManagement implements TargetManagement { } return cb.conjunction(); }; - return convertPage(criteriaNoCountDao.findAll(spec, pageable, JpaTarget.class)); + return convertPage(criteriaNoCountDao.findAll(spec, pageable, JpaTarget.class), pageable); } @Override @@ -159,7 +159,7 @@ public class JpaTargetManagement implements TargetManagement { } private Page findTargetsBySpec(final Specification spec, final Pageable pageable) { - return convertPage(targetRepository.findAll(spec, pageable)); + return convertPage(targetRepository.findAll(spec, pageable), pageable); } @Override @@ -222,17 +222,21 @@ public class JpaTargetManagement implements TargetManagement { final Specification spec = RSQLUtility.parse(rsqlParam, TargetFields.class); - return convertPage(targetRepository.findAll((Specification) (root, query, cb) -> cb.and( - TargetSpecifications.hasAssignedDistributionSet(distributionSetID).toPredicate(root, query, cb), - spec.toPredicate(root, query, cb)), pageReq)); + return convertPage( + targetRepository + .findAll((Specification) (root, query, + cb) -> cb.and(TargetSpecifications.hasAssignedDistributionSet(distributionSetID) + .toPredicate(root, query, cb), spec.toPredicate(root, query, cb)), + pageReq), + pageReq); } - private static Page convertPage(final Page findAll) { - return new PageImpl<>(new ArrayList<>(findAll.getContent())); + private static Page convertPage(final Page findAll, final Pageable pageable) { + return new PageImpl<>(new ArrayList<>(findAll.getContent()), pageable, findAll.getTotalElements()); } - private static Slice convertPage(final Slice findAll) { - return new PageImpl<>(new ArrayList<>(findAll.getContent())); + private static Slice convertPage(final Slice findAll, final Pageable pageable) { + return new PageImpl<>(new ArrayList<>(findAll.getContent()), pageable, 0); } @Override @@ -246,9 +250,13 @@ public class JpaTargetManagement implements TargetManagement { final Specification spec = RSQLUtility.parse(rsqlParam, TargetFields.class); - return convertPage(targetRepository.findAll((Specification) (root, query, cb) -> cb.and( - TargetSpecifications.hasInstalledDistributionSet(distributionSetId).toPredicate(root, query, cb), - spec.toPredicate(root, query, cb)), pageable)); + return convertPage( + targetRepository + .findAll((Specification) (root, query, + cb) -> cb.and(TargetSpecifications.hasInstalledDistributionSet(distributionSetId) + .toPredicate(root, query, cb), spec.toPredicate(root, query, cb)), + pageable), + pageable); } @Override @@ -296,10 +304,11 @@ public class JpaTargetManagement implements TargetManagement { private Slice findByCriteriaAPI(final Pageable pageable, final List> specList) { if (specList == null || specList.isEmpty()) { - return convertPage(criteriaNoCountDao.findAll(pageable, JpaTarget.class)); + return convertPage(criteriaNoCountDao.findAll(pageable, JpaTarget.class), pageable); } return convertPage( - criteriaNoCountDao.findAll(SpecificationsBuilder.combineWithAnd(specList), pageable, JpaTarget.class)); + criteriaNoCountDao.findAll(SpecificationsBuilder.combineWithAnd(specList), pageable, JpaTarget.class), + pageable); } private Long countByCriteriaAPI(final List> specList) { diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/RolloutGroupRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/RolloutGroupRepository.java index 0eaa237aa..134f7b18d 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/RolloutGroupRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/RolloutGroupRepository.java @@ -12,9 +12,9 @@ import java.util.List; import org.eclipse.hawkbit.repository.jpa.model.JpaRollout; import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup; -import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup.RolloutGroupStatus; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.RolloutGroup; +import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupStatus; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/RolloutRepository.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/RolloutRepository.java index e73c12952..74d47d99a 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/RolloutRepository.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/RolloutRepository.java @@ -11,8 +11,8 @@ package org.eclipse.hawkbit.repository.jpa; import java.util.List; import org.eclipse.hawkbit.repository.jpa.model.JpaRollout; -import org.eclipse.hawkbit.repository.jpa.model.JpaRollout.RolloutStatus; import org.eclipse.hawkbit.repository.model.Rollout; +import org.eclipse.hawkbit.repository.model.Rollout.RolloutStatus; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaArtifact.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaArtifact.java similarity index 93% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaArtifact.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaArtifact.java index be0b5e1ac..7a5bea6b7 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaArtifact.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaArtifact.java @@ -19,7 +19,7 @@ import org.eclipse.hawkbit.repository.model.SoftwareModule; * {@link SoftwareModule}. */ @MappedSuperclass -public abstract class JpaArtifact extends JpaTenantAwareBaseEntity implements Artifact { +public abstract class AbstractJpaArtifact extends AbstractJpaTenantAwareBaseEntity implements Artifact { private static final long serialVersionUID = 1L; @Column(name = "sha1_hash", length = 40, nullable = true) diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaBaseEntity.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaBaseEntity.java similarity index 96% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaBaseEntity.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaBaseEntity.java index cfe4ada52..b7e340085 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaBaseEntity.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaBaseEntity.java @@ -34,7 +34,7 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener; @MappedSuperclass @Access(AccessType.FIELD) @EntityListeners({ AuditingEntityListener.class, CacheFieldEntityListener.class, EntityPropertyChangeListener.class }) -public abstract class JpaBaseEntity implements BaseEntity { +public abstract class AbstractJpaBaseEntity implements BaseEntity { private static final long serialVersionUID = 1L; @Id @@ -54,7 +54,7 @@ public abstract class JpaBaseEntity implements BaseEntity { /** * Default constructor needed for JPA entities. */ - public JpaBaseEntity() { + public AbstractJpaBaseEntity() { // Default constructor needed for JPA entities. } @@ -167,7 +167,7 @@ public abstract class JpaBaseEntity implements BaseEntity { if (!(this.getClass().isInstance(obj))) { return false; } - final JpaBaseEntity other = (JpaBaseEntity) obj; + final AbstractJpaBaseEntity other = (AbstractJpaBaseEntity) obj; if (id == null) { if (other.id != null) { return false; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaMetaData.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaMetaData.java similarity index 90% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaMetaData.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaMetaData.java index f2d905d89..5a3f23ac3 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaMetaData.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaMetaData.java @@ -20,7 +20,7 @@ import org.eclipse.hawkbit.repository.model.MetaData; * */ @MappedSuperclass -public abstract class JpaMetaData implements MetaData { +public abstract class AbstractJpaMetaData implements MetaData { private static final long serialVersionUID = 1L; @Id @@ -31,13 +31,13 @@ public abstract class JpaMetaData implements MetaData { @Basic private String value; - public JpaMetaData(final String key, final String value) { + public AbstractJpaMetaData(final String key, final String value) { super(); this.key = key; this.value = value; } - public JpaMetaData() { + public AbstractJpaMetaData() { // Default constructor needed for JPA entities } @@ -81,7 +81,7 @@ public abstract class JpaMetaData implements MetaData { if (!(this.getClass().isInstance(obj))) { return false; } - final JpaMetaData other = (JpaMetaData) obj; + final AbstractJpaMetaData other = (AbstractJpaMetaData) obj; if (key == null) { if (other.key != null) { return false; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaNamedEntity.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaNamedEntity.java similarity index 87% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaNamedEntity.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaNamedEntity.java index e4e48ac36..196e636d9 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaNamedEntity.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaNamedEntity.java @@ -19,7 +19,7 @@ import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity; * addition to their technical ID. */ @MappedSuperclass -public abstract class JpaNamedEntity extends JpaTenantAwareBaseEntity implements NamedEntity { +public abstract class AbstractJpaNamedEntity extends AbstractJpaTenantAwareBaseEntity implements NamedEntity { private static final long serialVersionUID = 1L; @Column(name = "name", nullable = false, length = 64) @@ -31,7 +31,7 @@ public abstract class JpaNamedEntity extends JpaTenantAwareBaseEntity implements /** * Default constructor. */ - public JpaNamedEntity() { + public AbstractJpaNamedEntity() { super(); } @@ -43,7 +43,7 @@ public abstract class JpaNamedEntity extends JpaTenantAwareBaseEntity implements * @param description * of the {@link NamedEntity} */ - public JpaNamedEntity(final String name, final String description) { + public AbstractJpaNamedEntity(final String name, final String description) { this.name = name; this.description = description; } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaNamedVersionedEntity.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaNamedVersionedEntity.java similarity index 82% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaNamedVersionedEntity.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaNamedVersionedEntity.java index 33a7036d5..785666b67 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaNamedVersionedEntity.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaNamedVersionedEntity.java @@ -19,7 +19,7 @@ import org.eclipse.hawkbit.repository.model.NamedVersionedEntity; * */ @MappedSuperclass -public abstract class JpaNamedVersionedEntity extends JpaNamedEntity implements NamedVersionedEntity { +public abstract class AbstractJpaNamedVersionedEntity extends AbstractJpaNamedEntity implements NamedVersionedEntity { private static final long serialVersionUID = 1L; @Column(name = "version", nullable = false, length = 64) @@ -34,12 +34,12 @@ public abstract class JpaNamedVersionedEntity extends JpaNamedEntity implements * of the entity * @param description */ - public JpaNamedVersionedEntity(final String name, final String version, final String description) { + public AbstractJpaNamedVersionedEntity(final String name, final String version, final String description) { super(name, description); this.version = version; } - JpaNamedVersionedEntity() { + AbstractJpaNamedVersionedEntity() { super(); } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTag.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaTag.java similarity index 86% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTag.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaTag.java index ee4da0824..653b678bc 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTag.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaTag.java @@ -19,13 +19,13 @@ import org.eclipse.hawkbit.repository.model.Tag; * */ @MappedSuperclass -public abstract class JpaTag extends JpaNamedEntity implements Tag { +public abstract class AbstractJpaTag extends AbstractJpaNamedEntity implements Tag { private static final long serialVersionUID = 1L; @Column(name = "colour", nullable = true, length = 16) private String colour; - protected JpaTag() { + protected AbstractJpaTag() { super(); } @@ -39,7 +39,7 @@ public abstract class JpaTag extends JpaNamedEntity implements Tag { * @param colour * of tag in UI */ - public JpaTag(final String name, final String description, final String colour) { + public AbstractJpaTag(final String name, final String description, final String colour) { super(name, description); this.colour = colour; } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTenantAwareBaseEntity.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaTenantAwareBaseEntity.java similarity index 93% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTenantAwareBaseEntity.java rename to hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaTenantAwareBaseEntity.java index e921e6915..134d0c788 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTenantAwareBaseEntity.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaTenantAwareBaseEntity.java @@ -27,7 +27,7 @@ import org.eclipse.persistence.annotations.TenantDiscriminatorColumn; @MappedSuperclass @TenantDiscriminatorColumn(name = "tenant", length = 40) @Multitenant(MultitenantType.SINGLE_TABLE) -public abstract class JpaTenantAwareBaseEntity extends JpaBaseEntity implements TenantAwareBaseEntity { +public abstract class AbstractJpaTenantAwareBaseEntity extends AbstractJpaBaseEntity implements TenantAwareBaseEntity { private static final long serialVersionUID = 1L; @Column(name = "tenant", nullable = false, insertable = false, updatable = false, length = 40) @@ -36,7 +36,7 @@ public abstract class JpaTenantAwareBaseEntity extends JpaBaseEntity implements /** * Default constructor needed for JPA entities. */ - public JpaTenantAwareBaseEntity() { + public AbstractJpaTenantAwareBaseEntity() { // Default constructor needed for JPA entities. } @@ -101,7 +101,7 @@ public abstract class JpaTenantAwareBaseEntity extends JpaBaseEntity implements if (!super.equals(obj)) { return false; } - final JpaTenantAwareBaseEntity other = (JpaTenantAwareBaseEntity) obj; + final AbstractJpaTenantAwareBaseEntity other = (AbstractJpaTenantAwareBaseEntity) obj; if (tenant == null) { if (other.tenant != null) { return false; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaAction.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaAction.java index 1080b35fd..7ad7d7a60 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaAction.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaAction.java @@ -36,21 +36,11 @@ import org.eclipse.hawkbit.repository.model.ActionStatus; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.RolloutGroup; -import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.persistence.annotations.CascadeOnDelete; /** - *

- * Applicable transition changes of the {@link SoftwareModule}s state of a - * {@link Target}, e.g. install, uninstall, update and preparations for the - * transition change, i.e. download. - *

- * - *

- * Actions are managed by the SP server and applied to the targets by the - * client. - *

+ * JPA implementation of {@link Action}. */ @Table(name = "sp_action", indexes = { @Index(name = "sp_idx_action_01", columnList = "tenant,distribution_set"), @Index(name = "sp_idx_action_02", columnList = "tenant,target,active"), @@ -59,12 +49,9 @@ import org.eclipse.persistence.annotations.CascadeOnDelete; @NamedEntityGraph(name = "Action.all", attributeNodes = { @NamedAttributeNode("distributionSet"), @NamedAttributeNode(value = "target", subgraph = "target.ds") }, subgraphs = @NamedSubgraph(name = "target.ds", attributeNodes = @NamedAttributeNode("assignedDistributionSet"))) }) @Entity -public class JpaAction extends JpaTenantAwareBaseEntity implements Action { +public class JpaAction extends AbstractJpaTenantAwareBaseEntity implements Action { private static final long serialVersionUID = 1L; - /** - * the {@link DistributionSet} which should be installed by this action. - */ @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "distribution_set", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_action_ds")) private JpaDistributionSet distributionSet; @@ -106,33 +93,16 @@ public class JpaAction extends JpaTenantAwareBaseEntity implements Action { @CacheField(key = CacheKeys.DOWNLOAD_PROGRESS_PERCENT) private int downloadProgressPercent; - /** - * @return the distributionSet - */ @Override public DistributionSet getDistributionSet() { return distributionSet; } - /** - * @param distributionSet - * the distributionSet to set - */ @Override public void setDistributionSet(final DistributionSet distributionSet) { this.distributionSet = (JpaDistributionSet) distributionSet; } - /** - * @return true when action is in state {@link Status#CANCELING} or - * {@link Status#CANCELED}, false otherwise - */ - @Override - public boolean isCancelingOrCanceled() { - return status == Status.CANCELING || status == Status.CANCELED; - } - - @Override public void setActive(final boolean active) { this.active = active; } @@ -152,7 +122,6 @@ public class JpaAction extends JpaTenantAwareBaseEntity implements Action { return downloadProgressPercent; } - @Override public void setDownloadProgressPercent(final int downloadProgressPercent) { this.downloadProgressPercent = downloadProgressPercent; } @@ -162,14 +131,10 @@ public class JpaAction extends JpaTenantAwareBaseEntity implements Action { return active; } - @Override public void setActionType(final ActionType actionType) { this.actionType = actionType; } - /** - * @return the actionType - */ @Override public ActionType getActionType() { return actionType; @@ -195,7 +160,6 @@ public class JpaAction extends JpaTenantAwareBaseEntity implements Action { return forcedTime; } - @Override public void setForcedTime(final long forcedTime) { this.forcedTime = forcedTime; } @@ -205,7 +169,6 @@ public class JpaAction extends JpaTenantAwareBaseEntity implements Action { return rolloutGroup; } - @Override public void setRolloutGroup(final RolloutGroup rolloutGroup) { this.rolloutGroup = (JpaRolloutGroup) rolloutGroup; } @@ -215,57 +178,10 @@ public class JpaAction extends JpaTenantAwareBaseEntity implements Action { return rollout; } - @Override public void setRollout(final Rollout rollout) { this.rollout = (JpaRollout) rollout; } - /** - * checks if the {@link #forcedTime} is hit by the given - * {@code hitTimeMillis}, by means if the given milliseconds are greater - * than the forcedTime. - * - * @param hitTimeMillis - * the milliseconds, mostly the - * {@link System#currentTimeMillis()} - * @return {@code true} if this {@link #type} is in - * {@link ActionType#TIMEFORCED} and the given {@code hitTimeMillis} - * is greater than the {@link #forcedTime} otherwise {@code false} - */ - @Override - public boolean isHitAutoForceTime(final long hitTimeMillis) { - if (actionType == ActionType.TIMEFORCED) { - return hitTimeMillis >= forcedTime; - } - return false; - } - - /** - * @return {@code true} if either the {@link #type} is - * {@link ActionType#FORCED} or {@link ActionType#TIMEFORCED} but - * then if the {@link #forcedTime} has been exceeded otherwise - * always {@code false} - */ - @Override - public boolean isForce() { - switch (actionType) { - case FORCED: - return true; - case TIMEFORCED: - return isHitAutoForceTime(System.currentTimeMillis()); - default: - return false; - } - } - - /** - * @return true when action is forced, false otherwise - */ - @Override - public boolean isForced() { - return actionType == ActionType.FORCED; - } - @Override public String toString() { return "Action [distributionSet=" + distributionSet + ", getId()=" + getId() + "]"; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaActionStatus.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaActionStatus.java index 94f76cae7..cf146651d 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaActionStatus.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaActionStatus.java @@ -40,7 +40,7 @@ import com.google.common.base.Splitter; @Index(name = "sp_idx_action_status_prim", columnList = "tenant,id") }) @NamedEntityGraph(name = "ActionStatus.withMessages", attributeNodes = { @NamedAttributeNode("messages") }) @Entity -public class JpaActionStatus extends JpaTenantAwareBaseEntity implements ActionStatus { +public class JpaActionStatus extends AbstractJpaTenantAwareBaseEntity implements ActionStatus { private static final long serialVersionUID = 1L; @Column(name = "target_occurred_at") @@ -88,14 +88,11 @@ public class JpaActionStatus extends JpaTenantAwareBaseEntity implements ActionS * @param messages * the messages which should be added to this action status */ - public JpaActionStatus(final JpaAction action, final Status status, final Long occurredAt, - final String... messages) { + public JpaActionStatus(final JpaAction action, final Status status, final Long occurredAt, final String message) { this.action = action; this.status = status; this.occurredAt = occurredAt; - for (final String msg : messages) { - addMessage(msg); - } + addMessage(message); } /** @@ -115,15 +112,11 @@ public class JpaActionStatus extends JpaTenantAwareBaseEntity implements ActionS this.occurredAt = occurredAt; } - /** - * Adds message including splitting in case it exceeds 512 length. - * - * @param message - * to add - */ @Override public final void addMessage(final String message) { - Splitter.fixedLength(512).split(message).forEach(messages::add); + if (message != null) { + Splitter.fixedLength(512).split(message).forEach(messages::add); + } } @Override diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSet.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSet.java index 201d4d657..d01cf3f4c 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSet.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSet.java @@ -9,6 +9,7 @@ package org.eclipse.hawkbit.repository.jpa.model; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.List; @@ -47,14 +48,7 @@ import org.eclipse.hawkbit.repository.model.TargetInfo; import org.eclipse.persistence.annotations.CascadeOnDelete; /** - *

- * The {@link DistributionSet} is defined in the SP repository and contains at - * least an OS and an Agent Hub. - *

- * - *

- * A {@link Target} has exactly one target {@link DistributionSet} assigned. - *

+ * Jpa implementation of {@link DistributionSet}. * */ @Entity @@ -65,11 +59,11 @@ import org.eclipse.persistence.annotations.CascadeOnDelete; @Index(name = "sp_idx_distribution_set_prim", columnList = "tenant,id") }) @NamedEntityGraph(name = "DistributionSet.detail", attributeNodes = { @NamedAttributeNode("modules"), @NamedAttributeNode("tags"), @NamedAttributeNode("type") }) -public class JpaDistributionSet extends JpaNamedVersionedEntity implements DistributionSet { +public class JpaDistributionSet extends AbstractJpaNamedVersionedEntity implements DistributionSet { private static final long serialVersionUID = 1L; @Column(name = "required_migration_step") - private boolean requiredMigrationStep = false; + private boolean requiredMigrationStep; @ManyToMany(targetEntity = JpaSoftwareModule.class, fetch = FetchType.LAZY) @JoinTable(name = "sp_ds_module", joinColumns = { @@ -84,7 +78,7 @@ public class JpaDistributionSet extends JpaNamedVersionedEntity implements Distr private Set tags = new HashSet<>(); @Column(name = "deleted") - private boolean deleted = false; + private boolean deleted; @OneToMany(mappedBy = "assignedDistributionSet", targetEntity = JpaTarget.class, fetch = FetchType.LAZY) private List assignedToTargets; @@ -106,7 +100,7 @@ public class JpaDistributionSet extends JpaNamedVersionedEntity implements Distr private DistributionSetType type; @Column(name = "complete") - private boolean complete = false; + private boolean complete; /** * Default constructor. @@ -130,7 +124,7 @@ public class JpaDistributionSet extends JpaNamedVersionedEntity implements Distr * {@link SoftwareModule}s of the {@link DistributionSet} */ public JpaDistributionSet(final String name, final String version, final String description, - final DistributionSetType type, final Iterable moduleList) { + final DistributionSetType type, final Collection moduleList) { super(name, version, description); this.type = type; @@ -152,15 +146,11 @@ public class JpaDistributionSet extends JpaNamedVersionedEntity implements Distr return deleted; } - /** - * @return immutable list of meta data elements. - */ @Override public List getMetadata() { return Collections.unmodifiableList(metadata); } - @Override public List getActions() { return actions; } @@ -182,23 +172,16 @@ public class JpaDistributionSet extends JpaNamedVersionedEntity implements Distr return this; } - @Override public DistributionSet setTags(final Set tags) { this.tags = tags; return this; } - /** - * @return the assignedTargets - */ @Override public List getAssignedTargets() { return assignedToTargets; } - /** - * @return the installedTargets - */ @Override public List getInstalledTargets() { return installedAtTargets; @@ -210,10 +193,6 @@ public class JpaDistributionSet extends JpaNamedVersionedEntity implements Distr + ", getId()=" + getId() + "]"; } - /** - * - * @return unmodifiableSet of {@link SoftwareModule}. - */ @Override public Set getModules() { return Collections.unmodifiableSet(modules); @@ -224,12 +203,6 @@ public class JpaDistributionSet extends JpaNamedVersionedEntity implements Distr return new DistributionSetIdName(getId(), getName(), getVersion()); } - /** - * @param softwareModule - * @return true if the module was added and false - * if it already existed in the set - * - */ @Override public boolean addModule(final SoftwareModule softwareModule) { @@ -267,13 +240,6 @@ public class JpaDistributionSet extends JpaNamedVersionedEntity implements Distr return false; } - /** - * Removed given {@link SoftwareModule} from this DS instance. - * - * @param softwareModule - * to remove - * @return true if element was found and removed - */ @Override public boolean removeModule(final SoftwareModule softwareModule) { final Optional found = modules.stream() @@ -289,14 +255,6 @@ public class JpaDistributionSet extends JpaNamedVersionedEntity implements Distr } - /** - * Searches through modules for the given type. - * - * @param type - * to search for - * @return SoftwareModule of given type or null if not in the - * list. - */ @Override public SoftwareModule findFirstModuleByType(final SoftwareModuleType type) { final Optional result = modules.stream().filter(module -> module.getType().equals(type)) @@ -323,4 +281,5 @@ public class JpaDistributionSet extends JpaNamedVersionedEntity implements Distr public boolean isComplete() { return complete; } + } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetMetadata.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetMetadata.java index b73e3c72e..5d176b4a9 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetMetadata.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetMetadata.java @@ -28,7 +28,7 @@ import org.eclipse.hawkbit.repository.model.DistributionSetMetadata; @IdClass(DsMetadataCompositeKey.class) @Entity @Table(name = "sp_ds_metadata") -public class JpaDistributionSetMetadata extends JpaMetaData implements DistributionSetMetadata { +public class JpaDistributionSetMetadata extends AbstractJpaMetaData implements DistributionSetMetadata { private static final long serialVersionUID = 1L; @Id @@ -49,7 +49,6 @@ public class JpaDistributionSetMetadata extends JpaMetaData implements Distribut return new DsMetadataCompositeKey(distributionSet, getKey()); } - @Override public void setDistributionSet(final DistributionSet distributionSet) { this.distributionSet = (JpaDistributionSet) distributionSet; } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetTag.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetTag.java index 4b6e67135..c4b55fe03 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetTag.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetTag.java @@ -29,7 +29,7 @@ import org.eclipse.hawkbit.repository.model.DistributionSetTag; @Table(name = "sp_distributionset_tag", indexes = { @Index(name = "sp_idx_distribution_set_tag_prim", columnList = "tenant,id") }, uniqueConstraints = @UniqueConstraint(columnNames = { "name", "tenant" }, name = "uk_ds_tag")) -public class JpaDistributionSetTag extends JpaTag implements DistributionSetTag { +public class JpaDistributionSetTag extends AbstractJpaTag implements DistributionSetTag { private static final long serialVersionUID = 1L; @ManyToMany(mappedBy = "tags", targetEntity = JpaDistributionSet.class, fetch = FetchType.LAZY) diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetType.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetType.java index d8edd4dcc..fa5d57642 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetType.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetType.java @@ -38,7 +38,7 @@ import org.eclipse.hawkbit.repository.model.SoftwareModuleType; @Index(name = "sp_idx_distribution_set_type_prim", columnList = "tenant,id") }, uniqueConstraints = { @UniqueConstraint(columnNames = { "name", "tenant" }, name = "uk_dst_name"), @UniqueConstraint(columnNames = { "type_key", "tenant" }, name = "uk_dst_key") }) -public class JpaDistributionSetType extends JpaNamedEntity implements DistributionSetType { +public class JpaDistributionSetType extends AbstractJpaNamedEntity implements DistributionSetType { private static final long serialVersionUID = 1L; @OneToMany(targetEntity = DistributionSetTypeElement.class, cascade = { @@ -53,7 +53,7 @@ public class JpaDistributionSetType extends JpaNamedEntity implements Distributi private String colour; @Column(name = "deleted") - private boolean deleted = false; + private boolean deleted; public JpaDistributionSetType() { // default public constructor for JPA @@ -91,19 +91,11 @@ public class JpaDistributionSetType extends JpaNamedEntity implements Distributi colour = color; } - /** - * @return the deleted - */ @Override public boolean isDeleted() { return deleted; } - /** - * @param deleted - * the deleted to set - */ - @Override public void setDeleted(final boolean deleted) { this.deleted = deleted; } @@ -120,14 +112,6 @@ public class JpaDistributionSetType extends JpaNamedEntity implements Distributi .collect(Collectors.toSet()); } - /** - * Checks if the given {@link SoftwareModuleType} is in this - * {@link DistributionSetType}. - * - * @param softwareModuleType - * search for - * @return true if found - */ @Override public boolean containsModuleType(final SoftwareModuleType softwareModuleType) { for (final DistributionSetTypeElement distributionSetTypeElement : elements) { @@ -139,15 +123,6 @@ public class JpaDistributionSetType extends JpaNamedEntity implements Distributi return false; } - /** - * Checks if the given {@link SoftwareModuleType} is in this - * {@link DistributionSetType} and defined as - * {@link DistributionSetTypeElement#isMandatory()}. - * - * @param softwareModuleType - * search for - * @return true if found - */ @Override public boolean containsMandatoryModuleType(final SoftwareModuleType softwareModuleType) { return elements.stream().filter(element -> element.isMandatory()) @@ -155,15 +130,6 @@ public class JpaDistributionSetType extends JpaNamedEntity implements Distributi } - /** - * Checks if the given {@link SoftwareModuleType} is in this - * {@link DistributionSetType} and defined as - * {@link DistributionSetTypeElement#isMandatory()}. - * - * @param softwareModuleType - * search for by {@link SoftwareModuleType#getId()} - * @return true if found - */ @Override public boolean containsMandatoryModuleType(final Long softwareModuleTypeId) { return elements.stream().filter(element -> element.isMandatory()) @@ -171,15 +137,6 @@ public class JpaDistributionSetType extends JpaNamedEntity implements Distributi } - /** - * Checks if the given {@link SoftwareModuleType} is in this - * {@link DistributionSetType} and NOT defined as - * {@link DistributionSetTypeElement#isMandatory()}. - * - * @param softwareModuleType - * search for - * @return true if found - */ @Override public boolean containsOptionalModuleType(final SoftwareModuleType softwareModuleType) { return elements.stream().filter(element -> !element.isMandatory()) @@ -187,15 +144,6 @@ public class JpaDistributionSetType extends JpaNamedEntity implements Distributi } - /** - * Checks if the given {@link SoftwareModuleType} is in this - * {@link DistributionSetType} and NOT defined as - * {@link DistributionSetTypeElement#isMandatory()}. - * - * @param softwareModuleTypeId - * search by {@link SoftwareModuleType#getId()} - * @return true if found - */ @Override public boolean containsOptionalModuleType(final Long softwareModuleTypeId) { return elements.stream().filter(element -> !element.isMandatory()) @@ -203,27 +151,11 @@ public class JpaDistributionSetType extends JpaNamedEntity implements Distributi } - /** - * Compares the modules of this {@link DistributionSetType} and the given - * one. - * - * @param dsType - * to compare with - * @return true if the lists are identical. - */ @Override public boolean areModuleEntriesIdentical(final DistributionSetType dsType) { return new HashSet(((JpaDistributionSetType) dsType).elements).equals(elements); } - /** - * Adds {@link SoftwareModuleType} that is optional for the - * {@link DistributionSet}. - * - * @param smType - * to add - * @return updated instance - */ @Override public DistributionSetType addOptionalModuleType(final SoftwareModuleType smType) { elements.add(new DistributionSetTypeElement(this, (JpaSoftwareModuleType) smType, false)); @@ -231,14 +163,6 @@ public class JpaDistributionSetType extends JpaNamedEntity implements Distributi return this; } - /** - * Adds {@link SoftwareModuleType} that is mandatory for the - * {@link DistributionSet}. - * - * @param smType - * to add - * @return updated instance - */ @Override public DistributionSetType addMandatoryModuleType(final SoftwareModuleType smType) { elements.add(new DistributionSetTypeElement(this, (JpaSoftwareModuleType) smType, true)); @@ -246,13 +170,6 @@ public class JpaDistributionSetType extends JpaNamedEntity implements Distributi return this; } - /** - * Removes {@link SoftwareModuleType} from the list. - * - * @param smTypeId - * to remove - * @return updated instance - */ @Override public DistributionSetType removeModuleType(final Long smTypeId) { // we search by id (standard equals compares also revison) @@ -276,12 +193,6 @@ public class JpaDistributionSetType extends JpaNamedEntity implements Distributi this.key = key; } - /** - * @param distributionSet - * to check for completeness - * @return true if the all mandatory software module types are - * in the system. - */ @Override public boolean checkComplete(final DistributionSet distributionSet) { return distributionSet.getModules().stream().map(module -> module.getType()).collect(Collectors.toList()) diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaExternalArtifact.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaExternalArtifact.java index ab55bf307..91f3df598 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaExternalArtifact.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaExternalArtifact.java @@ -33,7 +33,7 @@ import org.eclipse.hawkbit.repository.model.SoftwareModule; @Table(name = "sp_external_artifact", indexes = { @Index(name = "sp_idx_external_artifact_prim", columnList = "id,tenant") }) @Entity -public class JpaExternalArtifact extends JpaArtifact implements ExternalArtifact { +public class JpaExternalArtifact extends AbstractJpaArtifact implements ExternalArtifact { private static final long serialVersionUID = 1L; @ManyToOne @@ -85,7 +85,6 @@ public class JpaExternalArtifact extends JpaArtifact implements ExternalArtifact return softwareModule; } - @Override public final void setSoftwareModule(final SoftwareModule softwareModule) { this.softwareModule = (JpaSoftwareModule) softwareModule; this.softwareModule.addArtifact(this); @@ -106,9 +105,8 @@ public class JpaExternalArtifact extends JpaArtifact implements ExternalArtifact return urlSuffix; } - @Override - public void setExternalArtifactProvider(final ExternalArtifactProvider externalArtifactProvider) { - this.externalArtifactProvider = (JpaExternalArtifactProvider) externalArtifactProvider; + public void setExternalArtifactProvider(final JpaExternalArtifactProvider externalArtifactProvider) { + this.externalArtifactProvider = externalArtifactProvider; } /** diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaExternalArtifactProvider.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaExternalArtifactProvider.java index 527a90510..06e572d57 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaExternalArtifactProvider.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaExternalArtifactProvider.java @@ -17,15 +17,13 @@ import org.eclipse.hawkbit.repository.model.ExternalArtifact; import org.eclipse.hawkbit.repository.model.ExternalArtifactProvider; /** - * External repositories for artifact storage. The SP server provides URLs for - * the targets to download from these external resources but does not access - * them itself. + * JPA implementation of {@link ExternalArtifactProvider}. * */ @Table(name = "sp_external_provider", indexes = { @Index(name = "sp_idx_external_provider_prim", columnList = "tenant,id") }) @Entity -public class JpaExternalArtifactProvider extends JpaNamedEntity implements ExternalArtifactProvider { +public class JpaExternalArtifactProvider extends AbstractJpaNamedEntity implements ExternalArtifactProvider { private static final long serialVersionUID = 1L; @Column(name = "base_url", length = 512, nullable = false) diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaLocalArtifact.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaLocalArtifact.java index 7c6de6c0d..4348a3a7d 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaLocalArtifact.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaLocalArtifact.java @@ -26,18 +26,13 @@ import com.mongodb.gridfs.GridFS; import com.mongodb.gridfs.GridFSFile; /** - * Tenant specific locally stored artifact representation that is used by - * {@link SoftwareModule} . It contains all information that is provided by the - * user while all SP server generated information related to the artifact (hash, - * length) is stored directly with the binary itself. - * - * + * JPA implementation of {@link LocalArtifact}. * */ @Table(name = "sp_artifact", indexes = { @Index(name = "sp_idx_artifact_01", columnList = "tenant,software_module"), @Index(name = "sp_idx_artifact_prim", columnList = "tenant,id") }) @Entity -public class JpaLocalArtifact extends JpaArtifact implements LocalArtifact { +public class JpaLocalArtifact extends AbstractJpaArtifact implements LocalArtifact { private static final long serialVersionUID = 1L; @NotNull @@ -101,7 +96,6 @@ public class JpaLocalArtifact extends JpaArtifact implements LocalArtifact { return softwareModule; } - @Override public final void setSoftwareModule(final SoftwareModule softwareModule) { this.softwareModule = (JpaSoftwareModule) softwareModule; this.softwareModule.addArtifact(this); diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRollout.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRollout.java index 25e1a3a93..38dadc1c4 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRollout.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRollout.java @@ -34,14 +34,14 @@ import org.eclipse.hawkbit.repository.model.RolloutGroup; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; /** - * @author Michael Hirsch + * JPA implementation of a {@link Rollout}. * */ @Entity @Table(name = "sp_rollout", indexes = { @Index(name = "sp_idx_rollout_01", columnList = "tenant,name") }, uniqueConstraints = @UniqueConstraint(columnNames = { "name", "tenant" }, name = "uk_rollout")) -public class JpaRollout extends JpaNamedEntity implements Rollout { +public class JpaRollout extends AbstractJpaNamedEntity implements Rollout { private static final long serialVersionUID = 1L; @@ -60,7 +60,7 @@ public class JpaRollout extends JpaNamedEntity implements Rollout { private RolloutStatus status = RolloutStatus.CREATING; @Column(name = "last_check") - private long lastCheck = 0L; + private long lastCheck; @Column(name = "action_type", nullable = false) @Enumerated(EnumType.STRING) @@ -74,11 +74,11 @@ public class JpaRollout extends JpaNamedEntity implements Rollout { @Transient @CacheField(key = CacheKeys.ROLLOUT_GROUP_TOTAL) - private int rolloutGroupsTotal = 0; + private int rolloutGroupsTotal; @Transient @CacheField(key = CacheKeys.ROLLOUT_GROUP_CREATED) - private int rolloutGroupsCreated = 0; + private int rolloutGroupsCreated; @Transient private transient TotalTargetCountStatus totalTargetCountStatus; @@ -98,7 +98,6 @@ public class JpaRollout extends JpaNamedEntity implements Rollout { return rolloutGroups; } - @Override public void setRolloutGroups(final List rolloutGroups) { this.rolloutGroups = rolloutGroups; } @@ -118,17 +117,14 @@ public class JpaRollout extends JpaNamedEntity implements Rollout { return status; } - @Override public void setStatus(final RolloutStatus status) { this.status = status; } - @Override public long getLastCheck() { return lastCheck; } - @Override public void setLastCheck(final long lastCheck) { this.lastCheck = lastCheck; } @@ -158,7 +154,6 @@ public class JpaRollout extends JpaNamedEntity implements Rollout { return totalTargets; } - @Override public void setTotalTargets(final long totalTargets) { this.totalTargets = totalTargets; } @@ -168,7 +163,6 @@ public class JpaRollout extends JpaNamedEntity implements Rollout { return rolloutGroupsTotal; } - @Override public void setRolloutGroupsTotal(final int rolloutGroupsTotal) { this.rolloutGroupsTotal = rolloutGroupsTotal; } @@ -178,7 +172,6 @@ public class JpaRollout extends JpaNamedEntity implements Rollout { return rolloutGroupsCreated; } - @Override public void setRolloutGroupsCreated(final int rolloutGroupsCreated) { this.rolloutGroupsCreated = rolloutGroupsCreated; } @@ -191,7 +184,6 @@ public class JpaRollout extends JpaNamedEntity implements Rollout { return totalTargetCountStatus; } - @Override public void setTotalTargetCountStatus(final TotalTargetCountStatus totalTargetCountStatus) { this.totalTargetCountStatus = totalTargetCountStatus; } @@ -203,58 +195,4 @@ public class JpaRollout extends JpaNamedEntity implements Rollout { + ", getName()=" + getName() + ", getId()=" + getId() + "]"; } - /** - * - * State machine for rollout. - * - */ - public enum RolloutStatus { - - /** - * Rollouts is beeing created. - */ - CREATING, - - /** - * Rollout is ready to start. - */ - READY, - - /** - * Rollout is paused. - */ - PAUSED, - - /** - * Rollout is starting. - */ - STARTING, - - /** - * Rollout is stopped. - */ - STOPPED, - - /** - * Rollout is running. - */ - RUNNING, - - /** - * Rollout is finished. - */ - FINISHED, - - /** - * Rollout could not created due errors, might be database problem due - * asynchronous creating. - */ - ERROR_CREATING, - - /** - * Rollout could not started due errors, might be database problem due - * asynchronous starting. - */ - ERROR_STARTING; - } } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRolloutGroup.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRolloutGroup.java index f167d89fd..ed2620ae6 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRolloutGroup.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRolloutGroup.java @@ -32,14 +32,12 @@ import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; /** * JPA entity definition of persisting a group of an rollout. * - * @author Michael Hirsch - * */ @Entity @Table(name = "sp_rolloutgroup", indexes = { @Index(name = "sp_idx_rolloutgroup_01", columnList = "tenant,name") }, uniqueConstraints = @UniqueConstraint(columnNames = { "name", "rollout", "tenant" }, name = "uk_rolloutgroup")) -public class JpaRolloutGroup extends JpaNamedEntity implements RolloutGroup { +public class JpaRolloutGroup extends AbstractJpaNamedEntity implements RolloutGroup { private static final long serialVersionUID = 1L; @@ -61,25 +59,25 @@ public class JpaRolloutGroup extends JpaNamedEntity implements RolloutGroup { private RolloutGroupSuccessCondition successCondition = RolloutGroupSuccessCondition.THRESHOLD; @Column(name = "success_condition_exp", length = 512, nullable = false) - private String successConditionExp = null; + private String successConditionExp; @Column(name = "success_action", nullable = false) private RolloutGroupSuccessAction successAction = RolloutGroupSuccessAction.NEXTGROUP; @Column(name = "success_action_exp", length = 512, nullable = false) - private String successActionExp = null; + private String successActionExp; @Column(name = "error_condition") - private RolloutGroupErrorCondition errorCondition = null; + private RolloutGroupErrorCondition errorCondition; @Column(name = "error_condition_exp", length = 512) - private String errorConditionExp = null; + private String errorConditionExp; @Column(name = "error_action") - private RolloutGroupErrorAction errorAction = null; + private RolloutGroupErrorAction errorAction; @Column(name = "error_action_exp", length = 512) - private String errorActionExp = null; + private String errorActionExp; @Column(name = "total_targets") private long totalTargets; @@ -239,271 +237,4 @@ public class JpaRolloutGroup extends JpaNamedEntity implements RolloutGroup { + ", getId()=" + getId() + "]"; } - /** - * Rollout goup state machine. - * - */ - public enum RolloutGroupStatus { - - /** - * Ready to start the group. - */ - READY, - - /** - * Group is scheduled and started sometime, e.g. trigger of group - * before. - */ - SCHEDULED, - - /** - * Group is finished. - */ - FINISHED, - - /** - * Group is finished and has errors. - */ - ERROR, - - /** - * Group is running. - */ - RUNNING; - } - - /** - * The condition to evaluate if an group is success state. - */ - public enum RolloutGroupSuccessCondition { - THRESHOLD("thresholdRolloutGroupSuccessCondition"); - - private final String beanName; - - private RolloutGroupSuccessCondition(final String beanName) { - this.beanName = beanName; - } - - /** - * @return the beanName - */ - public String getBeanName() { - return beanName; - } - } - - /** - * The condition to evaluate if an group is in error state. - */ - public enum RolloutGroupErrorCondition { - THRESHOLD("thresholdRolloutGroupErrorCondition"); - - private final String beanName; - - private RolloutGroupErrorCondition(final String beanName) { - this.beanName = beanName; - } - - /** - * @return the beanName - */ - public String getBeanName() { - return beanName; - } - } - - /** - * The actions executed when the {@link RolloutGroup#errorCondition} is hit. - */ - public enum RolloutGroupErrorAction { - PAUSE("pauseRolloutGroupAction"); - - private final String beanName; - - private RolloutGroupErrorAction(final String beanName) { - this.beanName = beanName; - } - - /** - * @return the beanName - */ - public String getBeanName() { - return beanName; - } - } - - /** - * The actions executed when the {@link RolloutGroup#successCondition} is - * hit. - */ - public enum RolloutGroupSuccessAction { - NEXTGROUP("startNextRolloutGroupAction"); - - private final String beanName; - - private RolloutGroupSuccessAction(final String beanName) { - this.beanName = beanName; - } - - /** - * @return the beanName - */ - public String getBeanName() { - return beanName; - } - } - - /** - * Object which holds all {@link RolloutGroup} conditions together which can - * easily built. - */ - public static class RolloutGroupConditions { - private RolloutGroupSuccessCondition successCondition = null; - private String successConditionExp = null; - private RolloutGroupSuccessAction successAction = null; - private String successActionExp = null; - private RolloutGroupErrorCondition errorCondition = null; - private String errorConditionExp = null; - private RolloutGroupErrorAction errorAction = null; - private String errorActionExp = null; - - public RolloutGroupSuccessCondition getSuccessCondition() { - return successCondition; - } - - public void setSuccessCondition(final RolloutGroupSuccessCondition finishCondition) { - successCondition = finishCondition; - } - - public String getSuccessConditionExp() { - return successConditionExp; - } - - public void setSuccessConditionExp(final String finishConditionExp) { - successConditionExp = finishConditionExp; - } - - public RolloutGroupSuccessAction getSuccessAction() { - return successAction; - } - - public void setSuccessAction(final RolloutGroupSuccessAction successAction) { - this.successAction = successAction; - } - - public String getSuccessActionExp() { - return successActionExp; - } - - public void setSuccessActionExp(final String successActionExp) { - this.successActionExp = successActionExp; - } - - public RolloutGroupErrorCondition getErrorCondition() { - return errorCondition; - } - - public void setErrorCondition(final RolloutGroupErrorCondition errorCondition) { - this.errorCondition = errorCondition; - } - - public String getErrorConditionExp() { - return errorConditionExp; - } - - public void setErrorConditionExp(final String errorConditionExp) { - this.errorConditionExp = errorConditionExp; - } - - public RolloutGroupErrorAction getErrorAction() { - return errorAction; - } - - public void setErrorAction(final RolloutGroupErrorAction errorAction) { - this.errorAction = errorAction; - } - - public String getErrorActionExp() { - return errorActionExp; - } - - public void setErrorActionExp(final String errorActionExp) { - this.errorActionExp = errorActionExp; - } - } - - /** - * Builder to build easily the {@link RolloutGroupConditions}. - * - */ - public static class RolloutGroupConditionBuilder { - private final RolloutGroupConditions conditions = new RolloutGroupConditions(); - - public RolloutGroupConditions build() { - return conditions; - } - - /** - * Sets the finish condition and expression on the builder. - * - * @param condition - * the finish condition - * @param expression - * the finish expression - * @return the builder itself - */ - public RolloutGroupConditionBuilder successCondition(final RolloutGroupSuccessCondition condition, - final String expression) { - conditions.setSuccessCondition(condition); - conditions.setSuccessConditionExp(expression); - return this; - } - - /** - * Sets the success action and expression on the builder. - * - * @param action - * the success action - * @param expression - * the error expression - * @return the builder itself - */ - public RolloutGroupConditionBuilder successAction(final RolloutGroupSuccessAction action, - final String expression) { - conditions.setSuccessAction(action); - conditions.setSuccessActionExp(expression); - return this; - } - - /** - * Sets the error condition and expression on the builder. - * - * @param condition - * the error condition - * @param expression - * the error expression - * @return the builder itself - */ - public RolloutGroupConditionBuilder errorCondition(final RolloutGroupErrorCondition condition, - final String expression) { - conditions.setErrorCondition(condition); - conditions.setErrorConditionExp(expression); - return this; - } - - /** - * Sets the error action and expression on the builder. - * - * @param action - * the error action - * @param expression - * the error expression - * @return the builder itself - */ - public RolloutGroupConditionBuilder errorAction(final RolloutGroupErrorAction action, final String expression) { - conditions.setErrorAction(action); - conditions.setErrorActionExp(expression); - return this; - } - } } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModule.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModule.java index 306b6980b..6465e135a 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModule.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModule.java @@ -50,7 +50,7 @@ import org.eclipse.persistence.annotations.CascadeOnDelete; @Index(name = "sp_idx_base_sw_module_02", columnList = "tenant,deleted,module_type"), @Index(name = "sp_idx_base_sw_module_prim", columnList = "tenant,id") }) @NamedEntityGraph(name = "SoftwareModule.artifacts", attributeNodes = { @NamedAttributeNode("artifacts") }) -public class JpaSoftwareModule extends JpaNamedVersionedEntity implements SoftwareModule { +public class JpaSoftwareModule extends AbstractJpaNamedVersionedEntity implements SoftwareModule { private static final long serialVersionUID = 1L; @ManyToOne @@ -61,7 +61,7 @@ public class JpaSoftwareModule extends JpaNamedVersionedEntity implements Softwa private final List assignedTo = new ArrayList<>(); @Column(name = "deleted") - private boolean deleted = false; + private boolean deleted; @Column(name = "vendor", nullable = true, length = 256) private String vendor; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModuleMetadata.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModuleMetadata.java index aba08f0ed..53ce08ca9 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModuleMetadata.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModuleMetadata.java @@ -28,7 +28,7 @@ import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata; @IdClass(SwMetadataCompositeKey.class) @Entity @Table(name = "sp_sw_metadata") -public class JpaSoftwareModuleMetadata extends JpaMetaData implements SoftwareModuleMetadata { +public class JpaSoftwareModuleMetadata extends AbstractJpaMetaData implements SoftwareModuleMetadata { private static final long serialVersionUID = 1L; @Id diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModuleType.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModuleType.java index 9948a7cde..a943b08a4 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModuleType.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModuleType.java @@ -26,12 +26,16 @@ import org.eclipse.hawkbit.repository.model.SoftwareModuleType; @Index(name = "sp_idx_software_module_type_prim", columnList = "tenant,id") }, uniqueConstraints = { @UniqueConstraint(columnNames = { "type_key", "tenant" }, name = "uk_smt_type_key"), @UniqueConstraint(columnNames = { "name", "tenant" }, name = "uk_smt_name") }) -public class JpaSoftwareModuleType extends JpaNamedEntity implements SoftwareModuleType { +public class JpaSoftwareModuleType extends AbstractJpaNamedEntity implements SoftwareModuleType { private static final long serialVersionUID = 1L; @Column(name = "type_key", nullable = false, length = 64) private String key; + public void setMaxAssignments(final int maxAssignments) { + this.maxAssignments = maxAssignments; + } + @Column(name = "max_ds_assignments", nullable = false) private int maxAssignments; @@ -39,7 +43,7 @@ public class JpaSoftwareModuleType extends JpaNamedEntity implements SoftwareMod private String colour; @Column(name = "deleted") - private boolean deleted = false; + private boolean deleted; /** * Constructor. @@ -53,7 +57,8 @@ public class JpaSoftwareModuleType extends JpaNamedEntity implements SoftwareMod * @param maxAssignments * assignments to a DS */ - public JpaSoftwareModuleType(final String key, final String name, final String description, final int maxAssignments) { + public JpaSoftwareModuleType(final String key, final String name, final String description, + final int maxAssignments) { this(key, name, description, maxAssignments, null); } @@ -71,8 +76,8 @@ public class JpaSoftwareModuleType extends JpaNamedEntity implements SoftwareMod * @param colour * of the type. It will be null by default */ - public JpaSoftwareModuleType(final String key, final String name, final String description, final int maxAssignments, - final String colour) { + public JpaSoftwareModuleType(final String key, final String name, final String description, + final int maxAssignments, final String colour) { super(); this.key = key; this.maxAssignments = maxAssignments; @@ -122,4 +127,9 @@ public class JpaSoftwareModuleType extends JpaNamedEntity implements SoftwareMod public String toString() { return "SoftwareModuleType [key=" + key + ", getName()=" + getName() + ", getId()=" + getId() + "]"; } + + @Override + public void setKey(final String key) { + this.key = key; + } } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTarget.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTarget.java index 08a66a9b3..229ef1a42 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTarget.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTarget.java @@ -73,7 +73,7 @@ import org.springframework.data.domain.Persistable; "controller_id", "tenant" }, name = "uk_tenant_controller_id")) @NamedEntityGraph(name = "Target.detail", attributeNodes = { @NamedAttributeNode("tags"), @NamedAttributeNode(value = "assignedDistributionSet"), @NamedAttributeNode(value = "targetInfo") }) -public class JpaTarget extends JpaNamedEntity implements Persistable, Target { +public class JpaTarget extends AbstractJpaNamedEntity implements Persistable, Target { private static final long serialVersionUID = 1L; @Column(name = "controller_id", length = 64) @@ -82,7 +82,7 @@ public class JpaTarget extends JpaNamedEntity implements Persistable, Targ private String controllerId; @Transient - private boolean entityNew = false; + private boolean entityNew; @ManyToMany(targetEntity = JpaTargetTag.class) @JoinTable(name = "sp_target_target_tag", joinColumns = { @@ -103,14 +103,14 @@ public class JpaTarget extends JpaNamedEntity implements Persistable, Targ @CascadeOnDelete @OneToOne(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, targetEntity = JpaTargetInfo.class) @PrimaryKeyJoinColumn - private JpaTargetInfo targetInfo = null; + private JpaTargetInfo targetInfo; /** * the security token of the target which allows if enabled to authenticate * with this security token. */ @Column(name = "sec_token", insertable = true, updatable = true, nullable = false, length = 128) - private String securityToken = null; + private String securityToken; @CascadeOnDelete @OneToMany(fetch = FetchType.LAZY, cascade = { CascadeType.REMOVE, CascadeType.PERSIST }) diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetFilterQuery.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetFilterQuery.java index 1ad1b69b8..55aaec0fe 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetFilterQuery.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetFilterQuery.java @@ -24,7 +24,7 @@ import org.eclipse.hawkbit.repository.model.TargetFilterQuery; @Table(name = "sp_target_filter_query", indexes = { @Index(name = "sp_idx_target_filter_query_01", columnList = "tenant,name") }, uniqueConstraints = @UniqueConstraint(columnNames = { "name", "tenant" }, name = "uk_tenant_custom_filter_name")) -public class JpaTargetFilterQuery extends JpaTenantAwareBaseEntity implements TargetFilterQuery { +public class JpaTargetFilterQuery extends AbstractJpaTenantAwareBaseEntity implements TargetFilterQuery { private static final long serialVersionUID = 7493966984413479089L; @Column(name = "name", length = 64) diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetInfo.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetInfo.java index 7b7b3e2e4..80e3cd563 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetInfo.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetInfo.java @@ -38,6 +38,7 @@ import javax.persistence.Table; import javax.persistence.Transient; import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.PollStatus; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetInfo; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; @@ -71,7 +72,7 @@ public class JpaTargetInfo implements Persistable, TargetInfo { private Long targetId; @Transient - private boolean entityNew = false; + private boolean entityNew; @CascadeOnDelete @OneToOne(cascade = { CascadeType.MERGE, @@ -81,10 +82,10 @@ public class JpaTargetInfo implements Persistable, TargetInfo { private JpaTarget target; @Column(name = "address", length = 512) - private String address = null; + private String address; @Column(name = "last_target_query") - private Long lastTargetQuery = null; + private Long lastTargetQuery; @Column(name = "install_date") private Long installationDate; @@ -216,6 +217,7 @@ public class JpaTargetInfo implements Persistable, TargetInfo { return controllerAttributes; } + @Override public boolean isRequestControllerAttributes() { return requestControllerAttributes; } @@ -275,63 +277,6 @@ public class JpaTargetInfo implements Persistable, TargetInfo { }); } - /** - * The poll time object which holds all the necessary information around the - * target poll time, e.g. the last poll time, the next poll time and the - * overdue poll time. - * - */ - public static final class PollStatus { - private final LocalDateTime lastPollDate; - private final LocalDateTime nextPollDate; - private final LocalDateTime overdueDate; - private final LocalDateTime currentDate; - - private PollStatus(final LocalDateTime lastPollDate, final LocalDateTime nextPollDate, - final LocalDateTime overdueDate, final LocalDateTime currentDate) { - this.lastPollDate = lastPollDate; - this.nextPollDate = nextPollDate; - this.overdueDate = overdueDate; - this.currentDate = currentDate; - } - - /** - * calculates if the target poll time is overdue and the target has not - * been polled in the configured poll time interval. - * - * @return {@code true} if the current time is after the poll time - * overdue date otherwise {@code false}. - */ - public boolean isOverdue() { - return currentDate.isAfter(overdueDate); - } - - /** - * @return the lastPollDate - */ - public LocalDateTime getLastPollDate() { - return lastPollDate; - } - - public LocalDateTime getNextPollDate() { - return nextPollDate; - } - - public LocalDateTime getOverdueDate() { - return overdueDate; - } - - public LocalDateTime getCurrentDate() { - return currentDate; - } - - @Override - public String toString() { - return "PollTime [lastPollDate=" + lastPollDate + ", nextPollDate=" + nextPollDate + ", overdueDate=" - + overdueDate + ", currentDate=" + currentDate + "]"; - } - } - @Override public int hashCode() { final int prime = 31; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetTag.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetTag.java index 0d8f3a5d1..800fcc15e 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetTag.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetTag.java @@ -29,7 +29,7 @@ import org.eclipse.hawkbit.repository.model.TargetTag; @Table(name = "sp_target_tag", indexes = { @Index(name = "sp_idx_target_tag_prim", columnList = "tenant,id") }, uniqueConstraints = @UniqueConstraint(columnNames = { "name", "tenant" }, name = "uk_targ_tag")) -public class JpaTargetTag extends JpaTag implements TargetTag { +public class JpaTargetTag extends AbstractJpaTag implements TargetTag { private static final long serialVersionUID = 1L; @ManyToMany(mappedBy = "tags", targetEntity = JpaTarget.class, fetch = FetchType.LAZY) diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTenantConfiguration.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTenantConfiguration.java index 2d1342b74..2b28aa55f 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTenantConfiguration.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTenantConfiguration.java @@ -23,7 +23,7 @@ import org.eclipse.hawkbit.repository.model.TenantConfiguration; @Entity @Table(name = "sp_tenant_configuration", uniqueConstraints = @UniqueConstraint(columnNames = { "conf_key", "tenant" }, name = "uk_tenant_key")) -public class JpaTenantConfiguration extends JpaTenantAwareBaseEntity implements TenantConfiguration { +public class JpaTenantConfiguration extends AbstractJpaTenantAwareBaseEntity implements TenantConfiguration { private static final long serialVersionUID = 1L; @Column(name = "conf_key", length = 128) diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTenantMetaData.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTenantMetaData.java index 7cb31b3c4..32b6b1082 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTenantMetaData.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTenantMetaData.java @@ -36,7 +36,7 @@ import org.eclipse.hawkbit.repository.model.TenantMetaData; @Index(name = "sp_idx_tenant_prim", columnList = "tenant,id") }, uniqueConstraints = { @UniqueConstraint(columnNames = { "tenant" }, name = "uk_tenantmd_tenant") }) @Entity -public class JpaTenantMetaData extends JpaBaseEntity implements TenantMetaData { +public class JpaTenantMetaData extends AbstractJpaBaseEntity implements TenantMetaData { private static final long serialVersionUID = 1L; @Column(name = "tenant", nullable = false, length = 40) diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/RolloutTargetGroupId.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/RolloutTargetGroupId.java index cc1c9cbe7..b4001d9dc 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/RolloutTargetGroupId.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/RolloutTargetGroupId.java @@ -50,4 +50,4 @@ public class RolloutTargetGroupId implements Serializable { public Long getTarget() { return target; } -} \ No newline at end of file +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Action.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Action.java index 51b57bb17..74f921642 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Action.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Action.java @@ -9,13 +9,21 @@ package org.eclipse.hawkbit.repository.model; import java.util.List; +import java.util.concurrent.TimeUnit; +/** + * Operations to be executed by the target. Usually a software update. Other + * supported actions are the cancellation of a running update action or a + * refresh request for target attributes. + * + */ public interface Action extends TenantAwareBaseEntity { /** - * indicating that target action has no force time {@link #hasForcedTime()}. + * indicating that target action has no force time which is only needed in + * case of {@link ActionType#TIMEFORCED}. */ - public static final long NO_FORCE_TIME = 0L; + long NO_FORCE_TIME = 0L; /** * @return the distributionSet @@ -29,74 +37,117 @@ public interface Action extends TenantAwareBaseEntity { void setDistributionSet(DistributionSet distributionSet); /** - * @return true when action is in state {@link Status#CANCELING} or - * {@link Status#CANCELED}, false otherwise + * @return true when action is in state + * {@link Status#CANCELING} or {@link Status#CANCELED}, false + * otherwise */ - boolean isCancelingOrCanceled(); - - void setActive(boolean active); - - Status getStatus(); - - void setStatus(Status status); - - int getDownloadProgressPercent(); - - void setDownloadProgressPercent(int downloadProgressPercent); - - boolean isActive(); - - void setActionType(ActionType actionType); + default boolean isCancelingOrCanceled() { + return Status.CANCELING.equals(getStatus()) || Status.CANCELED.equals(getStatus()); + } /** - * @return the actionType + * @return current {@link Status#DOWNLOAD} progress if known by the update + * server. + */ + int getDownloadProgressPercent(); + + /** + * @return current {@link Status} of the {@link Action}. + */ + Status getStatus(); + + /** + * @param status + * of the {@link Action} + */ + void setStatus(Status status); + + /** + * @return true if {@link Action} is still running. + */ + boolean isActive(); + + /** + * @return the {@link ActionType} */ ActionType getActionType(); + /** + * @return list of {@link ActionStatus} entries. + */ List getActionStatus(); + /** + * @param target + * of this {@link Action} + */ void setTarget(Target target); + /** + * @return {@link Target} of this {@link Action}. + */ Target getTarget(); + /** + * @return time in {@link TimeUnit#MILLISECONDS} after which + * {@link #isForced()} switches to true in case of + * {@link ActionType#TIMEFORCED}. + */ long getForcedTime(); - void setForcedTime(long forcedTime); - + /** + * @return rolloutGroup related to this {@link Action}. + */ RolloutGroup getRolloutGroup(); - void setRolloutGroup(RolloutGroup rolloutGroup); - + /** + * @return rollout related to this {@link Action}. + */ Rollout getRollout(); - void setRollout(Rollout rollout); - /** - * checks if the {@link #forcedTime} is hit by the given + * checks if the {@link #getForcedTime()} is hit by the given * {@code hitTimeMillis}, by means if the given milliseconds are greater * than the forcedTime. * * @param hitTimeMillis * the milliseconds, mostly the * {@link System#currentTimeMillis()} - * @return {@code true} if this {@link #type} is in + * @return {@code true} if this {@link #getActionType()} is in * {@link ActionType#TIMEFORCED} and the given {@code hitTimeMillis} - * is greater than the {@link #forcedTime} otherwise {@code false} + * is greater than the {@link #getForcedTime()} otherwise + * {@code false} */ - boolean isHitAutoForceTime(long hitTimeMillis); + default boolean isHitAutoForceTime(final long hitTimeMillis) { + if (ActionType.TIMEFORCED.equals(getActionType())) { + return hitTimeMillis >= getForcedTime(); + } + return false; + } /** - * @return {@code true} if either the {@link #type} is + * @return {@code true} if either the {@link #getActionType()} is * {@link ActionType#FORCED} or {@link ActionType#TIMEFORCED} but - * then if the {@link #forcedTime} has been exceeded otherwise + * then if the {@link #getForcedTime()} has been exceeded otherwise * always {@code false} */ - boolean isForce(); + default boolean isForce() { + switch (getActionType()) { + case FORCED: + return true; + case TIMEFORCED: + return isHitAutoForceTime(System.currentTimeMillis()); + default: + return false; + } + } /** * @return true when action is forced, false otherwise */ - boolean isForced(); + default boolean isForced() { + return ActionType.FORCED.equals(getActionType()); + } /** * Action status as reported by the controller. @@ -159,7 +210,21 @@ public interface Action extends TenantAwareBaseEntity { * */ public enum ActionType { - FORCED, SOFT, TIMEFORCED; - } + /** + * Forced action execution. Target is advised to executed immediately. + */ + FORCED, -} \ No newline at end of file + /** + * Soft action execution. Target is advised to execute when it fits. + */ + SOFT, + + /** + * {@link #SOFT} action execution until + * {@link Action#isHitAutoForceTime(long)} is reached, {@link #FORCED} + * after that. + */ + TIMEFORCED; + } +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ActionStatus.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ActionStatus.java index 05f6966d8..f3ca66887 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ActionStatus.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ActionStatus.java @@ -9,13 +9,30 @@ package org.eclipse.hawkbit.repository.model; import java.util.List; +import java.util.concurrent.TimeUnit; import org.eclipse.hawkbit.repository.model.Action.Status; +/** + * Status information of an {@link Action} which can be provided by the + * {@link Target} or is added by the update server itself. This can be the start + * of the {@link Action} life cycle, the end and update notifications in + * between. + * + */ public interface ActionStatus extends TenantAwareBaseEntity { + /** + * @return time in {@link TimeUnit#MILLISECONDS} when the status was + * reported. + */ Long getOccurredAt(); + /** + * @param occurredAt + * time in {@link TimeUnit#MILLISECONDS} when the status was + * reported. + */ void setOccurredAt(Long occurredAt); /** @@ -26,14 +43,36 @@ public interface ActionStatus extends TenantAwareBaseEntity { */ void addMessage(String message); + /** + * @return list of message entries that can be added to the + * {@link ActionStatus}. + */ List getMessages(); + /** + * @return {@link Action} this {@link ActionStatus} belongs to. + */ Action getAction(); + /** + * @param action + * this {@link ActionStatus} belongs to. + */ void setAction(Action action); + /** + * @return the {@link Status} of this {@link ActionStatus}. Caused + * potentially a transition change of the {@link #getAction()} if + * different from the previous {@link ActionStatus#getStatus()}. + */ Status getStatus(); + /** + * @param status + * of this {@link ActionStatus}. May cause a transition change of + * the {@link #getAction()} if different from the previous + * {@link ActionStatus#getStatus()}. + */ void setStatus(Status status); -} \ No newline at end of file +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ActionWithStatusCount.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ActionWithStatusCount.java index 4b81320e8..6bc1efa56 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ActionWithStatusCount.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ActionWithStatusCount.java @@ -20,8 +20,6 @@ import org.eclipse.hawkbit.repository.model.Action.Status; // TODO: create interface public class ActionWithStatusCount { private final Long actionStatusCount; - private final Long actionId; - private final ActionType actionType; private final boolean actionActive; private final long actionForceTime; private final Status actionStatus; @@ -67,8 +65,6 @@ public class ActionWithStatusCount { final long forcedTime, final Status status, final Long actionCreatedAt, final Long actionLastModifiedAt, final Long dsId, final String dsName, final String dsVersion, final Long actionStatusCount, final String rolloutName) { - this.actionId = actionId; - this.actionType = actionType; actionActive = active; actionForceTime = forcedTime; actionStatus = status; @@ -92,26 +88,6 @@ public class ActionWithStatusCount { return action; } - public Long getActionId() { - return actionId; - } - - public ActionType getActionType() { - return actionType; - } - - public boolean isActionActive() { - return actionActive; - } - - public long getActionForceTime() { - return actionForceTime; - } - - public Status getActionStatus() { - return actionStatus; - } - public Long getActionCreatedAt() { return actionCreatedAt; } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Artifact.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Artifact.java index a4db06d25..95689a9d9 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Artifact.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Artifact.java @@ -8,16 +8,35 @@ */ package org.eclipse.hawkbit.repository.model; +import com.google.common.io.BaseEncoding; + +/** + * Binaries for a {@link SoftwareModule} Note: the decision which artifacts have + * to be downloaded are done on the device side. e.g. Full Package, Signatures, + * binary deltas + * + */ public interface Artifact extends TenantAwareBaseEntity { + /** + * @return {@link SoftwareModule} this {@link Artifact} belongs to. + */ SoftwareModule getSoftwareModule(); - void setSoftwareModule(SoftwareModule softwareModule); - + /** + * @return MD5 hash of the artifact. + */ String getMd5Hash(); + /** + * @return SHA-1 hash of the artifact in {@link BaseEncoding#base16()} + * format. + */ String getSha1Hash(); + /** + * @return size of the artifact in bytes. + */ Long getSize(); } \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/BaseEntity.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/BaseEntity.java index 0b8a8c5ee..f23b226c6 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/BaseEntity.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/BaseEntity.java @@ -9,19 +9,41 @@ package org.eclipse.hawkbit.repository.model; import java.io.Serializable; +import java.util.concurrent.TimeUnit; import org.springframework.hateoas.Identifiable; +/** + * Core information of all entities. + * + */ public interface BaseEntity extends Serializable, Identifiable { + /** + * @return time in {@link TimeUnit#MILLISECONDS} when the {@link BaseEntity} + * was created. + */ Long getCreatedAt(); + /** + * @return user that created the {@link BaseEntity}. + */ String getCreatedBy(); + /** + * @return time in {@link TimeUnit#MILLISECONDS} when the {@link BaseEntity} + * was last time changed. + */ Long getLastModifiedAt(); + /** + * @return user that updated the {@link BaseEntity} last. + */ String getLastModifiedBy(); + /** + * @return version of the {@link BaseEntity}. + */ long getOptLockRevision(); } \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSet.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSet.java index 41b1e5f5d..1c23cec27 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSet.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSet.java @@ -11,27 +11,63 @@ package org.eclipse.hawkbit.repository.model; import java.util.List; import java.util.Set; +import org.eclipse.hawkbit.repository.DistributionSetManagement; + +/** + * A {@link DistributionSet} defines a meta package that combines a set of + * {@link SoftwareModule}s which have to be or are provisioned to a + * {@link Target}. + * + *

+ * A {@link Target} has exactly one target {@link DistributionSet} assigned. + *

+ * + */ public interface DistributionSet extends NamedVersionedEntity { + /** + * @return {@link Set} of assigned {@link DistributionSetTag}s. + */ Set getTags(); + /** + * @return true if the set is deleted and only kept for history + * purposes. + */ boolean isDeleted(); /** - * @return immutable list of meta data elements. + * @return immutable {@link List} of {@link DistributionSetMetadata} + * elements. See {@link DistributionSetManagement} to alter. */ List getMetadata(); - List getActions(); - + /** + * @return true if {@link DistributionSet} contains a mandatory + * migration step, i.e. unfinished {@link Action}s will kept active + * and not automatically canceled if overridden by a newer update. + */ boolean isRequiredMigrationStep(); + /** + * @param deleted + * to true if {@link DistributionSet} is no longer + * be usage but kept for history purposes. + * @return updated {@link DistributionSet} + */ DistributionSet setDeleted(boolean deleted); + /** + * @param isRequiredMigrationStep + * to true if {@link DistributionSet} contains a + * mandatory migration step, i.e. unfinished {@link Action}s will + * kept active and not automatically canceled if overridden by a + * newer update. + * + * @return updated {@link DistributionSet} + */ DistributionSet setRequiredMigrationStep(boolean isRequiredMigrationStep); - DistributionSet setTags(Set tags); - /** * @return the assignedTargets */ @@ -48,6 +84,9 @@ public interface DistributionSet extends NamedVersionedEntity { */ Set getModules(); + /** + * @return {@link DistributionSetIdName} view. + */ DistributionSetIdName getDistributionSetIdName(); /** @@ -77,10 +116,22 @@ public interface DistributionSet extends NamedVersionedEntity { */ SoftwareModule findFirstModuleByType(SoftwareModuleType type); + /** + * @return type of the {@link DistributionSet}. + */ DistributionSetType getType(); + /** + * @param type + * of the {@link DistributionSet}. + */ void setType(DistributionSetType type); + /** + * @return true if all defined + * {@link DistributionSetType#getMandatoryModuleTypes()} of + * {@link #getType()} are present in this {@link DistributionSet}. + */ boolean isComplete(); } \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetMetadata.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetMetadata.java index 187b04e81..dfa9b9716 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetMetadata.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetMetadata.java @@ -8,10 +8,15 @@ */ package org.eclipse.hawkbit.repository.model; +/** + * {@link MetaData} of a {@link DistributionSet}. + * + */ public interface DistributionSetMetadata extends MetaData { - void setDistributionSet(DistributionSet distributionSet); - + /** + * @return {@link DistributionSet} of this {@link MetaData} entry. + */ DistributionSet getDistributionSet(); } \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTag.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTag.java index cd5ded232..31f909348 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTag.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTag.java @@ -10,8 +10,16 @@ package org.eclipse.hawkbit.repository.model; import java.util.List; +/** + * {@link Tag} of a {@link DistributionSet}. + * + */ public interface DistributionSetTag extends Tag { + /** + * @return {@link List} of {@link DistributionSet}s this {@link Tag} is + * assigned to. + */ List getAssignedToDistributionSet(); } \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetType.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetType.java index f540428a9..07c63ee89 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetType.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetType.java @@ -12,21 +12,33 @@ import java.util.Set; import org.eclipse.hawkbit.repository.jpa.model.DistributionSetTypeElement; +/** + * A {@link DistributionSetType} is an abstract definition for + * {@link DistributionSet} that defines what {@link SoftwareModule}s can be + * added (optional) to {@link DistributionSet} of that type or have to added + * (mandatory) in order to be considered complete. Only complete DS can be + * assigned to a {@link Target}. + * + */ public interface DistributionSetType extends NamedEntity { /** - * @return the deleted + * @return true if the type is deleted and only kept for + * history purposes. */ boolean isDeleted(); /** - * @param deleted - * the deleted to set + * @return set of {@link SoftwareModuleType}s that need to be in a + * {@link DistributionSet} of this type to be + * {@link DistributionSet#isComplete()}. */ - void setDeleted(boolean deleted); - Set getMandatoryModuleTypes(); + /** + * @return set of optional {@link SoftwareModuleType}s that can be in a + * {@link DistributionSet} of this type. + */ Set getOptionalModuleTypes(); /** @@ -55,7 +67,7 @@ public interface DistributionSetType extends NamedEntity { * {@link DistributionSetType} and defined as * {@link DistributionSetTypeElement#isMandatory()}. * - * @param softwareModuleType + * @param softwareModuleTypeId * search for by {@link SoftwareModuleType#getId()} * @return true if found */ @@ -122,8 +134,15 @@ public interface DistributionSetType extends NamedEntity { */ DistributionSetType removeModuleType(Long smTypeId); + /** + * @return business key of this {@link DistributionSetType}. + */ String getKey(); + /** + * @param key + * of this {@link DistributionSetType}. + */ void setKey(String key); /** @@ -134,8 +153,15 @@ public interface DistributionSetType extends NamedEntity { */ boolean checkComplete(DistributionSet distributionSet); + /** + * @return get color code to by used in management UI views. + */ String getColour(); + /** + * @param colour + * code to by used in management UI views. + */ void setColour(final String colour); } \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifact.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifact.java index daf0d1ae5..4ff3ab5a8 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifact.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifact.java @@ -8,16 +8,30 @@ */ package org.eclipse.hawkbit.repository.model; +import java.net.URL; + +/** + * External artifact representation with all the necessary information to + * generate an artifact {@link URL} at runtime. + * + */ public interface ExternalArtifact extends Artifact { + /** + * @return {@link ExternalArtifactProvider} of this {@link Artifact}. + */ ExternalArtifactProvider getExternalArtifactProvider(); + /** + * @return generated download {@link URL}. + */ String getUrl(); + /** + * @return suffix for {@link URL} generation. + */ String getUrlSuffix(); - void setExternalArtifactProvider(ExternalArtifactProvider externalArtifactProvider); - /** * @param urlSuffix * the urlSuffix to set diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifactProvider.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifactProvider.java index bb9f2fbea..139327096 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifactProvider.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifactProvider.java @@ -8,14 +8,34 @@ */ package org.eclipse.hawkbit.repository.model; +/** + * External repositories for artifact storage. The update server provides URLs + * for the targets to download from these external resources but does not access + * them itself. + * + */ public interface ExternalArtifactProvider extends NamedEntity { + /** + * @return prefix for url generation + */ String getBasePath(); + /** + * @return default for {@link ExternalArtifact#getUrlSuffix()}. + */ String getDefaultSuffix(); + /** + * @param basePath + * prefix for url generation + */ void setBasePath(String basePath); + /** + * @param defaultSuffix + * for {@link ExternalArtifact#getUrlSuffix()}. + */ void setDefaultSuffix(String defaultSuffix); -} \ No newline at end of file +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/LocalArtifact.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/LocalArtifact.java index 0f3a22c41..9aeb791c4 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/LocalArtifact.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/LocalArtifact.java @@ -8,8 +8,21 @@ */ package org.eclipse.hawkbit.repository.model; +import org.eclipse.hawkbit.artifact.repository.ArtifactRepository; + +/** + * Tenant specific locally stored artifact representation that is used by + * {@link SoftwareModule}s . It contains all information that is provided by the + * user while all update server generated information related to the artifact + * (hash, length) is stored directly with the binary itself in the + * {@link ArtifactRepository}. + * + */ public interface LocalArtifact extends Artifact { + /** + * @return the filename that was provided during upload. + */ String getFilename(); -} \ No newline at end of file +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/MetaData.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/MetaData.java index 8d6e6eed6..4f3397b23 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/MetaData.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/MetaData.java @@ -10,14 +10,30 @@ package org.eclipse.hawkbit.repository.model; import java.io.Serializable; +/** + * Meta data for entities, a (key/value) store. + * + */ public interface MetaData extends Serializable { + /** + * @return the key + */ String getKey(); + /** + * @param key + */ void setKey(String key); + /** + * @return the value + */ String getValue(); + /** + * @param value + */ void setValue(String value); } \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/NamedEntity.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/NamedEntity.java index 1cc84bf8f..4d3f3e419 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/NamedEntity.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/NamedEntity.java @@ -8,14 +8,32 @@ */ package org.eclipse.hawkbit.repository.model; +/** + * Entities that have a name and description. + * + */ public interface NamedEntity extends TenantAwareBaseEntity { + /** + * @return the description of the entity. + */ String getDescription(); + /** + * @return the name of the entity. + */ String getName(); + /** + * @param description + * of the entity. + */ void setDescription(String description); + /** + * @param name + * of the entity. + */ void setName(String name); -} \ No newline at end of file +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/NamedVersionedEntity.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/NamedVersionedEntity.java index 710980f13..de6cded12 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/NamedVersionedEntity.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/NamedVersionedEntity.java @@ -8,10 +8,21 @@ */ package org.eclipse.hawkbit.repository.model; +/** + * Entities that have a name and a description. + * + */ public interface NamedVersionedEntity extends NamedEntity { + /** + * @return the version of entity. + */ String getVersion(); + /** + * @param version + * of the entity. + */ void setVersion(String version); } \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Rollout.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Rollout.java index bf696d2fd..f87b1067f 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Rollout.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Rollout.java @@ -10,31 +10,53 @@ package org.eclipse.hawkbit.repository.model; import java.util.List; -import org.eclipse.hawkbit.repository.jpa.model.JpaRollout.RolloutStatus; import org.eclipse.hawkbit.repository.model.Action.ActionType; +/** + * Software update operations in large scale IoT scenarios with hundred of + * thousands of devices require special handling. + * + * That includes secure handling of large volumes of devices at rollout creation + * time. Monitoring of the rollout progress. Emergency rollout shutdown in case + * of problems on to many devices and reporting capabilities for a complete + * understanding of the rollout progress at each point in time. + * + */ public interface Rollout extends NamedEntity { + /** + * @return {@link DistributionSet} that is rolled out + */ DistributionSet getDistributionSet(); + /** + * @param distributionSet + * that is rolled out + */ void setDistributionSet(DistributionSet distributionSet); + /** + * @return list of deployment groups of the rollout. + */ List getRolloutGroups(); - void setRolloutGroups(List rolloutGroups); - + /** + * @return rsql query that identifies the targets that are part of this + * rollout. + */ String getTargetFilterQuery(); + /** + * @param targetFilterQuery + * that identifies the targets that are part of this rollout. + */ void setTargetFilterQuery(String targetFilterQuery); + /** + * @return status of the rollout + */ RolloutStatus getStatus(); - void setStatus(RolloutStatus status); - - long getLastCheck(); - - void setLastCheck(long lastCheck); - ActionType getActionType(); void setActionType(ActionType actionType); @@ -45,18 +67,65 @@ public interface Rollout extends NamedEntity { long getTotalTargets(); - void setTotalTargets(long totalTargets); - int getRolloutGroupsTotal(); - void setRolloutGroupsTotal(int rolloutGroupsTotal); - int getRolloutGroupsCreated(); - void setRolloutGroupsCreated(int rolloutGroupsCreated); - TotalTargetCountStatus getTotalTargetCountStatus(); - void setTotalTargetCountStatus(TotalTargetCountStatus totalTargetCountStatus); + /** + * + * State machine for rollout. + * + */ + public enum RolloutStatus { + + /** + * Rollouts is being created. + */ + CREATING, + + /** + * Rollout is ready to start. + */ + READY, + + /** + * Rollout is paused. + */ + PAUSED, + + /** + * Rollout is starting. + */ + STARTING, + + /** + * Rollout is stopped. + */ + STOPPED, + + /** + * Rollout is running. + */ + RUNNING, + + /** + * Rollout is finished. + */ + FINISHED, + + /** + * Rollout could not be created due to errors, might be a database + * problem during asynchronous creating. + */ + ERROR_CREATING, + + /** + * Rollout could not be started due to errors, might be database problem + * during asynchronous starting. + */ + ERROR_STARTING; + } } \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/RolloutGroup.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/RolloutGroup.java index 647278b78..cd65c4d2f 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/RolloutGroup.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/RolloutGroup.java @@ -8,12 +8,6 @@ */ package org.eclipse.hawkbit.repository.model; -import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup.RolloutGroupErrorAction; -import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup.RolloutGroupErrorCondition; -import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup.RolloutGroupStatus; -import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup.RolloutGroupSuccessAction; -import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup.RolloutGroupSuccessCondition; - public interface RolloutGroup extends NamedEntity { Rollout getRollout(); @@ -75,4 +69,117 @@ public interface RolloutGroup extends NamedEntity { */ void setTotalTargetCountStatus(TotalTargetCountStatus totalTargetCountStatus); + /** + * Rollout goup state machine. + * + */ + public enum RolloutGroupStatus { + + /** + * Ready to start the group. + */ + READY, + + /** + * Group is scheduled and started sometime, e.g. trigger of group + * before. + */ + SCHEDULED, + + /** + * Group is finished. + */ + FINISHED, + + /** + * Group is finished and has errors. + */ + ERROR, + + /** + * Group is running. + */ + RUNNING; + } + + /** + * The condition to evaluate if an group is success state. + */ + public enum RolloutGroupSuccessCondition { + THRESHOLD("thresholdRolloutGroupSuccessCondition"); + + private final String beanName; + + private RolloutGroupSuccessCondition(final String beanName) { + this.beanName = beanName; + } + + /** + * @return the beanName + */ + public String getBeanName() { + return beanName; + } + } + + /** + * The condition to evaluate if an group is in error state. + */ + public enum RolloutGroupErrorCondition { + THRESHOLD("thresholdRolloutGroupErrorCondition"); + + private final String beanName; + + private RolloutGroupErrorCondition(final String beanName) { + this.beanName = beanName; + } + + /** + * @return the beanName + */ + public String getBeanName() { + return beanName; + } + } + + /** + * The actions executed when the {@link RolloutGroup#errorCondition} is hit. + */ + public enum RolloutGroupErrorAction { + PAUSE("pauseRolloutGroupAction"); + + private final String beanName; + + private RolloutGroupErrorAction(final String beanName) { + this.beanName = beanName; + } + + /** + * @return the beanName + */ + public String getBeanName() { + return beanName; + } + } + + /** + * The actions executed when the {@link RolloutGroup#successCondition} is + * hit. + */ + public enum RolloutGroupSuccessAction { + NEXTGROUP("startNextRolloutGroupAction"); + + private final String beanName; + + private RolloutGroupSuccessAction(final String beanName) { + this.beanName = beanName; + } + + /** + * @return the beanName + */ + public String getBeanName() { + return beanName; + } + } } \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleType.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleType.java index 534d45fa3..24417d3f8 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleType.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleType.java @@ -12,8 +12,12 @@ public interface SoftwareModuleType extends NamedEntity { String getKey(); + void setKey(String key); + int getMaxAssignments(); + void setMaxAssignments(int maxAssignments); + boolean isDeleted(); void setDeleted(boolean deleted); diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetInfo.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetInfo.java index 657b95c41..e918d7376 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetInfo.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetInfo.java @@ -12,8 +12,6 @@ import java.io.Serializable; import java.net.URI; import java.util.Map; -import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo.PollStatus; - public interface TargetInfo extends Serializable { Long getId(); @@ -43,4 +41,6 @@ public interface TargetInfo extends Serializable { */ PollStatus getPollStatus(); + boolean isRequestControllerAttributes(); + } \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/rollout/condition/PauseRolloutGroupAction.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/rollout/condition/PauseRolloutGroupAction.java index d80fc5a7b..43232ef2d 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/rollout/condition/PauseRolloutGroupAction.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/rollout/condition/PauseRolloutGroupAction.java @@ -11,9 +11,9 @@ package org.eclipse.hawkbit.rollout.condition; import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.jpa.RolloutGroupRepository; import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup; -import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup.RolloutGroupStatus; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.RolloutGroup; +import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupStatus; import org.eclipse.hawkbit.security.SystemSecurityContext; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/rollout/condition/StartNextGroupRolloutGroupSuccessAction.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/rollout/condition/StartNextGroupRolloutGroupSuccessAction.java index 223f20125..0f1d1376f 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/rollout/condition/StartNextGroupRolloutGroupSuccessAction.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/rollout/condition/StartNextGroupRolloutGroupSuccessAction.java @@ -13,10 +13,10 @@ import java.util.List; import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.jpa.RolloutGroupRepository; import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup; -import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup.RolloutGroupStatus; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.RolloutGroup; +import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupStatus; import org.eclipse.hawkbit.security.SystemSecurityContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/TestDataUtil.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/TestDataUtil.java index f0e2d382c..5992ed1fc 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/TestDataUtil.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/TestDataUtil.java @@ -24,8 +24,8 @@ import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.jpa.ActionRepository; +import org.eclipse.hawkbit.repository.jpa.model.AbstractJpaArtifact; import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus; -import org.eclipse.hawkbit.repository.jpa.model.JpaArtifact; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType; @@ -76,7 +76,7 @@ public class TestDataUtil { // load also lazy stuff set = distributionSetManagement.findDistributionSetByIdWithDetails(set.getId()); - assertThat(distributionSetManagement.findDistributionSetsAll(pageReq, false, true)).hasSize(1); + assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true)).hasSize(1); return set; } @@ -232,12 +232,12 @@ public class TestDataUtil { return generateDistributionSet(suffix, "v1.0", softwareManagement, distributionSetManagement, false); } - public static List generateArtifacts(final ArtifactManagement artifactManagement, + public static List generateArtifacts(final ArtifactManagement artifactManagement, final Long moduleId) { - final List artifacts = new ArrayList<>(); + final List artifacts = new ArrayList<>(); for (int i = 0; i < 3; i++) { final InputStream stubInputStream = IOUtils.toInputStream("some test data" + i); - artifacts.add((JpaArtifact) artifactManagement.createLocalArtifact(stubInputStream, moduleId, + artifacts.add((AbstractJpaArtifact) artifactManagement.createLocalArtifact(stubInputStream, moduleId, "filename" + i, false)); } diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ActionTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ActionTest.java index 4fbd46a5c..0b8938808 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ActionTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ActionTest.java @@ -11,7 +11,6 @@ package org.eclipse.hawkbit.repository; import static org.fest.assertions.api.Assertions.assertThat; import org.eclipse.hawkbit.repository.jpa.model.JpaAction; -import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.ActionType; import org.junit.Test; @@ -27,11 +26,11 @@ public class ActionTest { @Description("Ensures that timeforced moded switch from soft to forces after defined timeframe.") public void timeforcedHitNewHasCodeIsGenerated() throws InterruptedException { - final boolean active = true; + final boolean active; // current time + 1 seconds final long sleepTime = 1000; final long timeForceTimeAt = System.currentTimeMillis() + sleepTime; - final Action timeforcedAction = new JpaAction(); + final JpaAction timeforcedAction = new JpaAction(); timeforcedAction.setActionType(ActionType.TIMEFORCED); timeforcedAction.setForcedTime(timeForceTimeAt); assertThat(timeforcedAction.isForce()).isFalse(); diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ControllerManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ControllerManagementTest.java index 76286d217..4b2a92169 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ControllerManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ControllerManagementTest.java @@ -72,7 +72,7 @@ public class ControllerManagementTest extends AbstractIntegrationTest { .isEqualTo(TargetUpdateStatus.IN_SYNC); assertThat(actionStatusRepository.findAll(pageReq).getNumberOfElements()).isEqualTo(3); - assertThat(deploymentManagement.findActionStatusByAction(pageReq, savedAction, false).getNumberOfElements()) + assertThat(deploymentManagement.findActionStatusByAction(pageReq, savedAction).getNumberOfElements()) .isEqualTo(3); } diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DeploymentManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DeploymentManagementTest.java index 50b929622..c1b0541f2 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DeploymentManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DeploymentManagementTest.java @@ -511,8 +511,8 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { final List deployedTargetIDs = deploymentResult.getDeployedTargetIDs(); final List undeployedTargetIDs = deploymentResult.getUndeployedTargetIDs(); - final List savedNakedTargets = deploymentResult.getUndeployedTargets(); - final List savedDeployedTargets = deploymentResult.getDeployedTargets(); + final Collection savedNakedTargets = (Collection) deploymentResult.getUndeployedTargets(); + final Collection savedDeployedTargets = (Collection) deploymentResult.getDeployedTargets(); // retrieving all Actions created by the assignDistributionSet call final Page page = actionRepository.findAll(pageReq); @@ -540,11 +540,9 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { // test the content of different lists assertThat(allFoundTargets).as("content of founded target is wrong").containsAll(deployedTargetsFromDB) .containsAll(undeployedTargetsFromDB); - assertThat(deployedTargetsFromDB).as("content of deployed target is wrong") - .containsAll((Iterable) savedDeployedTargets) + assertThat(deployedTargetsFromDB).as("content of deployed target is wrong").containsAll(savedDeployedTargets) .doesNotContain(Iterables.toArray(undeployedTargetsFromDB, JpaTarget.class)); - assertThat(undeployedTargetsFromDB).as("content of undeployed target is wrong") - .containsAll((Iterable) savedNakedTargets) + assertThat(undeployedTargetsFromDB).as("content of undeployed target is wrong").containsAll(savedNakedTargets) .doesNotContain(Iterables.toArray(deployedTargetsFromDB, JpaTarget.class)); // For each of the 4 targets 1 distribution sets gets assigned @@ -675,10 +673,11 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { } // verify that deleted attribute is used correctly - List allFoundDS = distributionSetManagement.findDistributionSetsAll(pageReq, false, true) - .getContent(); + List allFoundDS = distributionSetManagement + .findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true).getContent(); assertThat(allFoundDS.size()).as("no ds should be founded").isEqualTo(0); - allFoundDS = distributionSetManagement.findDistributionSetsAll(pageRequest, true, true).getContent(); + allFoundDS = distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageRequest, true, true) + .getContent(); assertThat(allFoundDS).as("wrong size of founded ds").hasSize(noOfDistributionSets); for (final DistributionSet ds : deploymentResult.getDistributionSets()) { @@ -692,9 +691,11 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { // has been installed // successfully and no activeAction is referring to created distribution // sets - allFoundDS = distributionSetManagement.findDistributionSetsAll(pageRequest, false, true).getContent(); + allFoundDS = distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageRequest, false, true) + .getContent(); assertThat(allFoundDS.size()).as("no ds should be founded").isEqualTo(0); - allFoundDS = distributionSetManagement.findDistributionSetsAll(pageRequest, true, true).getContent(); + allFoundDS = distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageRequest, true, true) + .getContent(); assertThat(allFoundDS).as("size of founded ds is wrong").hasSize(noOfDistributionSets); } diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DistributionSetManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DistributionSetManagementTest.java index 3ed4e703e..5a5518cf3 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DistributionSetManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/DistributionSetManagementTest.java @@ -404,7 +404,7 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest { // modifying the meta data value dsMetadata.setValue(knownUpdateValue); dsMetadata.setKey(knownKey); - dsMetadata.setDistributionSet(changedLockRevisionDS); + ((JpaDistributionSetMetadata) dsMetadata).setDistributionSet(changedLockRevisionDS); Thread.sleep(100); @@ -728,7 +728,8 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest { public void findDistributionSetsWithoutLazy() { TestDataUtil.generateDistributionSets(20, softwareManagement, distributionSetManagement); - assertThat(distributionSetManagement.findDistributionSetsAll(pageReq, false, true)).hasSize(20); + assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true)) + .hasSize(20); } @Test @@ -747,8 +748,9 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest { distributionSetManagement.deleteDistributionSet(ds1.getId()); // not assigned so not marked as deleted but fully deleted assertThat(distributionSetRepository.findAll()).hasSize(1); - assertThat(distributionSetManagement.findDistributionSetsAll(pageReq, Boolean.FALSE, Boolean.TRUE) - .getTotalElements()).isEqualTo(1); + assertThat(distributionSetManagement + .findDistributionSetsByDeletedAndOrCompleted(pageReq, Boolean.FALSE, Boolean.TRUE).getTotalElements()) + .isEqualTo(1); } @Test @@ -816,8 +818,9 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest { // not assigned so not marked as deleted assertThat(distributionSetRepository.findAll()).hasSize(3); - assertThat(distributionSetManagement.findDistributionSetsAll(pageReq, Boolean.FALSE, Boolean.TRUE) - .getTotalElements()).isEqualTo(2); + assertThat(distributionSetManagement + .findDistributionSetsByDeletedAndOrCompleted(pageReq, Boolean.FALSE, Boolean.TRUE).getTotalElements()) + .isEqualTo(2); } private Target sendUpdateActionStatusToTarget(final Status status, final Action updActA, final Target t, diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/RolloutManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/RolloutManagementTest.java index e56ce6cd5..576315b3a 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/RolloutManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/RolloutManagementTest.java @@ -18,23 +18,22 @@ import java.util.concurrent.Callable; import org.eclipse.hawkbit.AbstractIntegrationTest; import org.eclipse.hawkbit.TestDataUtil; -import org.eclipse.hawkbit.repository.jpa.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.jpa.model.JpaAction; import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus; import org.eclipse.hawkbit.repository.jpa.model.JpaRollout; -import org.eclipse.hawkbit.repository.jpa.model.JpaRollout.RolloutStatus; -import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup; -import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup.RolloutGroupConditions; -import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup.RolloutGroupErrorAction; -import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup.RolloutGroupErrorCondition; -import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup.RolloutGroupStatus; -import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup.RolloutGroupSuccessCondition; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Rollout; +import org.eclipse.hawkbit.repository.model.Rollout.RolloutStatus; import org.eclipse.hawkbit.repository.model.RolloutGroup; +import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupErrorAction; +import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupErrorCondition; +import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupStatus; +import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupSuccessCondition; +import org.eclipse.hawkbit.repository.model.RolloutGroupConditionBuilder; +import org.eclipse.hawkbit.repository.model.RolloutGroupConditions; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; @@ -876,7 +875,7 @@ public class RolloutManagementTest extends AbstractIntegrationTest { softwareManagement, distributionSetManagement); targetManagement.createTargets( TestDataUtil.buildTargetFixtures(amountTargetsForRollout, targetPrefixName + "-", targetPrefixName)); - final RolloutGroupConditions conditions = new JpaRolloutGroup.RolloutGroupConditionBuilder() + final RolloutGroupConditions conditions = new RolloutGroupConditionBuilder() .successCondition(RolloutGroupSuccessCondition.THRESHOLD, successCondition) .errorCondition(RolloutGroupErrorCondition.THRESHOLD, errorCondition) .errorAction(RolloutGroupErrorAction.PAUSE, null).build(); @@ -963,7 +962,7 @@ public class RolloutManagementTest extends AbstractIntegrationTest { private Rollout createRolloutByVariables(final String rolloutName, final String rolloutDescription, final int groupSize, final String filterQuery, final DistributionSet distributionSet, final String successCondition, final String errorCondition) { - final RolloutGroupConditions conditions = new JpaRolloutGroup.RolloutGroupConditionBuilder() + final RolloutGroupConditions conditions = new RolloutGroupConditionBuilder() .successCondition(RolloutGroupSuccessCondition.THRESHOLD, successCondition) .errorCondition(RolloutGroupErrorCondition.THRESHOLD, errorCondition) .errorAction(RolloutGroupErrorAction.PAUSE, null).build(); diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/SoftwareManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/SoftwareManagementTest.java index 300fe78dc..befcf5f3d 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/SoftwareManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/SoftwareManagementTest.java @@ -961,7 +961,7 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { .getSoftwareModule(); try { - softwareManagement.findSoftwareModuleMetadata(new SwMetadataCompositeKey(ah, "doesnotexist")); + softwareManagement.findSoftwareModuleMetadata(ah, "doesnotexist"); fail("should not have worked as module metadata with that key does not exist"); } catch (final EntityNotFoundException e) { diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLRolloutGroupFields.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLRolloutGroupFields.java index 83c31b31a..32c4d8641 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLRolloutGroupFields.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLRolloutGroupFields.java @@ -14,11 +14,11 @@ import org.eclipse.hawkbit.AbstractIntegrationTest; import org.eclipse.hawkbit.TestDataUtil; import org.eclipse.hawkbit.repository.RolloutGroupFields; import org.eclipse.hawkbit.repository.jpa.model.JpaRollout; -import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup.RolloutGroupConditionBuilder; -import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup.RolloutGroupSuccessCondition; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.RolloutGroup; +import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupSuccessCondition; +import org.eclipse.hawkbit.repository.model.RolloutGroupConditionBuilder; import org.junit.Before; import org.junit.Test; import org.springframework.data.domain.Page; diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLSoftwareModuleTypeFieldsTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLSoftwareModuleTypeFieldsTest.java index 37a501a3f..e4988025e 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLSoftwareModuleTypeFieldsTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLSoftwareModuleTypeFieldsTest.java @@ -59,7 +59,7 @@ public class RSQLSoftwareModuleTypeFieldsTest extends AbstractIntegrationTest { } private void assertRSQLQuery(final String rsqlParam, final long excpectedEntity) { - final Page find = softwareManagement.findSoftwareModuleTypesByPredicate(rsqlParam, + final Page find = softwareManagement.findSoftwareModuleTypesAll(rsqlParam, new PageRequest(0, 100)); final long countAll = find.getTotalElements(); assertThat(find).isNotNull(); diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/tenancy/MultiTenancyEntityTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/tenancy/MultiTenancyEntityTest.java index ca0ef3840..e5cbc18a0 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/tenancy/MultiTenancyEntityTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/tenancy/MultiTenancyEntityTest.java @@ -194,7 +194,7 @@ public class MultiTenancyEntityTest extends AbstractIntegrationTest { private Page findDistributionSetForTenant(final String tenant) throws Exception { return securityRule.runAs(WithSpringAuthorityRule.withUserAndTenant("user", tenant), - () -> distributionSetManagement.findDistributionSetsAll(pageReq, false, false)); + () -> distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, false)); } } diff --git a/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/util/JsonBuilder.java b/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/util/JsonBuilder.java index b73320f0e..f67f15815 100644 --- a/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/util/JsonBuilder.java +++ b/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/util/JsonBuilder.java @@ -16,7 +16,7 @@ import java.util.stream.Collectors; import org.apache.commons.lang3.RandomStringUtils; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetType; -import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupConditions; +import org.eclipse.hawkbit.repository.model.RolloutGroupConditions; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.repository.model.Target; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/details/ArtifactBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/details/ArtifactBeanQuery.java index 5e7c0f3c7..b9bceda3a 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/details/ArtifactBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/details/ArtifactBeanQuery.java @@ -12,7 +12,8 @@ import java.util.List; import java.util.Map; import org.eclipse.hawkbit.repository.ArtifactManagement; -import org.eclipse.hawkbit.repository.jpa.OffsetBasedPageRequest; +import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; +import org.eclipse.hawkbit.repository.jpa.model.JpaLocalArtifact; import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; @@ -72,7 +73,7 @@ public class ArtifactBeanQuery extends AbstractBeanQuery { @Override protected LocalArtifact constructBean() { - return new LocalArtifact(); + return new JpaLocalArtifact(); } @Override diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/BaseSwModuleBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/BaseSwModuleBeanQuery.java index ea49d2f1f..29bea30eb 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/BaseSwModuleBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/BaseSwModuleBeanQuery.java @@ -12,8 +12,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.SoftwareManagement; -import org.eclipse.hawkbit.repository.jpa.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.ui.common.UserDetailsFormatter; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/ProxyBaseSoftwareModuleItem.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/ProxyBaseSoftwareModuleItem.java index 6e417435c..14568c307 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/ProxyBaseSoftwareModuleItem.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/ProxyBaseSoftwareModuleItem.java @@ -10,7 +10,7 @@ package org.eclipse.hawkbit.ui.artifacts.smtable; import java.security.SecureRandom; -import org.eclipse.hawkbit.repository.model.SoftwareModule; +import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; /** * @@ -19,7 +19,7 @@ import org.eclipse.hawkbit.repository.model.SoftwareModule; * * */ -public class ProxyBaseSoftwareModuleItem extends SoftwareModule { +public class ProxyBaseSoftwareModuleItem extends JpaSoftwareModule { private static final long serialVersionUID = -1555306616599140635L; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleAddUpdateWindow.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleAddUpdateWindow.java index 1e4029087..d6fbada89 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleAddUpdateWindow.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleAddUpdateWindow.java @@ -234,7 +234,7 @@ public class SoftwareModuleAddUpdateWindow implements Serializable { mainLayout.addComponent(hLayout); mainLayout.setComponentAlignment(hLayout, Alignment.MIDDLE_LEFT); mainLayout.addComponents(nameTextField, versionTextField, vendorTextField, descTextArea, buttonsLayout); - + /* add main layout to the window */ window = SPUIComponentProvider.getWindow(i18n.get("upload.caption.add.new.swmodule"), null, SPUIDefinitions.CREATE_UPDATE_WINDOW); @@ -277,8 +277,8 @@ public class SoftwareModuleAddUpdateWindow implements Serializable { uiNotifcation.displayValidationError( i18n.get("message.duplicate.softwaremodule", new Object[] { name, version })); } else { - final SoftwareModule newBaseSoftwareModule = HawkbitCommonUtil.addNewBaseSoftware(name, version, vendor, - softwareManagement.findSoftwareModuleTypeByName(type), description); + final SoftwareModule newBaseSoftwareModule = HawkbitCommonUtil.addNewBaseSoftware(softwareManagement, + name, version, vendor, softwareManagement.findSoftwareModuleTypeByName(type), description); if (newBaseSoftwareModule != null) { /* display success message */ uiNotifcation.displaySuccess(i18n.get("message.save.success", new Object[] { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/CreateUpdateSoftwareTypeLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/CreateUpdateSoftwareTypeLayout.java index f2e43c1fb..c71b06671 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/CreateUpdateSoftwareTypeLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/CreateUpdateSoftwareTypeLayout.java @@ -625,8 +625,10 @@ public class CreateUpdateSoftwareTypeLayout extends CustomComponent implements C } if (null != typeNameValue && null != typeKeyValue) { - SoftwareModuleType newSWType = new SoftwareModuleType(typeKeyValue, typeNameValue, typeDescValue, - assignNumber, colorPicked); + SoftwareModuleType newSWType = swTypeManagementService.generateSoftwareModuleType(typeKeyValue, + typeNameValue, typeDescValue, assignNumber); + newSWType.setColour(colorPicked); + if (null != typeDescValue) { newSWType.setDescription(typeDescValue); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/DistributionSetTypeBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/DistributionSetTypeBeanQuery.java index b8f5435dd..04200208b 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/DistributionSetTypeBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/DistributionSetTypeBeanQuery.java @@ -13,7 +13,7 @@ import java.util.List; import java.util.Map; import org.eclipse.hawkbit.repository.DistributionSetManagement; -import org.eclipse.hawkbit.repository.jpa.OffsetBasedPageRequest; +import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SpringContextHelper; @@ -57,8 +57,9 @@ public class DistributionSetTypeBeanQuery extends AbstractBeanQuery itemIds = (List) selectedTable.getItemIds(); if (null != typeNameValue && null != typeKeyValue && null != itemIds && !itemIds.isEmpty()) { - DistributionSetType newDistType = new DistributionSetType(typeKeyValue, typeNameValue, typeDescValue); + DistributionSetType newDistType = distributionSetManagement.generateDistributionSetType(typeKeyValue, + typeNameValue, typeDescValue); for (final Long id : itemIds) { final Item item = selectedTable.getItem(id); final String distTypeName = (String) item.getItemProperty(DIST_TYPE_NAME).getValue(); @@ -704,7 +705,8 @@ public class CreateUpdateDistSetTypeLayout extends CustomComponent implements Co updateDistSetType.setKey(typeKeyValue); updateDistSetType.setDescription(null != typeDescValue ? typeDescValue : null); - if (distributionSetRepository.countByType(existingType) <= 0 && null != itemIds && !itemIds.isEmpty()) { + if (distributionSetManagement.countDistributionSetsByType(existingType) <= 0 && null != itemIds + && !itemIds.isEmpty()) { for (final Long id : itemIds) { final Item item = selectedTable.getItem(id); final CheckBox mandatoryCheckBox = (CheckBox) item.getItemProperty(DIST_TYPE_MANDATORY).getValue(); @@ -1040,7 +1042,7 @@ public class CreateUpdateDistSetTypeLayout extends CustomComponent implements Co typeDesc.setValue(selectedTypeTag.getDescription()); typeKey.setValue(selectedTypeTag.getKey()); - if (distributionSetRepository.countByType(selectedTypeTag) <= 0) { + if (distributionSetManagement.countDistributionSetsByType(selectedTypeTag) <= 0) { distTypeSelectLayout.setEnabled(true); selectedTable.setEnabled(true); saveDistSetType.setEnabled(true); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/ManageDistBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/ManageDistBeanQuery.java index 1fd306816..91fd3336c 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/ManageDistBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/ManageDistBeanQuery.java @@ -17,7 +17,7 @@ import java.util.Map; import org.eclipse.hawkbit.repository.DistributionSetFilter; import org.eclipse.hawkbit.repository.DistributionSetFilter.DistributionSetFilterBuilder; import org.eclipse.hawkbit.repository.DistributionSetManagement; -import org.eclipse.hawkbit.repository.jpa.OffsetBasedPageRequest; +import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.ui.common.UserDetailsFormatter; @@ -96,7 +96,7 @@ public class ManageDistBeanQuery extends AbstractBeanQuery { } else if (Strings.isNullOrEmpty(searchText)) { // if no search filters available distBeans = getDistributionSetManagement() - .findDistributionSetsAll(new OffsetBasedPageRequest(startIndex, count, sort), false, null); + .findDistributionSetsByDeletedAndOrCompleted(new OffsetBasedPageRequest(startIndex, count, sort), false, null); } else { final DistributionSetFilter distributionSetFilter = new DistributionSetFilterBuilder().setIsDeleted(false) .setSearchText(searchText).setSelectDSWithNoTag(Boolean.FALSE).setType(distributionSetType).build(); @@ -133,7 +133,7 @@ public class ManageDistBeanQuery extends AbstractBeanQuery { if (Strings.isNullOrEmpty(searchText) && null == distributionSetType) { // if no search filters available firstPageDistributionSets = getDistributionSetManagement() - .findDistributionSetsAll(new PageRequest(0, SPUIDefinitions.PAGE_SIZE, sort), false, null); + .findDistributionSetsByDeletedAndOrCompleted(new PageRequest(0, SPUIDefinitions.PAGE_SIZE, sort), false, null); } else { final DistributionSetFilter distributionSetFilter = new DistributionSetFilterBuilder().setIsDeleted(false) .setSearchText(searchText).setSelectDSWithNoTag(Boolean.FALSE).setType(distributionSetType).build(); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleBeanQuery.java index eb53cef55..21ce01347 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleBeanQuery.java @@ -12,8 +12,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.SoftwareManagement; -import org.eclipse.hawkbit.repository.jpa.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.model.CustomSoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterHeader.java index 6a671e228..a89e98d56 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterHeader.java @@ -503,7 +503,7 @@ public class CreateOrUpdateFilterHeader extends VerticalLayout implements Button } private void createTargetFilterQuery() { - final TargetFilterQuery targetFilterQuery = new TargetFilterQuery(); + final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement.generateTargetFilterQuery(); targetFilterQuery.setName(nameTextField.getValue()); targetFilterQuery.setQuery(queryTextField.getValue()); targetFilterQueryManagement.createTargetFilterQuery(targetFilterQuery); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/actionhistory/ActionHistoryTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/actionhistory/ActionHistoryTable.java index 834566f7e..0288cf9c2 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/actionhistory/ActionHistoryTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/actionhistory/ActionHistoryTable.java @@ -268,29 +268,29 @@ public class ActionHistoryTable extends TreeTable implements Handler { final Action action = actionWithStatusCount.getAction(); - final Item item = hierarchicalContainer.addItem(actionWithStatusCount.getActionId()); + final Item item = hierarchicalContainer.addItem(actionWithStatusCount.getAction().getId()); item.getItemProperty(SPUIDefinitions.ACTION_HIS_TBL_STATUS_HIDDEN) - .setValue(actionWithStatusCount.getActionStatus()); + .setValue(actionWithStatusCount.getAction().getStatus()); /* * add action id. */ item.getItemProperty(SPUIDefinitions.ACTION_HIS_TBL_ACTION_ID) - .setValue(actionWithStatusCount.getActionId().toString()); + .setValue(actionWithStatusCount.getAction().getId().toString()); /* * add active/inactive status to the item which will be used in * Column generator to generate respective icon */ item.getItemProperty(SPUIDefinitions.ACTION_HIS_TBL_ACTIVE_HIDDEN).setValue( - actionWithStatusCount.isActionActive() ? SPUIDefinitions.ACTIVE : SPUIDefinitions.IN_ACTIVE); + actionWithStatusCount.getAction().isActive() ? SPUIDefinitions.ACTIVE : SPUIDefinitions.IN_ACTIVE); /* * add action Id to the item which will be used for fetching child * items ( previous action status ) during expand */ item.getItemProperty(SPUIDefinitions.ACTION_HIS_TBL_ACTION_ID_HIDDEN) - .setValue(actionWithStatusCount.getActionId()); + .setValue(actionWithStatusCount.getAction().getId()); /* * add distribution name to the item which will be displayed in the @@ -301,7 +301,7 @@ public class ActionHistoryTable extends TreeTable implements Handler { item.getItemProperty(SPUIDefinitions.ACTION_HIS_TBL_FORCED).setValue(action); /* Default no child */ - ((Hierarchical) hierarchicalContainer).setChildrenAllowed(actionWithStatusCount.getActionId(), false); + ((Hierarchical) hierarchicalContainer).setChildrenAllowed(actionWithStatusCount.getAction().getId(), false); item.getItemProperty(SPUIDefinitions.ACTION_HIS_TBL_DATETIME) .setValue(SPDateTimeUtil.getFormattedDate((actionWithStatusCount.getActionLastModifiedAt() != null) @@ -312,7 +312,7 @@ public class ActionHistoryTable extends TreeTable implements Handler { .setValue(actionWithStatusCount.getRolloutName()); if (actionWithStatusCount.getActionStatusCount() > 0) { - ((Hierarchical) hierarchicalContainer).setChildrenAllowed(actionWithStatusCount.getActionId(), true); + ((Hierarchical) hierarchicalContainer).setChildrenAllowed(actionWithStatusCount.getAction().getId(), true); } } } @@ -422,8 +422,12 @@ public class ActionHistoryTable extends TreeTable implements Handler { .findActionWithDetails(actionId); final Pageable pageReq = new PageRequest(0, 1000, new Sort(Direction.DESC, ActionStatusFields.ID.getFieldName())); - final Page actionStatusList = deploymentManagement.findActionStatusByAction(pageReq, action, - managementUIState.isActionHistoryMaximized()); + final Page actionStatusList; + if (managementUIState.isActionHistoryMaximized()) { + actionStatusList = deploymentManagement.findActionStatusByActionWithMessages(pageReq, action); + } else { + actionStatusList = deploymentManagement.findActionStatusByAction(pageReq, action); + } final List content = actionStatusList.getContent(); /* * Since the recent action status and messages are already diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionAddUpdateWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionAddUpdateWindowLayout.java index d13dc94cf..cc52ce795 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionAddUpdateWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionAddUpdateWindowLayout.java @@ -297,7 +297,7 @@ public class DistributionAddUpdateWindowLayout extends VerticalLayout { if (mandatoryCheck(name, version, distSetTypeName) && duplicateCheck(name, version)) { final String desc = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue()); final boolean isMigStepReq = reqMigStepCheckbox.getValue(); - DistributionSet newDist = new DistributionSet(); + DistributionSet newDist = distributionSetManagement.generateDistributionSet(); setDistributionValues(newDist, name, version, distSetTypeName, desc, isMigStepReq); newDist = distributionSetManagement.createDistributionSet(newDist); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionBeanQuery.java index 353ef3e95..5aee6cbe1 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionBeanQuery.java @@ -16,7 +16,7 @@ import java.util.Map; import org.eclipse.hawkbit.repository.DistributionSetFilter; import org.eclipse.hawkbit.repository.DistributionSetFilter.DistributionSetFilterBuilder; import org.eclipse.hawkbit.repository.DistributionSetManagement; -import org.eclipse.hawkbit.repository.jpa.OffsetBasedPageRequest; +import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.ui.common.UserDetailsFormatter; import org.eclipse.hawkbit.ui.components.ProxyDistribution; @@ -111,7 +111,7 @@ public class DistributionBeanQuery extends AbstractBeanQuery } else if (distributionTags.isEmpty() && Strings.isNullOrEmpty(searchText) && !noTagClicked) { // if no search filters available distBeans = getDistributionSetManagement() - .findDistributionSetsAll(new OffsetBasedPageRequest(startIndex, count, sort), false, true); + .findDistributionSetsByDeletedAndOrCompleted(new OffsetBasedPageRequest(startIndex, count, sort), false, true); } else { final DistributionSetFilter distributionSetFilter = new DistributionSetFilterBuilder().setIsDeleted(false) .setIsComplete(true).setSearchText(searchText).setSelectDSWithNoTag(noTagClicked) @@ -153,7 +153,7 @@ public class DistributionBeanQuery extends AbstractBeanQuery } else if (distributionTags.isEmpty() && Strings.isNullOrEmpty(searchText) && !noTagClicked) { // if no search filters available firstPageDistributionSets = getDistributionSetManagement() - .findDistributionSetsAll(new PageRequest(0, SPUIDefinitions.PAGE_SIZE, sort), false, true); + .findDistributionSetsByDeletedAndOrCompleted(new PageRequest(0, SPUIDefinitions.PAGE_SIZE, sort), false, true); } else { final DistributionSetFilter distributionSetFilter = new DistributionSetFilterBuilder().setIsDeleted(false) .setIsComplete(true).setSearchText(searchText).setSelectDSWithNoTag(noTagClicked) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/CreateUpdateDistributionTagLayoutWindow.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/CreateUpdateDistributionTagLayoutWindow.java index 4d63753fe..e540017c3 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/CreateUpdateDistributionTagLayoutWindow.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/CreateUpdateDistributionTagLayoutWindow.java @@ -98,14 +98,13 @@ public class CreateUpdateDistributionTagLayoutWindow extends CreateUpdateTagLayo final String tagDescValue = HawkbitCommonUtil.trimAndNullIfEmpty(tagDesc.getValue()); if (null != tagNameValue) { - DistributionSetTag newDistTag = new DistributionSetTag(tagNameValue); - if (null != tagDescValue) { - newDistTag.setDescription(tagDescValue); - } - newDistTag.setColour(new Color(0, 146, 58).getCSS()); + DistributionSetTag newDistTag = tagManagement.generateDistributionSetTag(tagNameValue, tagDescValue, + new Color(0, 146, 58).getCSS()); + if (colorPicked != null) { newDistTag.setColour(colorPicked); } + newDistTag = tagManagement.createDistributionSetTag(newDistTag); uiNotification.displaySuccess(i18n.get("message.save.success", new Object[] { newDistTag.getName() })); resetDistTagValues(); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagBeanQuery.java index 9b66f2836..8be9548f7 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagBeanQuery.java @@ -12,8 +12,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.TagManagement; -import org.eclipse.hawkbit.repository.jpa.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.ui.management.tag.ProxyTag; import org.eclipse.hawkbit.ui.management.tag.TagIdName; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagButtons.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagButtons.java index 934d9c4c7..fbf882695 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagButtons.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagButtons.java @@ -14,6 +14,7 @@ import java.util.Map; import org.eclipse.hawkbit.eventbus.event.DistributionSetTagCreatedBulkEvent; import org.eclipse.hawkbit.eventbus.event.DistributionSetTagDeletedEvent; import org.eclipse.hawkbit.eventbus.event.DistributionSetTagUpdateEvent; +import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.ui.common.filterlayout.AbstractFilterButtonClickBehaviour; import org.eclipse.hawkbit.ui.common.filterlayout.AbstractFilterButtons; @@ -51,13 +52,16 @@ public class DistributionTagButtons extends AbstractFilterButtons { @Autowired private DistributionTagDropEvent spDistTagDropEvent; + @Autowired + private TagManagement tagManagement; + @Autowired private ManagementUIState managementUIState; @Override public void init(final AbstractFilterButtonClickBehaviour filterButtonClickBehaviour) { super.init(filterButtonClickBehaviour); - addNewTag(new DistributionSetTag("NO TAG")); + addNewTag(tagManagement.generateDistributionSetTag("NO TAG")); } @EventBusListenerMethod(scope = EventScope.SESSION) @@ -139,7 +143,7 @@ public class DistributionTagButtons extends AbstractFilterButtons { private void refreshTagTable() { ((LazyQueryContainer) getContainerDataSource()).refresh(); removeGeneratedColumn(FILTER_BUTTON_COLUMN); - addNewTag(new DistributionSetTag("NO TAG")); + addNewTag(tagManagement.generateDistributionSetTag("NO TAG")); addColumn(); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java index 2369893c7..9ef0b742c 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java @@ -380,7 +380,7 @@ public class BulkUploadHandler extends CustomComponent final String newDesc = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue()); /* create new target entity */ - final Target newTarget = new Target(newControllerId); + final Target newTarget = targetManagement.generateTarget(newControllerId); setTargetValues(newTarget, newName, newDesc); targetManagement.createTarget(newTarget); managementUIState.getTargetTableFilters().getBulkUpload().getTargetsCreated().add(newControllerId); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetAddUpdateWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetAddUpdateWindowLayout.java index e54911d86..ddf109773 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetAddUpdateWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetAddUpdateWindowLayout.java @@ -245,7 +245,7 @@ public class TargetAddUpdateWindowLayout extends CustomComponent { final String newDesc = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue()); /* create new target entity */ - Target newTarget = new Target(newControlllerId); + Target newTarget = targetManagement.generateTarget(newControlllerId); /* set values to the new target entity */ setTargetValues(newTarget, newName, newDesc); /* save new target */ diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBeanQuery.java index f3e0078f3..e96a9af8e 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBeanQuery.java @@ -13,8 +13,8 @@ import java.util.Collection; import java.util.List; import java.util.Map; +import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.TargetManagement; -import org.eclipse.hawkbit.repository.jpa.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetFilterQuery; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java index 4ed2580f6..62ad96205 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java @@ -21,9 +21,9 @@ import java.util.stream.Collectors; import org.eclipse.hawkbit.eventbus.event.TargetCreatedEvent; import org.eclipse.hawkbit.eventbus.event.TargetDeletedEvent; import org.eclipse.hawkbit.eventbus.event.TargetInfoUpdateEvent; +import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.repository.TargetManagement; -import org.eclipse.hawkbit.repository.jpa.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.model.DistributionSetIdName; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetFilterQuery; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/CreateUpdateTargetTagLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/CreateUpdateTargetTagLayout.java index 79a44c38c..efd4084f5 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/CreateUpdateTargetTagLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/CreateUpdateTargetTagLayout.java @@ -193,7 +193,7 @@ public class CreateUpdateTargetTagLayout extends CreateUpdateTagLayout { final String tagNameValue = HawkbitCommonUtil.trimAndNullIfEmpty(tagName.getValue()); final String tagDescValue = HawkbitCommonUtil.trimAndNullIfEmpty(tagDesc.getValue()); if (null != tagNameValue) { - TargetTag newTargetTag = new TargetTag(tagNameValue); + TargetTag newTargetTag = tagManagement.generateTargetTag(tagNameValue); if (null != tagDescValue) { newTargetTag.setDescription(tagDescValue); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagBeanQuery.java index 066383d8a..5164a409a 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagBeanQuery.java @@ -12,8 +12,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.TagManagement; -import org.eclipse.hawkbit.repository.jpa.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.model.TargetTag; import org.eclipse.hawkbit.ui.management.tag.ProxyTag; import org.eclipse.hawkbit.ui.management.tag.TagIdName; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java index 48447f112..58721d77d 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java @@ -16,6 +16,7 @@ import org.eclipse.hawkbit.eventbus.event.TargetTagCreatedBulkEvent; import org.eclipse.hawkbit.eventbus.event.TargetTagDeletedEvent; import org.eclipse.hawkbit.eventbus.event.TargetTagUpdateEvent; import org.eclipse.hawkbit.repository.SpPermissionChecker; +import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.model.TargetIdName; import org.eclipse.hawkbit.repository.model.TargetTag; @@ -75,6 +76,9 @@ public class TargetTagFilterButtons extends AbstractFilterButtons { @Autowired private SpPermissionChecker permChecker; + @Autowired + private TagManagement tagManagement; + @Autowired private transient TargetManagement targetManagement; @@ -90,7 +94,7 @@ public class TargetTagFilterButtons extends AbstractFilterButtons { public void init(final TargetTagFilterButtonClick filterButtonClickBehaviour) { this.filterButtonClickBehaviour = filterButtonClickBehaviour; super.init(filterButtonClickBehaviour); - addNewTargetTag(new TargetTag("NO TAG")); + addNewTargetTag(tagManagement.generateTargetTag("NO TAG")); } @EventBusListenerMethod(scope = EventScope.SESSION) @@ -290,7 +294,7 @@ public class TargetTagFilterButtons extends AbstractFilterButtons { private void refreshContainer() { removeGeneratedColumn(FILTER_BUTTON_COLUMN); ((LazyQueryContainer) getContainerDataSource()).refresh(); - addNewTargetTag(new TargetTag("NO TAG")); + addNewTargetTag(tagManagement.generateTargetTag("NO TAG")); addColumn(); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java index 7e8d45e1b..c6a2bdc4d 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java @@ -21,11 +21,12 @@ import org.eclipse.hawkbit.repository.model.DistributionSetIdName; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.Rollout.RolloutStatus; import org.eclipse.hawkbit.repository.model.RolloutGroup; -import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupConditions; import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupErrorAction; import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupErrorCondition; import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupSuccessAction; import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupSuccessCondition; +import org.eclipse.hawkbit.repository.model.RolloutGroupConditionBuilder; +import org.eclipse.hawkbit.repository.model.RolloutGroupConditions; import org.eclipse.hawkbit.ui.UiProperties; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; @@ -478,12 +479,12 @@ public class AddUpdateRolloutWindowLayout extends CustomComponent { } private Rollout saveRollout() { - Rollout rolloutToCreate = new Rollout(); + Rollout rolloutToCreate = rolloutManagement.generateRollout(); final int amountGroup = Integer.parseInt(noOfGroups.getValue()); final String targetFilter = getTargetFilterQuery(); final int errorThresoldPercent = getErrorThresoldPercentage(amountGroup); - final RolloutGroupConditions conditions = new RolloutGroup.RolloutGroupConditionBuilder() + final RolloutGroupConditions conditions = new RolloutGroupConditionBuilder() .successAction(RolloutGroupSuccessAction.NEXTGROUP, null) .successCondition(RolloutGroupSuccessCondition.THRESHOLD, triggerThreshold.getValue()) .errorCondition(RolloutGroupErrorCondition.THRESHOLD, String.valueOf(errorThresoldPercent)) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java index 04c6659a5..4074edb55 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java @@ -10,7 +10,7 @@ package org.eclipse.hawkbit.ui.rollout.rollout; import java.util.Set; -import org.eclipse.hawkbit.repository.model.Rollout; +import org.eclipse.hawkbit.repository.jpa.model.JpaRollout; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RolloutRendererData; @@ -20,7 +20,7 @@ import com.vaadin.server.FontAwesome; * Proxy rollout with custom properties. * */ -public class ProxyRollout extends Rollout { +public class ProxyRollout extends JpaRollout { private static final long serialVersionUID = 4539849939617681918L; @@ -59,7 +59,7 @@ public class ProxyRollout extends Rollout { * the isRequiredMigrationStep to set */ - public void setIsRequiredMigrationStep(Boolean isRequiredMigrationStep) { + public void setIsRequiredMigrationStep(final Boolean isRequiredMigrationStep) { this.isRequiredMigrationStep = isRequiredMigrationStep; } @@ -76,7 +76,7 @@ public class ProxyRollout extends Rollout { * the discription to set */ - public void setDiscription(String discription) { + public void setDiscription(final String discription) { this.discription = discription; } @@ -92,7 +92,7 @@ public class ProxyRollout extends Rollout { * the type to set */ - public void setType(String type) { + public void setType(final String type) { this.type = type; } @@ -108,7 +108,7 @@ public class ProxyRollout extends Rollout { * @param swModules * Set to set */ - public void setSwModules(Set swModules) { + public void setSwModules(final Set swModules) { this.swModules = swModules; } @@ -116,7 +116,7 @@ public class ProxyRollout extends Rollout { return rolloutRendererData; } - public void setRolloutRendererData(RolloutRendererData rendererData) { + public void setRolloutRendererData(final RolloutRendererData rendererData) { this.rolloutRendererData = rendererData; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java index 08f2c0a0b..f6653d971 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java @@ -8,212 +8,212 @@ */ package org.eclipse.hawkbit.ui.rollout.rolloutgroup; -import org.eclipse.hawkbit.repository.model.RolloutGroup; +import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup; import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RolloutRendererData; /** * Proxy rollout group with renderer properties. * */ -public class ProxyRolloutGroup extends RolloutGroup { +public class ProxyRolloutGroup extends JpaRolloutGroup { - private static final long serialVersionUID = -2745056813306692356L; + private static final long serialVersionUID = -2745056813306692356L; - private String createdDate; + private String createdDate; - private String modifiedDate; + private String modifiedDate; - private String finishedPercentage; + private String finishedPercentage; - private Long runningTargetsCount; + private Long runningTargetsCount; - private Long scheduledTargetsCount; + private Long scheduledTargetsCount; - private Long cancelledTargetsCount; + private Long cancelledTargetsCount; - private Long errorTargetsCount; + private Long errorTargetsCount; - private Long finishedTargetsCount; + private Long finishedTargetsCount; - private Long notStartedTargetsCount; + private Long notStartedTargetsCount; - private Boolean isActionRecieved = Boolean.FALSE; + private Boolean isActionRecieved = Boolean.FALSE; - private String totalTargetsCount; + private String totalTargetsCount; - private RolloutRendererData rolloutRendererData; + private RolloutRendererData rolloutRendererData; - public RolloutRendererData getRolloutRendererData() { - return rolloutRendererData; - } + public RolloutRendererData getRolloutRendererData() { + return rolloutRendererData; + } - public void setRolloutRendererData(RolloutRendererData rendererData) { - this.rolloutRendererData = rendererData; - } + public void setRolloutRendererData(final RolloutRendererData rendererData) { + this.rolloutRendererData = rendererData; + } - /** - * @return the createdDate - */ - public String getCreatedDate() { - return createdDate; - } + /** + * @return the createdDate + */ + public String getCreatedDate() { + return createdDate; + } - /** - * @param createdDate - * the createdDate to set - */ - public void setCreatedDate(final String createdDate) { - this.createdDate = createdDate; - } + /** + * @param createdDate + * the createdDate to set + */ + public void setCreatedDate(final String createdDate) { + this.createdDate = createdDate; + } - /** - * @return the modifiedDate - */ - public String getModifiedDate() { - return modifiedDate; - } + /** + * @return the modifiedDate + */ + public String getModifiedDate() { + return modifiedDate; + } - /** - * @param modifiedDate - * the modifiedDate to set - */ - public void setModifiedDate(final String modifiedDate) { - this.modifiedDate = modifiedDate; - } + /** + * @param modifiedDate + * the modifiedDate to set + */ + public void setModifiedDate(final String modifiedDate) { + this.modifiedDate = modifiedDate; + } - /** - * @return the finishedPercentage - */ - public String getFinishedPercentage() { - return finishedPercentage; - } + /** + * @return the finishedPercentage + */ + public String getFinishedPercentage() { + return finishedPercentage; + } - /** - * @param finishedPercentage - * the finishedPercentage to set - */ - public void setFinishedPercentage(final String finishedPercentage) { - this.finishedPercentage = finishedPercentage; - } + /** + * @param finishedPercentage + * the finishedPercentage to set + */ + public void setFinishedPercentage(final String finishedPercentage) { + this.finishedPercentage = finishedPercentage; + } - /** - * @return the runningTargetsCount - */ - public Long getRunningTargetsCount() { - return runningTargetsCount; - } + /** + * @return the runningTargetsCount + */ + public Long getRunningTargetsCount() { + return runningTargetsCount; + } - /** - * @param runningTargetsCount - * the runningTargetsCount to set - */ - public void setRunningTargetsCount(final Long runningTargetsCount) { - this.runningTargetsCount = runningTargetsCount; - } + /** + * @param runningTargetsCount + * the runningTargetsCount to set + */ + public void setRunningTargetsCount(final Long runningTargetsCount) { + this.runningTargetsCount = runningTargetsCount; + } - /** - * @return the scheduledTargetsCount - */ - public Long getScheduledTargetsCount() { - return scheduledTargetsCount; - } + /** + * @return the scheduledTargetsCount + */ + public Long getScheduledTargetsCount() { + return scheduledTargetsCount; + } - /** - * @param scheduledTargetsCount - * the scheduledTargetsCount to set - */ - public void setScheduledTargetsCount(final Long scheduledTargetsCount) { - this.scheduledTargetsCount = scheduledTargetsCount; - } + /** + * @param scheduledTargetsCount + * the scheduledTargetsCount to set + */ + public void setScheduledTargetsCount(final Long scheduledTargetsCount) { + this.scheduledTargetsCount = scheduledTargetsCount; + } - /** - * @return the cancelledTargetsCount - */ - public Long getCancelledTargetsCount() { - return cancelledTargetsCount; - } + /** + * @return the cancelledTargetsCount + */ + public Long getCancelledTargetsCount() { + return cancelledTargetsCount; + } - /** - * @param cancelledTargetsCount - * the cancelledTargetsCount to set - */ - public void setCancelledTargetsCount(final Long cancelledTargetsCount) { - this.cancelledTargetsCount = cancelledTargetsCount; - } + /** + * @param cancelledTargetsCount + * the cancelledTargetsCount to set + */ + public void setCancelledTargetsCount(final Long cancelledTargetsCount) { + this.cancelledTargetsCount = cancelledTargetsCount; + } - /** - * @return the errorTargetsCount - */ - public Long getErrorTargetsCount() { - return errorTargetsCount; - } + /** + * @return the errorTargetsCount + */ + public Long getErrorTargetsCount() { + return errorTargetsCount; + } - /** - * @param errorTargetsCount - * the errorTargetsCount to set - */ - public void setErrorTargetsCount(final Long errorTargetsCount) { - this.errorTargetsCount = errorTargetsCount; - } + /** + * @param errorTargetsCount + * the errorTargetsCount to set + */ + public void setErrorTargetsCount(final Long errorTargetsCount) { + this.errorTargetsCount = errorTargetsCount; + } - /** - * @return the finishedTargetsCount - */ - public Long getFinishedTargetsCount() { - return finishedTargetsCount; - } + /** + * @return the finishedTargetsCount + */ + public Long getFinishedTargetsCount() { + return finishedTargetsCount; + } - /** - * @param finishedTargetsCount - * the finishedTargetsCount to set - */ - public void setFinishedTargetsCount(final Long finishedTargetsCount) { - this.finishedTargetsCount = finishedTargetsCount; - } + /** + * @param finishedTargetsCount + * the finishedTargetsCount to set + */ + public void setFinishedTargetsCount(final Long finishedTargetsCount) { + this.finishedTargetsCount = finishedTargetsCount; + } - /** - * @return the notStartedTargetsCount - */ - public Long getNotStartedTargetsCount() { - return notStartedTargetsCount; - } + /** + * @return the notStartedTargetsCount + */ + public Long getNotStartedTargetsCount() { + return notStartedTargetsCount; + } - /** - * @param notStartedTargetsCount - * the notStartedTargetsCount to set - */ - public void setNotStartedTargetsCount(final Long notStartedTargetsCount) { - this.notStartedTargetsCount = notStartedTargetsCount; - } + /** + * @param notStartedTargetsCount + * the notStartedTargetsCount to set + */ + public void setNotStartedTargetsCount(final Long notStartedTargetsCount) { + this.notStartedTargetsCount = notStartedTargetsCount; + } - /** - * @return the isActionRecieved - */ - public Boolean getIsActionRecieved() { - return isActionRecieved; - } + /** + * @return the isActionRecieved + */ + public Boolean getIsActionRecieved() { + return isActionRecieved; + } - /** - * @param isActionRecieved - * the isActionRecieved to set - */ - public void setIsActionRecieved(final Boolean isActionRecieved) { - this.isActionRecieved = isActionRecieved; - } + /** + * @param isActionRecieved + * the isActionRecieved to set + */ + public void setIsActionRecieved(final Boolean isActionRecieved) { + this.isActionRecieved = isActionRecieved; + } - /** - * @return the totalTargetsCount - */ - public String getTotalTargetsCount() { - return totalTargetsCount; - } + /** + * @return the totalTargetsCount + */ + public String getTotalTargetsCount() { + return totalTargetsCount; + } - /** - * @param totalTargetsCount - * the totalTargetsCount to set - */ - public void setTotalTargetsCount(final String totalTargetsCount) { - this.totalTargetsCount = totalTargetsCount; - } + /** + * @param totalTargetsCount + * the totalTargetsCount to set + */ + public void setTotalTargetsCount(final String totalTargetsCount) { + this.totalTargetsCount = totalTargetsCount; + } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java index 0e71567af..5491acaaf 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java @@ -24,10 +24,10 @@ import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.model.AssignmentResult; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.NamedEntity; +import org.eclipse.hawkbit.repository.model.PollStatus; import org.eclipse.hawkbit.repository.model.RolloutGroup; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; -import org.eclipse.hawkbit.repository.model.TargetInfo.PollStatus; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus.Status; @@ -781,10 +781,10 @@ public final class HawkbitCommonUtil { * base software module description * @return BaseSoftwareModule new base software module */ - public static SoftwareModule addNewBaseSoftware(final String bsname, final String bsversion, final String bsvendor, - final SoftwareModuleType bstype, final String description) { + public static SoftwareModule addNewBaseSoftware(final SoftwareManagement softwareManagement, final String bsname, + final String bsversion, final String bsvendor, final SoftwareModuleType bstype, final String description) { final SoftwareManagement swMgmtService = SpringContextHelper.getBean(SoftwareManagement.class); - SoftwareModule newSWModule = new SoftwareModule(); + SoftwareModule newSWModule = softwareManagement.generateSoftwareModule(); newSWModule.setType(bstype); newSWModule.setName(bsname); newSWModule.setVersion(bsversion); From 9301de096c6f1a7fdd2aab0ac0a5a541682c44bc Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Sun, 22 May 2016 08:48:47 +0200 Subject: [PATCH 18/54] Worked on the interfaces and documentation. Signed-off-by: Kai Zimmermann --- .../resource/DdiArtifactStoreController.java | 4 +- .../ddi/rest/resource/DdiRootController.java | 22 ++-- .../resource/DdiArtifactDownloadTest.java | 26 ++-- .../rest/resource/DdiCancelActionTest.java | 12 +- .../ddi/rest/resource/DdiConfigDataTest.java | 8 +- .../rest/resource/DdiDeploymentBaseTest.java | 102 ++++++++------- .../rest/resource/DdiRootControllerTest.java | 6 +- .../amqp/AmqpMessageDispatcherService.java | 4 + .../amqp/AmqpMessageHandlerService.java | 2 +- .../amqp/AmqpMessageHandlerServiceTest.java | 12 +- .../hawkbit/dmf/json/model/ActionStatus.java | 39 +++++- .../resource/MgmtDistributionSetMapper.java | 18 +-- .../resource/MgmtDistributionSetResource.java | 31 ++--- .../MgmtDistributionSetTagResource.java | 8 +- .../MgmtDistributionSetTypeMapper.java | 16 ++- .../MgmtDistributionSetTypeResource.java | 12 +- .../mgmt/rest/resource/MgmtRolloutMapper.java | 7 +- .../rest/resource/MgmtRolloutResource.java | 19 +-- .../resource/MgmtSoftwareModuleMapper.java | 14 +- .../resource/MgmtSoftwareModuleResource.java | 23 ++-- .../MgmtSoftwareModuleTypeMapper.java | 18 ++- .../MgmtSoftwareModuleTypeResource.java | 9 +- .../mgmt/rest/resource/MgmtTagMapper.java | 20 +-- .../mgmt/rest/resource/MgmtTargetMapper.java | 12 +- .../rest/resource/MgmtTargetResource.java | 18 +-- .../rest/resource/MgmtTargetTagResource.java | 7 +- .../MgmtDistributionSetResourceTest.java | 120 +++++++++-------- .../MgmtDistributionSetTypeResourceTest.java | 97 +++++++------- .../resource/MgmtRolloutResourceTest.java | 4 +- .../MgmtSoftwareModuleResourceTest.java | 122 ++++++++++-------- .../MgmtSoftwareModuleTypeResourceTest.java | 32 ++--- .../rest/resource/MgmtTargetResourceTest.java | 75 +++++------ ...MRessourceMisingMongoDbConnectionTest.java | 2 +- .../repository/DeploymentManagement.java | 9 +- .../DistributionSetAssignmentResult.java | 3 +- .../repository/DistributionSetManagement.java | 15 ++- .../hawkbit/repository/TagManagement.java | 46 ++++++- .../jpa/JpaControllerManagement.java | 2 +- .../jpa/JpaTenantConfigurationManagement.java | 7 +- .../jpa/model/JpaDistributionSetTag.java | 5 +- .../repository/jpa/model/JpaRollout.java | 1 - .../jpa/model/JpaSoftwareModuleType.java | 14 +- .../jpa/model/JpaTargetFilterQuery.java | 8 ++ .../repository/jpa/model/JpaTargetTag.java | 2 +- .../TargetFilterQuerySpecification.java | 10 +- .../hawkbit/repository/model/Action.java | 4 +- .../hawkbit/repository/model/PollStatus.java | 68 ++++++++++ .../hawkbit/repository/model/Rollout.java | 32 ++++- .../repository/model/RolloutGroup.java | 2 +- .../model/RolloutGroupConditionBuilder.java | 91 +++++++++++++ .../model/RolloutGroupConditions.java | 93 +++++++++++++ .../repository/model/SoftwareModuleType.java | 37 +++++- .../repository/model/TargetIdName.java | 2 + .../model/TenantConfigurationValue.java | 12 +- .../model/TotalTargetCountStatus.java | 93 ++++++++----- 55 files changed, 971 insertions(+), 506 deletions(-) create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/PollStatus.java create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/RolloutGroupConditionBuilder.java create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/RolloutGroupConditions.java diff --git a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java index 9c51cf8f4..36fa926e8 100644 --- a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java +++ b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java @@ -138,7 +138,7 @@ public class DdiArtifactStoreController implements DdiDlArtifactStoreControllerR .getActionForDownloadByTargetAndSoftwareModule(target.getControllerId(), artifact.getSoftwareModule()); final String range = request.getHeader("Range"); - final ActionStatus actionStatus = new ActionStatus(); + final ActionStatus actionStatus = controllerManagement.generateActionStatus(); actionStatus.setAction(action); actionStatus.setOccurredAt(System.currentTimeMillis()); actionStatus.setStatus(Status.DOWNLOAD); @@ -150,7 +150,7 @@ public class DdiArtifactStoreController implements DdiDlArtifactStoreControllerR actionStatus.addMessage( ControllerManagement.SERVER_MESSAGE_PREFIX + "Target downloads: " + request.getRequestURI()); } - controllerManagement.addActionStatusMessage(actionStatus); + controllerManagement.addInformationalActionStatus(actionStatus); return action; } diff --git a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java index 3bf70ccfd..355a43b3c 100644 --- a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java +++ b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java @@ -132,7 +132,7 @@ public class DdiRootController implements DdiRootControllerRestApi { return new ResponseEntity<>( DataConversionHelper.fromTarget(target, controllerManagement.findActionByTargetAndActive(target), - controllerManagement.findPollingTime(), tenantAware), + controllerManagement.getPollingTime(), tenantAware), HttpStatus.OK); } @@ -174,7 +174,7 @@ public class DdiRootController implements DdiRootControllerRestApi { .getActionForDownloadByTargetAndSoftwareModule(target.getControllerId(), module); final String range = request.getHeader("Range"); - final ActionStatus statusMessage = new ActionStatus(); + final ActionStatus statusMessage = controllerManagement.generateActionStatus(); statusMessage.setAction(action); statusMessage.setOccurredAt(System.currentTimeMillis()); statusMessage.setStatus(Status.DOWNLOAD); @@ -186,7 +186,7 @@ public class DdiRootController implements DdiRootControllerRestApi { statusMessage.addMessage( ControllerManagement.SERVER_MESSAGE_PREFIX + "Target downloads " + request.getRequestURI()); } - controllerManagement.addActionStatusMessage(statusMessage); + controllerManagement.addInformationalActionStatus(statusMessage); return action; } @@ -247,8 +247,7 @@ public class DdiRootController implements DdiRootControllerRestApi { LOG.debug("Found an active UpdateAction for target {}. returning deyploment: {}", targetid, base); - controllerManagement.registerRetrieved(action, - ControllerManagement.SERVER_MESSAGE_PREFIX + controllerManagement.registerRetrieved(action, ControllerManagement.SERVER_MESSAGE_PREFIX + "Target retrieved update action and should start now the download."); return new ResponseEntity<>(base, HttpStatus.OK); @@ -285,8 +284,7 @@ public class DdiRootController implements DdiRootControllerRestApi { return new ResponseEntity<>(HttpStatus.GONE); } - controllerManagement.addUpdateActionStatus( - generateUpdateStatus(feedback, targetid, feedback.getId(), action), action); + controllerManagement.addUpdateActionStatus(generateUpdateStatus(feedback, targetid, feedback.getId(), action)); return new ResponseEntity<>(HttpStatus.OK); @@ -295,7 +293,7 @@ public class DdiRootController implements DdiRootControllerRestApi { private ActionStatus generateUpdateStatus(final DdiActionFeedback feedback, final String targetid, final Long actionid, final Action action) { - final ActionStatus actionStatus = new ActionStatus(); + final ActionStatus actionStatus = controllerManagement.generateActionStatus(); actionStatus.setAction(action); actionStatus.setOccurredAt(System.currentTimeMillis()); @@ -420,15 +418,15 @@ public class DdiRootController implements DdiRootControllerRestApi { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } - controllerManagement - .addCancelActionStatus(generateActionCancelStatus(feedback, target, feedback.getId(), action), action); + controllerManagement.addCancelActionStatus( + generateActionCancelStatus(feedback, target, feedback.getId(), action, controllerManagement)); return new ResponseEntity<>(HttpStatus.OK); } private static ActionStatus generateActionCancelStatus(final DdiActionFeedback feedback, final Target target, - final Long actionid, final Action action) { + final Long actionid, final Action action, final ControllerManagement controllerManagement) { - final ActionStatus actionStatus = new ActionStatus(); + final ActionStatus actionStatus = controllerManagement.generateActionStatus(); actionStatus.setAction(action); actionStatus.setOccurredAt(System.currentTimeMillis()); diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java index 6c3bdea4e..25e4776c9 100644 --- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java +++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java @@ -73,7 +73,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong @Description("Tests non allowed requests on the artifact ressource, e.g. invalid URI, wrong if-match, wrong command.") public void invalidRequestsOnArtifactResource() throws Exception { // create target - Target target = new Target("4712"); + Target target = targetManagement.generateTarget("4712"); target = targetManagement.createTarget(target); final List targets = new ArrayList<>(); targets.add(target); @@ -158,7 +158,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong @Description("Tests non allowed requests on the artifact ressource, e.g. invalid URI, wrong if-match, wrong command.") public void invalidRequestsOnArtifactResourceByName() throws Exception { // create target - Target target = new Target("4712"); + Target target = targetManagement.generateTarget("4712"); target = targetManagement.createTarget(target); final List targets = new ArrayList<>(); targets.add(target); @@ -244,7 +244,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong assertThat(artifactRepository.findAll()).hasSize(0); // create target - Target target = new Target("4712"); + Target target = targetManagement.generateTarget("4712"); target = targetManagement.createTarget(target); final List targets = new ArrayList(); targets.add(target); @@ -287,7 +287,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong @Description("Tests valid MD5SUm file downloads through the artifact resource by identifying the artifact by ID.") public void downloadMd5sumThroughControllerApi() throws Exception { // create target - Target target = new Target("4712"); + Target target = targetManagement.generateTarget("4712"); target = targetManagement.createTarget(target); // create ds @@ -325,7 +325,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong assertThat(artifactRepository.findAll()).hasSize(0); // create target - Target target = new Target("4712"); + Target target = targetManagement.generateTarget("4712"); target = targetManagement.createTarget(target); final List targets = new ArrayList(); targets.add(target); @@ -356,7 +356,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong assertThat(artifactRepository.findAll()).hasSize(0); // create target - Target target = new Target("4712"); + Target target = targetManagement.generateTarget("4712"); target = targetManagement.createTarget(target); final List targets = new ArrayList<>(); targets.add(target); @@ -389,13 +389,13 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong Arrays.equals(result.getResponse().getContentAsByteArray(), random)); // one (update) action - assertThat(actionRepository.findByTargetAndDistributionSet(pageReq, target, ds).getContent()).hasSize(1); - final Action action = actionRepository.findByTargetAndDistributionSet(pageReq, target, ds).getContent().get(0); + assertThat(deploymentManagement.findActionsByTarget(target)).hasSize(1); + final Action action = deploymentManagement.findActionsByTarget(target).get(0); // one status - download assertThat(actionStatusRepository.findAll()).hasSize(2); - assertThat(actionStatusRepository.findByAction(pageReq, action).getContent()).hasSize(2); - assertThat(actionStatusRepository.findByAction(new PageRequest(0, 400, Direction.DESC, "id"), action) + assertThat(action.getActionStatus()).hasSize(2); + assertThat(deploymentManagement.findActionStatusByAction(new PageRequest(0, 400, Direction.DESC, "id"), action) .getContent().get(0).getStatus()).isEqualTo(Status.DOWNLOAD); // download complete @@ -407,7 +407,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong @Description("Test various HTTP range requests for artifact download, e.g. chunk download or download resume.") public void rangeDownloadArtifactByName() throws Exception { // create target - Target target = new Target("4712"); + Target target = targetManagement.generateTarget("4712"); target = targetManagement.createTarget(target); final List targets = new ArrayList<>(); targets.add(target); @@ -515,7 +515,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong assertThat(artifactRepository.findAll()).hasSize(0); // create target - Target target = new Target("4712"); + Target target = targetManagement.generateTarget("4712"); target = targetManagement.createTarget(target); final List targets = new ArrayList<>(); targets.add(target); @@ -538,7 +538,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong @Description("Downloads an MD5SUM file by the related artifacts filename.") public void downloadMd5sumFileByName() throws Exception { // create target - Target target = new Target("4712"); + Target target = targetManagement.generateTarget("4712"); target = targetManagement.createTarget(target); // create ds diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiCancelActionTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiCancelActionTest.java index 9913d5e51..b52d0fddc 100644 --- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiCancelActionTest.java +++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiCancelActionTest.java @@ -49,7 +49,7 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest { @Description("Test of the controller can continue a started update even after a cancel command if it so desires.") public void rootRsCancelActionButContinueAnyway() throws Exception { // prepare test data - final Target target = new Target("4712"); + final Target target = targetManagement.generateTarget("4712"); final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement, distributionSetManagement); final Target savedTarget = targetManagement.createTarget(target); @@ -106,7 +106,7 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest { @Test @Description("Test for cancel operation of a update action.") public void rootRsCancelAction() throws Exception { - final Target target = new Target("4712"); + final Target target = targetManagement.generateTarget("4712"); final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement, distributionSetManagement); final Target savedTarget = targetManagement.createTarget(target); @@ -224,7 +224,7 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest { } private Action createCancelAction(final String targetid) { - final Target target = new Target(targetid); + final Target target = targetManagement.generateTarget(targetid); final DistributionSet ds = TestDataUtil.generateDistributionSet(targetid, softwareManagement, distributionSetManagement); final Target savedTarget = targetManagement.createTarget(target); @@ -241,7 +241,7 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest { @Description("Tests the feedback channel of the cancel operation.") public void rootRsCancelActionFeedback() throws Exception { - final Target target = new Target("4712"); + final Target target = targetManagement.generateTarget("4712"); final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement, distributionSetManagement); @@ -334,7 +334,7 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest { @Test @Description("Tests the feeback chanel of for multiple open cancel operations on the same target.") public void multipleCancelActionFeedback() throws Exception { - final Target target = new Target("4712"); + final Target target = targetManagement.generateTarget("4712"); final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement, distributionSetManagement, true); final DistributionSet ds2 = TestDataUtil.generateDistributionSet("2", softwareManagement, @@ -453,7 +453,7 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest { @Test @Description("Tests the feeback channel closing for too many feedbacks, i.e. denial of service prevention.") public void tooMuchCancelActionFeedback() throws Exception { - final Target target = targetManagement.createTarget(new Target("4712")); + final Target target = targetManagement.createTarget(targetManagement.generateTarget("4712")); final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement, distributionSetManagement); diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiConfigDataTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiConfigDataTest.java index 4a86cfe8c..afb60043d 100644 --- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiConfigDataTest.java +++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiConfigDataTest.java @@ -46,7 +46,7 @@ public class DdiConfigDataTest extends AbstractIntegrationTest { @Description("We verify that the config data (i.e. device attributes like serial number, hardware revision etc.) " + "are requested only once from the device.") public void requestConfigDataIfEmpty() throws Exception { - final Target target = new Target("4712"); + final Target target = targetManagement.generateTarget("4712"); final Target savedTarget = targetManagement.createTarget(target); final long current = System.currentTimeMillis(); @@ -84,7 +84,7 @@ public class DdiConfigDataTest extends AbstractIntegrationTest { @Description("We verify that the config data (i.e. device attributes like serial number, hardware revision etc.) " + "can be uploaded correctly by the controller.") public void putConfigData() throws Exception { - targetManagement.createTarget(new Target("4717")); + targetManagement.createTarget(targetManagement.generateTarget("4717")); // initial final Map attributes = new HashMap<>(); @@ -127,7 +127,7 @@ public class DdiConfigDataTest extends AbstractIntegrationTest { @Description("We verify that the config data (i.e. device attributes like serial number, hardware revision etc.) " + "upload limitation is inplace which is meant to protect the server from malicious attempts.") public void putToMuchConfigData() throws Exception { - targetManagement.createTarget(new Target("4717")); + targetManagement.createTarget(targetManagement.generateTarget("4717")); // initial Map attributes = new HashMap<>(); @@ -150,7 +150,7 @@ public class DdiConfigDataTest extends AbstractIntegrationTest { @Description("We verify that the config data (i.e. device attributes like serial number, hardware revision etc.) " + "resource behaves as exptected in cae of invalid request attempts.") public void badConfigData() throws Exception { - final Target target = new Target("4712"); + final Target target = targetManagement.generateTarget("4712"); final Target savedTarget = targetManagement.createTarget(target); // not allowed methods diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java index df75bc6b3..741a6729a 100644 --- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java +++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java @@ -26,6 +26,7 @@ import java.util.List; import org.apache.commons.lang3.RandomUtils; import org.eclipse.hawkbit.TestDataUtil; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.ActionType; import org.eclipse.hawkbit.repository.model.Action.Status; @@ -40,8 +41,6 @@ import org.eclipse.hawkbit.rest.util.MockMvcResultPrinter; import org.fest.assertions.core.Condition; import org.junit.Test; import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort.Direction; import org.springframework.hateoas.MediaTypes; import org.springframework.http.MediaType; @@ -96,7 +95,7 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD @Description("Forced deployment to a controller. Checks if the resource reponse payload for a given deployment is as expected.") public void deplomentForceAction() throws Exception { // Prepare test data - final Target target = new Target("4712"); + final Target target = targetManagement.generateTarget("4712"); final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement, distributionSetManagement, true); final DistributionSet ds2 = TestDataUtil.generateDistributionSet("2", softwareManagement, @@ -228,9 +227,9 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD .isGreaterThanOrEqualTo(current); // Retrieved is reported - final Iterable actionStatusMessages = actionStatusRepository - .findAll(new PageRequest(0, 100, Direction.DESC, "id")); - assertThat(actionStatusMessages).hasSize(3); + final Iterable actionStatusMessages = deploymentManagement + .findActionStatusByAction(new PageRequest(0, 100, Direction.DESC, "id"), uaction); + assertThat(actionStatusMessages).hasSize(2); final ActionStatus actionStatusMessage = actionStatusMessages.iterator().next(); assertThat(actionStatusMessage.getStatus()).isEqualTo(Status.RETRIEVED); } @@ -239,7 +238,7 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD @Description("Attempt/soft deployment to a controller. Checks if the resource reponse payload for a given deployment is as expected.") public void deplomentAttemptAction() throws Exception { // Prepare test data - final Target target = new Target("4712"); + final Target target = targetManagement.generateTarget("4712"); final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement, distributionSetManagement, true); final DistributionSet ds2 = TestDataUtil.generateDistributionSet("2", softwareManagement, @@ -361,9 +360,9 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD .isGreaterThanOrEqualTo(current); // Retrieved is reported - final Iterable actionStatusMessages = actionStatusRepository - .findAll(new PageRequest(0, 100, Direction.DESC, "id")); - assertThat(actionStatusMessages).hasSize(3); + final List actionStatusMessages = deploymentManagement + .findActionStatusByAction(new PageRequest(0, 100, Direction.DESC, "id"), uaction).getContent(); + assertThat(actionStatusMessages).hasSize(2); final ActionStatus actionStatusMessage = actionStatusMessages.iterator().next(); assertThat(actionStatusMessage.getStatus()).isEqualTo(Status.RETRIEVED); } @@ -372,7 +371,7 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD @Description("Attempt/soft deployment to a controller including automated switch to hard. Checks if the resource reponse payload for a given deployment is as expected.") public void deplomentAutoForceAction() throws Exception { // Prepare test data - final Target target = new Target("4712"); + final Target target = targetManagement.generateTarget("4712"); final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement, distributionSetManagement, true); final DistributionSet ds2 = TestDataUtil.generateDistributionSet("2", softwareManagement, @@ -503,9 +502,9 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD .isGreaterThanOrEqualTo(current); // Retrieved is reported - final Iterable actionStatusMessages = actionStatusRepository - .findAll(new PageRequest(0, 100, Direction.DESC, "id")); - assertThat(actionStatusMessages).hasSize(3); + final Iterable actionStatusMessages = deploymentManagement + .findActionStatusByAction(new PageRequest(0, 100, Direction.DESC, "id"), uaction).getContent(); + assertThat(actionStatusMessages).hasSize(2); final ActionStatus actionStatusMessage = actionStatusMessages.iterator().next(); assertThat(actionStatusMessage.getStatus()).isEqualTo(Status.RETRIEVED); } @@ -513,7 +512,7 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD @Test @Description("Test various invalid access attempts to the deployment resource und the expected behaviour of the server.") public void badDeploymentAction() throws Exception { - final Target target = targetManagement.createTarget(new Target("4712")); + final Target target = targetManagement.createTarget(targetManagement.generateTarget("4712")); // not allowed methods mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/1", tenantAware.getCurrentTenant())) @@ -534,7 +533,7 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD .andDo(MockMvcResultPrinter.print()).andExpect(status().isNotFound()); // wrong media type - final List toAssign = new ArrayList(); + final List toAssign = new ArrayList<>(); toAssign.add(target); final DistributionSet savedSet = TestDataUtil.generateDistributionSet("", softwareManagement, distributionSetManagement); @@ -554,16 +553,15 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD @Description("The server protects itself against to many feedback upload attempts. The test verfies that " + "it is not possible to exceed the configured maximum number of feedback uplods.") public void toMuchDeplomentActionFeedback() throws Exception { - final Target target = targetManagement.createTarget(new Target("4712")); + final Target target = targetManagement.createTarget(targetManagement.generateTarget("4712")); final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement, distributionSetManagement); - final List toAssign = new ArrayList(); + final List toAssign = new ArrayList<>(); toAssign.add(target); deploymentManagement.assignDistributionSet(ds.getId(), new String[] { "4712" }); - final Pageable pageReq = new PageRequest(0, 100); - final Action action = actionRepository.findByDistributionSet(pageReq, ds).getContent().get(0); + final Action action = deploymentManagement.findActionsByTarget(target).get(0); final String feedback = JsonBuilder.deploymentActionFeedback(action.getId().toString(), "proceeding"); // assign distribution set creates an action status, so only 99 left @@ -583,9 +581,9 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD @Test @Description("Multiple uploads of deployment status feedback to the server.") public void multipleDeplomentActionFeedback() throws Exception { - final Target target1 = new Target("4712"); - final Target target2 = new Target("4713"); - final Target target3 = new Target("4714"); + final Target target1 = targetManagement.generateTarget("4712"); + final Target target2 = targetManagement.generateTarget("4713"); + final Target target3 = targetManagement.generateTarget("4714"); final Target savedTarget1 = targetManagement.createTarget(target1); targetManagement.createTarget(target2); targetManagement.createTarget(target3); @@ -597,7 +595,7 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD final DistributionSet ds3 = TestDataUtil.generateDistributionSet("3", softwareManagement, distributionSetManagement, true); - final List toAssign = new ArrayList(); + final List toAssign = new ArrayList<>(); toAssign.add(savedTarget1); final Action action1 = deploymentManagement.findActionWithDetails( @@ -637,7 +635,8 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD assertThat(myT.getTargetInfo().getInstalledDistributionSet().getId()).isEqualTo(ds1.getId()); assertThat(myT.getAssignedDistributionSet()).isEqualTo(ds3); - Iterable actionStatusMessages = actionStatusRepository.findAll(new Sort(Direction.DESC, "id")); + Iterable actionStatusMessages = deploymentManagement + .findActionStatusAll(new PageRequest(0, 100, Direction.DESC, "id")).getContent(); assertThat(actionStatusMessages).hasSize(4); assertThat(actionStatusMessages.iterator().next().getStatus()).isEqualTo(Status.FINISHED); @@ -657,7 +656,8 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD assertThat(deploymentManagement.findActiveActionsByTarget(myT)).hasSize(1); assertThat(myT.getTargetInfo().getInstalledDistributionSet().getId()).isEqualTo(ds2.getId()); assertThat(myT.getAssignedDistributionSet()).isEqualTo(ds3); - actionStatusMessages = actionStatusRepository.findAll(new PageRequest(0, 100, Direction.DESC, "id")); + actionStatusMessages = deploymentManagement.findActionStatusAll(new PageRequest(0, 100, Direction.DESC, "id")) + .getContent(); assertThat(actionStatusMessages).hasSize(5); assertThat(actionStatusMessages).haveAtLeast(1, new ActionStatusCondition(Status.FINISHED)); @@ -676,7 +676,8 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD assertThat(deploymentManagement.findActiveActionsByTarget(myT)).hasSize(0); assertThat(myT.getTargetInfo().getInstalledDistributionSet()).isEqualTo(ds3); assertThat(myT.getAssignedDistributionSet()).isEqualTo(ds3); - actionStatusMessages = actionStatusRepository.findAll(); + actionStatusMessages = deploymentManagement.findActionStatusAll(new PageRequest(0, 100, Direction.DESC, "id")) + .getContent(); assertThat(actionStatusMessages).hasSize(6); assertThat(actionStatusMessages).haveAtLeast(1, new ActionStatusCondition(Status.FINISHED)); @@ -685,18 +686,19 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD @Test @Description("Verfies that an update action is correctly set to error if the controller provides error feedback.") public void rootRsSingleDeplomentActionWithErrorFeedback() throws Exception { - final Target target = new Target("4712"); + final Target target = targetManagement.generateTarget("4712"); DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement, distributionSetManagement); final Target savedTarget = targetManagement.createTarget(target); - List toAssign = new ArrayList(); + List toAssign = new ArrayList<>(); toAssign.add(savedTarget); assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus()) .isEqualTo(TargetUpdateStatus.UNKNOWN); deploymentManagement.assignDistributionSet(ds, toAssign); - final Action action = actionRepository.findByDistributionSet(pageReq, ds).getContent().get(0); + final Action action = actionRepository.findByDistributionSet(pageReq, (JpaDistributionSet) ds).getContent() + .get(0); long current = System.currentTimeMillis(); long lastModified = targetManagement.findTargetByControllerID("4712").getLastModifiedAt(); @@ -719,7 +721,8 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD .hasSize(0); assertThat(deploymentManagement.findActiveActionsByTarget(myT)).hasSize(0); assertThat(deploymentManagement.findActionsByTarget(myT)).hasSize(1); - final Iterable actionStatusMessages = actionStatusRepository.findAll(); + final Iterable actionStatusMessages = deploymentManagement + .findActionStatusAll(new PageRequest(0, 100, Direction.DESC, "id")).getContent(); assertThat(actionStatusMessages).hasSize(2); assertThat(actionStatusMessages).haveAtLeast(1, new ActionStatusCondition(Status.ERROR)); @@ -751,9 +754,9 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD assertThat(deploymentManagement.findActiveActionsByTarget(myT)).hasSize(0); assertThat(deploymentManagement.findInActiveActionsByTarget(myT)).hasSize(2); assertThat(actionStatusRepository.findAll()).hasSize(4); - assertThat(actionStatusRepository.findByAction(pageReq, action).getContent()).haveAtLeast(1, + assertThat(deploymentManagement.findActionStatusByAction(pageReq, action).getContent()).haveAtLeast(1, new ActionStatusCondition(Status.ERROR)); - assertThat(actionStatusRepository.findByAction(pageReq, action2).getContent()).haveAtLeast(1, + assertThat(deploymentManagement.findActionStatusByAction(pageReq, action2).getContent()).haveAtLeast(1, new ActionStatusCondition(Status.FINISHED)); } @@ -761,27 +764,29 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD @Test @Description("Verfies that the controller can provided as much feedback entries as necessry as long as it is in the configured limites.") public void rootRsSingleDeplomentActionFeedback() throws Exception { - final Target target = new Target("4712"); + final Target target = targetManagement.generateTarget("4712"); final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement, distributionSetManagement); final Target savedTarget = targetManagement.createTarget(target); - final List toAssign = new ArrayList(); + final List toAssign = new ArrayList<>(); toAssign.add(savedTarget); Target myT = targetManagement.findTargetByControllerID("4712"); assertThat(myT.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.UNKNOWN); deploymentManagement.assignDistributionSet(ds, toAssign); - final Action action = actionRepository.findByDistributionSet(pageReq, ds).getContent().get(0); + final Action action = actionRepository.findByDistributionSet(pageReq, (JpaDistributionSet) ds).getContent() + .get(0); myT = targetManagement.findTargetByControllerID("4712"); assertThat(myT.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING); - assertThat(targetRepository.findByTargetInfoInstalledDistributionSet(new PageRequest(0, 10), ds)).hasSize(0); - assertThat(targetRepository.findByAssignedDistributionSet(new PageRequest(0, 10), ds)).hasSize(1); - assertThat(targetRepository - .findByAssignedDistributionSetOrTargetInfoInstalledDistributionSet(new PageRequest(0, 10), ds, ds)) - .hasSize(1); + assertThat(targetRepository.findByTargetInfoInstalledDistributionSet(new PageRequest(0, 10), + (JpaDistributionSet) ds)).hasSize(0); + assertThat(targetRepository.findByAssignedDistributionSet(new PageRequest(0, 10), (JpaDistributionSet) ds)) + .hasSize(1); + assertThat(targetRepository.findByAssignedDistributionSetOrTargetInfoInstalledDistributionSet( + new PageRequest(0, 10), (JpaDistributionSet) ds, (JpaDistributionSet) ds)).hasSize(1); // Now valid Feedback @@ -903,18 +908,19 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD assertThat(actionStatusRepository.findAll()).haveAtLeast(1, new ActionStatusCondition(Status.CANCELED)); assertThat(actionStatusRepository.findAll()).haveAtLeast(1, new ActionStatusCondition(Status.FINISHED)); - assertThat(targetRepository.findByTargetInfoInstalledDistributionSet(new PageRequest(0, 10), ds)).hasSize(1); - assertThat(targetRepository.findByAssignedDistributionSet(new PageRequest(0, 10), ds)).hasSize(1); - assertThat(targetRepository - .findByAssignedDistributionSetOrTargetInfoInstalledDistributionSet(new PageRequest(0, 10), ds, ds)) - .hasSize(1); + assertThat(targetRepository.findByTargetInfoInstalledDistributionSet(new PageRequest(0, 10), + (JpaDistributionSet) ds)).hasSize(1); + assertThat(targetRepository.findByAssignedDistributionSet(new PageRequest(0, 10), (JpaDistributionSet) ds)) + .hasSize(1); + assertThat(targetRepository.findByAssignedDistributionSetOrTargetInfoInstalledDistributionSet( + new PageRequest(0, 10), (JpaDistributionSet) ds, (JpaDistributionSet) ds)).hasSize(1); } @Test @Description("Various forbidden request appempts on the feedback resource. Ensures correct answering behaviour as expected to these kind of errors.") public void badDeplomentActionFeedback() throws Exception { - final Target target = new Target("4712"); - final Target target2 = new Target("4713"); + final Target target = targetManagement.generateTarget("4712"); + final Target target2 = targetManagement.generateTarget("4713"); final DistributionSet savedSet = TestDataUtil.generateDistributionSet("", softwareManagement, distributionSetManagement); final DistributionSet savedSet2 = TestDataUtil.generateDistributionSet("1", softwareManagement, diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootControllerTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootControllerTest.java index 8041e8b36..ffeed1956 100644 --- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootControllerTest.java +++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootControllerTest.java @@ -80,7 +80,7 @@ public class DdiRootControllerTest extends AbstractRestIntegrationTestWithMongoD // create target first with "knownPrincipal" user and audit data final String knownTargetControllerId = "target1"; final String knownCreatedBy = "knownPrincipal"; - targetManagement.createTarget(new Target(knownTargetControllerId)); + targetManagement.createTarget(targetManagement.generateTarget(knownTargetControllerId)); final Target findTargetByControllerID = targetManagement.findTargetByControllerID(knownTargetControllerId); assertThat(findTargetByControllerID.getCreatedBy()).isEqualTo(knownCreatedBy); assertThat(findTargetByControllerID.getCreatedAt()).isNotNull(); @@ -226,7 +226,7 @@ public class DdiRootControllerTest extends AbstractRestIntegrationTestWithMongoD @Description("Ensures that the target state machine of a precomissioned target switches from " + "UNKNOWN to REGISTERED when the target polls for the first time.") public void rootRsPrecommissioned() throws Exception { - final Target target = new Target("4711"); + final Target target = targetManagement.generateTarget("4711"); targetManagement.createTarget(target); assertThat(targetRepository.findByControllerId("4711").getTargetInfo().getUpdateStatus()) @@ -265,7 +265,7 @@ public class DdiRootControllerTest extends AbstractRestIntegrationTestWithMongoD public void tryToFinishAnUpdateProcessAfterItHasBeenFinished() throws Exception { // mock - final Target target = new Target("911"); + final Target target = targetManagement.generateTarget("911"); final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement, distributionSetManagement); Target savedTarget = targetManagement.createTarget(target); diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java index dae5772e6..dbfded401 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java +++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java @@ -26,6 +26,7 @@ import org.eclipse.hawkbit.dmf.json.model.SoftwareModule; import org.eclipse.hawkbit.eventbus.EventSubscriber; import org.eclipse.hawkbit.eventbus.event.CancelTargetAssignmentEvent; import org.eclipse.hawkbit.eventbus.event.TargetAssignDistributionSetEvent; +import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.util.IpUtil; import org.springframework.amqp.core.Message; @@ -52,6 +53,9 @@ public class AmqpMessageDispatcherService extends BaseAmqpService { @Autowired private AmqpSenderService amqpSenderService; + @Autowired + private SoftwareManagement softwareManagement; + /** * Constructor. * diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java index 3756688c2..03b2c7514 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java +++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java @@ -336,7 +336,7 @@ public class AmqpMessageHandlerService extends BaseAmqpService { final ActionUpdateStatus actionUpdateStatus = convertMessage(message, ActionUpdateStatus.class); final Action action = checkActionExist(message, actionUpdateStatus); - final ActionStatus actionStatus = new ActionStatus(); + final ActionStatus actionStatus = controllerManagement.generateActionStatus(); actionUpdateStatus.getMessage().forEach(actionStatus::addMessage); actionStatus.setAction(action); diff --git a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java index e057144df..b0c5d777b 100644 --- a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java +++ b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java @@ -40,11 +40,14 @@ import org.eclipse.hawkbit.eventbus.event.TargetAssignDistributionSetEvent; import org.eclipse.hawkbit.repository.ArtifactManagement; import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; +import org.eclipse.hawkbit.repository.jpa.model.JpaAction; +import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus; +import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; +import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; -import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.helper.SecurityTokenGeneratorHolder; import org.eclipse.hawkbit.security.SecurityTokenGenerator; import org.junit.Before; @@ -347,6 +350,7 @@ public class AmqpMessageHandlerServiceTest { final Action action = createActionWithTarget(22L, Status.FINISHED); when(controllerManagementMock.findActionWithDetails(Matchers.any())).thenReturn(action); when(controllerManagementMock.addUpdateActionStatus(Matchers.any())).thenReturn(action); + when(controllerManagementMock.generateActionStatus()).thenReturn(new JpaActionStatus()); // for the test the same action can be used final List actionList = new ArrayList<>(); actionList.add(action); @@ -409,7 +413,7 @@ public class AmqpMessageHandlerServiceTest { private List createSoftwareModuleList() { final List softwareModuleList = new ArrayList<>(); - final SoftwareModule softwareModule = new SoftwareModule(); + final JpaSoftwareModule softwareModule = new JpaSoftwareModule(); softwareModule.setId(777L); softwareModuleList.add(softwareModule); return softwareModuleList; @@ -420,11 +424,11 @@ public class AmqpMessageHandlerServiceTest { initalizeSecurityTokenGenerator(); // Mock - final Action action = new Action(); + final JpaAction action = new JpaAction(); action.setId(targetId); action.setStatus(status); action.setTenant("DEFAULT"); - final Target target = new Target("target1"); + final JpaTarget target = new JpaTarget("target1"); action.setTarget(target); return action; diff --git a/hawkbit-dmf-api/src/main/java/org/eclipse/hawkbit/dmf/json/model/ActionStatus.java b/hawkbit-dmf-api/src/main/java/org/eclipse/hawkbit/dmf/json/model/ActionStatus.java index c31ab83f3..2c38a771c 100644 --- a/hawkbit-dmf-api/src/main/java/org/eclipse/hawkbit/dmf/json/model/ActionStatus.java +++ b/hawkbit-dmf-api/src/main/java/org/eclipse/hawkbit/dmf/json/model/ActionStatus.java @@ -21,6 +21,43 @@ import com.fasterxml.jackson.annotation.JsonInclude.Include; @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) public enum ActionStatus { + /** + * Action requests download by this target which has now started. + */ + DOWNLOAD, - DOWNLOAD, RETRIEVED, RUNNING, FINISHED, ERROR, WARNING, CANCELED, CANCEL_REJECTED; + /** + * Action has been send to the target. + */ + RETRIEVED, + + /** + * Action is still running for this target. + */ + RUNNING, + + /** + * Action is finished successfully for this target. + */ + FINISHED, + + /** + * Action has failed for this target. + */ + ERROR, + + /** + * Action is still running but with warnings. + */ + WARNING, + + /** + * Action has been canceled for this target. + */ + CANCELED, + + /** + * Cancellation has been rejected by the target.. + */ + CANCEL_REJECTED; } diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetMapper.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetMapper.java index 6d2d890b2..d4780f71c 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetMapper.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetMapper.java @@ -97,7 +97,7 @@ public final class MgmtDistributionSetMapper { static DistributionSet fromRequest(final MgmtDistributionSetRequestBodyPost dsRest, final SoftwareManagement softwareManagement, final DistributionSetManagement distributionSetManagement) { - final DistributionSet result = new DistributionSet(); + final DistributionSet result = distributionSetManagement.generateDistributionSet(); result.setDescription(dsRest.getDescription()); result.setName(dsRest.getName()); result.setType(findDistributionSetTypeWithExceptionIfNotFound(dsRest.getType(), distributionSetManagement)); @@ -135,13 +135,14 @@ public final class MgmtDistributionSetMapper { * @return */ static List fromRequestDsMetadata(final DistributionSet ds, - final List metadata) { + final List metadata, final DistributionSetManagement distributionSetManagement) { final List mappedList = new ArrayList<>(metadata.size()); for (final MgmtMetadata metadataRest : metadata) { if (metadataRest.getKey() == null) { throw new IllegalArgumentException("the key of the metadata must be present"); } - mappedList.add(new DistributionSetMetadata(metadataRest.getKey(), ds, metadataRest.getValue())); + mappedList.add(distributionSetManagement.generateDistributionSetMetadata(ds, metadataRest.getKey(), + metadataRest.getValue())); } return mappedList; } @@ -170,12 +171,11 @@ public final class MgmtDistributionSetMapper { response.setRequiredMigrationStep(distributionSet.isRequiredMigrationStep()); - response.add( - linkTo(methodOn(MgmtDistributionSetRestApi.class).getDistributionSet(response.getDsId())).withRel("self")); + response.add(linkTo(methodOn(MgmtDistributionSetRestApi.class).getDistributionSet(response.getDsId())) + .withRel("self")); - response.add(linkTo( - methodOn(MgmtDistributionSetTypeRestApi.class).getDistributionSetType(distributionSet.getType().getId())) - .withRel("type")); + response.add(linkTo(methodOn(MgmtDistributionSetTypeRestApi.class) + .getDistributionSetType(distributionSet.getType().getId())).withRel("type")); response.add(linkTo(methodOn(MgmtDistributionSetRestApi.class).getMetadata(response.getDsId(), Integer.parseInt(MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET), @@ -206,7 +206,7 @@ public final class MgmtDistributionSetMapper { static MgmtMetadata toResponseDsMetadata(final DistributionSetMetadata metadata) { final MgmtMetadata metadataRest = new MgmtMetadata(); - metadataRest.setKey(metadata.getId().getKey()); + metadataRest.setKey(metadata.getKey()); metadataRest.setValue(metadata.getValue()); return metadataRest; } diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java index 17f4c3303..a048226ec 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java @@ -27,22 +27,18 @@ import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetRestApi; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.DistributionSetAssignmentResult; -import org.eclipse.hawkbit.repository.DistributionSetFields; import org.eclipse.hawkbit.repository.DistributionSetManagement; -import org.eclipse.hawkbit.repository.DistributionSetMetadataFields; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.SystemManagement; -import org.eclipse.hawkbit.repository.TargetFields; import org.eclipse.hawkbit.repository.TargetManagement; -import org.eclipse.hawkbit.repository.TargetWithActionType; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; +import org.eclipse.hawkbit.repository.jpa.TargetWithActionType; +import org.eclipse.hawkbit.repository.jpa.model.DsMetadataCompositeKey; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetMetadata; -import org.eclipse.hawkbit.repository.model.DsMetadataCompositeKey; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.Target; -import org.eclipse.hawkbit.repository.rsql.RSQLUtility; import org.eclipse.hawkbit.tenancy.TenantAware; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -96,10 +92,9 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi { final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting); final Page findDsPage; if (rsqlParam != null) { - findDsPage = this.distributionSetManagement.findDistributionSetsAll( - RSQLUtility.parse(rsqlParam, DistributionSetFields.class), pageable, false); + findDsPage = this.distributionSetManagement.findDistributionSetsAll(rsqlParam, pageable, false); } else { - findDsPage = this.distributionSetManagement.findDistributionSetsAll(pageable, false, null); + findDsPage = this.distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageable, false, null); } final List rest = MgmtDistributionSetMapper.toResponseFromDsList(findDsPage.getContent()); @@ -181,8 +176,8 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi { final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting); final Page targetsAssignedDS; if (rsqlParam != null) { - targetsAssignedDS = this.targetManagement.findTargetByAssignedDistributionSet(distributionSetId, - RSQLUtility.parse(rsqlParam, TargetFields.class), pageable); + targetsAssignedDS = this.targetManagement.findTargetByAssignedDistributionSet(distributionSetId, rsqlParam, + pageable); } else { targetsAssignedDS = this.targetManagement.findTargetByAssignedDistributionSet(distributionSetId, pageable); } @@ -210,7 +205,7 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi { final Page targetsInstalledDS; if (rsqlParam != null) { targetsInstalledDS = this.targetManagement.findTargetByInstalledDistributionSet(distributionSetId, - RSQLUtility.parse(rsqlParam, TargetFields.class), pageable); + rsqlParam, pageable); } else { targetsInstalledDS = this.targetManagement.findTargetByInstalledDistributionSet(distributionSetId, pageable); @@ -257,8 +252,8 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi { final Page metaDataPage; if (rsqlParam != null) { - metaDataPage = this.distributionSetManagement.findDistributionSetMetadataByDistributionSetId( - distributionSetId, RSQLUtility.parse(rsqlParam, DistributionSetMetadataFields.class), pageable); + metaDataPage = this.distributionSetManagement + .findDistributionSetMetadataByDistributionSetId(distributionSetId, rsqlParam, pageable); } else { metaDataPage = this.distributionSetManagement .findDistributionSetMetadataByDistributionSetId(distributionSetId, pageable); @@ -289,8 +284,8 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi { // check if distribution set exists otherwise throw exception // immediately final DistributionSet ds = findDistributionSetWithExceptionIfNotFound(distributionSetId); - final DistributionSetMetadata updated = this.distributionSetManagement - .updateDistributionSetMetadata(new DistributionSetMetadata(metadataKey, ds, metadata.getValue())); + final DistributionSetMetadata updated = this.distributionSetManagement.updateDistributionSetMetadata( + distributionSetManagement.generateDistributionSetMetadata(ds, metadataKey, metadata.getValue())); return ResponseEntity.ok(MgmtDistributionSetMapper.toResponseDsMetadata(updated)); } @@ -312,8 +307,8 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi { // immediately final DistributionSet ds = findDistributionSetWithExceptionIfNotFound(distributionSetId); - final List created = this.distributionSetManagement - .createDistributionSetMetadata(MgmtDistributionSetMapper.fromRequestDsMetadata(ds, metadataRest)); + final List created = this.distributionSetManagement.createDistributionSetMetadata( + MgmtDistributionSetMapper.fromRequestDsMetadata(ds, metadataRest, distributionSetManagement)); return new ResponseEntity<>(MgmtDistributionSetMapper.toResponseDsMetadata(created), HttpStatus.CREATED); } diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResource.java index 907bbb574..69f6e044c 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResource.java @@ -21,13 +21,11 @@ import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetTagRestApi; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; -import org.eclipse.hawkbit.repository.TagFields; import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult; -import org.eclipse.hawkbit.repository.rsql.RSQLUtility; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -75,8 +73,8 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes countTargetsAll = this.tagManagement.countTargetTags(); } else { - final Page findTargetPage = this.tagManagement - .findAllDistributionSetTags(RSQLUtility.parse(rsqlParam, TagFields.class), pageable); + final Page findTargetPage = this.tagManagement.findAllDistributionSetTags(rsqlParam, + pageable); countTargetsAll = findTargetPage.getTotalElements(); findTargetsAll = findTargetPage; @@ -99,7 +97,7 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes LOG.debug("creating {} ds tags", tags.size()); final List createdTags = this.tagManagement - .createDistributionSetTags(MgmtTagMapper.mapDistributionSetTagFromRequest(tags)); + .createDistributionSetTags(MgmtTagMapper.mapDistributionSetTagFromRequest(tagManagement, tags)); return new ResponseEntity<>(MgmtTagMapper.toResponseDistributionSetTag(createdTags), HttpStatus.CREATED); } diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeMapper.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeMapper.java index d3046f149..a6dd6f32b 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeMapper.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeMapper.java @@ -14,10 +14,11 @@ import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn; import java.util.ArrayList; import java.util.List; -import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionSetTypeRequestBodyPost; import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionSetType; +import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionSetTypeRequestBodyPost; import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetTypeRestApi; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; +import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.model.DistributionSetType; @@ -35,21 +36,22 @@ final class MgmtDistributionSetTypeMapper { } - static List smFromRequest(final SoftwareManagement softwareManagement, + static List smFromRequest(final DistributionSetManagement distributionSetManagement, + final SoftwareManagement softwareManagement, final Iterable smTypesRest) { final List mappedList = new ArrayList<>(); for (final MgmtDistributionSetTypeRequestBodyPost smRest : smTypesRest) { - mappedList.add(fromRequest(softwareManagement, smRest)); + mappedList.add(fromRequest(distributionSetManagement, softwareManagement, smRest)); } return mappedList; } - static DistributionSetType fromRequest(final SoftwareManagement softwareManagement, - final MgmtDistributionSetTypeRequestBodyPost smsRest) { + static DistributionSetType fromRequest(final DistributionSetManagement distributionSetManagement, + final SoftwareManagement softwareManagement, final MgmtDistributionSetTypeRequestBodyPost smsRest) { - final DistributionSetType result = new DistributionSetType(smsRest.getKey(), smsRest.getName(), - smsRest.getDescription()); + final DistributionSetType result = distributionSetManagement.generateDistributionSetType(smsRest.getKey(), + smsRest.getName(), smsRest.getDescription()); // Add mandatory smsRest.getMandatorymodules().stream().map(mand -> { diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResource.java index baa6f2955..16cba384b 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResource.java @@ -12,14 +12,13 @@ import java.util.List; import org.eclipse.hawkbit.mgmt.json.model.MgmtId; import org.eclipse.hawkbit.mgmt.json.model.PagedList; +import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionSetType; import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionSetTypeRequestBodyPost; import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionSetTypeRequestBodyPut; -import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionSetType; import org.eclipse.hawkbit.mgmt.json.model.softwaremoduletype.MgmtSoftwareModuleType; import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetTypeRestApi; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.repository.DistributionSetManagement; -import org.eclipse.hawkbit.repository.DistributionSetTypeFields; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; @@ -27,7 +26,6 @@ import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; -import org.eclipse.hawkbit.repository.rsql.RSQLUtility; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -71,8 +69,7 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR final Slice findModuleTypessAll; Long countModulesAll; if (rsqlParam != null) { - findModuleTypessAll = distributionSetManagement.findDistributionSetTypesByPredicate( - RSQLUtility.parse(rsqlParam, DistributionSetTypeFields.class), pageable); + findModuleTypessAll = distributionSetManagement.findDistributionSetTypesAll(rsqlParam, pageable); countModulesAll = ((Page) findModuleTypessAll).getTotalElements(); } else { findModuleTypessAll = distributionSetManagement.findDistributionSetTypesAll(pageable); @@ -124,8 +121,9 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR public ResponseEntity> createDistributionSetTypes( @RequestBody final List distributionSetTypes) { - final List createdSoftwareModules = distributionSetManagement.createDistributionSetTypes( - MgmtDistributionSetTypeMapper.smFromRequest(softwareManagement, distributionSetTypes)); + final List createdSoftwareModules = distributionSetManagement + .createDistributionSetTypes(MgmtDistributionSetTypeMapper.smFromRequest(distributionSetManagement, + softwareManagement, distributionSetTypes)); return new ResponseEntity<>(MgmtDistributionSetTypeMapper.toTypesResponse(createdSoftwareModules), HttpStatus.CREATED); diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutMapper.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutMapper.java index 4dcaf0bf1..e80889508 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutMapper.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutMapper.java @@ -22,6 +22,7 @@ import org.eclipse.hawkbit.mgmt.json.model.rollout.MgmtRolloutSuccessAction.Succ import org.eclipse.hawkbit.mgmt.json.model.rolloutgroup.MgmtRolloutGroupResponseBody; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRolloutRestApi; +import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.model.Action.ActionType; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Rollout; @@ -83,9 +84,9 @@ final class MgmtRolloutMapper { return body; } - static Rollout fromRequest(final MgmtRolloutRestRequestBody restRequest, final DistributionSet distributionSet, - final String filterQuery) { - final Rollout rollout = new Rollout(); + static Rollout fromRequest(final RolloutManagement rolloutManagement, final MgmtRolloutRestRequestBody restRequest, + final DistributionSet distributionSet, final String filterQuery) { + final Rollout rollout = rolloutManagement.generateRollout(); rollout.setName(restRequest.getName()); rollout.setDescription(restRequest.getDescription()); rollout.setDistributionSet(distributionSet); diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResource.java index 37d5c6fdc..ae025e51b 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResource.java @@ -19,8 +19,6 @@ import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRolloutRestApi; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; -import org.eclipse.hawkbit.repository.RolloutFields; -import org.eclipse.hawkbit.repository.RolloutGroupFields; import org.eclipse.hawkbit.repository.RolloutGroupManagement; import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.TargetFields; @@ -28,18 +26,18 @@ import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.RolloutGroup; -import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupConditions; import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupErrorAction; import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupErrorCondition; import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupSuccessAction; import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupSuccessCondition; +import org.eclipse.hawkbit.repository.model.RolloutGroupConditionBuilder; +import org.eclipse.hawkbit.repository.model.RolloutGroupConditions; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.rsql.RSQLUtility; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; -import org.springframework.data.jpa.domain.Specification; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; @@ -80,8 +78,7 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi { final Page findModulesAll; if (rsqlParam != null) { - findModulesAll = this.rolloutManagement - .findAllWithDetailedStatusByPredicate(RSQLUtility.parse(rsqlParam, RolloutFields.class), pageable); + findModulesAll = this.rolloutManagement.findAllWithDetailedStatusByPredicate(rsqlParam, pageable); } else { findModulesAll = this.rolloutManagement.findAll(pageable); } @@ -136,12 +133,12 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi { errorActionExpr = rolloutRequestBody.getErrorAction().getExpression(); } - final RolloutGroupConditions rolloutGroupConditions = new RolloutGroup.RolloutGroupConditionBuilder() + final RolloutGroupConditions rolloutGroupConditions = new RolloutGroupConditionBuilder() .successCondition(successCondition, successConditionExpr) .successAction(successAction, successActionExpr).errorCondition(errorCondition, errorConditionExpr) .errorAction(errorAction, errorActionExpr).build(); final Rollout rollout = this.rolloutManagement.createRollout( - MgmtRolloutMapper.fromRequest(rolloutRequestBody, distributionSet, + MgmtRolloutMapper.fromRequest(rolloutManagement, rolloutRequestBody, distributionSet, rolloutRequestBody.getTargetFilterQuery()), rolloutRequestBody.getAmountGroups(), rolloutGroupConditions); @@ -191,8 +188,7 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi { final Page findRolloutGroupsAll; if (rsqlParam != null) { - findRolloutGroupsAll = this.rolloutGroupManagement.findRolloutGroupsByPredicate(rollout, - RSQLUtility.parse(rsqlParam, RolloutGroupFields.class), pageable); + findRolloutGroupsAll = this.rolloutGroupManagement.findRolloutGroupsAll(rollout, rsqlParam, pageable); } else { findRolloutGroupsAll = this.rolloutGroupManagement.findRolloutGroupsByRolloutId(rolloutId, pageable); } @@ -228,8 +224,7 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi { final Page rolloutGroupTargets; if (rsqlParam != null) { - final Specification rsqlSpecification = RSQLUtility.parse(rsqlParam, TargetFields.class); - rolloutGroupTargets = this.rolloutGroupManagement.findRolloutGroupTargets(rolloutGroup, rsqlSpecification, + rolloutGroupTargets = this.rolloutGroupManagement.findRolloutGroupTargets(rolloutGroup, rsqlParam, pageable); } else { final Page pageTargets = this.rolloutGroupManagement.findRolloutGroupTargets(rolloutGroup, diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleMapper.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleMapper.java index 5ca100ca9..ff721dfbc 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleMapper.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleMapper.java @@ -54,18 +54,20 @@ public final class MgmtSoftwareModuleMapper { static SoftwareModule fromRequest(final MgmtSoftwareModuleRequestBodyPost smsRest, final SoftwareManagement softwareManagement) { - return new SoftwareModule(getSoftwareModuleTypeFromKeyString(smsRest.getType(), softwareManagement), - smsRest.getName(), smsRest.getVersion(), smsRest.getDescription(), smsRest.getVendor()); + return softwareManagement.generateSoftwareModule( + getSoftwareModuleTypeFromKeyString(smsRest.getType(), softwareManagement), smsRest.getName(), + smsRest.getVersion(), smsRest.getDescription(), smsRest.getVendor()); } - static List fromRequestSwMetadata(final SoftwareModule sw, - final List metadata) { + static List fromRequestSwMetadata(final SoftwareManagement softwareManagement, + final SoftwareModule sw, final List metadata) { final List mappedList = new ArrayList<>(metadata.size()); for (final MgmtMetadata metadataRest : metadata) { if (metadataRest.getKey() == null) { throw new IllegalArgumentException("the key of the metadata must be present"); } - mappedList.add(new SoftwareModuleMetadata(metadataRest.getKey(), sw, metadataRest.getValue())); + mappedList.add(softwareManagement.generateSoftwareModuleMetadata(sw, metadataRest.getKey(), + metadataRest.getValue())); } return mappedList; } @@ -116,7 +118,7 @@ public final class MgmtSoftwareModuleMapper { static MgmtMetadata toResponseSwMetadata(final SoftwareModuleMetadata metadata) { final MgmtMetadata metadataRest = new MgmtMetadata(); - metadataRest.setKey(metadata.getId().getKey()); + metadataRest.setKey(metadata.getKey()); metadataRest.setValue(metadata.getValue()); return metadataRest; } diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java index 75abe57f4..c01295828 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java @@ -22,14 +22,11 @@ import org.eclipse.hawkbit.mgmt.rest.api.MgmtSoftwareModuleRestApi; import org.eclipse.hawkbit.repository.ArtifactManagement; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.SoftwareManagement; -import org.eclipse.hawkbit.repository.SoftwareModuleFields; -import org.eclipse.hawkbit.repository.SoftwareModuleMetadataFields; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; +import org.eclipse.hawkbit.repository.jpa.model.SwMetadataCompositeKey; import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata; -import org.eclipse.hawkbit.repository.model.SwMetadataCompositeKey; -import org.eclipse.hawkbit.repository.rsql.RSQLUtility; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -139,8 +136,7 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi { final Slice findModulesAll; Long countModulesAll; if (rsqlParam != null) { - findModulesAll = softwareManagement - .findSoftwareModulesByPredicate(RSQLUtility.parse(rsqlParam, SoftwareModuleFields.class), pageable); + findModulesAll = softwareManagement.findSoftwareModulesByPredicate(rsqlParam, pageable); countModulesAll = ((Page) findModulesAll).getTotalElements(); } else { findModulesAll = softwareManagement.findSoftwareModulesAll(pageable); @@ -217,8 +213,8 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi { final Page metaDataPage; if (rsqlParam != null) { - metaDataPage = softwareManagement.findSoftwareModuleMetadataBySoftwareModuleId(softwareModuleId, - RSQLUtility.parse(rsqlParam, SoftwareModuleMetadataFields.class), pageable); + metaDataPage = softwareManagement.findSoftwareModuleMetadataBySoftwareModuleId(softwareModuleId, rsqlParam, + pageable); } else { metaDataPage = softwareManagement.findSoftwareModuleMetadataBySoftwareModuleId(softwareModuleId, pageable); } @@ -233,8 +229,7 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi { public ResponseEntity getMetadataValue(@PathVariable("softwareModuleId") final Long softwareModuleId, @PathVariable("metadataKey") final String metadataKey) { final SoftwareModule sw = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null); - final SoftwareModuleMetadata findOne = softwareManagement - .findSoftwareModuleMetadata(new SwMetadataCompositeKey(sw, metadataKey)); + final SoftwareModuleMetadata findOne = softwareManagement.findSoftwareModuleMetadata(sw, metadataKey); return ResponseEntity. ok(MgmtSoftwareModuleMapper.toResponseSwMetadata(findOne)); } @@ -242,8 +237,8 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi { public ResponseEntity updateMetadata(@PathVariable("softwareModuleId") final Long softwareModuleId, @PathVariable("metadataKey") final String metadataKey, @RequestBody final MgmtMetadata metadata) { final SoftwareModule sw = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null); - final SoftwareModuleMetadata updated = softwareManagement - .updateSoftwareModuleMetadata(new SoftwareModuleMetadata(metadataKey, sw, metadata.getValue())); + final SoftwareModuleMetadata updated = softwareManagement.updateSoftwareModuleMetadata( + softwareManagement.generateSoftwareModuleMetadata(sw, metadataKey, metadata.getValue())); return ResponseEntity.ok(MgmtSoftwareModuleMapper.toResponseSwMetadata(updated)); } @@ -261,8 +256,8 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi { @RequestBody final List metadataRest) { final SoftwareModule sw = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null); - final List created = softwareManagement - .createSoftwareModuleMetadata(MgmtSoftwareModuleMapper.fromRequestSwMetadata(sw, metadataRest)); + final List created = softwareManagement.createSoftwareModuleMetadata( + MgmtSoftwareModuleMapper.fromRequestSwMetadata(softwareManagement, sw, metadataRest)); return new ResponseEntity<>(MgmtSoftwareModuleMapper.toResponseSwMetadata(created), HttpStatus.CREATED); diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeMapper.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeMapper.java index 5b16436a9..f52ea7f2a 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeMapper.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeMapper.java @@ -18,6 +18,7 @@ import java.util.List; import org.eclipse.hawkbit.mgmt.json.model.softwaremoduletype.MgmtSoftwareModuleType; import org.eclipse.hawkbit.mgmt.json.model.softwaremoduletype.MgmtSoftwareModuleTypeRequestBodyPost; import org.eclipse.hawkbit.mgmt.rest.api.MgmtSoftwareModuleTypeRestApi; +import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; /** @@ -35,18 +36,25 @@ final class MgmtSoftwareModuleTypeMapper { } - static List smFromRequest(final Iterable smTypesRest) { + static List smFromRequest(final SoftwareManagement softwareManagement, + final Iterable smTypesRest) { final List mappedList = new ArrayList<>(); for (final MgmtSoftwareModuleTypeRequestBodyPost smRest : smTypesRest) { - mappedList.add(fromRequest(smRest)); + mappedList.add(fromRequest(softwareManagement, smRest)); } return mappedList; } - static SoftwareModuleType fromRequest(final MgmtSoftwareModuleTypeRequestBodyPost smsRest) { - return new SoftwareModuleType(smsRest.getKey(), smsRest.getName(), smsRest.getDescription(), - smsRest.getMaxAssignments()); + static SoftwareModuleType fromRequest(final SoftwareManagement softwareManagement, + final MgmtSoftwareModuleTypeRequestBodyPost smsRest) { + final SoftwareModuleType result = softwareManagement.generateSoftwareModuleType(); + result.setName(smsRest.getName()); + result.setKey(smsRest.getKey()); + result.setDescription(smsRest.getDescription()); + result.setMaxAssignments(smsRest.getMaxAssignments()); + + return result; } static List toTypesResponse(final List types) { diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResource.java index deba883f6..bbb61571c 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResource.java @@ -18,12 +18,10 @@ import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.mgmt.rest.api.MgmtSoftwareModuleTypeRestApi; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.SoftwareManagement; -import org.eclipse.hawkbit.repository.SoftwareModuleTypeFields; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; -import org.eclipse.hawkbit.repository.rsql.RSQLUtility; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -62,8 +60,7 @@ public class MgmtSoftwareModuleTypeResource implements MgmtSoftwareModuleTypeRes final Slice findModuleTypessAll; Long countModulesAll; if (rsqlParam != null) { - findModuleTypessAll = this.softwareManagement.findSoftwareModuleTypesByPredicate( - RSQLUtility.parse(rsqlParam, SoftwareModuleTypeFields.class), pageable); + findModuleTypessAll = this.softwareManagement.findSoftwareModuleTypesAll(rsqlParam, pageable); countModulesAll = ((Page) findModuleTypessAll).getTotalElements(); } else { findModuleTypessAll = this.softwareManagement.findSoftwareModuleTypesAll(pageable); @@ -112,8 +109,8 @@ public class MgmtSoftwareModuleTypeResource implements MgmtSoftwareModuleTypeRes public ResponseEntity> createSoftwareModuleTypes( @RequestBody final List softwareModuleTypes) { - final List createdSoftwareModules = this.softwareManagement - .createSoftwareModuleType(MgmtSoftwareModuleTypeMapper.smFromRequest(softwareModuleTypes)); + final List createdSoftwareModules = this.softwareManagement.createSoftwareModuleType( + MgmtSoftwareModuleTypeMapper.smFromRequest(softwareManagement, softwareModuleTypes)); return new ResponseEntity<>(MgmtSoftwareModuleTypeMapper.toTypesResponse(createdSoftwareModules), HttpStatus.CREATED); diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTagMapper.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTagMapper.java index 3ab2016ec..7ede69658 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTagMapper.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTagMapper.java @@ -18,6 +18,7 @@ import org.eclipse.hawkbit.mgmt.json.model.tag.MgmtTag; import org.eclipse.hawkbit.mgmt.json.model.tag.MgmtTagRequestBodyPut; import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetTagRestApi; import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetTagRestApi; +import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.Tag; import org.eclipse.hawkbit.repository.model.TargetTag; @@ -84,8 +85,9 @@ final class MgmtTagMapper { mapTag(response, distributionSetTag); - response.add(linkTo(methodOn(MgmtDistributionSetTagRestApi.class).getDistributionSetTag(distributionSetTag.getId())) - .withRel("self")); + response.add( + linkTo(methodOn(MgmtDistributionSetTagRestApi.class).getDistributionSetTag(distributionSetTag.getId())) + .withRel("self")); response.add(linkTo( methodOn(MgmtDistributionSetTagRestApi.class).getAssignedDistributionSets(distributionSetTag.getId())) @@ -94,20 +96,22 @@ final class MgmtTagMapper { return response; } - static List mapTargeTagFromRequest(final Iterable tags) { + static List mapTargeTagFromRequest(final TagManagement tagManagement, + final Iterable tags) { final List mappedList = new ArrayList<>(); for (final MgmtTagRequestBodyPut targetTagRest : tags) { - mappedList.add( - new TargetTag(targetTagRest.getName(), targetTagRest.getDescription(), targetTagRest.getColour())); + mappedList.add(tagManagement.generateTargetTag(targetTagRest.getName(), targetTagRest.getDescription(), + targetTagRest.getColour())); } return mappedList; } - static List mapDistributionSetTagFromRequest(final Iterable tags) { + static List mapDistributionSetTagFromRequest(final TagManagement tagManagement, + final Iterable tags) { final List mappedList = new ArrayList<>(); for (final MgmtTagRequestBodyPut targetTagRest : tags) { - mappedList.add(new DistributionSetTag(targetTagRest.getName(), targetTagRest.getDescription(), - targetTagRest.getColour())); + mappedList.add(tagManagement.generateDistributionSetTag(targetTagRest.getName(), + targetTagRest.getDescription(), targetTagRest.getColour())); } return mappedList; } diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetMapper.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetMapper.java index afb941bc1..b377e95f7 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetMapper.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetMapper.java @@ -25,10 +25,11 @@ import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTargetRequestBody; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetRestApi; import org.eclipse.hawkbit.repository.ActionFields; +import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.ActionStatus; +import org.eclipse.hawkbit.repository.model.PollStatus; import org.eclipse.hawkbit.repository.model.Target; -import org.eclipse.hawkbit.repository.model.TargetInfo.PollStatus; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; import org.eclipse.hawkbit.rest.data.SortDirection; @@ -168,16 +169,17 @@ public final class MgmtTargetMapper { return targetRest; } - static List fromRequest(final Iterable targetsRest) { + static List fromRequest(final TargetManagement targetManagement, + final Iterable targetsRest) { final List mappedList = new ArrayList<>(); for (final MgmtTargetRequestBody targetRest : targetsRest) { - mappedList.add(fromRequest(targetRest)); + mappedList.add(fromRequest(targetManagement, targetRest)); } return mappedList; } - static Target fromRequest(final MgmtTargetRequestBody targetRest) { - final Target target = new Target(targetRest.getControllerId()); + static Target fromRequest(final TargetManagement targetManagement, final MgmtTargetRequestBody targetRest) { + final Target target = targetManagement.generateTarget(targetRest.getControllerId()); target.setDescription(targetRest.getDescription()); target.setName(targetRest.getName()); return target; diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResource.java index 4a7c760e3..e02072238 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResource.java @@ -26,18 +26,15 @@ import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTargetRequestBody; import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetRestApi; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetRestApi; -import org.eclipse.hawkbit.repository.ActionFields; import org.eclipse.hawkbit.repository.ActionStatusFields; import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; -import org.eclipse.hawkbit.repository.TargetFields; import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.ActionType; import org.eclipse.hawkbit.repository.model.ActionStatus; import org.eclipse.hawkbit.repository.model.Target; -import org.eclipse.hawkbit.repository.rsql.RSQLUtility; import org.eclipse.hawkbit.rest.data.SortDirection; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -46,7 +43,6 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; import org.springframework.data.domain.Sort; -import org.springframework.data.jpa.domain.Specification; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; @@ -93,8 +89,7 @@ public class MgmtTargetResource implements MgmtTargetRestApi { final Slice findTargetsAll; final Long countTargetsAll; if (rsqlParam != null) { - final Page findTargetPage = this.targetManagement - .findTargetsAll(RSQLUtility.parse(rsqlParam, TargetFields.class), pageable); + final Page findTargetPage = this.targetManagement.findTargetsAll(rsqlParam, pageable); countTargetsAll = findTargetPage.getTotalElements(); findTargetsAll = findTargetPage; } else { @@ -110,7 +105,7 @@ public class MgmtTargetResource implements MgmtTargetRestApi { public ResponseEntity> createTargets(@RequestBody final List targets) { LOG.debug("creating {} targets", targets.size()); final Iterable createdTargets = this.targetManagement - .createTargets(MgmtTargetMapper.fromRequest(targets)); + .createTargets(MgmtTargetMapper.fromRequest(targetManagement, targets)); LOG.debug("{} targets created, return status {}", targets.size(), HttpStatus.CREATED); return new ResponseEntity<>(MgmtTargetMapper.toResponse(createdTargets), HttpStatus.CREATED); } @@ -170,9 +165,8 @@ public class MgmtTargetResource implements MgmtTargetRestApi { final Slice activeActions; final Long totalActionCount; if (rsqlParam != null) { - final Specification parse = RSQLUtility.parse(rsqlParam, ActionFields.class); - activeActions = this.deploymentManagement.findActionsByTarget(parse, foundTarget, pageable); - totalActionCount = this.deploymentManagement.countActionsByTarget(parse, foundTarget); + activeActions = this.deploymentManagement.findActionsByTarget(rsqlParam, foundTarget, pageable); + totalActionCount = this.deploymentManagement.countActionsByTarget(rsqlParam, foundTarget); } else { activeActions = this.deploymentManagement.findActionsByTarget(foundTarget, pageable); totalActionCount = this.deploymentManagement.countActionsByTarget(foundTarget); @@ -250,8 +244,8 @@ public class MgmtTargetResource implements MgmtTargetRestApi { final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam); final Sort sorting = PagingUtility.sanitizeActionStatusSortParam(sortParam); - final Page statusList = this.deploymentManagement.findActionStatusByAction( - new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting), action, true); + final Page statusList = this.deploymentManagement.findActionStatusByActionWithMessages( + new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting), action); return new ResponseEntity<>( new PagedList<>(MgmtTargetMapper.toActionStatusRestResponse(statusList.getContent()), diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResource.java index 2bafecd8b..7d1ba3f7f 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResource.java @@ -20,14 +20,12 @@ import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTarget; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetTagRestApi; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; -import org.eclipse.hawkbit.repository.TagFields; import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetTag; import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult; -import org.eclipse.hawkbit.repository.rsql.RSQLUtility; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -75,8 +73,7 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi { countTargetsAll = this.tagManagement.countTargetTags(); } else { - final Page findTargetPage = this.tagManagement - .findAllTargetTags(RSQLUtility.parse(rsqlParam, TagFields.class), pageable); + final Page findTargetPage = this.tagManagement.findAllTargetTags(rsqlParam, pageable); countTargetsAll = findTargetPage.getTotalElements(); findTargetsAll = findTargetPage; @@ -96,7 +93,7 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi { public ResponseEntity> createTargetTags(@RequestBody final List tags) { LOG.debug("creating {} target tags", tags.size()); final List createdTargetTags = this.tagManagement - .createTargetTags(MgmtTagMapper.mapTargeTagFromRequest(tags)); + .createTargetTags(MgmtTagMapper.mapTargeTagFromRequest(tagManagement, tags)); return new ResponseEntity<>(MgmtTagMapper.toResponse(createdTargetTags), HttpStatus.CREATED); } diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java index 8cfef095e..daa010166 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java @@ -30,10 +30,10 @@ import org.eclipse.hawkbit.TestDataUtil; import org.eclipse.hawkbit.WithUser; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; +import org.eclipse.hawkbit.repository.jpa.model.DsMetadataCompositeKey; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetMetadata; -import org.eclipse.hawkbit.repository.model.DsMetadataCompositeKey; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.rest.AbstractRestIntegrationTest; @@ -76,7 +76,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest final DistributionSet disSet = TestDataUtil.generateDistributionSetWithNoSoftwareModules("Eris", "560a", distributionSetManagement); final List smIDs = new ArrayList(); - SoftwareModule sm = new SoftwareModule(osType, "Dysnomia ", "15,772", null, null); + SoftwareModule sm = softwareManagement.generateSoftwareModule(osType, "Dysnomia ", "15,772", null, null); sm = softwareManagement.createSoftwareModule(sm); smIDs.add(sm.getId()); final JSONArray smList = new JSONArray(); @@ -92,7 +92,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest final String[] knownTargetIds = new String[] { "1", "2" }; final JSONArray list = new JSONArray(); for (final String targetId : knownTargetIds) { - targetManagement.createTarget(new Target(targetId)); + targetManagement.createTarget(targetManagement.generateTarget(targetId)); list.put(new JSONObject().put("id", Long.valueOf(targetId))); } deploymentManagement.assignDistributionSet(disSet.getId(), knownTargetIds[0]); @@ -120,7 +120,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest final DistributionSet disSet = TestDataUtil.generateDistributionSetWithNoSoftwareModules("Mars", "686,980", distributionSetManagement); final List smIDs = new ArrayList<>(); - SoftwareModule sm = new SoftwareModule(osType, "Phobos", "0,3189", null, null); + SoftwareModule sm = softwareManagement.generateSoftwareModule(osType, "Phobos", "0,3189", null, null); sm = softwareManagement.createSoftwareModule(sm); smIDs.add(sm.getId()); final JSONArray smList = new JSONArray(); @@ -136,7 +136,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest final String[] knownTargetIds = new String[] { "1", "2" }; final JSONArray list = new JSONArray(); for (final String targetId : knownTargetIds) { - targetManagement.createTarget(new Target(targetId)); + targetManagement.createTarget(targetManagement.generateTarget(targetId)); list.put(new JSONObject().put("id", Long.valueOf(targetId))); } // assign DisSet to target and test assignment @@ -150,8 +150,8 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest .andExpect(jsonPath("$.total", equalTo(knownTargetIds.length))); // Create another SM and post assignment - final List smID2s = new ArrayList(); - SoftwareModule sm2 = new SoftwareModule(appType, "Deimos", "1,262", null, null); + final List smID2s = new ArrayList<>(); + SoftwareModule sm2 = softwareManagement.generateSoftwareModule(appType, "Deimos", "1,262", null, null); sm2 = softwareManagement.createSoftwareModule(sm2); smID2s.add(sm2.getId()); final JSONArray smList2 = new JSONArray(); @@ -178,13 +178,13 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest .andExpect(jsonPath("$.size", equalTo(disSet.getModules().size()))); // create Software Modules final List smIDs = new ArrayList(); - SoftwareModule sm = new SoftwareModule(osType, "Europa", "3,551", null, null); + SoftwareModule sm = softwareManagement.generateSoftwareModule(osType, "Europa", "3,551", null, null); sm = softwareManagement.createSoftwareModule(sm); smIDs.add(sm.getId()); - SoftwareModule sm2 = new SoftwareModule(appType, "Ganymed", "7,155", null, null); + SoftwareModule sm2 = softwareManagement.generateSoftwareModule(appType, "Ganymed", "7,155", null, null); sm2 = softwareManagement.createSoftwareModule(sm2); smIDs.add(sm2.getId()); - SoftwareModule sm3 = new SoftwareModule(runtimeType, "Kallisto", "16,689", null, null); + SoftwareModule sm3 = softwareManagement.generateSoftwareModule(runtimeType, "Kallisto", "16,689", null, null); sm3 = softwareManagement.createSoftwareModule(sm3); smIDs.add(sm3.getId()); final JSONArray list = new JSONArray(); @@ -234,7 +234,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest final String[] knownTargetIds = new String[] { "1", "2", "3", "4", "5" }; final JSONArray list = new JSONArray(); for (final String targetId : knownTargetIds) { - targetManagement.createTarget(new Target(targetId)); + targetManagement.createTarget(targetManagement.generateTarget(targetId)); list.put(new JSONObject().put("id", Long.valueOf(targetId))); } // assign already one target to DS @@ -258,7 +258,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest final String knownTargetId = "knownTargetId1"; final Set createDistributionSetsAlphabetical = createDistributionSetsAlphabetical(1); final DistributionSet createdDs = createDistributionSetsAlphabetical.iterator().next(); - targetManagement.createTarget(new Target(knownTargetId)); + targetManagement.createTarget(targetManagement.generateTarget(knownTargetId)); deploymentManagement.assignDistributionSet(createdDs.getId(), knownTargetId); mvc.perform(get( @@ -285,10 +285,10 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest final String knownTargetId = "knownTargetId1"; final Set createDistributionSetsAlphabetical = createDistributionSetsAlphabetical(1); final DistributionSet createdDs = createDistributionSetsAlphabetical.iterator().next(); - final Target createTarget = targetManagement.createTarget(new Target(knownTargetId)); + final Target createTarget = targetManagement.createTarget(targetManagement.generateTarget(knownTargetId)); // create some dummy targets which are not assigned or installed - targetManagement.createTarget(new Target("dummy1")); - targetManagement.createTarget(new Target("dummy2")); + targetManagement.createTarget(targetManagement.generateTarget("dummy1")); + targetManagement.createTarget(targetManagement.generateTarget("dummy2")); // assign knownTargetId to distribution set deploymentManagement.assignDistributionSet(createdDs.getId(), knownTargetId); // make it in install state @@ -348,7 +348,8 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest @Description("Ensures that multiple DS requested are listed with expected payload.") public void getDistributionSets() throws Exception { // prepare test data - assertThat(distributionSetManagement.findDistributionSetsAll(pageReq, false, true)).hasSize(0); + assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true)) + .hasSize(0); DistributionSet set = TestDataUtil.generateDistributionSet("one", softwareManagement, distributionSetManagement); @@ -361,7 +362,8 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest // load also lazy stuff set = distributionSetManagement.findDistributionSetByIdWithDetails(set.getId()); - assertThat(distributionSetManagement.findDistributionSetsAll(pageReq, false, true)).hasSize(1); + assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true)) + .hasSize(1); // perform request mvc.perform(get("/rest/v1/distributionsets").accept(MediaType.APPLICATION_JSON)) @@ -425,14 +427,15 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest @WithUser(principal = "uploadTester", allSpPermissions = true) @Description("Ensures that multipe DS posted to API are created in the repository.") public void createDistributionSets() throws JSONException, Exception { - assertThat(distributionSetManagement.findDistributionSetsAll(pageReq, false, true)).hasSize(0); + assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true)) + .hasSize(0); - final SoftwareModule ah = softwareManagement - .createSoftwareModule(new SoftwareModule(appType, "agent-hub", "1.0.1", null, "")); - final SoftwareModule jvm = softwareManagement - .createSoftwareModule(new SoftwareModule(runtimeType, "oracle-jre", "1.7.2", null, "")); + final SoftwareModule ah = softwareManagement.createSoftwareModule( + softwareManagement.generateSoftwareModule(appType, "agent-hub", "1.0.1", null, "")); + final SoftwareModule jvm = softwareManagement.createSoftwareModule( + softwareManagement.generateSoftwareModule(runtimeType, "oracle-jre", "1.7.2", null, "")); final SoftwareModule os = softwareManagement - .createSoftwareModule(new SoftwareModule(osType, "poky", "3.0.2", null, "")); + .createSoftwareModule(softwareManagement.generateSoftwareModule(osType, "poky", "3.0.2", null, "")); DistributionSet one = TestDataUtil.buildDistributionSet("one", "one", standardDsType, os, jvm, ah); DistributionSet two = TestDataUtil.buildDistributionSet("two", "two", standardDsType, os, jvm, ah); @@ -527,7 +530,8 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest .isEqualTo(String.valueOf(three.getId())); // check in database - assertThat(distributionSetManagement.findDistributionSetsAll(pageReq, false, true)).hasSize(3); + assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true)) + .hasSize(3); assertThat(one.isRequiredMigrationStep()).isEqualTo(false); assertThat(two.isRequiredMigrationStep()).isEqualTo(false); assertThat(three.isRequiredMigrationStep()).isEqualTo(true); @@ -541,19 +545,22 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest @Description("Ensures that DS deletion request to API is reflected by the repository.") public void deleteUnassignedistributionSet() throws Exception { // prepare test data - assertThat(distributionSetManagement.findDistributionSetsAll(pageReq, false, true)).hasSize(0); + assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true)) + .hasSize(0); final DistributionSet set = TestDataUtil.generateDistributionSet("one", softwareManagement, distributionSetManagement); - assertThat(distributionSetManagement.findDistributionSetsAll(pageReq, false, true)).hasSize(1); + assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true)) + .hasSize(1); // perform request mvc.perform(delete("/rest/v1/distributionsets/{smId}", set.getId())).andDo(MockMvcResultPrinter.print()) .andExpect(status().isOk()); // check repository content - assertThat(distributionSetManagement.findDistributionSetsAll(pageReq, false, true)).isEmpty(); + assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true)) + .isEmpty(); assertThat(distributionSetRepository.findAll()).isEmpty(); } @@ -561,22 +568,26 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest @Description("Ensures that assigned DS deletion request to API is reflected by the repository by means of deleted flag set.") public void deleteAssignedDistributionSet() throws Exception { // prepare test data - assertThat(distributionSetManagement.findDistributionSetsAll(pageReq, false, true)).hasSize(0); + assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true)) + .hasSize(0); final DistributionSet set = TestDataUtil.generateDistributionSet("one", softwareManagement, distributionSetManagement); - targetManagement.createTarget(new Target("test")); + targetManagement.createTarget(targetManagement.generateTarget("test")); deploymentManagement.assignDistributionSet(set.getId(), "test"); - assertThat(distributionSetManagement.findDistributionSetsAll(pageReq, false, true)).hasSize(1); + assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true)) + .hasSize(1); // perform request mvc.perform(delete("/rest/v1/distributionsets/{smId}", set.getId())).andDo(MockMvcResultPrinter.print()) .andExpect(status().isOk()); // check repository content - assertThat(distributionSetManagement.findDistributionSetsAll(pageReq, false, true)).hasSize(0); - assertThat(distributionSetManagement.findDistributionSetsAll(pageReq, true, true)).hasSize(1); + assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true)) + .hasSize(0); + assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, true, true)) + .hasSize(1); } @Test @@ -584,14 +595,16 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest public void updateDistributionSet() throws Exception { // prepare test data - assertThat(distributionSetManagement.findDistributionSetsAll(pageReq, false, true)).hasSize(0); + assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true)) + .hasSize(0); final DistributionSet set = TestDataUtil.generateDistributionSet("one", softwareManagement, distributionSetManagement); - assertThat(distributionSetManagement.findDistributionSetsAll(pageReq, false, true)).hasSize(1); + assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true)) + .hasSize(1); - final DistributionSet update = new DistributionSet(); + final DistributionSet update = distributionSetManagement.generateDistributionSet(); update.setVersion("anotherVersion"); update.setName(null); update.setType(standardDsType); @@ -600,11 +613,10 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); - assertThat(distributionSetManagement.findDistributionSetsAll(pageReq, false, true).getContent().get(0) - .getVersion()).isEqualTo("anotherVersion"); - assertThat( - distributionSetManagement.findDistributionSetsAll(pageReq, false, true).getContent().get(0).getName()) - .isEqualTo(set.getName()); + assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true) + .getContent().get(0).getVersion()).isEqualTo("anotherVersion"); + assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true) + .getContent().get(0).getName()).isEqualTo(set.getName()); } @Test @@ -692,8 +704,8 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest final DistributionSet testDS = TestDataUtil.generateDistributionSet("one", softwareManagement, distributionSetManagement); - distributionSetManagement - .createDistributionSetMetadata(new DistributionSetMetadata(knownKey, testDS, knownValue)); + distributionSetManagement.createDistributionSetMetadata( + distributionSetManagement.generateDistributionSetMetadata(testDS, knownKey, knownValue)); final JSONObject jsonObject = new JSONObject().put("key", knownKey).put("value", updateValue); @@ -718,8 +730,8 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest final DistributionSet testDS = TestDataUtil.generateDistributionSet("one", softwareManagement, distributionSetManagement); - distributionSetManagement - .createDistributionSetMetadata(new DistributionSetMetadata(knownKey, testDS, knownValue)); + distributionSetManagement.createDistributionSetMetadata( + distributionSetManagement.generateDistributionSetMetadata(testDS, knownKey, knownValue)); mvc.perform(delete("/rest/v1/distributionsets/{dsId}/metadata/{key}", testDS.getId(), knownKey)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); @@ -740,8 +752,8 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest final String knownValue = "knownValue"; final DistributionSet testDS = TestDataUtil.generateDistributionSet("one", softwareManagement, distributionSetManagement); - distributionSetManagement - .createDistributionSetMetadata(new DistributionSetMetadata(knownKey, testDS, knownValue)); + distributionSetManagement.createDistributionSetMetadata( + distributionSetManagement.generateDistributionSetMetadata(testDS, knownKey, knownValue)); mvc.perform(get("/rest/v1/distributionsets/{dsId}/metadata/{key}", testDS.getId(), knownKey)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) @@ -760,8 +772,9 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest final DistributionSet testDS = TestDataUtil.generateDistributionSet("one", softwareManagement, distributionSetManagement); for (int index = 0; index < totalMetadata; index++) { - distributionSetManagement.createDistributionSetMetadata(new DistributionSetMetadata(knownKeyPrefix + index, - distributionSetManagement.findDistributionSetById(testDS.getId()), knownValuePrefix + index)); + distributionSetManagement.createDistributionSetMetadata(distributionSetManagement + .generateDistributionSetMetadata(distributionSetManagement.findDistributionSetById(testDS.getId()), + knownKeyPrefix + index, knownValuePrefix + index)); } mvc.perform(get("/rest/v1/distributionsets/{dsId}/metadata?offset=" + offsetParam + "&limit=" + limitParam, @@ -795,8 +808,8 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest public void filterDistributionSetComplete() throws Exception { final int amount = 10; TestDataUtil.generateDistributionSets(amount, softwareManagement, distributionSetManagement); - distributionSetManagement.createDistributionSet(new DistributionSet("incomplete", "2", "incomplete", - distributionSetManagement.findDistributionSetTypeByKey("ecl_os"), null)); + distributionSetManagement.createDistributionSet(distributionSetManagement.generateDistributionSet("incomplete", + "2", "incomplete", distributionSetManagement.findDistributionSetTypeByKey("ecl_os"), null)); final String rsqlFindLikeDs1OrDs2 = "complete==" + Boolean.TRUE; @@ -815,7 +828,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest final String[] knownTargetIds = new String[] { "1", "2", "3", "4", "5" }; final JSONArray list = new JSONArray(); for (final String targetId : knownTargetIds) { - targetManagement.createTarget(new Target(targetId)); + targetManagement.createTarget(targetManagement.generateTarget(targetId)); list.put(new JSONObject().put("id", Long.valueOf(targetId))); } @@ -840,8 +853,9 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest final DistributionSet testDS = TestDataUtil.generateDistributionSet("one", softwareManagement, distributionSetManagement); for (int index = 0; index < totalMetadata; index++) { - distributionSetManagement.createDistributionSetMetadata(new DistributionSetMetadata(knownKeyPrefix + index, - distributionSetManagement.findDistributionSetById(testDS.getId()), knownValuePrefix + index)); + distributionSetManagement.createDistributionSetMetadata(distributionSetManagement + .generateDistributionSetMetadata(distributionSetManagement.findDistributionSetById(testDS.getId()), + knownKeyPrefix + index, knownValuePrefix + index)); } final String rsqlSearchValue1 = "value==knownValue1"; diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResourceTest.java index dcd78513b..005a7f51f 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResourceTest.java @@ -25,7 +25,6 @@ import java.util.List; import org.eclipse.hawkbit.WithUser; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; -import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; @@ -58,8 +57,8 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration @Description("Checks the correct behaviour of /rest/v1/distributionsettypes GET requests.") public void getDistributionSetTypes() throws Exception { - DistributionSetType testType = distributionSetManagement - .createDistributionSetType(new DistributionSetType("test123", "TestName123", "Desc123")); + DistributionSetType testType = distributionSetManagement.createDistributionSetType( + distributionSetManagement.generateDistributionSetType("test123", "TestName123", "Desc123")); testType.setDescription("Desc1234"); testType = distributionSetManagement.updateDistributionSetType(testType); @@ -96,8 +95,8 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration @Description("Checks the correct behaviour of /rest/v1/distributionsettypes GET requests with sorting by KEY.") public void getDistributionSetTypesSortedByKey() throws Exception { - DistributionSetType testType = distributionSetManagement - .createDistributionSetType(new DistributionSetType("zzzzz", "TestName123", "Desc123")); + DistributionSetType testType = distributionSetManagement.createDistributionSetType( + distributionSetManagement.generateDistributionSetType("zzzzz", "TestName123", "Desc123")); testType.setDescription("Desc1234"); testType = distributionSetManagement.updateDistributionSetType(testType); @@ -136,12 +135,12 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration assertThat(distributionSetManagement.countDistributionSetTypesAll()).isEqualTo(3); final List types = new ArrayList<>(); - types.add(new DistributionSetType("test1", "TestName1", "Desc1").addMandatoryModuleType(osType) - .addOptionalModuleType(runtimeType)); - types.add(new DistributionSetType("test2", "TestName2", "Desc2").addOptionalModuleType(osType) - .addOptionalModuleType(runtimeType).addOptionalModuleType(appType)); - types.add(new DistributionSetType("test3", "TestName3", "Desc3").addMandatoryModuleType(osType) - .addMandatoryModuleType(runtimeType)); + types.add(distributionSetManagement.generateDistributionSetType("test1", "TestName1", "Desc1") + .addMandatoryModuleType(osType).addOptionalModuleType(runtimeType)); + types.add(distributionSetManagement.generateDistributionSetType("test2", "TestName2", "Desc2") + .addOptionalModuleType(osType).addOptionalModuleType(runtimeType).addOptionalModuleType(appType)); + types.add(distributionSetManagement.generateDistributionSetType("test3", "TestName3", "Desc3") + .addMandatoryModuleType(osType).addMandatoryModuleType(runtimeType)); final MvcResult mvcResult = mvc .perform(post("/rest/v1/distributionsettypes/").content(JsonBuilder.distributionSetTypes(types)) @@ -205,8 +204,8 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration @WithUser(principal = "uploadTester", allSpPermissions = true) @Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID}/mandatorymoduletypes POST requests.") public void addMandatoryModuleToDistributionSetType() throws JSONException, Exception { - DistributionSetType testType = distributionSetManagement - .createDistributionSetType(new DistributionSetType("test123", "TestName123", "Desc123")); + DistributionSetType testType = distributionSetManagement.createDistributionSetType( + distributionSetManagement.generateDistributionSetType("test123", "TestName123", "Desc123")); assertThat(testType.getOptLockRevision()).isEqualTo(1); mvc.perform(post("/rest/v1/distributionsettypes/{dstID}/mandatorymoduletypes", testType.getId()) @@ -224,8 +223,8 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration @WithUser(principal = "uploadTester", allSpPermissions = true) @Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID}/optionalmoduletypes POST requests.") public void addOptionalModuleToDistributionSetType() throws JSONException, Exception { - DistributionSetType testType = distributionSetManagement - .createDistributionSetType(new DistributionSetType("test123", "TestName123", "Desc123")); + DistributionSetType testType = distributionSetManagement.createDistributionSetType( + distributionSetManagement.generateDistributionSetType("test123", "TestName123", "Desc123")); assertThat(testType.getOptLockRevision()).isEqualTo(1); mvc.perform(post("/rest/v1/distributionsettypes/{dstID}/optionalmoduletypes", testType.getId()) @@ -244,8 +243,8 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration @WithUser(principal = "uploadTester", allSpPermissions = true) @Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID}/mandatorymoduletypes GET requests.") public void getMandatoryModulesOfDistributionSetType() throws JSONException, Exception { - final DistributionSetType testType = distributionSetManagement - .createDistributionSetType(new DistributionSetType("test123", "TestName123", "Desc123") + final DistributionSetType testType = distributionSetManagement.createDistributionSetType( + distributionSetManagement.generateDistributionSetType("test123", "TestName123", "Desc123") .addMandatoryModuleType(osType).addOptionalModuleType(appType)); assertThat(testType.getOptLockRevision()).isEqualTo(1); assertThat(testType.getOptionalModuleTypes()).containsExactly(appType); @@ -263,8 +262,8 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration @WithUser(principal = "uploadTester", allSpPermissions = true) @Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID}/optionalmoduletypes GET requests.") public void getOptionalModulesOfDistributionSetType() throws JSONException, Exception { - final DistributionSetType testType = distributionSetManagement - .createDistributionSetType(new DistributionSetType("test123", "TestName123", "Desc123") + final DistributionSetType testType = distributionSetManagement.createDistributionSetType( + distributionSetManagement.generateDistributionSetType("test123", "TestName123", "Desc123") .addMandatoryModuleType(osType).addOptionalModuleType(appType)); assertThat(testType.getOptLockRevision()).isEqualTo(1); assertThat(testType.getOptionalModuleTypes()).containsExactly(appType); @@ -283,8 +282,8 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration @WithUser(principal = "uploadTester", allSpPermissions = true) @Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID}/mandatorymoduletypes/{ID} GET requests.") public void getMandatoryModuleOfDistributionSetType() throws JSONException, Exception { - final DistributionSetType testType = distributionSetManagement - .createDistributionSetType(new DistributionSetType("test123", "TestName123", "Desc123") + final DistributionSetType testType = distributionSetManagement.createDistributionSetType( + distributionSetManagement.generateDistributionSetType("test123", "TestName123", "Desc123") .addMandatoryModuleType(osType).addOptionalModuleType(appType)); assertThat(testType.getOptLockRevision()).isEqualTo(1); assertThat(testType.getOptionalModuleTypes()).containsExactly(appType); @@ -305,8 +304,8 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration @WithUser(principal = "uploadTester", allSpPermissions = true) @Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID}/optionalmoduletypes/{ID} GET requests.") public void getOptionalModuleOfDistributionSetType() throws JSONException, Exception { - final DistributionSetType testType = distributionSetManagement - .createDistributionSetType(new DistributionSetType("test123", "TestName123", "Desc123") + final DistributionSetType testType = distributionSetManagement.createDistributionSetType( + distributionSetManagement.generateDistributionSetType("test123", "TestName123", "Desc123") .addMandatoryModuleType(osType).addOptionalModuleType(appType)); assertThat(testType.getOptLockRevision()).isEqualTo(1); assertThat(testType.getOptionalModuleTypes()).containsExactly(appType); @@ -327,8 +326,8 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration @WithUser(principal = "uploadTester", allSpPermissions = true) @Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID}/mandatorymoduletypes/{ID} DELETE requests.") public void removeMandatoryModuleToDistributionSetType() throws JSONException, Exception { - DistributionSetType testType = distributionSetManagement - .createDistributionSetType(new DistributionSetType("test123", "TestName123", "Desc123") + DistributionSetType testType = distributionSetManagement.createDistributionSetType( + distributionSetManagement.generateDistributionSetType("test123", "TestName123", "Desc123") .addMandatoryModuleType(osType).addOptionalModuleType(appType)); assertThat(testType.getOptLockRevision()).isEqualTo(1); assertThat(testType.getOptionalModuleTypes()).containsExactly(appType); @@ -349,8 +348,8 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration @WithUser(principal = "uploadTester", allSpPermissions = true) @Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID}/optionalmoduletypes/{ID} DELETE requests.") public void removeOptionalModuleToDistributionSetType() throws JSONException, Exception { - DistributionSetType testType = distributionSetManagement - .createDistributionSetType(new DistributionSetType("test123", "TestName123", "Desc123") + DistributionSetType testType = distributionSetManagement.createDistributionSetType( + distributionSetManagement.generateDistributionSetType("test123", "TestName123", "Desc123") .addMandatoryModuleType(osType).addOptionalModuleType(appType)); assertThat(testType.getOptLockRevision()).isEqualTo(1); assertThat(testType.getOptionalModuleTypes()).containsExactly(appType); @@ -372,8 +371,8 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration @Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID} GET requests.") public void getDistributionSetType() throws Exception { - DistributionSetType testType = distributionSetManagement - .createDistributionSetType(new DistributionSetType("test123", "TestName123", "Desc123")); + DistributionSetType testType = distributionSetManagement.createDistributionSetType( + distributionSetManagement.generateDistributionSetType("test123", "TestName123", "Desc123")); testType.setDescription("Desc1234"); testType = distributionSetManagement.updateDistributionSetType(testType); @@ -391,8 +390,8 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration @WithUser(principal = "uploadTester", allSpPermissions = true) @Description("Checks the correct behaviour of /rest/v1/DistributionSetTypes/{ID} DELETE requests (hard delete scenario).") public void deleteDistributionSetTypeUnused() throws Exception { - final DistributionSetType testType = distributionSetManagement - .createDistributionSetType(new DistributionSetType("test123", "TestName123", "Desc123")); + final DistributionSetType testType = distributionSetManagement.createDistributionSetType( + distributionSetManagement.generateDistributionSetType("test123", "TestName123", "Desc123")); assertThat(distributionSetManagement.countDistributionSetTypesAll()).isEqualTo(4); @@ -406,10 +405,10 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration @WithUser(principal = "uploadTester", allSpPermissions = true) @Description("Checks the correct behaviour of /rest/v1/DistributionSetTypes/{ID} DELETE requests (soft delete scenario).") public void deleteDistributionSetTypeUsed() throws Exception { - final DistributionSetType testType = distributionSetManagement - .createDistributionSetType(new DistributionSetType("test123", "TestName123", "Desc123")); - distributionSetManagement - .createDistributionSet(new DistributionSet("sdfsd", "dsfsdf", "sdfsdf", testType, null)); + final DistributionSetType testType = distributionSetManagement.createDistributionSetType( + distributionSetManagement.generateDistributionSetType("test123", "TestName123", "Desc123")); + distributionSetManagement.createDistributionSet( + distributionSetManagement.generateDistributionSet("sdfsd", "dsfsdf", "sdfsdf", testType, null)); assertThat(distributionSetManagement.countDistributionSetTypesAll()).isEqualTo(4); assertThat(distributionSetTypeRepository.count()).isEqualTo(4); @@ -424,8 +423,8 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration @Test @Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID} PUT requests.") public void updateDistributionSetTypeOnlyDescriptionAndNameUntouched() throws Exception { - final DistributionSetType testType = distributionSetManagement - .createDistributionSetType(new DistributionSetType("test123", "TestName123", "Desc123")); + final DistributionSetType testType = distributionSetManagement.createDistributionSetType( + distributionSetManagement.generateDistributionSetType("test123", "TestName123", "Desc123")); final String body = new JSONObject().put("id", testType.getId()).put("description", "foobardesc") .put("name", "nameShouldNotBeChanged").toString(); @@ -479,11 +478,11 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration @Test @Description("Ensures that the server is behaving as expected on invalid requests (wrong media type, wrong ID etc.).") public void invalidRequestsOnDistributionSetTypesResource() throws Exception { - final DistributionSetType testType = distributionSetManagement - .createDistributionSetType(new DistributionSetType("test123", "TestName123", "Desc123")); + final DistributionSetType testType = distributionSetManagement.createDistributionSetType( + distributionSetManagement.generateDistributionSetType("test123", "TestName123", "Desc123")); - final SoftwareModuleType testSmType = softwareManagement - .createSoftwareModuleType(new SoftwareModuleType("test123", "TestName123", "Desc123", 5)); + final SoftwareModuleType testSmType = softwareManagement.createSoftwareModuleType( + softwareManagement.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5)); final List types = new ArrayList<>(); types.add(testType); @@ -526,8 +525,10 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration // Modules types at creation time invalid - final DistributionSetType testNewType = new DistributionSetType("test123", "TestName123", "Desc123"); - testNewType.addMandatoryModuleType(new SoftwareModuleType("foo", "bar", "test", Integer.MAX_VALUE)); + final DistributionSetType testNewType = distributionSetManagement.generateDistributionSetType("test123", + "TestName123", "Desc123"); + testNewType.addMandatoryModuleType( + softwareManagement.generateSoftwareModuleType("foo", "bar", "test", Integer.MAX_VALUE)); mvc.perform(post("/rest/v1/distributionsettypes") .content(JsonBuilder.distributionSetTypes(Lists.newArrayList(testNewType))) @@ -560,10 +561,10 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration @Test @Description("Search erquest of software module types.") public void searchDistributionSetTypeRsql() throws Exception { - final DistributionSetType testType = distributionSetManagement - .createDistributionSetType(new DistributionSetType("test123", "TestName123", "Desc123")); - final DistributionSetType testType2 = distributionSetManagement - .createDistributionSetType(new DistributionSetType("test1234", "TestName1234", "Desc123")); + final DistributionSetType testType = distributionSetManagement.createDistributionSetType( + distributionSetManagement.generateDistributionSetType("test123", "TestName123", "Desc123")); + final DistributionSetType testType2 = distributionSetManagement.createDistributionSetType( + distributionSetManagement.generateDistributionSetType("test1234", "TestName1234", "Desc123")); final String rsqlFindLikeDs1OrDs2 = "name==TestName123,name==TestName1234"; @@ -577,7 +578,7 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration char character = 'a'; for (int index = 0; index < amount; index++) { final String str = String.valueOf(character); - final SoftwareModule softwareModule = new SoftwareModule(osType, str, str, str, str); + final SoftwareModule softwareModule = softwareManagement.generateSoftwareModule(osType, str, str, str, str); softwareManagement.createSoftwareModule(softwareModule); character++; diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResourceTest.java index 09281721c..b1c843042 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResourceTest.java @@ -30,8 +30,8 @@ import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.Rollout.RolloutStatus; import org.eclipse.hawkbit.repository.model.RolloutGroup; -import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupConditionBuilder; import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupSuccessCondition; +import org.eclipse.hawkbit.repository.model.RolloutGroupConditionBuilder; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.rest.AbstractRestIntegrationTest; import org.eclipse.hawkbit.rest.util.JsonBuilder; @@ -577,7 +577,7 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest { private Rollout createRollout(final String name, final int amountGroups, final long distributionSetId, final String targetFilterQuery) { - final Rollout rollout = new Rollout(); + final Rollout rollout = rolloutManagement.generateRollout(); rollout.setDistributionSet(distributionSetManagement.findDistributionSetById(distributionSetId)); rollout.setName(name); rollout.setTargetFilterQuery(targetFilterQuery); diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java index a63dd754f..379674f98 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java @@ -44,7 +44,6 @@ import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata; -import org.eclipse.hawkbit.repository.model.SwMetadataCompositeKey; import org.eclipse.hawkbit.rest.AbstractRestIntegrationTestWithMongoDB; import org.eclipse.hawkbit.rest.json.model.ExceptionInfo; import org.eclipse.hawkbit.rest.util.JsonBuilder; @@ -92,11 +91,15 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW final String updateVendor = "newVendor1"; final String updateDescription = "newDescription1"; - softwareManagement.createSoftwareModule(new SoftwareModule(appType, "agent-hub", "1.0.1", null, "")); - softwareManagement.createSoftwareModule(new SoftwareModule(runtimeType, "oracle-jre", "1.7.2", null, "")); - softwareManagement.createSoftwareModule(new SoftwareModule(osType, "poky", "3.0.2", null, "")); + softwareManagement.createSoftwareModule( + softwareManagement.generateSoftwareModule(appType, "agent-hub", "1.0.1", null, "")); + softwareManagement.createSoftwareModule( + softwareManagement.generateSoftwareModule(runtimeType, "oracle-jre", "1.7.2", null, "")); + softwareManagement + .createSoftwareModule(softwareManagement.generateSoftwareModule(osType, "poky", "3.0.2", null, "")); - SoftwareModule sm = new SoftwareModule(osType, knownSWName, knownSWVersion, knownSWDescription, knownSWVendor); + SoftwareModule sm = softwareManagement.generateSoftwareModule(osType, knownSWName, knownSWVersion, + knownSWDescription, knownSWVendor); sm = softwareManagement.createSoftwareModule(sm); assertThat(sm.getName()).as("Wrong name of the software module").isEqualTo(knownSWName); @@ -122,7 +125,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW @Test @Description("Tests the uppload of an artifact binary. The upload is executed and the content checked in the repository for completenes.") public void uploadArtifact() throws Exception { - SoftwareModule sm = new SoftwareModule(osType, "name 1", "version 1", null, null); + SoftwareModule sm = softwareManagement.generateSoftwareModule(osType, "name 1", "version 1", null, null); sm = softwareManagement.createSoftwareModule(sm); assertThat(artifactRepository.findAll()).hasSize(0); @@ -191,7 +194,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0); assertThat(artifactRepository.findAll()).hasSize(0); - SoftwareModule sm = new SoftwareModule(osType, "name 1", "version 1", null, null); + SoftwareModule sm = softwareManagement.generateSoftwareModule(osType, "name 1", "version 1", null, null); sm = softwareManagement.createSoftwareModule(sm); final MockMultipartFile file = new MockMultipartFile("file", "orig", null, new byte[0]); @@ -204,7 +207,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW @Test @Description("Verfies that the system does not accept identical artifacts uploads for the same software module. Expected response: CONFLICT") public void duplicateUploadArtifact() throws Exception { - SoftwareModule sm = new SoftwareModule(osType, "name 1", "version 1", null, null); + SoftwareModule sm = softwareManagement.generateSoftwareModule(osType, "name 1", "version 1", null, null); sm = softwareManagement.createSoftwareModule(sm); final byte random[] = RandomStringUtils.random(5 * 1024).getBytes(); @@ -226,7 +229,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW @Test @Description("verfies that option to upload artifacts with a custom defined by metadata, i.e. not the file name of the binary itself.") public void uploadArtifactWithCustomName() throws Exception { - SoftwareModule sm = new SoftwareModule(osType, "name 1", "version 1", null, null); + SoftwareModule sm = softwareManagement.generateSoftwareModule(osType, "name 1", "version 1", null, null); sm = softwareManagement.createSoftwareModule(sm); assertThat(artifactRepository.findAll()).hasSize(0); @@ -253,7 +256,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW @Test @Description("Verfies that the system refuses upload of an artifact where the provided hash sums do not match. Expected result: BAD REQUEST") public void uploadArtifactWithHashCheck() throws Exception { - SoftwareModule sm = new SoftwareModule(osType, "name 1", "version 1", null, null); + SoftwareModule sm = softwareManagement.generateSoftwareModule(osType, "name 1", "version 1", null, null); sm = softwareManagement.createSoftwareModule(sm); assertThat(artifactRepository.findAll()).hasSize(0); @@ -297,7 +300,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW @Test @Description("Tests binary download of an artifact including verfication that the downloaded binary is consistent and that the etag header is as expected identical to the SHA1 hash of the file.") public void downloadArtifact() throws Exception { - SoftwareModule sm = new SoftwareModule(osType, "name 1", "version 1", null, null); + SoftwareModule sm = softwareManagement.generateSoftwareModule(osType, "name 1", "version 1", null, null); sm = softwareManagement.createSoftwareModule(sm); final byte random[] = RandomStringUtils.random(5 * 1024).getBytes(); @@ -332,7 +335,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW @Description("Verifies the listing of one defined artifact assigned to a given software module. That includes the artifact metadata and download links.") public void getArtifact() throws Exception { // prepare data for test - SoftwareModule sm = new SoftwareModule(osType, "name 1", "version 1", null, null); + SoftwareModule sm = softwareManagement.generateSoftwareModule(osType, "name 1", "version 1", null, null); sm = softwareManagement.createSoftwareModule(sm); final byte random[] = RandomStringUtils.random(5 * 1024).getBytes(); @@ -358,7 +361,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW @Test @Description("Verifies the listing of all artifacts assigned to a software module. That includes the artifact metadata and download links.") public void getArtifacts() throws Exception { - SoftwareModule sm = new SoftwareModule(osType, "name 1", "version 1", null, null); + SoftwareModule sm = softwareManagement.generateSoftwareModule(osType, "name 1", "version 1", null, null); sm = softwareManagement.createSoftwareModule(sm); final byte random[] = RandomStringUtils.random(5 * 1024).getBytes(); @@ -401,7 +404,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW final byte random[] = RandomStringUtils.random(5 * 1024).getBytes(); final MockMultipartFile file = new MockMultipartFile("file", "orig", null, random); - SoftwareModule sm = new SoftwareModule(osType, "name 1", "version 1", null, null); + SoftwareModule sm = softwareManagement.generateSoftwareModule(osType, "name 1", "version 1", null, null); sm = softwareManagement.createSoftwareModule(sm); // no artifact available @@ -434,7 +437,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW @Test @Description("Verfies that the system refuses unsupported request types and answers as defined to them, e.g. NOT FOUND on a non existing resource. Or a HTTP POST for updating a resource results in METHOD NOT ALLOWED etc.") public void invalidRequestsOnSoftwaremodulesResource() throws Exception { - SoftwareModule sm = new SoftwareModule(osType, "name 1", "version 1", null, null); + SoftwareModule sm = softwareManagement.generateSoftwareModule(osType, "name 1", "version 1", null, null); sm = softwareManagement.createSoftwareModule(sm); final List modules = new ArrayList<>(); @@ -516,13 +519,16 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW @WithUser(principal = "uploadTester", allSpPermissions = true) @Description("Test retrieval of all software modules the user has access to.") public void getSoftwareModules() throws Exception { - SoftwareModule os = new SoftwareModule(osType, "name1", "version1", "description1", "vendor1"); + SoftwareModule os = softwareManagement.generateSoftwareModule(osType, "name1", "version1", "description1", + "vendor1"); os = softwareManagement.createSoftwareModule(os); - SoftwareModule jvm = new SoftwareModule(runtimeType, "name1", "version1", "description1", "vendor1"); + SoftwareModule jvm = softwareManagement.generateSoftwareModule(runtimeType, "name1", "version1", "description1", + "vendor1"); jvm = softwareManagement.createSoftwareModule(jvm); - SoftwareModule ah = new SoftwareModule(appType, "name1", "version1", "description1", "vendor1"); + SoftwareModule ah = softwareManagement.generateSoftwareModule(appType, "name1", "version1", "description1", + "vendor1"); ah = softwareManagement.createSoftwareModule(ah); mvc.perform(get("/rest/v1/softwaremodules").accept(MediaType.APPLICATION_JSON)) @@ -584,22 +590,28 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW @Test @Description("Test the various filter parameters, e.g. filter by name or type of the module.") public void getSoftwareModulesWithFilterParameters() throws Exception { - SoftwareModule os1 = new SoftwareModule(osType, "osName1", "1.0.0", "description1", "vendor1"); + SoftwareModule os1 = softwareManagement.generateSoftwareModule(osType, "osName1", "1.0.0", "description1", + "vendor1"); os1 = softwareManagement.createSoftwareModule(os1); - SoftwareModule jvm1 = new SoftwareModule(runtimeType, "runtimeName1", "2.0.0", "description1", "vendor1"); + SoftwareModule jvm1 = softwareManagement.generateSoftwareModule(runtimeType, "runtimeName1", "2.0.0", + "description1", "vendor1"); jvm1 = softwareManagement.createSoftwareModule(jvm1); - SoftwareModule ah1 = new SoftwareModule(appType, "appName1", "3.0.0", "description1", "vendor1"); + SoftwareModule ah1 = softwareManagement.generateSoftwareModule(appType, "appName1", "3.0.0", "description1", + "vendor1"); ah1 = softwareManagement.createSoftwareModule(ah1); - SoftwareModule os2 = new SoftwareModule(osType, "osName2", "1.0.1", "description2", "vendor2"); + SoftwareModule os2 = softwareManagement.generateSoftwareModule(osType, "osName2", "1.0.1", "description2", + "vendor2"); os2 = softwareManagement.createSoftwareModule(os2); - SoftwareModule jvm2 = new SoftwareModule(runtimeType, "runtimeName2", "2.0.1", "description2", "vendor2"); + SoftwareModule jvm2 = softwareManagement.generateSoftwareModule(runtimeType, "runtimeName2", "2.0.1", + "description2", "vendor2"); jvm2 = softwareManagement.createSoftwareModule(jvm2); - SoftwareModule ah2 = new SoftwareModule(appType, "appName2", "3.0.1", "description2", "vendor2"); + SoftwareModule ah2 = softwareManagement.generateSoftwareModule(appType, "appName2", "3.0.1", "description2", + "vendor2"); ah2 = softwareManagement.createSoftwareModule(ah2); assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(6); @@ -676,7 +688,8 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW @WithUser(principal = "uploadTester", allSpPermissions = true) @Description("Tests GET request on /rest/v1/softwaremodules/{smId}.") public void getSoftareModule() throws Exception { - SoftwareModule os = new SoftwareModule(osType, "name1", "version1", "description1", "vendor1"); + SoftwareModule os = softwareManagement.generateSoftwareModule(osType, "name1", "version1", "description1", + "vendor1"); os = softwareManagement.createSoftwareModule(os); mvc.perform(get("/rest/v1/softwaremodules/{smId}", os.getId()).accept(MediaType.APPLICATION_JSON)) @@ -695,7 +708,8 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW .andExpect(jsonPath("$_links.artifacts.href", equalTo("http://localhost/rest/v1/softwaremodules/" + os.getId() + "/artifacts"))); - SoftwareModule jvm = new SoftwareModule(runtimeType, "name1", "version1", "description1", "vendor1"); + SoftwareModule jvm = softwareManagement.generateSoftwareModule(runtimeType, "name1", "version1", "description1", + "vendor1"); jvm = softwareManagement.createSoftwareModule(jvm); mvc.perform(get("/rest/v1/softwaremodules/{smId}", jvm.getId()).accept(MediaType.APPLICATION_JSON)) @@ -714,7 +728,8 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW .andExpect(jsonPath("$_links.artifacts.href", equalTo("http://localhost/rest/v1/softwaremodules/" + jvm.getId() + "/artifacts"))); - SoftwareModule ah = new SoftwareModule(appType, "name1", "version1", "description1", "vendor1"); + SoftwareModule ah = softwareManagement.generateSoftwareModule(appType, "name1", "version1", "description1", + "vendor1"); ah = softwareManagement.createSoftwareModule(ah); mvc.perform(get("/rest/v1/softwaremodules/{smId}", ah.getId()).accept(MediaType.APPLICATION_JSON)) @@ -740,9 +755,12 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW @WithUser(principal = "uploadTester", allSpPermissions = true) @Description("Verfies that the create request actually results in the creation of the modules in the repository.") public void createSoftwareModules() throws JSONException, Exception { - final SoftwareModule os = new SoftwareModule(osType, "name1", "version1", "description1", "vendor1"); - final SoftwareModule jvm = new SoftwareModule(runtimeType, "name2", "version1", "description1", "vendor1"); - final SoftwareModule ah = new SoftwareModule(appType, "name3", "version1", "description1", "vendor1"); + final SoftwareModule os = softwareManagement.generateSoftwareModule(osType, "name1", "version1", "description1", + "vendor1"); + final SoftwareModule jvm = softwareManagement.generateSoftwareModule(runtimeType, "name2", "version1", + "description1", "vendor1"); + final SoftwareModule ah = softwareManagement.generateSoftwareModule(appType, "name3", "version1", + "description1", "vendor1"); final List modules = new ArrayList<>(); modules.add(os); @@ -823,7 +841,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW @Description("Verifies successfull deletion of software modules that are not in use, i.e. assigned to a DS.") public void deleteUnassignedSoftwareModule() throws Exception { - SoftwareModule sm = new SoftwareModule(osType, "name 1", "version 1", null, null); + SoftwareModule sm = softwareManagement.generateSoftwareModule(osType, "name 1", "version 1", null, null); sm = softwareManagement.createSoftwareModule(sm); final byte random[] = RandomStringUtils.random(5 * 1024).getBytes(); @@ -879,7 +897,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW @Description("Tests the deletion of an artifact including verfication that the artifact is actually erased in the repository and removed from the software module.") public void deleteArtifact() throws Exception { // Create 1 SM - SoftwareModule sm = new SoftwareModule(osType, "name 1", "version 1", null, null); + SoftwareModule sm = softwareManagement.generateSoftwareModule(osType, "name 1", "version 1", null, null); sm = softwareManagement.createSoftwareModule(sm); final byte random[] = RandomStringUtils.random(5 * 1024).getBytes(); @@ -918,8 +936,8 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW final String knownKey2 = "knownKey1"; final String knownValue2 = "knownValue1"; - final SoftwareModule sm = softwareManagement - .createSoftwareModule(new SoftwareModule(osType, "name 1", "version 1", null, null)); + final SoftwareModule sm = softwareManagement.createSoftwareModule( + softwareManagement.generateSoftwareModule(osType, "name 1", "version 1", null, null)); final JSONArray jsonArray = new JSONArray(); jsonArray.put(new JSONObject().put("key", knownKey1).put("value", knownValue1)); @@ -932,10 +950,8 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW .andExpect(jsonPath("[1]key", equalTo(knownKey2))) .andExpect(jsonPath("[1]value", equalTo(knownValue2))); - final SoftwareModuleMetadata metaKey1 = softwareManagement - .findSoftwareModuleMetadata(new SwMetadataCompositeKey(sm, knownKey1)); - final SoftwareModuleMetadata metaKey2 = softwareManagement - .findSoftwareModuleMetadata(new SwMetadataCompositeKey(sm, knownKey2)); + final SoftwareModuleMetadata metaKey1 = softwareManagement.findSoftwareModuleMetadata(sm, knownKey1); + final SoftwareModuleMetadata metaKey2 = softwareManagement.findSoftwareModuleMetadata(sm, knownKey2); assertThat(metaKey1.getValue()).as("Metadata key is wrong").isEqualTo(knownValue1); assertThat(metaKey2.getValue()).as("Metadata key is wrong").isEqualTo(knownValue2); @@ -949,9 +965,10 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW final String knownValue = "knownValue"; final String updateValue = "valueForUpdate"; - final SoftwareModule sm = softwareManagement - .createSoftwareModule(new SoftwareModule(osType, "name 1", "version 1", null, null)); - softwareManagement.createSoftwareModuleMetadata(new SoftwareModuleMetadata(knownKey, sm, knownValue)); + final SoftwareModule sm = softwareManagement.createSoftwareModule( + softwareManagement.generateSoftwareModule(osType, "name 1", "version 1", null, null)); + softwareManagement.createSoftwareModuleMetadata( + softwareManagement.generateSoftwareModuleMetadata(sm, knownKey, knownValue)); final JSONObject jsonObject = new JSONObject().put("key", knownKey).put("value", updateValue); @@ -961,8 +978,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("key", equalTo(knownKey))).andExpect(jsonPath("value", equalTo(updateValue))); - final SoftwareModuleMetadata assertDS = softwareManagement - .findSoftwareModuleMetadata(new SwMetadataCompositeKey(sm, knownKey)); + final SoftwareModuleMetadata assertDS = softwareManagement.findSoftwareModuleMetadata(sm, knownKey); assertThat(assertDS.getValue()).as("Metadata is wrong").isEqualTo(updateValue); } @@ -973,15 +989,16 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW final String knownKey = "knownKey"; final String knownValue = "knownValue"; - final SoftwareModule sm = softwareManagement - .createSoftwareModule(new SoftwareModule(osType, "name 1", "version 1", null, null)); - softwareManagement.createSoftwareModuleMetadata(new SoftwareModuleMetadata(knownKey, sm, knownValue)); + final SoftwareModule sm = softwareManagement.createSoftwareModule( + softwareManagement.generateSoftwareModule(osType, "name 1", "version 1", null, null)); + softwareManagement.createSoftwareModuleMetadata( + softwareManagement.generateSoftwareModuleMetadata(sm, knownKey, knownValue)); mvc.perform(delete("/rest/v1/softwaremodules/{swId}/metadata/{key}", sm.getId(), knownKey)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); try { - softwareManagement.findSoftwareModuleMetadata(new SwMetadataCompositeKey(sm, knownKey)); + softwareManagement.findSoftwareModuleMetadata(sm, knownKey); fail("expected EntityNotFoundException but didn't throw"); } catch (final EntityNotFoundException e) { // ok as expected @@ -994,12 +1011,13 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW final int totalMetadata = 10; final String knownKeyPrefix = "knownKey"; final String knownValuePrefix = "knownValue"; - final SoftwareModule sm = softwareManagement - .createSoftwareModule(new SoftwareModule(osType, "name 1", "version 1", null, null)); + final SoftwareModule sm = softwareManagement.createSoftwareModule( + softwareManagement.generateSoftwareModule(osType, "name 1", "version 1", null, null)); for (int index = 0; index < totalMetadata; index++) { - softwareManagement.createSoftwareModuleMetadata(new SoftwareModuleMetadata(knownKeyPrefix + index, - softwareManagement.findSoftwareModuleById(sm.getId()), knownValuePrefix + index)); + softwareManagement.createSoftwareModuleMetadata(softwareManagement.generateSoftwareModuleMetadata( + softwareManagement.findSoftwareModuleById(sm.getId()), knownKeyPrefix + index, + knownValuePrefix + index)); } final String rsqlSearchValue1 = "value==knownValue1"; @@ -1014,7 +1032,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW char character = 'a'; for (int index = 0; index < amount; index++) { final String str = String.valueOf(character); - final SoftwareModule softwareModule = new SoftwareModule(osType, str, str, str, str); + final SoftwareModule softwareModule = softwareManagement.generateSoftwareModule(osType, str, str, str, str); softwareManagement.createSoftwareModule(softwareModule); character++; diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResourceTest.java index b69558e59..85df4fc70 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResourceTest.java @@ -54,8 +54,8 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT @WithUser(principal = "uploadTester", allSpPermissions = true) @Description("Checks the correct behaviour of /rest/v1/softwaremoduletypes GET requests.") public void getSoftwareModuleTypes() throws Exception { - SoftwareModuleType testType = softwareManagement - .createSoftwareModuleType(new SoftwareModuleType("test123", "TestName123", "Desc123", 5)); + SoftwareModuleType testType = softwareManagement.createSoftwareModuleType( + softwareManagement.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5)); testType.setDescription("Desc1234"); testType = softwareManagement.updateSoftwareModuleType(testType); @@ -97,7 +97,7 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT @Description("Checks the correct behaviour of /rest/v1/softwaremoduletypes GET requests with sorting by MAXASSIGNMENTS field.") public void getSoftwareModuleTypesSortedByMaxAssignments() throws Exception { SoftwareModuleType testType = softwareManagement - .createSoftwareModuleType(new SoftwareModuleType("test123", "TestName123", "Desc123", 5)); + .createSoftwareModuleType(softwareManagement.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5)); testType.setDescription("Desc1234"); testType = softwareManagement.updateSoftwareModuleType(testType); @@ -138,9 +138,9 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT public void createSoftwareModuleTypes() throws JSONException, Exception { final List types = new ArrayList<>(); - types.add(new SoftwareModuleType("test1", "TestName1", "Desc1", 1)); - types.add(new SoftwareModuleType("test2", "TestName2", "Desc2", 2)); - types.add(new SoftwareModuleType("test3", "TestName3", "Desc3", 3)); + types.add(softwareManagement.generateSoftwareModuleType("test1", "TestName1", "Desc1", 1)); + types.add(softwareManagement.generateSoftwareModuleType("test2", "TestName2", "Desc2", 2)); + types.add(softwareManagement.generateSoftwareModuleType("test3", "TestName3", "Desc3", 3)); final MvcResult mvcResult = mvc .perform(post("/rest/v1/softwaremoduletypes/").content(JsonBuilder.softwareModuleTypes(types)) @@ -183,7 +183,7 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT @Description("Checks the correct behaviour of /rest/v1/softwaremoduletypes/{ID} GET requests.") public void getSoftwareModuleType() throws Exception { SoftwareModuleType testType = softwareManagement - .createSoftwareModuleType(new SoftwareModuleType("test123", "TestName123", "Desc123", 5)); + .createSoftwareModuleType(softwareManagement.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5)); testType.setDescription("Desc1234"); testType = softwareManagement.updateSoftwareModuleType(testType); @@ -204,7 +204,7 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT @Description("Checks the correct behaviour of /rest/v1/softwaremoduletypes/{ID} DELETE requests (hard delete scenario).") public void deleteSoftwareModuleTypeUnused() throws Exception { final SoftwareModuleType testType = softwareManagement - .createSoftwareModuleType(new SoftwareModuleType("test123", "TestName123", "Desc123", 5)); + .createSoftwareModuleType(softwareManagement.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5)); assertThat(softwareManagement.countSoftwareModuleTypesAll()).isEqualTo(4); @@ -219,9 +219,9 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT @Description("Checks the correct behaviour of /rest/v1/softwaremoduletypes/{ID} DELETE requests (soft delete scenario).") public void deleteSoftwareModuleTypeUsed() throws Exception { final SoftwareModuleType testType = softwareManagement - .createSoftwareModuleType(new SoftwareModuleType("test123", "TestName123", "Desc123", 5)); - softwareManagement - .createSoftwareModule(new SoftwareModule(testType, "name", "version", "description", "vendor")); + .createSoftwareModuleType(softwareManagement.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5)); + softwareManagement.createSoftwareModule( + softwareManagement.generateSoftwareModule(testType, "name", "version", "description", "vendor")); assertThat(softwareManagement.countSoftwareModuleTypesAll()).isEqualTo(4); assertThat(softwareModuleTypeRepository.count()).isEqualTo(4); @@ -237,7 +237,7 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT @Description("Checks the correct behaviour of /rest/v1/softwaremoduletypes/{ID} PUT requests.") public void updateSoftwareModuleTypeOnlyDescriptionAndNameUntouched() throws Exception { final SoftwareModuleType testType = softwareManagement - .createSoftwareModuleType(new SoftwareModuleType("test123", "TestName123", "Desc123", 5)); + .createSoftwareModuleType(softwareManagement.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5)); final String body = new JSONObject().put("id", testType.getId()).put("description", "foobardesc") .put("name", "nameShouldNotBeChanged").toString(); @@ -293,7 +293,7 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT @Description("Ensures that the server is behaving as expected on invalid requests (wrong media type, wrong ID etc.).") public void invalidRequestsOnSoftwaremoduleTypesResource() throws Exception { final SoftwareModuleType testType = softwareManagement - .createSoftwareModuleType(new SoftwareModuleType("test123", "TestName123", "Desc123", 5)); + .createSoftwareModuleType(softwareManagement.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5)); final List types = new ArrayList<>(); types.add(testType); @@ -332,9 +332,9 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT @Description("Search erquest of software module types.") public void searchSoftwareModuleTypeRsql() throws Exception { final SoftwareModuleType testType = softwareManagement - .createSoftwareModuleType(new SoftwareModuleType("test123", "TestName123", "Desc123", 5)); + .createSoftwareModuleType(softwareManagement.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5)); final SoftwareModuleType testType2 = softwareManagement - .createSoftwareModuleType(new SoftwareModuleType("test1234", "TestName1234", "Desc123", 5)); + .createSoftwareModuleType(softwareManagement.generateSoftwareModuleType("test1234", "TestName1234", "Desc123", 5)); final String rsqlFindLikeDs1OrDs2 = "name==TestName123,name==TestName1234"; @@ -349,7 +349,7 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT char character = 'a'; for (int index = 0; index < amount; index++) { final String str = String.valueOf(character); - final SoftwareModule softwareModule = new SoftwareModule(osType, str, str, str, str); + final SoftwareModule softwareModule = softwareManagement.generateSoftwareModule(osType, str, str, str, str); softwareManagement.createSoftwareModule(softwareModule); character++; diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java index c8d33edc9..bc0f1cb0d 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java @@ -37,6 +37,9 @@ import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.repository.ActionFields; import org.eclipse.hawkbit.repository.ActionStatusFields; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; +import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; +import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.ActionType; import org.eclipse.hawkbit.repository.model.Action.Status; @@ -44,7 +47,6 @@ import org.eclipse.hawkbit.repository.model.ActionStatus; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.Target; -import org.eclipse.hawkbit.repository.model.TargetInfo; import org.eclipse.hawkbit.rest.AbstractRestIntegrationTest; import org.eclipse.hawkbit.rest.exception.MessageNotReadableException; import org.eclipse.hawkbit.rest.json.model.ExceptionInfo; @@ -56,7 +58,6 @@ import org.json.JSONObject; import org.junit.Ignore; import org.junit.Test; import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; import org.springframework.data.domain.Sort.Direction; import org.springframework.http.HttpStatus; @@ -110,9 +111,8 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { final String knownTargetId = "targetId"; final List actions = generateTargetWithTwoUpdatesWithOneOverride(knownTargetId); actions.get(0).setStatus(Status.FINISHED); - controllerManagament.addUpdateActionStatus( - new ActionStatus(actions.get(0), Status.FINISHED, System.currentTimeMillis(), "testmessage"), - actions.get(0)); + controllerManagament.addUpdateActionStatus(controllerManagament.generateActionStatus(actions.get(0), + Status.FINISHED, System.currentTimeMillis(), "testmessage")); final PageRequest pageRequest = new PageRequest(0, 1000, Direction.ASC, ActionFields.ID.getFieldName()); final ActionStatus status = deploymentManagement @@ -141,7 +141,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { public void securityTokenIsNotInResponseIfMissingPermission() throws Exception { final String knownControllerId = "knownControllerId"; - targetManagement.createTarget(new Target(knownControllerId)); + targetManagement.createTarget(targetManagement.generateTarget(knownControllerId)); mvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}", knownControllerId)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(jsonPath("securityToken").doesNotExist()); @@ -154,7 +154,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { public void securityTokenIsInResponseWithCorrectPermission() throws Exception { final String knownControllerId = "knownControllerId"; - final Target createTarget = targetManagement.createTarget(new Target(knownControllerId)); + final Target createTarget = targetManagement.createTarget(targetManagement.generateTarget(knownControllerId)); mvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}", knownControllerId)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(jsonPath("securityToken", equalTo(createTarget.getSecurityToken()))); @@ -185,8 +185,8 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { } private void createTarget(final String controllerId) { - final Target target = new Target(controllerId); - final TargetInfo targetInfo = new TargetInfo(target); + final JpaTarget target = (JpaTarget) targetManagement.generateTarget(controllerId); + final JpaTargetInfo targetInfo = new JpaTargetInfo(target); targetInfo.setAddress(IpUtil.createHttpUri("127.0.0.1").toString()); target.setTargetInfo(targetInfo); targetManagement.createTarget(target); @@ -199,7 +199,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { // prepare test final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement, distributionSetManagement); - final Target createTarget = targetManagement.createTarget(new Target("knownTargetId")); + final Target createTarget = targetManagement.createTarget(targetManagement.generateTarget("knownTargetId")); deploymentManagement.assignDistributionSet(dsA, Lists.newArrayList(createTarget)); @@ -306,7 +306,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { @Description("Ensures that deletion is executed if permitted.") public void deleteTargetReturnsOK() throws Exception { final String knownControllerId = "knownControllerIdDelete"; - targetManagement.createTarget(new Target(knownControllerId)); + targetManagement.createTarget(targetManagement.generateTarget(knownControllerId)); mvc.perform(delete(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownControllerId)) .andExpect(status().isOk()); @@ -342,7 +342,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { final String body = new JSONObject().put("description", knownNewDescription).toString(); // prepare - final Target t = new Target(knownControllerId); + final Target t = targetManagement.generateTarget(knownControllerId); t.setDescription("old description"); t.setName(knownNameNotModiy); targetManagement.createTarget(t); @@ -599,9 +599,10 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement, distributionSetManagement); // assign ds to target - deploymentManagement.assignDistributionSet(ds.getId(), knownControllerId); + final Long actionId = deploymentManagement.assignDistributionSet(ds.getId(), knownControllerId).getActions() + .get(0); // give feedback, so installedDS is in SNYC - feedbackToByInSync(knownControllerId, ds); + feedbackToByInSync(actionId); // test final SoftwareModule os = ds.findFirstModuleByType(osType); @@ -683,13 +684,13 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { @Test public void createTargetsListReturnsSuccessful() throws Exception { - final Target test1 = new Target("id1"); + final Target test1 = targetManagement.generateTarget("id1"); test1.setDescription("testid1"); test1.setName("testname1"); - final Target test2 = new Target("id2"); + final Target test2 = targetManagement.generateTarget("id2"); test2.setDescription("testid2"); test2.setName("testname2"); - final Target test3 = new Target("id3"); + final Target test3 = targetManagement.generateTarget("id3"); test3.setName("testname3"); test3.setDescription("testid3"); @@ -812,7 +813,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { @Test public void getActionWithEmptyResult() throws Exception { final String knownTargetId = "targetId"; - final Target target = new Target(knownTargetId); + final Target target = targetManagement.generateTarget(knownTargetId); targetManagement.createTarget(target); mvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownTargetId + "/" @@ -1027,12 +1028,12 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { final PageRequest pageRequest = new PageRequest(0, 100, Direction.ASC, ActionStatusFields.ID.getFieldName()); - Target target = new Target(knownTargetId); + Target target = targetManagement.generateTarget(knownTargetId); target = targetManagement.createTarget(target); final List targets = new ArrayList<>(); targets.add(target); - final Iterator sets = TestDataUtil + final Iterator sets = TestDataUtil .generateDistributionSets(2, softwareManagement, distributionSetManagement).iterator(); final DistributionSet one = sets.next(); final DistributionSet two = sets.next(); @@ -1045,8 +1046,8 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { Thread.sleep(10); deploymentManagement.assignDistributionSet(two, updatedTargets); - // two updates, one cancelation - final List actions = actionRepository.findAll(pageRequest).getContent(); + // two updates, one cancellation + final List actions = deploymentManagement.findActionsByTarget(target); assertThat(actions).hasSize(2); return actions; @@ -1073,7 +1074,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { @Test public void assignDistributionSetToTarget() throws Exception { - final Target target = targetManagement.createTarget(new Target("fsdfsd")); + final Target target = targetManagement.createTarget(targetManagement.generateTarget("fsdfsd")); final DistributionSet set = TestDataUtil.generateDistributionSet("one", softwareManagement, distributionSetManagement); @@ -1087,7 +1088,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { @Test public void assignDistributionSetToTargetWithActionTimeForcedAndTime() throws Exception { - final Target target = targetManagement.createTarget(new Target("fsdfsd")); + final Target target = targetManagement.createTarget(targetManagement.generateTarget("fsdfsd")); final DistributionSet set = TestDataUtil.generateDistributionSet("one", softwareManagement, distributionSetManagement); @@ -1116,7 +1117,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { .content("{\"id\":" + set.getId() + "}").contentType(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isNotFound()); - targetManagement.createTarget(new Target("fsdfsd")); + targetManagement.createTarget(targetManagement.generateTarget("fsdfsd")); mvc.perform(post(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/fsdfsd/assignedDS") .content("{\"id\":" + set.getId() + "}").contentType(MediaType.APPLICATION_JSON)) @@ -1206,7 +1207,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { final Map knownControllerAttrs = new HashMap<>(); knownControllerAttrs.put("a", "1"); knownControllerAttrs.put("b", "2"); - final Target target = new Target(knownTargetId); + final Target target = targetManagement.generateTarget(knownTargetId); targetManagement.createTarget(target); controllerManagament.updateControllerAttributes(knownTargetId, knownControllerAttrs); @@ -1220,7 +1221,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { public void getControllerEmptyAttributesReturnsNoContent() throws Exception { // create target with attributes final String knownTargetId = "targetIdWithAttributes"; - final Target target = new Target(knownTargetId); + final Target target = targetManagement.generateTarget(knownTargetId); targetManagement.createTarget(target); // test query target over rest resource @@ -1254,7 +1255,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { } private void createSingleTarget(final String controllerId, final String name) { - final Target target = new Target(controllerId); + final Target target = targetManagement.generateTarget(controllerId); target.setName(name); target.setDescription(TARGET_DESCRIPTION_TEST); targetManagement.createTarget(target); @@ -1271,7 +1272,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { char character = 'a'; for (int index = 0; index < amount; index++) { final String str = String.valueOf(character); - final Target target = new Target(str); + final Target target = targetManagement.generateTarget(str); target.setName(str); target.setDescription(str); final Target savedTarget = targetManagement.createTarget(target); @@ -1283,20 +1284,12 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { /** * helper method to give feedback mark an target IN_SNCY * - * @param controllerId - * the controller id to give feedback to - * @param savedSet - * the distribution set - * @throws Exception - * @throws JSONException */ - private void feedbackToByInSync(final String controllerId, final DistributionSet savedSet) - throws Exception, JSONException { - final Pageable pageReq = new PageRequest(0, 100); - final Action action = actionRepository.findByDistributionSet(pageReq, savedSet).getContent().get(0); + private void feedbackToByInSync(final Long actionId) { + final Action action = deploymentManagement.findAction(actionId); - final ActionStatus actionStatus = new ActionStatus(action, Status.FINISHED, 0l); - controllerManagement.addUpdateActionStatus(actionStatus, action); + final ActionStatus actionStatus = controllerManagement.generateActionStatus(action, Status.FINISHED, 0L); + controllerManagement.addUpdateActionStatus(actionStatus); } /** diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/SMRessourceMisingMongoDbConnectionTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/SMRessourceMisingMongoDbConnectionTest.java index 15d22c703..dc5d5122d 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/SMRessourceMisingMongoDbConnectionTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/SMRessourceMisingMongoDbConnectionTest.java @@ -49,7 +49,7 @@ public class SMRessourceMisingMongoDbConnectionTest extends AbstractIntegrationT assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0); assertThat(artifactRepository.findAll()).hasSize(0); - SoftwareModule sm = new SoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1", + SoftwareModule sm = softwareManagement.generateSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1", "version 1", null, null); sm = softwareManagement.createSoftwareModule(sm); assertThat(artifactRepository.findAll()).hasSize(0); diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java index f58af4ca6..42843b495 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java @@ -171,8 +171,8 @@ public interface DeploymentManagement { /** * counts all actions associated to a specific target. * - * @param spec - * the specification to filter the count result + * @param rsqlParam + * rsql query string * @param target * the target associated to the actions to count * @return the count value of found actions associated to the target @@ -271,8 +271,8 @@ public interface DeploymentManagement { * Retrieves all {@link Action}s assigned to a specific {@link Target} and a * given specification. * - * @param specifiction - * the specification to narrow down the search + * @param rsqlParam + * rsql query string * @param target * the target which must be assigned to the actions * @param pageable @@ -280,7 +280,6 @@ public interface DeploymentManagement { * @return a slice of actions assigned to the specific target and the * specification */ - // TODO fix this @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) Slice findActionsByTarget(@NotNull String rsqlParam, @NotNull Target target, @NotNull Pageable pageable); diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetAssignmentResult.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetAssignmentResult.java index 1393504ab..f21763883 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetAssignmentResult.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetAssignmentResult.java @@ -59,10 +59,9 @@ public class DistributionSetAssignmentResult extends AssignmentResult { return actions; } - @SuppressWarnings("unchecked") @Override public List getAssignedEntity() { - return (List) targetManagement.findTargetByControllerID(assignedTargets); + return targetManagement.findTargetByControllerID(assignedTargets); } } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java index 9b4dcb8c7..8316508d9 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java @@ -86,6 +86,9 @@ public interface DistributionSetManagement { /** * Count all {@link DistributionSet}s in the repository that are not marked * as deleted. + * + * @param type + * to look for * * @return number of {@link DistributionSet}s */ @@ -289,8 +292,8 @@ public interface DistributionSetManagement { * * @param distributionSetId * the distribution set id to retrieve the meta data from - * @param spec - * the specification to filter the result + * @param rsqlParam + * rsql query string * @param pageable * the page request to page the result * @return a paged result of all meta data entries for a given distribution @@ -343,8 +346,8 @@ public interface DistributionSetManagement { /** * finds all {@link DistributionSet}s. * - * @param spec - * the specification to add for the search query. + * @param rsqlParam + * rsql query string * @param pageReq * the pagination parameter * @param deleted @@ -432,8 +435,8 @@ public interface DistributionSetManagement { /** * Generic predicate based query for {@link DistributionSetType}. * - * @param spec - * of the search + * @param rsqlParam + * rsql query string * @param pageable * parameter for paging * diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TagManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TagManagement.java index 786308e70..551e34dd9 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TagManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TagManagement.java @@ -130,8 +130,8 @@ public interface TagManagement { /** * Retrieves all DistributionSet tags based on the given specification. * - * @param spec - * the specification for the query + * @param rsqlParam + * rsql query string * @param pageable * pagination parameter * @return the found {@link DistributionSetTag}s, never {@code null} @@ -159,8 +159,8 @@ public interface TagManagement { /** * Retrieves all target tags based on the given specification. * - * @param spec - * the specification for the query + * @param rsqlParam + * rsql query string * @param pageable * pagination parameter * @return the found {@link Target}s, never {@code null} @@ -245,12 +245,48 @@ public interface TagManagement { */ DistributionSetTag generateDistributionSetTag(); + /** + * Generates a {@link TargetTag} without persisting it. + * + * @param name + * of the tag + * @param description + * of the tag + * @param colour + * of the tag + * @return {@link TargetTag} object + */ TargetTag generateTargetTag(String name, String description, String colour); + /** + * Generates a {@link TargetTag} without persisting it. + * + * @param name + * of the tag + * @return {@link TargetTag} object + */ TargetTag generateTargetTag(String name); + /** + * Generates a {@link DistributionSetTag} without persisting it. + * + * @param name + * of the tag + * @param description + * of the tag + * @param colour + * of the tag + * @return {@link DistributionSetTag} object + */ DistributionSetTag generateDistributionSetTag(String name, String description, String colour); + /** + * Generates a {@link DistributionSetTag} without persisting it. + * + * @param name + * of the tag + * @return {@link DistributionSetTag} object + */ DistributionSetTag generateDistributionSetTag(String name); -} \ No newline at end of file +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java index 09283f67c..af7f6371d 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java @@ -395,7 +395,7 @@ public class JpaControllerManagement implements ControllerManagement { // retrieves after the other we don't want to store to protect to // overflood action status in // case controller retrieves a action multiple times. - if (resultList.isEmpty() || resultList.get(0)[1] != Status.RETRIEVED) { + if (resultList.isEmpty() || !Status.RETRIEVED.equals(resultList.get(0)[1])) { // document that the status has been retrieved actionStatusRepository .save(new JpaActionStatus(action, Status.RETRIEVED, System.currentTimeMillis(), message)); diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTenantConfigurationManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTenantConfigurationManagement.java index c9781a2a4..ec5f3e843 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTenantConfigurationManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTenantConfigurationManagement.java @@ -81,7 +81,7 @@ public class JpaTenantConfigurationManagement implements EnvironmentAware, Tenan final TenantConfigurationKey configurationKey, final Class propertyType, final TenantConfiguration tenantConfiguration) { if (tenantConfiguration != null) { - return TenantConfigurationValue. builder().isGlobal(false).createdBy(tenantConfiguration.getCreatedBy()) + return TenantConfigurationValue. builder().global(false).createdBy(tenantConfiguration.getCreatedBy()) .createdAt(tenantConfiguration.getCreatedAt()) .lastModifiedAt(tenantConfiguration.getLastModifiedAt()) .lastModifiedBy(tenantConfiguration.getLastModifiedBy()) @@ -89,7 +89,7 @@ public class JpaTenantConfigurationManagement implements EnvironmentAware, Tenan } else if (configurationKey.getDefaultKeyName() != null) { - return TenantConfigurationValue. builder().isGlobal(true).createdBy(null).createdAt(null) + return TenantConfigurationValue. builder().global(true).createdBy(null).createdAt(null) .lastModifiedAt(null).lastModifiedBy(null) .value(getGlobalConfigurationValue(configurationKey, propertyType)).build(); } @@ -149,8 +149,7 @@ public class JpaTenantConfigurationManagement implements EnvironmentAware, Tenan final Class clazzT = (Class) value.getClass(); - return TenantConfigurationValue. builder().isGlobal(false) - .createdBy(updatedTenantConfiguration.getCreatedBy()) + return TenantConfigurationValue. builder().global(false).createdBy(updatedTenantConfiguration.getCreatedBy()) .createdAt(updatedTenantConfiguration.getCreatedAt()) .lastModifiedAt(updatedTenantConfiguration.getLastModifiedAt()) .lastModifiedBy(updatedTenantConfiguration.getLastModifiedBy()) diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetTag.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetTag.java index c4b55fe03..1663fb620 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetTag.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetTag.java @@ -59,8 +59,11 @@ public class JpaDistributionSetTag extends AbstractJpaTag implements Distributio super(name, description, colour); } + /** + * Default constructor for JPA. + */ public JpaDistributionSetTag() { - super(); + // Default constructor for JPA. } @Override diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRollout.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRollout.java index 38dadc1c4..40622134f 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRollout.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRollout.java @@ -158,7 +158,6 @@ public class JpaRollout extends AbstractJpaNamedEntity implements Rollout { this.totalTargets = totalTargets; } - @Override public int getRolloutGroupsTotal() { return rolloutGroupsTotal; } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModuleType.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModuleType.java index a943b08a4..bb99eba3e 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModuleType.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModuleType.java @@ -32,10 +32,6 @@ public class JpaSoftwareModuleType extends AbstractJpaNamedEntity implements Sof @Column(name = "type_key", nullable = false, length = 64) private String key; - public void setMaxAssignments(final int maxAssignments) { - this.maxAssignments = maxAssignments; - } - @Column(name = "max_ds_assignments", nullable = false) private int maxAssignments; @@ -87,10 +83,15 @@ public class JpaSoftwareModuleType extends AbstractJpaNamedEntity implements Sof } /** - * Default Constructor. + * Default Constructor for JPA. */ public JpaSoftwareModuleType() { - super(); + // Default Constructor for JPA. + } + + @Override + public void setMaxAssignments(final int maxAssignments) { + this.maxAssignments = maxAssignments; } @Override @@ -108,7 +109,6 @@ public class JpaSoftwareModuleType extends AbstractJpaNamedEntity implements Sof return deleted; } - @Override public void setDeleted(final boolean deleted) { this.deleted = deleted; } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetFilterQuery.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetFilterQuery.java index 55aaec0fe..5ebb8e2bf 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetFilterQuery.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetFilterQuery.java @@ -37,6 +37,14 @@ public class JpaTargetFilterQuery extends AbstractJpaTenantAwareBaseEntity imple // Default constructor for JPA. } + /** + * Public constructor. + * + * @param name + * of the {@link TargetFilterQuery}. + * @param query + * of the {@link TargetFilterQuery}. + */ public JpaTargetFilterQuery(final String name, final String query) { this.name = name; this.query = query; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetTag.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetTag.java index 800fcc15e..96989f14a 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetTag.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetTag.java @@ -60,7 +60,7 @@ public class JpaTargetTag extends AbstractJpaTag implements TargetTag { } public JpaTargetTag() { - super(); + // Default constructor for JPA. } @Override diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/TargetFilterQuerySpecification.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/TargetFilterQuerySpecification.java index cb3b775ac..4b27c7fc7 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/TargetFilterQuerySpecification.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/TargetFilterQuerySpecification.java @@ -18,11 +18,19 @@ import org.springframework.data.jpa.domain.Specification; * Spring Data JPQL Specifications. * */ -public class TargetFilterQuerySpecification { +public final class TargetFilterQuerySpecification { private TargetFilterQuerySpecification() { // utility class } + /** + * {@link Specification} for retrieving {@link JpaTargetFilterQuery}s based + * on is {@link JpaTargetFilterQuery#getName()}. + * + * @param searchText + * of the filter + * @return the {@link JpaTargetFilterQuery} {@link Specification} + */ public static Specification likeName(final String searchText) { return (targetFilterQueryRoot, query, cb) -> { final String searchTextToLower = searchText.toLowerCase(); diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Action.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Action.java index 74f921642..1bd3f8c35 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Action.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Action.java @@ -189,12 +189,12 @@ public interface Action extends TenantAwareBaseEntity { CANCELING, /** - * Action has been presented to the target. + * Action has been send to the target. */ RETRIEVED, /** - * Action needs download by this target which has now started. + * Action requests download by this target which has now started. */ DOWNLOAD, diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/PollStatus.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/PollStatus.java new file mode 100644 index 000000000..876020dbd --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/PollStatus.java @@ -0,0 +1,68 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.model; + +import java.time.LocalDateTime; + +/** + * The poll time object which holds all the necessary information around the + * target poll time, e.g. the last poll time, the next poll time and the overdue + * poll time. + * + */ +public class PollStatus { + private final LocalDateTime lastPollDate; + private final LocalDateTime nextPollDate; + private final LocalDateTime overdueDate; + private final LocalDateTime currentDate; + + public PollStatus(final LocalDateTime lastPollDate, final LocalDateTime nextPollDate, + final LocalDateTime overdueDate, final LocalDateTime currentDate) { + this.lastPollDate = lastPollDate; + this.nextPollDate = nextPollDate; + this.overdueDate = overdueDate; + this.currentDate = currentDate; + } + + /** + * calculates if the target poll time is overdue and the target has not been + * polled in the configured poll time interval. + * + * @return {@code true} if the current time is after the poll time overdue + * date otherwise {@code false}. + */ + public boolean isOverdue() { + return currentDate.isAfter(overdueDate); + } + + /** + * @return the lastPollDate + */ + public LocalDateTime getLastPollDate() { + return lastPollDate; + } + + public LocalDateTime getNextPollDate() { + return nextPollDate; + } + + public LocalDateTime getOverdueDate() { + return overdueDate; + } + + public LocalDateTime getCurrentDate() { + return currentDate; + } + + @Override + public String toString() { + return "PollTime [lastPollDate=" + lastPollDate + ", nextPollDate=" + nextPollDate + ", overdueDate=" + + overdueDate + ", currentDate=" + currentDate + "]"; + } +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Rollout.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Rollout.java index f87b1067f..5094c1af8 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Rollout.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Rollout.java @@ -9,8 +9,10 @@ package org.eclipse.hawkbit.repository.model; import java.util.List; +import java.util.concurrent.TimeUnit; import org.eclipse.hawkbit.repository.model.Action.ActionType; +import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus.Status; /** * Software update operations in large scale IoT scenarios with hundred of @@ -57,20 +59,46 @@ public interface Rollout extends NamedEntity { */ RolloutStatus getStatus(); + /** + * @return {@link ActionType} of the rollout. + */ ActionType getActionType(); + /** + * @param actionType + * of the rollout. + */ void setActionType(ActionType actionType); + /** + * @return time in {@link TimeUnit#MILLISECONDS} after which + * {@link #isForced()} switches to true in case of + * {@link ActionType#TIMEFORCED}. + */ long getForcedTime(); + /** + * @param forcedTime + * in {@link TimeUnit#MILLISECONDS} after which + * {@link #isForced()} switches to true in case of + * {@link ActionType#TIMEFORCED}. + */ void setForcedTime(long forcedTime); + /** + * @return number of {@link Target}s in this rollout. + */ long getTotalTargets(); - int getRolloutGroupsTotal(); - + /** + * @return number of {@link RolloutGroup}s. + */ int getRolloutGroupsCreated(); + /** + * @return all states with the respective target count in that + * {@link Status}. + */ TotalTargetCountStatus getTotalTargetCountStatus(); /** diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/RolloutGroup.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/RolloutGroup.java index cd65c4d2f..3f383d605 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/RolloutGroup.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/RolloutGroup.java @@ -182,4 +182,4 @@ public interface RolloutGroup extends NamedEntity { return beanName; } } -} \ No newline at end of file +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/RolloutGroupConditionBuilder.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/RolloutGroupConditionBuilder.java new file mode 100644 index 000000000..7ef8c8a19 --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/RolloutGroupConditionBuilder.java @@ -0,0 +1,91 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.model; + +import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupErrorAction; +import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupErrorCondition; +import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupSuccessAction; +import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupSuccessCondition; + +/** + * Builder to build easily the {@link RolloutGroupConditions}. + * + */ +public class RolloutGroupConditionBuilder { + private final RolloutGroupConditions conditions = new RolloutGroupConditions(); + + /** + * @return completed {@link RolloutGroupConditions}. + */ + public RolloutGroupConditions build() { + return conditions; + } + + /** + * Sets the finish condition and expression on the builder. + * + * @param condition + * the finish condition + * @param expression + * the finish expression + * @return the builder itself + */ + public RolloutGroupConditionBuilder successCondition(final RolloutGroupSuccessCondition condition, + final String expression) { + conditions.setSuccessCondition(condition); + conditions.setSuccessConditionExp(expression); + return this; + } + + /** + * Sets the success action and expression on the builder. + * + * @param action + * the success action + * @param expression + * the error expression + * @return the builder itself + */ + public RolloutGroupConditionBuilder successAction(final RolloutGroupSuccessAction action, final String expression) { + conditions.setSuccessAction(action); + conditions.setSuccessActionExp(expression); + return this; + } + + /** + * Sets the error condition and expression on the builder. + * + * @param condition + * the error condition + * @param expression + * the error expression + * @return the builder itself + */ + public RolloutGroupConditionBuilder errorCondition(final RolloutGroupErrorCondition condition, + final String expression) { + conditions.setErrorCondition(condition); + conditions.setErrorConditionExp(expression); + return this; + } + + /** + * Sets the error action and expression on the builder. + * + * @param action + * the error action + * @param expression + * the error expression + * @return the builder itself + */ + public RolloutGroupConditionBuilder errorAction(final RolloutGroupErrorAction action, final String expression) { + conditions.setErrorAction(action); + conditions.setErrorActionExp(expression); + return this; + } +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/RolloutGroupConditions.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/RolloutGroupConditions.java new file mode 100644 index 000000000..618e93c4e --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/RolloutGroupConditions.java @@ -0,0 +1,93 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.model; + +import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupErrorAction; +import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupErrorCondition; +import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupSuccessAction; +import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupSuccessCondition; + +/** + * Object which holds all {@link RolloutGroup} conditions together which can + * easily built. + */ +public class RolloutGroupConditions { + private RolloutGroupSuccessCondition successCondition; + private String successConditionExp; + private RolloutGroupSuccessAction successAction; + private String successActionExp; + private RolloutGroupErrorCondition errorCondition; + private String errorConditionExp; + private RolloutGroupErrorAction errorAction; + private String errorActionExp; + + public RolloutGroupSuccessCondition getSuccessCondition() { + return successCondition; + } + + public void setSuccessCondition(final RolloutGroupSuccessCondition finishCondition) { + successCondition = finishCondition; + } + + public String getSuccessConditionExp() { + return successConditionExp; + } + + public void setSuccessConditionExp(final String finishConditionExp) { + successConditionExp = finishConditionExp; + } + + public RolloutGroupSuccessAction getSuccessAction() { + return successAction; + } + + public void setSuccessAction(final RolloutGroupSuccessAction successAction) { + this.successAction = successAction; + } + + public String getSuccessActionExp() { + return successActionExp; + } + + public void setSuccessActionExp(final String successActionExp) { + this.successActionExp = successActionExp; + } + + public RolloutGroupErrorCondition getErrorCondition() { + return errorCondition; + } + + public void setErrorCondition(final RolloutGroupErrorCondition errorCondition) { + this.errorCondition = errorCondition; + } + + public String getErrorConditionExp() { + return errorConditionExp; + } + + public void setErrorConditionExp(final String errorConditionExp) { + this.errorConditionExp = errorConditionExp; + } + + public RolloutGroupErrorAction getErrorAction() { + return errorAction; + } + + public void setErrorAction(final RolloutGroupErrorAction errorAction) { + this.errorAction = errorAction; + } + + public String getErrorActionExp() { + return errorActionExp; + } + + public void setErrorActionExp(final String errorActionExp) { + this.errorActionExp = errorActionExp; + } +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleType.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleType.java index 24417d3f8..313525199 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleType.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleType.java @@ -8,22 +8,53 @@ */ package org.eclipse.hawkbit.repository.model; +/** + * {@link SoftwareModuleType} is an abstract definition used in + * {@link DistributionSetType}s and includes additional {@link SoftwareModule} + * specific information. + * + */ public interface SoftwareModuleType extends NamedEntity { + /** + * @return business key of this {@link SoftwareModuleType}. + */ String getKey(); + /** + * @param key + * of this {@link SoftwareModuleType}. + */ void setKey(String key); + /** + * @return maximum assignments of an {@link SoftwareModule} of this type to + * a {@link DistributionSet}. + */ int getMaxAssignments(); + /** + * @param maxAssignments + * of an {@link SoftwareModule} of this type to a + * {@link DistributionSet}. + */ void setMaxAssignments(int maxAssignments); + /** + * @return true if the type is deleted and only kept for + * history purposes. + */ boolean isDeleted(); - void setDeleted(boolean deleted); - + /** + * @return get color code to by used in management UI views. + */ String getColour(); - void setColour(String colour); + /** + * @param colour + * code to by used in management UI views. + */ + void setColour(final String colour); } \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetIdName.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetIdName.java index 26a74e9bb..444874581 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetIdName.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetIdName.java @@ -60,6 +60,8 @@ public class TargetIdName implements Serializable { } @Override + // Exception squid:S864 - generated code + @SuppressWarnings("squid:S864") public int hashCode() { final int prime = 31; int result = 1; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TenantConfigurationValue.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TenantConfigurationValue.java index 37e00e247..a204ef506 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TenantConfigurationValue.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TenantConfigurationValue.java @@ -14,14 +14,14 @@ package org.eclipse.hawkbit.repository.model; * @param * type of the configuration value */ -public class TenantConfigurationValue { +public final class TenantConfigurationValue { private T value; private Long lastModifiedAt; private String lastModifiedBy; private Long createdAt; private String createdBy; - private boolean isGlobal = true; + private boolean global = true; private TenantConfigurationValue() { } @@ -41,7 +41,7 @@ public class TenantConfigurationValue { * @return true, if is global */ public boolean isGlobal() { - return isGlobal; + return global; } /** @@ -126,13 +126,13 @@ public class TenantConfigurationValue { /** * set the is global attribute. * - * @param isGlobal + * @param global * true when there is no tenant specific value, false * otherwise * @return the tenant configuration value builder */ - public TenantConfigurationValueBuilder isGlobal(final boolean isGlobal) { - this.configuration.isGlobal = isGlobal; + public TenantConfigurationValueBuilder global(final boolean global) { + this.configuration.global = global; return this; } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TotalTargetCountStatus.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TotalTargetCountStatus.java index 13c41baf3..bcb0df3f4 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TotalTargetCountStatus.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TotalTargetCountStatus.java @@ -15,7 +15,8 @@ import java.util.Map; /** * - * Store all states with the target count of a rollout or rolloutgroup. + * Store target count of a {@link Rollout} or {@link RolloutGroup} for every + * {@link Status}. * */ public class TotalTargetCountStatus { @@ -24,7 +25,35 @@ public class TotalTargetCountStatus { * Status of the total target counts. */ public enum Status { - SCHEDULED, RUNNING, ERROR, FINISHED, CANCELLED, NOTSTARTED + /** + * Action is scheduled. + */ + SCHEDULED, + + /** + * Action is still running. + */ + RUNNING, + + /** + * Action failed. + */ + ERROR, + + /** + * Action is completed. + */ + FINISHED, + + /** + * Action is canceled. + */ + CANCELLED, + + /** + * Action is not started yet. + */ + NOTSTARTED } private final Map statusTotalCountMap = new EnumMap<>(Status.class); @@ -35,7 +64,7 @@ public class TotalTargetCountStatus { * * @param targetCountActionStatus * the action state map - * @param totalTargets + * @param totalTargetCount * the total target count */ public TotalTargetCountStatus(final List targetCountActionStatus, @@ -81,8 +110,7 @@ public class TotalTargetCountStatus { * @param statusTotalCountMap * the map * @param rolloutStatusCountItems - * all target statut with total count - * @return some state is populated nothing is happend + * all target {@link Status} with total count */ private final void mapActionStatusToTotalTargetCountStatus( final List targetCountActionStatus) { @@ -93,33 +121,40 @@ public class TotalTargetCountStatus { statusTotalCountMap.put(Status.RUNNING, 0L); Long notStartedTargetCount = totalTargetCount; for (final TotalTargetCountActionStatus item : targetCountActionStatus) { - switch (item.getStatus()) { - case SCHEDULED: - statusTotalCountMap.put(Status.SCHEDULED, item.getCount()); - break; - case ERROR: - statusTotalCountMap.put(Status.ERROR, item.getCount()); - break; - case FINISHED: - statusTotalCountMap.put(Status.FINISHED, item.getCount()); - break; - case RETRIEVED: - case RUNNING: - case WARNING: - case DOWNLOAD: - case CANCELING: - final Long runningItemsCount = statusTotalCountMap.get(Status.RUNNING) + item.getCount(); - statusTotalCountMap.put(Status.RUNNING, runningItemsCount); - break; - case CANCELED: - statusTotalCountMap.put(Status.CANCELLED, item.getCount()); - break; - default: - throw new IllegalArgumentException("State " + item.getStatus() + "is not valid"); - } + convertStatus(item); notStartedTargetCount -= item.getCount(); } statusTotalCountMap.put(TotalTargetCountStatus.Status.NOTSTARTED, notStartedTargetCount); } + // Exception squid:MethodCyclomaticComplexity - simple state conversion, not + // really complex. + @SuppressWarnings("squid:MethodCyclomaticComplexity") + private void convertStatus(final TotalTargetCountActionStatus item) { + switch (item.getStatus()) { + case SCHEDULED: + statusTotalCountMap.put(Status.SCHEDULED, item.getCount()); + break; + case ERROR: + statusTotalCountMap.put(Status.ERROR, item.getCount()); + break; + case FINISHED: + statusTotalCountMap.put(Status.FINISHED, item.getCount()); + break; + case RETRIEVED: + case RUNNING: + case WARNING: + case DOWNLOAD: + case CANCELING: + final Long runningItemsCount = statusTotalCountMap.get(Status.RUNNING) + item.getCount(); + statusTotalCountMap.put(Status.RUNNING, runningItemsCount); + break; + case CANCELED: + statusTotalCountMap.put(Status.CANCELLED, item.getCount()); + break; + default: + throw new IllegalArgumentException("State " + item.getStatus() + "is not valid"); + } + } + } From 693c6783772880df43041e89e9da59dbbce11de7 Mon Sep 17 00:00:00 2001 From: Asharani Date: Tue, 24 May 2016 14:38:06 +0530 Subject: [PATCH 19/54] Do not log the exception trace when upload fails by user abort action Signed-off-by: Asharani --- .../ui/artifacts/upload/UploadHandler.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java index dc56ff325..28b6c5243 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java @@ -250,7 +250,7 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene // uploadStarted method if (!uploadInterrupted) { if (aborted) { - LOG.error("User aborted file upload"); + LOG.info("User aborted file upload for file : {}", fileName); failureReason = i18n.get("message.uploadedfile.aborted"); interruptFileUpload(); return; @@ -275,7 +275,7 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene @Override public void onProgress(final StreamingProgressEvent event) { if (aborted) { - LOG.error("User aborted the upload"); + LOG.info("User aborted the upload for file : {}", event.getFileName()); failureReason = i18n.get("message.uploadedfile.aborted"); interruptFileStreaming(); return; @@ -300,14 +300,16 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene */ @Override public void streamingFailed(final StreamingErrorEvent event) { - LOG.info("Streaming failed for file :{}", event.getFileName()); if (failureReason == null) { failureReason = event.getException().getMessage(); } eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_STREAMING_FAILED, new UploadFileStatus(fileName, failureReason, selectedSw))); - LOG.info("Streaming failed due to :{}", event.getException()); + if (!aborted) { + LOG.info("Streaming failed for file :{}", event.getFileName()); + LOG.info("Streaming failed due to :{}", event.getException()); + } } /** @@ -317,13 +319,15 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene */ @Override public void uploadFailed(final FailedEvent event) { - LOG.info("Upload failed for file :{}", event.getFilename()); if (failureReason == null) { failureReason = event.getReason().getMessage(); } eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_FAILED, new UploadFileStatus( fileName, failureReason, selectedSwForUpload))); - LOG.info("Upload failed for file :{}", event.getReason()); + if (!aborted) { + LOG.info("Upload failed for file :{}", event.getFilename()); + LOG.info("Upload failed for file :{}", event.getReason()); + } } /** From 1e91643b83556346c029dc7ca8ecdaa8e60f71a6 Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Tue, 24 May 2016 18:04:09 +0200 Subject: [PATCH 20/54] Adapted repo scan --- .../org/eclipse/hawkbit/RepositoryApplicationConfiguration.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java index d5e8db96f..255561be3 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java @@ -42,7 +42,7 @@ import org.springframework.validation.beanvalidation.MethodValidationPostProcess * General configuration for the SP Repository. * */ -@EnableJpaRepositories(basePackages = { "org.eclipse.hawkbit.repository" }) +@EnableJpaRepositories(basePackages = { "org.eclipse.hawkbit.repository.jpa" }) @EnableTransactionManagement @EnableJpaAuditing @EnableAspectJAutoProxy From f2e13b8d22805e3ac73b4f1f84ec578ce0c70856 Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Wed, 25 May 2016 17:43:57 +0200 Subject: [PATCH 21/54] Split into separate maven modules. Signed-off-by: Kai Zimmermann --- hawkbit-autoconfigure/pom.xml | 2 +- hawkbit-ddi-resource/pom.xml | 4 +- hawkbit-dmf-amqp/pom.xml | 4 +- hawkbit-http-security/pom.xml | 2 +- hawkbit-mgmt-resource/pom.xml | 4 +- .../resource/MgmtDistributionSetResource.java | 11 +- .../resource/MgmtSoftwareModuleResource.java | 3 +- .../MgmtDistributionSetResourceTest.java | 12 +- .../hawkbit-repository-api/pom.xml | 40 +++ .../event/AbstractBaseEntityEvent.java | 0 .../event/AbstractEntityBulkEvent.java | 0 .../event/AbstractPropertyChangeEvent.java | 0 .../eventbus/event/ActionCreatedEvent.java | 0 .../event/ActionPropertyChangeEvent.java | 0 ...istributionSetTagAssigmentResultEvent.java | 0 .../DistributionSetTagCreatedBulkEvent.java | 0 .../event/DistributionSetTagDeletedEvent.java | 0 .../event/DistributionSetTagUpdateEvent.java | 0 .../eventbus/event/EntityBulkEvent.java | 0 .../eventbus/event/RolloutChangeEvent.java | 0 .../event/RolloutGroupChangeEvent.java | 0 .../event/RolloutGroupCreatedEvent.java | 0 .../RolloutGroupPropertyChangeEvent.java | 0 .../event/RolloutPropertyChangeEvent.java | 0 .../TargetAssignDistributionSetEvent.java | 0 .../eventbus/event/TargetCreatedEvent.java | 0 .../eventbus/event/TargetInfoUpdateEvent.java | 0 .../event/TargetTagAssigmentResultEvent.java | 0 .../event/TargetTagCreatedBulkEvent.java | 0 .../eventbus/event/TargetTagDeletedEvent.java | 0 .../eventbus/event/TargetTagUpdateEvent.java | 0 .../report/model/AbstractReportSeries.java | 0 .../report/model/DataReportSeries.java | 0 .../report/model/DataReportSeriesItem.java | 0 .../model/InnerOuterDataReportSeries.java | 0 .../report/model/ListReportSeries.java | 0 .../hawkbit/report/model/SeriesTime.java | 0 .../report/model/SystemUsageReport.java | 0 .../hawkbit/report/model/TenantUsage.java | 0 .../repository/ArtifactManagement.java | 0 .../repository/ControllerManagement.java | 0 .../repository/DeploymentManagement.java | 9 +- .../DistributionSetAssignmentResult.java | 0 .../repository/DistributionSetFilter.java | 0 .../repository/DistributionSetManagement.java | 10 +- .../repository/OffsetBasedPageRequest.java | 0 .../hawkbit/repository/ReportManagement.java | 7 +- .../repository/RolloutGroupManagement.java | 10 +- .../hawkbit/repository/RolloutManagement.java | 0 .../hawkbit/repository/RolloutProperties.java | 0 .../hawkbit/repository/RolloutScheduler.java | 0 .../repository/SoftwareManagement.java | 8 +- .../hawkbit/repository/SystemManagement.java | 0 .../hawkbit/repository/TagManagement.java | 0 .../TargetFilterQueryManagement.java | 0 .../hawkbit/repository/TargetManagement.java | 1 - .../repository}/TargetWithActionType.java | 6 +- .../TenantConfigurationManagement.java | 0 .../repository/TenantStatsManagement.java | 0 .../ArtifactDeleteFailedException.java | 0 .../ArtifactUploadFailedException.java | 0 .../CancelActionNotAllowedException.java | 0 .../ConcurrentModificationException.java | 0 ...FailedMissingMandatoryModuleException.java | 0 ...DistributionSetTypeUndefinedException.java | 0 .../EntityAlreadyExistsException.java | 0 .../exception/EntityLockedException.java | 0 .../exception/EntityNotFoundException.java | 0 .../exception/EntityReadOnlyException.java | 0 .../ForceQuitActionNotAllowedException.java | 0 .../GridFSDBFileNotFoundException.java | 0 .../IncompleteDistributionSetException.java | 0 .../InsufficientPermissionException.java | 0 .../exception/InvalidMD5HashException.java | 0 .../exception/InvalidSHA1HashException.java | 0 .../RSQLParameterSyntaxException.java | 2 +- ...SQLParameterUnsupportedFieldException.java | 2 +- .../RolloutIllegalStateException.java | 0 .../exception/TenantNotExistException.java | 0 .../ToManyAttributeEntriesException.java | 0 .../ToManyStatusEntriesException.java | 0 ...ModuleForThisDistributionSetException.java | 0 .../hawkbit/repository/model/Action.java | 0 .../repository/model/ActionStatus.java | 0 .../model/ActionWithStatusCount.java | 48 ++++ .../hawkbit/repository/model/Artifact.java | 0 .../model/AssignedSoftwareModule.java} | 16 +- .../repository/model/AssignmentResult.java | 28 +- .../hawkbit/repository/model/BaseEntity.java | 0 .../repository/model/DistributionSet.java | 0 .../model/DistributionSetIdName.java | 0 .../model/DistributionSetMetadata.java | 0 .../repository/model/DistributionSetTag.java | 0 .../DistributionSetTagAssignmentResult.java | 0 .../repository/model/DistributionSetType.java | 2 - .../repository/model/ExternalArtifact.java | 0 .../model/ExternalArtifactProvider.java | 0 .../repository/model/LocalArtifact.java | 0 .../hawkbit/repository/model/MetaData.java | 0 .../hawkbit/repository/model/NamedEntity.java | 0 .../model/NamedVersionedEntity.java | 0 .../hawkbit/repository/model/PollStatus.java | 0 .../hawkbit/repository/model/Rollout.java | 0 .../repository/model/RolloutGroup.java | 14 +- .../model/RolloutGroupConditionBuilder.java | 0 .../model/RolloutGroupConditions.java | 0 .../repository/model/SoftwareModule.java | 0 .../model/SoftwareModuleIdName.java | 0 .../model/SoftwareModuleMetadata.java | 0 .../repository/model/SoftwareModuleType.java | 0 .../eclipse/hawkbit/repository/model/Tag.java | 0 .../hawkbit/repository/model/Target.java | 61 +++++ .../repository/model/TargetFilterQuery.java | 0 .../repository/model/TargetIdName.java | 0 .../hawkbit/repository/model/TargetInfo.java | 0 .../hawkbit/repository/model/TargetTag.java | 0 .../model/TargetTagAssignmentResult.java | 0 .../repository/model/TargetUpdateStatus.java | 0 .../model/TargetWithActionStatus.java | 2 +- .../model/TenantAwareBaseEntity.java | 7 + .../repository/model/TenantConfiguration.java | 0 .../model/TenantConfigurationValue.java | 0 .../repository/model/TenantMetaData.java | 15 ++ .../model/TotalTargetCountActionStatus.java | 0 .../model/TotalTargetCountStatus.java | 0 .../{ => hawkbit-repository-jpa}/README.md | 0 .../hawkbit-repository-jpa/pom.xml | 238 +++++++++++++++++ .../src/fbExcludeFilter.xml | 0 .../java/org/eclipse/hawkbit/Constants.java | 0 .../MultiTenantJpaTransactionManager.java | 0 .../RepositoryApplicationConfiguration.java | 0 .../ExceptionMappingAspectHandler.java | 0 .../org/eclipse/hawkbit/cache/CacheField.java | 0 .../org/eclipse/hawkbit/cache/CacheKeys.java | 0 .../hawkbit/cache/CacheWriteNotify.java | 0 .../eventbus/CacheFieldEntityListener.java | 0 .../eventbus/EntityChangeEventListener.java | 0 .../EntityPropertyChangeListener.java | 0 .../hawkbit/eventbus}/EventMerger.java | 10 +- ...ansactionCommitDefaultServiceExecutor.java | 0 .../AfterTransactionCommitExecutor.java | 0 .../repository/jpa/ActionRepository.java | 0 .../jpa/ActionStatusRepository.java | 0 .../repository/jpa/BaseEntityRepository.java | 0 .../repository/jpa/DeploymentHelper.java | 0 .../DistributionSetMetadataRepository.java | 0 .../jpa/DistributionSetRepository.java | 0 .../jpa/DistributionSetTagRepository.java | 0 .../jpa/DistributionSetTypeRepository.java | 0 .../jpa/EclipseLinkTargetInfoRepository.java | 0 .../ExternalArtifactProviderRepository.java | 0 .../jpa/ExternalArtifactRepository.java | 0 .../repository/jpa/JpaArtifactManagement.java | 0 .../jpa/JpaControllerManagement.java | 2 +- .../jpa/JpaDeploymentManagement.java | 10 +- .../jpa/JpaDistributionSetManagement.java | 13 +- .../repository/jpa/JpaReportManagement.java | 0 .../jpa/JpaRolloutGroupManagement.java | 0 .../repository/jpa/JpaRolloutManagement.java | 3 +- .../repository/jpa/JpaSoftwareManagement.java | 14 +- .../repository/jpa/JpaSystemManagement.java | 0 .../repository/jpa/JpaTagManagement.java | 0 .../jpa/JpaTargetFilterQueryManagement.java | 0 .../repository/jpa/JpaTargetManagement.java | 0 .../jpa/JpaTenantConfigurationManagement.java | 0 .../jpa/JpaTenantStatsManagement.java | 0 .../jpa/LocalArtifactRepository.java | 0 .../jpa/NoCountPagingRepository.java | 0 .../jpa/RolloutGroupRepository.java | 0 .../repository/jpa/RolloutRepository.java | 0 .../jpa/RolloutTargetGroupRepository.java | 0 .../jpa/SoftwareModuleMetadataRepository.java | 0 .../jpa/SoftwareModuleRepository.java | 0 .../jpa/SoftwareModuleTypeRepository.java | 0 .../jpa/TargetFilterQueryRepository.java | 0 .../repository/jpa/TargetInfoRepository.java | 0 .../repository/jpa/TargetRepository.java | 0 .../repository/jpa/TargetTagRepository.java | 0 .../jpa/TenantConfigurationRepository.java | 0 .../repository/jpa/TenantKeyGenerator.java | 0 .../jpa/TenantMetaDataRepository.java | 0 .../jpa/model/AbstractJpaArtifact.java | 0 .../jpa/model/AbstractJpaBaseEntity.java | 0 .../jpa/model/AbstractJpaMetaData.java | 0 .../jpa/model/AbstractJpaNamedEntity.java | 0 .../AbstractJpaNamedVersionedEntity.java | 0 .../repository/jpa/model/AbstractJpaTag.java | 0 .../AbstractJpaTenantAwareBaseEntity.java | 0 .../jpa/model/DistributionSetTypeElement.java | 0 ...istributionSetTypeElementCompositeKey.java | 0 .../jpa/model/DsMetadataCompositeKey.java | 0 .../repository/jpa/model/JpaAction.java | 0 .../repository/jpa/model/JpaActionStatus.java | 0 .../jpa/model/JpaActionWithStatusCount.java} | 49 ++-- .../jpa/model/JpaDistributionSet.java | 0 .../jpa/model/JpaDistributionSetMetadata.java | 0 .../jpa/model/JpaDistributionSetTag.java | 0 .../jpa/model/JpaDistributionSetType.java | 0 .../jpa/model/JpaExternalArtifact.java | 0 .../model/JpaExternalArtifactProvider.java | 0 .../jpa/model/JpaLocalArtifact.java | 0 .../repository/jpa/model/JpaRollout.java | 0 .../repository/jpa/model/JpaRolloutGroup.java | 4 - .../jpa/model/JpaSoftwareModule.java | 0 .../jpa/model/JpaSoftwareModuleMetadata.java | 0 .../jpa/model/JpaSoftwareModuleType.java | 0 .../repository/jpa/model/JpaTarget.java | 25 +- .../jpa/model/JpaTargetFilterQuery.java | 0 .../repository/jpa/model/JpaTargetInfo.java | 0 .../repository/jpa/model/JpaTargetTag.java | 0 .../jpa/model/JpaTenantConfiguration.java | 0 .../jpa/model/JpaTenantMetaData.java | 0 .../jpa/model/RolloutTargetGroup.java | 0 .../jpa/model/RolloutTargetGroupId.java | 0 .../jpa/model/SwMetadataCompositeKey.java | 0 .../specifications/ActionSpecifications.java | 0 .../DistributionSetSpecification.java | 0 .../DistributionSetTypeSpecification.java | 0 .../SoftwareModuleSpecification.java | 0 .../specifications/SpecificationsBuilder.java | 0 .../TargetFilterQuerySpecification.java | 0 .../specifications/TargetSpecifications.java | 0 .../AfterTransactionCommitExecutorHolder.java | 0 .../model/helper/CacheManagerHolder.java | 0 .../model/helper/EventBusHolder.java | 0 .../model/helper/SecurityChecker.java | 0 .../helper/SecurityTokenGeneratorHolder.java | 0 .../model/helper/SystemManagementHolder.java | 0 .../helper/SystemSecurityContextHolder.java | 0 .../model/helper/TenantAwareHolder.java | 0 .../TenantConfigurationManagementHolder.java | 0 .../repository/rsql/PropertyMapper.java | 0 .../hawkbit/repository/rsql/RSQLUtility.java | 2 + .../condition/PauseRolloutGroupAction.java | 0 .../RolloutGroupActionEvaluator.java | 0 .../RolloutGroupConditionEvaluator.java | 0 ...artNextGroupRolloutGroupSuccessAction.java | 0 .../ThresholdRolloutGroupErrorCondition.java | 0 ...ThresholdRolloutGroupSuccessCondition.java | 0 .../db/migration/H2/V1_0_1__init___H2.sql | 0 ...0__update_target_info_for_message___H2.sql | 0 .../H2/V1_4_0__cascade_delete___H2.sql | 0 .../H2/V1_4_1__cascade_delete___H2.sql | 0 .../H2/V1_5_0__target_filter_query___H2.sql | 0 .../H2/V1_6_0__rollout_management___H2.sql | 0 .../migration/MYSQL/V1_0_1__init___MYSQL.sql | 0 ...update_target_info_for_message___MYSQL.sql | 0 .../MYSQL/V1_4_0__cascade_delete___MYSQL.sql | 0 .../MYSQL/V1_4_1__cascade_delete___MYSQL.sql | 0 .../V1_5_0__target_filter_query___MYSQL.sql | 0 .../V1_6_0__rollout_management___MYSQL.sql | 0 .../hawkbit/AbstractIntegrationTest.java | 0 .../AbstractIntegrationTestWithMongoDB.java | 0 .../eclipse/hawkbit/CIMySqlTestDatabase.java | 0 .../eclipse/hawkbit/FreePortFileWriter.java | 0 .../eclipse/hawkbit/HashGeneratorUtils.java | 0 .../eclipse/hawkbit/LocalH2TestDatabase.java | 0 .../eclipse/hawkbit/MethodSecurityUtil.java | 0 .../hawkbit/RandomGeneratedInputStream.java | 0 .../eclipse/hawkbit/TestConfiguration.java | 0 .../org/eclipse/hawkbit/TestDataUtil.java | 0 .../org/eclipse/hawkbit/Testdatabase.java | 0 .../hawkbit/WithSpringAuthorityRule.java | 0 .../java/org/eclipse/hawkbit/WithUser.java | 0 .../eclipse/hawkbit/cache/CacheKeysTest.java | 0 .../hawkbit/cache/CacheWriteNotifyTest.java | 0 .../CacheFieldEntityListenerTest.java | 0 .../hawkbit/repository/ActionTest.java | 0 .../ArtifactManagementNoMongoDbTest.java | 0 .../repository/ArtifactManagementTest.java | 0 .../repository/ControllerManagementTest.java | 0 .../repository/DeploymentManagementTest.java | 0 .../DistributionSetManagementTest.java | 0 .../repository/ReportManagementTest.java | 0 .../repository/RolloutManagementTest.java | 0 .../repository/SoftwareManagementTest.java | 19 +- .../repository/SystemManagementTest.java | 0 .../hawkbit/repository/TagManagementTest.java | 0 .../TargetFilterQueryManagenmentTest.java | 0 .../TargetManagementSearchTest.java | 0 .../repository/TargetManagementTest.java | 0 .../TenantConfigurationManagementTest.java | 0 .../model/ModelEqualsHashcodeTest.java | 0 .../repository/rsql/RSQLActionFieldsTest.java | 1 + .../rsql/RSQLDistributionSetFieldTest.java | 1 + ...RSQLDistributionSetMetadataFieldsTest.java | 0 .../rsql/RSQLRolloutGroupFields.java | 0 .../rsql/RSQLSoftwareModuleFieldTest.java | 0 .../RSQLSoftwareModuleMetadataFieldsTest.java | 0 .../RSQLSoftwareModuleTypeFieldsTest.java | 0 .../repository/rsql/RSQLTagFieldsTest.java | 0 .../repository/rsql/RSQLTargetFieldTest.java | 1 + .../repository/rsql/RSQLUtilityTest.java | 2 + .../utils/MultipleInvokeHelper.java | 0 .../utils/RepositoryDataGenerator.java | 0 .../repository/utils/SuccessCondition.java | 0 .../tenancy/MultiTenancyEntityTest.java | 0 .../resources/application-test.properties | 0 hawkbit-repository/pom.xml | 239 +----------------- .../hawkbit/repository/model/Target.java | 54 ---- hawkbit-rest-core/pom.xml | 4 +- hawkbit-security-core/pom.xml | 2 +- .../im/authentication/SpPermission.java | 9 + hawkbit-security-integration/pom.xml | 2 +- hawkbit-ui/pom.xml | 7 +- .../hawkbit/ui/components/ProxyTarget.java | 69 ++++- .../smtable/SwModuleBeanQuery.java | 8 +- .../FilterQueryValidation.java | 4 +- .../actionhistory/ActionHistoryTable.java | 6 +- .../hawkbit/ui/utils/HawkbitCommonUtil.java | 1 - 310 files changed, 647 insertions(+), 482 deletions(-) create mode 100644 hawkbit-repository/hawkbit-repository-api/pom.xml rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/eventbus/event/AbstractBaseEntityEvent.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/eventbus/event/AbstractEntityBulkEvent.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/eventbus/event/AbstractPropertyChangeEvent.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/eventbus/event/ActionCreatedEvent.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/eventbus/event/ActionPropertyChangeEvent.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/eventbus/event/DistributionSetTagAssigmentResultEvent.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/eventbus/event/DistributionSetTagCreatedBulkEvent.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/eventbus/event/DistributionSetTagDeletedEvent.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/eventbus/event/DistributionSetTagUpdateEvent.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/eventbus/event/EntityBulkEvent.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/eventbus/event/RolloutChangeEvent.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/eventbus/event/RolloutGroupChangeEvent.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/eventbus/event/RolloutGroupCreatedEvent.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/eventbus/event/RolloutGroupPropertyChangeEvent.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/eventbus/event/RolloutPropertyChangeEvent.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetAssignDistributionSetEvent.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetCreatedEvent.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetInfoUpdateEvent.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetTagAssigmentResultEvent.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetTagCreatedBulkEvent.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetTagDeletedEvent.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetTagUpdateEvent.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/report/model/AbstractReportSeries.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/report/model/DataReportSeries.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/report/model/DataReportSeriesItem.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/report/model/InnerOuterDataReportSeries.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/report/model/ListReportSeries.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/report/model/SeriesTime.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/report/model/SystemUsageReport.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/report/model/TenantUsage.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/ArtifactManagement.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java (97%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/DistributionSetAssignmentResult.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/DistributionSetFilter.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java (97%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/OffsetBasedPageRequest.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/ReportManagement.java (99%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupManagement.java (96%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/RolloutProperties.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/RolloutScheduler.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java (98%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/TagManagement.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagement.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java (99%) rename hawkbit-repository/{src/main/java/org/eclipse/hawkbit/repository/jpa => hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository}/TargetWithActionType.java (88%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/TenantConfigurationManagement.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/TenantStatsManagement.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/exception/ArtifactDeleteFailedException.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/exception/ArtifactUploadFailedException.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/exception/CancelActionNotAllowedException.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/exception/ConcurrentModificationException.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/exception/DistributionSetCreationFailedMissingMandatoryModuleException.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/exception/DistributionSetTypeUndefinedException.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/exception/EntityAlreadyExistsException.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/exception/EntityLockedException.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/exception/EntityNotFoundException.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/exception/EntityReadOnlyException.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/exception/ForceQuitActionNotAllowedException.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/exception/GridFSDBFileNotFoundException.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/exception/IncompleteDistributionSetException.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/exception/InsufficientPermissionException.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/exception/InvalidMD5HashException.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/exception/InvalidSHA1HashException.java (100%) rename hawkbit-repository/{src/main/java/org/eclipse/hawkbit/repository/rsql => hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception}/RSQLParameterSyntaxException.java (97%) rename hawkbit-repository/{src/main/java/org/eclipse/hawkbit/repository/rsql => hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception}/RSQLParameterUnsupportedFieldException.java (97%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/exception/RolloutIllegalStateException.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/exception/TenantNotExistException.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/exception/ToManyAttributeEntriesException.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/exception/ToManyStatusEntriesException.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/exception/UnsupportedSoftwareModuleForThisDistributionSetException.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/model/Action.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/model/ActionStatus.java (100%) create mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/ActionWithStatusCount.java rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/model/Artifact.java (100%) rename hawkbit-repository/{src/main/java/org/eclipse/hawkbit/repository/model/CustomSoftwareModule.java => hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/AssignedSoftwareModule.java} (79%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/model/AssignmentResult.java (83%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/model/BaseEntity.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSet.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetIdName.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetMetadata.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTag.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTagAssignmentResult.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetType.java (98%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifact.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifactProvider.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/model/LocalArtifact.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/model/MetaData.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/model/NamedEntity.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/model/NamedVersionedEntity.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/model/PollStatus.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/model/Rollout.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/model/RolloutGroup.java (95%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/model/RolloutGroupConditionBuilder.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/model/RolloutGroupConditions.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModule.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleIdName.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleMetadata.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleType.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/model/Tag.java (100%) create mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Target.java rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/model/TargetFilterQuery.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/model/TargetIdName.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/model/TargetInfo.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/model/TargetTag.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/model/TargetTagAssignmentResult.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/model/TargetUpdateStatus.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/model/TargetWithActionStatus.java (96%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/model/TenantAwareBaseEntity.java (80%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/model/TenantConfiguration.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/model/TenantConfigurationValue.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/model/TenantMetaData.java (64%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/model/TotalTargetCountActionStatus.java (100%) rename hawkbit-repository/{ => hawkbit-repository-api}/src/main/java/org/eclipse/hawkbit/repository/model/TotalTargetCountStatus.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/README.md (100%) create mode 100644 hawkbit-repository/hawkbit-repository-jpa/pom.xml rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/fbExcludeFilter.xml (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/Constants.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/MultiTenantJpaTransactionManager.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/aspects/ExceptionMappingAspectHandler.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/cache/CacheField.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/cache/CacheKeys.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/cache/CacheWriteNotify.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/eventbus/CacheFieldEntityListener.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/eventbus/EntityChangeEventListener.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/eventbus/EntityPropertyChangeListener.java (100%) rename hawkbit-repository/{src/main/java/org/eclipse/hawkbit/eventbus/event => hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/eventbus}/EventMerger.java (92%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/executor/AfterTransactionCommitDefaultServiceExecutor.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/executor/AfterTransactionCommitExecutor.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/ActionRepository.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/ActionStatusRepository.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/BaseEntityRepository.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/DeploymentHelper.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetMetadataRepository.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetRepository.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetTagRepository.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetTypeRepository.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/EclipseLinkTargetInfoRepository.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/ExternalArtifactProviderRepository.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/ExternalArtifactRepository.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaArtifactManagement.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java (99%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java (98%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java (98%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaReportManagement.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutGroupManagement.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java (99%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java (98%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTagManagement.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetFilterQueryManagement.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetManagement.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTenantConfigurationManagement.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTenantStatsManagement.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/LocalArtifactRepository.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/NoCountPagingRepository.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/RolloutGroupRepository.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/RolloutRepository.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/RolloutTargetGroupRepository.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleMetadataRepository.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleRepository.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleTypeRepository.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetFilterQueryRepository.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetInfoRepository.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetRepository.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetTagRepository.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/TenantConfigurationRepository.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/TenantKeyGenerator.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/TenantMetaDataRepository.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaArtifact.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaBaseEntity.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaMetaData.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaNamedEntity.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaNamedVersionedEntity.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaTag.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaTenantAwareBaseEntity.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/model/DistributionSetTypeElement.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/model/DistributionSetTypeElementCompositeKey.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/model/DsMetadataCompositeKey.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaAction.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaActionStatus.java (100%) rename hawkbit-repository/{src/main/java/org/eclipse/hawkbit/repository/model/ActionWithStatusCount.java => hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaActionWithStatusCount.java} (73%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSet.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetMetadata.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetTag.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetType.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaExternalArtifact.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaExternalArtifactProvider.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaLocalArtifact.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRollout.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRolloutGroup.java (99%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModule.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModuleMetadata.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModuleType.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTarget.java (90%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetFilterQuery.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetInfo.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetTag.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTenantConfiguration.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTenantMetaData.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/model/RolloutTargetGroup.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/model/RolloutTargetGroupId.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/model/SwMetadataCompositeKey.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/ActionSpecifications.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/DistributionSetSpecification.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/DistributionSetTypeSpecification.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/SoftwareModuleSpecification.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/SpecificationsBuilder.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/TargetFilterQuerySpecification.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/TargetSpecifications.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/model/helper/AfterTransactionCommitExecutorHolder.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/model/helper/CacheManagerHolder.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/model/helper/EventBusHolder.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/model/helper/SecurityChecker.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/model/helper/SecurityTokenGeneratorHolder.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/model/helper/SystemManagementHolder.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/model/helper/SystemSecurityContextHolder.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/model/helper/TenantAwareHolder.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/model/helper/TenantConfigurationManagementHolder.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/rsql/PropertyMapper.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/repository/rsql/RSQLUtility.java (99%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/rollout/condition/PauseRolloutGroupAction.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/rollout/condition/RolloutGroupActionEvaluator.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/rollout/condition/RolloutGroupConditionEvaluator.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/rollout/condition/StartNextGroupRolloutGroupSuccessAction.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/rollout/condition/ThresholdRolloutGroupErrorCondition.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/java/org/eclipse/hawkbit/rollout/condition/ThresholdRolloutGroupSuccessCondition.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/resources/db/migration/H2/V1_0_1__init___H2.sql (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/resources/db/migration/H2/V1_2_0__update_target_info_for_message___H2.sql (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/resources/db/migration/H2/V1_4_0__cascade_delete___H2.sql (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/resources/db/migration/H2/V1_4_1__cascade_delete___H2.sql (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/resources/db/migration/H2/V1_5_0__target_filter_query___H2.sql (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/resources/db/migration/H2/V1_6_0__rollout_management___H2.sql (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/resources/db/migration/MYSQL/V1_0_1__init___MYSQL.sql (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/resources/db/migration/MYSQL/V1_2_0__update_target_info_for_message___MYSQL.sql (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/resources/db/migration/MYSQL/V1_4_0__cascade_delete___MYSQL.sql (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/resources/db/migration/MYSQL/V1_4_1__cascade_delete___MYSQL.sql (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/resources/db/migration/MYSQL/V1_5_0__target_filter_query___MYSQL.sql (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/main/resources/db/migration/MYSQL/V1_6_0__rollout_management___MYSQL.sql (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/test/java/org/eclipse/hawkbit/AbstractIntegrationTest.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/test/java/org/eclipse/hawkbit/AbstractIntegrationTestWithMongoDB.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/test/java/org/eclipse/hawkbit/CIMySqlTestDatabase.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/test/java/org/eclipse/hawkbit/FreePortFileWriter.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/test/java/org/eclipse/hawkbit/HashGeneratorUtils.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/test/java/org/eclipse/hawkbit/LocalH2TestDatabase.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/test/java/org/eclipse/hawkbit/MethodSecurityUtil.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/test/java/org/eclipse/hawkbit/RandomGeneratedInputStream.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/test/java/org/eclipse/hawkbit/TestConfiguration.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/test/java/org/eclipse/hawkbit/TestDataUtil.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/test/java/org/eclipse/hawkbit/Testdatabase.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/test/java/org/eclipse/hawkbit/WithSpringAuthorityRule.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/test/java/org/eclipse/hawkbit/WithUser.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/test/java/org/eclipse/hawkbit/cache/CacheKeysTest.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/test/java/org/eclipse/hawkbit/cache/CacheWriteNotifyTest.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/test/java/org/eclipse/hawkbit/eventbus/CacheFieldEntityListenerTest.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/test/java/org/eclipse/hawkbit/repository/ActionTest.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/test/java/org/eclipse/hawkbit/repository/ArtifactManagementNoMongoDbTest.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/test/java/org/eclipse/hawkbit/repository/ArtifactManagementTest.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/test/java/org/eclipse/hawkbit/repository/ControllerManagementTest.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/test/java/org/eclipse/hawkbit/repository/DeploymentManagementTest.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/test/java/org/eclipse/hawkbit/repository/DistributionSetManagementTest.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/test/java/org/eclipse/hawkbit/repository/ReportManagementTest.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/test/java/org/eclipse/hawkbit/repository/RolloutManagementTest.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/test/java/org/eclipse/hawkbit/repository/SoftwareManagementTest.java (98%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/test/java/org/eclipse/hawkbit/repository/SystemManagementTest.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/test/java/org/eclipse/hawkbit/repository/TagManagementTest.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/test/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagenmentTest.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/test/java/org/eclipse/hawkbit/repository/TargetManagementSearchTest.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/test/java/org/eclipse/hawkbit/repository/TargetManagementTest.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/test/java/org/eclipse/hawkbit/repository/TenantConfigurationManagementTest.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/test/java/org/eclipse/hawkbit/repository/model/ModelEqualsHashcodeTest.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLActionFieldsTest.java (97%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLDistributionSetFieldTest.java (98%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLDistributionSetMetadataFieldsTest.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLRolloutGroupFields.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLSoftwareModuleFieldTest.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLSoftwareModuleMetadataFieldsTest.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLSoftwareModuleTypeFieldsTest.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLTagFieldsTest.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLTargetFieldTest.java (98%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLUtilityTest.java (98%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/test/java/org/eclipse/hawkbit/repository/utils/MultipleInvokeHelper.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/test/java/org/eclipse/hawkbit/repository/utils/RepositoryDataGenerator.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/test/java/org/eclipse/hawkbit/repository/utils/SuccessCondition.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/test/java/org/eclipse/hawkbit/tenancy/MultiTenancyEntityTest.java (100%) rename hawkbit-repository/{ => hawkbit-repository-jpa}/src/test/resources/application-test.properties (100%) delete mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Target.java diff --git a/hawkbit-autoconfigure/pom.xml b/hawkbit-autoconfigure/pom.xml index 7ad0e0911..044e6aece 100644 --- a/hawkbit-autoconfigure/pom.xml +++ b/hawkbit-autoconfigure/pom.xml @@ -46,7 +46,7 @@ org.eclipse.hawkbit - hawkbit-repository + hawkbit-repository-jpa ${project.version} true diff --git a/hawkbit-ddi-resource/pom.xml b/hawkbit-ddi-resource/pom.xml index f3eb5c2c7..177494912 100644 --- a/hawkbit-ddi-resource/pom.xml +++ b/hawkbit-ddi-resource/pom.xml @@ -38,7 +38,7 @@ org.eclipse.hawkbit - hawkbit-repository + hawkbit-repository-jpa ${project.version} @@ -93,7 +93,7 @@ org.eclipse.hawkbit - hawkbit-repository + hawkbit-repository-jpa ${project.version} tests test diff --git a/hawkbit-dmf-amqp/pom.xml b/hawkbit-dmf-amqp/pom.xml index 127103b91..d1cb0cb30 100644 --- a/hawkbit-dmf-amqp/pom.xml +++ b/hawkbit-dmf-amqp/pom.xml @@ -23,7 +23,7 @@ org.eclipse.hawkbit - hawkbit-repository + hawkbit-repository-jpa ${project.version} @@ -90,7 +90,7 @@ org.eclipse.hawkbit - hawkbit-repository + hawkbit-repository-jpa ${project.version} tests diff --git a/hawkbit-http-security/pom.xml b/hawkbit-http-security/pom.xml index a9b8a4080..03a9b6678 100644 --- a/hawkbit-http-security/pom.xml +++ b/hawkbit-http-security/pom.xml @@ -22,7 +22,7 @@ org.eclipse.hawkbit - hawkbit-repository + hawkbit-repository-jpa ${project.version} diff --git a/hawkbit-mgmt-resource/pom.xml b/hawkbit-mgmt-resource/pom.xml index 160299651..2279172e9 100644 --- a/hawkbit-mgmt-resource/pom.xml +++ b/hawkbit-mgmt-resource/pom.xml @@ -23,7 +23,7 @@ org.eclipse.hawkbit - hawkbit-repository + hawkbit-repository-jpa ${project.version} @@ -92,7 +92,7 @@ org.eclipse.hawkbit - hawkbit-repository + hawkbit-repository-jpa ${project.version} tests test diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java index a048226ec..ae4972610 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java @@ -32,9 +32,8 @@ import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.repository.TargetManagement; +import org.eclipse.hawkbit.repository.TargetWithActionType; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; -import org.eclipse.hawkbit.repository.jpa.TargetWithActionType; -import org.eclipse.hawkbit.repository.jpa.model.DsMetadataCompositeKey; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetMetadata; import org.eclipse.hawkbit.repository.model.SoftwareModule; @@ -94,7 +93,8 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi { if (rsqlParam != null) { findDsPage = this.distributionSetManagement.findDistributionSetsAll(rsqlParam, pageable, false); } else { - findDsPage = this.distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageable, false, null); + findDsPage = this.distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageable, false, + null); } final List rest = MgmtDistributionSetMapper.toResponseFromDsList(findDsPage.getContent()); @@ -273,8 +273,7 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi { // check if distribution set exists otherwise throw exception // immediately final DistributionSet ds = findDistributionSetWithExceptionIfNotFound(distributionSetId); - final DistributionSetMetadata findOne = this.distributionSetManagement - .findOne(new DsMetadataCompositeKey(ds, metadataKey)); + final DistributionSetMetadata findOne = this.distributionSetManagement.findOne(ds, metadataKey); return ResponseEntity. ok(MgmtDistributionSetMapper.toResponseDsMetadata(findOne)); } @@ -295,7 +294,7 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi { // check if distribution set exists otherwise throw exception // immediately final DistributionSet ds = findDistributionSetWithExceptionIfNotFound(distributionSetId); - this.distributionSetManagement.deleteDistributionSetMetadata(new DsMetadataCompositeKey(ds, metadataKey)); + this.distributionSetManagement.deleteDistributionSetMetadata(ds, metadataKey); return ResponseEntity.ok().build(); } diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java index c01295828..aeaffa013 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java @@ -23,7 +23,6 @@ import org.eclipse.hawkbit.repository.ArtifactManagement; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; -import org.eclipse.hawkbit.repository.jpa.model.SwMetadataCompositeKey; import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata; @@ -246,7 +245,7 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi { public ResponseEntity deleteMetadata(@PathVariable("softwareModuleId") final Long softwareModuleId, @PathVariable("metadataKey") final String metadataKey) { final SoftwareModule sw = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null); - softwareManagement.deleteSoftwareModuleMetadata(new SwMetadataCompositeKey(sw, metadataKey)); + softwareManagement.deleteSoftwareModuleMetadata(sw, metadataKey); return ResponseEntity.ok().build(); } diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java index daa010166..63e09fb98 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java @@ -30,7 +30,6 @@ import org.eclipse.hawkbit.TestDataUtil; import org.eclipse.hawkbit.WithUser; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; -import org.eclipse.hawkbit.repository.jpa.model.DsMetadataCompositeKey; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetMetadata; @@ -685,10 +684,8 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest .andExpect(jsonPath("[1]key", equalTo(knownKey2))) .andExpect(jsonPath("[1]value", equalTo(knownValue2))); - final DistributionSetMetadata metaKey1 = distributionSetManagement - .findOne(new DsMetadataCompositeKey(testDS, knownKey1)); - final DistributionSetMetadata metaKey2 = distributionSetManagement - .findOne(new DsMetadataCompositeKey(testDS, knownKey2)); + final DistributionSetMetadata metaKey1 = distributionSetManagement.findOne(testDS, knownKey1); + final DistributionSetMetadata metaKey2 = distributionSetManagement.findOne(testDS, knownKey2); assertThat(metaKey1.getValue()).isEqualTo(knownValue1); assertThat(metaKey2.getValue()).isEqualTo(knownValue2); @@ -715,8 +712,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("key", equalTo(knownKey))).andExpect(jsonPath("value", equalTo(updateValue))); - final DistributionSetMetadata assertDS = distributionSetManagement - .findOne(new DsMetadataCompositeKey(testDS, knownKey)); + final DistributionSetMetadata assertDS = distributionSetManagement.findOne(testDS, knownKey); assertThat(assertDS.getValue()).isEqualTo(updateValue); } @@ -737,7 +733,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); try { - distributionSetManagement.findOne(new DsMetadataCompositeKey(testDS, knownKey)); + distributionSetManagement.findOne(testDS, knownKey); fail("expected EntityNotFoundException but didn't throw"); } catch (final EntityNotFoundException e) { // ok as expected diff --git a/hawkbit-repository/hawkbit-repository-api/pom.xml b/hawkbit-repository/hawkbit-repository-api/pom.xml new file mode 100644 index 000000000..ab8ab75db --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-api/pom.xml @@ -0,0 +1,40 @@ + + + 4.0.0 + + org.eclipse.hawkbit + hawkbit-repository + 0.2.0-SNAPSHOT + + hawkbit-repository-api + hawkBit :: Repository API + + + + org.eclipse.hawkbit + hawkbit-security-core + ${project.version} + + + javax.validation + validation-api + + + org.hibernate + hibernate-validator + + + org.springframework.hateoas + spring-hateoas + + + \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/AbstractBaseEntityEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/AbstractBaseEntityEvent.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/AbstractBaseEntityEvent.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/AbstractBaseEntityEvent.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/AbstractEntityBulkEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/AbstractEntityBulkEvent.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/AbstractEntityBulkEvent.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/AbstractEntityBulkEvent.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/AbstractPropertyChangeEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/AbstractPropertyChangeEvent.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/AbstractPropertyChangeEvent.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/AbstractPropertyChangeEvent.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/ActionCreatedEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/ActionCreatedEvent.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/ActionCreatedEvent.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/ActionCreatedEvent.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/ActionPropertyChangeEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/ActionPropertyChangeEvent.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/ActionPropertyChangeEvent.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/ActionPropertyChangeEvent.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/DistributionSetTagAssigmentResultEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/DistributionSetTagAssigmentResultEvent.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/DistributionSetTagAssigmentResultEvent.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/DistributionSetTagAssigmentResultEvent.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/DistributionSetTagCreatedBulkEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/DistributionSetTagCreatedBulkEvent.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/DistributionSetTagCreatedBulkEvent.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/DistributionSetTagCreatedBulkEvent.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/DistributionSetTagDeletedEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/DistributionSetTagDeletedEvent.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/DistributionSetTagDeletedEvent.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/DistributionSetTagDeletedEvent.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/DistributionSetTagUpdateEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/DistributionSetTagUpdateEvent.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/DistributionSetTagUpdateEvent.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/DistributionSetTagUpdateEvent.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/EntityBulkEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/EntityBulkEvent.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/EntityBulkEvent.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/EntityBulkEvent.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/RolloutChangeEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/RolloutChangeEvent.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/RolloutChangeEvent.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/RolloutChangeEvent.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/RolloutGroupChangeEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/RolloutGroupChangeEvent.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/RolloutGroupChangeEvent.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/RolloutGroupChangeEvent.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/RolloutGroupCreatedEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/RolloutGroupCreatedEvent.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/RolloutGroupCreatedEvent.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/RolloutGroupCreatedEvent.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/RolloutGroupPropertyChangeEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/RolloutGroupPropertyChangeEvent.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/RolloutGroupPropertyChangeEvent.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/RolloutGroupPropertyChangeEvent.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/RolloutPropertyChangeEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/RolloutPropertyChangeEvent.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/RolloutPropertyChangeEvent.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/RolloutPropertyChangeEvent.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetAssignDistributionSetEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetAssignDistributionSetEvent.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetAssignDistributionSetEvent.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetAssignDistributionSetEvent.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetCreatedEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetCreatedEvent.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetCreatedEvent.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetCreatedEvent.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetInfoUpdateEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetInfoUpdateEvent.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetInfoUpdateEvent.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetInfoUpdateEvent.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetTagAssigmentResultEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetTagAssigmentResultEvent.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetTagAssigmentResultEvent.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetTagAssigmentResultEvent.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetTagCreatedBulkEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetTagCreatedBulkEvent.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetTagCreatedBulkEvent.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetTagCreatedBulkEvent.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetTagDeletedEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetTagDeletedEvent.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetTagDeletedEvent.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetTagDeletedEvent.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetTagUpdateEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetTagUpdateEvent.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetTagUpdateEvent.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetTagUpdateEvent.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/report/model/AbstractReportSeries.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/report/model/AbstractReportSeries.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/report/model/AbstractReportSeries.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/report/model/AbstractReportSeries.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/report/model/DataReportSeries.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/report/model/DataReportSeries.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/report/model/DataReportSeries.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/report/model/DataReportSeries.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/report/model/DataReportSeriesItem.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/report/model/DataReportSeriesItem.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/report/model/DataReportSeriesItem.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/report/model/DataReportSeriesItem.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/report/model/InnerOuterDataReportSeries.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/report/model/InnerOuterDataReportSeries.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/report/model/InnerOuterDataReportSeries.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/report/model/InnerOuterDataReportSeries.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/report/model/ListReportSeries.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/report/model/ListReportSeries.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/report/model/ListReportSeries.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/report/model/ListReportSeries.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/report/model/SeriesTime.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/report/model/SeriesTime.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/report/model/SeriesTime.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/report/model/SeriesTime.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/report/model/SystemUsageReport.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/report/model/SystemUsageReport.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/report/model/SystemUsageReport.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/report/model/SystemUsageReport.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/report/model/TenantUsage.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/report/model/TenantUsage.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/report/model/TenantUsage.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/report/model/TenantUsage.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ArtifactManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ArtifactManagement.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ArtifactManagement.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ArtifactManagement.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java similarity index 97% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java index 42843b495..b6efec9b0 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java @@ -16,7 +16,6 @@ import javax.validation.constraints.NotNull; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; import org.eclipse.hawkbit.repository.exception.CancelActionNotAllowedException; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; -import org.eclipse.hawkbit.repository.jpa.TargetWithActionType; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.ActionType; import org.eclipse.hawkbit.repository.model.ActionStatus; @@ -101,8 +100,6 @@ public interface DeploymentManagement { DistributionSetAssignmentResult assignDistributionSet(@NotNull Long dsID, @NotEmpty Collection targets); - // TODO document: why are rollouts in the signature ? can all the parameters - // be null or the list empty? /** * method assigns the {@link DistributionSet} to all {@link Target}s by * their IDs with a specific {@link ActionType} and {@code forcetime}. @@ -190,7 +187,6 @@ public interface DeploymentManagement { @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) Long countActionsByTarget(@NotNull Target target); - // TODO: validate parameters /** * Creates an action entry into the action repository. In case of existing * scheduled actions the scheduled actions gets canceled. A scheduled action @@ -210,8 +206,9 @@ public interface DeploymentManagement { * the roll out group for this action */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET) - void createScheduledAction(Collection targets, DistributionSet distributionSet, ActionType actionType, - long forcedTime, Rollout rollout, RolloutGroup rolloutGroup); + void createScheduledAction(@NotEmpty Collection targets, @NotNull DistributionSet distributionSet, + @NotNull ActionType actionType, Long forcedTime, @NotNull Rollout rollout, + @NotNull RolloutGroup rolloutGroup); /** * Get the {@link Action} entity for given actionId. diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetAssignmentResult.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DistributionSetAssignmentResult.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetAssignmentResult.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DistributionSetAssignmentResult.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetFilter.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DistributionSetFilter.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetFilter.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DistributionSetFilter.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java similarity index 97% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java index 8316508d9..dcb135e62 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java @@ -12,7 +12,6 @@ import java.util.Collection; import java.util.List; import java.util.Set; -import javax.persistence.Entity; import javax.validation.constraints.NotNull; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; @@ -21,8 +20,6 @@ import org.eclipse.hawkbit.repository.exception.DistributionSetCreationFailedMis import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.exception.EntityReadOnlyException; -import org.eclipse.hawkbit.repository.jpa.model.DistributionSetTypeElement; -import org.eclipse.hawkbit.repository.jpa.model.DsMetadataCompositeKey; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetMetadata; @@ -37,8 +34,6 @@ import org.hibernate.validator.constraints.NotEmpty; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.transaction.annotation.Isolation; -import org.springframework.transaction.annotation.Transactional; /** * Management service for {@link DistributionSet}s. @@ -176,7 +171,6 @@ public interface DistributionSetManagement { * @return created {@link Entity} */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) - @Transactional(isolation = Isolation.READ_UNCOMMITTED) List createDistributionSetTypes(@NotNull Collection types); /** @@ -215,7 +209,7 @@ public interface DistributionSetManagement { * the ID of the distribution set meta data to delete */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - void deleteDistributionSetMetadata(@NotNull DsMetadataCompositeKey id); + void deleteDistributionSetMetadata(@NotNull final DistributionSet distributionSet, @NotNull final String key); /** * Deletes or mark as delete in case the type is in use. @@ -456,7 +450,7 @@ public interface DistributionSetManagement { * in case the meta data does not exists for the given key */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - DistributionSetMetadata findOne(@NotNull DsMetadataCompositeKey id); + DistributionSetMetadata findOne(@NotNull DistributionSet distributionSet, @NotNull String key); /** * Generates an empty {@link DistributionSet} without persisting it. diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/OffsetBasedPageRequest.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/OffsetBasedPageRequest.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/OffsetBasedPageRequest.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/OffsetBasedPageRequest.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ReportManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ReportManagement.java similarity index 99% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ReportManagement.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ReportManagement.java index 933f2ad9e..fca145908 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ReportManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ReportManagement.java @@ -67,6 +67,10 @@ public interface ReportManagement { private static final long serialVersionUID = 1L; private static final PerMonth PER_MONTH = new PerMonth(); + private DateTypes() { + // Utility class + } + /** * @return PerMonth */ @@ -74,9 +78,6 @@ public interface ReportManagement { return PER_MONTH; } - private DateTypes() { - - } } /** diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupManagement.java similarity index 96% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupManagement.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupManagement.java index bf58e3053..ae1cc5882 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupManagement.java @@ -18,7 +18,6 @@ import org.eclipse.hawkbit.repository.model.TargetWithActionStatus; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; -import org.springframework.data.jpa.domain.Specification; import org.springframework.security.access.prepost.PreAuthorize; /** @@ -40,7 +39,6 @@ public interface RolloutGroupManagement { @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) Page findAllRolloutGroupsWithDetailedStatus(@NotNull Long rolloutId, @NotNull Pageable pageable); - // TODO discuss: target read perm missing? /** * * Find all targets with action status by rollout group id. The action @@ -55,7 +53,7 @@ public interface RolloutGroupManagement { * rollout group * @return {@link TargetWithActionStatus} target with action status */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ_AND_TARGET_READ) Page findAllTargetsWithActionStatus(@NotNull PageRequest pageRequest, @NotNull RolloutGroup rolloutGroup); @@ -100,7 +98,6 @@ public interface RolloutGroupManagement { @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) Page findRolloutGroupsByRolloutId(@NotNull Long rolloutId, @NotNull Pageable pageable); - // TODO discuss: target read perm missing? /** * Get targets of specified rollout group. * @@ -111,10 +108,9 @@ public interface RolloutGroupManagement { * * @return Page list of targets of a rollout group */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ_AND_TARGET_READ) Page findRolloutGroupTargets(@NotNull RolloutGroup rolloutGroup, @NotNull Pageable page); - // TODO discuss: target read perm missing? /** * Get targets of specified rollout group. * @@ -127,7 +123,7 @@ public interface RolloutGroupManagement { * * @return Page list of targets of a rollout group */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ_AND_TARGET_READ) Page findRolloutGroupTargets(@NotNull RolloutGroup rolloutGroup, @NotNull String rsqlParam, @NotNull Pageable pageable); diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutProperties.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutProperties.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutProperties.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutProperties.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutScheduler.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutScheduler.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutScheduler.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutScheduler.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java similarity index 98% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java index a586c0bfb..465cb50ea 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java @@ -11,14 +11,12 @@ package org.eclipse.hawkbit.repository; import java.util.Collection; import java.util.List; -import javax.persistence.Entity; import javax.validation.constraints.NotNull; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; -import org.eclipse.hawkbit.repository.jpa.model.SwMetadataCompositeKey; -import org.eclipse.hawkbit.repository.model.CustomSoftwareModule; +import org.eclipse.hawkbit.repository.model.AssignedSoftwareModule; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata; @@ -159,7 +157,7 @@ public interface SoftwareManagement { * the ID of the software module meta data to delete */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - void deleteSoftwareModuleMetadata(@NotNull SwMetadataCompositeKey id); + void deleteSoftwareModuleMetadata(@NotNull SoftwareModule softwareModule, @NotNull String key); /** * Deletes {@link SoftwareModule}s which is any if the given ids. @@ -312,7 +310,7 @@ public interface SoftwareManagement { * @return the page of found {@link SoftwareModule} */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Slice findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc( + Slice findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc( @NotNull Pageable pageable, @NotNull Long orderByDistributionId, String searchText, SoftwareModuleType type); diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TagManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TagManagement.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TagManagement.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TagManagement.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagement.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagement.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagement.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java similarity index 99% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java index f8e5e8a91..ccf8c6712 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java @@ -12,7 +12,6 @@ import java.net.URI; import java.util.Collection; import java.util.List; -import javax.persistence.Entity; import javax.validation.constraints.NotNull; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetWithActionType.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetWithActionType.java similarity index 88% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetWithActionType.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetWithActionType.java index a2c0a7d8f..579b4ef0d 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetWithActionType.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetWithActionType.java @@ -6,14 +6,14 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.jpa; +package org.eclipse.hawkbit.repository; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.ActionType; +import org.eclipse.hawkbit.repository.model.Target; /** - * A custom JPA database return value object with the proper constructor so JPA - * is able to parse the result-set directly into this object. + * A custom view on {@link Target} with {@link ActionType}. * * * diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantConfigurationManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TenantConfigurationManagement.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantConfigurationManagement.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TenantConfigurationManagement.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantStatsManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TenantStatsManagement.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantStatsManagement.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TenantStatsManagement.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/exception/ArtifactDeleteFailedException.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/ArtifactDeleteFailedException.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/exception/ArtifactDeleteFailedException.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/ArtifactDeleteFailedException.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/exception/ArtifactUploadFailedException.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/ArtifactUploadFailedException.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/exception/ArtifactUploadFailedException.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/ArtifactUploadFailedException.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/exception/CancelActionNotAllowedException.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/CancelActionNotAllowedException.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/exception/CancelActionNotAllowedException.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/CancelActionNotAllowedException.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/exception/ConcurrentModificationException.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/ConcurrentModificationException.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/exception/ConcurrentModificationException.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/ConcurrentModificationException.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/exception/DistributionSetCreationFailedMissingMandatoryModuleException.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/DistributionSetCreationFailedMissingMandatoryModuleException.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/exception/DistributionSetCreationFailedMissingMandatoryModuleException.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/DistributionSetCreationFailedMissingMandatoryModuleException.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/exception/DistributionSetTypeUndefinedException.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/DistributionSetTypeUndefinedException.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/exception/DistributionSetTypeUndefinedException.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/DistributionSetTypeUndefinedException.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/exception/EntityAlreadyExistsException.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/EntityAlreadyExistsException.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/exception/EntityAlreadyExistsException.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/EntityAlreadyExistsException.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/exception/EntityLockedException.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/EntityLockedException.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/exception/EntityLockedException.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/EntityLockedException.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/exception/EntityNotFoundException.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/EntityNotFoundException.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/exception/EntityNotFoundException.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/EntityNotFoundException.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/exception/EntityReadOnlyException.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/EntityReadOnlyException.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/exception/EntityReadOnlyException.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/EntityReadOnlyException.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/exception/ForceQuitActionNotAllowedException.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/ForceQuitActionNotAllowedException.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/exception/ForceQuitActionNotAllowedException.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/ForceQuitActionNotAllowedException.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/exception/GridFSDBFileNotFoundException.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/GridFSDBFileNotFoundException.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/exception/GridFSDBFileNotFoundException.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/GridFSDBFileNotFoundException.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/exception/IncompleteDistributionSetException.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/IncompleteDistributionSetException.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/exception/IncompleteDistributionSetException.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/IncompleteDistributionSetException.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/exception/InsufficientPermissionException.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/InsufficientPermissionException.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/exception/InsufficientPermissionException.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/InsufficientPermissionException.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/exception/InvalidMD5HashException.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/InvalidMD5HashException.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/exception/InvalidMD5HashException.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/InvalidMD5HashException.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/exception/InvalidSHA1HashException.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/InvalidSHA1HashException.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/exception/InvalidSHA1HashException.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/InvalidSHA1HashException.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/rsql/RSQLParameterSyntaxException.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/RSQLParameterSyntaxException.java similarity index 97% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/rsql/RSQLParameterSyntaxException.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/RSQLParameterSyntaxException.java index aa43f1bbb..268ab02ba 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/rsql/RSQLParameterSyntaxException.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/RSQLParameterSyntaxException.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.rsql; +package org.eclipse.hawkbit.repository.exception; import org.eclipse.hawkbit.exception.SpServerError; import org.eclipse.hawkbit.exception.SpServerRtException; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/rsql/RSQLParameterUnsupportedFieldException.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/RSQLParameterUnsupportedFieldException.java similarity index 97% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/rsql/RSQLParameterUnsupportedFieldException.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/RSQLParameterUnsupportedFieldException.java index e95368acb..df58ecc8b 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/rsql/RSQLParameterUnsupportedFieldException.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/RSQLParameterUnsupportedFieldException.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.rsql; +package org.eclipse.hawkbit.repository.exception; import org.eclipse.hawkbit.exception.SpServerError; import org.eclipse.hawkbit.exception.SpServerRtException; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/exception/RolloutIllegalStateException.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/RolloutIllegalStateException.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/exception/RolloutIllegalStateException.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/RolloutIllegalStateException.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/exception/TenantNotExistException.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/TenantNotExistException.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/exception/TenantNotExistException.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/TenantNotExistException.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/exception/ToManyAttributeEntriesException.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/ToManyAttributeEntriesException.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/exception/ToManyAttributeEntriesException.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/ToManyAttributeEntriesException.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/exception/ToManyStatusEntriesException.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/ToManyStatusEntriesException.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/exception/ToManyStatusEntriesException.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/ToManyStatusEntriesException.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/exception/UnsupportedSoftwareModuleForThisDistributionSetException.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/UnsupportedSoftwareModuleForThisDistributionSetException.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/exception/UnsupportedSoftwareModuleForThisDistributionSetException.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/UnsupportedSoftwareModuleForThisDistributionSetException.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Action.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Action.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Action.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Action.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ActionStatus.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/ActionStatus.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ActionStatus.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/ActionStatus.java diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/ActionWithStatusCount.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/ActionWithStatusCount.java new file mode 100644 index 000000000..c497783e2 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/ActionWithStatusCount.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.model; + +/** + * View for querying {@link Action} include the count of the action's + * {@link ActionStatus} entries. + * + */ +public interface ActionWithStatusCount { + + /** + * @return {@link Action} + */ + Action getAction(); + + /** + * @return {@link DistributionSet} ID. + */ + Long getDsId(); + + /** + * @return {@link DistributionSet} name. + */ + String getDsName(); + + /** + * @return {@link DistributionSet} version. + */ + String getDsVersion(); + + /** + * @return number of {@link ActionStatus} entries + */ + Long getActionStatusCount(); + + /** + * @return name of the {@link Rollout}. + */ + String getRolloutName(); + +} \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Artifact.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Artifact.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Artifact.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Artifact.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/CustomSoftwareModule.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/AssignedSoftwareModule.java similarity index 79% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/CustomSoftwareModule.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/AssignedSoftwareModule.java index 34aa8345a..b23b3f0fe 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/CustomSoftwareModule.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/AssignedSoftwareModule.java @@ -14,7 +14,7 @@ import java.io.Serializable; * Use to display software modules for the selected distribution. * */ -public class CustomSoftwareModule implements Serializable { +public class AssignedSoftwareModule implements Serializable { private static final long serialVersionUID = 6144585781451168439L; @@ -31,22 +31,28 @@ public class CustomSoftwareModule implements Serializable { * as true if the software module is assigned and false if not * assigned. */ - public CustomSoftwareModule(final SoftwareModule softwareModule, final boolean assigned) { + public AssignedSoftwareModule(final SoftwareModule softwareModule, final boolean assigned) { this.softwareModule = softwareModule; this.assigned = assigned; } + /** + * @return {@link SoftwareModule} + */ public SoftwareModule getSoftwareModule() { return softwareModule; } + /** + * @return true if assigned + */ public boolean isAssigned() { return assigned; } @Override public String toString() { - return "CustomSoftwareModule [softwareModule=" + softwareModule + ", assigned=" + assigned + "]"; + return "AssignedSoftwareModule [softwareModule=" + softwareModule + ", assigned=" + assigned + "]"; } @Override @@ -66,10 +72,10 @@ public class CustomSoftwareModule implements Serializable { if (obj == null) { return false; } - if (!(obj instanceof CustomSoftwareModule)) { + if (!(obj instanceof AssignedSoftwareModule)) { return false; } - final CustomSoftwareModule other = (CustomSoftwareModule) obj; + final AssignedSoftwareModule other = (AssignedSoftwareModule) obj; if (assigned != other.assigned) { return false; } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/AssignmentResult.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/AssignmentResult.java similarity index 83% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/AssignmentResult.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/AssignmentResult.java index 2dea94f33..043386ed1 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/AssignmentResult.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/AssignmentResult.java @@ -19,7 +19,6 @@ public class AssignmentResult { private final int total; private final int assigned; private final int alreadyAssigned; - private final int unassigned; private final List assignedEntity; private final List unassignedEntity; @@ -47,28 +46,45 @@ public class AssignmentResult { this.assignedEntity = assignedEntity; this.unassignedEntity = unassignedEntity; } - + + /** + * @return number of newly assigned elements. + */ public int getAssigned() { return assigned; } - + + /** + * @return total number (assigned and already assigned). + */ public int getTotal() { return total; } - + + /** + * @return number of already assigned/ignored elements. + */ public int getAlreadyAssigned() { return alreadyAssigned; } - + /** + * @return number of unsassigned elements + */ public int getUnassigned() { return unassigned; } + /** + * @return {@link List} of assigned entity. + */ public List getAssignedEntity() { return assignedEntity; } - + + /** + * @return {@link List} of unassigned entity. + */ public List getUnassignedEntity() { return unassignedEntity; } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/BaseEntity.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/BaseEntity.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/BaseEntity.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/BaseEntity.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSet.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSet.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSet.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSet.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetIdName.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetIdName.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetIdName.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetIdName.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetMetadata.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetMetadata.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetMetadata.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetMetadata.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTag.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTag.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTag.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTag.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTagAssignmentResult.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTagAssignmentResult.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTagAssignmentResult.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTagAssignmentResult.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetType.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetType.java similarity index 98% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetType.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetType.java index 07c63ee89..14683b1b1 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetType.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetType.java @@ -10,8 +10,6 @@ package org.eclipse.hawkbit.repository.model; import java.util.Set; -import org.eclipse.hawkbit.repository.jpa.model.DistributionSetTypeElement; - /** * A {@link DistributionSetType} is an abstract definition for * {@link DistributionSet} that defines what {@link SoftwareModule}s can be diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifact.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifact.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifact.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifact.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifactProvider.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifactProvider.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifactProvider.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifactProvider.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/LocalArtifact.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/LocalArtifact.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/LocalArtifact.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/LocalArtifact.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/MetaData.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/MetaData.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/MetaData.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/MetaData.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/NamedEntity.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/NamedEntity.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/NamedEntity.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/NamedEntity.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/NamedVersionedEntity.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/NamedVersionedEntity.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/NamedVersionedEntity.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/NamedVersionedEntity.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/PollStatus.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/PollStatus.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/PollStatus.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/PollStatus.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Rollout.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Rollout.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Rollout.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Rollout.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/RolloutGroup.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/RolloutGroup.java similarity index 95% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/RolloutGroup.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/RolloutGroup.java index 3f383d605..e4d9f5bb7 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/RolloutGroup.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/RolloutGroup.java @@ -8,6 +8,12 @@ */ package org.eclipse.hawkbit.repository.model; +/** + * The core functionality of a {@link Rollout} is the cascading processing of + * (sub) deployment groups. The group defines under which conditions the + * following group is processed. + * + */ public interface RolloutGroup extends NamedEntity { Rollout getRollout(); @@ -20,8 +26,6 @@ public interface RolloutGroup extends NamedEntity { RolloutGroup getParent(); - void setParent(RolloutGroup parent); - RolloutGroupSuccessCondition getSuccessCondition(); void setSuccessCondition(RolloutGroupSuccessCondition finishCondition); @@ -52,12 +56,6 @@ public interface RolloutGroup extends NamedEntity { long getTotalTargets(); - void setTotalTargets(long totalTargets); - - void setSuccessAction(RolloutGroupSuccessAction successAction); - - void setSuccessActionExp(String successActionExp); - /** * @return the totalTargetCountStatus */ diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/RolloutGroupConditionBuilder.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/RolloutGroupConditionBuilder.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/RolloutGroupConditionBuilder.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/RolloutGroupConditionBuilder.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/RolloutGroupConditions.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/RolloutGroupConditions.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/RolloutGroupConditions.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/RolloutGroupConditions.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModule.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModule.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModule.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModule.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleIdName.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleIdName.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleIdName.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleIdName.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleMetadata.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleMetadata.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleMetadata.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleMetadata.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleType.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleType.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleType.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleType.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Tag.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Tag.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Tag.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Tag.java diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Target.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Target.java new file mode 100644 index 000000000..56ab89ad3 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Target.java @@ -0,0 +1,61 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.model; + +import java.util.List; +import java.util.Set; + +/** + *

+ * The {@link Target} is the target of all provisioning operations. It contains + * the currently installed {@link DistributionSet} (i.e. current state). In + * addition it holds the target {@link DistributionSet} that has to be + * provisioned next (i.e. target state). + *

+ */ +public interface Target extends NamedEntity { + + /** + * @return currently assigned {@link DistributionSet}. + */ + DistributionSet getAssignedDistributionSet(); + + /** + * @return business identifier of the {@link Target} + */ + String getControllerId(); + + /** + * @return assigned {@link TargetTag}s. + */ + Set getTags(); + + /** + * @return {@link Action} history of the {@link Target}. + */ + List getActions(); + + /** + * @return {@link TargetIdName} view of the {@link Target}. + */ + default TargetIdName getTargetIdName() { + return new TargetIdName(getId(), getControllerId(), getName()); + } + + /** + * @return the targetInfo object + */ + TargetInfo getTargetInfo(); + + /** + * @return the securityToken + */ + String getSecurityToken(); + +} diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetFilterQuery.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetFilterQuery.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetFilterQuery.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetFilterQuery.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetIdName.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetIdName.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetIdName.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetIdName.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetInfo.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetInfo.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetInfo.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetInfo.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetTag.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetTag.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetTag.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetTag.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetTagAssignmentResult.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetTagAssignmentResult.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetTagAssignmentResult.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetTagAssignmentResult.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetUpdateStatus.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetUpdateStatus.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetUpdateStatus.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetUpdateStatus.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetWithActionStatus.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetWithActionStatus.java similarity index 96% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetWithActionStatus.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetWithActionStatus.java index 987b993e1..f775a3879 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TargetWithActionStatus.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetWithActionStatus.java @@ -12,7 +12,7 @@ import org.eclipse.hawkbit.repository.model.Action.Status; /** * - * Rollout - Target with action status. + * Target with action status. * */ public class TargetWithActionStatus { diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TenantAwareBaseEntity.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TenantAwareBaseEntity.java similarity index 80% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TenantAwareBaseEntity.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TenantAwareBaseEntity.java index 4b7bf861e..f79306d75 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TenantAwareBaseEntity.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TenantAwareBaseEntity.java @@ -8,8 +8,15 @@ */ package org.eclipse.hawkbit.repository.model; +/** + * {@link BaseEntity} that distinguishes between tenants. + * + */ public interface TenantAwareBaseEntity extends BaseEntity { + /** + * @return tenant name + */ String getTenant(); } \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TenantConfiguration.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TenantConfiguration.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TenantConfiguration.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TenantConfiguration.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TenantConfigurationValue.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TenantConfigurationValue.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TenantConfigurationValue.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TenantConfigurationValue.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TenantMetaData.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TenantMetaData.java similarity index 64% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TenantMetaData.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TenantMetaData.java index 38f9ddbb3..23f81ae6f 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TenantMetaData.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TenantMetaData.java @@ -8,12 +8,27 @@ */ package org.eclipse.hawkbit.repository.model; +/** + * MetaData of a tenant account. + * + */ public interface TenantMetaData extends BaseEntity { + /** + * @return default {@link DistributionSetType}. + */ DistributionSetType getDefaultDsType(); + /** + * @param defaultDsType + * that is used of none is selected for a new + * {@link DistributionSet}. + */ void setDefaultDsType(DistributionSetType defaultDsType); + /** + * @return tenant name + */ String getTenant(); } \ No newline at end of file diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TotalTargetCountActionStatus.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TotalTargetCountActionStatus.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TotalTargetCountActionStatus.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TotalTargetCountActionStatus.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TotalTargetCountStatus.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TotalTargetCountStatus.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TotalTargetCountStatus.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TotalTargetCountStatus.java diff --git a/hawkbit-repository/README.md b/hawkbit-repository/hawkbit-repository-jpa/README.md similarity index 100% rename from hawkbit-repository/README.md rename to hawkbit-repository/hawkbit-repository-jpa/README.md diff --git a/hawkbit-repository/hawkbit-repository-jpa/pom.xml b/hawkbit-repository/hawkbit-repository-jpa/pom.xml new file mode 100644 index 000000000..d84b36778 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-jpa/pom.xml @@ -0,0 +1,238 @@ + + + 4.0.0 + + org.eclipse.hawkbit + 0.2.0-SNAPSHOT + hawkbit-repository + + hawkbit-repository-jpa + hawkBit :: Repository JPA Implementation + + + + + com.ethlo.eclipselink.tools + http://ethlo.com/maven + + + + + + com.ethlo.eclipselink.tools + http://ethlo.com/maven + + + + + + + + com.fasterxml.jackson.core + jackson-core + + + com.fasterxml.jackson.core + jackson-databind + + + + + org.eclipse.hawkbit + hawkbit-repository-api + ${project.version} + + + org.eclipse.hawkbit + hawkbit-artifact-repository-mongo + ${project.version} + + + com.google.guava + guava + + + net._01001111 + jlorem + + + org.springframework.boot + spring-boot + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.eclipse.persistence + org.eclipse.persistence.jpa + + + org.springframework.security + spring-security-core + + + org.flywaydb + flyway-core + + + org.springframework.boot + spring-boot-configuration-processor + true + + + + + com.h2database + h2 + test + + + org.mariadb.jdbc + mariadb-java-client + test + + + javax.el + javax.el-api + test + + + org.springframework + spring-context-support + test + + + ru.yandex.qatools.allure + allure-junit-adaptor + test + + + org.springframework.data + spring-data-rest-webmvc + test + + + org.springframework.security + spring-security-aspects + test + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework + spring-test + test + + + org.easytesting + fest-assert-core + test + + + org.easytesting + fest-assert + test + + + de.flapdoodle.embed + de.flapdoodle.embed.mongo + test + + + org.springframework.security + spring-security-config + test + + + org.springframework.security + spring-security-web + test + + + cz.jirutka.rsql + rsql-parser + + + + + + + + org.bsc.maven + maven-processor-plugin + + + process + + process + + generate-sources + + + org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor + + + + + + + org.hibernate + hibernate-jpamodelgen + ${hibernate.version} + + + + + + com.ethlo.persistence.tools + eclipselink-maven-plugin + 2.6.2 + + + process-classes + + weave + + + + + + org.eclipse.persistence + org.eclipse.persistence.jpa + ${eclipselink.version} + + + org.javassist + javassist + 3.20.0-GA + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + test-jar + + + + + + + diff --git a/hawkbit-repository/src/fbExcludeFilter.xml b/hawkbit-repository/hawkbit-repository-jpa/src/fbExcludeFilter.xml similarity index 100% rename from hawkbit-repository/src/fbExcludeFilter.xml rename to hawkbit-repository/hawkbit-repository-jpa/src/fbExcludeFilter.xml diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/Constants.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/Constants.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/Constants.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/Constants.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/MultiTenantJpaTransactionManager.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/MultiTenantJpaTransactionManager.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/MultiTenantJpaTransactionManager.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/MultiTenantJpaTransactionManager.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/aspects/ExceptionMappingAspectHandler.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/aspects/ExceptionMappingAspectHandler.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/aspects/ExceptionMappingAspectHandler.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/aspects/ExceptionMappingAspectHandler.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/cache/CacheField.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/cache/CacheField.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/cache/CacheField.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/cache/CacheField.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/cache/CacheKeys.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/cache/CacheKeys.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/cache/CacheKeys.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/cache/CacheKeys.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/cache/CacheWriteNotify.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/cache/CacheWriteNotify.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/cache/CacheWriteNotify.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/cache/CacheWriteNotify.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/CacheFieldEntityListener.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/eventbus/CacheFieldEntityListener.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/CacheFieldEntityListener.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/eventbus/CacheFieldEntityListener.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/EntityChangeEventListener.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/eventbus/EntityChangeEventListener.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/EntityChangeEventListener.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/eventbus/EntityChangeEventListener.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/EntityPropertyChangeListener.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/eventbus/EntityPropertyChangeListener.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/EntityPropertyChangeListener.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/eventbus/EntityPropertyChangeListener.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/EventMerger.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/eventbus/EventMerger.java similarity index 92% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/EventMerger.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/eventbus/EventMerger.java index fe4cf4b34..b4ebdb743 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/EventMerger.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/eventbus/EventMerger.java @@ -6,13 +6,21 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.eventbus.event; +package org.eclipse.hawkbit.eventbus; import java.util.Iterator; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import org.eclipse.hawkbit.eventbus.EventSubscriber; +import org.eclipse.hawkbit.eventbus.event.ActionCreatedEvent; +import org.eclipse.hawkbit.eventbus.event.ActionPropertyChangeEvent; +import org.eclipse.hawkbit.eventbus.event.Event; +import org.eclipse.hawkbit.eventbus.event.RolloutChangeEvent; +import org.eclipse.hawkbit.eventbus.event.RolloutGroupChangeEvent; +import org.eclipse.hawkbit.eventbus.event.RolloutGroupCreatedEvent; +import org.eclipse.hawkbit.eventbus.event.RolloutGroupPropertyChangeEvent; +import org.eclipse.hawkbit.eventbus.event.RolloutPropertyChangeEvent; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.RolloutGroup; import org.springframework.beans.factory.annotation.Autowired; diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/executor/AfterTransactionCommitDefaultServiceExecutor.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/executor/AfterTransactionCommitDefaultServiceExecutor.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/executor/AfterTransactionCommitDefaultServiceExecutor.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/executor/AfterTransactionCommitDefaultServiceExecutor.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/executor/AfterTransactionCommitExecutor.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/executor/AfterTransactionCommitExecutor.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/executor/AfterTransactionCommitExecutor.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/executor/AfterTransactionCommitExecutor.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/ActionRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/ActionRepository.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/ActionRepository.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/ActionRepository.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/ActionStatusRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/ActionStatusRepository.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/ActionStatusRepository.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/ActionStatusRepository.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/BaseEntityRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/BaseEntityRepository.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/BaseEntityRepository.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/BaseEntityRepository.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/DeploymentHelper.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/DeploymentHelper.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/DeploymentHelper.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/DeploymentHelper.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetMetadataRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetMetadataRepository.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetMetadataRepository.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetMetadataRepository.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetRepository.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetRepository.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetRepository.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetTagRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetTagRepository.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetTagRepository.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetTagRepository.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetTypeRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetTypeRepository.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetTypeRepository.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/DistributionSetTypeRepository.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/EclipseLinkTargetInfoRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/EclipseLinkTargetInfoRepository.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/EclipseLinkTargetInfoRepository.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/EclipseLinkTargetInfoRepository.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/ExternalArtifactProviderRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/ExternalArtifactProviderRepository.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/ExternalArtifactProviderRepository.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/ExternalArtifactProviderRepository.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/ExternalArtifactRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/ExternalArtifactRepository.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/ExternalArtifactRepository.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/ExternalArtifactRepository.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaArtifactManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaArtifactManagement.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaArtifactManagement.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaArtifactManagement.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java similarity index 99% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java index af7f6371d..9f692e5f6 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java @@ -287,7 +287,7 @@ public class JpaControllerManagement implements ControllerManagement { return actionRepository.save(mergedAction); } - private void handleErrorOnAction(final JpaAction mergedAction, final Target mergedTarget) { + private void handleErrorOnAction(final JpaAction mergedAction, final JpaTarget mergedTarget) { mergedAction.setActive(false); mergedAction.setStatus(Status.ERROR); mergedTarget.setAssignedDistributionSet(null); diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java similarity index 98% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java index 999a5a5c9..d869dd758 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java @@ -37,12 +37,14 @@ import org.eclipse.hawkbit.repository.ActionFields; import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.DistributionSetAssignmentResult; import org.eclipse.hawkbit.repository.TargetManagement; +import org.eclipse.hawkbit.repository.TargetWithActionType; import org.eclipse.hawkbit.repository.exception.CancelActionNotAllowedException; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.exception.ForceQuitActionNotAllowedException; import org.eclipse.hawkbit.repository.exception.IncompleteDistributionSetException; import org.eclipse.hawkbit.repository.jpa.model.JpaAction; import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus; +import org.eclipse.hawkbit.repository.jpa.model.JpaActionWithStatusCount; import org.eclipse.hawkbit.repository.jpa.model.JpaAction_; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet_; @@ -479,7 +481,7 @@ public class JpaDeploymentManagement implements DeploymentManagement { @Modifying @Transactional(isolation = Isolation.READ_COMMITTED) public void createScheduledAction(final Collection targets, final DistributionSet distributionSet, - final ActionType actionType, final long forcedTime, final Rollout rollout, + final ActionType actionType, final Long forcedTime, final Rollout rollout, final RolloutGroup rolloutGroup) { // cancel all current scheduled actions for this target. E.g. an action // is already scheduled and a next action is created then cancel the @@ -576,14 +578,14 @@ public class JpaDeploymentManagement implements DeploymentManagement { @Override public List findActionsWithStatusCountByTargetOrderByIdDesc(final Target target) { final CriteriaBuilder cb = entityManager.getCriteriaBuilder(); - final CriteriaQuery query = cb.createQuery(ActionWithStatusCount.class); + final CriteriaQuery query = cb.createQuery(JpaActionWithStatusCount.class); final Root actionRoot = query.from(JpaAction.class); final ListJoin actionStatusJoin = actionRoot.join(JpaAction_.actionStatus, JoinType.LEFT); final Join actionDsJoin = actionRoot.join(JpaAction_.distributionSet); final Join actionRolloutJoin = actionRoot.join(JpaAction_.rollout, JoinType.LEFT); - final CriteriaQuery multiselect = query.distinct(true).multiselect( + final CriteriaQuery multiselect = query.distinct(true).multiselect( actionRoot.get(JpaAction_.id), actionRoot.get(JpaAction_.actionType), actionRoot.get(JpaAction_.active), actionRoot.get(JpaAction_.forcedTime), actionRoot.get(JpaAction_.status), actionRoot.get(JpaAction_.createdAt), actionRoot.get(JpaAction_.lastModifiedAt), @@ -593,7 +595,7 @@ public class JpaDeploymentManagement implements DeploymentManagement { multiselect.where(cb.equal(actionRoot.get(JpaAction_.target), target)); multiselect.orderBy(cb.desc(actionRoot.get(JpaAction_.id))); multiselect.groupBy(actionRoot.get(JpaAction_.id)); - return entityManager.createQuery(multiselect).getResultList(); + return new ArrayList<>(entityManager.createQuery(multiselect).getResultList()); } @Override diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java similarity index 98% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java index e17c737e7..66bb9037d 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java @@ -508,7 +508,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { final JpaDistributionSetMetadata metadata = (JpaDistributionSetMetadata) md; // check if exists otherwise throw entity not found exception - findOne(metadata.getId()); + findOne(metadata.getDistributionSet(), metadata.getKey()); // touch it to update the lock revision because we are modifying the // DS indirectly entityManager.merge((JpaDistributionSet) metadata.getDistributionSet()).setLastModifiedAt(0L); @@ -518,8 +518,8 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { @Override @Transactional(isolation = Isolation.READ_UNCOMMITTED) @Modifying - public void deleteDistributionSetMetadata(final DsMetadataCompositeKey id) { - distributionSetMetadataRepository.delete(id); + public void deleteDistributionSetMetadata(final DistributionSet distributionSet, final String key) { + distributionSetMetadataRepository.delete(new DsMetadataCompositeKey(distributionSet, key)); } @Override @@ -555,10 +555,11 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { } @Override - public DistributionSetMetadata findOne(final DsMetadataCompositeKey id) { - final DistributionSetMetadata findOne = distributionSetMetadataRepository.findOne(id); + public DistributionSetMetadata findOne(final DistributionSet distributionSet, final String key) { + final DistributionSetMetadata findOne = distributionSetMetadataRepository + .findOne(new DsMetadataCompositeKey(distributionSet, key)); if (findOne == null) { - throw new EntityNotFoundException("Metadata with key '" + id.getKey() + "' does not exist"); + throw new EntityNotFoundException("Metadata with key '" + key + "' does not exist"); } return findOne; } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaReportManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaReportManagement.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaReportManagement.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaReportManagement.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutGroupManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutGroupManagement.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutGroupManagement.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutGroupManagement.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java similarity index 99% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java index 744c863ba..6a5b534d1 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java @@ -24,6 +24,7 @@ import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.RolloutFields; import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.TargetManagement; +import org.eclipse.hawkbit.repository.TargetWithActionType; import org.eclipse.hawkbit.repository.exception.RolloutIllegalStateException; import org.eclipse.hawkbit.repository.jpa.model.JpaRollout; import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup; @@ -266,7 +267,7 @@ public class JpaRolloutManagement implements RolloutManagement { group.setErrorAction(conditions.getErrorAction()); group.setErrorActionExp(conditions.getErrorActionExp()); - final RolloutGroup savedGroup = rolloutGroupRepository.save(group); + final JpaRolloutGroup savedGroup = rolloutGroupRepository.save(group); final Slice targetGroup = targetManagement.findTargetsAll(savedRollout.getTargetFilterQuery(), new OffsetBasedPageRequest(pageIndex, groupSize, new Sort(Direction.ASC, "id"))); diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java similarity index 98% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java index b98ff0754..05a38d428 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java @@ -43,7 +43,7 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule_; import org.eclipse.hawkbit.repository.jpa.model.SwMetadataCompositeKey; import org.eclipse.hawkbit.repository.jpa.specifications.SoftwareModuleSpecification; import org.eclipse.hawkbit.repository.jpa.specifications.SpecificationsBuilder; -import org.eclipse.hawkbit.repository.model.CustomSoftwareModule; +import org.eclipse.hawkbit.repository.model.AssignedSoftwareModule; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; @@ -371,12 +371,12 @@ public class JpaSoftwareManagement implements SoftwareManagement { } @Override - public Slice findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc( + public Slice findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc( final Pageable pageable, final Long orderByDistributionId, final String searchText, final SoftwareModuleType ty) { final JpaSoftwareModuleType type = (JpaSoftwareModuleType) ty; - final List resultList = new ArrayList<>(); + final List resultList = new ArrayList<>(); final int pageSize = pageable.getPageSize(); final CriteriaBuilder cb = entityManager.getCriteriaBuilder(); @@ -405,7 +405,7 @@ public class JpaSoftwareManagement implements SoftwareManagement { if (pageable.getOffset() < assignedSoftwareModules.size()) { assignedSoftwareModules .subList(pageable.getOffset(), Math.min(assignedSoftwareModules.size(), pageable.getPageSize())) - .forEach(sw -> resultList.add(new CustomSoftwareModule(sw, true))); + .forEach(sw -> resultList.add(new AssignedSoftwareModule(sw, true))); } if (assignedSoftwareModules.size() >= pageSize) { @@ -434,7 +434,7 @@ public class JpaSoftwareManagement implements SoftwareManagement { .setFirstResult(Math.max(0, pageable.getOffset() - assignedSoftwareModules.size())) .setMaxResults(pageSize).getResultList(); // map result - unassignedSoftwareModules.forEach(sw -> resultList.add(new CustomSoftwareModule(sw, false))); + unassignedSoftwareModules.forEach(sw -> resultList.add(new AssignedSoftwareModule(sw, false))); return new SliceImpl<>(resultList); } @@ -597,8 +597,8 @@ public class JpaSoftwareManagement implements SoftwareManagement { @Override @Transactional(isolation = Isolation.READ_UNCOMMITTED) @Modifying - public void deleteSoftwareModuleMetadata(final SwMetadataCompositeKey id) { - softwareModuleMetadataRepository.delete(id); + public void deleteSoftwareModuleMetadata(final SoftwareModule softwareModule, final String key) { + softwareModuleMetadataRepository.delete(new SwMetadataCompositeKey(softwareModule, key)); } @Override diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTagManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTagManagement.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTagManagement.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTagManagement.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetFilterQueryManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetFilterQueryManagement.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetFilterQueryManagement.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetFilterQueryManagement.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetManagement.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetManagement.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetManagement.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTenantConfigurationManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTenantConfigurationManagement.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTenantConfigurationManagement.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTenantConfigurationManagement.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTenantStatsManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTenantStatsManagement.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTenantStatsManagement.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTenantStatsManagement.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/LocalArtifactRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/LocalArtifactRepository.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/LocalArtifactRepository.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/LocalArtifactRepository.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/NoCountPagingRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/NoCountPagingRepository.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/NoCountPagingRepository.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/NoCountPagingRepository.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/RolloutGroupRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/RolloutGroupRepository.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/RolloutGroupRepository.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/RolloutGroupRepository.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/RolloutRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/RolloutRepository.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/RolloutRepository.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/RolloutRepository.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/RolloutTargetGroupRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/RolloutTargetGroupRepository.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/RolloutTargetGroupRepository.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/RolloutTargetGroupRepository.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleMetadataRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleMetadataRepository.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleMetadataRepository.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleMetadataRepository.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleRepository.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleRepository.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleRepository.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleTypeRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleTypeRepository.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleTypeRepository.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleTypeRepository.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetFilterQueryRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetFilterQueryRepository.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetFilterQueryRepository.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetFilterQueryRepository.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetInfoRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetInfoRepository.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetInfoRepository.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetInfoRepository.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetRepository.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetRepository.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetRepository.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetTagRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetTagRepository.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetTagRepository.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetTagRepository.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TenantConfigurationRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/TenantConfigurationRepository.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TenantConfigurationRepository.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/TenantConfigurationRepository.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TenantKeyGenerator.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/TenantKeyGenerator.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TenantKeyGenerator.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/TenantKeyGenerator.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TenantMetaDataRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/TenantMetaDataRepository.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/TenantMetaDataRepository.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/TenantMetaDataRepository.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaArtifact.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaArtifact.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaArtifact.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaArtifact.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaBaseEntity.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaBaseEntity.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaBaseEntity.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaBaseEntity.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaMetaData.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaMetaData.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaMetaData.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaMetaData.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaNamedEntity.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaNamedEntity.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaNamedEntity.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaNamedEntity.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaNamedVersionedEntity.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaNamedVersionedEntity.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaNamedVersionedEntity.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaNamedVersionedEntity.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaTag.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaTag.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaTag.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaTag.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaTenantAwareBaseEntity.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaTenantAwareBaseEntity.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaTenantAwareBaseEntity.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaTenantAwareBaseEntity.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/DistributionSetTypeElement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/DistributionSetTypeElement.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/DistributionSetTypeElement.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/DistributionSetTypeElement.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/DistributionSetTypeElementCompositeKey.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/DistributionSetTypeElementCompositeKey.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/DistributionSetTypeElementCompositeKey.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/DistributionSetTypeElementCompositeKey.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/DsMetadataCompositeKey.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/DsMetadataCompositeKey.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/DsMetadataCompositeKey.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/DsMetadataCompositeKey.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaAction.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaAction.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaAction.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaAction.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaActionStatus.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaActionStatus.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaActionStatus.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaActionStatus.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ActionWithStatusCount.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaActionWithStatusCount.java similarity index 73% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ActionWithStatusCount.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaActionWithStatusCount.java index 6bc1efa56..32b01cbe2 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ActionWithStatusCount.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaActionWithStatusCount.java @@ -6,25 +6,21 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.model; +package org.eclipse.hawkbit.repository.jpa.model; -import org.eclipse.hawkbit.repository.jpa.model.JpaAction; +import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.ActionType; import org.eclipse.hawkbit.repository.model.Action.Status; +import org.eclipse.hawkbit.repository.model.ActionStatus; +import org.eclipse.hawkbit.repository.model.ActionWithStatusCount; /** * Custom JPA Model for querying {@link Action} include the count of the * action's {@link ActionStatus}. * */ -// TODO: create interface -public class ActionWithStatusCount { +public class JpaActionWithStatusCount implements ActionWithStatusCount { private final Long actionStatusCount; - private final boolean actionActive; - private final long actionForceTime; - private final Status actionStatus; - private final Long actionCreatedAt; - private final Long actionLastModifiedAt; private final Long dsId; private final String dsName; private final String dsVersion; @@ -60,16 +56,12 @@ public class ActionWithStatusCount { * @param rolloutName * the rollout name */ - - public ActionWithStatusCount(final Long actionId, final ActionType actionType, final boolean active, + // Exception squid:S00107 - needed this way for JPA to fill the view + @SuppressWarnings("squid:S00107") + public JpaActionWithStatusCount(final Long actionId, final ActionType actionType, final boolean active, final long forcedTime, final Status status, final Long actionCreatedAt, final Long actionLastModifiedAt, final Long dsId, final String dsName, final String dsVersion, final Long actionStatusCount, final String rolloutName) { - actionActive = active; - actionForceTime = forcedTime; - actionStatus = status; - this.actionCreatedAt = actionCreatedAt; - this.actionLastModifiedAt = actionLastModifiedAt; this.dsId = dsId; this.dsName = dsName; this.dsVersion = dsVersion; @@ -78,42 +70,43 @@ public class ActionWithStatusCount { action = new JpaAction(); action.setActionType(actionType); - action.setActive(actionActive); - action.setForcedTime(actionForceTime); - action.setStatus(actionStatus); + action.setActive(active); + action.setForcedTime(forcedTime); + action.setStatus(status); action.setId(actionId); + action.setActionType(actionType); + action.setCreatedAt(actionCreatedAt); + action.setLastModifiedAt(actionLastModifiedAt); + } + @Override public Action getAction() { return action; } - public Long getActionCreatedAt() { - return actionCreatedAt; - } - - public Long getActionLastModifiedAt() { - return actionLastModifiedAt; - } - + @Override public Long getDsId() { return dsId; } + @Override public String getDsName() { return dsName; } + @Override public String getDsVersion() { return dsVersion; } + @Override public Long getActionStatusCount() { return actionStatusCount; } + @Override public String getRolloutName() { return rolloutName; } - } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSet.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSet.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSet.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSet.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetMetadata.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetMetadata.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetMetadata.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetMetadata.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetTag.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetTag.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetTag.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetTag.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetType.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetType.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetType.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetType.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaExternalArtifact.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaExternalArtifact.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaExternalArtifact.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaExternalArtifact.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaExternalArtifactProvider.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaExternalArtifactProvider.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaExternalArtifactProvider.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaExternalArtifactProvider.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaLocalArtifact.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaLocalArtifact.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaLocalArtifact.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaLocalArtifact.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRollout.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRollout.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRollout.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRollout.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRolloutGroup.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRolloutGroup.java similarity index 99% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRolloutGroup.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRolloutGroup.java index ed2620ae6..6be29bb9c 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRolloutGroup.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRolloutGroup.java @@ -114,7 +114,6 @@ public class JpaRolloutGroup extends AbstractJpaNamedEntity implements RolloutGr return parent; } - @Override public void setParent(final RolloutGroup parent) { this.parent = (JpaRolloutGroup) parent; } @@ -194,17 +193,14 @@ public class JpaRolloutGroup extends AbstractJpaNamedEntity implements RolloutGr return totalTargets; } - @Override public void setTotalTargets(final long totalTargets) { this.totalTargets = totalTargets; } - @Override public void setSuccessAction(final RolloutGroupSuccessAction successAction) { this.successAction = successAction; } - @Override public void setSuccessActionExp(final String successActionExp) { this.successActionExp = successActionExp; } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModule.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModule.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModule.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModule.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModuleMetadata.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModuleMetadata.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModuleMetadata.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModuleMetadata.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModuleType.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModuleType.java similarity index 100% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModuleType.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModuleType.java diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTarget.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTarget.java similarity index 90% rename from hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTarget.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTarget.java index 4540b68d3..f89eeb184 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTarget.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTarget.java @@ -39,7 +39,6 @@ import org.eclipse.hawkbit.im.authentication.SpPermission; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Target; -import org.eclipse.hawkbit.repository.model.TargetIdName; import org.eclipse.hawkbit.repository.model.TargetInfo; import org.eclipse.hawkbit.repository.model.TargetTag; import org.eclipse.hawkbit.repository.model.helper.SecurityChecker; @@ -49,19 +48,7 @@ import org.eclipse.persistence.annotations.CascadeOnDelete; import org.springframework.data.domain.Persistable; /** - *

- * The {@link Target} is the target of all provisioning operations. It contains - * the currently installed {@link DistributionSet} (i.e. current state). In - * addition it holds the target {@link DistributionSet} that has to be - * provisioned next (i.e. target state). - *

- * - *

- * {@link #getStatus()}s() shows if the {@link Target} is - * {@link TargetStatus#IN_SYNC} or a provisioning is - * {@link TargetStatus#PENDING} or the target is only - * {@link TargetStatus#REGISTERED}, i.e. a target {@link DistributionSet} . - *

+ * JPA implementation of {@link Target}. * */ @Entity @@ -154,17 +141,14 @@ public class JpaTarget extends AbstractJpaNamedEntity implements Persistable tags) { this.tags = tags; } @@ -174,11 +158,6 @@ public class JpaTarget extends AbstractJpaNamedEntity implements Persistable hawkbit-repository hawkBit :: Repository + pom + + + hawkbit-repository-jpa + hawkbit-repository-api + - - - - com.ethlo.eclipselink.tools - http://ethlo.com/maven - - - - - - com.ethlo.eclipselink.tools - http://ethlo.com/maven - - - - - - - - com.fasterxml.jackson.core - jackson-core - - - com.fasterxml.jackson.core - jackson-databind - - - - - org.eclipse.hawkbit - hawkbit-artifact-repository-mongo - ${project.version} - - - org.eclipse.hawkbit - hawkbit-core - ${project.version} - - - org.eclipse.hawkbit - hawkbit-security-core - ${project.version} - - - org.hibernate - hibernate-validator - - - javax.validation - validation-api - - - com.google.guava - guava - - - net._01001111 - jlorem - - - org.springframework.boot - spring-boot - - - org.springframework.boot - spring-boot-starter-data-jpa - - - org.eclipse.persistence - org.eclipse.persistence.jpa - - - org.springframework.security - spring-security-core - - - org.springframework.hateoas - spring-hateoas - - - org.flywaydb - flyway-core - - - org.springframework.boot - spring-boot-configuration-processor - true - - - - - com.h2database - h2 - test - - - org.mariadb.jdbc - mariadb-java-client - test - - - javax.el - javax.el-api - test - - - org.springframework - spring-context-support - test - - - ru.yandex.qatools.allure - allure-junit-adaptor - test - - - org.springframework.data - spring-data-rest-webmvc - test - - - org.springframework.security - spring-security-aspects - test - - - org.springframework.boot - spring-boot-starter-test - test - - - org.springframework - spring-test - test - - - org.easytesting - fest-assert-core - test - - - org.easytesting - fest-assert - test - - - de.flapdoodle.embed - de.flapdoodle.embed.mongo - test - - - org.springframework.security - spring-security-config - test - - - org.springframework.security - spring-security-web - test - - - cz.jirutka.rsql - rsql-parser - - - - - - - - org.bsc.maven - maven-processor-plugin - - - process - - process - - generate-sources - - - org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor - - - - - - - org.hibernate - hibernate-jpamodelgen - ${hibernate.version} - - - - - - com.ethlo.persistence.tools - eclipselink-maven-plugin - 2.6.2 - - - process-classes - - weave - - - - - - org.eclipse.persistence - org.eclipse.persistence.jpa - ${eclipselink.version} - - - org.javassist - javassist - 3.20.0-GA - - - - - org.apache.maven.plugins - maven-jar-plugin - - - - test-jar - - - - - - diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Target.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Target.java deleted file mode 100644 index ba6f8c42c..000000000 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Target.java +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.model; - -import java.util.List; -import java.util.Set; - -public interface Target extends NamedEntity { - - DistributionSet getAssignedDistributionSet(); - - String getControllerId(); - - Set getTags(); - - void setAssignedDistributionSet(DistributionSet assignedDistributionSet); - - void setControllerId(String controllerId); - - void setTags(Set tags); - - List getActions(); - - TargetIdName getTargetIdName(); - - /** - * @return the targetInfo - */ - TargetInfo getTargetInfo(); - - /** - * @param targetInfo - * the targetInfo to set - */ - void setTargetInfo(TargetInfo targetInfo); - - /** - * @return the securityToken - */ - String getSecurityToken(); - - /** - * @param securityToken - * the securityToken to set - */ - void setSecurityToken(String securityToken); - -} \ No newline at end of file diff --git a/hawkbit-rest-core/pom.xml b/hawkbit-rest-core/pom.xml index a4a421f0d..66fb1655a 100644 --- a/hawkbit-rest-core/pom.xml +++ b/hawkbit-rest-core/pom.xml @@ -23,7 +23,7 @@ org.eclipse.hawkbit - hawkbit-repository + hawkbit-repository-jpa ${project.version} @@ -51,7 +51,7 @@ org.eclipse.hawkbit - hawkbit-repository + hawkbit-repository-jpa ${project.version} tests diff --git a/hawkbit-security-core/pom.xml b/hawkbit-security-core/pom.xml index a3b262726..a9b2347b6 100644 --- a/hawkbit-security-core/pom.xml +++ b/hawkbit-security-core/pom.xml @@ -21,7 +21,7 @@ - + org.eclipse.hawkbit hawkbit-core ${project.version} diff --git a/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/im/authentication/SpPermission.java b/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/im/authentication/SpPermission.java index 2e222d879..bcd44e510 100644 --- a/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/im/authentication/SpPermission.java +++ b/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/im/authentication/SpPermission.java @@ -314,6 +314,15 @@ public final class SpPermission { public static final String HAS_AUTH_ROLLOUT_MANAGEMENT_READ = HAS_AUTH_PREFIX + ROLLOUT_MANAGEMENT + HAS_AUTH_SUFFIX; + /** + * Spring security eval hasAuthority expression to check if spring + * context contains {@link SpPermission#ROLLOUT_MANAGEMENT} and + * {@link SpPermission#READ_TARGET} + */ + public static final String HAS_AUTH_ROLLOUT_MANAGEMENT_READ_AND_TARGET_READ = HAS_AUTH_PREFIX + + ROLLOUT_MANAGEMENT + HAS_AUTH_SUFFIX + HAS_AUTH_AND + HAS_AUTH_PREFIX + READ_TARGET + + HAS_AUTH_SUFFIX;; + /** * Spring security eval hasAuthority expression to check if spring * context contains {@link SpPermission#ROLLOUT_MANAGEMENT} and diff --git a/hawkbit-security-integration/pom.xml b/hawkbit-security-integration/pom.xml index c17317b3d..194a5e3cb 100644 --- a/hawkbit-security-integration/pom.xml +++ b/hawkbit-security-integration/pom.xml @@ -23,7 +23,7 @@ org.eclipse.hawkbit - hawkbit-repository + hawkbit-repository-jpa ${project.version} diff --git a/hawkbit-ui/pom.xml b/hawkbit-ui/pom.xml index e0bde576a..a9cd5aca3 100644 --- a/hawkbit-ui/pom.xml +++ b/hawkbit-ui/pom.xml @@ -151,7 +151,7 @@ org.eclipse.hawkbit - hawkbit-repository + hawkbit-repository-jpa ${project.version} @@ -254,5 +254,10 @@ allure-junit-adaptor test + + org.scala-lang + scala-library + 2.10.4 + \ No newline at end of file diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/ProxyTarget.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/ProxyTarget.java index d9d97f55d..3441198d9 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/ProxyTarget.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/ProxyTarget.java @@ -8,31 +8,33 @@ */ package org.eclipse.hawkbit.ui.components; +import java.io.Serializable; import java.net.URI; import java.security.SecureRandom; -import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.DistributionSet; -import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetIdName; +import org.eclipse.hawkbit.repository.model.TargetInfo; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; /** * Proxy for {@link Target}. * - * - * - * + */ +/** + * @author kaizimmerm * */ -public class ProxyTarget extends JpaTarget { +public class ProxyTarget implements Serializable { private static final long serialVersionUID = -8891449133620645310L; private String controllerId; private URI address = null; private Long lastTargetQuery = null; private Long installationDate; + private Long id; + private TargetUpdateStatus updateStatus = TargetUpdateStatus.UNKNOWN; private DistributionSet installedDistributionSet; @@ -57,11 +59,58 @@ public class ProxyTarget extends JpaTarget { private Status status; + private String name; + + private String description; + + private Long createdAt; + + private TargetInfo targetInfo; + + public Long getId() { + return id; + } + + public void setId(final Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(final String description) { + this.description = description; + } + + public Long getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(final Long createdAt) { + this.createdAt = createdAt; + } + + public TargetInfo getTargetInfo() { + return targetInfo; + } + + public void setTargetInfo(final TargetInfo targetInfo) { + this.targetInfo = targetInfo; + } + /** * @param controllerId */ public ProxyTarget() { - super(null); final Integer generatedId = new SecureRandom().nextInt(Integer.MAX_VALUE) - Integer.MAX_VALUE; targetIdName = new TargetIdName(generatedId, generatedId.toString(), generatedId.toString()); } @@ -161,7 +210,6 @@ public class ProxyTarget extends JpaTarget { * * @return String as ID. */ - @Override public String getControllerId() { return controllerId; } @@ -172,7 +220,6 @@ public class ProxyTarget extends JpaTarget { * @param controllerId * as ID */ - @Override public void setControllerId(final String controllerId) { this.controllerId = controllerId; } @@ -270,11 +317,7 @@ public class ProxyTarget extends JpaTarget { /** * @return the targetIdName */ - @Override public TargetIdName getTargetIdName() { - if (this.targetIdName == null) { - return super.getTargetIdName(); - } return this.targetIdName; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleBeanQuery.java index 21ce01347..16636e64b 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleBeanQuery.java @@ -14,7 +14,7 @@ import java.util.Map; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.SoftwareManagement; -import org.eclipse.hawkbit.repository.model.CustomSoftwareModule; +import org.eclipse.hawkbit.repository.model.AssignedSoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.ui.common.UserDetailsFormatter; @@ -75,20 +75,20 @@ public class SwModuleBeanQuery extends AbstractBeanQuery @Override protected List loadBeans(final int startIndex, final int count) { - final Slice swModuleBeans; + final Slice swModuleBeans; final List proxyBeans = new ArrayList<>(); swModuleBeans = getSoftwareManagement().findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc( new OffsetBasedPageRequest(startIndex, count), orderByDistId, searchText, type); - for (final CustomSoftwareModule swModule : swModuleBeans) { + for (final AssignedSoftwareModule swModule : swModuleBeans) { proxyBeans.add(getProxyBean(swModule)); } return proxyBeans; } - private ProxyBaseSwModuleItem getProxyBean(final CustomSoftwareModule customSoftwareModule) { + private ProxyBaseSwModuleItem getProxyBean(final AssignedSoftwareModule customSoftwareModule) { final SoftwareModule bean = customSoftwareModule.getSoftwareModule(); final ProxyBaseSwModuleItem proxyItem = new ProxyBaseSwModuleItem(); proxyItem.setSwId(bean.getId()); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/FilterQueryValidation.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/FilterQueryValidation.java index 4f528c74a..6d1f1a7ab 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/FilterQueryValidation.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/FilterQueryValidation.java @@ -17,8 +17,8 @@ import java.util.stream.Collectors; import org.eclipse.hawkbit.repository.TargetFields; import org.eclipse.hawkbit.repository.TargetManagement; -import org.eclipse.hawkbit.repository.rsql.RSQLParameterSyntaxException; -import org.eclipse.hawkbit.repository.rsql.RSQLParameterUnsupportedFieldException; +import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException; +import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException; import org.eclipse.hawkbit.ui.utils.SpringContextHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/actionhistory/ActionHistoryTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/actionhistory/ActionHistoryTable.java index 74f518d56..b571bb3df 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/actionhistory/ActionHistoryTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/actionhistory/ActionHistoryTable.java @@ -304,9 +304,9 @@ public class ActionHistoryTable extends TreeTable implements Handler { ((Hierarchical) hierarchicalContainer).setChildrenAllowed(actionWithStatusCount.getAction().getId(), false); item.getItemProperty(SPUIDefinitions.ACTION_HIS_TBL_DATETIME) - .setValue(SPDateTimeUtil.getFormattedDate((actionWithStatusCount.getActionLastModifiedAt() != null) - ? actionWithStatusCount.getActionLastModifiedAt() - : actionWithStatusCount.getActionCreatedAt())); + .setValue(SPDateTimeUtil.getFormattedDate((actionWithStatusCount.getAction().getLastModifiedAt() != null) + ? actionWithStatusCount.getAction().getLastModifiedAt() + : actionWithStatusCount.getAction().getLastModifiedAt())); item.getItemProperty(SPUIDefinitions.ACTION_HIS_TBL_ROLLOUT_NAME) .setValue(actionWithStatusCount.getRolloutName()); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java index 575b73b4d..7ed9c81dd 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java @@ -19,7 +19,6 @@ import java.util.Map; import java.util.Map.Entry; import java.util.TimeZone; -import org.apache.commons.lang3.StringUtils; import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.model.AssignmentResult; import org.eclipse.hawkbit.repository.model.DistributionSet; From eeee57fbc4004f5440d86de3b2b0326c22c448f7 Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Thu, 26 May 2016 14:03:14 +0200 Subject: [PATCH 22/54] Refactored package names. Signed-off-by: Kai Zimmermann --- .../hawkbit/repository/ReportManagement.java | 8 +++---- .../hawkbit/repository/RolloutManagement.java | 2 +- .../hawkbit/repository/SystemManagement.java | 2 +- .../repository/TenantStatsManagement.java | 2 +- .../event/AbstractBaseEntityEvent.java | 4 +++- .../event/AbstractEntityBulkEvent.java | 2 +- .../event/AbstractPropertyChangeEvent.java | 2 +- .../eventbus/event/ActionCreatedEvent.java | 2 +- .../event/ActionPropertyChangeEvent.java | 2 +- ...istributionSetTagAssigmentResultEvent.java | 2 +- .../DistributionSetTagCreatedBulkEvent.java | 2 +- .../event/DistributionSetTagDeletedEvent.java | 2 +- .../event/DistributionSetTagUpdateEvent.java | 2 +- .../eventbus/event/EntityBulkEvent.java | 3 ++- .../eventbus/event/RolloutChangeEvent.java | 4 +++- .../event/RolloutGroupChangeEvent.java | 4 +++- .../event/RolloutGroupCreatedEvent.java | 4 +++- .../RolloutGroupPropertyChangeEvent.java | 2 +- .../event/RolloutPropertyChangeEvent.java | 2 +- .../TargetAssignDistributionSetEvent.java | 3 ++- .../eventbus/event/TargetCreatedEvent.java | 2 +- .../eventbus/event/TargetInfoUpdateEvent.java | 3 ++- .../event/TargetTagAssigmentResultEvent.java | 2 +- .../event/TargetTagCreatedBulkEvent.java | 2 +- .../eventbus/event/TargetTagDeletedEvent.java | 2 +- .../eventbus/event/TargetTagUpdateEvent.java | 2 +- .../report/model/AbstractReportSeries.java | 2 +- .../report/model/DataReportSeries.java | 2 +- .../report/model/DataReportSeriesItem.java | 2 +- .../model/InnerOuterDataReportSeries.java | 2 +- .../report/model/ListReportSeries.java | 2 +- .../report/model/SeriesTime.java | 2 +- .../report/model/SystemUsageReport.java | 2 +- .../report/model/TenantUsage.java | 2 +- .../jpa/JpaDeploymentManagement.java | 10 ++++----- .../jpa/JpaDistributionSetManagement.java | 6 ++--- .../repository/jpa/JpaReportManagement.java | 8 +++---- .../jpa/JpaRolloutGroupManagement.java | 2 +- .../repository/jpa/JpaRolloutManagement.java | 8 +++---- .../repository/jpa/JpaSoftwareManagement.java | 2 +- .../repository/jpa/JpaSystemManagement.java | 2 +- .../repository/jpa/JpaTagManagement.java | 16 +++++++------- .../repository/jpa/JpaTargetManagement.java | 8 +++---- .../jpa/JpaTenantStatsManagement.java | 2 +- .../ExceptionMappingAspectHandler.java | 2 +- .../jpa}/cache/CacheField.java | 4 ++-- .../{ => repository/jpa}/cache/CacheKeys.java | 4 ++-- .../jpa}/cache/CacheWriteNotify.java | 4 ++-- .../jpa/configuration}/Constants.java | 2 +- .../MultiTenantJpaTransactionManager.java | 2 +- .../RepositoryApplicationConfiguration.java | 18 +++++++-------- .../eventbus/CacheFieldEntityListener.java | 8 +++---- .../eventbus/EntityChangeEventListener.java | 8 +++---- .../EntityPropertyChangeListener.java | 18 +++++++-------- .../jpa}/eventbus/EventMerger.java | 16 +++++++------- ...ansactionCommitDefaultServiceExecutor.java | 2 +- .../AfterTransactionCommitExecutor.java | 2 +- .../jpa/model/AbstractJpaBaseEntity.java | 4 ++-- .../AbstractJpaTenantAwareBaseEntity.java | 4 ++-- .../repository/jpa/model/JpaAction.java | 4 ++-- .../repository/jpa/model/JpaRollout.java | 4 ++-- .../repository/jpa/model/JpaTarget.java | 6 ++--- .../repository/jpa/model/JpaTargetInfo.java | 4 ++-- .../AfterTransactionCommitExecutorHolder.java | 6 ++--- .../model/helper/CacheManagerHolder.java | 4 ++-- .../model/helper/EventBusHolder.java | 4 ++-- .../model/helper/SecurityChecker.java | 2 +- .../helper/SecurityTokenGeneratorHolder.java | 2 +- .../model/helper/SystemManagementHolder.java | 2 +- .../helper/SystemSecurityContextHolder.java | 2 +- .../model/helper/TenantAwareHolder.java | 2 +- .../TenantConfigurationManagementHolder.java | 2 +- .../repository}/rsql/PropertyMapper.java | 2 +- .../repository}/rsql/RSQLUtility.java | 2 +- .../condition/PauseRolloutGroupAction.java | 2 +- .../RolloutGroupActionEvaluator.java | 2 +- .../RolloutGroupConditionEvaluator.java | 2 +- ...artNextGroupRolloutGroupSuccessAction.java | 2 +- .../ThresholdRolloutGroupErrorCondition.java | 2 +- ...ThresholdRolloutGroupSuccessCondition.java | 2 +- .../jpa}/AbstractIntegrationTest.java | 22 ++++--------------- .../AbstractIntegrationTestWithMongoDB.java | 2 +- .../repository/{ => jpa}/ActionTest.java | 2 +- .../ArtifactManagementNoMongoDbTest.java | 3 +-- .../{ => jpa}/ArtifactManagementTest.java | 7 ++---- .../jpa}/CIMySqlTestDatabase.java | 2 +- .../{ => jpa}/ControllerManagementTest.java | 4 +--- .../{ => jpa}/DeploymentManagementTest.java | 11 +++++----- .../DistributionSetManagementTest.java | 6 ++--- .../jpa}/FreePortFileWriter.java | 2 +- .../jpa}/HashGeneratorUtils.java | 2 +- .../jpa}/LocalH2TestDatabase.java | 2 +- .../jpa}/MethodSecurityUtil.java | 2 +- .../jpa}/RandomGeneratedInputStream.java | 2 +- .../{ => jpa}/ReportManagementTest.java | 16 ++++++-------- .../{ => jpa}/RolloutManagementTest.java | 11 +++++----- .../{ => jpa}/SoftwareManagementTest.java | 6 +---- .../{ => jpa}/SystemManagementTest.java | 7 ++---- .../{ => jpa}/TagManagementTest.java | 5 ++--- .../TargetFilterQueryManagenmentTest.java | 4 ++-- .../{ => jpa}/TargetManagementSearchTest.java | 4 +--- .../{ => jpa}/TargetManagementTest.java | 7 ++---- .../TenantConfigurationManagementTest.java | 3 +-- .../jpa}/TestConfiguration.java | 9 ++++---- .../{ => repository/jpa}/TestDataUtil.java | 3 +-- .../{ => repository/jpa}/Testdatabase.java | 2 +- .../jpa}/WithSpringAuthorityRule.java | 4 ++-- .../{ => repository/jpa}/WithUser.java | 2 +- .../jpa}/cache/CacheKeysTest.java | 2 +- .../jpa}/cache/CacheWriteNotifyTest.java | 2 +- .../CacheFieldEntityListenerTest.java | 8 +++---- .../model/ModelEqualsHashcodeTest.java | 11 +++------- .../{ => jpa}/rsql/RSQLActionFieldsTest.java | 4 ++-- .../rsql/RSQLDistributionSetFieldTest.java | 6 ++--- ...RSQLDistributionSetMetadataFieldsTest.java | 6 ++--- .../rsql/RSQLRolloutGroupFields.java | 6 ++--- .../rsql/RSQLSoftwareModuleFieldTest.java | 4 ++-- .../RSQLSoftwareModuleMetadataFieldsTest.java | 6 ++--- .../RSQLSoftwareModuleTypeFieldsTest.java | 4 ++-- .../{ => jpa}/rsql/RSQLTagFieldsTest.java | 4 ++-- .../{ => jpa}/rsql/RSQLTargetFieldTest.java | 6 ++--- .../{ => jpa}/rsql/RSQLUtilityTest.java | 3 ++- .../jpa}/tenancy/MultiTenancyEntityTest.java | 8 +++---- .../{ => jpa}/utils/MultipleInvokeHelper.java | 2 +- .../utils/RepositoryDataGenerator.java | 4 ++-- .../{ => jpa}/utils/SuccessCondition.java | 2 +- .../util/RestResourceConversionHelper.java | 2 +- .../rest/AbstractRestIntegrationTest.java | 2 +- ...bstractRestIntegrationTestWithMongoDB.java | 2 +- .../hawkbit/ui/HawkbitEventProvider.java | 20 ++++++++--------- .../tagdetails/AbstractTargetTagToken.java | 4 ++-- .../tagdetails/DistributionTagToken.java | 8 +++---- .../ui/common/tagdetails/TargetTagToken.java | 4 ++-- ...eateUpdateDistributionTagLayoutWindow.java | 6 ++--- .../dstag/DistributionTagButtons.java | 6 ++--- .../management/targettable/TargetTable.java | 4 ++-- .../CreateUpdateTargetTagLayout.java | 6 ++--- .../targettag/TargetTagFilterButtons.java | 6 ++--- .../ui/rollout/rollout/RolloutListGrid.java | 2 +- .../rolloutgroup/RolloutGroupListGrid.java | 2 +- 140 files changed, 295 insertions(+), 326 deletions(-) rename hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/{ => repository}/eventbus/event/AbstractBaseEntityEvent.java (88%) rename hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/{ => repository}/eventbus/event/AbstractEntityBulkEvent.java (96%) rename hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/{ => repository}/eventbus/event/AbstractPropertyChangeEvent.java (97%) rename hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/{ => repository}/eventbus/event/ActionCreatedEvent.java (93%) rename hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/{ => repository}/eventbus/event/ActionPropertyChangeEvent.java (94%) rename hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/{ => repository}/eventbus/event/DistributionSetTagAssigmentResultEvent.java (94%) rename hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/{ => repository}/eventbus/event/DistributionSetTagCreatedBulkEvent.java (95%) rename hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/{ => repository}/eventbus/event/DistributionSetTagDeletedEvent.java (93%) rename hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/{ => repository}/eventbus/event/DistributionSetTagUpdateEvent.java (93%) rename hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/{ => repository}/eventbus/event/EntityBulkEvent.java (91%) rename hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/{ => repository}/eventbus/event/RolloutChangeEvent.java (89%) rename hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/{ => repository}/eventbus/event/RolloutGroupChangeEvent.java (92%) rename hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/{ => repository}/eventbus/event/RolloutGroupCreatedEvent.java (94%) rename hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/{ => repository}/eventbus/event/RolloutGroupPropertyChangeEvent.java (94%) rename hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/{ => repository}/eventbus/event/RolloutPropertyChangeEvent.java (94%) rename hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/{ => repository}/eventbus/event/TargetAssignDistributionSetEvent.java (95%) rename hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/{ => repository}/eventbus/event/TargetCreatedEvent.java (93%) rename hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/{ => repository}/eventbus/event/TargetInfoUpdateEvent.java (93%) rename hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/{ => repository}/eventbus/event/TargetTagAssigmentResultEvent.java (94%) rename hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/{ => repository}/eventbus/event/TargetTagCreatedBulkEvent.java (95%) rename hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/{ => repository}/eventbus/event/TargetTagDeletedEvent.java (93%) rename hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/{ => repository}/eventbus/event/TargetTagUpdateEvent.java (93%) rename hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/{ => repository}/report/model/AbstractReportSeries.java (94%) rename hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/{ => repository}/report/model/DataReportSeries.java (97%) rename hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/{ => repository}/report/model/DataReportSeriesItem.java (95%) rename hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/{ => repository}/report/model/InnerOuterDataReportSeries.java (96%) rename hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/{ => repository}/report/model/ListReportSeries.java (96%) rename hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/{ => repository}/report/model/SeriesTime.java (93%) rename hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/{ => repository}/report/model/SystemUsageReport.java (97%) rename hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/{ => repository}/report/model/TenantUsage.java (98%) rename hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/{ => repository/jpa}/aspects/ExceptionMappingAspectHandler.java (99%) rename hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/{ => repository/jpa}/cache/CacheField.java (89%) rename hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/{ => repository/jpa}/cache/CacheKeys.java (92%) rename hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/{ => repository/jpa}/cache/CacheWriteNotify.java (97%) rename hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/{ => repository/jpa/configuration}/Constants.java (94%) rename hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/{ => repository/jpa/configuration}/MultiTenantJpaTransactionManager.java (96%) rename hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/{ => repository/jpa/configuration}/RepositoryApplicationConfiguration.java (88%) rename hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/{ => repository/jpa}/eventbus/CacheFieldEntityListener.java (95%) rename hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/{ => repository/jpa}/eventbus/EntityChangeEventListener.java (95%) rename hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/{ => repository/jpa}/eventbus/EntityPropertyChangeListener.java (83%) rename hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/{ => repository/jpa}/eventbus/EventMerger.java (92%) rename hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/{ => repository/jpa}/executor/AfterTransactionCommitDefaultServiceExecutor.java (98%) rename hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/{ => repository/jpa}/executor/AfterTransactionCommitExecutor.java (93%) rename hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/{ => jpa/repository}/model/helper/AfterTransactionCommitExecutorHolder.java (86%) rename hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/{ => jpa/repository}/model/helper/CacheManagerHolder.java (91%) rename hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/{ => jpa/repository}/model/helper/EventBusHolder.java (89%) rename hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/{ => jpa/repository}/model/helper/SecurityChecker.java (96%) rename hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/{ => jpa/repository}/model/helper/SecurityTokenGeneratorHolder.java (95%) rename hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/{ => jpa/repository}/model/helper/SystemManagementHolder.java (95%) rename hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/{ => jpa/repository}/model/helper/SystemSecurityContextHolder.java (94%) rename hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/{ => jpa/repository}/model/helper/TenantAwareHolder.java (94%) rename hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/{ => jpa/repository}/model/helper/TenantConfigurationManagementHolder.java (95%) rename hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/{ => jpa/repository}/rsql/PropertyMapper.java (95%) rename hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/{ => jpa/repository}/rsql/RSQLUtility.java (99%) rename hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/{ => repository/jpa}/rollout/condition/PauseRolloutGroupAction.java (96%) rename hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/{ => repository/jpa}/rollout/condition/RolloutGroupActionEvaluator.java (91%) rename hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/{ => repository/jpa}/rollout/condition/RolloutGroupConditionEvaluator.java (94%) rename hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/{ => repository/jpa}/rollout/condition/StartNextGroupRolloutGroupSuccessAction.java (98%) rename hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/{ => repository/jpa}/rollout/condition/ThresholdRolloutGroupErrorCondition.java (97%) rename hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/{ => repository/jpa}/rollout/condition/ThresholdRolloutGroupSuccessCondition.java (97%) rename hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/{ => repository/jpa}/AbstractIntegrationTest.java (90%) rename hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/{ => repository/jpa}/AbstractIntegrationTestWithMongoDB.java (98%) rename hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/{ => jpa}/ActionTest.java (97%) rename hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/{ => jpa}/ArtifactManagementNoMongoDbTest.java (95%) rename hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/{ => jpa}/ArtifactManagementTest.java (98%) rename hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/{ => repository/jpa}/CIMySqlTestDatabase.java (98%) rename hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/{ => jpa}/ControllerManagementTest.java (98%) rename hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/{ => jpa}/DeploymentManagementTest.java (99%) rename hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/{ => jpa}/DistributionSetManagementTest.java (99%) rename hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/{ => repository/jpa}/FreePortFileWriter.java (97%) rename hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/{ => repository/jpa}/HashGeneratorUtils.java (98%) rename hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/{ => repository/jpa}/LocalH2TestDatabase.java (98%) rename hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/{ => repository/jpa}/MethodSecurityUtil.java (98%) rename hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/{ => repository/jpa}/RandomGeneratedInputStream.java (96%) rename hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/{ => jpa}/ReportManagementTest.java (98%) rename hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/{ => jpa}/RolloutManagementTest.java (99%) rename hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/{ => jpa}/SoftwareManagementTest.java (99%) rename hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/{ => jpa}/SystemManagementTest.java (96%) rename hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/{ => jpa}/TagManagementTest.java (99%) rename hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/{ => jpa}/TargetFilterQueryManagenmentTest.java (97%) rename hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/{ => jpa}/TargetManagementSearchTest.java (99%) rename hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/{ => jpa}/TargetManagementTest.java (99%) rename hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/{ => jpa}/TenantConfigurationManagementTest.java (99%) rename hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/{ => repository/jpa}/TestConfiguration.java (91%) rename hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/{ => repository/jpa}/TestDataUtil.java (99%) rename hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/{ => repository/jpa}/Testdatabase.java (91%) rename hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/{ => repository/jpa}/WithSpringAuthorityRule.java (98%) rename hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/{ => repository/jpa}/WithUser.java (97%) rename hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/{ => repository/jpa}/cache/CacheKeysTest.java (95%) rename hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/{ => repository/jpa}/cache/CacheWriteNotifyTest.java (97%) rename hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/{ => repository/jpa}/eventbus/CacheFieldEntityListenerTest.java (93%) rename hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/{ => jpa}/model/ModelEqualsHashcodeTest.java (91%) rename hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/{ => jpa}/rsql/RSQLActionFieldsTest.java (96%) rename hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/{ => jpa}/rsql/RSQLDistributionSetFieldTest.java (97%) rename hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/{ => jpa}/rsql/RSQLDistributionSetMetadataFieldsTest.java (94%) rename hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/{ => jpa}/rsql/RSQLRolloutGroupFields.java (96%) rename hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/{ => jpa}/rsql/RSQLSoftwareModuleFieldTest.java (97%) rename hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/{ => jpa}/rsql/RSQLSoftwareModuleMetadataFieldsTest.java (95%) rename hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/{ => jpa}/rsql/RSQLSoftwareModuleTypeFieldsTest.java (95%) rename hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/{ => jpa}/rsql/RSQLTagFieldsTest.java (97%) rename hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/{ => jpa}/rsql/RSQLTargetFieldTest.java (97%) rename hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/{ => jpa}/rsql/RSQLUtilityTest.java (99%) rename hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/{ => repository/jpa}/tenancy/MultiTenancyEntityTest.java (97%) rename hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/{ => jpa}/utils/MultipleInvokeHelper.java (98%) rename hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/{ => jpa}/utils/RepositoryDataGenerator.java (99%) rename hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/{ => jpa}/utils/SuccessCondition.java (92%) diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ReportManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ReportManagement.java index fca145908..49b0b505d 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ReportManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ReportManagement.java @@ -18,11 +18,11 @@ import java.util.List; import javax.validation.constraints.NotNull; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; -import org.eclipse.hawkbit.report.model.DataReportSeries; -import org.eclipse.hawkbit.report.model.InnerOuterDataReportSeries; -import org.eclipse.hawkbit.report.model.ListReportSeries; -import org.eclipse.hawkbit.report.model.SeriesTime; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; +import org.eclipse.hawkbit.repository.report.model.DataReportSeries; +import org.eclipse.hawkbit.repository.report.model.InnerOuterDataReportSeries; +import org.eclipse.hawkbit.repository.report.model.ListReportSeries; +import org.eclipse.hawkbit.repository.report.model.SeriesTime; import org.springframework.security.access.prepost.PreAuthorize; /** diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java index f75ff545b..3ff6e0d4b 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java @@ -10,8 +10,8 @@ package org.eclipse.hawkbit.repository; import javax.validation.constraints.NotNull; -import org.eclipse.hawkbit.eventbus.event.RolloutGroupCreatedEvent; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; +import org.eclipse.hawkbit.repository.eventbus.event.RolloutGroupCreatedEvent; import org.eclipse.hawkbit.repository.exception.RolloutIllegalStateException; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.Rollout.RolloutStatus; diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java index b62ed0ad3..19138ae9b 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java @@ -13,8 +13,8 @@ import java.util.List; import javax.validation.constraints.NotNull; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; -import org.eclipse.hawkbit.report.model.SystemUsageReport; import org.eclipse.hawkbit.repository.model.TenantMetaData; +import org.eclipse.hawkbit.repository.report.model.SystemUsageReport; import org.eclipse.hawkbit.tenancy.TenantAware; import org.springframework.cache.interceptor.KeyGenerator; import org.springframework.context.annotation.Bean; diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TenantStatsManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TenantStatsManagement.java index bb4ca8ef0..32ecdcce4 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TenantStatsManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TenantStatsManagement.java @@ -9,7 +9,7 @@ package org.eclipse.hawkbit.repository; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; -import org.eclipse.hawkbit.report.model.TenantUsage; +import org.eclipse.hawkbit.repository.report.model.TenantUsage; import org.springframework.security.access.prepost.PreAuthorize; /** diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/AbstractBaseEntityEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/AbstractBaseEntityEvent.java similarity index 88% rename from hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/AbstractBaseEntityEvent.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/AbstractBaseEntityEvent.java index d27669ade..d13e89ee7 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/AbstractBaseEntityEvent.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/AbstractBaseEntityEvent.java @@ -6,8 +6,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.eventbus.event; +package org.eclipse.hawkbit.repository.eventbus.event; +import org.eclipse.hawkbit.eventbus.event.AbstractDistributedEvent; +import org.eclipse.hawkbit.eventbus.event.EntityEvent; import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity; /** diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/AbstractEntityBulkEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/AbstractEntityBulkEvent.java similarity index 96% rename from hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/AbstractEntityBulkEvent.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/AbstractEntityBulkEvent.java index 56f3e585a..f8d43d6cd 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/AbstractEntityBulkEvent.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/AbstractEntityBulkEvent.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.eventbus.event; +package org.eclipse.hawkbit.repository.eventbus.event; import java.util.Arrays; import java.util.List; diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/AbstractPropertyChangeEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/AbstractPropertyChangeEvent.java similarity index 97% rename from hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/AbstractPropertyChangeEvent.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/AbstractPropertyChangeEvent.java index 795f6ff88..97cf13b66 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/AbstractPropertyChangeEvent.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/AbstractPropertyChangeEvent.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.eventbus.event; +package org.eclipse.hawkbit.repository.eventbus.event; import java.util.Map; diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/ActionCreatedEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/ActionCreatedEvent.java similarity index 93% rename from hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/ActionCreatedEvent.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/ActionCreatedEvent.java index 5efdca2a9..73188b85e 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/ActionCreatedEvent.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/ActionCreatedEvent.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.eventbus.event; +package org.eclipse.hawkbit.repository.eventbus.event; import org.eclipse.hawkbit.repository.model.Action; diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/ActionPropertyChangeEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/ActionPropertyChangeEvent.java similarity index 94% rename from hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/ActionPropertyChangeEvent.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/ActionPropertyChangeEvent.java index 822f9bbeb..84487547e 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/ActionPropertyChangeEvent.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/ActionPropertyChangeEvent.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.eventbus.event; +package org.eclipse.hawkbit.repository.eventbus.event; import java.util.Map; diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/DistributionSetTagAssigmentResultEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/DistributionSetTagAssigmentResultEvent.java similarity index 94% rename from hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/DistributionSetTagAssigmentResultEvent.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/DistributionSetTagAssigmentResultEvent.java index e10b9a51f..d723251da 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/DistributionSetTagAssigmentResultEvent.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/DistributionSetTagAssigmentResultEvent.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.eventbus.event; +package org.eclipse.hawkbit.repository.eventbus.event; import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult; diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/DistributionSetTagCreatedBulkEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/DistributionSetTagCreatedBulkEvent.java similarity index 95% rename from hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/DistributionSetTagCreatedBulkEvent.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/DistributionSetTagCreatedBulkEvent.java index fb7c4a862..2fc08c272 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/DistributionSetTagCreatedBulkEvent.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/DistributionSetTagCreatedBulkEvent.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.eventbus.event; +package org.eclipse.hawkbit.repository.eventbus.event; import java.util.List; diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/DistributionSetTagDeletedEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/DistributionSetTagDeletedEvent.java similarity index 93% rename from hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/DistributionSetTagDeletedEvent.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/DistributionSetTagDeletedEvent.java index b909390d1..f2f134a3a 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/DistributionSetTagDeletedEvent.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/DistributionSetTagDeletedEvent.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.eventbus.event; +package org.eclipse.hawkbit.repository.eventbus.event; import org.eclipse.hawkbit.repository.model.DistributionSetTag; diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/DistributionSetTagUpdateEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/DistributionSetTagUpdateEvent.java similarity index 93% rename from hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/DistributionSetTagUpdateEvent.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/DistributionSetTagUpdateEvent.java index 2825322f9..d74872b01 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/DistributionSetTagUpdateEvent.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/DistributionSetTagUpdateEvent.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.eventbus.event; +package org.eclipse.hawkbit.repository.eventbus.event; import org.eclipse.hawkbit.repository.model.DistributionSetTag; diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/EntityBulkEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/EntityBulkEvent.java similarity index 91% rename from hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/EntityBulkEvent.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/EntityBulkEvent.java index eac1b6bb9..0102fda47 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/EntityBulkEvent.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/EntityBulkEvent.java @@ -6,11 +6,12 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.eventbus.event; +package org.eclipse.hawkbit.repository.eventbus.event; import java.io.Serializable; import java.util.List; +import org.eclipse.hawkbit.eventbus.event.Event; import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity; /** diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/RolloutChangeEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/RolloutChangeEvent.java similarity index 89% rename from hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/RolloutChangeEvent.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/RolloutChangeEvent.java index 576a6b99c..2ff739726 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/RolloutChangeEvent.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/RolloutChangeEvent.java @@ -6,7 +6,9 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.eventbus.event; +package org.eclipse.hawkbit.repository.eventbus.event; + +import org.eclipse.hawkbit.eventbus.event.AbstractEvent; /** * Event declaration for the UI to notify the UI that a rollout has been diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/RolloutGroupChangeEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/RolloutGroupChangeEvent.java similarity index 92% rename from hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/RolloutGroupChangeEvent.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/RolloutGroupChangeEvent.java index cbda44ef5..5c36ab61f 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/RolloutGroupChangeEvent.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/RolloutGroupChangeEvent.java @@ -6,7 +6,9 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.eventbus.event; +package org.eclipse.hawkbit.repository.eventbus.event; + +import org.eclipse.hawkbit.eventbus.event.AbstractEvent; /** * Event declaration for the UI to notify the UI that a rollout has been diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/RolloutGroupCreatedEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/RolloutGroupCreatedEvent.java similarity index 94% rename from hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/RolloutGroupCreatedEvent.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/RolloutGroupCreatedEvent.java index 465ff6088..41f08c91d 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/RolloutGroupCreatedEvent.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/RolloutGroupCreatedEvent.java @@ -6,7 +6,9 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.eventbus.event; +package org.eclipse.hawkbit.repository.eventbus.event; + +import org.eclipse.hawkbit.eventbus.event.AbstractDistributedEvent; /** * Event definition which is been published in case a rollout group has been diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/RolloutGroupPropertyChangeEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/RolloutGroupPropertyChangeEvent.java similarity index 94% rename from hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/RolloutGroupPropertyChangeEvent.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/RolloutGroupPropertyChangeEvent.java index 6caa46547..887a1c2ff 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/RolloutGroupPropertyChangeEvent.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/RolloutGroupPropertyChangeEvent.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.eventbus.event; +package org.eclipse.hawkbit.repository.eventbus.event; import java.util.Map; diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/RolloutPropertyChangeEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/RolloutPropertyChangeEvent.java similarity index 94% rename from hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/RolloutPropertyChangeEvent.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/RolloutPropertyChangeEvent.java index 5f72307df..9287a0fb3 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/RolloutPropertyChangeEvent.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/RolloutPropertyChangeEvent.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.eventbus.event; +package org.eclipse.hawkbit.repository.eventbus.event; import java.util.Map; diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetAssignDistributionSetEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetAssignDistributionSetEvent.java similarity index 95% rename from hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetAssignDistributionSetEvent.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetAssignDistributionSetEvent.java index 68b3f1289..077e05462 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetAssignDistributionSetEvent.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetAssignDistributionSetEvent.java @@ -6,11 +6,12 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.eventbus.event; +package org.eclipse.hawkbit.repository.eventbus.event; import java.net.URI; import java.util.Collection; +import org.eclipse.hawkbit.eventbus.event.AbstractEvent; import org.eclipse.hawkbit.repository.model.SoftwareModule; /** diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetCreatedEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetCreatedEvent.java similarity index 93% rename from hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetCreatedEvent.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetCreatedEvent.java index 7e89565b1..446f21856 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetCreatedEvent.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetCreatedEvent.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.eventbus.event; +package org.eclipse.hawkbit.repository.eventbus.event; import org.eclipse.hawkbit.repository.model.Target; diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetInfoUpdateEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetInfoUpdateEvent.java similarity index 93% rename from hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetInfoUpdateEvent.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetInfoUpdateEvent.java index 563bb4bdc..1e7e29719 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetInfoUpdateEvent.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetInfoUpdateEvent.java @@ -6,8 +6,9 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.eventbus.event; +package org.eclipse.hawkbit.repository.eventbus.event; +import org.eclipse.hawkbit.eventbus.event.EntityEvent; import org.eclipse.hawkbit.repository.model.TargetInfo; /** diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetTagAssigmentResultEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetTagAssigmentResultEvent.java similarity index 94% rename from hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetTagAssigmentResultEvent.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetTagAssigmentResultEvent.java index 6bdc3aebd..b846a80da 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetTagAssigmentResultEvent.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetTagAssigmentResultEvent.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.eventbus.event; +package org.eclipse.hawkbit.repository.eventbus.event; import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult; diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetTagCreatedBulkEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetTagCreatedBulkEvent.java similarity index 95% rename from hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetTagCreatedBulkEvent.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetTagCreatedBulkEvent.java index c66a5150e..950c351e0 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetTagCreatedBulkEvent.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetTagCreatedBulkEvent.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.eventbus.event; +package org.eclipse.hawkbit.repository.eventbus.event; import java.util.List; diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetTagDeletedEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetTagDeletedEvent.java similarity index 93% rename from hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetTagDeletedEvent.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetTagDeletedEvent.java index 040fbc19a..ebf6c73c9 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetTagDeletedEvent.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetTagDeletedEvent.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.eventbus.event; +package org.eclipse.hawkbit.repository.eventbus.event; import org.eclipse.hawkbit.repository.model.TargetTag; diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetTagUpdateEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetTagUpdateEvent.java similarity index 93% rename from hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetTagUpdateEvent.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetTagUpdateEvent.java index 4562063aa..f87443235 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/eventbus/event/TargetTagUpdateEvent.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetTagUpdateEvent.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.eventbus.event; +package org.eclipse.hawkbit.repository.eventbus.event; import org.eclipse.hawkbit.repository.model.TargetTag; diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/report/model/AbstractReportSeries.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/report/model/AbstractReportSeries.java similarity index 94% rename from hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/report/model/AbstractReportSeries.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/report/model/AbstractReportSeries.java index 0542f68c9..747cd8279 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/report/model/AbstractReportSeries.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/report/model/AbstractReportSeries.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.report.model; +package org.eclipse.hawkbit.repository.report.model; import java.io.Serializable; diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/report/model/DataReportSeries.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/report/model/DataReportSeries.java similarity index 97% rename from hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/report/model/DataReportSeries.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/report/model/DataReportSeries.java index 39c8f5723..e9fb032c3 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/report/model/DataReportSeries.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/report/model/DataReportSeries.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.report.model; +package org.eclipse.hawkbit.repository.report.model; import java.io.Serializable; import java.util.ArrayList; diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/report/model/DataReportSeriesItem.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/report/model/DataReportSeriesItem.java similarity index 95% rename from hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/report/model/DataReportSeriesItem.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/report/model/DataReportSeriesItem.java index 492e27e1e..7dba6c082 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/report/model/DataReportSeriesItem.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/report/model/DataReportSeriesItem.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.report.model; +package org.eclipse.hawkbit.repository.report.model; import java.io.Serializable; diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/report/model/InnerOuterDataReportSeries.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/report/model/InnerOuterDataReportSeries.java similarity index 96% rename from hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/report/model/InnerOuterDataReportSeries.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/report/model/InnerOuterDataReportSeries.java index b63935b39..357f9a554 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/report/model/InnerOuterDataReportSeries.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/report/model/InnerOuterDataReportSeries.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.report.model; +package org.eclipse.hawkbit.repository.report.model; import java.io.Serializable; diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/report/model/ListReportSeries.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/report/model/ListReportSeries.java similarity index 96% rename from hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/report/model/ListReportSeries.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/report/model/ListReportSeries.java index 79c496480..18b011420 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/report/model/ListReportSeries.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/report/model/ListReportSeries.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.report.model; +package org.eclipse.hawkbit.repository.report.model; import java.util.ArrayList; import java.util.Collections; diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/report/model/SeriesTime.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/report/model/SeriesTime.java similarity index 93% rename from hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/report/model/SeriesTime.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/report/model/SeriesTime.java index a50171479..0ab466acd 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/report/model/SeriesTime.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/report/model/SeriesTime.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.report.model; +package org.eclipse.hawkbit.repository.report.model; /** * A series time enum definition for {@link DataReportSeriesItem}s. diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/report/model/SystemUsageReport.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/report/model/SystemUsageReport.java similarity index 97% rename from hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/report/model/SystemUsageReport.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/report/model/SystemUsageReport.java index 45cc60cba..fe6c6bb96 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/report/model/SystemUsageReport.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/report/model/SystemUsageReport.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.report.model; +package org.eclipse.hawkbit.repository.report.model; import java.util.ArrayList; import java.util.List; diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/report/model/TenantUsage.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/report/model/TenantUsage.java similarity index 98% rename from hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/report/model/TenantUsage.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/report/model/TenantUsage.java index d0ee7102c..5467099c4 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/report/model/TenantUsage.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/report/model/TenantUsage.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.report.model; +package org.eclipse.hawkbit.repository.report.model; /** * System usage stats element for a tenant. diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java index d869dd758..a3c717d98 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java @@ -28,20 +28,20 @@ import javax.persistence.criteria.ListJoin; import javax.persistence.criteria.Root; import javax.validation.constraints.NotNull; -import org.eclipse.hawkbit.Constants; import org.eclipse.hawkbit.eventbus.event.CancelTargetAssignmentEvent; -import org.eclipse.hawkbit.eventbus.event.TargetAssignDistributionSetEvent; -import org.eclipse.hawkbit.eventbus.event.TargetInfoUpdateEvent; -import org.eclipse.hawkbit.executor.AfterTransactionCommitExecutor; import org.eclipse.hawkbit.repository.ActionFields; import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.DistributionSetAssignmentResult; import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.TargetWithActionType; +import org.eclipse.hawkbit.repository.eventbus.event.TargetAssignDistributionSetEvent; +import org.eclipse.hawkbit.repository.eventbus.event.TargetInfoUpdateEvent; import org.eclipse.hawkbit.repository.exception.CancelActionNotAllowedException; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.exception.ForceQuitActionNotAllowedException; import org.eclipse.hawkbit.repository.exception.IncompleteDistributionSetException; +import org.eclipse.hawkbit.repository.jpa.configuration.Constants; +import org.eclipse.hawkbit.repository.jpa.executor.AfterTransactionCommitExecutor; import org.eclipse.hawkbit.repository.jpa.model.JpaAction; import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus; import org.eclipse.hawkbit.repository.jpa.model.JpaActionWithStatusCount; @@ -54,6 +54,7 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaRollout_; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo; +import org.eclipse.hawkbit.repository.jpa.repository.rsql.RSQLUtility; import org.eclipse.hawkbit.repository.jpa.specifications.TargetSpecifications; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.ActionType; @@ -68,7 +69,6 @@ import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; -import org.eclipse.hawkbit.repository.rsql.RSQLUtility; import org.eclipse.hawkbit.security.SystemSecurityContext; import org.hibernate.validator.constraints.NotEmpty; import org.slf4j.Logger; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java index 66bb9037d..8398832b6 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java @@ -22,8 +22,6 @@ import java.util.stream.Collectors; import javax.persistence.EntityManager; -import org.eclipse.hawkbit.eventbus.event.DistributionSetTagAssigmentResultEvent; -import org.eclipse.hawkbit.executor.AfterTransactionCommitExecutor; import org.eclipse.hawkbit.repository.DistributionSetFields; import org.eclipse.hawkbit.repository.DistributionSetFilter; import org.eclipse.hawkbit.repository.DistributionSetFilter.DistributionSetFilterBuilder; @@ -32,10 +30,12 @@ import org.eclipse.hawkbit.repository.DistributionSetMetadataFields; import org.eclipse.hawkbit.repository.DistributionSetTypeFields; import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.repository.TagManagement; +import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetTagAssigmentResultEvent; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.exception.EntityLockedException; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.exception.EntityReadOnlyException; +import org.eclipse.hawkbit.repository.jpa.executor.AfterTransactionCommitExecutor; import org.eclipse.hawkbit.repository.jpa.model.DsMetadataCompositeKey; import org.eclipse.hawkbit.repository.jpa.model.JpaAction; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; @@ -43,6 +43,7 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetMetadata; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetMetadata_; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet_; +import org.eclipse.hawkbit.repository.jpa.repository.rsql.RSQLUtility; import org.eclipse.hawkbit.repository.jpa.specifications.DistributionSetSpecification; import org.eclipse.hawkbit.repository.jpa.specifications.DistributionSetTypeSpecification; import org.eclipse.hawkbit.repository.jpa.specifications.SpecificationsBuilder; @@ -53,7 +54,6 @@ import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult; import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.SoftwareModule; -import org.eclipse.hawkbit.repository.rsql.RSQLUtility; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaReportManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaReportManagement.java index bada97a7b..76eb04a34 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaReportManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaReportManagement.java @@ -29,10 +29,6 @@ import javax.persistence.criteria.JoinType; import javax.persistence.criteria.ListJoin; import javax.persistence.criteria.Root; -import org.eclipse.hawkbit.report.model.DataReportSeries; -import org.eclipse.hawkbit.report.model.DataReportSeriesItem; -import org.eclipse.hawkbit.report.model.InnerOuterDataReportSeries; -import org.eclipse.hawkbit.report.model.SeriesTime; import org.eclipse.hawkbit.repository.ReportManagement; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet_; @@ -41,6 +37,10 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo; import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo_; import org.eclipse.hawkbit.repository.jpa.model.JpaTarget_; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; +import org.eclipse.hawkbit.repository.report.model.DataReportSeries; +import org.eclipse.hawkbit.repository.report.model.DataReportSeriesItem; +import org.eclipse.hawkbit.repository.report.model.InnerOuterDataReportSeries; +import org.eclipse.hawkbit.repository.report.model.SeriesTime; import org.eclipse.hawkbit.tenancy.TenantAware; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutGroupManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutGroupManagement.java index cde2a0a15..dce07dc79 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutGroupManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutGroupManagement.java @@ -32,6 +32,7 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; import org.eclipse.hawkbit.repository.jpa.model.JpaTarget_; import org.eclipse.hawkbit.repository.jpa.model.RolloutTargetGroup; import org.eclipse.hawkbit.repository.jpa.model.RolloutTargetGroup_; +import org.eclipse.hawkbit.repository.jpa.repository.rsql.RSQLUtility; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.Rollout.RolloutStatus; @@ -40,7 +41,6 @@ import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetWithActionStatus; import org.eclipse.hawkbit.repository.model.TotalTargetCountActionStatus; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; -import org.eclipse.hawkbit.repository.rsql.RSQLUtility; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java index 6a5b534d1..e2f5ea8aa 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java @@ -18,7 +18,6 @@ import java.util.stream.Collectors; import javax.persistence.EntityManager; -import org.eclipse.hawkbit.cache.CacheWriteNotify; import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.RolloutFields; @@ -26,10 +25,14 @@ import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.TargetWithActionType; import org.eclipse.hawkbit.repository.exception.RolloutIllegalStateException; +import org.eclipse.hawkbit.repository.jpa.cache.CacheWriteNotify; import org.eclipse.hawkbit.repository.jpa.model.JpaRollout; import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup; import org.eclipse.hawkbit.repository.jpa.model.JpaRollout_; import org.eclipse.hawkbit.repository.jpa.model.RolloutTargetGroup; +import org.eclipse.hawkbit.repository.jpa.repository.rsql.RSQLUtility; +import org.eclipse.hawkbit.repository.jpa.rollout.condition.RolloutGroupActionEvaluator; +import org.eclipse.hawkbit.repository.jpa.rollout.condition.RolloutGroupConditionEvaluator; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.ActionType; import org.eclipse.hawkbit.repository.model.DistributionSet; @@ -43,9 +46,6 @@ import org.eclipse.hawkbit.repository.model.RolloutGroupConditions; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TotalTargetCountActionStatus; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; -import org.eclipse.hawkbit.repository.rsql.RSQLUtility; -import org.eclipse.hawkbit.rollout.condition.RolloutGroupActionEvaluator; -import org.eclipse.hawkbit.rollout.condition.RolloutGroupConditionEvaluator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeansException; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java index 05a38d428..ff3783783 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java @@ -41,6 +41,7 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleMetadata_; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule_; import org.eclipse.hawkbit.repository.jpa.model.SwMetadataCompositeKey; +import org.eclipse.hawkbit.repository.jpa.repository.rsql.RSQLUtility; import org.eclipse.hawkbit.repository.jpa.specifications.SoftwareModuleSpecification; import org.eclipse.hawkbit.repository.jpa.specifications.SpecificationsBuilder; import org.eclipse.hawkbit.repository.model.AssignedSoftwareModule; @@ -49,7 +50,6 @@ import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; -import org.eclipse.hawkbit.repository.rsql.RSQLUtility; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.AuditorAware; import org.springframework.data.domain.Page; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java index 1acbd0f1b..05d5d486e 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java @@ -16,7 +16,6 @@ import java.util.stream.Collectors; import javax.persistence.EntityManager; import org.eclipse.hawkbit.cache.TenancyCacheManager; -import org.eclipse.hawkbit.report.model.SystemUsageReport; import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.repository.TenantStatsManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; @@ -26,6 +25,7 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaTenantMetaData; import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.repository.model.TenantMetaData; +import org.eclipse.hawkbit.repository.report.model.SystemUsageReport; import org.eclipse.hawkbit.tenancy.TenantAware; import org.eclipse.persistence.config.PersistenceUnitProperties; import org.springframework.beans.factory.annotation.Autowired; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTagManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTagManagement.java index c8358b7ec..dd10ffce8 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTagManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTagManagement.java @@ -15,23 +15,23 @@ import java.util.Collection; import java.util.LinkedList; import java.util.List; -import org.eclipse.hawkbit.eventbus.event.DistributionSetTagCreatedBulkEvent; -import org.eclipse.hawkbit.eventbus.event.DistributionSetTagDeletedEvent; -import org.eclipse.hawkbit.eventbus.event.DistributionSetTagUpdateEvent; -import org.eclipse.hawkbit.eventbus.event.TargetTagCreatedBulkEvent; -import org.eclipse.hawkbit.eventbus.event.TargetTagDeletedEvent; -import org.eclipse.hawkbit.eventbus.event.TargetTagUpdateEvent; -import org.eclipse.hawkbit.executor.AfterTransactionCommitExecutor; import org.eclipse.hawkbit.repository.TagFields; import org.eclipse.hawkbit.repository.TagManagement; +import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetTagCreatedBulkEvent; +import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetTagDeletedEvent; +import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetTagUpdateEvent; +import org.eclipse.hawkbit.repository.eventbus.event.TargetTagCreatedBulkEvent; +import org.eclipse.hawkbit.repository.eventbus.event.TargetTagDeletedEvent; +import org.eclipse.hawkbit.repository.eventbus.event.TargetTagUpdateEvent; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; +import org.eclipse.hawkbit.repository.jpa.executor.AfterTransactionCommitExecutor; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag; import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag; +import org.eclipse.hawkbit.repository.jpa.repository.rsql.RSQLUtility; import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.TargetTag; -import org.eclipse.hawkbit.repository.rsql.RSQLUtility; import org.eclipse.hawkbit.tenancy.TenantAware; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetManagement.java index d73a9ae5f..e5be3d7c3 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetManagement.java @@ -27,18 +27,19 @@ import javax.persistence.criteria.Order; import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Root; -import org.eclipse.hawkbit.Constants; -import org.eclipse.hawkbit.eventbus.event.TargetTagAssigmentResultEvent; -import org.eclipse.hawkbit.executor.AfterTransactionCommitExecutor; import org.eclipse.hawkbit.repository.TargetFields; import org.eclipse.hawkbit.repository.TargetManagement; +import org.eclipse.hawkbit.repository.eventbus.event.TargetTagAssigmentResultEvent; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; +import org.eclipse.hawkbit.repository.jpa.configuration.Constants; +import org.eclipse.hawkbit.repository.jpa.executor.AfterTransactionCommitExecutor; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet_; import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo; import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo_; import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag; import org.eclipse.hawkbit.repository.jpa.model.JpaTarget_; +import org.eclipse.hawkbit.repository.jpa.repository.rsql.RSQLUtility; import org.eclipse.hawkbit.repository.jpa.specifications.SpecificationsBuilder; import org.eclipse.hawkbit.repository.jpa.specifications.TargetSpecifications; import org.eclipse.hawkbit.repository.model.Target; @@ -47,7 +48,6 @@ import org.eclipse.hawkbit.repository.model.TargetIdName; import org.eclipse.hawkbit.repository.model.TargetTag; import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; -import org.eclipse.hawkbit.repository.rsql.RSQLUtility; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheEvict; import org.springframework.data.domain.Page; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTenantStatsManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTenantStatsManagement.java index 5c9cb7223..e3866a8ad 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTenantStatsManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTenantStatsManagement.java @@ -10,8 +10,8 @@ package org.eclipse.hawkbit.repository.jpa; import java.util.Optional; -import org.eclipse.hawkbit.report.model.TenantUsage; import org.eclipse.hawkbit.repository.TenantStatsManagement; +import org.eclipse.hawkbit.repository.report.model.TenantUsage; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Isolation; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/aspects/ExceptionMappingAspectHandler.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/aspects/ExceptionMappingAspectHandler.java similarity index 99% rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/aspects/ExceptionMappingAspectHandler.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/aspects/ExceptionMappingAspectHandler.java index c3da509aa..be21cdfe7 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/aspects/ExceptionMappingAspectHandler.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/aspects/ExceptionMappingAspectHandler.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.aspects; +package org.eclipse.hawkbit.repository.jpa.aspects; import java.sql.SQLException; import java.util.ArrayList; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/cache/CacheField.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/cache/CacheField.java similarity index 89% rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/cache/CacheField.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/cache/CacheField.java index 8909c1125..04627f920 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/cache/CacheField.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/cache/CacheField.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.cache; +package org.eclipse.hawkbit.repository.jpa.cache; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.RetentionPolicy.RUNTIME; @@ -14,7 +14,7 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Retention; import java.lang.annotation.Target; -import org.eclipse.hawkbit.eventbus.CacheFieldEntityListener; +import org.eclipse.hawkbit.repository.jpa.eventbus.CacheFieldEntityListener; import org.springframework.cache.CacheManager; import org.springframework.data.annotation.Transient; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/cache/CacheKeys.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/cache/CacheKeys.java similarity index 92% rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/cache/CacheKeys.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/cache/CacheKeys.java index 9cb53a317..9ba7cc763 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/cache/CacheKeys.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/cache/CacheKeys.java @@ -6,9 +6,9 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.cache; +package org.eclipse.hawkbit.repository.jpa.cache; -import org.eclipse.hawkbit.eventbus.CacheFieldEntityListener; +import org.eclipse.hawkbit.repository.jpa.eventbus.CacheFieldEntityListener; /** * Constants for cache keys used in multiple classes. diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/cache/CacheWriteNotify.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/cache/CacheWriteNotify.java similarity index 97% rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/cache/CacheWriteNotify.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/cache/CacheWriteNotify.java index bf690e07e..fdaf868e8 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/cache/CacheWriteNotify.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/cache/CacheWriteNotify.java @@ -6,10 +6,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.cache; +package org.eclipse.hawkbit.repository.jpa.cache; import org.eclipse.hawkbit.eventbus.event.DownloadProgressEvent; -import org.eclipse.hawkbit.eventbus.event.RolloutGroupCreatedEvent; +import org.eclipse.hawkbit.repository.eventbus.event.RolloutGroupCreatedEvent; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.ActionStatus; import org.eclipse.hawkbit.repository.model.Rollout; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/Constants.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/configuration/Constants.java similarity index 94% rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/Constants.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/configuration/Constants.java index ef0b70438..fb6a319f9 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/Constants.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/configuration/Constants.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit; +package org.eclipse.hawkbit.repository.jpa.configuration; /** * A constant class which holds only static constants used within the SP server. diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/MultiTenantJpaTransactionManager.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/configuration/MultiTenantJpaTransactionManager.java similarity index 96% rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/MultiTenantJpaTransactionManager.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/configuration/MultiTenantJpaTransactionManager.java index b3821e5f3..e8547c52b 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/MultiTenantJpaTransactionManager.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/configuration/MultiTenantJpaTransactionManager.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit; +package org.eclipse.hawkbit.repository.jpa.configuration; import javax.persistence.EntityManager; import javax.transaction.Transaction; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/configuration/RepositoryApplicationConfiguration.java similarity index 88% rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/configuration/RepositoryApplicationConfiguration.java index 255561be3..aaed3e64e 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/configuration/RepositoryApplicationConfiguration.java @@ -6,21 +6,21 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit; +package org.eclipse.hawkbit.repository.jpa.configuration; import java.util.HashMap; import java.util.Map; -import org.eclipse.hawkbit.aspects.ExceptionMappingAspectHandler; import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; -import org.eclipse.hawkbit.repository.model.helper.AfterTransactionCommitExecutorHolder; -import org.eclipse.hawkbit.repository.model.helper.CacheManagerHolder; -import org.eclipse.hawkbit.repository.model.helper.SecurityTokenGeneratorHolder; -import org.eclipse.hawkbit.repository.model.helper.SystemManagementHolder; -import org.eclipse.hawkbit.repository.model.helper.SystemSecurityContextHolder; -import org.eclipse.hawkbit.repository.model.helper.TenantAwareHolder; -import org.eclipse.hawkbit.repository.model.helper.TenantConfigurationManagementHolder; +import org.eclipse.hawkbit.repository.jpa.aspects.ExceptionMappingAspectHandler; +import org.eclipse.hawkbit.repository.jpa.repository.model.helper.AfterTransactionCommitExecutorHolder; +import org.eclipse.hawkbit.repository.jpa.repository.model.helper.CacheManagerHolder; +import org.eclipse.hawkbit.repository.jpa.repository.model.helper.SecurityTokenGeneratorHolder; +import org.eclipse.hawkbit.repository.jpa.repository.model.helper.SystemManagementHolder; +import org.eclipse.hawkbit.repository.jpa.repository.model.helper.SystemSecurityContextHolder; +import org.eclipse.hawkbit.repository.jpa.repository.model.helper.TenantAwareHolder; +import org.eclipse.hawkbit.repository.jpa.repository.model.helper.TenantConfigurationManagementHolder; import org.eclipse.hawkbit.security.SecurityTokenGenerator; import org.eclipse.hawkbit.security.SystemSecurityContext; import org.eclipse.hawkbit.tenancy.TenantAware; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/eventbus/CacheFieldEntityListener.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/eventbus/CacheFieldEntityListener.java similarity index 95% rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/eventbus/CacheFieldEntityListener.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/eventbus/CacheFieldEntityListener.java index 7275cb4ec..20c5b0caa 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/eventbus/CacheFieldEntityListener.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/eventbus/CacheFieldEntityListener.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.eventbus; +package org.eclipse.hawkbit.repository.jpa.eventbus; import java.io.Serializable; import java.lang.reflect.Field; @@ -15,9 +15,9 @@ import javax.persistence.PostLoad; import javax.persistence.PostRemove; import org.apache.commons.lang3.reflect.FieldUtils; -import org.eclipse.hawkbit.cache.CacheField; -import org.eclipse.hawkbit.cache.CacheKeys; -import org.eclipse.hawkbit.repository.model.helper.CacheManagerHolder; +import org.eclipse.hawkbit.repository.jpa.cache.CacheField; +import org.eclipse.hawkbit.repository.jpa.cache.CacheKeys; +import org.eclipse.hawkbit.repository.jpa.repository.model.helper.CacheManagerHolder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.cache.Cache; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/eventbus/EntityChangeEventListener.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/eventbus/EntityChangeEventListener.java similarity index 95% rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/eventbus/EntityChangeEventListener.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/eventbus/EntityChangeEventListener.java index 0c33435d2..5f41063d2 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/eventbus/EntityChangeEventListener.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/eventbus/EntityChangeEventListener.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.eventbus; +package org.eclipse.hawkbit.repository.jpa.eventbus; import java.util.Collection; @@ -15,11 +15,11 @@ import javax.persistence.EntityManager; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; -import org.eclipse.hawkbit.eventbus.event.TargetCreatedEvent; import org.eclipse.hawkbit.eventbus.event.TargetDeletedEvent; -import org.eclipse.hawkbit.eventbus.event.TargetInfoUpdateEvent; -import org.eclipse.hawkbit.executor.AfterTransactionCommitExecutor; +import org.eclipse.hawkbit.repository.eventbus.event.TargetCreatedEvent; +import org.eclipse.hawkbit.repository.eventbus.event.TargetInfoUpdateEvent; import org.eclipse.hawkbit.repository.jpa.TargetRepository; +import org.eclipse.hawkbit.repository.jpa.executor.AfterTransactionCommitExecutor; import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetInfo; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/eventbus/EntityPropertyChangeListener.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/eventbus/EntityPropertyChangeListener.java similarity index 83% rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/eventbus/EntityPropertyChangeListener.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/eventbus/EntityPropertyChangeListener.java index 28b5e677c..35cfd9f5e 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/eventbus/EntityPropertyChangeListener.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/eventbus/EntityPropertyChangeListener.java @@ -6,23 +6,23 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.eventbus; +package org.eclipse.hawkbit.repository.jpa.eventbus; import java.util.Map; import java.util.stream.Collectors; -import org.eclipse.hawkbit.eventbus.event.AbstractPropertyChangeEvent; -import org.eclipse.hawkbit.eventbus.event.ActionCreatedEvent; -import org.eclipse.hawkbit.eventbus.event.ActionPropertyChangeEvent; -import org.eclipse.hawkbit.eventbus.event.RolloutGroupPropertyChangeEvent; -import org.eclipse.hawkbit.eventbus.event.RolloutPropertyChangeEvent; -import org.eclipse.hawkbit.executor.AfterTransactionCommitExecutor; +import org.eclipse.hawkbit.repository.eventbus.event.AbstractPropertyChangeEvent; +import org.eclipse.hawkbit.repository.eventbus.event.ActionCreatedEvent; +import org.eclipse.hawkbit.repository.eventbus.event.ActionPropertyChangeEvent; +import org.eclipse.hawkbit.repository.eventbus.event.RolloutGroupPropertyChangeEvent; +import org.eclipse.hawkbit.repository.eventbus.event.RolloutPropertyChangeEvent; +import org.eclipse.hawkbit.repository.jpa.executor.AfterTransactionCommitExecutor; +import org.eclipse.hawkbit.repository.jpa.repository.model.helper.AfterTransactionCommitExecutorHolder; +import org.eclipse.hawkbit.repository.jpa.repository.model.helper.EventBusHolder; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.RolloutGroup; import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity; -import org.eclipse.hawkbit.repository.model.helper.AfterTransactionCommitExecutorHolder; -import org.eclipse.hawkbit.repository.model.helper.EventBusHolder; import org.eclipse.persistence.descriptors.DescriptorEvent; import org.eclipse.persistence.descriptors.DescriptorEventAdapter; import org.eclipse.persistence.internal.sessions.ObjectChangeSet; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/eventbus/EventMerger.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/eventbus/EventMerger.java similarity index 92% rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/eventbus/EventMerger.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/eventbus/EventMerger.java index b4ebdb743..702555be8 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/eventbus/EventMerger.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/eventbus/EventMerger.java @@ -6,21 +6,21 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.eventbus; +package org.eclipse.hawkbit.repository.jpa.eventbus; import java.util.Iterator; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import org.eclipse.hawkbit.eventbus.EventSubscriber; -import org.eclipse.hawkbit.eventbus.event.ActionCreatedEvent; -import org.eclipse.hawkbit.eventbus.event.ActionPropertyChangeEvent; import org.eclipse.hawkbit.eventbus.event.Event; -import org.eclipse.hawkbit.eventbus.event.RolloutChangeEvent; -import org.eclipse.hawkbit.eventbus.event.RolloutGroupChangeEvent; -import org.eclipse.hawkbit.eventbus.event.RolloutGroupCreatedEvent; -import org.eclipse.hawkbit.eventbus.event.RolloutGroupPropertyChangeEvent; -import org.eclipse.hawkbit.eventbus.event.RolloutPropertyChangeEvent; +import org.eclipse.hawkbit.repository.eventbus.event.ActionCreatedEvent; +import org.eclipse.hawkbit.repository.eventbus.event.ActionPropertyChangeEvent; +import org.eclipse.hawkbit.repository.eventbus.event.RolloutChangeEvent; +import org.eclipse.hawkbit.repository.eventbus.event.RolloutGroupChangeEvent; +import org.eclipse.hawkbit.repository.eventbus.event.RolloutGroupCreatedEvent; +import org.eclipse.hawkbit.repository.eventbus.event.RolloutGroupPropertyChangeEvent; +import org.eclipse.hawkbit.repository.eventbus.event.RolloutPropertyChangeEvent; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.RolloutGroup; import org.springframework.beans.factory.annotation.Autowired; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/executor/AfterTransactionCommitDefaultServiceExecutor.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/executor/AfterTransactionCommitDefaultServiceExecutor.java similarity index 98% rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/executor/AfterTransactionCommitDefaultServiceExecutor.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/executor/AfterTransactionCommitDefaultServiceExecutor.java index 0d65b291e..687c1e3d4 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/executor/AfterTransactionCommitDefaultServiceExecutor.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/executor/AfterTransactionCommitDefaultServiceExecutor.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.executor; +package org.eclipse.hawkbit.repository.jpa.executor; import java.util.ArrayList; import java.util.List; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/executor/AfterTransactionCommitExecutor.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/executor/AfterTransactionCommitExecutor.java similarity index 93% rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/executor/AfterTransactionCommitExecutor.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/executor/AfterTransactionCommitExecutor.java index ab5c67bab..34b0e8d5f 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/executor/AfterTransactionCommitExecutor.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/executor/AfterTransactionCommitExecutor.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.executor; +package org.eclipse.hawkbit.repository.jpa.executor; /** * diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaBaseEntity.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaBaseEntity.java index b7e340085..c99993158 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaBaseEntity.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaBaseEntity.java @@ -18,8 +18,8 @@ import javax.persistence.Id; import javax.persistence.MappedSuperclass; import javax.persistence.Version; -import org.eclipse.hawkbit.eventbus.CacheFieldEntityListener; -import org.eclipse.hawkbit.eventbus.EntityPropertyChangeListener; +import org.eclipse.hawkbit.repository.jpa.eventbus.CacheFieldEntityListener; +import org.eclipse.hawkbit.repository.jpa.eventbus.EntityPropertyChangeListener; import org.eclipse.hawkbit.repository.model.BaseEntity; import org.springframework.data.annotation.CreatedBy; import org.springframework.data.annotation.CreatedDate; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaTenantAwareBaseEntity.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaTenantAwareBaseEntity.java index 134d0c788..235687d1f 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaTenantAwareBaseEntity.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaTenantAwareBaseEntity.java @@ -13,9 +13,9 @@ import javax.persistence.MappedSuperclass; import javax.persistence.PrePersist; import org.eclipse.hawkbit.repository.exception.TenantNotExistException; +import org.eclipse.hawkbit.repository.jpa.repository.model.helper.SystemManagementHolder; +import org.eclipse.hawkbit.repository.jpa.repository.model.helper.TenantAwareHolder; import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity; -import org.eclipse.hawkbit.repository.model.helper.SystemManagementHolder; -import org.eclipse.hawkbit.repository.model.helper.TenantAwareHolder; import org.eclipse.persistence.annotations.Multitenant; import org.eclipse.persistence.annotations.MultitenantType; import org.eclipse.persistence.annotations.TenantDiscriminatorColumn; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaAction.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaAction.java index 7ad7d7a60..e0cde5416 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaAction.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaAction.java @@ -29,8 +29,8 @@ import javax.persistence.OneToMany; import javax.persistence.Table; import javax.persistence.Transient; -import org.eclipse.hawkbit.cache.CacheField; -import org.eclipse.hawkbit.cache.CacheKeys; +import org.eclipse.hawkbit.repository.jpa.cache.CacheField; +import org.eclipse.hawkbit.repository.jpa.cache.CacheKeys; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.ActionStatus; import org.eclipse.hawkbit.repository.model.DistributionSet; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRollout.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRollout.java index 40622134f..ae68fec03 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRollout.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRollout.java @@ -25,8 +25,8 @@ import javax.persistence.Table; import javax.persistence.Transient; import javax.persistence.UniqueConstraint; -import org.eclipse.hawkbit.cache.CacheField; -import org.eclipse.hawkbit.cache.CacheKeys; +import org.eclipse.hawkbit.repository.jpa.cache.CacheField; +import org.eclipse.hawkbit.repository.jpa.cache.CacheKeys; import org.eclipse.hawkbit.repository.model.Action.ActionType; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Rollout; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTarget.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTarget.java index f89eeb184..24cabf7d4 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTarget.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTarget.java @@ -36,14 +36,14 @@ import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; import org.eclipse.hawkbit.im.authentication.SpPermission; +import org.eclipse.hawkbit.repository.jpa.repository.model.helper.SecurityChecker; +import org.eclipse.hawkbit.repository.jpa.repository.model.helper.SecurityTokenGeneratorHolder; +import org.eclipse.hawkbit.repository.jpa.repository.model.helper.SystemSecurityContextHolder; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetInfo; import org.eclipse.hawkbit.repository.model.TargetTag; -import org.eclipse.hawkbit.repository.model.helper.SecurityChecker; -import org.eclipse.hawkbit.repository.model.helper.SecurityTokenGeneratorHolder; -import org.eclipse.hawkbit.repository.model.helper.SystemSecurityContextHolder; import org.eclipse.persistence.annotations.CascadeOnDelete; import org.springframework.data.domain.Persistable; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetInfo.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetInfo.java index 80e3cd563..ce7074443 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetInfo.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetInfo.java @@ -37,13 +37,13 @@ import javax.persistence.OneToOne; import javax.persistence.Table; import javax.persistence.Transient; +import org.eclipse.hawkbit.repository.jpa.repository.model.helper.SystemSecurityContextHolder; +import org.eclipse.hawkbit.repository.jpa.repository.model.helper.TenantConfigurationManagementHolder; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.PollStatus; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetInfo; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; -import org.eclipse.hawkbit.repository.model.helper.SystemSecurityContextHolder; -import org.eclipse.hawkbit.repository.model.helper.TenantConfigurationManagementHolder; import org.eclipse.hawkbit.tenancy.configuration.DurationHelper; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; import org.eclipse.persistence.annotations.CascadeOnDelete; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/model/helper/AfterTransactionCommitExecutorHolder.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/AfterTransactionCommitExecutorHolder.java similarity index 86% rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/model/helper/AfterTransactionCommitExecutorHolder.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/AfterTransactionCommitExecutorHolder.java index 1282bc99d..dcd02d30a 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/model/helper/AfterTransactionCommitExecutorHolder.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/AfterTransactionCommitExecutorHolder.java @@ -6,10 +6,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.model.helper; +package org.eclipse.hawkbit.repository.jpa.repository.model.helper; -import org.eclipse.hawkbit.eventbus.EntityPropertyChangeListener; -import org.eclipse.hawkbit.executor.AfterTransactionCommitExecutor; +import org.eclipse.hawkbit.repository.jpa.eventbus.EntityPropertyChangeListener; +import org.eclipse.hawkbit.repository.jpa.executor.AfterTransactionCommitExecutor; import org.springframework.beans.factory.annotation.Autowired; /** diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/model/helper/CacheManagerHolder.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/CacheManagerHolder.java similarity index 91% rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/model/helper/CacheManagerHolder.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/CacheManagerHolder.java index c8c081d95..b380ced8f 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/model/helper/CacheManagerHolder.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/CacheManagerHolder.java @@ -6,9 +6,9 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.model.helper; +package org.eclipse.hawkbit.repository.jpa.repository.model.helper; -import org.eclipse.hawkbit.eventbus.CacheFieldEntityListener; +import org.eclipse.hawkbit.repository.jpa.eventbus.CacheFieldEntityListener; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.CacheManager; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/model/helper/EventBusHolder.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/EventBusHolder.java similarity index 89% rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/model/helper/EventBusHolder.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/EventBusHolder.java index 8111a1c28..0b0a54829 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/model/helper/EventBusHolder.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/EventBusHolder.java @@ -6,9 +6,9 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.model.helper; +package org.eclipse.hawkbit.repository.jpa.repository.model.helper; -import org.eclipse.hawkbit.eventbus.CacheFieldEntityListener; +import org.eclipse.hawkbit.repository.jpa.eventbus.CacheFieldEntityListener; import org.springframework.beans.factory.annotation.Autowired; import com.google.common.eventbus.EventBus; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/model/helper/SecurityChecker.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/SecurityChecker.java similarity index 96% rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/model/helper/SecurityChecker.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/SecurityChecker.java index 7c9763e6d..54448cf2b 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/model/helper/SecurityChecker.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/SecurityChecker.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.model.helper; +package org.eclipse.hawkbit.repository.jpa.repository.model.helper; import org.springframework.security.core.Authentication; import org.springframework.security.core.GrantedAuthority; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/model/helper/SecurityTokenGeneratorHolder.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/SecurityTokenGeneratorHolder.java similarity index 95% rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/model/helper/SecurityTokenGeneratorHolder.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/SecurityTokenGeneratorHolder.java index ffc1e308f..10191b9e1 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/model/helper/SecurityTokenGeneratorHolder.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/SecurityTokenGeneratorHolder.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.model.helper; +package org.eclipse.hawkbit.repository.jpa.repository.model.helper; import org.eclipse.hawkbit.security.SecurityTokenGenerator; import org.springframework.beans.factory.annotation.Autowired; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/model/helper/SystemManagementHolder.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/SystemManagementHolder.java similarity index 95% rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/model/helper/SystemManagementHolder.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/SystemManagementHolder.java index d1327c690..7365fec90 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/model/helper/SystemManagementHolder.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/SystemManagementHolder.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.model.helper; +package org.eclipse.hawkbit.repository.jpa.repository.model.helper; import org.eclipse.hawkbit.repository.SystemManagement; import org.springframework.beans.factory.annotation.Autowired; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/model/helper/SystemSecurityContextHolder.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/SystemSecurityContextHolder.java similarity index 94% rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/model/helper/SystemSecurityContextHolder.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/SystemSecurityContextHolder.java index 7d005e9bc..f6b20a3fd 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/model/helper/SystemSecurityContextHolder.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/SystemSecurityContextHolder.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.model.helper; +package org.eclipse.hawkbit.repository.jpa.repository.model.helper; import org.eclipse.hawkbit.security.SystemSecurityContext; import org.springframework.beans.factory.annotation.Autowired; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/model/helper/TenantAwareHolder.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/TenantAwareHolder.java similarity index 94% rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/model/helper/TenantAwareHolder.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/TenantAwareHolder.java index 5b85745d7..c4ded314d 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/model/helper/TenantAwareHolder.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/TenantAwareHolder.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.model.helper; +package org.eclipse.hawkbit.repository.jpa.repository.model.helper; import org.eclipse.hawkbit.tenancy.TenantAware; import org.springframework.beans.factory.annotation.Autowired; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/model/helper/TenantConfigurationManagementHolder.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/TenantConfigurationManagementHolder.java similarity index 95% rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/model/helper/TenantConfigurationManagementHolder.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/TenantConfigurationManagementHolder.java index 700511db6..8fbcb2411 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/model/helper/TenantConfigurationManagementHolder.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/TenantConfigurationManagementHolder.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.model.helper; +package org.eclipse.hawkbit.repository.jpa.repository.model.helper; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; import org.springframework.beans.factory.annotation.Autowired; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/rsql/PropertyMapper.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/rsql/PropertyMapper.java similarity index 95% rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/rsql/PropertyMapper.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/rsql/PropertyMapper.java index ffa0e9212..85051d192 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/rsql/PropertyMapper.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/rsql/PropertyMapper.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.rsql; +package org.eclipse.hawkbit.repository.jpa.repository.rsql; import java.util.HashMap; import java.util.Map; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/rsql/RSQLUtility.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/rsql/RSQLUtility.java similarity index 99% rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/rsql/RSQLUtility.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/rsql/RSQLUtility.java index 87883f91f..c8b796e2d 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/rsql/RSQLUtility.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/rsql/RSQLUtility.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.rsql; +package org.eclipse.hawkbit.repository.jpa.repository.rsql; import java.util.ArrayList; import java.util.Arrays; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/rollout/condition/PauseRolloutGroupAction.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rollout/condition/PauseRolloutGroupAction.java similarity index 96% rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/rollout/condition/PauseRolloutGroupAction.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rollout/condition/PauseRolloutGroupAction.java index 43232ef2d..e20f632f8 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/rollout/condition/PauseRolloutGroupAction.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rollout/condition/PauseRolloutGroupAction.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.rollout.condition; +package org.eclipse.hawkbit.repository.jpa.rollout.condition; import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.jpa.RolloutGroupRepository; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/rollout/condition/RolloutGroupActionEvaluator.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rollout/condition/RolloutGroupActionEvaluator.java similarity index 91% rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/rollout/condition/RolloutGroupActionEvaluator.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rollout/condition/RolloutGroupActionEvaluator.java index 1e2c98707..d375e68c5 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/rollout/condition/RolloutGroupActionEvaluator.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rollout/condition/RolloutGroupActionEvaluator.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.rollout.condition; +package org.eclipse.hawkbit.repository.jpa.rollout.condition; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.RolloutGroup; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/rollout/condition/RolloutGroupConditionEvaluator.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rollout/condition/RolloutGroupConditionEvaluator.java similarity index 94% rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/rollout/condition/RolloutGroupConditionEvaluator.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rollout/condition/RolloutGroupConditionEvaluator.java index 62c9050b1..642386c69 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/rollout/condition/RolloutGroupConditionEvaluator.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rollout/condition/RolloutGroupConditionEvaluator.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.rollout.condition; +package org.eclipse.hawkbit.repository.jpa.rollout.condition; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.RolloutGroup; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/rollout/condition/StartNextGroupRolloutGroupSuccessAction.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rollout/condition/StartNextGroupRolloutGroupSuccessAction.java similarity index 98% rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/rollout/condition/StartNextGroupRolloutGroupSuccessAction.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rollout/condition/StartNextGroupRolloutGroupSuccessAction.java index 0f1d1376f..e12a26bac 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/rollout/condition/StartNextGroupRolloutGroupSuccessAction.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rollout/condition/StartNextGroupRolloutGroupSuccessAction.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.rollout.condition; +package org.eclipse.hawkbit.repository.jpa.rollout.condition; import java.util.List; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/rollout/condition/ThresholdRolloutGroupErrorCondition.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rollout/condition/ThresholdRolloutGroupErrorCondition.java similarity index 97% rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/rollout/condition/ThresholdRolloutGroupErrorCondition.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rollout/condition/ThresholdRolloutGroupErrorCondition.java index 32e9725f8..cba134402 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/rollout/condition/ThresholdRolloutGroupErrorCondition.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rollout/condition/ThresholdRolloutGroupErrorCondition.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.rollout.condition; +package org.eclipse.hawkbit.repository.jpa.rollout.condition; import org.eclipse.hawkbit.repository.jpa.ActionRepository; import org.eclipse.hawkbit.repository.jpa.model.JpaRollout; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/rollout/condition/ThresholdRolloutGroupSuccessCondition.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rollout/condition/ThresholdRolloutGroupSuccessCondition.java similarity index 97% rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/rollout/condition/ThresholdRolloutGroupSuccessCondition.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rollout/condition/ThresholdRolloutGroupSuccessCondition.java index 5f9167931..3e098c701 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/rollout/condition/ThresholdRolloutGroupSuccessCondition.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rollout/condition/ThresholdRolloutGroupSuccessCondition.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.rollout.condition; +package org.eclipse.hawkbit.repository.jpa.rollout.condition; import org.eclipse.hawkbit.repository.jpa.ActionRepository; import org.eclipse.hawkbit.repository.model.Action; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/AbstractIntegrationTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractIntegrationTest.java similarity index 90% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/AbstractIntegrationTest.java rename to hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractIntegrationTest.java index 96e4aced8..e951f736f 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/AbstractIntegrationTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractIntegrationTest.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit; +package org.eclipse.hawkbit.repository.jpa; import static org.fest.assertions.api.Assertions.assertThat; @@ -15,6 +15,7 @@ import java.util.List; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; +import org.eclipse.hawkbit.ExcludePathAwareShallowETagFilter; import org.eclipse.hawkbit.cache.TenantAwareCacheManager; import org.eclipse.hawkbit.repository.ArtifactManagement; import org.eclipse.hawkbit.repository.ControllerManagement; @@ -28,25 +29,10 @@ import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.TargetFilterQueryManagement; import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; -import org.eclipse.hawkbit.repository.jpa.ActionRepository; -import org.eclipse.hawkbit.repository.jpa.ActionStatusRepository; -import org.eclipse.hawkbit.repository.jpa.DistributionSetRepository; -import org.eclipse.hawkbit.repository.jpa.DistributionSetTagRepository; -import org.eclipse.hawkbit.repository.jpa.DistributionSetTypeRepository; -import org.eclipse.hawkbit.repository.jpa.ExternalArtifactRepository; -import org.eclipse.hawkbit.repository.jpa.LocalArtifactRepository; -import org.eclipse.hawkbit.repository.jpa.RolloutGroupRepository; -import org.eclipse.hawkbit.repository.jpa.RolloutRepository; -import org.eclipse.hawkbit.repository.jpa.SoftwareModuleMetadataRepository; -import org.eclipse.hawkbit.repository.jpa.SoftwareModuleRepository; -import org.eclipse.hawkbit.repository.jpa.SoftwareModuleTypeRepository; -import org.eclipse.hawkbit.repository.jpa.TargetInfoRepository; -import org.eclipse.hawkbit.repository.jpa.TargetRepository; -import org.eclipse.hawkbit.repository.jpa.TargetTagRepository; -import org.eclipse.hawkbit.repository.jpa.TenantMetaDataRepository; +import org.eclipse.hawkbit.repository.jpa.configuration.RepositoryApplicationConfiguration; +import org.eclipse.hawkbit.repository.jpa.utils.RepositoryDataGenerator.DatabaseCleanupUtil; import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; -import org.eclipse.hawkbit.repository.utils.RepositoryDataGenerator.DatabaseCleanupUtil; import org.eclipse.hawkbit.security.DosFilter; import org.eclipse.hawkbit.security.SystemSecurityContext; import org.eclipse.hawkbit.tenancy.TenantAware; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/AbstractIntegrationTestWithMongoDB.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractIntegrationTestWithMongoDB.java similarity index 98% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/AbstractIntegrationTestWithMongoDB.java rename to hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractIntegrationTestWithMongoDB.java index 6d116c5f0..d83f2e5cf 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/AbstractIntegrationTestWithMongoDB.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractIntegrationTestWithMongoDB.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit; +package org.eclipse.hawkbit.repository.jpa; import java.io.IOException; import java.net.UnknownHostException; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/ActionTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ActionTest.java similarity index 97% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/ActionTest.java rename to hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ActionTest.java index 0b8938808..9104f28cf 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/ActionTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ActionTest.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.jpa; import static org.fest.assertions.api.Assertions.assertThat; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/ArtifactManagementNoMongoDbTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementNoMongoDbTest.java similarity index 95% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/ArtifactManagementNoMongoDbTest.java rename to hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementNoMongoDbTest.java index ee1cb3acd..fd91a2158 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/ArtifactManagementNoMongoDbTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementNoMongoDbTest.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.jpa; import static org.junit.Assert.fail; @@ -14,7 +14,6 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import org.apache.commons.lang3.RandomStringUtils; -import org.eclipse.hawkbit.AbstractIntegrationTest; import org.eclipse.hawkbit.repository.exception.ArtifactUploadFailedException; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; import org.junit.BeforeClass; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/ArtifactManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementTest.java similarity index 98% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/ArtifactManagementTest.java rename to hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementTest.java index 7b704af12..4c37c00e3 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/ArtifactManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementTest.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.jpa; import static org.fest.assertions.api.Assertions.assertThat; import static org.junit.Assert.assertNotNull; @@ -20,11 +20,8 @@ import java.security.NoSuchAlgorithmException; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.RandomStringUtils; -import org.eclipse.hawkbit.AbstractIntegrationTestWithMongoDB; -import org.eclipse.hawkbit.HashGeneratorUtils; -import org.eclipse.hawkbit.RandomGeneratedInputStream; -import org.eclipse.hawkbit.WithUser; import org.eclipse.hawkbit.im.authentication.SpPermission; +import org.eclipse.hawkbit.repository.ArtifactManagement; import org.eclipse.hawkbit.repository.exception.ArtifactDeleteFailedException; import org.eclipse.hawkbit.repository.exception.InsufficientPermissionException; import org.eclipse.hawkbit.repository.jpa.model.JpaExternalArtifact; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/CIMySqlTestDatabase.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/CIMySqlTestDatabase.java similarity index 98% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/CIMySqlTestDatabase.java rename to hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/CIMySqlTestDatabase.java index 0a9b4b1b3..c0a8b161c 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/CIMySqlTestDatabase.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/CIMySqlTestDatabase.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit; +package org.eclipse.hawkbit.repository.jpa; import java.sql.Connection; import java.sql.DriverManager; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/ControllerManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ControllerManagementTest.java similarity index 98% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/ControllerManagementTest.java rename to hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ControllerManagementTest.java index 4b2a92169..c79c47af9 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/ControllerManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ControllerManagementTest.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.jpa; import static org.fest.assertions.api.Assertions.assertThat; import static org.junit.Assert.fail; @@ -17,8 +17,6 @@ import java.util.List; import javax.validation.ConstraintViolationException; import org.apache.commons.lang3.RandomStringUtils; -import org.eclipse.hawkbit.AbstractIntegrationTest; -import org.eclipse.hawkbit.TestDataUtil; import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus; import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; import org.eclipse.hawkbit.repository.model.Action; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/DeploymentManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DeploymentManagementTest.java similarity index 99% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/DeploymentManagementTest.java rename to hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DeploymentManagementTest.java index c1b0541f2..0016d4d7d 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/DeploymentManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DeploymentManagementTest.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.jpa; import static org.fest.assertions.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; @@ -21,14 +21,13 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; -import org.eclipse.hawkbit.AbstractIntegrationTest; -import org.eclipse.hawkbit.Constants; -import org.eclipse.hawkbit.TestDataUtil; import org.eclipse.hawkbit.eventbus.event.CancelTargetAssignmentEvent; -import org.eclipse.hawkbit.eventbus.event.TargetAssignDistributionSetEvent; +import org.eclipse.hawkbit.repository.ActionStatusFields; +import org.eclipse.hawkbit.repository.DistributionSetAssignmentResult; +import org.eclipse.hawkbit.repository.eventbus.event.TargetAssignDistributionSetEvent; import org.eclipse.hawkbit.repository.exception.ForceQuitActionNotAllowedException; import org.eclipse.hawkbit.repository.exception.IncompleteDistributionSetException; -import org.eclipse.hawkbit.repository.jpa.TargetRepository; +import org.eclipse.hawkbit.repository.jpa.configuration.Constants; import org.eclipse.hawkbit.repository.jpa.model.JpaAction; import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/DistributionSetManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DistributionSetManagementTest.java similarity index 99% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/DistributionSetManagementTest.java rename to hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DistributionSetManagementTest.java index 5a5518cf3..a29a76086 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/DistributionSetManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DistributionSetManagementTest.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.jpa; import static org.fest.assertions.api.Assertions.assertThat; import static org.junit.Assert.fail; @@ -16,10 +16,8 @@ import java.util.Collection; import java.util.Iterator; import java.util.List; -import org.eclipse.hawkbit.AbstractIntegrationTest; -import org.eclipse.hawkbit.TestDataUtil; -import org.eclipse.hawkbit.WithUser; import org.eclipse.hawkbit.repository.DistributionSetFilter.DistributionSetFilterBuilder; +import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.exception.DistributionSetTypeUndefinedException; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.exception.EntityLockedException; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/FreePortFileWriter.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/FreePortFileWriter.java similarity index 97% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/FreePortFileWriter.java rename to hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/FreePortFileWriter.java index c67928910..8d900a593 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/FreePortFileWriter.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/FreePortFileWriter.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit; +package org.eclipse.hawkbit.repository.jpa; import java.io.File; import java.net.InetSocketAddress; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/HashGeneratorUtils.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/HashGeneratorUtils.java similarity index 98% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/HashGeneratorUtils.java rename to hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/HashGeneratorUtils.java index 10f4ede4c..a94807958 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/HashGeneratorUtils.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/HashGeneratorUtils.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit; +package org.eclipse.hawkbit.repository.jpa; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/LocalH2TestDatabase.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/LocalH2TestDatabase.java similarity index 98% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/LocalH2TestDatabase.java rename to hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/LocalH2TestDatabase.java index a32c481fc..7812527c8 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/LocalH2TestDatabase.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/LocalH2TestDatabase.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit; +package org.eclipse.hawkbit.repository.jpa; import java.io.IOException; import java.sql.Connection; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/MethodSecurityUtil.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/MethodSecurityUtil.java similarity index 98% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/MethodSecurityUtil.java rename to hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/MethodSecurityUtil.java index 6633a27e5..032289e87 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/MethodSecurityUtil.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/MethodSecurityUtil.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit; +package org.eclipse.hawkbit.repository.jpa; import static org.fest.assertions.Assertions.assertThat; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/RandomGeneratedInputStream.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/RandomGeneratedInputStream.java similarity index 96% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/RandomGeneratedInputStream.java rename to hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/RandomGeneratedInputStream.java index bd5be54f5..a7a1c0956 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/RandomGeneratedInputStream.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/RandomGeneratedInputStream.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit; +package org.eclipse.hawkbit.repository.jpa; import java.io.IOException; import java.io.InputStream; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/ReportManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ReportManagementTest.java similarity index 98% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/ReportManagementTest.java rename to hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ReportManagementTest.java index 0a18c0b03..57fc13379 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/ReportManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ReportManagementTest.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.jpa; import static org.fest.assertions.Assertions.assertThat; import static org.fest.assertions.api.Assertions.fail; @@ -20,14 +20,8 @@ import java.util.Calendar; import java.util.List; import java.util.stream.Collectors; -import org.eclipse.hawkbit.AbstractIntegrationTest; -import org.eclipse.hawkbit.TestDataUtil; -import org.eclipse.hawkbit.WithSpringAuthorityRule; -import org.eclipse.hawkbit.WithUser; -import org.eclipse.hawkbit.report.model.DataReportSeries; -import org.eclipse.hawkbit.report.model.DataReportSeriesItem; -import org.eclipse.hawkbit.report.model.InnerOuterDataReportSeries; -import org.eclipse.hawkbit.report.model.SeriesTime; +import org.eclipse.hawkbit.repository.DistributionSetAssignmentResult; +import org.eclipse.hawkbit.repository.ReportManagement; import org.eclipse.hawkbit.repository.ReportManagement.DateTypes; import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; @@ -40,6 +34,10 @@ import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; +import org.eclipse.hawkbit.repository.report.model.DataReportSeries; +import org.eclipse.hawkbit.repository.report.model.DataReportSeriesItem; +import org.eclipse.hawkbit.repository.report.model.InnerOuterDataReportSeries; +import org.eclipse.hawkbit.repository.report.model.SeriesTime; import org.junit.After; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/RolloutManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/RolloutManagementTest.java similarity index 99% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/RolloutManagementTest.java rename to hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/RolloutManagementTest.java index 576315b3a..28ece9239 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/RolloutManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/RolloutManagementTest.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.jpa; import static org.fest.assertions.api.Assertions.assertThat; @@ -16,12 +16,15 @@ import java.util.List; import java.util.Map; import java.util.concurrent.Callable; -import org.eclipse.hawkbit.AbstractIntegrationTest; -import org.eclipse.hawkbit.TestDataUtil; +import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; +import org.eclipse.hawkbit.repository.RolloutGroupManagement; +import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.jpa.model.JpaAction; import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus; import org.eclipse.hawkbit.repository.jpa.model.JpaRollout; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; +import org.eclipse.hawkbit.repository.jpa.utils.MultipleInvokeHelper; +import org.eclipse.hawkbit.repository.jpa.utils.SuccessCondition; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.DistributionSet; @@ -38,8 +41,6 @@ import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; -import org.eclipse.hawkbit.repository.utils.MultipleInvokeHelper; -import org.eclipse.hawkbit.repository.utils.SuccessCondition; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Description; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/SoftwareManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SoftwareManagementTest.java similarity index 99% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/SoftwareManagementTest.java rename to hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SoftwareManagementTest.java index f7943c78b..69e19ea3a 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/SoftwareManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SoftwareManagementTest.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.jpa; import static org.fest.assertions.api.Assertions.assertThat; import static org.junit.Assert.assertTrue; @@ -20,10 +20,6 @@ import java.util.Iterator; import java.util.List; import org.apache.commons.lang3.RandomUtils; -import org.eclipse.hawkbit.AbstractIntegrationTestWithMongoDB; -import org.eclipse.hawkbit.RandomGeneratedInputStream; -import org.eclipse.hawkbit.TestDataUtil; -import org.eclipse.hawkbit.WithUser; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/SystemManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SystemManagementTest.java similarity index 96% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/SystemManagementTest.java rename to hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SystemManagementTest.java index 261b921c8..185416984 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/SystemManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SystemManagementTest.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.jpa; import static org.fest.assertions.api.Assertions.assertThat; @@ -14,13 +14,10 @@ import java.io.ByteArrayInputStream; import java.util.List; import java.util.Random; -import org.eclipse.hawkbit.AbstractIntegrationTestWithMongoDB; -import org.eclipse.hawkbit.TestDataUtil; -import org.eclipse.hawkbit.WithSpringAuthorityRule; -import org.eclipse.hawkbit.report.model.TenantUsage; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Target; +import org.eclipse.hawkbit.repository.report.model.TenantUsage; import org.junit.Test; import ru.yandex.qatools.allure.annotations.Description; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/TagManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TagManagementTest.java similarity index 99% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/TagManagementTest.java rename to hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TagManagementTest.java index 66ea38e77..67c7de049 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/TagManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TagManagementTest.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.jpa; import static org.fest.assertions.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; @@ -18,9 +18,8 @@ import java.util.Collection; import java.util.List; import java.util.stream.Collectors; -import org.eclipse.hawkbit.AbstractIntegrationTest; -import org.eclipse.hawkbit.TestDataUtil; import org.eclipse.hawkbit.repository.DistributionSetFilter.DistributionSetFilterBuilder; +import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag; import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagenmentTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetFilterQueryManagenmentTest.java similarity index 97% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagenmentTest.java rename to hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetFilterQueryManagenmentTest.java index 498364cf9..e2a06d5fc 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagenmentTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetFilterQueryManagenmentTest.java @@ -6,12 +6,12 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.jpa; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; -import org.eclipse.hawkbit.AbstractIntegrationTest; +import org.eclipse.hawkbit.repository.TargetFilterQueryManagement; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.jpa.model.JpaTargetFilterQuery; import org.eclipse.hawkbit.repository.model.TargetFilterQuery; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/TargetManagementSearchTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetManagementSearchTest.java similarity index 99% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/TargetManagementSearchTest.java rename to hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetManagementSearchTest.java index 4ff845e1a..7b128de3b 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/TargetManagementSearchTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetManagementSearchTest.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.jpa; import static org.fest.assertions.api.Assertions.assertThat; @@ -17,8 +17,6 @@ import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; -import org.eclipse.hawkbit.AbstractIntegrationTest; -import org.eclipse.hawkbit.TestDataUtil; import org.eclipse.hawkbit.repository.jpa.model.JpaAction; import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus; import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/TargetManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetManagementTest.java similarity index 99% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/TargetManagementTest.java rename to hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetManagementTest.java index 0f01a5a43..10f614caa 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/TargetManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetManagementTest.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.jpa; import static org.fest.assertions.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; @@ -28,11 +28,8 @@ import java.util.stream.Collectors; import javax.persistence.Query; import javax.validation.ConstraintViolationException; -import org.eclipse.hawkbit.AbstractIntegrationTest; -import org.eclipse.hawkbit.TestDataUtil; -import org.eclipse.hawkbit.WithSpringAuthorityRule; -import org.eclipse.hawkbit.WithUser; import org.eclipse.hawkbit.im.authentication.SpPermission; +import org.eclipse.hawkbit.repository.DistributionSetAssignmentResult; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.exception.TenantNotExistException; import org.eclipse.hawkbit.repository.jpa.model.JpaAction; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/TenantConfigurationManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TenantConfigurationManagementTest.java similarity index 99% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/TenantConfigurationManagementTest.java rename to hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TenantConfigurationManagementTest.java index 1427df25b..0e0d50bbc 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/TenantConfigurationManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TenantConfigurationManagementTest.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.jpa; import static org.fest.assertions.api.Assertions.assertThat; import static org.junit.Assert.fail; @@ -16,7 +16,6 @@ import java.util.Arrays; import java.util.HashMap; import java.util.Map; -import org.eclipse.hawkbit.AbstractIntegrationTestWithMongoDB; import org.eclipse.hawkbit.repository.model.TenantConfigurationValue; import org.eclipse.hawkbit.tenancy.configuration.DurationHelper; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/TestConfiguration.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TestConfiguration.java similarity index 91% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/TestConfiguration.java rename to hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TestConfiguration.java index d96856557..22ae16d6f 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/TestConfiguration.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TestConfiguration.java @@ -6,17 +6,18 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit; +package org.eclipse.hawkbit.repository.jpa; import java.util.concurrent.Executor; import java.util.concurrent.Executors; +import org.eclipse.hawkbit.HawkbitServerProperties; import org.eclipse.hawkbit.cache.CacheConstants; import org.eclipse.hawkbit.cache.TenancyCacheManager; import org.eclipse.hawkbit.cache.TenantAwareCacheManager; -import org.eclipse.hawkbit.repository.model.helper.EventBusHolder; -import org.eclipse.hawkbit.repository.utils.RepositoryDataGenerator; -import org.eclipse.hawkbit.repository.utils.RepositoryDataGenerator.DatabaseCleanupUtil; +import org.eclipse.hawkbit.repository.jpa.repository.model.helper.EventBusHolder; +import org.eclipse.hawkbit.repository.jpa.utils.RepositoryDataGenerator; +import org.eclipse.hawkbit.repository.jpa.utils.RepositoryDataGenerator.DatabaseCleanupUtil; import org.eclipse.hawkbit.security.DdiSecurityProperties; import org.eclipse.hawkbit.security.SecurityContextTenantAware; import org.eclipse.hawkbit.security.SpringSecurityAuditorAware; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/TestDataUtil.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TestDataUtil.java similarity index 99% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/TestDataUtil.java rename to hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TestDataUtil.java index 5992ed1fc..296fb98ea 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/TestDataUtil.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TestDataUtil.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit; +package org.eclipse.hawkbit.repository.jpa; import static org.fest.assertions.api.Assertions.assertThat; @@ -23,7 +23,6 @@ import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.TargetManagement; -import org.eclipse.hawkbit.repository.jpa.ActionRepository; import org.eclipse.hawkbit.repository.jpa.model.AbstractJpaArtifact; import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/Testdatabase.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/Testdatabase.java similarity index 91% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/Testdatabase.java rename to hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/Testdatabase.java index a11984481..38133c800 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/Testdatabase.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/Testdatabase.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit; +package org.eclipse.hawkbit.repository.jpa; /** * diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/WithSpringAuthorityRule.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/WithSpringAuthorityRule.java similarity index 98% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/WithSpringAuthorityRule.java rename to hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/WithSpringAuthorityRule.java index 40f6a64c2..aeacad509 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/WithSpringAuthorityRule.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/WithSpringAuthorityRule.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit; +package org.eclipse.hawkbit.repository.jpa; import java.lang.annotation.Annotation; import java.lang.reflect.Field; @@ -17,7 +17,7 @@ import java.util.concurrent.Callable; import org.eclipse.hawkbit.im.authentication.SpPermission; import org.eclipse.hawkbit.im.authentication.TenantAwareAuthenticationDetails; -import org.eclipse.hawkbit.repository.model.helper.SystemManagementHolder; +import org.eclipse.hawkbit.repository.jpa.repository.model.helper.SystemManagementHolder; import org.junit.rules.TestRule; import org.junit.runner.Description; import org.junit.runners.model.Statement; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/WithUser.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/WithUser.java similarity index 97% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/WithUser.java rename to hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/WithUser.java index 3b0412ff1..0a936f1c0 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/WithUser.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/WithUser.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit; +package org.eclipse.hawkbit.repository.jpa; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/cache/CacheKeysTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/cache/CacheKeysTest.java similarity index 95% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/cache/CacheKeysTest.java rename to hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/cache/CacheKeysTest.java index b0da78abd..921d1953a 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/cache/CacheKeysTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/cache/CacheKeysTest.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.cache; +package org.eclipse.hawkbit.repository.jpa.cache; import static org.fest.assertions.api.Assertions.assertThat; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/cache/CacheWriteNotifyTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/cache/CacheWriteNotifyTest.java similarity index 97% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/cache/CacheWriteNotifyTest.java rename to hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/cache/CacheWriteNotifyTest.java index c88a3e717..603af17c9 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/cache/CacheWriteNotifyTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/cache/CacheWriteNotifyTest.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.cache; +package org.eclipse.hawkbit.repository.jpa.cache; import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/eventbus/CacheFieldEntityListenerTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/eventbus/CacheFieldEntityListenerTest.java similarity index 93% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/eventbus/CacheFieldEntityListenerTest.java rename to hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/eventbus/CacheFieldEntityListenerTest.java index 4943ea88a..4845e2ccc 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/eventbus/CacheFieldEntityListenerTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/eventbus/CacheFieldEntityListenerTest.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.eventbus; +package org.eclipse.hawkbit.repository.jpa.eventbus; import static org.fest.assertions.api.Assertions.assertThat; import static org.mockito.Matchers.anyString; @@ -14,9 +14,9 @@ import static org.mockito.Matchers.eq; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import org.eclipse.hawkbit.cache.CacheField; -import org.eclipse.hawkbit.cache.CacheKeys; -import org.eclipse.hawkbit.repository.model.helper.CacheManagerHolder; +import org.eclipse.hawkbit.repository.jpa.cache.CacheField; +import org.eclipse.hawkbit.repository.jpa.cache.CacheKeys; +import org.eclipse.hawkbit.repository.jpa.repository.model.helper.CacheManagerHolder; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/model/ModelEqualsHashcodeTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/model/ModelEqualsHashcodeTest.java similarity index 91% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/model/ModelEqualsHashcodeTest.java rename to hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/model/ModelEqualsHashcodeTest.java index c8f34cd48..2114afc42 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/model/ModelEqualsHashcodeTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/model/ModelEqualsHashcodeTest.java @@ -6,17 +6,12 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.model; +package org.eclipse.hawkbit.repository.jpa.model; import static org.fest.assertions.api.Assertions.assertThat; -import org.eclipse.hawkbit.AbstractIntegrationTest; -import org.eclipse.hawkbit.repository.jpa.model.JpaAction; -import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus; -import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; -import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType; -import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; -import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType; +import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest; +import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.junit.Test; import ru.yandex.qatools.allure.annotations.Description; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLActionFieldsTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLActionFieldsTest.java similarity index 96% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLActionFieldsTest.java rename to hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLActionFieldsTest.java index be6fd01b7..949e278ab 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLActionFieldsTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLActionFieldsTest.java @@ -6,14 +6,14 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.rsql; +package org.eclipse.hawkbit.repository.jpa.rsql; import static org.fest.assertions.api.Assertions.assertThat; import static org.junit.Assert.fail; -import org.eclipse.hawkbit.AbstractIntegrationTest; import org.eclipse.hawkbit.repository.ActionFields; import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException; +import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest; import org.eclipse.hawkbit.repository.jpa.model.JpaAction; import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; import org.eclipse.hawkbit.repository.model.Action; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLDistributionSetFieldTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLDistributionSetFieldTest.java similarity index 97% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLDistributionSetFieldTest.java rename to hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLDistributionSetFieldTest.java index 1e9d5e1b8..2c3747586 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLDistributionSetFieldTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLDistributionSetFieldTest.java @@ -6,17 +6,17 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.rsql; +package org.eclipse.hawkbit.repository.jpa.rsql; import static org.fest.assertions.api.Assertions.assertThat; import static org.junit.Assert.fail; import java.util.Arrays; -import org.eclipse.hawkbit.AbstractIntegrationTest; -import org.eclipse.hawkbit.TestDataUtil; import org.eclipse.hawkbit.repository.DistributionSetFields; import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException; +import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest; +import org.eclipse.hawkbit.repository.jpa.TestDataUtil; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetMetadata; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag; import org.eclipse.hawkbit.repository.model.DistributionSet; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLDistributionSetMetadataFieldsTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLDistributionSetMetadataFieldsTest.java similarity index 94% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLDistributionSetMetadataFieldsTest.java rename to hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLDistributionSetMetadataFieldsTest.java index 09c1e8dd0..af96da86f 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLDistributionSetMetadataFieldsTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLDistributionSetMetadataFieldsTest.java @@ -6,16 +6,16 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.rsql; +package org.eclipse.hawkbit.repository.jpa.rsql; import static org.fest.assertions.api.Assertions.assertThat; import java.util.ArrayList; import java.util.List; -import org.eclipse.hawkbit.AbstractIntegrationTest; -import org.eclipse.hawkbit.TestDataUtil; import org.eclipse.hawkbit.repository.DistributionSetMetadataFields; +import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest; +import org.eclipse.hawkbit.repository.jpa.TestDataUtil; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetMetadata; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetMetadata; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLRolloutGroupFields.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLRolloutGroupFields.java similarity index 96% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLRolloutGroupFields.java rename to hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLRolloutGroupFields.java index 32c4d8641..408c1847e 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLRolloutGroupFields.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLRolloutGroupFields.java @@ -6,13 +6,13 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.rsql; +package org.eclipse.hawkbit.repository.jpa.rsql; import static org.fest.assertions.api.Assertions.assertThat; -import org.eclipse.hawkbit.AbstractIntegrationTest; -import org.eclipse.hawkbit.TestDataUtil; import org.eclipse.hawkbit.repository.RolloutGroupFields; +import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest; +import org.eclipse.hawkbit.repository.jpa.TestDataUtil; import org.eclipse.hawkbit.repository.jpa.model.JpaRollout; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Rollout; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLSoftwareModuleFieldTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleFieldTest.java similarity index 97% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLSoftwareModuleFieldTest.java rename to hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleFieldTest.java index b049daa0c..6fb220880 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLSoftwareModuleFieldTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleFieldTest.java @@ -6,12 +6,12 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.rsql; +package org.eclipse.hawkbit.repository.jpa.rsql; import static org.fest.assertions.api.Assertions.assertThat; -import org.eclipse.hawkbit.AbstractIntegrationTest; import org.eclipse.hawkbit.repository.SoftwareModuleFields; +import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleMetadata; import org.eclipse.hawkbit.repository.model.SoftwareModule; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLSoftwareModuleMetadataFieldsTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleMetadataFieldsTest.java similarity index 95% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLSoftwareModuleMetadataFieldsTest.java rename to hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleMetadataFieldsTest.java index 362428887..87f151873 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLSoftwareModuleMetadataFieldsTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleMetadataFieldsTest.java @@ -6,16 +6,16 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.rsql; +package org.eclipse.hawkbit.repository.jpa.rsql; import static org.fest.assertions.api.Assertions.assertThat; import java.util.ArrayList; import java.util.List; -import org.eclipse.hawkbit.AbstractIntegrationTest; -import org.eclipse.hawkbit.TestDataUtil; import org.eclipse.hawkbit.repository.SoftwareModuleMetadataFields; +import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest; +import org.eclipse.hawkbit.repository.jpa.TestDataUtil; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleMetadata; import org.eclipse.hawkbit.repository.model.SoftwareModule; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLSoftwareModuleTypeFieldsTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleTypeFieldsTest.java similarity index 95% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLSoftwareModuleTypeFieldsTest.java rename to hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleTypeFieldsTest.java index e4988025e..3254ee4f6 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLSoftwareModuleTypeFieldsTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleTypeFieldsTest.java @@ -6,12 +6,12 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.rsql; +package org.eclipse.hawkbit.repository.jpa.rsql; import static org.fest.assertions.api.Assertions.assertThat; -import org.eclipse.hawkbit.AbstractIntegrationTest; import org.eclipse.hawkbit.repository.SoftwareModuleTypeFields; +import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.junit.Test; import org.springframework.data.domain.Page; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLTagFieldsTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLTagFieldsTest.java similarity index 97% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLTagFieldsTest.java rename to hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLTagFieldsTest.java index 85474e70e..a60d17818 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLTagFieldsTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLTagFieldsTest.java @@ -6,12 +6,12 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.rsql; +package org.eclipse.hawkbit.repository.jpa.rsql; import static org.fest.assertions.api.Assertions.assertThat; -import org.eclipse.hawkbit.AbstractIntegrationTest; import org.eclipse.hawkbit.repository.TagFields; +import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag; import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag; import org.eclipse.hawkbit.repository.model.DistributionSetTag; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLTargetFieldTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLTargetFieldTest.java similarity index 97% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLTargetFieldTest.java rename to hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLTargetFieldTest.java index a50230503..2e4f0346f 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLTargetFieldTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLTargetFieldTest.java @@ -6,17 +6,17 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.rsql; +package org.eclipse.hawkbit.repository.jpa.rsql; import static org.fest.assertions.api.Assertions.assertThat; import static org.junit.Assert.fail; import java.util.Arrays; -import org.eclipse.hawkbit.AbstractIntegrationTest; -import org.eclipse.hawkbit.TestDataUtil; import org.eclipse.hawkbit.repository.TargetFields; import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException; +import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest; +import org.eclipse.hawkbit.repository.jpa.TestDataUtil; import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo; import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLUtilityTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLUtilityTest.java similarity index 99% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLUtilityTest.java rename to hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLUtilityTest.java index dda0395da..9e0627178 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLUtilityTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLUtilityTest.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.rsql; +package org.eclipse.hawkbit.repository.jpa.rsql; import static org.junit.Assert.fail; import static org.mockito.Matchers.any; @@ -32,6 +32,7 @@ import org.eclipse.hawkbit.repository.SoftwareModuleFields; import org.eclipse.hawkbit.repository.TargetFields; import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException; import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException; +import org.eclipse.hawkbit.repository.jpa.repository.rsql.RSQLUtility; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/tenancy/MultiTenancyEntityTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/tenancy/MultiTenancyEntityTest.java similarity index 97% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/tenancy/MultiTenancyEntityTest.java rename to hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/tenancy/MultiTenancyEntityTest.java index e5cbc18a0..1c0beeabf 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/tenancy/MultiTenancyEntityTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/tenancy/MultiTenancyEntityTest.java @@ -6,13 +6,13 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.tenancy; +package org.eclipse.hawkbit.repository.jpa.tenancy; import static org.fest.assertions.api.Assertions.assertThat; -import org.eclipse.hawkbit.AbstractIntegrationTest; -import org.eclipse.hawkbit.WithSpringAuthorityRule; -import org.eclipse.hawkbit.WithUser; +import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest; +import org.eclipse.hawkbit.repository.jpa.WithSpringAuthorityRule; +import org.eclipse.hawkbit.repository.jpa.WithUser; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType; import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/utils/MultipleInvokeHelper.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/utils/MultipleInvokeHelper.java similarity index 98% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/utils/MultipleInvokeHelper.java rename to hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/utils/MultipleInvokeHelper.java index d40fe1fd0..c4710ca4b 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/utils/MultipleInvokeHelper.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/utils/MultipleInvokeHelper.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.utils; +package org.eclipse.hawkbit.repository.jpa.utils; import java.util.concurrent.Callable; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/utils/RepositoryDataGenerator.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/utils/RepositoryDataGenerator.java similarity index 99% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/utils/RepositoryDataGenerator.java rename to hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/utils/RepositoryDataGenerator.java index 9cacd9a82..9d41ecb65 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/utils/RepositoryDataGenerator.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/utils/RepositoryDataGenerator.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.utils; +package org.eclipse.hawkbit.repository.jpa.utils; import java.net.URI; import java.util.ArrayList; @@ -22,7 +22,6 @@ import javax.persistence.EntityManager; import javax.persistence.Query; import javax.transaction.Transactional; -import org.eclipse.hawkbit.TestDataUtil; import org.eclipse.hawkbit.im.authentication.SpPermission; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; import org.eclipse.hawkbit.im.authentication.TenantAwareAuthenticationDetails; @@ -33,6 +32,7 @@ import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.TargetManagement; +import org.eclipse.hawkbit.repository.jpa.TestDataUtil; import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/utils/SuccessCondition.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/utils/SuccessCondition.java similarity index 92% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/utils/SuccessCondition.java rename to hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/utils/SuccessCondition.java index 6c9553dc8..b5e421107 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/utils/SuccessCondition.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/utils/SuccessCondition.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.utils; +package org.eclipse.hawkbit.repository.jpa.utils; /** * SuccessCondition Interface. diff --git a/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/util/RestResourceConversionHelper.java b/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/util/RestResourceConversionHelper.java index 181ccc1f8..baa18edb2 100644 --- a/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/util/RestResourceConversionHelper.java +++ b/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/util/RestResourceConversionHelper.java @@ -22,7 +22,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.eclipse.hawkbit.artifact.repository.model.DbArtifact; -import org.eclipse.hawkbit.cache.CacheWriteNotify; +import org.eclipse.hawkbit.repository.jpa.cache.CacheWriteNotify; import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTest.java b/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTest.java index 38f36859b..e86f78d68 100644 --- a/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTest.java +++ b/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTest.java @@ -8,7 +8,7 @@ */ package org.eclipse.hawkbit.rest; -import org.eclipse.hawkbit.AbstractIntegrationTest; +import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest; import org.eclipse.hawkbit.rest.configuration.RestConfiguration; import org.eclipse.hawkbit.rest.util.FilterHttpResponse; import org.springframework.beans.factory.annotation.Autowired; diff --git a/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTestWithMongoDB.java b/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTestWithMongoDB.java index 9a25eb631..d3da40035 100644 --- a/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTestWithMongoDB.java +++ b/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTestWithMongoDB.java @@ -8,7 +8,7 @@ */ package org.eclipse.hawkbit.rest; -import org.eclipse.hawkbit.AbstractIntegrationTestWithMongoDB; +import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTestWithMongoDB; import org.eclipse.hawkbit.rest.configuration.RestConfiguration; import org.eclipse.hawkbit.rest.util.FilterHttpResponse; import org.springframework.beans.factory.annotation.Autowired; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/HawkbitEventProvider.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/HawkbitEventProvider.java index 4358bb734..cca4bdd4c 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/HawkbitEventProvider.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/HawkbitEventProvider.java @@ -11,18 +11,18 @@ package org.eclipse.hawkbit.ui; import java.util.HashSet; import java.util.Set; -import org.eclipse.hawkbit.eventbus.event.DistributionSetTagCreatedBulkEvent; -import org.eclipse.hawkbit.eventbus.event.DistributionSetTagDeletedEvent; -import org.eclipse.hawkbit.eventbus.event.DistributionSetTagUpdateEvent; import org.eclipse.hawkbit.eventbus.event.Event; -import org.eclipse.hawkbit.eventbus.event.RolloutChangeEvent; -import org.eclipse.hawkbit.eventbus.event.RolloutGroupChangeEvent; -import org.eclipse.hawkbit.eventbus.event.TargetCreatedEvent; import org.eclipse.hawkbit.eventbus.event.TargetDeletedEvent; -import org.eclipse.hawkbit.eventbus.event.TargetInfoUpdateEvent; -import org.eclipse.hawkbit.eventbus.event.TargetTagCreatedBulkEvent; -import org.eclipse.hawkbit.eventbus.event.TargetTagDeletedEvent; -import org.eclipse.hawkbit.eventbus.event.TargetTagUpdateEvent; +import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetTagCreatedBulkEvent; +import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetTagDeletedEvent; +import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetTagUpdateEvent; +import org.eclipse.hawkbit.repository.eventbus.event.RolloutChangeEvent; +import org.eclipse.hawkbit.repository.eventbus.event.RolloutGroupChangeEvent; +import org.eclipse.hawkbit.repository.eventbus.event.TargetCreatedEvent; +import org.eclipse.hawkbit.repository.eventbus.event.TargetInfoUpdateEvent; +import org.eclipse.hawkbit.repository.eventbus.event.TargetTagCreatedBulkEvent; +import org.eclipse.hawkbit.repository.eventbus.event.TargetTagDeletedEvent; +import org.eclipse.hawkbit.repository.eventbus.event.TargetTagUpdateEvent; /** * The default hawkbit event provider. diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTargetTagToken.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTargetTagToken.java index ce9f101f3..e74a331af 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTargetTagToken.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTargetTagToken.java @@ -8,9 +8,9 @@ */ package org.eclipse.hawkbit.ui.common.tagdetails; -import org.eclipse.hawkbit.eventbus.event.TargetTagCreatedBulkEvent; -import org.eclipse.hawkbit.eventbus.event.TargetTagDeletedEvent; import org.eclipse.hawkbit.repository.TagManagement; +import org.eclipse.hawkbit.repository.eventbus.event.TargetTagCreatedBulkEvent; +import org.eclipse.hawkbit.repository.eventbus.event.TargetTagDeletedEvent; import org.eclipse.hawkbit.repository.model.BaseEntity; import org.eclipse.hawkbit.repository.model.TargetTag; import org.springframework.beans.factory.annotation.Autowired; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/DistributionTagToken.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/DistributionTagToken.java index 178610c23..88467d838 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/DistributionTagToken.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/DistributionTagToken.java @@ -14,12 +14,12 @@ import java.util.List; import java.util.Set; import java.util.stream.Collectors; -import org.eclipse.hawkbit.eventbus.event.DistributionSetTagAssigmentResultEvent; -import org.eclipse.hawkbit.eventbus.event.DistributionSetTagCreatedBulkEvent; -import org.eclipse.hawkbit.eventbus.event.DistributionSetTagDeletedEvent; -import org.eclipse.hawkbit.eventbus.event.DistributionSetTagUpdateEvent; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.TagManagement; +import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetTagAssigmentResultEvent; +import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetTagCreatedBulkEvent; +import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetTagDeletedEvent; +import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetTagUpdateEvent; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/TargetTagToken.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/TargetTagToken.java index 6f03c5860..2cd4ec978 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/TargetTagToken.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/TargetTagToken.java @@ -14,9 +14,9 @@ import java.util.List; import java.util.Set; import java.util.stream.Collectors; -import org.eclipse.hawkbit.eventbus.event.TargetTagAssigmentResultEvent; -import org.eclipse.hawkbit.eventbus.event.TargetTagUpdateEvent; import org.eclipse.hawkbit.repository.TargetManagement; +import org.eclipse.hawkbit.repository.eventbus.event.TargetTagAssigmentResultEvent; +import org.eclipse.hawkbit.repository.eventbus.event.TargetTagUpdateEvent; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetTag; import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/CreateUpdateDistributionTagLayoutWindow.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/CreateUpdateDistributionTagLayoutWindow.java index e540017c3..56ba4183b 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/CreateUpdateDistributionTagLayoutWindow.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/CreateUpdateDistributionTagLayoutWindow.java @@ -11,9 +11,9 @@ package org.eclipse.hawkbit.ui.management.dstag; import java.util.ArrayList; import java.util.List; -import org.eclipse.hawkbit.eventbus.event.DistributionSetTagCreatedBulkEvent; -import org.eclipse.hawkbit.eventbus.event.DistributionSetTagDeletedEvent; -import org.eclipse.hawkbit.eventbus.event.DistributionSetTagUpdateEvent; +import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetTagCreatedBulkEvent; +import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetTagDeletedEvent; +import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetTagUpdateEvent; import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.management.tag.CreateUpdateTagLayout; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagButtons.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagButtons.java index fbf882695..003700df5 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagButtons.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagButtons.java @@ -11,10 +11,10 @@ package org.eclipse.hawkbit.ui.management.dstag; import java.util.HashMap; import java.util.Map; -import org.eclipse.hawkbit.eventbus.event.DistributionSetTagCreatedBulkEvent; -import org.eclipse.hawkbit.eventbus.event.DistributionSetTagDeletedEvent; -import org.eclipse.hawkbit.eventbus.event.DistributionSetTagUpdateEvent; import org.eclipse.hawkbit.repository.TagManagement; +import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetTagCreatedBulkEvent; +import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetTagDeletedEvent; +import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetTagUpdateEvent; import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.ui.common.filterlayout.AbstractFilterButtonClickBehaviour; import org.eclipse.hawkbit.ui.common.filterlayout.AbstractFilterButtons; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java index 62ad96205..552349f0a 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java @@ -18,12 +18,12 @@ import java.util.Map; import java.util.Set; import java.util.stream.Collectors; -import org.eclipse.hawkbit.eventbus.event.TargetCreatedEvent; import org.eclipse.hawkbit.eventbus.event.TargetDeletedEvent; -import org.eclipse.hawkbit.eventbus.event.TargetInfoUpdateEvent; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.repository.TargetManagement; +import org.eclipse.hawkbit.repository.eventbus.event.TargetCreatedEvent; +import org.eclipse.hawkbit.repository.eventbus.event.TargetInfoUpdateEvent; import org.eclipse.hawkbit.repository.model.DistributionSetIdName; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetFilterQuery; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/CreateUpdateTargetTagLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/CreateUpdateTargetTagLayout.java index efd4084f5..e5990be49 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/CreateUpdateTargetTagLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/CreateUpdateTargetTagLayout.java @@ -11,9 +11,9 @@ package org.eclipse.hawkbit.ui.management.targettag; import java.util.ArrayList; import java.util.List; -import org.eclipse.hawkbit.eventbus.event.TargetTagCreatedBulkEvent; -import org.eclipse.hawkbit.eventbus.event.TargetTagDeletedEvent; -import org.eclipse.hawkbit.eventbus.event.TargetTagUpdateEvent; +import org.eclipse.hawkbit.repository.eventbus.event.TargetTagCreatedBulkEvent; +import org.eclipse.hawkbit.repository.eventbus.event.TargetTagDeletedEvent; +import org.eclipse.hawkbit.repository.eventbus.event.TargetTagUpdateEvent; import org.eclipse.hawkbit.repository.model.TargetTag; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.management.tag.CreateUpdateTagLayout; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java index 58721d77d..eeac79728 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java @@ -12,12 +12,12 @@ import java.util.List; import java.util.Set; import java.util.stream.Collectors; -import org.eclipse.hawkbit.eventbus.event.TargetTagCreatedBulkEvent; -import org.eclipse.hawkbit.eventbus.event.TargetTagDeletedEvent; -import org.eclipse.hawkbit.eventbus.event.TargetTagUpdateEvent; import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.TargetManagement; +import org.eclipse.hawkbit.repository.eventbus.event.TargetTagCreatedBulkEvent; +import org.eclipse.hawkbit.repository.eventbus.event.TargetTagDeletedEvent; +import org.eclipse.hawkbit.repository.eventbus.event.TargetTagUpdateEvent; import org.eclipse.hawkbit.repository.model.TargetIdName; import org.eclipse.hawkbit.repository.model.TargetTag; import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java index 7f3877a9a..1e5c3b3c0 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java @@ -21,9 +21,9 @@ import java.util.Locale; import java.util.Map; import java.util.Set; -import org.eclipse.hawkbit.eventbus.event.RolloutChangeEvent; import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.SpPermissionChecker; +import org.eclipse.hawkbit.repository.eventbus.event.RolloutChangeEvent; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.Rollout.RolloutStatus; import org.eclipse.hawkbit.repository.model.SoftwareModule; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java index f09b02cfc..e2a8194ed 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java @@ -15,10 +15,10 @@ import java.util.List; import java.util.Locale; import java.util.Map; -import org.eclipse.hawkbit.eventbus.event.RolloutGroupChangeEvent; import org.eclipse.hawkbit.repository.RolloutGroupManagement; import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.SpPermissionChecker; +import org.eclipse.hawkbit.repository.eventbus.event.RolloutGroupChangeEvent; import org.eclipse.hawkbit.repository.model.RolloutGroup; import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupStatus; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; From e6ff96dc5a81d4eda350180c03d22dbb5983e982 Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Fri, 27 May 2016 13:30:18 +0200 Subject: [PATCH 23/54] Completed maven module split. Signed-off-by: Kai Zimmermann --- examples/hawkbit-device-simulator/pom.xml | 6 ------ .../eventbus/EventBusAutoConfiguration.java | 2 +- .../resource/DdiArtifactStoreController.java | 2 +- .../ddi/rest/resource/DdiRootController.java | 2 +- .../rest/resource/DdiArtifactDownloadTest.java | 4 ++-- .../ddi/rest/resource/DdiCancelActionTest.java | 2 +- .../ddi/rest/resource/DdiConfigDataTest.java | 2 +- .../rest/resource/DdiDeploymentBaseTest.java | 2 +- .../rest/resource/DdiRootControllerTest.java | 6 +++--- .../amqp/AmqpMessageDispatcherService.java | 2 +- .../amqp/AmqpMessageHandlerService.java | 2 +- .../amqp/AmqpMessageDispatcherServiceTest.java | 6 +++--- .../amqp/AmqpMessageHandlerServiceTest.java | 4 ++-- .../PropertyBasedArtifactUrlHandlerTest.java | 6 +++--- .../rest/resource/MgmtRolloutResource.java | 2 +- .../resource/MgmtSystemManagementResource.java | 4 ++-- .../MgmtDistributionSetResourceTest.java | 4 ++-- .../MgmtDistributionSetTypeResourceTest.java | 2 +- .../resource/MgmtDownloadResourceTest.java | 2 +- .../rest/resource/MgmtRolloutResourceTest.java | 4 ++-- .../MgmtSoftwareModuleResourceTest.java | 6 +++--- .../MgmtSoftwareModuleTypeResourceTest.java | 2 +- .../rest/resource/MgmtTargetResourceTest.java | 4 ++-- ...SMRessourceMisingMongoDbConnectionTest.java | 2 +- .../hawkbit-repository-jpa/pom.xml | 14 +++++++++----- .../RepositoryApplicationConfiguration.java | 18 ++++++++++-------- .../jpa/JpaDeploymentManagement.java | 2 +- .../jpa/JpaDistributionSetManagement.java | 2 +- .../jpa/JpaRolloutGroupManagement.java | 2 +- .../repository/jpa/JpaRolloutManagement.java | 2 +- .../repository/jpa/JpaSoftwareManagement.java | 2 +- .../repository/jpa/JpaTagManagement.java | 2 +- .../repository/jpa/JpaTargetManagement.java | 2 +- .../jpa/eventbus/CacheFieldEntityListener.java | 2 +- .../eventbus/EntityPropertyChangeListener.java | 4 ++-- .../AbstractJpaTenantAwareBaseEntity.java | 4 ++-- .../repository/jpa/model/JpaTarget.java | 6 +++--- .../repository/jpa/model/JpaTargetInfo.java | 4 ++-- .../AfterTransactionCommitExecutorHolder.java | 2 +- .../model/helper/CacheManagerHolder.java | 2 +- .../model/helper/EventBusHolder.java | 2 +- .../model/helper/SecurityChecker.java | 2 +- .../helper/SecurityTokenGeneratorHolder.java | 2 +- .../model/helper/SystemManagementHolder.java | 2 +- .../helper/SystemSecurityContextHolder.java | 2 +- .../model/helper/TenantAwareHolder.java | 2 +- .../TenantConfigurationManagementHolder.java | 2 +- .../{repository => }/rsql/PropertyMapper.java | 2 +- .../jpa/{repository => }/rsql/RSQLUtility.java | 2 +- .../jpa/AbstractIntegrationTest.java | 18 +++++++++++++++++- .../repository/jpa/TestConfiguration.java | 2 +- .../jpa/WithSpringAuthorityRule.java | 2 +- .../eventbus/CacheFieldEntityListenerTest.java | 2 +- .../repository/jpa/rsql/RSQLUtilityTest.java | 1 - .../rest/json/model/ExceptionInfoTest.java | 1 - 55 files changed, 104 insertions(+), 90 deletions(-) rename hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/{repository/jpa/configuration => }/RepositoryApplicationConfiguration.java (88%) rename hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/{repository => }/model/helper/AfterTransactionCommitExecutorHolder.java (96%) rename hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/{repository => }/model/helper/CacheManagerHolder.java (96%) rename hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/{repository => }/model/helper/EventBusHolder.java (95%) rename hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/{repository => }/model/helper/SecurityChecker.java (96%) rename hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/{repository => }/model/helper/SecurityTokenGeneratorHolder.java (95%) rename hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/{repository => }/model/helper/SystemManagementHolder.java (95%) rename hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/{repository => }/model/helper/SystemSecurityContextHolder.java (94%) rename hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/{repository => }/model/helper/TenantAwareHolder.java (94%) rename hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/{repository => }/model/helper/TenantConfigurationManagementHolder.java (95%) rename hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/{repository => }/rsql/PropertyMapper.java (95%) rename hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/{repository => }/rsql/RSQLUtility.java (99%) diff --git a/examples/hawkbit-device-simulator/pom.xml b/examples/hawkbit-device-simulator/pom.xml index 1b1bc5fdc..3c3df9486 100644 --- a/examples/hawkbit-device-simulator/pom.xml +++ b/examples/hawkbit-device-simulator/pom.xml @@ -116,10 +116,6 @@ org.springframework.boot spring-boot-autoconfigure
- - org.springframework.boot - spring-boot-autoconfigure - com.google.guava guava @@ -127,12 +123,10 @@ com.netflix.feign feign-jackson - 8.14.1 com.netflix.feign feign-core - 8.12.1 com.jayway.jsonpath diff --git a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/eventbus/EventBusAutoConfiguration.java b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/eventbus/EventBusAutoConfiguration.java index 37e72880c..d4cc32825 100644 --- a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/eventbus/EventBusAutoConfiguration.java +++ b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/eventbus/EventBusAutoConfiguration.java @@ -12,7 +12,7 @@ import java.util.concurrent.Executor; import org.eclipse.hawkbit.eventbus.EventBusSubscriberProcessor; import org.eclipse.hawkbit.eventbus.EventSubscriber; -import org.eclipse.hawkbit.repository.model.helper.EventBusHolder; +import org.eclipse.hawkbit.repository.jpa.model.helper.EventBusHolder; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; diff --git a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java index 36fa926e8..6c133f03c 100644 --- a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java +++ b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java @@ -15,10 +15,10 @@ import java.util.List; import javax.servlet.http.HttpServletRequest; import org.eclipse.hawkbit.artifact.repository.model.DbArtifact; -import org.eclipse.hawkbit.cache.CacheWriteNotify; import org.eclipse.hawkbit.ddi.dl.rest.api.DdiDlArtifactStoreControllerRestApi; import org.eclipse.hawkbit.repository.ArtifactManagement; import org.eclipse.hawkbit.repository.ControllerManagement; +import org.eclipse.hawkbit.repository.jpa.cache.CacheWriteNotify; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; diff --git a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java index 355a43b3c..09cb4c577 100644 --- a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java +++ b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java @@ -17,7 +17,6 @@ import javax.validation.Valid; import org.eclipse.hawkbit.api.ArtifactUrlHandler; import org.eclipse.hawkbit.artifact.repository.model.DbArtifact; -import org.eclipse.hawkbit.cache.CacheWriteNotify; import org.eclipse.hawkbit.ddi.json.model.DdiActionFeedback; import org.eclipse.hawkbit.ddi.json.model.DdiCancel; import org.eclipse.hawkbit.ddi.json.model.DdiCancelActionToStop; @@ -33,6 +32,7 @@ import org.eclipse.hawkbit.repository.ArtifactManagement; import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; +import org.eclipse.hawkbit.repository.jpa.cache.CacheWriteNotify; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java index 25e4776c9..2e56ed840 100644 --- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java +++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java @@ -26,9 +26,9 @@ import java.util.Arrays; import java.util.List; import org.apache.commons.lang3.RandomUtils; -import org.eclipse.hawkbit.TestDataUtil; -import org.eclipse.hawkbit.WithUser; import org.eclipse.hawkbit.eventbus.event.DownloadProgressEvent; +import org.eclipse.hawkbit.repository.jpa.TestDataUtil; +import org.eclipse.hawkbit.repository.jpa.WithUser; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.Artifact; diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiCancelActionTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiCancelActionTest.java index b52d0fddc..8fd832b95 100644 --- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiCancelActionTest.java +++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiCancelActionTest.java @@ -22,7 +22,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. import java.util.ArrayList; import java.util.List; -import org.eclipse.hawkbit.TestDataUtil; +import org.eclipse.hawkbit.repository.jpa.TestDataUtil; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.DistributionSet; diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiConfigDataTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiConfigDataTest.java index afb60043d..a216ce501 100644 --- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiConfigDataTest.java +++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiConfigDataTest.java @@ -21,7 +21,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. import java.util.HashMap; import java.util.Map; -import org.eclipse.hawkbit.AbstractIntegrationTest; +import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.rest.util.JsonBuilder; import org.eclipse.hawkbit.rest.util.MockMvcResultPrinter; diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java index 0790a6705..9d52a67f4 100644 --- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java +++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java @@ -25,7 +25,7 @@ import java.util.ArrayList; import java.util.List; import org.apache.commons.lang3.RandomUtils; -import org.eclipse.hawkbit.TestDataUtil; +import org.eclipse.hawkbit.repository.jpa.TestDataUtil; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.ActionType; diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootControllerTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootControllerTest.java index ffeed1956..490e76161 100644 --- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootControllerTest.java +++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootControllerTest.java @@ -22,11 +22,11 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. import java.util.ArrayList; import java.util.List; -import org.eclipse.hawkbit.TestDataUtil; -import org.eclipse.hawkbit.WithSpringAuthorityRule; -import org.eclipse.hawkbit.WithUser; import org.eclipse.hawkbit.im.authentication.SpPermission; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; +import org.eclipse.hawkbit.repository.jpa.TestDataUtil; +import org.eclipse.hawkbit.repository.jpa.WithSpringAuthorityRule; +import org.eclipse.hawkbit.repository.jpa.WithUser; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Target; diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java index dbfded401..3b05c96a6 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java +++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java @@ -25,8 +25,8 @@ import org.eclipse.hawkbit.dmf.json.model.DownloadAndUpdateRequest; import org.eclipse.hawkbit.dmf.json.model.SoftwareModule; import org.eclipse.hawkbit.eventbus.EventSubscriber; import org.eclipse.hawkbit.eventbus.event.CancelTargetAssignmentEvent; -import org.eclipse.hawkbit.eventbus.event.TargetAssignDistributionSetEvent; import org.eclipse.hawkbit.repository.SoftwareManagement; +import org.eclipse.hawkbit.repository.eventbus.event.TargetAssignDistributionSetEvent; import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.util.IpUtil; import org.springframework.amqp.core.Message; diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java index 03b2c7514..90039d4ba 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java +++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java @@ -30,11 +30,11 @@ import org.eclipse.hawkbit.dmf.json.model.ArtifactHash; import org.eclipse.hawkbit.dmf.json.model.DownloadResponse; import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken; import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken.FileResource; -import org.eclipse.hawkbit.eventbus.event.TargetAssignDistributionSetEvent; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; import org.eclipse.hawkbit.im.authentication.TenantAwareAuthenticationDetails; import org.eclipse.hawkbit.repository.ArtifactManagement; import org.eclipse.hawkbit.repository.ControllerManagement; +import org.eclipse.hawkbit.repository.eventbus.event.TargetAssignDistributionSetEvent; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; diff --git a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java index 9164e655d..132ddb650 100644 --- a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java +++ b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java @@ -25,8 +25,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Optional; -import org.eclipse.hawkbit.AbstractIntegrationTestWithMongoDB; -import org.eclipse.hawkbit.TestDataUtil; import org.eclipse.hawkbit.api.ArtifactUrlHandler; import org.eclipse.hawkbit.artifact.repository.model.DbArtifact; import org.eclipse.hawkbit.dmf.amqp.api.EventTopic; @@ -34,7 +32,9 @@ import org.eclipse.hawkbit.dmf.amqp.api.MessageHeaderKey; import org.eclipse.hawkbit.dmf.amqp.api.MessageType; import org.eclipse.hawkbit.dmf.json.model.DownloadAndUpdateRequest; import org.eclipse.hawkbit.eventbus.event.CancelTargetAssignmentEvent; -import org.eclipse.hawkbit.eventbus.event.TargetAssignDistributionSetEvent; +import org.eclipse.hawkbit.repository.eventbus.event.TargetAssignDistributionSetEvent; +import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTestWithMongoDB; +import org.eclipse.hawkbit.repository.jpa.TestDataUtil; import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.LocalArtifact; diff --git a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java index b0c5d777b..2ce6cd91c 100644 --- a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java +++ b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java @@ -36,19 +36,19 @@ import org.eclipse.hawkbit.dmf.json.model.ActionUpdateStatus; import org.eclipse.hawkbit.dmf.json.model.DownloadResponse; import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken; import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken.FileResource; -import org.eclipse.hawkbit.eventbus.event.TargetAssignDistributionSetEvent; import org.eclipse.hawkbit.repository.ArtifactManagement; import org.eclipse.hawkbit.repository.ControllerManagement; +import org.eclipse.hawkbit.repository.eventbus.event.TargetAssignDistributionSetEvent; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.jpa.model.JpaAction; import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; +import org.eclipse.hawkbit.repository.jpa.model.helper.SecurityTokenGeneratorHolder; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; -import org.eclipse.hawkbit.repository.model.helper.SecurityTokenGeneratorHolder; import org.eclipse.hawkbit.security.SecurityTokenGenerator; import org.junit.Before; import org.junit.Test; diff --git a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/util/PropertyBasedArtifactUrlHandlerTest.java b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/util/PropertyBasedArtifactUrlHandlerTest.java index f9a2ea316..3d83fed69 100644 --- a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/util/PropertyBasedArtifactUrlHandlerTest.java +++ b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/util/PropertyBasedArtifactUrlHandlerTest.java @@ -10,13 +10,13 @@ package org.eclipse.hawkbit.util; import static org.junit.Assert.assertEquals; -import org.eclipse.hawkbit.AbstractIntegrationTestWithMongoDB; import org.eclipse.hawkbit.AmqpTestConfiguration; import org.eclipse.hawkbit.RepositoryApplicationConfiguration; -import org.eclipse.hawkbit.TestConfiguration; -import org.eclipse.hawkbit.TestDataUtil; import org.eclipse.hawkbit.api.ArtifactUrlHandler; import org.eclipse.hawkbit.api.UrlProtocol; +import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTestWithMongoDB; +import org.eclipse.hawkbit.repository.jpa.TestConfiguration; +import org.eclipse.hawkbit.repository.jpa.TestDataUtil; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResource.java index ae025e51b..0b3a77101 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResource.java @@ -23,6 +23,7 @@ import org.eclipse.hawkbit.repository.RolloutGroupManagement; import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.TargetFields; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; +import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.RolloutGroup; @@ -33,7 +34,6 @@ import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupSuccessCond import org.eclipse.hawkbit.repository.model.RolloutGroupConditionBuilder; import org.eclipse.hawkbit.repository.model.RolloutGroupConditions; import org.eclipse.hawkbit.repository.model.Target; -import org.eclipse.hawkbit.repository.rsql.RSQLUtility; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSystemManagementResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSystemManagementResource.java index 46e51f2ee..3392d2659 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSystemManagementResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSystemManagementResource.java @@ -18,9 +18,9 @@ import org.eclipse.hawkbit.mgmt.json.model.systemmanagement.MgmtSystemCache; import org.eclipse.hawkbit.mgmt.json.model.systemmanagement.MgmtSystemStatisticsRest; import org.eclipse.hawkbit.mgmt.json.model.systemmanagement.MgmtSystemTenantServiceUsage; import org.eclipse.hawkbit.mgmt.rest.api.MgmtSystemManagementRestApi; -import org.eclipse.hawkbit.report.model.SystemUsageReport; -import org.eclipse.hawkbit.report.model.TenantUsage; import org.eclipse.hawkbit.repository.SystemManagement; +import org.eclipse.hawkbit.repository.report.model.SystemUsageReport; +import org.eclipse.hawkbit.repository.report.model.TenantUsage; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java index 63e09fb98..700a2735c 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java @@ -26,10 +26,10 @@ import java.util.Iterator; import java.util.List; import java.util.Set; -import org.eclipse.hawkbit.TestDataUtil; -import org.eclipse.hawkbit.WithUser; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; +import org.eclipse.hawkbit.repository.jpa.TestDataUtil; +import org.eclipse.hawkbit.repository.jpa.WithUser; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetMetadata; diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResourceTest.java index 005a7f51f..d4596bde7 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResourceTest.java @@ -23,8 +23,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. import java.util.ArrayList; import java.util.List; -import org.eclipse.hawkbit.WithUser; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; +import org.eclipse.hawkbit.repository.jpa.WithUser; import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDownloadResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDownloadResourceTest.java index 17f23f888..fcdbfa918 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDownloadResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDownloadResourceTest.java @@ -11,11 +11,11 @@ package org.eclipse.hawkbit.mgmt.rest.resource; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import org.eclipse.hawkbit.TestDataUtil; import org.eclipse.hawkbit.cache.CacheConstants; import org.eclipse.hawkbit.cache.DownloadArtifactCache; import org.eclipse.hawkbit.cache.DownloadType; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; +import org.eclipse.hawkbit.repository.jpa.TestDataUtil; import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.SoftwareModule; diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResourceTest.java index b1c843042..fd171b7da 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResourceTest.java @@ -21,11 +21,11 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. import java.util.List; import java.util.concurrent.Callable; -import org.eclipse.hawkbit.TestDataUtil; -import org.eclipse.hawkbit.WithUser; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.repository.RolloutGroupManagement; import org.eclipse.hawkbit.repository.RolloutManagement; +import org.eclipse.hawkbit.repository.jpa.TestDataUtil; +import org.eclipse.hawkbit.repository.jpa.WithUser; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.Rollout.RolloutStatus; diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java index 379674f98..2e9f1a47b 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java @@ -32,13 +32,13 @@ import java.util.List; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.RandomStringUtils; -import org.eclipse.hawkbit.HashGeneratorUtils; -import org.eclipse.hawkbit.TestDataUtil; -import org.eclipse.hawkbit.WithUser; import org.eclipse.hawkbit.exception.SpServerError; import org.eclipse.hawkbit.mgmt.json.model.artifact.MgmtArtifact; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; +import org.eclipse.hawkbit.repository.jpa.HashGeneratorUtils; +import org.eclipse.hawkbit.repository.jpa.TestDataUtil; +import org.eclipse.hawkbit.repository.jpa.WithUser; import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.LocalArtifact; diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResourceTest.java index 85df4fc70..ae137e125 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResourceTest.java @@ -23,8 +23,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. import java.util.ArrayList; import java.util.List; -import org.eclipse.hawkbit.WithUser; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; +import org.eclipse.hawkbit.repository.jpa.WithUser; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.rest.AbstractRestIntegrationTest; diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java index bc0f1cb0d..b1ed0eb26 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java @@ -29,14 +29,14 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; -import org.eclipse.hawkbit.TestDataUtil; -import org.eclipse.hawkbit.WithUser; import org.eclipse.hawkbit.exception.SpServerError; import org.eclipse.hawkbit.im.authentication.SpPermission; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.repository.ActionFields; import org.eclipse.hawkbit.repository.ActionStatusFields; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; +import org.eclipse.hawkbit.repository.jpa.TestDataUtil; +import org.eclipse.hawkbit.repository.jpa.WithUser; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo; diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/SMRessourceMisingMongoDbConnectionTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/SMRessourceMisingMongoDbConnectionTest.java index dc5d5122d..9e698e0af 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/SMRessourceMisingMongoDbConnectionTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/SMRessourceMisingMongoDbConnectionTest.java @@ -13,8 +13,8 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import org.apache.commons.lang3.RandomStringUtils; -import org.eclipse.hawkbit.AbstractIntegrationTest; import org.eclipse.hawkbit.exception.SpServerError; +import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.rest.json.model.ExceptionInfo; import org.eclipse.hawkbit.rest.util.MockMvcResultPrinter; diff --git a/hawkbit-repository/hawkbit-repository-jpa/pom.xml b/hawkbit-repository/hawkbit-repository-jpa/pom.xml index d84b36778..e61ad8325 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/pom.xml +++ b/hawkbit-repository/hawkbit-repository-jpa/pom.xml @@ -69,6 +69,10 @@ org.springframework.boot spring-boot + + org.springframework.boot + spring-boot-starter-logging + org.springframework.boot spring-boot-starter-data-jpa @@ -117,11 +121,11 @@ allure-junit-adaptor test - - org.springframework.data - spring-data-rest-webmvc - test - + + + + + org.springframework.security spring-security-aspects diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/configuration/RepositoryApplicationConfiguration.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java similarity index 88% rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/configuration/RepositoryApplicationConfiguration.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java index aaed3e64e..afb6f4245 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/configuration/RepositoryApplicationConfiguration.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.jpa.configuration; +package org.eclipse.hawkbit; import java.util.HashMap; import java.util.Map; @@ -14,13 +14,14 @@ import java.util.Map; import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; import org.eclipse.hawkbit.repository.jpa.aspects.ExceptionMappingAspectHandler; -import org.eclipse.hawkbit.repository.jpa.repository.model.helper.AfterTransactionCommitExecutorHolder; -import org.eclipse.hawkbit.repository.jpa.repository.model.helper.CacheManagerHolder; -import org.eclipse.hawkbit.repository.jpa.repository.model.helper.SecurityTokenGeneratorHolder; -import org.eclipse.hawkbit.repository.jpa.repository.model.helper.SystemManagementHolder; -import org.eclipse.hawkbit.repository.jpa.repository.model.helper.SystemSecurityContextHolder; -import org.eclipse.hawkbit.repository.jpa.repository.model.helper.TenantAwareHolder; -import org.eclipse.hawkbit.repository.jpa.repository.model.helper.TenantConfigurationManagementHolder; +import org.eclipse.hawkbit.repository.jpa.configuration.MultiTenantJpaTransactionManager; +import org.eclipse.hawkbit.repository.jpa.model.helper.AfterTransactionCommitExecutorHolder; +import org.eclipse.hawkbit.repository.jpa.model.helper.CacheManagerHolder; +import org.eclipse.hawkbit.repository.jpa.model.helper.SecurityTokenGeneratorHolder; +import org.eclipse.hawkbit.repository.jpa.model.helper.SystemManagementHolder; +import org.eclipse.hawkbit.repository.jpa.model.helper.SystemSecurityContextHolder; +import org.eclipse.hawkbit.repository.jpa.model.helper.TenantAwareHolder; +import org.eclipse.hawkbit.repository.jpa.model.helper.TenantConfigurationManagementHolder; import org.eclipse.hawkbit.security.SecurityTokenGenerator; import org.eclipse.hawkbit.security.SystemSecurityContext; import org.eclipse.hawkbit.tenancy.TenantAware; @@ -157,6 +158,7 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration { properties.put("eclipselink.ddl-generation", "none"); properties.put("eclipselink.persistence-context.flush-mode", "auto"); + properties.put("eclipselink.logging.logger", "JavaLogger"); return properties; } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java index a3c717d98..8463f2d37 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java @@ -54,7 +54,7 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaRollout_; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo; -import org.eclipse.hawkbit.repository.jpa.repository.rsql.RSQLUtility; +import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility; import org.eclipse.hawkbit.repository.jpa.specifications.TargetSpecifications; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.ActionType; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java index 8398832b6..52c140109 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java @@ -43,7 +43,7 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetMetadata; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetMetadata_; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet_; -import org.eclipse.hawkbit.repository.jpa.repository.rsql.RSQLUtility; +import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility; import org.eclipse.hawkbit.repository.jpa.specifications.DistributionSetSpecification; import org.eclipse.hawkbit.repository.jpa.specifications.DistributionSetTypeSpecification; import org.eclipse.hawkbit.repository.jpa.specifications.SpecificationsBuilder; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutGroupManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutGroupManagement.java index dce07dc79..ea6214824 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutGroupManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutGroupManagement.java @@ -32,7 +32,7 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; import org.eclipse.hawkbit.repository.jpa.model.JpaTarget_; import org.eclipse.hawkbit.repository.jpa.model.RolloutTargetGroup; import org.eclipse.hawkbit.repository.jpa.model.RolloutTargetGroup_; -import org.eclipse.hawkbit.repository.jpa.repository.rsql.RSQLUtility; +import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.Rollout.RolloutStatus; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java index e2f5ea8aa..f4523330d 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java @@ -30,9 +30,9 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaRollout; import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup; import org.eclipse.hawkbit.repository.jpa.model.JpaRollout_; import org.eclipse.hawkbit.repository.jpa.model.RolloutTargetGroup; -import org.eclipse.hawkbit.repository.jpa.repository.rsql.RSQLUtility; import org.eclipse.hawkbit.repository.jpa.rollout.condition.RolloutGroupActionEvaluator; import org.eclipse.hawkbit.repository.jpa.rollout.condition.RolloutGroupConditionEvaluator; +import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.ActionType; import org.eclipse.hawkbit.repository.model.DistributionSet; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java index ff3783783..eceec20d1 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java @@ -41,7 +41,7 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleMetadata_; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule_; import org.eclipse.hawkbit.repository.jpa.model.SwMetadataCompositeKey; -import org.eclipse.hawkbit.repository.jpa.repository.rsql.RSQLUtility; +import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility; import org.eclipse.hawkbit.repository.jpa.specifications.SoftwareModuleSpecification; import org.eclipse.hawkbit.repository.jpa.specifications.SpecificationsBuilder; import org.eclipse.hawkbit.repository.model.AssignedSoftwareModule; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTagManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTagManagement.java index dd10ffce8..9a44f1319 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTagManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTagManagement.java @@ -29,7 +29,7 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag; import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag; -import org.eclipse.hawkbit.repository.jpa.repository.rsql.RSQLUtility; +import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility; import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.TargetTag; import org.eclipse.hawkbit.tenancy.TenantAware; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetManagement.java index e5be3d7c3..8d2fabac7 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetManagement.java @@ -39,7 +39,7 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo; import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo_; import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag; import org.eclipse.hawkbit.repository.jpa.model.JpaTarget_; -import org.eclipse.hawkbit.repository.jpa.repository.rsql.RSQLUtility; +import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility; import org.eclipse.hawkbit.repository.jpa.specifications.SpecificationsBuilder; import org.eclipse.hawkbit.repository.jpa.specifications.TargetSpecifications; import org.eclipse.hawkbit.repository.model.Target; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/eventbus/CacheFieldEntityListener.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/eventbus/CacheFieldEntityListener.java index 20c5b0caa..3c0a46b14 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/eventbus/CacheFieldEntityListener.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/eventbus/CacheFieldEntityListener.java @@ -17,7 +17,7 @@ import javax.persistence.PostRemove; import org.apache.commons.lang3.reflect.FieldUtils; import org.eclipse.hawkbit.repository.jpa.cache.CacheField; import org.eclipse.hawkbit.repository.jpa.cache.CacheKeys; -import org.eclipse.hawkbit.repository.jpa.repository.model.helper.CacheManagerHolder; +import org.eclipse.hawkbit.repository.jpa.model.helper.CacheManagerHolder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.cache.Cache; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/eventbus/EntityPropertyChangeListener.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/eventbus/EntityPropertyChangeListener.java index 35cfd9f5e..df9d600c1 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/eventbus/EntityPropertyChangeListener.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/eventbus/EntityPropertyChangeListener.java @@ -17,8 +17,8 @@ import org.eclipse.hawkbit.repository.eventbus.event.ActionPropertyChangeEvent; import org.eclipse.hawkbit.repository.eventbus.event.RolloutGroupPropertyChangeEvent; import org.eclipse.hawkbit.repository.eventbus.event.RolloutPropertyChangeEvent; import org.eclipse.hawkbit.repository.jpa.executor.AfterTransactionCommitExecutor; -import org.eclipse.hawkbit.repository.jpa.repository.model.helper.AfterTransactionCommitExecutorHolder; -import org.eclipse.hawkbit.repository.jpa.repository.model.helper.EventBusHolder; +import org.eclipse.hawkbit.repository.jpa.model.helper.AfterTransactionCommitExecutorHolder; +import org.eclipse.hawkbit.repository.jpa.model.helper.EventBusHolder; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.RolloutGroup; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaTenantAwareBaseEntity.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaTenantAwareBaseEntity.java index 235687d1f..880a51167 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaTenantAwareBaseEntity.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaTenantAwareBaseEntity.java @@ -13,8 +13,8 @@ import javax.persistence.MappedSuperclass; import javax.persistence.PrePersist; import org.eclipse.hawkbit.repository.exception.TenantNotExistException; -import org.eclipse.hawkbit.repository.jpa.repository.model.helper.SystemManagementHolder; -import org.eclipse.hawkbit.repository.jpa.repository.model.helper.TenantAwareHolder; +import org.eclipse.hawkbit.repository.jpa.model.helper.SystemManagementHolder; +import org.eclipse.hawkbit.repository.jpa.model.helper.TenantAwareHolder; import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity; import org.eclipse.persistence.annotations.Multitenant; import org.eclipse.persistence.annotations.MultitenantType; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTarget.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTarget.java index 24cabf7d4..05c8bc229 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTarget.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTarget.java @@ -36,9 +36,9 @@ import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; import org.eclipse.hawkbit.im.authentication.SpPermission; -import org.eclipse.hawkbit.repository.jpa.repository.model.helper.SecurityChecker; -import org.eclipse.hawkbit.repository.jpa.repository.model.helper.SecurityTokenGeneratorHolder; -import org.eclipse.hawkbit.repository.jpa.repository.model.helper.SystemSecurityContextHolder; +import org.eclipse.hawkbit.repository.jpa.model.helper.SecurityChecker; +import org.eclipse.hawkbit.repository.jpa.model.helper.SecurityTokenGeneratorHolder; +import org.eclipse.hawkbit.repository.jpa.model.helper.SystemSecurityContextHolder; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Target; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetInfo.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetInfo.java index ce7074443..6b5a3d1af 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetInfo.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetInfo.java @@ -37,8 +37,8 @@ import javax.persistence.OneToOne; import javax.persistence.Table; import javax.persistence.Transient; -import org.eclipse.hawkbit.repository.jpa.repository.model.helper.SystemSecurityContextHolder; -import org.eclipse.hawkbit.repository.jpa.repository.model.helper.TenantConfigurationManagementHolder; +import org.eclipse.hawkbit.repository.jpa.model.helper.SystemSecurityContextHolder; +import org.eclipse.hawkbit.repository.jpa.model.helper.TenantConfigurationManagementHolder; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.PollStatus; import org.eclipse.hawkbit.repository.model.Target; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/AfterTransactionCommitExecutorHolder.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/AfterTransactionCommitExecutorHolder.java similarity index 96% rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/AfterTransactionCommitExecutorHolder.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/AfterTransactionCommitExecutorHolder.java index dcd02d30a..a1a4416c3 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/AfterTransactionCommitExecutorHolder.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/AfterTransactionCommitExecutorHolder.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.jpa.repository.model.helper; +package org.eclipse.hawkbit.repository.jpa.model.helper; import org.eclipse.hawkbit.repository.jpa.eventbus.EntityPropertyChangeListener; import org.eclipse.hawkbit.repository.jpa.executor.AfterTransactionCommitExecutor; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/CacheManagerHolder.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/CacheManagerHolder.java similarity index 96% rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/CacheManagerHolder.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/CacheManagerHolder.java index b380ced8f..cdc834f08 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/CacheManagerHolder.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/CacheManagerHolder.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.jpa.repository.model.helper; +package org.eclipse.hawkbit.repository.jpa.model.helper; import org.eclipse.hawkbit.repository.jpa.eventbus.CacheFieldEntityListener; import org.springframework.beans.factory.annotation.Autowired; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/EventBusHolder.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/EventBusHolder.java similarity index 95% rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/EventBusHolder.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/EventBusHolder.java index 0b0a54829..0bf29cbdb 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/EventBusHolder.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/EventBusHolder.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.jpa.repository.model.helper; +package org.eclipse.hawkbit.repository.jpa.model.helper; import org.eclipse.hawkbit.repository.jpa.eventbus.CacheFieldEntityListener; import org.springframework.beans.factory.annotation.Autowired; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/SecurityChecker.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/SecurityChecker.java similarity index 96% rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/SecurityChecker.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/SecurityChecker.java index 54448cf2b..da4f223e6 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/SecurityChecker.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/SecurityChecker.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.jpa.repository.model.helper; +package org.eclipse.hawkbit.repository.jpa.model.helper; import org.springframework.security.core.Authentication; import org.springframework.security.core.GrantedAuthority; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/SecurityTokenGeneratorHolder.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/SecurityTokenGeneratorHolder.java similarity index 95% rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/SecurityTokenGeneratorHolder.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/SecurityTokenGeneratorHolder.java index 10191b9e1..64c158c87 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/SecurityTokenGeneratorHolder.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/SecurityTokenGeneratorHolder.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.jpa.repository.model.helper; +package org.eclipse.hawkbit.repository.jpa.model.helper; import org.eclipse.hawkbit.security.SecurityTokenGenerator; import org.springframework.beans.factory.annotation.Autowired; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/SystemManagementHolder.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/SystemManagementHolder.java similarity index 95% rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/SystemManagementHolder.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/SystemManagementHolder.java index 7365fec90..1b1fbb091 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/SystemManagementHolder.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/SystemManagementHolder.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.jpa.repository.model.helper; +package org.eclipse.hawkbit.repository.jpa.model.helper; import org.eclipse.hawkbit.repository.SystemManagement; import org.springframework.beans.factory.annotation.Autowired; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/SystemSecurityContextHolder.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/SystemSecurityContextHolder.java similarity index 94% rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/SystemSecurityContextHolder.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/SystemSecurityContextHolder.java index f6b20a3fd..109c11280 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/SystemSecurityContextHolder.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/SystemSecurityContextHolder.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.jpa.repository.model.helper; +package org.eclipse.hawkbit.repository.jpa.model.helper; import org.eclipse.hawkbit.security.SystemSecurityContext; import org.springframework.beans.factory.annotation.Autowired; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/TenantAwareHolder.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/TenantAwareHolder.java similarity index 94% rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/TenantAwareHolder.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/TenantAwareHolder.java index c4ded314d..a034cd605 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/TenantAwareHolder.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/TenantAwareHolder.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.jpa.repository.model.helper; +package org.eclipse.hawkbit.repository.jpa.model.helper; import org.eclipse.hawkbit.tenancy.TenantAware; import org.springframework.beans.factory.annotation.Autowired; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/TenantConfigurationManagementHolder.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/TenantConfigurationManagementHolder.java similarity index 95% rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/TenantConfigurationManagementHolder.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/TenantConfigurationManagementHolder.java index 8fbcb2411..239274c45 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/model/helper/TenantConfigurationManagementHolder.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/TenantConfigurationManagementHolder.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.jpa.repository.model.helper; +package org.eclipse.hawkbit.repository.jpa.model.helper; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; import org.springframework.beans.factory.annotation.Autowired; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/rsql/PropertyMapper.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/PropertyMapper.java similarity index 95% rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/rsql/PropertyMapper.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/PropertyMapper.java index 85051d192..db4417960 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/rsql/PropertyMapper.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/PropertyMapper.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.jpa.repository.rsql; +package org.eclipse.hawkbit.repository.jpa.rsql; import java.util.HashMap; import java.util.Map; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/rsql/RSQLUtility.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLUtility.java similarity index 99% rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/rsql/RSQLUtility.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLUtility.java index c8b796e2d..91e03342e 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/rsql/RSQLUtility.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLUtility.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.jpa.repository.rsql; +package org.eclipse.hawkbit.repository.jpa.rsql; import java.util.ArrayList; import java.util.Arrays; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractIntegrationTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractIntegrationTest.java index e951f736f..a1eff3fae 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractIntegrationTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractIntegrationTest.java @@ -16,6 +16,7 @@ import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import org.eclipse.hawkbit.ExcludePathAwareShallowETagFilter; +import org.eclipse.hawkbit.RepositoryApplicationConfiguration; import org.eclipse.hawkbit.cache.TenantAwareCacheManager; import org.eclipse.hawkbit.repository.ArtifactManagement; import org.eclipse.hawkbit.repository.ControllerManagement; @@ -29,7 +30,22 @@ import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.TargetFilterQueryManagement; import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; -import org.eclipse.hawkbit.repository.jpa.configuration.RepositoryApplicationConfiguration; +import org.eclipse.hawkbit.repository.jpa.ActionRepository; +import org.eclipse.hawkbit.repository.jpa.ActionStatusRepository; +import org.eclipse.hawkbit.repository.jpa.DistributionSetRepository; +import org.eclipse.hawkbit.repository.jpa.DistributionSetTagRepository; +import org.eclipse.hawkbit.repository.jpa.DistributionSetTypeRepository; +import org.eclipse.hawkbit.repository.jpa.ExternalArtifactRepository; +import org.eclipse.hawkbit.repository.jpa.LocalArtifactRepository; +import org.eclipse.hawkbit.repository.jpa.RolloutGroupRepository; +import org.eclipse.hawkbit.repository.jpa.RolloutRepository; +import org.eclipse.hawkbit.repository.jpa.SoftwareModuleMetadataRepository; +import org.eclipse.hawkbit.repository.jpa.SoftwareModuleRepository; +import org.eclipse.hawkbit.repository.jpa.SoftwareModuleTypeRepository; +import org.eclipse.hawkbit.repository.jpa.TargetInfoRepository; +import org.eclipse.hawkbit.repository.jpa.TargetRepository; +import org.eclipse.hawkbit.repository.jpa.TargetTagRepository; +import org.eclipse.hawkbit.repository.jpa.TenantMetaDataRepository; import org.eclipse.hawkbit.repository.jpa.utils.RepositoryDataGenerator.DatabaseCleanupUtil; import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TestConfiguration.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TestConfiguration.java index 22ae16d6f..5339ceef2 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TestConfiguration.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TestConfiguration.java @@ -15,7 +15,7 @@ import org.eclipse.hawkbit.HawkbitServerProperties; import org.eclipse.hawkbit.cache.CacheConstants; import org.eclipse.hawkbit.cache.TenancyCacheManager; import org.eclipse.hawkbit.cache.TenantAwareCacheManager; -import org.eclipse.hawkbit.repository.jpa.repository.model.helper.EventBusHolder; +import org.eclipse.hawkbit.repository.jpa.model.helper.EventBusHolder; import org.eclipse.hawkbit.repository.jpa.utils.RepositoryDataGenerator; import org.eclipse.hawkbit.repository.jpa.utils.RepositoryDataGenerator.DatabaseCleanupUtil; import org.eclipse.hawkbit.security.DdiSecurityProperties; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/WithSpringAuthorityRule.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/WithSpringAuthorityRule.java index aeacad509..e61215973 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/WithSpringAuthorityRule.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/WithSpringAuthorityRule.java @@ -17,7 +17,7 @@ import java.util.concurrent.Callable; import org.eclipse.hawkbit.im.authentication.SpPermission; import org.eclipse.hawkbit.im.authentication.TenantAwareAuthenticationDetails; -import org.eclipse.hawkbit.repository.jpa.repository.model.helper.SystemManagementHolder; +import org.eclipse.hawkbit.repository.jpa.model.helper.SystemManagementHolder; import org.junit.rules.TestRule; import org.junit.runner.Description; import org.junit.runners.model.Statement; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/eventbus/CacheFieldEntityListenerTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/eventbus/CacheFieldEntityListenerTest.java index 4845e2ccc..9c5415bbb 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/eventbus/CacheFieldEntityListenerTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/eventbus/CacheFieldEntityListenerTest.java @@ -16,7 +16,7 @@ import static org.mockito.Mockito.when; import org.eclipse.hawkbit.repository.jpa.cache.CacheField; import org.eclipse.hawkbit.repository.jpa.cache.CacheKeys; -import org.eclipse.hawkbit.repository.jpa.repository.model.helper.CacheManagerHolder; +import org.eclipse.hawkbit.repository.jpa.model.helper.CacheManagerHolder; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLUtilityTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLUtilityTest.java index 9e0627178..04901d948 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLUtilityTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLUtilityTest.java @@ -32,7 +32,6 @@ import org.eclipse.hawkbit.repository.SoftwareModuleFields; import org.eclipse.hawkbit.repository.TargetFields; import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException; import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException; -import org.eclipse.hawkbit.repository.jpa.repository.rsql.RSQLUtility; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/json/model/ExceptionInfoTest.java b/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/json/model/ExceptionInfoTest.java index 263bb75c5..901702795 100644 --- a/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/json/model/ExceptionInfoTest.java +++ b/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/json/model/ExceptionInfoTest.java @@ -13,7 +13,6 @@ import static org.fest.assertions.Assertions.assertThat; import java.util.ArrayList; import java.util.List; -import org.eclipse.hawkbit.rest.json.model.ExceptionInfo; import org.junit.Test; import ru.yandex.qatools.allure.annotations.Description; From 53156cb16fdf8b503c9d3e26f4cd91a404a54289 Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Fri, 27 May 2016 15:25:08 +0200 Subject: [PATCH 24/54] Javadoc, sonar issue, package cycles. Signed-off-by: Kai Zimmermann --- .../resource/DdiArtifactStoreController.java | 5 +- .../ddi/rest/resource/DdiRootController.java | 19 ++++---- .../rest/resource/DdiDeploymentBaseTest.java | 5 +- .../resource/MgmtDistributionSetResource.java | 2 +- .../hawkbit-repository-api/pom.xml | 7 ++- .../eclipse/hawkbit/repository/Constants.java | 31 ++++++++++++ .../repository/ControllerManagement.java | 48 +++++++++++++++++-- .../repository/DeploymentManagement.java | 43 +++++++++++++---- .../repository/DistributionSetManagement.java | 23 ++++++++- .../hawkbit/repository/ReportManagement.java | 3 +- .../repository/RolloutGroupManagement.java | 24 ++++++++-- .../hawkbit/repository/RolloutManagement.java | 10 +++- .../repository/SoftwareManagement.java | 20 ++++++++ .../hawkbit/repository/TagManagement.java | 14 ++++++ .../hawkbit/repository/TargetManagement.java | 20 ++++++-- .../hawkbit/repository/model/Action.java | 6 --- .../repository/model/AssignmentResult.java | 3 ++ .../hawkbit/repository/model/Constants.java | 27 +++++++++++ .../repository/model/DistributionSet.java | 5 -- .../{ => model}/DistributionSetFilter.java | 4 +- .../repository/model/DistributionSetType.java | 42 +++++++++------- .../model/SoftwareModuleMetadata.java | 11 +++++ .../eclipse/hawkbit/repository/model/Tag.java | 10 ++++ .../repository/model/TargetFilterQuery.java | 38 +++++++++++++++ .../hawkbit/repository/model/TargetInfo.java | 33 +++++++++++-- .../hawkbit/repository/model/TargetTag.java | 7 +++ .../{ => model}/TargetWithActionType.java | 6 +-- .../repository/model/TenantConfiguration.java | 19 ++++++++ .../jpa/JpaControllerManagement.java | 19 +++++--- .../jpa/JpaDeploymentManagement.java | 6 +-- .../jpa/JpaDistributionSetManagement.java | 6 +-- .../repository/jpa/JpaRolloutManagement.java | 2 +- .../repository/jpa/cache/CacheField.java | 2 +- .../repository/jpa/cache/CacheKeys.java | 2 +- .../repository/jpa/eventbus/EventMerger.java | 4 +- .../jpa/model/AbstractJpaArtifact.java | 3 ++ .../jpa/model/AbstractJpaBaseEntity.java | 5 +- .../jpa/model/AbstractJpaNamedEntity.java | 3 ++ .../AbstractJpaNamedVersionedEntity.java | 3 ++ .../repository/jpa/model/AbstractJpaTag.java | 3 ++ .../CacheFieldEntityListener.java | 2 +- .../EntityPropertyChangeListener.java | 2 +- .../repository/jpa/model/JpaAction.java | 3 ++ .../repository/jpa/model/JpaActionStatus.java | 3 ++ .../jpa/model/JpaDistributionSet.java | 9 ++-- .../jpa/model/JpaDistributionSetType.java | 42 ++-------------- .../jpa/model/JpaExternalArtifact.java | 3 ++ .../model/JpaExternalArtifactProvider.java | 3 ++ .../jpa/model/JpaLocalArtifact.java | 3 ++ .../repository/jpa/model/JpaRollout.java | 3 ++ .../repository/jpa/model/JpaRolloutGroup.java | 3 ++ .../jpa/model/JpaSoftwareModule.java | 3 ++ .../jpa/model/JpaSoftwareModuleType.java | 3 ++ .../repository/jpa/model/JpaTarget.java | 3 ++ .../jpa/model/JpaTargetFilterQuery.java | 3 ++ .../jpa/model/JpaTenantConfiguration.java | 3 ++ .../jpa/model/JpaTenantMetaData.java | 23 ++------- .../AfterTransactionCommitExecutorHolder.java | 2 +- .../jpa/model/helper/CacheManagerHolder.java | 2 +- .../jpa/model/helper/EventBusHolder.java | 2 +- .../jpa/rollout}/RolloutScheduler.java | 5 +- .../jpa/DeploymentManagementTest.java | 13 ++--- .../jpa/DistributionSetManagementTest.java | 2 +- .../repository/jpa/TagManagementTest.java | 2 +- .../CacheFieldEntityListenerTest.java | 1 + .../ui/common}/DistributionSetIdName.java | 10 +++- .../SoftwareModuleDetailsTable.java | 3 +- .../dstable/DistributionSetDetails.java | 2 +- .../dstable/DistributionSetTable.java | 4 +- .../dstable/ManageDistBeanQuery.java | 4 +- .../SoftwareModuleAssignmentDiscardEvent.java | 2 +- .../footer/DSDeleteActionsLayout.java | 2 +- ...DistributionsConfirmationWindowLayout.java | 2 +- .../state/ManageDistUIState.java | 2 +- .../dstable/DistributionBeanQuery.java | 4 +- .../management/dstable/DistributionTable.java | 2 +- .../event/DistributionTagDropEvent.java | 2 +- .../management/footer/CountMessageLabel.java | 2 +- .../footer/DeleteActionsLayout.java | 2 +- .../ManangementConfirmationWindowLayout.java | 6 +-- .../management/state/ManagementUIState.java | 2 +- .../ui/management/state/TargetBulkUpload.java | 2 +- .../management/state/TargetTableFilters.java | 2 +- .../targettable/BulkUploadHandler.java | 2 +- .../TargetBulkUpdateWindowLayout.java | 2 +- .../management/targettable/TargetTable.java | 2 +- .../targettable/TargetTableHeader.java | 2 +- .../rollout/AddUpdateRolloutWindowLayout.java | 8 ++-- .../rollout/DistributionBeanQuery.java | 4 +- 89 files changed, 548 insertions(+), 213 deletions(-) create mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/Constants.java create mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Constants.java rename hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/{ => model}/DistributionSetFilter.java (97%) rename hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/{ => model}/TargetWithActionType.java (88%) rename hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/{eventbus => model}/CacheFieldEntityListener.java (99%) rename hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/{eventbus => model}/EntityPropertyChangeListener.java (98%) rename hawkbit-repository/{hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository => hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rollout}/RolloutScheduler.java (93%) rename {hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model => hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common}/DistributionSetIdName.java (86%) diff --git a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java index 6c133f03c..859b4c156 100644 --- a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java +++ b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java @@ -17,6 +17,7 @@ import javax.servlet.http.HttpServletRequest; import org.eclipse.hawkbit.artifact.repository.model.DbArtifact; import org.eclipse.hawkbit.ddi.dl.rest.api.DdiDlArtifactStoreControllerRestApi; import org.eclipse.hawkbit.repository.ArtifactManagement; +import org.eclipse.hawkbit.repository.Constants; import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.jpa.cache.CacheWriteNotify; import org.eclipse.hawkbit.repository.model.Action; @@ -144,11 +145,11 @@ public class DdiArtifactStoreController implements DdiDlArtifactStoreControllerR actionStatus.setStatus(Status.DOWNLOAD); if (range != null) { - actionStatus.addMessage(ControllerManagement.SERVER_MESSAGE_PREFIX + "Target downloads range " + range + actionStatus.addMessage(Constants.SERVER_MESSAGE_PREFIX + "Target downloads range " + range + " of: " + request.getRequestURI()); } else { actionStatus.addMessage( - ControllerManagement.SERVER_MESSAGE_PREFIX + "Target downloads: " + request.getRequestURI()); + Constants.SERVER_MESSAGE_PREFIX + "Target downloads: " + request.getRequestURI()); } controllerManagement.addInformationalActionStatus(actionStatus); return action; diff --git a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java index 09cb4c577..881eee659 100644 --- a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java +++ b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java @@ -29,6 +29,7 @@ import org.eclipse.hawkbit.ddi.json.model.DdiDeploymentBase; import org.eclipse.hawkbit.ddi.json.model.DdiResult.FinalResult; import org.eclipse.hawkbit.ddi.rest.api.DdiRootControllerRestApi; import org.eclipse.hawkbit.repository.ArtifactManagement; +import org.eclipse.hawkbit.repository.Constants; import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; @@ -180,11 +181,11 @@ public class DdiRootController implements DdiRootControllerRestApi { statusMessage.setStatus(Status.DOWNLOAD); if (range != null) { - statusMessage.addMessage(ControllerManagement.SERVER_MESSAGE_PREFIX + "Target downloads range " + range + statusMessage.addMessage(Constants.SERVER_MESSAGE_PREFIX + "Target downloads range " + range + " of: " + request.getRequestURI()); } else { statusMessage.addMessage( - ControllerManagement.SERVER_MESSAGE_PREFIX + "Target downloads " + request.getRequestURI()); + Constants.SERVER_MESSAGE_PREFIX + "Target downloads " + request.getRequestURI()); } controllerManagement.addInformationalActionStatus(statusMessage); return action; @@ -247,7 +248,7 @@ public class DdiRootController implements DdiRootControllerRestApi { LOG.debug("Found an active UpdateAction for target {}. returning deyploment: {}", targetid, base); - controllerManagement.registerRetrieved(action, ControllerManagement.SERVER_MESSAGE_PREFIX + controllerManagement.registerRetrieved(action, Constants.SERVER_MESSAGE_PREFIX + "Target retrieved update action and should start now the download."); return new ResponseEntity<>(base, HttpStatus.OK); @@ -302,13 +303,13 @@ public class DdiRootController implements DdiRootControllerRestApi { LOG.debug("Controller confirmed cancel (actionid: {}, targetid: {}) as we got {} report.", actionid, targetid, feedback.getStatus().getExecution()); actionStatus.setStatus(Status.CANCELED); - actionStatus.addMessage(ControllerManagement.SERVER_MESSAGE_PREFIX + "Target confirmed cancelation."); + actionStatus.addMessage(Constants.SERVER_MESSAGE_PREFIX + "Target confirmed cancelation."); break; case REJECTED: LOG.info("Controller reported internal error (actionid: {}, targetid: {}) as we got {} report.", actionid, targetid, feedback.getStatus().getExecution()); actionStatus.setStatus(Status.WARNING); - actionStatus.addMessage(ControllerManagement.SERVER_MESSAGE_PREFIX + "Target REJECTED update."); + actionStatus.addMessage(Constants.SERVER_MESSAGE_PREFIX + "Target REJECTED update."); break; case CLOSED: handleClosedUpdateStatus(feedback, targetid, actionid, actionStatus); @@ -336,7 +337,7 @@ public class DdiRootController implements DdiRootControllerRestApi { targetid, feedback.getStatus().getExecution()); actionStatus.setStatus(Status.RUNNING); actionStatus.addMessage( - ControllerManagement.SERVER_MESSAGE_PREFIX + "Target reported " + feedback.getStatus().getExecution()); + Constants.SERVER_MESSAGE_PREFIX + "Target reported " + feedback.getStatus().getExecution()); } private static void handleClosedUpdateStatus(final DdiActionFeedback feedback, final String targetid, @@ -345,10 +346,10 @@ public class DdiRootController implements DdiRootControllerRestApi { feedback.getStatus().getExecution()); if (feedback.getStatus().getResult().getFinished() == FinalResult.FAILURE) { actionStatus.setStatus(Status.ERROR); - actionStatus.addMessage(ControllerManagement.SERVER_MESSAGE_PREFIX + "Target reported CLOSED with ERROR!"); + actionStatus.addMessage(Constants.SERVER_MESSAGE_PREFIX + "Target reported CLOSED with ERROR!"); } else { actionStatus.setStatus(Status.FINISHED); - actionStatus.addMessage(ControllerManagement.SERVER_MESSAGE_PREFIX + "Target reported CLOSED with OK!"); + actionStatus.addMessage(Constants.SERVER_MESSAGE_PREFIX + "Target reported CLOSED with OK!"); } } @@ -386,7 +387,7 @@ public class DdiRootController implements DdiRootControllerRestApi { LOG.debug("Found an active CancelAction for target {}. returning cancel: {}", targetid, cancel); - controllerManagement.registerRetrieved(action, ControllerManagement.SERVER_MESSAGE_PREFIX + controllerManagement.registerRetrieved(action, Constants.SERVER_MESSAGE_PREFIX + "Target retrieved cancel action and should start now the cancelation."); return new ResponseEntity<>(cancel, HttpStatus.OK); diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java index 9d52a67f4..cafe655e9 100644 --- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java +++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java @@ -31,6 +31,7 @@ import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.ActionType; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; +import org.eclipse.hawkbit.repository.model.Constants; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.Target; @@ -117,7 +118,7 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD assertThat(actionStatusRepository.findAll()).isEmpty(); List saved = deploymentManagement.assignDistributionSet(ds.getId(), ActionType.FORCED, - Action.NO_FORCE_TIME, savedTarget.getControllerId()).getAssignedEntity(); + Constants.NO_FORCE_TIME, savedTarget.getControllerId()).getAssignedEntity(); assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(1); final Action action = deploymentManagement.findActiveActionsByTarget(savedTarget).get(0); @@ -256,7 +257,7 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD assertThat(actionStatusRepository.findAll()).isEmpty(); List saved = deploymentManagement - .assignDistributionSet(ds.getId(), ActionType.SOFT, Action.NO_FORCE_TIME, savedTarget.getControllerId()) + .assignDistributionSet(ds.getId(), ActionType.SOFT, Constants.NO_FORCE_TIME, savedTarget.getControllerId()) .getAssignedEntity(); assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(1); diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java index ae4972610..e9249f551 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java @@ -32,12 +32,12 @@ import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.repository.TargetManagement; -import org.eclipse.hawkbit.repository.TargetWithActionType; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetMetadata; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.Target; +import org.eclipse.hawkbit.repository.model.TargetWithActionType; import org.eclipse.hawkbit.tenancy.TenantAware; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/hawkbit-repository/hawkbit-repository-api/pom.xml b/hawkbit-repository/hawkbit-repository-api/pom.xml index ab8ab75db..076ae8cd8 100644 --- a/hawkbit-repository/hawkbit-repository-api/pom.xml +++ b/hawkbit-repository/hawkbit-repository-api/pom.xml @@ -36,5 +36,10 @@ org.springframework.hateoas spring-hateoas -
+ + org.springframework.boot + spring-boot-configuration-processor + true + +
\ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/Constants.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/Constants.java new file mode 100644 index 000000000..114997fca --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/Constants.java @@ -0,0 +1,31 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository; + +import org.eclipse.hawkbit.repository.model.ActionStatus; +import org.eclipse.hawkbit.repository.model.Target; + +/** + * Repository constants. + * + */ +public final class Constants { + + /** + * Prefix that the server puts in front of + * {@link ActionStatus#getMessages()} is the comments was generated by it + * and not be thy {@link Target}. + */ + public static final String SERVER_MESSAGE_PREFIX = "Update Server: "; + + private Constants() { + // Utility class. + } + +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java index dd91ee07a..cb325cbc9 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java @@ -12,6 +12,7 @@ import java.net.URI; import java.util.Collection; import java.util.List; import java.util.Map; +import java.util.concurrent.TimeUnit; import javax.validation.constraints.NotNull; @@ -40,8 +41,6 @@ import org.springframework.security.access.prepost.PreAuthorize; */ public interface ControllerManagement { - String SERVER_MESSAGE_PREFIX = "Update Server: "; - /** * Adds an {@link ActionStatus} for a cancel {@link Action} including * potential state changes for the target and the {@link Action} itself. @@ -270,17 +269,60 @@ public interface ControllerManagement { URI address); /** - * Generates an empty {@link ActionStatus} without persisting it. + * Generates an empty {@link ActionStatus} object without persisting it. * * @return {@link ActionStatus} object */ ActionStatus generateActionStatus(); + /** + * Generates an {@link ActionStatus} object without persisting it. + * + * @param action + * the {@link ActionStatus} belongs to. + * @param status + * as reflected by this {@link ActionStatus}. + * @param occurredAt + * time in {@link TimeUnit#MILLISECONDS} GMT when the status + * change happened. + * @param message + * optional comment + * + * @return {@link ActionStatus} object + */ ActionStatus generateActionStatus(Action action, Status status, Long occurredAt, final String message); + /** + * Generates an {@link ActionStatus} object without persisting it. + * + * @param action + * the {@link ActionStatus} belongs to. + * @param status + * as reflected by this {@link ActionStatus}. + * @param occurredAt + * time in {@link TimeUnit#MILLISECONDS} GMT when the status + * change happened. + * @param messages + * optional comments + * + * @return {@link ActionStatus} object + */ ActionStatus generateActionStatus(Action action, final Status status, Long occurredAt, final Collection messages); + /** + * Generates an {@link ActionStatus} object without persisting it. + * + * @param action + * the {@link ActionStatus} belongs to. + * @param status + * as reflected by this {@link ActionStatus}. + * @param occurredAt + * time in {@link TimeUnit#MILLISECONDS} GMT when the status + * change happened. + * + * @return {@link ActionStatus} object + */ ActionStatus generateActionStatus(Action action, Status status, Long occurredAt); } diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java index b6efec9b0..6a6c7851d 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java @@ -16,8 +16,11 @@ import javax.validation.constraints.NotNull; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; import org.eclipse.hawkbit.repository.exception.CancelActionNotAllowedException; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; +import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException; +import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.ActionType; +import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; import org.eclipse.hawkbit.repository.model.ActionWithStatusCount; import org.eclipse.hawkbit.repository.model.DistributionSet; @@ -26,6 +29,7 @@ import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.RolloutGroup; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.repository.model.Target; +import org.eclipse.hawkbit.repository.model.TargetWithActionType; import org.hibernate.validator.constraints.NotEmpty; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -147,17 +151,17 @@ public interface DeploymentManagement { /** * Cancels given {@link Action} for given {@link Target}. The method will - * immediately add a {@link ActionStatus.Status#CANCELED} status to the - * action. However, it might be possible that the controller will continue - * to work on the cancellation. + * immediately add a {@link Status#CANCELED} status to the action. However, + * it might be possible that the controller will continue to work on the + * cancellation. * * @param action * to be canceled * @param target * for which the action needs cancellation * - * @return generated {@link CancelAction} or null if not in - * {@link Target#getActiveActions()}. + * @return generated {@link Action} or null if not active on + * given {@link Target}. * @throws CancelActionNotAllowedException * in case the given action is not active or is already a cancel * action @@ -173,6 +177,12 @@ public interface DeploymentManagement { * @param target * the target associated to the actions to count * @return the count value of found actions associated to the target + * + * @throws RSQLParameterUnsupportedFieldException + * if a field in the RSQL string is used but not provided by the + * given {@code fieldNameProvider} + * @throws RSQLParameterSyntaxException + * if the RSQL syntax is wrong */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) Long countActionsByTarget(@NotNull String rsqlParam, @NotNull Target target); @@ -276,6 +286,12 @@ public interface DeploymentManagement { * the page request * @return a slice of actions assigned to the specific target and the * specification + * + * @throws RSQLParameterUnsupportedFieldException + * if a field in the RSQL string is used but not provided by the + * given {@code fieldNameProvider} + * @throws RSQLParameterSyntaxException + * if the RSQL syntax is wrong */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) Slice findActionsByTarget(@NotNull String rsqlParam, @NotNull Target target, @NotNull Pageable pageable); @@ -404,8 +420,8 @@ public interface DeploymentManagement { * @param target * for which the action needs cancellation * - * @return generated {@link CancelAction} or null if not in - * {@link Target#getActiveActions()}. + * @return generated {@link Action} or null if not active on + * {@link Target}. * @throws CancelActionNotAllowedException * in case the given action is not active */ @@ -413,14 +429,14 @@ public interface DeploymentManagement { Action forceQuitAction(@NotNull Action action); /** - * Updates a {@link TargetAction} and forces the {@link TargetAction} if - * it's not already forced. + * Updates a {@link Action} and forces the {@link Action} if it's not + * already forced. * * @param targetId * the ID of the target * @param actionId * the ID of the action - * @return the updated or the found {@link TargetAction} + * @return the updated or the found {@link Action} */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET) Action forceTargetAction(@NotNull Long actionId); @@ -444,6 +460,13 @@ public interface DeploymentManagement { */ Action generateAction(); + /** + * All {@link ActionStatus} entries in the repository. + * + * @param pageable + * the pagination parameter + * @return {@link Page} of {@link ActionStatus} entries + */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) Page findActionStatusAll(@NotNull Pageable pageable); } diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java index dcb135e62..3e31a5a9c 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java @@ -15,13 +15,15 @@ import java.util.Set; import javax.validation.constraints.NotNull; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; -import org.eclipse.hawkbit.repository.DistributionSetFilter.DistributionSetFilterBuilder; import org.eclipse.hawkbit.repository.exception.DistributionSetCreationFailedMissingMandatoryModuleException; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.exception.EntityReadOnlyException; +import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException; +import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.DistributionSetFilter; import org.eclipse.hawkbit.repository.model.DistributionSetMetadata; import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult; @@ -30,6 +32,7 @@ import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.repository.model.Tag; import org.eclipse.hawkbit.repository.model.Target; +import org.eclipse.hawkbit.repository.model.DistributionSetFilter.DistributionSetFilterBuilder; import org.hibernate.validator.constraints.NotEmpty; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -292,6 +295,12 @@ public interface DistributionSetManagement { * the page request to page the result * @return a paged result of all meta data entries for a given distribution * set id + * + * @throws RSQLParameterUnsupportedFieldException + * if a field in the RSQL string is used but not provided by the + * given {@code fieldNameProvider} + * @throws RSQLParameterSyntaxException + * if the RSQL syntax is wrong */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) Page findDistributionSetMetadataByDistributionSetId(@NotNull Long distributionSetId, @@ -350,6 +359,12 @@ public interface DistributionSetManagement { * {@link DistributionSet#isDeleted()} == FALSE are returned. * null if both are to be returned * @return all found {@link DistributionSet}s + * + * @throws RSQLParameterUnsupportedFieldException + * if a field in the RSQL string is used but not provided by the + * given {@code fieldNameProvider} + * @throws RSQLParameterSyntaxException + * if the RSQL syntax is wrong */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) Page findDistributionSetsAll(@NotNull String rsqlParam, @NotNull Pageable pageReq, @@ -435,6 +450,12 @@ public interface DistributionSetManagement { * parameter for paging * * @return the found {@link SoftwareModuleType}s + * + * @throws RSQLParameterUnsupportedFieldException + * if a field in the RSQL string is used but not provided by the + * given {@code fieldNameProvider} + * @throws RSQLParameterSyntaxException + * if the RSQL syntax is wrong */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) Page findDistributionSetTypesAll(@NotNull String rsqlParam, @NotNull Pageable pageable); diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ReportManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ReportManagement.java index 49b0b505d..a27154868 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ReportManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ReportManagement.java @@ -18,6 +18,7 @@ import java.util.List; import javax.validation.constraints.NotNull; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; +import org.eclipse.hawkbit.repository.model.TargetInfo; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; import org.eclipse.hawkbit.repository.report.model.DataReportSeries; import org.eclipse.hawkbit.repository.report.model.InnerOuterDataReportSeries; @@ -182,7 +183,7 @@ public interface ReportManagement { /** * Generates a report as a {@link ListReportSeries} targets polled based on - * the {@link TargetStatus#getLastTargetQuery()} within an hour, day, week, + * the {@link TargetInfo#getLastTargetQuery()} within an hour, day, week, * month, year, more than a year, never. * * The order of the numbers within the {@link DataReportSeries} is the order diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupManagement.java index ae1cc5882..d1d3678f5 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupManagement.java @@ -11,6 +11,8 @@ package org.eclipse.hawkbit.repository; import javax.validation.constraints.NotNull; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; +import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException; +import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.RolloutGroup; import org.eclipse.hawkbit.repository.model.Target; @@ -70,16 +72,22 @@ public interface RolloutGroupManagement { /** * Retrieves a page of {@link RolloutGroup}s filtered by a given - * {@link Rollout} and the given {@link Specification}. + * {@link Rollout} and the an rsql filter. * - * @param rolloutId - * the ID of the rollout to filter the {@link RolloutGroup}s - * @param specification + * @param rollout + * the rollout to filter the {@link RolloutGroup}s + * @param rsqlParam * the specification to filter the result set based on attributes * of the {@link RolloutGroup} * @param pageable * the page request to sort and limit the result * @return a page of found {@link RolloutGroup}s + * + * @throws RSQLParameterUnsupportedFieldException + * if a field in the RSQL string is used but not provided by the + * given {@code fieldNameProvider} + * @throws RSQLParameterSyntaxException + * if the RSQL syntax is wrong */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) Page findRolloutGroupsAll(@NotNull Rollout rollout, @NotNull String rsqlParam, @@ -116,12 +124,18 @@ public interface RolloutGroupManagement { * * @param rolloutGroup * rollout group - * @param specification + * @param rsqlParam * the specification for filtering the targets of a rollout group * @param pageable * the page request to sort and limit the result * * @return Page list of targets of a rollout group + * + * @throws RSQLParameterUnsupportedFieldException + * if a field in the RSQL string is used but not provided by the + * given {@code fieldNameProvider} + * @throws RSQLParameterSyntaxException + * if the RSQL syntax is wrong */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ_AND_TARGET_READ) Page findRolloutGroupTargets(@NotNull RolloutGroup rolloutGroup, @NotNull String rsqlParam, diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java index 3ff6e0d4b..4753e70ef 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java @@ -12,6 +12,8 @@ import javax.validation.constraints.NotNull; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; import org.eclipse.hawkbit.repository.eventbus.event.RolloutGroupCreatedEvent; +import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException; +import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException; import org.eclipse.hawkbit.repository.exception.RolloutIllegalStateException; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.Rollout.RolloutStatus; @@ -171,11 +173,17 @@ public interface RolloutManagement { /** * Retrieves all rollouts found by the given specification. * - * @param specification + * @param rsqlParam * the specification to filter rollouts * @param pageable * the page request to sort and limit the result * @return a page of found rollouts + * + * @throws RSQLParameterUnsupportedFieldException + * if a field in the RSQL string is used but not provided by the + * given {@code fieldNameProvider} + * @throws RSQLParameterSyntaxException + * if the RSQL syntax is wrong */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) Page findAllWithDetailedStatusByPredicate(@NotNull String rsqlParam, @NotNull Pageable pageable); diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java index 465cb50ea..9723dfd73 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java @@ -16,6 +16,8 @@ import javax.validation.constraints.NotNull; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; +import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException; +import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException; import org.eclipse.hawkbit.repository.model.AssignedSoftwareModule; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.SoftwareModule; @@ -284,6 +286,12 @@ public interface SoftwareManagement { * the page request to page the result * @return a paged result of all meta data entries for a given software * module id + * + * @throws RSQLParameterUnsupportedFieldException + * if a field in the RSQL string is used but not provided by the + * given {@code fieldNameProvider} + * @throws RSQLParameterSyntaxException + * if the RSQL syntax is wrong */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) Page findSoftwareModuleMetadataBySoftwareModuleId(@NotNull Long softwareModuleId, @@ -342,6 +350,12 @@ public interface SoftwareManagement { * @param pageable * pagination parameter * @return the found {@link SoftwareModule}s + * + * @throws RSQLParameterUnsupportedFieldException + * if a field in the RSQL string is used but not provided by the + * given {@code fieldNameProvider} + * @throws RSQLParameterSyntaxException + * if the RSQL syntax is wrong */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) Page findSoftwareModulesByPredicate(@NotNull String rsqlParam, @NotNull Pageable pageable); @@ -405,6 +419,12 @@ public interface SoftwareManagement { * @param pageable * pagination parameter * @return the found {@link SoftwareModuleType}s + * + * @throws RSQLParameterUnsupportedFieldException + * if a field in the RSQL string is used but not provided by the + * given {@code fieldNameProvider} + * @throws RSQLParameterSyntaxException + * if the RSQL syntax is wrong */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) Page findSoftwareModuleTypesAll(@NotNull String rsqlParam, @NotNull Pageable pageable); diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TagManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TagManagement.java index 551e34dd9..85e5d0273 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TagManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TagManagement.java @@ -15,6 +15,8 @@ import javax.validation.constraints.NotNull; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; +import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException; +import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.Tag; @@ -135,6 +137,12 @@ public interface TagManagement { * @param pageable * pagination parameter * @return the found {@link DistributionSetTag}s, never {@code null} + * + * @throws RSQLParameterUnsupportedFieldException + * if a field in the RSQL string is used but not provided by the + * given {@code fieldNameProvider} + * @throws RSQLParameterSyntaxException + * if the RSQL syntax is wrong */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) Page findAllDistributionSetTags(@NotNull String rsqlParam, @NotNull Pageable pageable); @@ -164,6 +172,12 @@ public interface TagManagement { * @param pageable * pagination parameter * @return the found {@link Target}s, never {@code null} + * + * @throws RSQLParameterUnsupportedFieldException + * if a field in the RSQL string is used but not provided by the + * given {@code fieldNameProvider} + * @throws RSQLParameterSyntaxException + * if the RSQL syntax is wrong */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) Page findAllTargetTags(@NotNull String rsqlParam, @NotNull Pageable pageable); diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java index ccf8c6712..7ebb3e4b4 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java @@ -16,6 +16,8 @@ import javax.validation.constraints.NotNull; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; +import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException; +import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Tag; import org.eclipse.hawkbit.repository.model.Target; @@ -281,11 +283,17 @@ public interface TargetManagement { * * @param distributionSetID * the ID of the {@link DistributionSet} - * @param spec + * @param rsqlParam * the specification to filter the result set * @param pageReq * page parameter * @return the found {@link Target}s, never {@code null} + * @throws RSQLParameterUnsupportedFieldException + * if a field in the RSQL string is used but not provided by the + * given {@code fieldNameProvider} + * @throws RSQLParameterSyntaxException + * if the RSQL syntax is wrong + * */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_READ_TARGET) Page findTargetByAssignedDistributionSet(@NotNull Long distributionSetID, @NotNull String rsqlParam, @@ -381,11 +389,17 @@ public interface TargetManagement { * * @param distributionSetId * the ID of the {@link DistributionSet} - * @param spec + * @param rsqlParam * the specification to filter the result * @param pageable * page parameter * @return the found {@link Target}s, never {@code null} + * + * @throws RSQLParameterUnsupportedFieldException + * if a field in the RSQL string is used but not provided by the + * given {@code fieldNameProvider} + * @throws RSQLParameterSyntaxException + * if the RSQL syntax is wrong */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_READ_TARGET) Page findTargetByInstalledDistributionSet(@NotNull Long distributionSetId, @NotNull String rsqlParam, @@ -531,7 +545,7 @@ public interface TargetManagement { TargetTagAssignmentResult toggleTagAssignment(@NotEmpty Collection targetIds, @NotEmpty String tagName); /** - * {@link Entity} based method call for + * {@link Target} based method call for * {@link #toggleTagAssignment(Collection, String)}. * * @param targets diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Action.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Action.java index 1bd3f8c35..c2b96905e 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Action.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Action.java @@ -19,12 +19,6 @@ import java.util.concurrent.TimeUnit; */ public interface Action extends TenantAwareBaseEntity { - /** - * indicating that target action has no force time which is only needed in - * case of {@link ActionType#TIMEFORCED}. - */ - long NO_FORCE_TIME = 0L; - /** * @return the distributionSet */ diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/AssignmentResult.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/AssignmentResult.java index 043386ed1..9468c8a88 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/AssignmentResult.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/AssignmentResult.java @@ -12,6 +12,9 @@ import java.util.List; /** * Generic assignment result bean. + * + * @param + * type of the assigned and unassigned {@link BaseEntity}s. * */ public class AssignmentResult { diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Constants.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Constants.java new file mode 100644 index 000000000..b43ec6f88 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Constants.java @@ -0,0 +1,27 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.model; + +/** + * Repository model constants. + * + */ +public final class Constants { + + /** + * indicating that target action has no force time which is only needed in + * case of {@link Action.ActionType#TIMEFORCED}. + */ + public static final Long NO_FORCE_TIME = 0L; + + private Constants() { + // Utility class. + } + +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSet.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSet.java index 1c23cec27..c6532b339 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSet.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSet.java @@ -84,11 +84,6 @@ public interface DistributionSet extends NamedVersionedEntity { */ Set getModules(); - /** - * @return {@link DistributionSetIdName} view. - */ - DistributionSetIdName getDistributionSetIdName(); - /** * @param softwareModule * @return true if the module was added and false diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DistributionSetFilter.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetFilter.java similarity index 97% rename from hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DistributionSetFilter.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetFilter.java index 54f7eb8e5..c095d0f7e 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DistributionSetFilter.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetFilter.java @@ -6,12 +6,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.model; import java.util.Collection; -import org.eclipse.hawkbit.repository.model.DistributionSetType; - /** * Holds distribution set filter parameters. */ diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetType.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetType.java index 14683b1b1..5546a9f6d 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetType.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetType.java @@ -47,51 +47,59 @@ public interface DistributionSetType extends NamedEntity { * search for * @return true if found */ - boolean containsModuleType(SoftwareModuleType softwareModuleType); + default boolean containsModuleType(final SoftwareModuleType softwareModuleType) { + return containsMandatoryModuleType(softwareModuleType) || containsOptionalModuleType(softwareModuleType); + } /** - * Checks if the given {@link SoftwareModuleType} is in this - * {@link DistributionSetType} and defined as - * {@link DistributionSetTypeElement#isMandatory()}. + * Checks if the given {@link SoftwareModuleType} is in + * {@link #getMandatoryModuleTypes()}. * * @param softwareModuleType * search for * @return true if found */ - boolean containsMandatoryModuleType(SoftwareModuleType softwareModuleType); + default boolean containsMandatoryModuleType(final SoftwareModuleType softwareModuleType) { + return containsMandatoryModuleType(softwareModuleType.getId()); + } /** - * Checks if the given {@link SoftwareModuleType} is in this - * {@link DistributionSetType} and defined as - * {@link DistributionSetTypeElement#isMandatory()}. + * Checks if the given {@link SoftwareModuleType} is in + * {@link #getMandatoryModuleTypes()}. * * @param softwareModuleTypeId * search for by {@link SoftwareModuleType#getId()} * @return true if found */ - boolean containsMandatoryModuleType(Long softwareModuleTypeId); + default boolean containsMandatoryModuleType(final Long softwareModuleTypeId) { + return getMandatoryModuleTypes().stream().filter(element -> element.getId().equals(softwareModuleTypeId)) + .findFirst().isPresent(); + } /** - * Checks if the given {@link SoftwareModuleType} is in this - * {@link DistributionSetType} and NOT defined as - * {@link DistributionSetTypeElement#isMandatory()}. + * Checks if the given {@link SoftwareModuleType} is in + * {@link #getOptionalModuleTypes()}. * * @param softwareModuleType * search for * @return true if found */ - boolean containsOptionalModuleType(SoftwareModuleType softwareModuleType); + default boolean containsOptionalModuleType(final SoftwareModuleType softwareModuleType) { + return containsOptionalModuleType(softwareModuleType.getId()); + } /** - * Checks if the given {@link SoftwareModuleType} is in this - * {@link DistributionSetType} and NOT defined as - * {@link DistributionSetTypeElement#isMandatory()}. + * Checks if the given {@link SoftwareModuleType} is in + * {@link #getOptionalModuleTypes()}. * * @param softwareModuleTypeId * search by {@link SoftwareModuleType#getId()} * @return true if found */ - boolean containsOptionalModuleType(Long softwareModuleTypeId); + default boolean containsOptionalModuleType(final Long softwareModuleTypeId) { + return getOptionalModuleTypes().stream().filter(element -> element.getId().equals(softwareModuleTypeId)) + .findFirst().isPresent(); + } /** * Compares the modules of this {@link DistributionSetType} and the given diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleMetadata.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleMetadata.java index 8cece2a39..bb0f877ce 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleMetadata.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleMetadata.java @@ -8,10 +8,21 @@ */ package org.eclipse.hawkbit.repository.model; +/** + * {@link MetaData} element of a {@link SoftwareModule}. + * + */ public interface SoftwareModuleMetadata extends MetaData { + /** + * @return {@link SoftwareModule} this entry belongs to. + */ SoftwareModule getSoftwareModule(); + /** + * @param softwareModule + * this entry belongs to. + */ void setSoftwareModule(SoftwareModule softwareModule); } \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Tag.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Tag.java index 236ff2d3d..e57763920 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Tag.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Tag.java @@ -8,10 +8,20 @@ */ package org.eclipse.hawkbit.repository.model; +/** + * {@link Tag} entry. + * + */ public interface Tag extends NamedEntity { + /** + * @return colour code of the tag used in Management UI. + */ String getColour(); + /** + * @param colour + */ void setColour(String colour); } \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetFilterQuery.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetFilterQuery.java index 03508555a..9cc200d0d 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetFilterQuery.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetFilterQuery.java @@ -8,14 +8,52 @@ */ package org.eclipse.hawkbit.repository.model; +/** + * Managed filter entity. + * + * Supported operators. + *
    + *
  • Equal to : ==
  • + *
  • Not equal to : !=
  • + *
  • Less than : =lt= or <
  • + *
  • Less than or equal to : =le= or <=
  • + *
  • Greater than operator : =gt= or >
  • + *
  • Greater than or equal to : =ge= or >=
  • + *
+ * Examples of RSQL expressions in both FIQL-like and alternative notation: + *
    + *
  • version==2.0.0
  • + *
  • name==targetId1;description==plugAndPlay
  • + *
  • name==targetId1 and description==plugAndPlay
  • + *
  • name==targetId1;description==plugAndPlay
  • + *
  • name==targetId1 and description==plugAndPlay
  • + *
  • name==targetId1,description==plugAndPlay,updateStatus==UNKNOWN
  • + *
  • name==targetId1 or description==plugAndPlay or updateStatus==UNKNOWN
  • + *
+ * + */ public interface TargetFilterQuery extends TenantAwareBaseEntity { + /** + * @return name of the {@link TargetFilterQuery}. + */ String getName(); + /** + * @param name + * of the {@link TargetFilterQuery}. + */ void setName(String name); + /** + * @return RSQL query + */ String getQuery(); + /** + * @param query + * in RSQL notation. + */ void setQuery(String query); } \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetInfo.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetInfo.java index e918d7376..d2e96664c 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetInfo.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetInfo.java @@ -10,27 +10,48 @@ package org.eclipse.hawkbit.repository.model; import java.io.Serializable; import java.net.URI; +import java.text.AttributedCharacterIterator; import java.util.Map; +import java.util.concurrent.TimeUnit; public interface TargetInfo extends Serializable { - - Long getId(); - /** - * @return the ipAddress + * @return the address under whioch the target can be reached */ URI getAddress(); + /** + * @return {@link Target} this info element belongs to. + */ Target getTarget(); + /** + * @return time in {@link TimeUnit#MILLISECONDS} GMT when the {@link Target} + * polled the server the last time. + */ Long getLastTargetQuery(); + /** + * @return {@link AttributedCharacterIterator} that have been provided by + * the {@link Target} itself, e.g. hardware revision, serial number, + * mac address etc. + */ Map getControllerAttributes(); + /** + * @return time in {@link TimeUnit#MILLISECONDS} GMT when + * {@link #getInstalledDistributionSet()} was applied. + */ Long getInstallationDate(); + /** + * @return current status of the {@link Target}. + */ TargetUpdateStatus getUpdateStatus(); + /** + * @return currently installed {@link DistributionSet}. + */ DistributionSet getInstalledDistributionSet(); /** @@ -41,6 +62,10 @@ public interface TargetInfo extends Serializable { */ PollStatus getPollStatus(); + /** + * @return true if the {@link Target} has not jet provided + * {@link #getControllerAttributes()}. + */ boolean isRequestControllerAttributes(); } \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetTag.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetTag.java index 3abe3cdd5..585bf8c12 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetTag.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetTag.java @@ -10,8 +10,15 @@ package org.eclipse.hawkbit.repository.model; import java.util.List; +/** + * Target tag element. + * + */ public interface TargetTag extends Tag { + /** + * @return {@link List} of targets assigned to this {@link Tag}. + */ List getAssignedToTargets(); } \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetWithActionType.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetWithActionType.java similarity index 88% rename from hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetWithActionType.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetWithActionType.java index 579b4ef0d..c05f1ec3f 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetWithActionType.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetWithActionType.java @@ -6,11 +6,9 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.model; -import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.ActionType; -import org.eclipse.hawkbit.repository.model.Target; /** * A custom view on {@link Target} with {@link ActionType}. @@ -53,7 +51,7 @@ public class TargetWithActionType { if (actionType == ActionType.TIMEFORCED) { return forceTime; } - return Action.NO_FORCE_TIME; + return Constants.NO_FORCE_TIME; } /** diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TenantConfiguration.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TenantConfiguration.java index 78201410b..fa9962eec 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TenantConfiguration.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TenantConfiguration.java @@ -8,14 +8,33 @@ */ package org.eclipse.hawkbit.repository.model; +/** + * Unstructured tenant configuration elements. Can be used to store arbitrary + * tenant configuration elements. + * + */ public interface TenantConfiguration extends TenantAwareBaseEntity { + /** + * @return key of the entry + */ String getKey(); + /** + * @param key + * of the entry + */ void setKey(String key); + /** + * @return value of the entry + */ String getValue(); + /** + * @param value + * of the entry + */ void setValue(String value); } \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java index 9f692e5f6..653d02870 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java @@ -20,6 +20,7 @@ import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.Root; import javax.validation.constraints.NotNull; +import org.eclipse.hawkbit.repository.Constants; import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; @@ -214,17 +215,13 @@ public class JpaControllerManagement implements ControllerManagement { break; case CANCELED: case FINISHED: - // in case of successful cancellation we also report the success at - // the canceled action itself. - actionStatus.addMessage( - ControllerManagement.SERVER_MESSAGE_PREFIX + "Cancellation completion is finished sucessfully."); - DeploymentHelper.successCancellation(action, actionRepository, targetManagement, targetInfoRepository, - entityManager); + handleFinishedCancelation(actionStatus, action); break; case RETRIEVED: - actionStatus.addMessage(ControllerManagement.SERVER_MESSAGE_PREFIX + "Cancellation request retrieved."); + actionStatus.addMessage(Constants.SERVER_MESSAGE_PREFIX + "Cancellation request retrieved."); break; default: + // do nothing } actionRepository.save(action); actionStatusRepository.save((JpaActionStatus) actionStatus); @@ -232,6 +229,14 @@ public class JpaControllerManagement implements ControllerManagement { return action; } + private void handleFinishedCancelation(final ActionStatus actionStatus, final JpaAction action) { + // in case of successful cancellation we also report the success at + // the canceled action itself. + actionStatus.addMessage(Constants.SERVER_MESSAGE_PREFIX + "Cancellation completion is finished sucessfully."); + DeploymentHelper.successCancellation(action, actionRepository, targetManagement, targetInfoRepository, + entityManager); + } + @Override @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java index 8463f2d37..aa843d8fc 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java @@ -33,7 +33,6 @@ import org.eclipse.hawkbit.repository.ActionFields; import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.DistributionSetAssignmentResult; import org.eclipse.hawkbit.repository.TargetManagement; -import org.eclipse.hawkbit.repository.TargetWithActionType; import org.eclipse.hawkbit.repository.eventbus.event.TargetAssignDistributionSetEvent; import org.eclipse.hawkbit.repository.eventbus.event.TargetInfoUpdateEvent; import org.eclipse.hawkbit.repository.exception.CancelActionNotAllowedException; @@ -69,6 +68,7 @@ import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; +import org.eclipse.hawkbit.repository.model.TargetWithActionType; import org.eclipse.hawkbit.security.SystemSecurityContext; import org.hibernate.validator.constraints.NotEmpty; import org.slf4j.Logger; @@ -146,7 +146,7 @@ public class JpaDeploymentManagement implements DeploymentManagement { return assignDistributionSetByTargetId((JpaDistributionSet) pset, targets.stream().map(target -> target.getControllerId()).collect(Collectors.toList()), - ActionType.FORCED, Action.NO_FORCE_TIME); + ActionType.FORCED, org.eclipse.hawkbit.repository.model.Constants.NO_FORCE_TIME); } @@ -155,7 +155,7 @@ public class JpaDeploymentManagement implements DeploymentManagement { @Transactional(isolation = Isolation.READ_COMMITTED) @CacheEvict(value = { "distributionUsageAssigned" }, allEntries = true) public DistributionSetAssignmentResult assignDistributionSet(final Long dsID, final String... targetIDs) { - return assignDistributionSet(dsID, ActionType.FORCED, Action.NO_FORCE_TIME, targetIDs); + return assignDistributionSet(dsID, ActionType.FORCED, org.eclipse.hawkbit.repository.model.Constants.NO_FORCE_TIME, targetIDs); } @Override diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java index 52c140109..426733bcc 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java @@ -23,8 +23,6 @@ import java.util.stream.Collectors; import javax.persistence.EntityManager; import org.eclipse.hawkbit.repository.DistributionSetFields; -import org.eclipse.hawkbit.repository.DistributionSetFilter; -import org.eclipse.hawkbit.repository.DistributionSetFilter.DistributionSetFilterBuilder; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.DistributionSetMetadataFields; import org.eclipse.hawkbit.repository.DistributionSetTypeFields; @@ -49,6 +47,8 @@ import org.eclipse.hawkbit.repository.jpa.specifications.DistributionSetTypeSpec import org.eclipse.hawkbit.repository.jpa.specifications.SpecificationsBuilder; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.DistributionSetFilter; +import org.eclipse.hawkbit.repository.model.DistributionSetFilter.DistributionSetFilterBuilder; import org.eclipse.hawkbit.repository.model.DistributionSetMetadata; import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult; @@ -497,7 +497,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { } metadata.forEach(m -> entityManager.merge((JpaDistributionSet) m.getDistributionSet()).setLastModifiedAt(0L)); - return new ArrayList( + return new ArrayList<>( (Collection) distributionSetMetadataRepository.save(metadata)); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java index f4523330d..b3e451932 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java @@ -23,7 +23,6 @@ import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.RolloutFields; import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.TargetManagement; -import org.eclipse.hawkbit.repository.TargetWithActionType; import org.eclipse.hawkbit.repository.exception.RolloutIllegalStateException; import org.eclipse.hawkbit.repository.jpa.cache.CacheWriteNotify; import org.eclipse.hawkbit.repository.jpa.model.JpaRollout; @@ -44,6 +43,7 @@ import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupStatus; import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupSuccessCondition; import org.eclipse.hawkbit.repository.model.RolloutGroupConditions; import org.eclipse.hawkbit.repository.model.Target; +import org.eclipse.hawkbit.repository.model.TargetWithActionType; import org.eclipse.hawkbit.repository.model.TotalTargetCountActionStatus; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; import org.slf4j.Logger; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/cache/CacheField.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/cache/CacheField.java index 04627f920..b4e322c77 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/cache/CacheField.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/cache/CacheField.java @@ -14,7 +14,7 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Retention; import java.lang.annotation.Target; -import org.eclipse.hawkbit.repository.jpa.eventbus.CacheFieldEntityListener; +import org.eclipse.hawkbit.repository.jpa.model.CacheFieldEntityListener; import org.springframework.cache.CacheManager; import org.springframework.data.annotation.Transient; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/cache/CacheKeys.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/cache/CacheKeys.java index 9ba7cc763..fdfe7a263 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/cache/CacheKeys.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/cache/CacheKeys.java @@ -8,7 +8,7 @@ */ package org.eclipse.hawkbit.repository.jpa.cache; -import org.eclipse.hawkbit.repository.jpa.eventbus.CacheFieldEntityListener; +import org.eclipse.hawkbit.repository.jpa.model.CacheFieldEntityListener; /** * Constants for cache keys used in multiple classes. diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/eventbus/EventMerger.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/eventbus/EventMerger.java index 702555be8..6a4302c5b 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/eventbus/EventMerger.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/eventbus/EventMerger.java @@ -36,10 +36,8 @@ import com.google.common.eventbus.Subscribe; * interested in all fine grained events, e.g. UI code. The UI code is not * interested in handling the flood of events, so collecting the events and * merge them to one event together and post them in a fixed interval is easier - * to consume e.g. for push notifcations on UI. + * to consume e.g. for push notifications on UI. * - * @author Michael Hirsch - * */ @EventSubscriber public class EventMerger { diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaArtifact.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaArtifact.java index 7a5bea6b7..6ead1df9e 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaArtifact.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaArtifact.java @@ -19,6 +19,9 @@ import org.eclipse.hawkbit.repository.model.SoftwareModule; * {@link SoftwareModule}. */ @MappedSuperclass +// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for +// sub entities +@SuppressWarnings("squid:S2160") public abstract class AbstractJpaArtifact extends AbstractJpaTenantAwareBaseEntity implements Artifact { private static final long serialVersionUID = 1L; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaBaseEntity.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaBaseEntity.java index c99993158..257828c6f 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaBaseEntity.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaBaseEntity.java @@ -18,8 +18,6 @@ import javax.persistence.Id; import javax.persistence.MappedSuperclass; import javax.persistence.Version; -import org.eclipse.hawkbit.repository.jpa.eventbus.CacheFieldEntityListener; -import org.eclipse.hawkbit.repository.jpa.eventbus.EntityPropertyChangeListener; import org.eclipse.hawkbit.repository.model.BaseEntity; import org.springframework.data.annotation.CreatedBy; import org.springframework.data.annotation.CreatedDate; @@ -156,8 +154,7 @@ public abstract class AbstractJpaBaseEntity implements BaseEntity { * @see java.lang.Object#equals(java.lang.Object) */ @Override - public boolean equals(final Object obj) { // NOSONAR - as this is generated - // code + public boolean equals(final Object obj) { if (this == obj) { return true; } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaNamedEntity.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaNamedEntity.java index 196e636d9..ebf5eac3c 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaNamedEntity.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaNamedEntity.java @@ -19,6 +19,9 @@ import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity; * addition to their technical ID. */ @MappedSuperclass +// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for +// sub entities +@SuppressWarnings("squid:S2160") public abstract class AbstractJpaNamedEntity extends AbstractJpaTenantAwareBaseEntity implements NamedEntity { private static final long serialVersionUID = 1L; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaNamedVersionedEntity.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaNamedVersionedEntity.java index 785666b67..ffdb1dfa6 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaNamedVersionedEntity.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaNamedVersionedEntity.java @@ -19,6 +19,9 @@ import org.eclipse.hawkbit.repository.model.NamedVersionedEntity; * */ @MappedSuperclass +// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for +// sub entities +@SuppressWarnings("squid:S2160") public abstract class AbstractJpaNamedVersionedEntity extends AbstractJpaNamedEntity implements NamedVersionedEntity { private static final long serialVersionUID = 1L; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaTag.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaTag.java index 653b678bc..b2e8163da 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaTag.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaTag.java @@ -19,6 +19,9 @@ import org.eclipse.hawkbit.repository.model.Tag; * */ @MappedSuperclass +// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for +// sub entities +@SuppressWarnings("squid:S2160") public abstract class AbstractJpaTag extends AbstractJpaNamedEntity implements Tag { private static final long serialVersionUID = 1L; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/eventbus/CacheFieldEntityListener.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/CacheFieldEntityListener.java similarity index 99% rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/eventbus/CacheFieldEntityListener.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/CacheFieldEntityListener.java index 3c0a46b14..dddc01d91 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/eventbus/CacheFieldEntityListener.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/CacheFieldEntityListener.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.jpa.eventbus; +package org.eclipse.hawkbit.repository.jpa.model; import java.io.Serializable; import java.lang.reflect.Field; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/eventbus/EntityPropertyChangeListener.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/EntityPropertyChangeListener.java similarity index 98% rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/eventbus/EntityPropertyChangeListener.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/EntityPropertyChangeListener.java index df9d600c1..cc0041646 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/eventbus/EntityPropertyChangeListener.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/EntityPropertyChangeListener.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.jpa.eventbus; +package org.eclipse.hawkbit.repository.jpa.model; import java.util.Map; import java.util.stream.Collectors; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaAction.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaAction.java index e0cde5416..2b8744618 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaAction.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaAction.java @@ -49,6 +49,9 @@ import org.eclipse.persistence.annotations.CascadeOnDelete; @NamedEntityGraph(name = "Action.all", attributeNodes = { @NamedAttributeNode("distributionSet"), @NamedAttributeNode(value = "target", subgraph = "target.ds") }, subgraphs = @NamedSubgraph(name = "target.ds", attributeNodes = @NamedAttributeNode("assignedDistributionSet"))) }) @Entity +// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for +// sub entities +@SuppressWarnings("squid:S2160") public class JpaAction extends AbstractJpaTenantAwareBaseEntity implements Action { private static final long serialVersionUID = 1L; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaActionStatus.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaActionStatus.java index cf146651d..ef1ad3d1e 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaActionStatus.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaActionStatus.java @@ -40,6 +40,9 @@ import com.google.common.base.Splitter; @Index(name = "sp_idx_action_status_prim", columnList = "tenant,id") }) @NamedEntityGraph(name = "ActionStatus.withMessages", attributeNodes = { @NamedAttributeNode("messages") }) @Entity +// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for +// sub entities +@SuppressWarnings("squid:S2160") public class JpaActionStatus extends AbstractJpaTenantAwareBaseEntity implements ActionStatus { private static final long serialVersionUID = 1L; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSet.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSet.java index d01cf3f4c..676215424 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSet.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSet.java @@ -37,7 +37,6 @@ import org.eclipse.hawkbit.repository.exception.DistributionSetTypeUndefinedExce import org.eclipse.hawkbit.repository.exception.UnsupportedSoftwareModuleForThisDistributionSetException; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.DistributionSet; -import org.eclipse.hawkbit.repository.model.DistributionSetIdName; import org.eclipse.hawkbit.repository.model.DistributionSetMetadata; import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.DistributionSetType; @@ -59,6 +58,9 @@ import org.eclipse.persistence.annotations.CascadeOnDelete; @Index(name = "sp_idx_distribution_set_prim", columnList = "tenant,id") }) @NamedEntityGraph(name = "DistributionSet.detail", attributeNodes = { @NamedAttributeNode("modules"), @NamedAttributeNode("tags"), @NamedAttributeNode("type") }) +// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for +// sub entities +@SuppressWarnings("squid:S2160") public class JpaDistributionSet extends AbstractJpaNamedVersionedEntity implements DistributionSet { private static final long serialVersionUID = 1L; @@ -198,11 +200,6 @@ public class JpaDistributionSet extends AbstractJpaNamedVersionedEntity implemen return Collections.unmodifiableSet(modules); } - @Override - public DistributionSetIdName getDistributionSetIdName() { - return new DistributionSetIdName(getId(), getName(), getVersion()); - } - @Override public boolean addModule(final SoftwareModule softwareModule) { diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetType.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetType.java index fa5d57642..54aed44dd 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetType.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetType.java @@ -38,6 +38,9 @@ import org.eclipse.hawkbit.repository.model.SoftwareModuleType; @Index(name = "sp_idx_distribution_set_type_prim", columnList = "tenant,id") }, uniqueConstraints = { @UniqueConstraint(columnNames = { "name", "tenant" }, name = "uk_dst_name"), @UniqueConstraint(columnNames = { "type_key", "tenant" }, name = "uk_dst_key") }) +// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for +// sub entities +@SuppressWarnings("squid:S2160") public class JpaDistributionSetType extends AbstractJpaNamedEntity implements DistributionSetType { private static final long serialVersionUID = 1L; @@ -112,45 +115,6 @@ public class JpaDistributionSetType extends AbstractJpaNamedEntity implements Di .collect(Collectors.toSet()); } - @Override - public boolean containsModuleType(final SoftwareModuleType softwareModuleType) { - for (final DistributionSetTypeElement distributionSetTypeElement : elements) { - if (distributionSetTypeElement.getSmType().equals(softwareModuleType)) { - return true; - } - - } - return false; - } - - @Override - public boolean containsMandatoryModuleType(final SoftwareModuleType softwareModuleType) { - return elements.stream().filter(element -> element.isMandatory()) - .filter(element -> element.getSmType().equals(softwareModuleType)).findFirst().isPresent(); - - } - - @Override - public boolean containsMandatoryModuleType(final Long softwareModuleTypeId) { - return elements.stream().filter(element -> element.isMandatory()) - .filter(element -> element.getSmType().getId().equals(softwareModuleTypeId)).findFirst().isPresent(); - - } - - @Override - public boolean containsOptionalModuleType(final SoftwareModuleType softwareModuleType) { - return elements.stream().filter(element -> !element.isMandatory()) - .filter(element -> element.getSmType().equals(softwareModuleType)).findFirst().isPresent(); - - } - - @Override - public boolean containsOptionalModuleType(final Long softwareModuleTypeId) { - return elements.stream().filter(element -> !element.isMandatory()) - .filter(element -> element.getSmType().getId().equals(softwareModuleTypeId)).findFirst().isPresent(); - - } - @Override public boolean areModuleEntriesIdentical(final DistributionSetType dsType) { return new HashSet(((JpaDistributionSetType) dsType).elements).equals(elements); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaExternalArtifact.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaExternalArtifact.java index 91f3df598..b8408cdcc 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaExternalArtifact.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaExternalArtifact.java @@ -33,6 +33,9 @@ import org.eclipse.hawkbit.repository.model.SoftwareModule; @Table(name = "sp_external_artifact", indexes = { @Index(name = "sp_idx_external_artifact_prim", columnList = "id,tenant") }) @Entity +// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for +// sub entities +@SuppressWarnings("squid:S2160") public class JpaExternalArtifact extends AbstractJpaArtifact implements ExternalArtifact { private static final long serialVersionUID = 1L; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaExternalArtifactProvider.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaExternalArtifactProvider.java index 06e572d57..7a4e2a067 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaExternalArtifactProvider.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaExternalArtifactProvider.java @@ -23,6 +23,9 @@ import org.eclipse.hawkbit.repository.model.ExternalArtifactProvider; @Table(name = "sp_external_provider", indexes = { @Index(name = "sp_idx_external_provider_prim", columnList = "tenant,id") }) @Entity +// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for +// sub entities +@SuppressWarnings("squid:S2160") public class JpaExternalArtifactProvider extends AbstractJpaNamedEntity implements ExternalArtifactProvider { private static final long serialVersionUID = 1L; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaLocalArtifact.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaLocalArtifact.java index 4348a3a7d..52cc01b20 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaLocalArtifact.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaLocalArtifact.java @@ -32,6 +32,9 @@ import com.mongodb.gridfs.GridFSFile; @Table(name = "sp_artifact", indexes = { @Index(name = "sp_idx_artifact_01", columnList = "tenant,software_module"), @Index(name = "sp_idx_artifact_prim", columnList = "tenant,id") }) @Entity +// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for +// sub entities +@SuppressWarnings("squid:S2160") public class JpaLocalArtifact extends AbstractJpaArtifact implements LocalArtifact { private static final long serialVersionUID = 1L; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRollout.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRollout.java index ae68fec03..3cbe65717 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRollout.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRollout.java @@ -41,6 +41,9 @@ import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; @Table(name = "sp_rollout", indexes = { @Index(name = "sp_idx_rollout_01", columnList = "tenant,name") }, uniqueConstraints = @UniqueConstraint(columnNames = { "name", "tenant" }, name = "uk_rollout")) +// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for +// sub entities +@SuppressWarnings("squid:S2160") public class JpaRollout extends AbstractJpaNamedEntity implements Rollout { private static final long serialVersionUID = 1L; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRolloutGroup.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRolloutGroup.java index 6be29bb9c..79da6630a 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRolloutGroup.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRolloutGroup.java @@ -37,6 +37,9 @@ import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; @Table(name = "sp_rolloutgroup", indexes = { @Index(name = "sp_idx_rolloutgroup_01", columnList = "tenant,name") }, uniqueConstraints = @UniqueConstraint(columnNames = { "name", "rollout", "tenant" }, name = "uk_rolloutgroup")) +// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for +// sub entities +@SuppressWarnings("squid:S2160") public class JpaRolloutGroup extends AbstractJpaNamedEntity implements RolloutGroup { private static final long serialVersionUID = 1L; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModule.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModule.java index 6465e135a..80156edb8 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModule.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModule.java @@ -50,6 +50,9 @@ import org.eclipse.persistence.annotations.CascadeOnDelete; @Index(name = "sp_idx_base_sw_module_02", columnList = "tenant,deleted,module_type"), @Index(name = "sp_idx_base_sw_module_prim", columnList = "tenant,id") }) @NamedEntityGraph(name = "SoftwareModule.artifacts", attributeNodes = { @NamedAttributeNode("artifacts") }) +// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for +// sub entities +@SuppressWarnings("squid:S2160") public class JpaSoftwareModule extends AbstractJpaNamedVersionedEntity implements SoftwareModule { private static final long serialVersionUID = 1L; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModuleType.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModuleType.java index bb99eba3e..f2a716c40 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModuleType.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModuleType.java @@ -26,6 +26,9 @@ import org.eclipse.hawkbit.repository.model.SoftwareModuleType; @Index(name = "sp_idx_software_module_type_prim", columnList = "tenant,id") }, uniqueConstraints = { @UniqueConstraint(columnNames = { "type_key", "tenant" }, name = "uk_smt_type_key"), @UniqueConstraint(columnNames = { "name", "tenant" }, name = "uk_smt_name") }) +// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for +// sub entities +@SuppressWarnings("squid:S2160") public class JpaSoftwareModuleType extends AbstractJpaNamedEntity implements SoftwareModuleType { private static final long serialVersionUID = 1L; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTarget.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTarget.java index 05c8bc229..94f50ff0d 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTarget.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTarget.java @@ -61,6 +61,9 @@ import org.springframework.data.domain.Persistable; "controller_id", "tenant" }, name = "uk_tenant_controller_id")) @NamedEntityGraph(name = "Target.detail", attributeNodes = { @NamedAttributeNode("tags"), @NamedAttributeNode(value = "assignedDistributionSet"), @NamedAttributeNode(value = "targetInfo") }) +// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for +// sub entities +@SuppressWarnings("squid:S2160") public class JpaTarget extends AbstractJpaNamedEntity implements Persistable, Target { private static final long serialVersionUID = 1L; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetFilterQuery.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetFilterQuery.java index 5ebb8e2bf..38275c71a 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetFilterQuery.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTargetFilterQuery.java @@ -24,6 +24,9 @@ import org.eclipse.hawkbit.repository.model.TargetFilterQuery; @Table(name = "sp_target_filter_query", indexes = { @Index(name = "sp_idx_target_filter_query_01", columnList = "tenant,name") }, uniqueConstraints = @UniqueConstraint(columnNames = { "name", "tenant" }, name = "uk_tenant_custom_filter_name")) +// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for +// sub entities +@SuppressWarnings("squid:S2160") public class JpaTargetFilterQuery extends AbstractJpaTenantAwareBaseEntity implements TargetFilterQuery { private static final long serialVersionUID = 7493966984413479089L; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTenantConfiguration.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTenantConfiguration.java index 2b28aa55f..d6f9a7a97 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTenantConfiguration.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTenantConfiguration.java @@ -23,6 +23,9 @@ import org.eclipse.hawkbit.repository.model.TenantConfiguration; @Entity @Table(name = "sp_tenant_configuration", uniqueConstraints = @UniqueConstraint(columnNames = { "conf_key", "tenant" }, name = "uk_tenant_key")) +// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for +// sub entities +@SuppressWarnings("squid:S2160") public class JpaTenantConfiguration extends AbstractJpaTenantAwareBaseEntity implements TenantConfiguration { private static final long serialVersionUID = 1L; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTenantMetaData.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTenantMetaData.java index 32b6b1082..9363a4db8 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTenantMetaData.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTenantMetaData.java @@ -36,6 +36,9 @@ import org.eclipse.hawkbit.repository.model.TenantMetaData; @Index(name = "sp_idx_tenant_prim", columnList = "tenant,id") }, uniqueConstraints = { @UniqueConstraint(columnNames = { "tenant" }, name = "uk_tenantmd_tenant") }) @Entity +// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for +// sub entities +@SuppressWarnings("squid:S2160") public class JpaTenantMetaData extends AbstractJpaBaseEntity implements TenantMetaData { private static final long serialVersionUID = 1L; @@ -84,24 +87,4 @@ public class JpaTenantMetaData extends AbstractJpaBaseEntity implements TenantMe public void setTenant(final String tenant) { this.tenant = tenant; } - - @Override - public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = prime * result + this.getClass().getName().hashCode(); - return result; - } - - @Override - public boolean equals(final Object obj) { - if (!super.equals(obj)) { - return false; - } - if (!(obj instanceof TenantMetaData)) { - return false; - } - - return true; - } } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/AfterTransactionCommitExecutorHolder.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/AfterTransactionCommitExecutorHolder.java index a1a4416c3..a0e918585 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/AfterTransactionCommitExecutorHolder.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/AfterTransactionCommitExecutorHolder.java @@ -8,8 +8,8 @@ */ package org.eclipse.hawkbit.repository.jpa.model.helper; -import org.eclipse.hawkbit.repository.jpa.eventbus.EntityPropertyChangeListener; import org.eclipse.hawkbit.repository.jpa.executor.AfterTransactionCommitExecutor; +import org.eclipse.hawkbit.repository.jpa.model.EntityPropertyChangeListener; import org.springframework.beans.factory.annotation.Autowired; /** diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/CacheManagerHolder.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/CacheManagerHolder.java index cdc834f08..64417c7d6 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/CacheManagerHolder.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/CacheManagerHolder.java @@ -8,7 +8,7 @@ */ package org.eclipse.hawkbit.repository.jpa.model.helper; -import org.eclipse.hawkbit.repository.jpa.eventbus.CacheFieldEntityListener; +import org.eclipse.hawkbit.repository.jpa.model.CacheFieldEntityListener; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.CacheManager; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/EventBusHolder.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/EventBusHolder.java index 0bf29cbdb..5196283d1 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/EventBusHolder.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/EventBusHolder.java @@ -8,7 +8,7 @@ */ package org.eclipse.hawkbit.repository.jpa.model.helper; -import org.eclipse.hawkbit.repository.jpa.eventbus.CacheFieldEntityListener; +import org.eclipse.hawkbit.repository.jpa.model.CacheFieldEntityListener; import org.springframework.beans.factory.annotation.Autowired; import com.google.common.eventbus.EventBus; diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutScheduler.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rollout/RolloutScheduler.java similarity index 93% rename from hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutScheduler.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rollout/RolloutScheduler.java index bc8f25feb..7335c1cb6 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutScheduler.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rollout/RolloutScheduler.java @@ -6,10 +6,13 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.jpa.rollout; import java.util.List; +import org.eclipse.hawkbit.repository.RolloutManagement; +import org.eclipse.hawkbit.repository.RolloutProperties; +import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.security.SystemSecurityContext; import org.eclipse.hawkbit.tenancy.TenantAware; import org.slf4j.Logger; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DeploymentManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DeploymentManagementTest.java index 0016d4d7d..0900973d0 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DeploymentManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DeploymentManagementTest.java @@ -857,8 +857,9 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { final DistributionSet ds = TestDataUtil.generateDistributionSet("a", softwareManagement, distributionSetManagement); // assign ds to create an action - final DistributionSetAssignmentResult assignDistributionSet = deploymentManagement - .assignDistributionSet(ds.getId(), ActionType.SOFT, Action.NO_FORCE_TIME, target.getControllerId()); + final DistributionSetAssignmentResult assignDistributionSet = deploymentManagement.assignDistributionSet( + ds.getId(), ActionType.SOFT, org.eclipse.hawkbit.repository.model.Constants.NO_FORCE_TIME, + target.getControllerId()); final Action action = deploymentManagement.findActionWithDetails(assignDistributionSet.getActions().get(0)); // verify preparation Action findAction = deploymentManagement.findAction(action.getId()); @@ -880,8 +881,9 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { final DistributionSet ds = TestDataUtil.generateDistributionSet("a", softwareManagement, distributionSetManagement); // assign ds to create an action - final DistributionSetAssignmentResult assignDistributionSet = deploymentManagement - .assignDistributionSet(ds.getId(), ActionType.FORCED, Action.NO_FORCE_TIME, target.getControllerId()); + final DistributionSetAssignmentResult assignDistributionSet = deploymentManagement.assignDistributionSet( + ds.getId(), ActionType.FORCED, org.eclipse.hawkbit.repository.model.Constants.NO_FORCE_TIME, + target.getControllerId()); final Action action = deploymentManagement.findActionWithDetails(assignDistributionSet.getActions().get(0)); // verify perparation Action findAction = deploymentManagement.findAction(action.getId()); @@ -1060,8 +1062,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { public List getEvents(final long timeout, final TimeUnit unit) throws InterruptedException { latch.await(timeout, unit); - final List handledEvents = new LinkedList( - events); + final List handledEvents = new LinkedList<>(events); assertThat(handledEvents).as("Did not receive the expected amount of events (" + expectedNumberOfEvents + ") within timeout. Received events are " + handledEvents).hasSize(expectedNumberOfEvents); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DistributionSetManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DistributionSetManagementTest.java index a29a76086..f102ac86c 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DistributionSetManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DistributionSetManagementTest.java @@ -16,7 +16,6 @@ import java.util.Collection; import java.util.Iterator; import java.util.List; -import org.eclipse.hawkbit.repository.DistributionSetFilter.DistributionSetFilterBuilder; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.exception.DistributionSetTypeUndefinedException; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; @@ -32,6 +31,7 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; +import org.eclipse.hawkbit.repository.model.DistributionSetFilter.DistributionSetFilterBuilder; import org.eclipse.hawkbit.repository.model.ActionStatus; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetMetadata; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TagManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TagManagementTest.java index 67c7de049..25437b0ed 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TagManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TagManagementTest.java @@ -18,7 +18,6 @@ import java.util.Collection; import java.util.List; import java.util.stream.Collectors; -import org.eclipse.hawkbit.repository.DistributionSetFilter.DistributionSetFilterBuilder; import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag; @@ -30,6 +29,7 @@ import org.eclipse.hawkbit.repository.model.Tag; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetTag; import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult; +import org.eclipse.hawkbit.repository.model.DistributionSetFilter.DistributionSetFilterBuilder; import org.junit.Before; import org.junit.Test; import org.slf4j.LoggerFactory; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/eventbus/CacheFieldEntityListenerTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/eventbus/CacheFieldEntityListenerTest.java index 9c5415bbb..3479ed232 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/eventbus/CacheFieldEntityListenerTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/eventbus/CacheFieldEntityListenerTest.java @@ -16,6 +16,7 @@ import static org.mockito.Mockito.when; import org.eclipse.hawkbit.repository.jpa.cache.CacheField; import org.eclipse.hawkbit.repository.jpa.cache.CacheKeys; +import org.eclipse.hawkbit.repository.jpa.model.CacheFieldEntityListener; import org.eclipse.hawkbit.repository.jpa.model.helper.CacheManagerHolder; import org.junit.Before; import org.junit.Test; diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetIdName.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/DistributionSetIdName.java similarity index 86% rename from hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetIdName.java rename to hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/DistributionSetIdName.java index f8662567a..c499babcd 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetIdName.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/DistributionSetIdName.java @@ -6,10 +6,12 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.model; +package org.eclipse.hawkbit.ui.common; import java.io.Serializable; +import org.eclipse.hawkbit.repository.model.DistributionSet; + /** * * @@ -21,6 +23,12 @@ public class DistributionSetIdName implements Serializable { private final String name; private final String version; + public static DistributionSetIdName generate(final DistributionSet distributionSet) { + return new DistributionSetIdName(distributionSet.getId(), distributionSet.getName(), + distributionSet.getVersion()); + + } + /** * @param id * the {@link DistributionSet#getId()} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/SoftwareModuleDetailsTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/SoftwareModuleDetailsTable.java index c0ecf9869..6e4c7dddd 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/SoftwareModuleDetailsTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/SoftwareModuleDetailsTable.java @@ -16,6 +16,7 @@ import org.eclipse.hawkbit.repository.exception.EntityLockedException; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; +import org.eclipse.hawkbit.ui.common.DistributionSetIdName; import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; @@ -214,7 +215,7 @@ public class SoftwareModuleDetailsTable extends Table { .getItem(event.getButton().getId()).getItemProperty(SOFT_MODULE).getValue(), alreadyAssignedSwModules); final DistributionSet newDistributionSet = distributionSetManagement.unassignSoftwareModule(distributionSet, unAssignedSw); - manageDistUIState.setLastSelectedEntity(newDistributionSet.getDistributionSetIdName()); + manageDistUIState.setLastSelectedEntity(DistributionSetIdName.generate(newDistributionSet)); eventBus.publish(this, new DistributionTableEvent(BaseEntityEventType.SELECTED_ENTITY, newDistributionSet)); eventBus.publish(this, DistributionsUIEvent.ORDER_BY_DISTRIBUTION); uiNotification.displaySuccess(i18n.get("message.sw.unassigned", unAssignedSw.getName())); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetDetails.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetDetails.java index a1d1ffcfe..3b93d4f93 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetDetails.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetDetails.java @@ -16,11 +16,11 @@ import java.util.Set; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.model.DistributionSet; -import org.eclipse.hawkbit.repository.model.DistributionSetIdName; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleIdName; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent.SoftwareModuleEventType; +import org.eclipse.hawkbit.ui.common.DistributionSetIdName; import org.eclipse.hawkbit.ui.common.detailslayout.AbstractNamedVersionedEntityTableDetailsLayout; import org.eclipse.hawkbit.ui.common.detailslayout.SoftwareModuleDetailsTable; import org.eclipse.hawkbit.ui.common.tagdetails.DistributionTagToken; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java index c1ee96146..e276ca5d2 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java @@ -22,11 +22,11 @@ import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.model.DistributionSet; -import org.eclipse.hawkbit.repository.model.DistributionSetIdName; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleIdName; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent.SoftwareModuleEventType; +import org.eclipse.hawkbit.ui.common.DistributionSetIdName; import org.eclipse.hawkbit.ui.common.table.AbstractNamedVersionTable; import org.eclipse.hawkbit.ui.common.table.AbstractTable; import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; @@ -453,7 +453,7 @@ public class DistributionSetTable extends AbstractNamedVersionTable> saveAssignedList = new HashMap<>(); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/state/ManagementUIState.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/state/ManagementUIState.java index 653075735..e7ecfbfae 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/state/ManagementUIState.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/state/ManagementUIState.java @@ -17,8 +17,8 @@ import java.util.Optional; import java.util.Set; import java.util.concurrent.atomic.AtomicLong; -import org.eclipse.hawkbit.repository.model.DistributionSetIdName; import org.eclipse.hawkbit.repository.model.TargetIdName; +import org.eclipse.hawkbit.ui.common.DistributionSetIdName; import org.eclipse.hawkbit.ui.common.ManagmentEntityState; import org.springframework.beans.factory.annotation.Autowired; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/state/TargetBulkUpload.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/state/TargetBulkUpload.java index d69f91b64..4d658516a 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/state/TargetBulkUpload.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/state/TargetBulkUpload.java @@ -12,7 +12,7 @@ import java.io.Serializable; import java.util.ArrayList; import java.util.List; -import org.eclipse.hawkbit.repository.model.DistributionSetIdName; +import org.eclipse.hawkbit.ui.common.DistributionSetIdName; /** * Hold details for target bulk upload window. diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/state/TargetTableFilters.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/state/TargetTableFilters.java index 6d8297345..289927660 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/state/TargetTableFilters.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/state/TargetTableFilters.java @@ -13,9 +13,9 @@ import java.util.ArrayList; import java.util.List; import java.util.Optional; -import org.eclipse.hawkbit.repository.model.DistributionSetIdName; import org.eclipse.hawkbit.repository.model.TargetFilterQuery; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; +import org.eclipse.hawkbit.ui.common.DistributionSetIdName; import com.vaadin.spring.annotation.SpringComponent; import com.vaadin.spring.annotation.VaadinSessionScope; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java index 9ef0b742c..23a82da0f 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java @@ -29,8 +29,8 @@ import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.model.Action.ActionType; -import org.eclipse.hawkbit.repository.model.DistributionSetIdName; import org.eclipse.hawkbit.repository.model.Target; +import org.eclipse.hawkbit.ui.common.DistributionSetIdName; import org.eclipse.hawkbit.ui.common.tagdetails.AbstractTagToken.TagData; import org.eclipse.hawkbit.ui.management.event.BulkUploadValidationMessageEvent; import org.eclipse.hawkbit.ui.management.event.TargetTableEvent; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBulkUpdateWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBulkUpdateWindowLayout.java index 657cd97af..b6bf5ebcd 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBulkUpdateWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetBulkUpdateWindowLayout.java @@ -17,8 +17,8 @@ import javax.annotation.PreDestroy; import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.TargetManagement; -import org.eclipse.hawkbit.repository.model.DistributionSetIdName; import org.eclipse.hawkbit.ui.UiProperties; +import org.eclipse.hawkbit.ui.common.DistributionSetIdName; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; import org.eclipse.hawkbit.ui.management.dstable.DistributionBeanQuery; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java index 552349f0a..209f80429 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java @@ -24,13 +24,13 @@ import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.eventbus.event.TargetCreatedEvent; import org.eclipse.hawkbit.repository.eventbus.event.TargetInfoUpdateEvent; -import org.eclipse.hawkbit.repository.model.DistributionSetIdName; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetFilterQuery; import org.eclipse.hawkbit.repository.model.TargetIdName; import org.eclipse.hawkbit.repository.model.TargetInfo; import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; +import org.eclipse.hawkbit.ui.common.DistributionSetIdName; import org.eclipse.hawkbit.ui.common.ManagmentEntityState; import org.eclipse.hawkbit.ui.common.UserDetailsFormatter; import org.eclipse.hawkbit.ui.common.table.AbstractTable; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTableHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTableHeader.java index 09c9bf499..6aac4eace 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTableHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTableHeader.java @@ -10,7 +10,7 @@ package org.eclipse.hawkbit.ui.management.targettable; import java.util.Set; -import org.eclipse.hawkbit.repository.model.DistributionSetIdName; +import org.eclipse.hawkbit.ui.common.DistributionSetIdName; import org.eclipse.hawkbit.ui.common.table.AbstractTable; import org.eclipse.hawkbit.ui.common.table.AbstractTableHeader; import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java index c6a2bdc4d..f0329e3fe 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java @@ -15,9 +15,8 @@ import java.util.List; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.TargetManagement; -import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.ActionType; -import org.eclipse.hawkbit.repository.model.DistributionSetIdName; +import org.eclipse.hawkbit.repository.model.Constants; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.Rollout.RolloutStatus; import org.eclipse.hawkbit.repository.model.RolloutGroup; @@ -28,6 +27,7 @@ import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupSuccessCond import org.eclipse.hawkbit.repository.model.RolloutGroupConditionBuilder; import org.eclipse.hawkbit.repository.model.RolloutGroupConditions; import org.eclipse.hawkbit.ui.UiProperties; +import org.eclipse.hawkbit.ui.common.DistributionSetIdName; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; import org.eclipse.hawkbit.ui.filtermanagement.TargetFilterBeanQuery; @@ -461,7 +461,7 @@ public class AddUpdateRolloutWindowLayout extends CustomComponent { return (((ActionTypeOptionGroupLayout.ActionTypeOption) actionTypeOptionGroupLayout.getActionTypeOptionGroup() .getValue()) == ActionTypeOption.AUTO_FORCED) ? actionTypeOptionGroupLayout.getForcedTimeDateField().getValue().getTime() - : Action.NO_FORCE_TIME; + : Constants.NO_FORCE_TIME; } private ActionType getActionType() { @@ -752,7 +752,7 @@ public class AddUpdateRolloutWindowLayout extends CustomComponent { rolloutForEdit = rolloutManagement.findRolloutById(rolloutId); rolloutName.setValue(rolloutForEdit.getName()); description.setValue(rolloutForEdit.getDescription()); - distributionSet.setValue(rolloutForEdit.getDistributionSet().getDistributionSetIdName()); + distributionSet.setValue(DistributionSetIdName.generate(rolloutForEdit.getDistributionSet())); final List rolloutGroups = rolloutForEdit.getRolloutGroups(); setThresoldValues(rolloutGroups); setActionType(rolloutForEdit); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/DistributionBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/DistributionBeanQuery.java index 75d2741af..e98fef512 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/DistributionBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/DistributionBeanQuery.java @@ -14,10 +14,10 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -import org.eclipse.hawkbit.repository.DistributionSetFilter; -import org.eclipse.hawkbit.repository.DistributionSetFilter.DistributionSetFilterBuilder; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.DistributionSetFilter; +import org.eclipse.hawkbit.repository.model.DistributionSetFilter.DistributionSetFilterBuilder; import org.eclipse.hawkbit.ui.common.UserDetailsFormatter; import org.eclipse.hawkbit.ui.components.ProxyDistribution; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; From a4e0fc2457064a053098b0cd2022dcde02d6422a Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Fri, 27 May 2016 16:04:37 +0200 Subject: [PATCH 25/54] Fixed a broken query. Signed-off-by: Kai Zimmermann --- .../ui/components/ProxyDistribution.java | 5 +++++ .../dstable/ManageDistBeanQuery.java | 11 +++++------ .../dstable/DistributionBeanQuery.java | 17 ++++++++--------- .../rollout/rollout/DistributionBeanQuery.java | 1 - 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/ProxyDistribution.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/ProxyDistribution.java index 91c9d7a62..a8e7fe9d1 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/ProxyDistribution.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/ProxyDistribution.java @@ -10,6 +10,7 @@ package org.eclipse.hawkbit.ui.components; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.ui.common.DistributionSetIdName; /** * Proxy for {@link DistributionSet}. @@ -41,6 +42,10 @@ public class ProxyDistribution extends JpaDistributionSet { return nameVersion; } + public DistributionSetIdName getDistributionSetIdName() { + return DistributionSetIdName.generate(this); + } + /** * @param nameVersion * the nameVersion to set diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/ManageDistBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/ManageDistBeanQuery.java index 4fb3efb03..a262f0d20 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/ManageDistBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/ManageDistBeanQuery.java @@ -18,8 +18,8 @@ import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetFilter; -import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.DistributionSetFilter.DistributionSetFilterBuilder; +import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.ui.common.UserDetailsFormatter; import org.eclipse.hawkbit.ui.components.ProxyDistribution; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; @@ -95,8 +95,8 @@ public class ManageDistBeanQuery extends AbstractBeanQuery { distBeans = firstPageDistributionSets; } else if (Strings.isNullOrEmpty(searchText)) { // if no search filters available - distBeans = getDistributionSetManagement() - .findDistributionSetsByDeletedAndOrCompleted(new OffsetBasedPageRequest(startIndex, count, sort), false, null); + distBeans = getDistributionSetManagement().findDistributionSetsByDeletedAndOrCompleted( + new OffsetBasedPageRequest(startIndex, count, sort), false, null); } else { final DistributionSetFilter distributionSetFilter = new DistributionSetFilterBuilder().setIsDeleted(false) .setSearchText(searchText).setSelectDSWithNoTag(Boolean.FALSE).setType(distributionSetType).build(); @@ -113,7 +113,6 @@ public class ManageDistBeanQuery extends AbstractBeanQuery { proxyDistribution.setVersion(distributionSet.getVersion()); proxyDistribution.setCreatedDate(SPDateTimeUtil.getFormattedDate(distributionSet.getCreatedAt())); proxyDistribution.setLastModifiedDate(SPDateTimeUtil.getFormattedDate(distributionSet.getLastModifiedAt())); - proxyDistribution.setDescription(distributionSet.getDescription()); proxyDistribution.setCreatedByUser(UserDetailsFormatter.loadAndFormatCreatedBy(distributionSet)); proxyDistribution.setModifiedByUser(UserDetailsFormatter.loadAndFormatLastModifiedBy(distributionSet)); proxyDistribution.setIsComplete(distributionSet.isComplete()); @@ -132,8 +131,8 @@ public class ManageDistBeanQuery extends AbstractBeanQuery { public int size() { if (Strings.isNullOrEmpty(searchText) && null == distributionSetType) { // if no search filters available - firstPageDistributionSets = getDistributionSetManagement() - .findDistributionSetsByDeletedAndOrCompleted(new PageRequest(0, SPUIDefinitions.PAGE_SIZE, sort), false, null); + firstPageDistributionSets = getDistributionSetManagement().findDistributionSetsByDeletedAndOrCompleted( + new PageRequest(0, SPUIDefinitions.PAGE_SIZE, sort), false, null); } else { final DistributionSetFilter distributionSetFilter = new DistributionSetFilterBuilder().setIsDeleted(false) .setSearchText(searchText).setSelectDSWithNoTag(Boolean.FALSE).setType(distributionSetType).build(); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionBeanQuery.java index 70c560b9e..63ed91250 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionBeanQuery.java @@ -42,11 +42,11 @@ public class DistributionBeanQuery extends AbstractBeanQuery private static final long serialVersionUID = 5862679853949173536L; private Sort sort = new Sort(Direction.ASC, "name", "version"); - private Collection distributionTags = null; - private String searchText = null; - private String pinnedControllerId = null; + private Collection distributionTags; + private String searchText; + private String pinnedControllerId; private transient DistributionSetManagement distributionSetManagement; - private transient Page firstPageDistributionSets = null; + private transient Page firstPageDistributionSets; private Boolean noTagClicked = Boolean.FALSE; /** @@ -110,8 +110,8 @@ public class DistributionBeanQuery extends AbstractBeanQuery pinnedControllerId); } else if (distributionTags.isEmpty() && Strings.isNullOrEmpty(searchText) && !noTagClicked) { // if no search filters available - distBeans = getDistributionSetManagement() - .findDistributionSetsByDeletedAndOrCompleted(new OffsetBasedPageRequest(startIndex, count, sort), false, true); + distBeans = getDistributionSetManagement().findDistributionSetsByDeletedAndOrCompleted( + new OffsetBasedPageRequest(startIndex, count, sort), false, true); } else { final DistributionSetFilter distributionSetFilter = new DistributionSetFilterBuilder().setIsDeleted(false) .setIsComplete(true).setSearchText(searchText).setSelectDSWithNoTag(noTagClicked) @@ -129,7 +129,6 @@ public class DistributionBeanQuery extends AbstractBeanQuery proxyDistribution.setVersion(distributionSet.getVersion()); proxyDistribution.setCreatedDate(SPDateTimeUtil.getFormattedDate(distributionSet.getCreatedAt())); proxyDistribution.setLastModifiedDate(SPDateTimeUtil.getFormattedDate(distributionSet.getLastModifiedAt())); - proxyDistribution.setDescription(distributionSet.getDescription()); proxyDistribution.setCreatedByUser(UserDetailsFormatter.loadAndFormatCreatedBy(distributionSet)); proxyDistribution.setModifiedByUser(UserDetailsFormatter.loadAndFormatLastModifiedBy(distributionSet)); proxyDistribution.setNameVersion( @@ -152,8 +151,8 @@ public class DistributionBeanQuery extends AbstractBeanQuery pinnedControllerId); } else if (distributionTags.isEmpty() && Strings.isNullOrEmpty(searchText) && !noTagClicked) { // if no search filters available - firstPageDistributionSets = getDistributionSetManagement() - .findDistributionSetsByDeletedAndOrCompleted(new PageRequest(0, SPUIDefinitions.PAGE_SIZE, sort), false, true); + firstPageDistributionSets = getDistributionSetManagement().findDistributionSetsByDeletedAndOrCompleted( + new PageRequest(0, SPUIDefinitions.PAGE_SIZE, sort), false, true); } else { final DistributionSetFilter distributionSetFilter = new DistributionSetFilterBuilder().setIsDeleted(false) .setIsComplete(true).setSearchText(searchText).setSelectDSWithNoTag(noTagClicked) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/DistributionBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/DistributionBeanQuery.java index e98fef512..0a8ebd25d 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/DistributionBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/DistributionBeanQuery.java @@ -113,7 +113,6 @@ public class DistributionBeanQuery extends AbstractBeanQuery proxyDistribution.setVersion(distributionSet.getVersion()); proxyDistribution.setCreatedDate(SPDateTimeUtil.getFormattedDate(distributionSet.getCreatedAt())); proxyDistribution.setLastModifiedDate(SPDateTimeUtil.getFormattedDate(distributionSet.getLastModifiedAt())); - proxyDistribution.setDescription(distributionSet.getDescription()); proxyDistribution.setCreatedByUser(UserDetailsFormatter.loadAndFormatCreatedBy(distributionSet)); proxyDistribution.setModifiedByUser(UserDetailsFormatter.loadAndFormatLastModifiedBy(distributionSet)); proxyDistribution.setIsComplete(distributionSet.isComplete()); From 2d90900f3765519324030da287ca79e9e5a1a769 Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Tue, 31 May 2016 08:48:06 +0200 Subject: [PATCH 26/54] fix javadoc Signed-off-by: Michael Hirsch --- .../main/java/org/eclipse/hawkbit/repository/Constants.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/Constants.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/Constants.java index 114997fca..385d59a63 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/Constants.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/Constants.java @@ -9,7 +9,6 @@ package org.eclipse.hawkbit.repository; import org.eclipse.hawkbit.repository.model.ActionStatus; -import org.eclipse.hawkbit.repository.model.Target; /** * Repository constants. @@ -19,8 +18,8 @@ public final class Constants { /** * Prefix that the server puts in front of - * {@link ActionStatus#getMessages()} is the comments was generated by it - * and not be thy {@link Target}. + * {@link ActionStatus#getMessages()} if the message is generated by the + * server. */ public static final String SERVER_MESSAGE_PREFIX = "Update Server: "; From 7a98c584075603f51ec79cba37405dc30263dbb3 Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Tue, 31 May 2016 08:51:49 +0200 Subject: [PATCH 27/54] refactored test data generation. Refactored entity factor methods. Signed-off-by: Kai Zimmermann --- .../java/org/eclipse/hawkbit/app/Start.java | 3 - .../java/org/eclipse/hawkbit/app/Start.java | 3 - .../JpaRepositoryAutoConfiguration.java | 25 + hawkbit-ddi-resource/pom.xml | 6 + .../resource/DdiArtifactStoreController.java | 13 +- .../ddi/rest/resource/DdiRootController.java | 25 +- .../resource/DdiArtifactDownloadTest.java | 53 +- .../rest/resource/DdiCancelActionTest.java | 70 +- .../ddi/rest/resource/DdiConfigDataTest.java | 12 +- .../rest/resource/DdiDeploymentBaseTest.java | 186 ++--- .../rest/resource/DdiRootControllerTest.java | 30 +- hawkbit-dmf-amqp/pom.xml | 6 + .../amqp/AmqpMessageHandlerService.java | 10 +- .../hawkbit/AmqpTestConfiguration.java | 11 + .../AmqpMessageDispatcherServiceTest.java | 13 +- .../amqp/AmqpMessageHandlerServiceTest.java | 7 +- .../PropertyBasedArtifactUrlHandlerTest.java | 9 +- hawkbit-mgmt-resource/pom.xml | 6 + .../resource/MgmtDistributionSetMapper.java | 17 +- .../resource/MgmtDistributionSetResource.java | 13 +- .../MgmtDistributionSetTagResource.java | 6 +- .../MgmtDistributionSetTypeMapper.java | 10 +- .../MgmtDistributionSetTypeResource.java | 9 +- .../mgmt/rest/resource/MgmtRolloutMapper.java | 6 +- .../rest/resource/MgmtRolloutResource.java | 6 +- .../resource/MgmtSoftwareModuleMapper.java | 19 +- .../resource/MgmtSoftwareModuleResource.java | 12 +- .../MgmtSoftwareModuleTypeMapper.java | 10 +- .../MgmtSoftwareModuleTypeResource.java | 6 +- .../mgmt/rest/resource/MgmtTagMapper.java | 10 +- .../mgmt/rest/resource/MgmtTargetMapper.java | 10 +- .../rest/resource/MgmtTargetResource.java | 6 +- .../rest/resource/MgmtTargetTagResource.java | 6 +- .../MgmtDistributionSetResourceTest.java | 147 ++-- .../MgmtDistributionSetTypeResourceTest.java | 84 +- .../resource/MgmtDownloadResourceTest.java | 7 +- .../resource/MgmtRolloutResourceTest.java | 102 +-- .../MgmtSoftwareModuleResourceTest.java | 118 ++- .../MgmtSoftwareModuleTypeResourceTest.java | 87 +-- .../rest/resource/MgmtTargetResourceTest.java | 70 +- ...MRessourceMisingMongoDbConnectionTest.java | 14 +- .../src/test/resources/log4j2.xml | 26 - .../src/test/resources/logback.xml | 35 + .../repository/ArtifactManagement.java | 6 + .../eclipse/hawkbit/repository/Constants.java | 7 + .../repository/ControllerManagement.java | 59 -- .../repository/DeploymentManagement.java | 16 +- .../repository/DistributionSetManagement.java | 23 - .../hawkbit/repository/EntityFactory.java | 333 ++++++++ .../repository/OffsetBasedPageRequest.java | 27 + .../repository/RolloutGroupManagement.java | 7 - .../hawkbit/repository/RolloutManagement.java | 7 - .../repository/SoftwareManagement.java | 46 -- .../hawkbit/repository/SystemManagement.java | 10 +- .../hawkbit/repository/TagManagement.java | 58 -- .../TargetFilterQueryManagement.java | 7 - .../hawkbit/repository/TargetManagement.java | 10 - .../repository/TenantStatsManagement.java | 1 + .../hawkbit-repository-core/pom.xml | 29 + .../model/helper/SystemManagementHolder.java | 0 .../hawkbit-repository-jpa/pom.xml | 37 +- .../src/fbExcludeFilter.xml | 15 - .../eclipse/hawkbit/EnableJpaRepository.java | 33 + .../RepositoryApplicationConfiguration.java | 3 +- .../repository/jpa/JpaArtifactManagement.java | 10 + .../jpa/JpaControllerManagement.java | 31 - .../jpa/JpaDeploymentManagement.java | 25 +- .../jpa/JpaDistributionSetManagement.java | 40 - .../repository/jpa/JpaEntityFactory.java | 201 +++++ .../jpa/JpaRolloutGroupManagement.java | 6 - .../repository/jpa/JpaRolloutManagement.java | 5 - .../repository/jpa/JpaSoftwareManagement.java | 41 - .../repository/jpa/JpaSystemManagement.java | 36 +- .../repository/jpa/JpaTagManagement.java | 38 - .../jpa/JpaTargetFilterQueryManagement.java | 5 - .../repository/jpa/JpaTargetManagement.java | 7 - .../jpa/model/CacheFieldEntityListener.java | 26 +- .../RolloutGroupConditionEvaluator.java | 3 +- .../jpa/AbstractJpaIntegrationTest.java | 104 +++ ...AbstractJpaIntegrationTestWithMongoDB.java | 104 +++ .../jpa/ArtifactManagementNoMongoDbTest.java | 2 +- .../jpa/ArtifactManagementTest.java | 3 +- .../jpa/ControllerManagementTest.java | 8 +- .../jpa/DeploymentManagementTest.java | 121 ++- .../jpa/DistributionSetManagementTest.java | 62 +- .../jpa/JpaTestRepositoryManagement.java | 109 +++ .../repository/jpa/ReportManagementTest.java | 59 +- .../repository/jpa/RolloutManagementTest.java | 43 +- .../jpa/SoftwareManagementTest.java | 7 +- .../repository/jpa/SystemManagementTest.java | 12 +- .../repository/jpa/TagManagementTest.java | 45 +- .../jpa/TargetFilterQueryManagenmentTest.java | 2 +- .../jpa/TargetManagementSearchTest.java | 42 +- .../repository/jpa/TargetManagementTest.java | 60 +- .../TenantConfigurationManagementTest.java | 2 +- .../repository/jpa/TestConfiguration.java | 18 +- .../hawkbit/repository/jpa/TestDataUtil.java | 435 ----------- .../jpa/model/ModelEqualsHashcodeTest.java | 4 +- .../jpa/rsql/RSQLActionFieldsTest.java | 4 +- .../rsql/RSQLDistributionSetFieldTest.java | 27 +- ...RSQLDistributionSetMetadataFieldsTest.java | 8 +- .../jpa/rsql/RSQLRolloutGroupFields.java | 10 +- .../jpa/rsql/RSQLSoftwareModuleFieldTest.java | 4 +- .../RSQLSoftwareModuleMetadataFieldsTest.java | 12 +- .../RSQLSoftwareModuleTypeFieldsTest.java | 8 +- .../jpa/rsql/RSQLTagFieldsTest.java | 4 +- .../jpa/rsql/RSQLTargetFieldTest.java | 22 +- .../jpa/tenancy/MultiTenancyEntityTest.java | 8 +- .../jpa/utils/RepositoryDataGenerator.java | 485 ------------ .../hawkbit-repository-test/pom.xml | 59 ++ .../util}/AbstractIntegrationTest.java | 187 +---- .../AbstractIntegrationTestWithMongoDB.java | 14 +- .../repository/util}/FreePortFileWriter.java | 2 +- .../util/TestRepositoryManagement.java | 22 + .../repository/util/TestdataFactory.java | 737 ++++++++++++++++++ .../util}/WithSpringAuthorityRule.java | 2 +- .../hawkbit/repository/util}/WithUser.java | 2 +- hawkbit-repository/pom.xml | 2 + hawkbit-rest-core/pom.xml | 6 + .../rest/AbstractRestIntegrationTest.java | 5 +- ...bstractRestIntegrationTestWithMongoDB.java | 6 +- .../SoftwareModuleAddUpdateWindow.java | 8 +- .../CreateUpdateSoftwareTypeLayout.java | 8 +- .../common/DistributionSetTypeBeanQuery.java | 11 +- .../common/SoftwareModuleTypeBeanQuery.java | 11 +- .../CreateUpdateDistSetTypeLayout.java | 8 +- .../CreateOrUpdateFilterHeader.java | 6 +- .../DistributionAddUpdateWindowLayout.java | 12 +- ...eateUpdateDistributionTagLayoutWindow.java | 6 +- .../dstag/DistributionTagButtons.java | 10 +- .../targettable/BulkUploadHandler.java | 6 +- .../TargetAddUpdateWindowLayout.java | 6 +- .../CreateUpdateTargetTagLayout.java | 6 +- .../targettag/TargetTagFilterButtons.java | 8 +- .../rollout/AddUpdateRolloutWindowLayout.java | 6 +- .../hawkbit/ui/utils/HawkbitCommonUtil.java | 7 +- pom.xml | 1 - 137 files changed, 2937 insertions(+), 2593 deletions(-) create mode 100644 hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/repository/JpaRepositoryAutoConfiguration.java delete mode 100644 hawkbit-mgmt-resource/src/test/resources/log4j2.xml create mode 100644 hawkbit-mgmt-resource/src/test/resources/logback.xml create mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/EntityFactory.java create mode 100644 hawkbit-repository/hawkbit-repository-core/pom.xml rename hawkbit-repository/{hawkbit-repository-jpa => hawkbit-repository-core}/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/SystemManagementHolder.java (100%) delete mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/fbExcludeFilter.xml create mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/EnableJpaRepository.java create mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaEntityFactory.java create mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTest.java create mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTestWithMongoDB.java create mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/JpaTestRepositoryManagement.java delete mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TestDataUtil.java delete mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/utils/RepositoryDataGenerator.java create mode 100644 hawkbit-repository/hawkbit-repository-test/pom.xml rename hawkbit-repository/{hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa => hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util}/AbstractIntegrationTest.java (51%) rename hawkbit-repository/{hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa => hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util}/AbstractIntegrationTestWithMongoDB.java (89%) rename hawkbit-repository/{hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa => hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util}/FreePortFileWriter.java (97%) create mode 100644 hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/TestRepositoryManagement.java create mode 100644 hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/TestdataFactory.java rename hawkbit-repository/{hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa => hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util}/WithSpringAuthorityRule.java (99%) rename hawkbit-repository/{hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa => hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util}/WithUser.java (97%) diff --git a/examples/hawkbit-custom-theme-example/src/main/java/org/eclipse/hawkbit/app/Start.java b/examples/hawkbit-custom-theme-example/src/main/java/org/eclipse/hawkbit/app/Start.java index abf2740fa..fdad8a999 100644 --- a/examples/hawkbit-custom-theme-example/src/main/java/org/eclipse/hawkbit/app/Start.java +++ b/examples/hawkbit-custom-theme-example/src/main/java/org/eclipse/hawkbit/app/Start.java @@ -8,11 +8,9 @@ package org.eclipse.hawkbit.app; * http://www.eclipse.org/legal/epl-v10.html */ -import org.eclipse.hawkbit.RepositoryApplicationConfiguration; import org.eclipse.hawkbit.autoconfigure.security.EnableHawkbitManagedSecurityConfiguration; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.Import; /** * A {@link SpringBootApplication} annotated class with a main method to start. @@ -20,7 +18,6 @@ import org.springframework.context.annotation.Import; * */ @SpringBootApplication -@Import({ RepositoryApplicationConfiguration.class }) @EnableHawkbitManagedSecurityConfiguration // Exception squid:S1118 - Spring boot standard behavior @SuppressWarnings({ "squid:S1118" }) diff --git a/examples/hawkbit-example-app/src/main/java/org/eclipse/hawkbit/app/Start.java b/examples/hawkbit-example-app/src/main/java/org/eclipse/hawkbit/app/Start.java index 4a3e6028a..d22d6f4a1 100644 --- a/examples/hawkbit-example-app/src/main/java/org/eclipse/hawkbit/app/Start.java +++ b/examples/hawkbit-example-app/src/main/java/org/eclipse/hawkbit/app/Start.java @@ -8,13 +8,11 @@ */ package org.eclipse.hawkbit.app; -import org.eclipse.hawkbit.RepositoryApplicationConfiguration; import org.eclipse.hawkbit.autoconfigure.security.EnableHawkbitManagedSecurityConfiguration; import org.eclipse.hawkbit.ddi.EnableDdiApi; import org.eclipse.hawkbit.mgmt.EnableMgmtApi; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.Import; /** * A {@link SpringBootApplication} annotated class with a main method to start. @@ -22,7 +20,6 @@ import org.springframework.context.annotation.Import; * */ @SpringBootApplication -@Import({ RepositoryApplicationConfiguration.class }) @EnableHawkbitManagedSecurityConfiguration @EnableMgmtApi @EnableDdiApi diff --git a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/repository/JpaRepositoryAutoConfiguration.java b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/repository/JpaRepositoryAutoConfiguration.java new file mode 100644 index 000000000..dd6ead86b --- /dev/null +++ b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/repository/JpaRepositoryAutoConfiguration.java @@ -0,0 +1,25 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.autoconfigure.repository; + +import org.eclipse.hawkbit.EnableJpaRepository; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; + +/** + * Auto-Configuration for enabling the REST-Resources. + * + */ +@Configuration +@ConditionalOnClass({ EnableJpaRepository.class }) +@Import({ EnableJpaRepository.class }) +public class JpaRepositoryAutoConfiguration { + +} diff --git a/hawkbit-ddi-resource/pom.xml b/hawkbit-ddi-resource/pom.xml index 177494912..35aff47f5 100644 --- a/hawkbit-ddi-resource/pom.xml +++ b/hawkbit-ddi-resource/pom.xml @@ -48,6 +48,12 @@ + + org.eclipse.hawkbit + hawkbit-repository-test + ${project.version} + test + org.eclipse.hawkbit hawkbit-rest-core diff --git a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java index 859b4c156..9d690f9d2 100644 --- a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java +++ b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java @@ -19,6 +19,7 @@ import org.eclipse.hawkbit.ddi.dl.rest.api.DdiDlArtifactStoreControllerRestApi; import org.eclipse.hawkbit.repository.ArtifactManagement; import org.eclipse.hawkbit.repository.Constants; import org.eclipse.hawkbit.repository.ControllerManagement; +import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.jpa.cache.CacheWriteNotify; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; @@ -68,6 +69,9 @@ public class DdiArtifactStoreController implements DdiDlArtifactStoreControllerR @Autowired private RequestResponseContextHolder requestResponseContextHolder; + @Autowired + private EntityFactory entityFactory; + @Override public ResponseEntity downloadArtifactByFilename(@PathVariable("fileName") final String fileName, @AuthenticationPrincipal final String targetid) { @@ -139,17 +143,16 @@ public class DdiArtifactStoreController implements DdiDlArtifactStoreControllerR .getActionForDownloadByTargetAndSoftwareModule(target.getControllerId(), artifact.getSoftwareModule()); final String range = request.getHeader("Range"); - final ActionStatus actionStatus = controllerManagement.generateActionStatus(); + final ActionStatus actionStatus = entityFactory.generateActionStatus(); actionStatus.setAction(action); actionStatus.setOccurredAt(System.currentTimeMillis()); actionStatus.setStatus(Status.DOWNLOAD); if (range != null) { - actionStatus.addMessage(Constants.SERVER_MESSAGE_PREFIX + "Target downloads range " + range - + " of: " + request.getRequestURI()); + actionStatus.addMessage(Constants.SERVER_MESSAGE_PREFIX + "Target downloads range " + range + " of: " + + request.getRequestURI()); } else { - actionStatus.addMessage( - Constants.SERVER_MESSAGE_PREFIX + "Target downloads: " + request.getRequestURI()); + actionStatus.addMessage(Constants.SERVER_MESSAGE_PREFIX + "Target downloads: " + request.getRequestURI()); } controllerManagement.addInformationalActionStatus(actionStatus); return action; diff --git a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java index 881eee659..656835e95 100644 --- a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java +++ b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java @@ -31,6 +31,7 @@ import org.eclipse.hawkbit.ddi.rest.api.DdiRootControllerRestApi; import org.eclipse.hawkbit.repository.ArtifactManagement; import org.eclipse.hawkbit.repository.Constants; import org.eclipse.hawkbit.repository.ControllerManagement; +import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.jpa.cache.CacheWriteNotify; @@ -97,6 +98,9 @@ public class DdiRootController implements DdiRootControllerRestApi { @Autowired private RequestResponseContextHolder requestResponseContextHolder; + @Autowired + private EntityFactory entityFactory; + @Override public ResponseEntity> getSoftwareModulesArtifacts( @PathVariable("targetid") final String targetid, @@ -175,17 +179,16 @@ public class DdiRootController implements DdiRootControllerRestApi { .getActionForDownloadByTargetAndSoftwareModule(target.getControllerId(), module); final String range = request.getHeader("Range"); - final ActionStatus statusMessage = controllerManagement.generateActionStatus(); + final ActionStatus statusMessage = entityFactory.generateActionStatus(); statusMessage.setAction(action); statusMessage.setOccurredAt(System.currentTimeMillis()); statusMessage.setStatus(Status.DOWNLOAD); if (range != null) { - statusMessage.addMessage(Constants.SERVER_MESSAGE_PREFIX + "Target downloads range " + range - + " of: " + request.getRequestURI()); + statusMessage.addMessage(Constants.SERVER_MESSAGE_PREFIX + "Target downloads range " + range + " of: " + + request.getRequestURI()); } else { - statusMessage.addMessage( - Constants.SERVER_MESSAGE_PREFIX + "Target downloads " + request.getRequestURI()); + statusMessage.addMessage(Constants.SERVER_MESSAGE_PREFIX + "Target downloads " + request.getRequestURI()); } controllerManagement.addInformationalActionStatus(statusMessage); return action; @@ -294,7 +297,7 @@ public class DdiRootController implements DdiRootControllerRestApi { private ActionStatus generateUpdateStatus(final DdiActionFeedback feedback, final String targetid, final Long actionid, final Action action) { - final ActionStatus actionStatus = controllerManagement.generateActionStatus(); + final ActionStatus actionStatus = entityFactory.generateActionStatus(); actionStatus.setAction(action); actionStatus.setOccurredAt(System.currentTimeMillis()); @@ -336,8 +339,8 @@ public class DdiRootController implements DdiRootControllerRestApi { LOG.debug("Controller reported intermediate status (actionid: {}, targetid: {}) as we got {} report.", actionid, targetid, feedback.getStatus().getExecution()); actionStatus.setStatus(Status.RUNNING); - actionStatus.addMessage( - Constants.SERVER_MESSAGE_PREFIX + "Target reported " + feedback.getStatus().getExecution()); + actionStatus + .addMessage(Constants.SERVER_MESSAGE_PREFIX + "Target reported " + feedback.getStatus().getExecution()); } private static void handleClosedUpdateStatus(final DdiActionFeedback feedback, final String targetid, @@ -420,14 +423,14 @@ public class DdiRootController implements DdiRootControllerRestApi { } controllerManagement.addCancelActionStatus( - generateActionCancelStatus(feedback, target, feedback.getId(), action, controllerManagement)); + generateActionCancelStatus(feedback, target, feedback.getId(), action, entityFactory)); return new ResponseEntity<>(HttpStatus.OK); } private static ActionStatus generateActionCancelStatus(final DdiActionFeedback feedback, final Target target, - final Long actionid, final Action action, final ControllerManagement controllerManagement) { + final Long actionid, final Action action, final EntityFactory entityFactory) { - final ActionStatus actionStatus = controllerManagement.generateActionStatus(); + final ActionStatus actionStatus = entityFactory.generateActionStatus(); actionStatus.setAction(action); actionStatus.setOccurredAt(System.currentTimeMillis()); diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java index 2e56ed840..b3828582c 100644 --- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java +++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java @@ -27,14 +27,13 @@ import java.util.List; import org.apache.commons.lang3.RandomUtils; import org.eclipse.hawkbit.eventbus.event.DownloadProgressEvent; -import org.eclipse.hawkbit.repository.jpa.TestDataUtil; -import org.eclipse.hawkbit.repository.jpa.WithUser; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.Target; +import org.eclipse.hawkbit.repository.util.WithUser; import org.eclipse.hawkbit.rest.AbstractRestIntegrationTestWithMongoDB; import org.junit.Test; import org.slf4j.LoggerFactory; @@ -73,14 +72,13 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong @Description("Tests non allowed requests on the artifact ressource, e.g. invalid URI, wrong if-match, wrong command.") public void invalidRequestsOnArtifactResource() throws Exception { // create target - Target target = targetManagement.generateTarget("4712"); + Target target = entityFactory.generateTarget("4712"); target = targetManagement.createTarget(target); final List targets = new ArrayList<>(); targets.add(target); // create ds - final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); + final DistributionSet ds = testdataFactory.createDistributionSet(""); deploymentManagement.assignDistributionSet(ds, targets); // create artifact @@ -158,14 +156,13 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong @Description("Tests non allowed requests on the artifact ressource, e.g. invalid URI, wrong if-match, wrong command.") public void invalidRequestsOnArtifactResourceByName() throws Exception { // create target - Target target = targetManagement.generateTarget("4712"); + Target target = entityFactory.generateTarget("4712"); target = targetManagement.createTarget(target); final List targets = new ArrayList<>(); targets.add(target); // create ds - final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); + final DistributionSet ds = testdataFactory.createDistributionSet(""); deploymentManagement.assignDistributionSet(ds, targets); // create artifact @@ -241,17 +238,15 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong downLoadProgress = 1; eventBus.register(this); assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0); - assertThat(artifactRepository.findAll()).hasSize(0); // create target - Target target = targetManagement.generateTarget("4712"); + Target target = entityFactory.generateTarget("4712"); target = targetManagement.createTarget(target); final List targets = new ArrayList(); targets.add(target); // create ds - final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); + final DistributionSet ds = testdataFactory.createDistributionSet(""); // create artifact final byte random[] = RandomUtils.nextBytes(5 * 1024 * 1024); @@ -287,12 +282,11 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong @Description("Tests valid MD5SUm file downloads through the artifact resource by identifying the artifact by ID.") public void downloadMd5sumThroughControllerApi() throws Exception { // create target - Target target = targetManagement.generateTarget("4712"); + Target target = entityFactory.generateTarget("4712"); target = targetManagement.createTarget(target); // create ds - final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); + final DistributionSet ds = testdataFactory.createDistributionSet(""); // create artifact final byte random[] = RandomUtils.nextBytes(5 * 1024); @@ -322,17 +316,15 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong eventBus.register(this); assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0); - assertThat(artifactRepository.findAll()).hasSize(0); // create target - Target target = targetManagement.generateTarget("4712"); + Target target = entityFactory.generateTarget("4712"); target = targetManagement.createTarget(target); final List targets = new ArrayList(); targets.add(target); // create ds - final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); + final DistributionSet ds = testdataFactory.createDistributionSet(""); // create artifact final byte random[] = RandomUtils.nextBytes(5 * 1024); @@ -353,17 +345,15 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong eventBus.register(this); assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0); - assertThat(artifactRepository.findAll()).hasSize(0); // create target - Target target = targetManagement.generateTarget("4712"); + Target target = entityFactory.generateTarget("4712"); target = targetManagement.createTarget(target); final List targets = new ArrayList<>(); targets.add(target); // create ds - final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); + final DistributionSet ds = testdataFactory.createDistributionSet(""); // create artifact final byte random[] = RandomUtils.nextBytes(5 * 1024 * 1024); @@ -393,7 +383,6 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong final Action action = deploymentManagement.findActionsByTarget(target).get(0); // one status - download - assertThat(actionStatusRepository.findAll()).hasSize(2); assertThat(action.getActionStatus()).hasSize(2); assertThat(deploymentManagement.findActionStatusByAction(new PageRequest(0, 400, Direction.DESC, "id"), action) .getContent().get(0).getStatus()).isEqualTo(Status.DOWNLOAD); @@ -407,14 +396,13 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong @Description("Test various HTTP range requests for artifact download, e.g. chunk download or download resume.") public void rangeDownloadArtifactByName() throws Exception { // create target - Target target = targetManagement.generateTarget("4712"); + Target target = entityFactory.generateTarget("4712"); target = targetManagement.createTarget(target); final List targets = new ArrayList<>(); targets.add(target); // create ds - final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); + final DistributionSet ds = testdataFactory.createDistributionSet(""); final int resultLength = 5 * 1000 * 1024; @@ -512,17 +500,15 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong @Description("Ensures that the download fails if te controller is not authenticated.") public void faildDownloadArtifactByNameIfAuthenticationMissing() throws Exception { assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0); - assertThat(artifactRepository.findAll()).hasSize(0); // create target - Target target = targetManagement.generateTarget("4712"); + Target target = entityFactory.generateTarget("4712"); target = targetManagement.createTarget(target); final List targets = new ArrayList<>(); targets.add(target); // create ds - final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); + final DistributionSet ds = testdataFactory.createDistributionSet(""); // create artifact final byte random[] = RandomUtils.nextBytes(5 * 1024); @@ -538,12 +524,11 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong @Description("Downloads an MD5SUM file by the related artifacts filename.") public void downloadMd5sumFileByName() throws Exception { // create target - Target target = targetManagement.generateTarget("4712"); + Target target = entityFactory.generateTarget("4712"); target = targetManagement.createTarget(target); // create ds - final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); + final DistributionSet ds = testdataFactory.createDistributionSet(""); // create artifact final byte random[] = RandomUtils.nextBytes(5 * 1024); diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiCancelActionTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiCancelActionTest.java index 8fd832b95..821c8b8ad 100644 --- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiCancelActionTest.java +++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiCancelActionTest.java @@ -22,7 +22,6 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. import java.util.ArrayList; import java.util.List; -import org.eclipse.hawkbit.repository.jpa.TestDataUtil; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.DistributionSet; @@ -49,9 +48,8 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest { @Description("Test of the controller can continue a started update even after a cancel command if it so desires.") public void rootRsCancelActionButContinueAnyway() throws Exception { // prepare test data - final Target target = targetManagement.generateTarget("4712"); - final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); + final Target target = entityFactory.generateTarget("4712"); + final DistributionSet ds = testdataFactory.createDistributionSet(""); final Target savedTarget = targetManagement.createTarget(target); final List toAssign = new ArrayList(); @@ -106,9 +104,8 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest { @Test @Description("Test for cancel operation of a update action.") public void rootRsCancelAction() throws Exception { - final Target target = targetManagement.generateTarget("4712"); - final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); + final Target target = entityFactory.generateTarget("4712"); + final DistributionSet ds = testdataFactory.createDistributionSet(""); final Target savedTarget = targetManagement.createTarget(target); final List toAssign = new ArrayList(); @@ -224,9 +221,8 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest { } private Action createCancelAction(final String targetid) { - final Target target = targetManagement.generateTarget(targetid); - final DistributionSet ds = TestDataUtil.generateDistributionSet(targetid, softwareManagement, - distributionSetManagement); + final Target target = entityFactory.generateTarget(targetid); + final DistributionSet ds = testdataFactory.createDistributionSet(targetid); final Target savedTarget = targetManagement.createTarget(target); final List toAssign = new ArrayList(); toAssign.add(savedTarget); @@ -241,9 +237,8 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest { @Description("Tests the feedback channel of the cancel operation.") public void rootRsCancelActionFeedback() throws Exception { - final Target target = targetManagement.generateTarget("4712"); - final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); + final Target target = entityFactory.generateTarget("4712"); + final DistributionSet ds = testdataFactory.createDistributionSet(""); final Target savedTarget = targetManagement.createTarget(target); @@ -253,7 +248,7 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest { // cancel action manually final Action cancelAction = deploymentManagement.cancelAction(updateAction, targetManagement.findTargetByControllerID(savedTarget.getControllerId())); - assertThat(actionStatusRepository.findAll()).hasSize(2); + assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(2); assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(1); long current = System.currentTimeMillis(); @@ -266,7 +261,7 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest { .isGreaterThanOrEqualTo(current); assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(1); - assertThat(actionStatusRepository.findAll()).hasSize(3); + assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(3); current = System.currentTimeMillis(); mvc.perform(post("/{tenant}/controller/v1/4712/cancelAction/" + cancelAction.getId() + "/feedback", @@ -277,7 +272,7 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest { assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getLastTargetQuery()) .isGreaterThanOrEqualTo(current); assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(1); - assertThat(actionStatusRepository.findAll()).hasSize(4); + assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(4); current = System.currentTimeMillis(); mvc.perform(post("/{tenant}/controller/v1/4712/cancelAction/" + cancelAction.getId() + "/feedback", @@ -287,7 +282,7 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest { .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getLastTargetQuery()) .isGreaterThanOrEqualTo(current); - assertThat(actionStatusRepository.findAll()).hasSize(5); + assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(5); assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(1); // cancelation canceled -> should remove the action from active @@ -300,7 +295,7 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest { .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getLastTargetQuery()) .isGreaterThanOrEqualTo(current); - assertThat(actionStatusRepository.findAll()).hasSize(6); + assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(6); assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(1); // cancelation rejected -> action still active until controller close it @@ -315,7 +310,7 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest { .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getLastTargetQuery()) .isGreaterThanOrEqualTo(current); - assertThat(actionStatusRepository.findAll()).hasSize(7); + assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(7); assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(1); // cancelaction closed -> should remove the action from active @@ -327,20 +322,17 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest { .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getLastTargetQuery()) .isGreaterThanOrEqualTo(current); - assertThat(actionStatusRepository.findAll()).hasSize(8); + assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(8); assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(0); } @Test @Description("Tests the feeback chanel of for multiple open cancel operations on the same target.") public void multipleCancelActionFeedback() throws Exception { - final Target target = targetManagement.generateTarget("4712"); - final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement, true); - final DistributionSet ds2 = TestDataUtil.generateDistributionSet("2", softwareManagement, - distributionSetManagement, true); - final DistributionSet ds3 = TestDataUtil.generateDistributionSet("3", softwareManagement, - distributionSetManagement, true); + final Target target = entityFactory.generateTarget("4712"); + final DistributionSet ds = testdataFactory.createDistributionSet("", true); + final DistributionSet ds2 = testdataFactory.createDistributionSet("2", true); + final DistributionSet ds3 = testdataFactory.createDistributionSet("3", true); final Target savedTarget = targetManagement.createTarget(target); @@ -351,7 +343,7 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest { final Action updateAction3 = deploymentManagement.findActionWithDetails( deploymentManagement.assignDistributionSet(ds3.getId(), new String[] { "4712" }).getActions().get(0)); - assertThat(actionStatusRepository.findAll()).hasSize(3); + assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(3); // 3 update actions, 0 cancel actions assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(3); @@ -370,7 +362,7 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest { .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$id", equalTo(String.valueOf(cancelAction.getId())))) .andExpect(jsonPath("$cancelAction.stopId", equalTo(String.valueOf(updateAction.getId())))); - assertThat(actionStatusRepository.findAll()).hasSize(6); + assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(6); mvc.perform(get("/{tenant}/controller/v1/4712", tenantAware.getCurrentTenant())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) @@ -386,7 +378,7 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest { .content(JsonBuilder.cancelActionFeedback(cancelAction.getId().toString(), "closed")) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); - assertThat(actionStatusRepository.findAll()).hasSize(7); + assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(7); // 1 update actions, 1 cancel actions assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(2); @@ -396,7 +388,7 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest { .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$id", equalTo(String.valueOf(cancelAction2.getId())))) .andExpect(jsonPath("$cancelAction.stopId", equalTo(String.valueOf(updateAction2.getId())))); - assertThat(actionStatusRepository.findAll()).hasSize(8); + assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(8); mvc.perform(get("/{tenant}/controller/v1/4712", tenantAware.getCurrentTenant())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) @@ -412,17 +404,18 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest { .content(JsonBuilder.cancelActionFeedback(cancelAction2.getId().toString(), "closed")) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); - assertThat(actionStatusRepository.findAll()).hasSize(9); + assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(9); assertThat(targetManagement.findTargetByControllerID("4712").getAssignedDistributionSet()).isEqualTo(ds3); mvc.perform(get("/{tenant}/controller/v1/4712/deploymentBase/" + updateAction3.getId(), tenantAware.getCurrentTenant())).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); - assertThat(actionStatusRepository.findAll()).hasSize(10); + assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(10); // 1 update actions, 0 cancel actions assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(1); - final Action cancelAction3 = deploymentManagement.cancelAction(actionRepository.findOne(updateAction3.getId()), + final Action cancelAction3 = deploymentManagement.cancelAction( + deploymentManagement.findAction(updateAction3.getId()), targetManagement.findTargetByControllerID(savedTarget.getControllerId())); // action is in cancelling state @@ -435,7 +428,7 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest { .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$id", equalTo(String.valueOf(cancelAction3.getId())))) .andExpect(jsonPath("$cancelAction.stopId", equalTo(String.valueOf(updateAction3.getId())))); - assertThat(actionStatusRepository.findAll()).hasSize(12); + assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(12); // now lets return feedback for the third cancelation mvc.perform(post("/{tenant}/controller/v1/4712/cancelAction/" + cancelAction3.getId() + "/feedback", @@ -443,7 +436,7 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest { .content(JsonBuilder.cancelActionFeedback(cancelAction3.getId().toString(), "closed")) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); - assertThat(actionStatusRepository.findAll()).hasSize(13); + assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(13); // final status assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(0); @@ -453,9 +446,8 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest { @Test @Description("Tests the feeback channel closing for too many feedbacks, i.e. denial of service prevention.") public void tooMuchCancelActionFeedback() throws Exception { - final Target target = targetManagement.createTarget(targetManagement.generateTarget("4712")); - final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); + final Target target = targetManagement.createTarget(entityFactory.generateTarget("4712")); + final DistributionSet ds = testdataFactory.createDistributionSet(""); final List toAssign = new ArrayList(); toAssign.add(target); diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiConfigDataTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiConfigDataTest.java index a216ce501..395e2284c 100644 --- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiConfigDataTest.java +++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiConfigDataTest.java @@ -21,8 +21,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. import java.util.HashMap; import java.util.Map; -import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest; import org.eclipse.hawkbit.repository.model.Target; +import org.eclipse.hawkbit.rest.AbstractRestIntegrationTest; import org.eclipse.hawkbit.rest.util.JsonBuilder; import org.eclipse.hawkbit.rest.util.MockMvcResultPrinter; import org.junit.Test; @@ -40,13 +40,13 @@ import ru.yandex.qatools.allure.annotations.Stories; @ActiveProfiles({ "im", "test" }) @Features("Component Tests - Direct Device Integration API") @Stories("Config Data Resource") -public class DdiConfigDataTest extends AbstractIntegrationTest { +public class DdiConfigDataTest extends AbstractRestIntegrationTest { @Test @Description("We verify that the config data (i.e. device attributes like serial number, hardware revision etc.) " + "are requested only once from the device.") public void requestConfigDataIfEmpty() throws Exception { - final Target target = targetManagement.generateTarget("4712"); + final Target target = entityFactory.generateTarget("4712"); final Target savedTarget = targetManagement.createTarget(target); final long current = System.currentTimeMillis(); @@ -84,7 +84,7 @@ public class DdiConfigDataTest extends AbstractIntegrationTest { @Description("We verify that the config data (i.e. device attributes like serial number, hardware revision etc.) " + "can be uploaded correctly by the controller.") public void putConfigData() throws Exception { - targetManagement.createTarget(targetManagement.generateTarget("4717")); + targetManagement.createTarget(entityFactory.generateTarget("4717")); // initial final Map attributes = new HashMap<>(); @@ -127,7 +127,7 @@ public class DdiConfigDataTest extends AbstractIntegrationTest { @Description("We verify that the config data (i.e. device attributes like serial number, hardware revision etc.) " + "upload limitation is inplace which is meant to protect the server from malicious attempts.") public void putToMuchConfigData() throws Exception { - targetManagement.createTarget(targetManagement.generateTarget("4717")); + targetManagement.createTarget(entityFactory.generateTarget("4717")); // initial Map attributes = new HashMap<>(); @@ -150,7 +150,7 @@ public class DdiConfigDataTest extends AbstractIntegrationTest { @Description("We verify that the config data (i.e. device attributes like serial number, hardware revision etc.) " + "resource behaves as exptected in cae of invalid request attempts.") public void badConfigData() throws Exception { - final Target target = targetManagement.generateTarget("4712"); + final Target target = entityFactory.generateTarget("4712"); final Target savedTarget = targetManagement.createTarget(target); // not allowed methods diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java index cafe655e9..124d8e38d 100644 --- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java +++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java @@ -25,8 +25,6 @@ import java.util.ArrayList; import java.util.List; import org.apache.commons.lang3.RandomUtils; -import org.eclipse.hawkbit.repository.jpa.TestDataUtil; -import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.ActionType; import org.eclipse.hawkbit.repository.model.Action.Status; @@ -63,7 +61,7 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD @Test() @Description("Ensures that artifacts are not found, when softare module does not exists.") public void artifactsNotFound() throws Exception { - final Target target = TestDataUtil.createTarget(targetManagement); + final Target target = testdataFactory.createTarget(); final Long softwareModuleIdNotExist = 1l; mvc.perform(get("/{tenant}/controller/v1/{targetNotExist}/softwaremodules/{softwareModuleId}/artifacts", tenantAware.getCurrentTenant(), target.getName(), softwareModuleIdNotExist)) @@ -73,9 +71,8 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD @Test() @Description("Ensures that artifacts are found, when software module exists.") public void artifactsExists() throws Exception { - final Target target = TestDataUtil.createTarget(targetManagement); - final DistributionSet distributionSet = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); + final Target target = testdataFactory.createTarget(); + final DistributionSet distributionSet = testdataFactory.createDistributionSet(""); deploymentManagement.assignDistributionSet(distributionSet.getId(), new String[] { target.getName() }); @@ -84,7 +81,7 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD tenantAware.getCurrentTenant(), target.getName(), softwareModuleId)).andDo(MockMvcResultPrinter.print()) .andExpect(status().isOk()).andExpect(jsonPath("$", hasSize(0))); - TestDataUtil.generateArtifacts(artifactManagement, softwareModuleId); + testdataFactory.createLocalArtifacts(softwareModuleId); mvc.perform(get("/{tenant}/controller/v1/{targetNotExist}/softwaremodules/{softwareModuleId}/artifacts", tenantAware.getCurrentTenant(), target.getName(), softwareModuleId)).andDo(MockMvcResultPrinter.print()) @@ -99,11 +96,9 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD @Description("Forced deployment to a controller. Checks if the resource reponse payload for a given deployment is as expected.") public void deplomentForceAction() throws Exception { // Prepare test data - final Target target = targetManagement.generateTarget("4712"); - final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement, true); - final DistributionSet ds2 = TestDataUtil.generateDistributionSet("2", softwareManagement, - distributionSetManagement, true); + final Target target = entityFactory.generateTarget("4712"); + final DistributionSet ds = testdataFactory.createDistributionSet("", true); + final DistributionSet ds2 = testdataFactory.createDistributionSet("2", true); final byte random[] = RandomUtils.nextBytes(5 * 1024); final LocalArtifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), @@ -114,18 +109,18 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD final Target savedTarget = targetManagement.createTarget(target); assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).isEmpty(); - assertThat(actionRepository.findAll()).isEmpty(); - assertThat(actionStatusRepository.findAll()).isEmpty(); + assertThat(deploymentManagement.countActionsAll()).isEqualTo(0); + assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(0); List saved = deploymentManagement.assignDistributionSet(ds.getId(), ActionType.FORCED, Constants.NO_FORCE_TIME, savedTarget.getControllerId()).getAssignedEntity(); assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(1); final Action action = deploymentManagement.findActiveActionsByTarget(savedTarget).get(0); - assertThat(actionRepository.findAll()).hasSize(1); + assertThat(deploymentManagement.countActionsAll()).isEqualTo(1); saved = deploymentManagement.assignDistributionSet(ds2, saved).getAssignedEntity(); assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(2); - assertThat(actionRepository.findAll()).hasSize(2); + assertThat(deploymentManagement.countActionsAll()).isEqualTo(2); final Action uaction = deploymentManagement.findActiveActionsByTarget(savedTarget).get(0); assertThat(uaction.getDistributionSet()).isEqualTo(ds); @@ -143,7 +138,7 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD .isGreaterThanOrEqualTo(current); assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getLastTargetQuery()) .isLessThanOrEqualTo(System.currentTimeMillis()); - assertThat(actionStatusRepository.findAll()).hasSize(2); + assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(2); current = System.currentTimeMillis(); @@ -238,11 +233,9 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD @Description("Attempt/soft deployment to a controller. Checks if the resource reponse payload for a given deployment is as expected.") public void deplomentAttemptAction() throws Exception { // Prepare test data - final Target target = targetManagement.generateTarget("4712"); - final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement, true); - final DistributionSet ds2 = TestDataUtil.generateDistributionSet("2", softwareManagement, - distributionSetManagement, true); + final Target target = entityFactory.generateTarget("4712"); + final DistributionSet ds = testdataFactory.createDistributionSet("", true); + final DistributionSet ds2 = testdataFactory.createDistributionSet("2", true); final byte random[] = RandomUtils.nextBytes(5 * 1024); final LocalArtifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), @@ -253,19 +246,18 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD final Target savedTarget = targetManagement.createTarget(target); assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).isEmpty(); - assertThat(actionRepository.findAll()).isEmpty(); - assertThat(actionStatusRepository.findAll()).isEmpty(); + assertThat(deploymentManagement.countActionsAll()).isEqualTo(0); + assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(0); - List saved = deploymentManagement - .assignDistributionSet(ds.getId(), ActionType.SOFT, Constants.NO_FORCE_TIME, savedTarget.getControllerId()) - .getAssignedEntity(); + List saved = deploymentManagement.assignDistributionSet(ds.getId(), ActionType.SOFT, + Constants.NO_FORCE_TIME, savedTarget.getControllerId()).getAssignedEntity(); assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(1); final Action action = deploymentManagement.findActiveActionsByTarget(savedTarget).get(0); - assertThat(actionRepository.findAll()).hasSize(1); + assertThat(deploymentManagement.countActionsAll()).isEqualTo(1); saved = deploymentManagement.assignDistributionSet(ds2, saved).getAssignedEntity(); assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(2); - assertThat(actionRepository.findAll()).hasSize(2); + assertThat(deploymentManagement.countActionsAll()).isEqualTo(2); final Action uaction = deploymentManagement.findActiveActionsByTarget(savedTarget).get(0); assertThat(uaction.getDistributionSet()).isEqualTo(ds); @@ -284,7 +276,7 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD .isGreaterThanOrEqualTo(current); assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getLastTargetQuery()) .isLessThanOrEqualTo(System.currentTimeMillis()); - assertThat(actionStatusRepository.findAll()).hasSize(2); + assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(2); current = System.currentTimeMillis(); @@ -369,11 +361,9 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD @Description("Attempt/soft deployment to a controller including automated switch to hard. Checks if the resource reponse payload for a given deployment is as expected.") public void deplomentAutoForceAction() throws Exception { // Prepare test data - final Target target = targetManagement.generateTarget("4712"); - final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement, true); - final DistributionSet ds2 = TestDataUtil.generateDistributionSet("2", softwareManagement, - distributionSetManagement, true); + final Target target = entityFactory.generateTarget("4712"); + final DistributionSet ds = testdataFactory.createDistributionSet("", true); + final DistributionSet ds2 = testdataFactory.createDistributionSet("2", true); final byte random[] = RandomUtils.nextBytes(5 * 1024); final LocalArtifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), @@ -384,18 +374,18 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD final Target savedTarget = targetManagement.createTarget(target); assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).isEmpty(); - assertThat(actionRepository.findAll()).isEmpty(); - assertThat(actionStatusRepository.findAll()).isEmpty(); + assertThat(deploymentManagement.countActionsAll()).isEqualTo(0); + assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(0); List saved = deploymentManagement.assignDistributionSet(ds.getId(), ActionType.TIMEFORCED, System.currentTimeMillis(), savedTarget.getControllerId()).getAssignedEntity(); assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(1); final Action action = deploymentManagement.findActiveActionsByTarget(savedTarget).get(0); - assertThat(actionRepository.findAll()).hasSize(1); + assertThat(deploymentManagement.countActionsAll()).isEqualTo(1); saved = deploymentManagement.assignDistributionSet(ds2, saved).getAssignedEntity(); assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(2); - assertThat(actionRepository.findAll()).hasSize(2); + assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(2); final Action uaction = deploymentManagement.findActiveActionsByTarget(savedTarget).get(0); assertThat(uaction.getDistributionSet()).isEqualTo(ds); @@ -414,7 +404,7 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD .isGreaterThanOrEqualTo(current); assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getLastTargetQuery()) .isLessThanOrEqualTo(System.currentTimeMillis()); - assertThat(actionStatusRepository.findAll()).hasSize(2); + assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(2); current = System.currentTimeMillis(); @@ -506,7 +496,7 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD @Test @Description("Test various invalid access attempts to the deployment resource und the expected behaviour of the server.") public void badDeploymentAction() throws Exception { - final Target target = targetManagement.createTarget(targetManagement.generateTarget("4712")); + final Target target = targetManagement.createTarget(entityFactory.generateTarget("4712")); // not allowed methods mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/1", tenantAware.getCurrentTenant())) @@ -529,8 +519,7 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD // wrong media type final List toAssign = new ArrayList<>(); toAssign.add(target); - final DistributionSet savedSet = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); + final DistributionSet savedSet = testdataFactory.createDistributionSet(""); final Action action1 = deploymentManagement.findActionWithDetails( deploymentManagement.assignDistributionSet(savedSet, toAssign).getActions().get(0)); @@ -547,9 +536,8 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD @Description("The server protects itself against to many feedback upload attempts. The test verfies that " + "it is not possible to exceed the configured maximum number of feedback uplods.") public void toMuchDeplomentActionFeedback() throws Exception { - final Target target = targetManagement.createTarget(targetManagement.generateTarget("4712")); - final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); + final Target target = targetManagement.createTarget(entityFactory.generateTarget("4712")); + final DistributionSet ds = testdataFactory.createDistributionSet(""); final List toAssign = new ArrayList<>(); toAssign.add(target); @@ -575,19 +563,16 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD @Test @Description("Multiple uploads of deployment status feedback to the server.") public void multipleDeplomentActionFeedback() throws Exception { - final Target target1 = targetManagement.generateTarget("4712"); - final Target target2 = targetManagement.generateTarget("4713"); - final Target target3 = targetManagement.generateTarget("4714"); + final Target target1 = entityFactory.generateTarget("4712"); + final Target target2 = entityFactory.generateTarget("4713"); + final Target target3 = entityFactory.generateTarget("4714"); final Target savedTarget1 = targetManagement.createTarget(target1); targetManagement.createTarget(target2); targetManagement.createTarget(target3); - final DistributionSet ds1 = TestDataUtil.generateDistributionSet("1", softwareManagement, - distributionSetManagement, true); - final DistributionSet ds2 = TestDataUtil.generateDistributionSet("2", softwareManagement, - distributionSetManagement, true); - final DistributionSet ds3 = TestDataUtil.generateDistributionSet("3", softwareManagement, - distributionSetManagement, true); + final DistributionSet ds1 = testdataFactory.createDistributionSet("1", true); + final DistributionSet ds2 = testdataFactory.createDistributionSet("2", true); + final DistributionSet ds3 = testdataFactory.createDistributionSet("3", true); final List toAssign = new ArrayList<>(); toAssign.add(savedTarget1); @@ -680,8 +665,8 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD @Test @Description("Verfies that an update action is correctly set to error if the controller provides error feedback.") public void rootRsSingleDeplomentActionWithErrorFeedback() throws Exception { - final Target target = targetManagement.generateTarget("4712"); - DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement, distributionSetManagement); + final Target target = entityFactory.generateTarget("4712"); + DistributionSet ds = testdataFactory.createDistributionSet(""); final Target savedTarget = targetManagement.createTarget(target); @@ -691,8 +676,7 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getUpdateStatus()) .isEqualTo(TargetUpdateStatus.UNKNOWN); deploymentManagement.assignDistributionSet(ds, toAssign); - final Action action = actionRepository.findByDistributionSet(pageReq, (JpaDistributionSet) ds).getContent() - .get(0); + final Action action = deploymentManagement.findActionsByDistributionSet(pageReq, ds).getContent().get(0); long current = System.currentTimeMillis(); long lastModified = targetManagement.findTargetByControllerID("4712").getLastModifiedAt(); @@ -747,7 +731,7 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD .hasSize(1); assertThat(deploymentManagement.findActiveActionsByTarget(myT)).hasSize(0); assertThat(deploymentManagement.findInActiveActionsByTarget(myT)).hasSize(2); - assertThat(actionStatusRepository.findAll()).hasSize(4); + assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(4); assertThat(deploymentManagement.findActionStatusByAction(pageReq, action).getContent()).haveAtLeast(1, new ActionStatusCondition(Status.ERROR)); assertThat(deploymentManagement.findActionStatusByAction(pageReq, action2).getContent()).haveAtLeast(1, @@ -758,9 +742,8 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD @Test @Description("Verfies that the controller can provided as much feedback entries as necessry as long as it is in the configured limites.") public void rootRsSingleDeplomentActionFeedback() throws Exception { - final Target target = targetManagement.generateTarget("4712"); - final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); + final Target target = entityFactory.generateTarget("4712"); + final DistributionSet ds = testdataFactory.createDistributionSet(""); final Target savedTarget = targetManagement.createTarget(target); @@ -770,17 +753,12 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD Target myT = targetManagement.findTargetByControllerID("4712"); assertThat(myT.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.UNKNOWN); deploymentManagement.assignDistributionSet(ds, toAssign); - final Action action = actionRepository.findByDistributionSet(pageReq, (JpaDistributionSet) ds).getContent() - .get(0); + final Action action = deploymentManagement.findActionsByDistributionSet(pageReq, ds).getContent().get(0); myT = targetManagement.findTargetByControllerID("4712"); assertThat(myT.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING); - assertThat(targetRepository.findByTargetInfoInstalledDistributionSet(new PageRequest(0, 10), - (JpaDistributionSet) ds)).hasSize(0); - assertThat(targetRepository.findByAssignedDistributionSet(new PageRequest(0, 10), (JpaDistributionSet) ds)) - .hasSize(1); - assertThat(targetRepository.findByAssignedDistributionSetOrTargetInfoInstalledDistributionSet( - new PageRequest(0, 10), (JpaDistributionSet) ds, (JpaDistributionSet) ds)).hasSize(1); + assertThat(targetManagement.findTargetByInstalledDistributionSet(ds.getId(), pageReq)).hasSize(0); + assertThat(targetManagement.findTargetByAssignedDistributionSet(ds.getId(), pageReq)).hasSize(1); // Now valid Feedback @@ -804,8 +782,9 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.IN_SYNC)) .hasSize(0); assertThat(deploymentManagement.findActiveActionsByTarget(myT)).hasSize(1); - assertThat(actionStatusRepository.findAll()).hasSize(5); - assertThat(actionStatusRepository.findAll()).haveAtLeast(5, new ActionStatusCondition(Status.RUNNING)); + assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(5); + assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(5, + new ActionStatusCondition(Status.RUNNING)); current = System.currentTimeMillis(); mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action.getId() + "/feedback", @@ -823,8 +802,9 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.IN_SYNC)) .hasSize(0); assertThat(deploymentManagement.findActiveActionsByTarget(myT)).hasSize(1); - assertThat(actionStatusRepository.findAll()).hasSize(6); - assertThat(actionStatusRepository.findAll()).haveAtLeast(5, new ActionStatusCondition(Status.RUNNING)); + assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(6); + assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(5, + new ActionStatusCondition(Status.RUNNING)); current = System.currentTimeMillis(); mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action.getId() + "/feedback", @@ -842,8 +822,9 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.IN_SYNC)) .hasSize(0); assertThat(deploymentManagement.findActiveActionsByTarget(myT)).hasSize(1); - assertThat(actionStatusRepository.findAll()).hasSize(7); - assertThat(actionStatusRepository.findAll()).haveAtLeast(6, new ActionStatusCondition(Status.RUNNING)); + assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(7); + assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(6, + new ActionStatusCondition(Status.RUNNING)); current = System.currentTimeMillis(); mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action.getId() + "/feedback", @@ -862,9 +843,11 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.IN_SYNC)) .hasSize(0); - assertThat(actionStatusRepository.findAll()).hasSize(8); - assertThat(actionStatusRepository.findAll()).haveAtLeast(7, new ActionStatusCondition(Status.RUNNING)); - assertThat(actionStatusRepository.findAll()).haveAtLeast(1, new ActionStatusCondition(Status.CANCELED)); + assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(8); + assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(7, + new ActionStatusCondition(Status.RUNNING)); + assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(1, + new ActionStatusCondition(Status.CANCELED)); current = System.currentTimeMillis(); mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action.getId() + "/feedback", @@ -876,10 +859,13 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD assertThat(myT.getTargetInfo().getLastTargetQuery()).isGreaterThanOrEqualTo(current); assertThat(myT.getTargetInfo().getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING); assertThat(deploymentManagement.findActiveActionsByTarget(myT)).hasSize(1); - assertThat(actionStatusRepository.findAll()).hasSize(9); - assertThat(actionStatusRepository.findAll()).haveAtLeast(6, new ActionStatusCondition(Status.RUNNING)); - assertThat(actionStatusRepository.findAll()).haveAtLeast(1, new ActionStatusCondition(Status.WARNING)); - assertThat(actionStatusRepository.findAll()).haveAtLeast(1, new ActionStatusCondition(Status.CANCELED)); + assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(9); + assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(6, + new ActionStatusCondition(Status.RUNNING)); + assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(1, + new ActionStatusCondition(Status.WARNING)); + assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(1, + new ActionStatusCondition(Status.CANCELED)); current = System.currentTimeMillis(); mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/" + action.getId() + "/feedback", @@ -896,29 +882,27 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD assertThat(targetManagement.findTargetByUpdateStatus(new PageRequest(0, 10), TargetUpdateStatus.IN_SYNC)) .hasSize(1); - assertThat(actionStatusRepository.findAll()).hasSize(10); - assertThat(actionStatusRepository.findAll()).haveAtLeast(7, new ActionStatusCondition(Status.RUNNING)); - assertThat(actionStatusRepository.findAll()).haveAtLeast(1, new ActionStatusCondition(Status.WARNING)); - assertThat(actionStatusRepository.findAll()).haveAtLeast(1, new ActionStatusCondition(Status.CANCELED)); - assertThat(actionStatusRepository.findAll()).haveAtLeast(1, new ActionStatusCondition(Status.FINISHED)); + assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(10); + assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(7, + new ActionStatusCondition(Status.RUNNING)); + assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(1, + new ActionStatusCondition(Status.WARNING)); + assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(1, + new ActionStatusCondition(Status.CANCELED)); + assertThat(deploymentManagement.findActionStatusAll(pageReq).getContent()).haveAtLeast(1, + new ActionStatusCondition(Status.FINISHED)); - assertThat(targetRepository.findByTargetInfoInstalledDistributionSet(new PageRequest(0, 10), - (JpaDistributionSet) ds)).hasSize(1); - assertThat(targetRepository.findByAssignedDistributionSet(new PageRequest(0, 10), (JpaDistributionSet) ds)) - .hasSize(1); - assertThat(targetRepository.findByAssignedDistributionSetOrTargetInfoInstalledDistributionSet( - new PageRequest(0, 10), (JpaDistributionSet) ds, (JpaDistributionSet) ds)).hasSize(1); + assertThat(targetManagement.findTargetByInstalledDistributionSet(ds.getId(), pageReq)).hasSize(1); + assertThat(targetManagement.findTargetByAssignedDistributionSet(ds.getId(), pageReq)).hasSize(1); } @Test @Description("Various forbidden request appempts on the feedback resource. Ensures correct answering behaviour as expected to these kind of errors.") public void badDeplomentActionFeedback() throws Exception { - final Target target = targetManagement.generateTarget("4712"); - final Target target2 = targetManagement.generateTarget("4713"); - final DistributionSet savedSet = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); - final DistributionSet savedSet2 = TestDataUtil.generateDistributionSet("1", softwareManagement, - distributionSetManagement); + final Target target = entityFactory.generateTarget("4712"); + final Target target2 = entityFactory.generateTarget("4713"); + final DistributionSet savedSet = testdataFactory.createDistributionSet(""); + final DistributionSet savedSet2 = testdataFactory.createDistributionSet("1"); // target does not exist mvc.perform(post("/{tenant}/controller/v1/4712/deploymentBase/1234/feedback", tenantAware.getCurrentTenant()) diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootControllerTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootControllerTest.java index 490e76161..135754604 100644 --- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootControllerTest.java +++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootControllerTest.java @@ -24,13 +24,12 @@ import java.util.List; import org.eclipse.hawkbit.im.authentication.SpPermission; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; -import org.eclipse.hawkbit.repository.jpa.TestDataUtil; -import org.eclipse.hawkbit.repository.jpa.WithSpringAuthorityRule; -import org.eclipse.hawkbit.repository.jpa.WithUser; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; +import org.eclipse.hawkbit.repository.util.WithSpringAuthorityRule; +import org.eclipse.hawkbit.repository.util.WithUser; import org.eclipse.hawkbit.rest.AbstractRestIntegrationTestWithMongoDB; import org.eclipse.hawkbit.rest.util.JsonBuilder; import org.eclipse.hawkbit.rest.util.MockMvcResultPrinter; @@ -80,7 +79,7 @@ public class DdiRootControllerTest extends AbstractRestIntegrationTestWithMongoD // create target first with "knownPrincipal" user and audit data final String knownTargetControllerId = "target1"; final String knownCreatedBy = "knownPrincipal"; - targetManagement.createTarget(targetManagement.generateTarget(knownTargetControllerId)); + targetManagement.createTarget(entityFactory.generateTarget(knownTargetControllerId)); final Target findTargetByControllerID = targetManagement.findTargetByControllerID(knownTargetControllerId); assertThat(findTargetByControllerID.getCreatedBy()).isEqualTo(knownCreatedBy); assertThat(findTargetByControllerID.getCreatedAt()).isNotNull(); @@ -121,7 +120,7 @@ public class DdiRootControllerTest extends AbstractRestIntegrationTestWithMongoD assertThat(targetManagement.findTargetByControllerID("4711").getTargetInfo().getLastTargetQuery()) .isGreaterThanOrEqualTo(current); - assertThat(targetRepository.findByControllerId("4711").getTargetInfo().getUpdateStatus()) + assertThat(targetManagement.findTargetByControllerID("4711").getTargetInfo().getUpdateStatus()) .isEqualTo(TargetUpdateStatus.REGISTERED); // not allowed methods @@ -169,9 +168,8 @@ public class DdiRootControllerTest extends AbstractRestIntegrationTestWithMongoD mvc.perform(get("/{tenant}/controller/v1/4711", tenantAware.getCurrentTenant()).header("If-None-Match", etag)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isNotModified()); - final Target target = targetRepository.findByControllerId("4711"); - final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); + final Target target = targetManagement.findTargetByControllerID("4711"); + final DistributionSet ds = testdataFactory.createDistributionSet(""); deploymentManagement.assignDistributionSet(ds.getId(), new String[] { "4711" }); @@ -204,8 +202,7 @@ public class DdiRootControllerTest extends AbstractRestIntegrationTestWithMongoD .andDo(MockMvcResultPrinter.print()).andExpect(status().isNotModified()); // Now another deployment - final DistributionSet ds2 = TestDataUtil.generateDistributionSet("2", softwareManagement, - distributionSetManagement); + final DistributionSet ds2 = testdataFactory.createDistributionSet("2"); deploymentManagement.assignDistributionSet(ds2.getId(), new String[] { "4711" }); @@ -226,10 +223,10 @@ public class DdiRootControllerTest extends AbstractRestIntegrationTestWithMongoD @Description("Ensures that the target state machine of a precomissioned target switches from " + "UNKNOWN to REGISTERED when the target polls for the first time.") public void rootRsPrecommissioned() throws Exception { - final Target target = targetManagement.generateTarget("4711"); + final Target target = entityFactory.generateTarget("4711"); targetManagement.createTarget(target); - assertThat(targetRepository.findByControllerId("4711").getTargetInfo().getUpdateStatus()) + assertThat(targetManagement.findTargetByControllerID("4711").getTargetInfo().getUpdateStatus()) .isEqualTo(TargetUpdateStatus.UNKNOWN); final long current = System.currentTimeMillis(); @@ -242,7 +239,7 @@ public class DdiRootControllerTest extends AbstractRestIntegrationTestWithMongoD assertThat(targetManagement.findTargetByControllerID("4711").getTargetInfo().getLastTargetQuery()) .isGreaterThanOrEqualTo(current); - assertThat(targetRepository.findByControllerId("4711").getTargetInfo().getUpdateStatus()) + assertThat(targetManagement.findTargetByControllerID("4711").getTargetInfo().getUpdateStatus()) .isEqualTo(TargetUpdateStatus.REGISTERED); } @@ -265,11 +262,10 @@ public class DdiRootControllerTest extends AbstractRestIntegrationTestWithMongoD public void tryToFinishAnUpdateProcessAfterItHasBeenFinished() throws Exception { // mock - final Target target = targetManagement.generateTarget("911"); - final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); + final Target target = entityFactory.generateTarget("911"); + final DistributionSet ds = testdataFactory.createDistributionSet(""); Target savedTarget = targetManagement.createTarget(target); - final List toAssign = new ArrayList(); + final List toAssign = new ArrayList<>(); toAssign.add(savedTarget); savedTarget = deploymentManagement.assignDistributionSet(ds, toAssign).getAssignedEntity().iterator().next(); final Action savedAction = deploymentManagement.findActiveActionsByTarget(savedTarget).get(0); diff --git a/hawkbit-dmf-amqp/pom.xml b/hawkbit-dmf-amqp/pom.xml index d1cb0cb30..bcebc9628 100644 --- a/hawkbit-dmf-amqp/pom.xml +++ b/hawkbit-dmf-amqp/pom.xml @@ -73,6 +73,12 @@ + + org.eclipse.hawkbit + hawkbit-repository-test + ${project.version} + test + com.h2database h2 diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java index 90039d4ba..107850fc1 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java +++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java @@ -34,6 +34,7 @@ import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; import org.eclipse.hawkbit.im.authentication.TenantAwareAuthenticationDetails; import org.eclipse.hawkbit.repository.ArtifactManagement; import org.eclipse.hawkbit.repository.ControllerManagement; +import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.eventbus.event.TargetAssignDistributionSetEvent; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.model.Action; @@ -97,6 +98,9 @@ public class AmqpMessageHandlerService extends BaseAmqpService { @Autowired private HostnameResolver hostnameResolver; + @Autowired + private EntityFactory entityFactory; + /** * Constructor. * @@ -336,7 +340,7 @@ public class AmqpMessageHandlerService extends BaseAmqpService { final ActionUpdateStatus actionUpdateStatus = convertMessage(message, ActionUpdateStatus.class); final Action action = checkActionExist(message, actionUpdateStatus); - final ActionStatus actionStatus = controllerManagement.generateActionStatus(); + final ActionStatus actionStatus = entityFactory.generateActionStatus(); actionUpdateStatus.getMessage().forEach(actionStatus::addMessage); actionStatus.setAction(action); @@ -449,4 +453,8 @@ public class AmqpMessageHandlerService extends BaseAmqpService { this.eventBus = eventBus; } + void setEntityFactory(final EntityFactory entityFactory) { + this.entityFactory = entityFactory; + } + } diff --git a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/AmqpTestConfiguration.java b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/AmqpTestConfiguration.java index a1dd54710..c9be9ffa6 100644 --- a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/AmqpTestConfiguration.java +++ b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/AmqpTestConfiguration.java @@ -10,6 +10,8 @@ package org.eclipse.hawkbit; import org.eclipse.hawkbit.amqp.AmqpSenderService; import org.eclipse.hawkbit.amqp.DefaultAmqpSenderService; +import org.eclipse.hawkbit.repository.jpa.model.helper.SystemSecurityContextHolder; +import org.eclipse.hawkbit.security.SystemSecurityContext; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; import org.springframework.amqp.support.converter.MessageConverter; @@ -22,6 +24,15 @@ import org.springframework.context.annotation.Configuration; */ @Configuration public class AmqpTestConfiguration { + /** + * @return the {@link SystemSecurityContext} singleton bean which make it + * accessible in beans which cannot access the service directly, + * e.g. JPA entities. + */ + @Bean + public SystemSecurityContextHolder systemSecurityContextHolder() { + return SystemSecurityContextHolder.getInstance(); + } /** * Method to set the Jackson2JsonMessageConverter. diff --git a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java index 132ddb650..480948683 100644 --- a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java +++ b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java @@ -33,8 +33,7 @@ import org.eclipse.hawkbit.dmf.amqp.api.MessageType; import org.eclipse.hawkbit.dmf.json.model.DownloadAndUpdateRequest; import org.eclipse.hawkbit.eventbus.event.CancelTargetAssignmentEvent; import org.eclipse.hawkbit.repository.eventbus.event.TargetAssignDistributionSetEvent; -import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTestWithMongoDB; -import org.eclipse.hawkbit.repository.jpa.TestDataUtil; +import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTestWithMongoDB; import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.LocalArtifact; @@ -57,7 +56,7 @@ import ru.yandex.qatools.allure.annotations.Stories; @ActiveProfiles({ "test" }) @Features("Component Tests - Device Management Federation API") @Stories("AmqpMessage Dispatcher Service Test") -public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTestWithMongoDB { +public class AmqpMessageDispatcherServiceTest extends AbstractJpaIntegrationTestWithMongoDB { private static final String TENANT = "default"; @@ -108,8 +107,7 @@ public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTestWit @Test @Description("Verfies that download and install event with 3 software moduls and no artifacts works") public void testSendDownloadRequesWithSoftwareModulesAndNoArtifacts() { - final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); + final DistributionSet dsA = testdataFactory.createDistributionSet(""); final TargetAssignDistributionSetEvent targetAssignDistributionSetEvent = new TargetAssignDistributionSetEvent( 1L, TENANT, CONTROLLER_ID, 1L, dsA.getModules(), AMQP_URI, TEST_TOKEN); amqpMessageDispatcherService.targetAssignDistributionSet(targetAssignDistributionSetEvent); @@ -139,11 +137,10 @@ public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTestWit @Test @Description("Verfies that download and install event with software moduls and artifacts works") public void testSendDownloadRequest() { - final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); + final DistributionSet dsA = testdataFactory.createDistributionSet(""); final SoftwareModule module = dsA.getModules().iterator().next(); final List receivedList = new ArrayList<>(); - for (final Artifact artifact : TestDataUtil.generateArtifacts(artifactManagement, module.getId())) { + for (final Artifact artifact : testdataFactory.createLocalArtifacts(module.getId())) { module.addArtifact((LocalArtifact) artifact); receivedList.add(new DbArtifact()); } diff --git a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java index 2ce6cd91c..283b08eed 100644 --- a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java +++ b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java @@ -38,6 +38,7 @@ import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken; import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken.FileResource; import org.eclipse.hawkbit.repository.ArtifactManagement; import org.eclipse.hawkbit.repository.ControllerManagement; +import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.eventbus.event.TargetAssignDistributionSetEvent; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.jpa.model.JpaAction; @@ -85,6 +86,9 @@ public class AmqpMessageHandlerServiceTest { @Mock private ControllerManagement controllerManagementMock; + @Mock + private EntityFactory entityFactoryMock; + @Mock private ArtifactManagement artifactManagementMock; @@ -117,6 +121,7 @@ public class AmqpMessageHandlerServiceTest { amqpMessageHandlerService.setCache(cacheMock); amqpMessageHandlerService.setHostnameResolver(hostnameResolverMock); amqpMessageHandlerService.setEventBus(eventBus); + amqpMessageHandlerService.setEntityFactory(entityFactoryMock); } @@ -350,7 +355,7 @@ public class AmqpMessageHandlerServiceTest { final Action action = createActionWithTarget(22L, Status.FINISHED); when(controllerManagementMock.findActionWithDetails(Matchers.any())).thenReturn(action); when(controllerManagementMock.addUpdateActionStatus(Matchers.any())).thenReturn(action); - when(controllerManagementMock.generateActionStatus()).thenReturn(new JpaActionStatus()); + when(entityFactoryMock.generateActionStatus()).thenReturn(new JpaActionStatus()); // for the test the same action can be used final List actionList = new ArrayList<>(); actionList.add(action); diff --git a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/util/PropertyBasedArtifactUrlHandlerTest.java b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/util/PropertyBasedArtifactUrlHandlerTest.java index 3d83fed69..8f855da68 100644 --- a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/util/PropertyBasedArtifactUrlHandlerTest.java +++ b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/util/PropertyBasedArtifactUrlHandlerTest.java @@ -14,12 +14,11 @@ import org.eclipse.hawkbit.AmqpTestConfiguration; import org.eclipse.hawkbit.RepositoryApplicationConfiguration; import org.eclipse.hawkbit.api.ArtifactUrlHandler; import org.eclipse.hawkbit.api.UrlProtocol; -import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTestWithMongoDB; import org.eclipse.hawkbit.repository.jpa.TestConfiguration; -import org.eclipse.hawkbit.repository.jpa.TestDataUtil; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; +import org.eclipse.hawkbit.repository.util.AbstractIntegrationTestWithMongoDB; import org.eclipse.hawkbit.tenancy.TenantAware; import org.junit.Before; import org.junit.Test; @@ -53,11 +52,9 @@ public class PropertyBasedArtifactUrlHandlerTest extends AbstractIntegrationTest @Before public void setup() { - final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); + final DistributionSet dsA = testdataFactory.createDistributionSet(""); final SoftwareModule module = dsA.getModules().iterator().next(); - localArtifact = (LocalArtifact) TestDataUtil.generateArtifacts(artifactManagement, module.getId()).stream() - .findAny().get(); + localArtifact = testdataFactory.createLocalArtifacts(module.getId()).stream().findAny().get(); softwareModuleId = localArtifact.getSoftwareModule().getId(); fileName = localArtifact.getFilename(); sha1Hash = localArtifact.getSha1Hash(); diff --git a/hawkbit-mgmt-resource/pom.xml b/hawkbit-mgmt-resource/pom.xml index 2279172e9..fb0167793 100644 --- a/hawkbit-mgmt-resource/pom.xml +++ b/hawkbit-mgmt-resource/pom.xml @@ -47,6 +47,12 @@ + + org.eclipse.hawkbit + hawkbit-repository-test + ${project.version} + test + org.eclipse.hawkbit hawkbit-rest-core diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetMapper.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetMapper.java index d4780f71c..4a0f8d90e 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetMapper.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetMapper.java @@ -23,6 +23,7 @@ import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetTypeRestApi; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.repository.DistributionSetAssignmentResult; import org.eclipse.hawkbit.repository.DistributionSetManagement; +import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.model.DistributionSet; @@ -75,11 +76,12 @@ public final class MgmtDistributionSetMapper { * @return converted list of {@link DistributionSet}s */ static List dsFromRequest(final Iterable sets, - final SoftwareManagement softwareManagement, final DistributionSetManagement distributionSetManagement) { + final SoftwareManagement softwareManagement, final DistributionSetManagement distributionSetManagement, + final EntityFactory entityFactory) { final List mappedList = new ArrayList<>(); for (final MgmtDistributionSetRequestBodyPost dsRest : sets) { - mappedList.add(fromRequest(dsRest, softwareManagement, distributionSetManagement)); + mappedList.add(fromRequest(dsRest, softwareManagement, distributionSetManagement, entityFactory)); } return mappedList; @@ -95,9 +97,10 @@ public final class MgmtDistributionSetMapper { * @return converted {@link DistributionSet} */ static DistributionSet fromRequest(final MgmtDistributionSetRequestBodyPost dsRest, - final SoftwareManagement softwareManagement, final DistributionSetManagement distributionSetManagement) { + final SoftwareManagement softwareManagement, final DistributionSetManagement distributionSetManagement, + final EntityFactory entityFactory) { - final DistributionSet result = distributionSetManagement.generateDistributionSet(); + final DistributionSet result = entityFactory.generateDistributionSet(); result.setDescription(dsRest.getDescription()); result.setName(dsRest.getName()); result.setType(findDistributionSetTypeWithExceptionIfNotFound(dsRest.getType(), distributionSetManagement)); @@ -135,14 +138,14 @@ public final class MgmtDistributionSetMapper { * @return */ static List fromRequestDsMetadata(final DistributionSet ds, - final List metadata, final DistributionSetManagement distributionSetManagement) { + final List metadata, final EntityFactory entityFactory) { final List mappedList = new ArrayList<>(metadata.size()); for (final MgmtMetadata metadataRest : metadata) { if (metadataRest.getKey() == null) { throw new IllegalArgumentException("the key of the metadata must be present"); } - mappedList.add(distributionSetManagement.generateDistributionSetMetadata(ds, metadataRest.getKey(), - metadataRest.getValue())); + mappedList.add( + entityFactory.generateDistributionSetMetadata(ds, metadataRest.getKey(), metadataRest.getValue())); } return mappedList; } diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java index e9249f551..e99a33c5f 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java @@ -28,6 +28,7 @@ import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.DistributionSetAssignmentResult; import org.eclipse.hawkbit.repository.DistributionSetManagement; +import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.SystemManagement; @@ -74,6 +75,9 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi { @Autowired private TenantAware currentTenant; + @Autowired + private EntityFactory entityFactory; + @Autowired private DistributionSetManagement distributionSetManagement; @@ -118,8 +122,9 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi { sets.stream().filter(ds -> ds.getType() == null).forEach(ds -> ds.setType(this.systemManagement .getTenantMetadata(this.currentTenant.getCurrentTenant()).getDefaultDsType().getKey())); - final Iterable createdDSets = this.distributionSetManagement.createDistributionSets( - MgmtDistributionSetMapper.dsFromRequest(sets, this.softwareManagement, this.distributionSetManagement)); + final Iterable createdDSets = this.distributionSetManagement + .createDistributionSets(MgmtDistributionSetMapper.dsFromRequest(sets, this.softwareManagement, + this.distributionSetManagement, entityFactory)); LOG.debug("{} distribution sets created, return status {}", sets.size(), HttpStatus.CREATED); return new ResponseEntity<>(MgmtDistributionSetMapper.toResponseDistributionSets(createdDSets), @@ -284,7 +289,7 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi { // immediately final DistributionSet ds = findDistributionSetWithExceptionIfNotFound(distributionSetId); final DistributionSetMetadata updated = this.distributionSetManagement.updateDistributionSetMetadata( - distributionSetManagement.generateDistributionSetMetadata(ds, metadataKey, metadata.getValue())); + entityFactory.generateDistributionSetMetadata(ds, metadataKey, metadata.getValue())); return ResponseEntity.ok(MgmtDistributionSetMapper.toResponseDsMetadata(updated)); } @@ -307,7 +312,7 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi { final DistributionSet ds = findDistributionSetWithExceptionIfNotFound(distributionSetId); final List created = this.distributionSetManagement.createDistributionSetMetadata( - MgmtDistributionSetMapper.fromRequestDsMetadata(ds, metadataRest, distributionSetManagement)); + MgmtDistributionSetMapper.fromRequestDsMetadata(ds, metadataRest, entityFactory)); return new ResponseEntity<>(MgmtDistributionSetMapper.toResponseDsMetadata(created), HttpStatus.CREATED); } diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResource.java index 69f6e044c..18ec162ca 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResource.java @@ -20,6 +20,7 @@ import org.eclipse.hawkbit.mgmt.json.model.tag.MgmtTagRequestBodyPut; import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetTagRestApi; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.repository.DistributionSetManagement; +import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; @@ -54,6 +55,9 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes @Autowired private DistributionSetManagement distributionSetManagement; + @Autowired + private EntityFactory entityFactory; + @Override public ResponseEntity> getDistributionSetTags( @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, @@ -97,7 +101,7 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes LOG.debug("creating {} ds tags", tags.size()); final List createdTags = this.tagManagement - .createDistributionSetTags(MgmtTagMapper.mapDistributionSetTagFromRequest(tagManagement, tags)); + .createDistributionSetTags(MgmtTagMapper.mapDistributionSetTagFromRequest(entityFactory, tags)); return new ResponseEntity<>(MgmtTagMapper.toResponseDistributionSetTag(createdTags), HttpStatus.CREATED); } diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeMapper.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeMapper.java index a6dd6f32b..5c139027c 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeMapper.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeMapper.java @@ -18,7 +18,7 @@ import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionS import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionSetTypeRequestBodyPost; import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetTypeRestApi; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; -import org.eclipse.hawkbit.repository.DistributionSetManagement; +import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.model.DistributionSetType; @@ -36,21 +36,21 @@ final class MgmtDistributionSetTypeMapper { } - static List smFromRequest(final DistributionSetManagement distributionSetManagement, + static List smFromRequest(final EntityFactory entityFactory, final SoftwareManagement softwareManagement, final Iterable smTypesRest) { final List mappedList = new ArrayList<>(); for (final MgmtDistributionSetTypeRequestBodyPost smRest : smTypesRest) { - mappedList.add(fromRequest(distributionSetManagement, softwareManagement, smRest)); + mappedList.add(fromRequest(entityFactory, softwareManagement, smRest)); } return mappedList; } - static DistributionSetType fromRequest(final DistributionSetManagement distributionSetManagement, + static DistributionSetType fromRequest(final EntityFactory entityFactory, final SoftwareManagement softwareManagement, final MgmtDistributionSetTypeRequestBodyPost smsRest) { - final DistributionSetType result = distributionSetManagement.generateDistributionSetType(smsRest.getKey(), + final DistributionSetType result = entityFactory.generateDistributionSetType(smsRest.getKey(), smsRest.getName(), smsRest.getDescription()); // Add mandatory diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResource.java index 16cba384b..d69e4d8d4 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResource.java @@ -19,6 +19,7 @@ import org.eclipse.hawkbit.mgmt.json.model.softwaremoduletype.MgmtSoftwareModule import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetTypeRestApi; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.repository.DistributionSetManagement; +import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; @@ -53,6 +54,9 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR @Autowired private DistributionSetManagement distributionSetManagement; + @Autowired + private EntityFactory entityFactory; + @Override public ResponseEntity> getDistributionSetTypes( @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, @@ -121,9 +125,8 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR public ResponseEntity> createDistributionSetTypes( @RequestBody final List distributionSetTypes) { - final List createdSoftwareModules = distributionSetManagement - .createDistributionSetTypes(MgmtDistributionSetTypeMapper.smFromRequest(distributionSetManagement, - softwareManagement, distributionSetTypes)); + final List createdSoftwareModules = distributionSetManagement.createDistributionSetTypes( + MgmtDistributionSetTypeMapper.smFromRequest(entityFactory, softwareManagement, distributionSetTypes)); return new ResponseEntity<>(MgmtDistributionSetTypeMapper.toTypesResponse(createdSoftwareModules), HttpStatus.CREATED); diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutMapper.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutMapper.java index e80889508..7467a45b0 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutMapper.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutMapper.java @@ -22,7 +22,7 @@ import org.eclipse.hawkbit.mgmt.json.model.rollout.MgmtRolloutSuccessAction.Succ import org.eclipse.hawkbit.mgmt.json.model.rolloutgroup.MgmtRolloutGroupResponseBody; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRolloutRestApi; -import org.eclipse.hawkbit.repository.RolloutManagement; +import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.model.Action.ActionType; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Rollout; @@ -84,9 +84,9 @@ final class MgmtRolloutMapper { return body; } - static Rollout fromRequest(final RolloutManagement rolloutManagement, final MgmtRolloutRestRequestBody restRequest, + static Rollout fromRequest(final EntityFactory entityFactory, final MgmtRolloutRestRequestBody restRequest, final DistributionSet distributionSet, final String filterQuery) { - final Rollout rollout = rolloutManagement.generateRollout(); + final Rollout rollout = entityFactory.generateRollout(); rollout.setName(restRequest.getName()); rollout.setDescription(restRequest.getDescription()); rollout.setDistributionSet(distributionSet); diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResource.java index 0b3a77101..623241981 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResource.java @@ -18,6 +18,7 @@ import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTarget; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRolloutRestApi; import org.eclipse.hawkbit.repository.DistributionSetManagement; +import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.RolloutGroupManagement; import org.eclipse.hawkbit.repository.RolloutManagement; @@ -63,6 +64,9 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi { @Autowired private DistributionSetManagement distributionSetManagement; + @Autowired + private EntityFactory entityFactory; + @Override public ResponseEntity> getRollouts( @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, @@ -138,7 +142,7 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi { .successAction(successAction, successActionExpr).errorCondition(errorCondition, errorConditionExpr) .errorAction(errorAction, errorActionExpr).build(); final Rollout rollout = this.rolloutManagement.createRollout( - MgmtRolloutMapper.fromRequest(rolloutManagement, rolloutRequestBody, distributionSet, + MgmtRolloutMapper.fromRequest(entityFactory, rolloutRequestBody, distributionSet, rolloutRequestBody.getTargetFilterQuery()), rolloutRequestBody.getAmountGroups(), rolloutGroupConditions); diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleMapper.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleMapper.java index ff721dfbc..adc19df0a 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleMapper.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleMapper.java @@ -22,6 +22,7 @@ import org.eclipse.hawkbit.mgmt.json.model.softwaremodule.MgmtSoftwareModuleRequ import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.mgmt.rest.api.MgmtSoftwareModuleRestApi; import org.eclipse.hawkbit.mgmt.rest.api.MgmtSoftwareModuleTypeRestApi; +import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.model.Artifact; @@ -52,31 +53,31 @@ public final class MgmtSoftwareModuleMapper { return smType; } - static SoftwareModule fromRequest(final MgmtSoftwareModuleRequestBodyPost smsRest, - final SoftwareManagement softwareManagement) { - return softwareManagement.generateSoftwareModule( + static SoftwareModule fromRequest(final EntityFactory entityFactory, + final MgmtSoftwareModuleRequestBodyPost smsRest, final SoftwareManagement softwareManagement) { + return entityFactory.generateSoftwareModule( getSoftwareModuleTypeFromKeyString(smsRest.getType(), softwareManagement), smsRest.getName(), smsRest.getVersion(), smsRest.getDescription(), smsRest.getVendor()); } - static List fromRequestSwMetadata(final SoftwareManagement softwareManagement, + static List fromRequestSwMetadata(final EntityFactory entityFactory, final SoftwareModule sw, final List metadata) { final List mappedList = new ArrayList<>(metadata.size()); for (final MgmtMetadata metadataRest : metadata) { if (metadataRest.getKey() == null) { throw new IllegalArgumentException("the key of the metadata must be present"); } - mappedList.add(softwareManagement.generateSoftwareModuleMetadata(sw, metadataRest.getKey(), - metadataRest.getValue())); + mappedList.add( + entityFactory.generateSoftwareModuleMetadata(sw, metadataRest.getKey(), metadataRest.getValue())); } return mappedList; } - static List smFromRequest(final Iterable smsRest, - final SoftwareManagement softwareManagement) { + static List smFromRequest(final EntityFactory entityFactory, + final Iterable smsRest, final SoftwareManagement softwareManagement) { final List mappedList = new ArrayList<>(); for (final MgmtSoftwareModuleRequestBodyPost smRest : smsRest) { - mappedList.add(fromRequest(smRest, softwareManagement)); + mappedList.add(fromRequest(entityFactory, smRest, softwareManagement)); } return mappedList; } diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java index aeaffa013..b4f1e8adb 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java @@ -20,6 +20,7 @@ import org.eclipse.hawkbit.mgmt.json.model.softwaremodule.MgmtSoftwareModuleRequ import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.mgmt.rest.api.MgmtSoftwareModuleRestApi; import org.eclipse.hawkbit.repository.ArtifactManagement; +import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; @@ -57,6 +58,9 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi { @Autowired private SoftwareManagement softwareManagement; + @Autowired + private EntityFactory entityFactory; + @Override public ResponseEntity uploadArtifact(@PathVariable("softwareModuleId") final Long softwareModuleId, @RequestParam("file") final MultipartFile file, @@ -158,8 +162,8 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi { public ResponseEntity> createSoftwareModules( @RequestBody final List softwareModules) { LOG.debug("creating {} softwareModules", softwareModules.size()); - final Iterable createdSoftwareModules = softwareManagement - .createSoftwareModule(MgmtSoftwareModuleMapper.smFromRequest(softwareModules, softwareManagement)); + final Iterable createdSoftwareModules = softwareManagement.createSoftwareModule( + MgmtSoftwareModuleMapper.smFromRequest(entityFactory, softwareModules, softwareManagement)); LOG.debug("{} softwareModules created, return status {}", softwareModules.size(), HttpStatus.CREATED); return new ResponseEntity<>(MgmtSoftwareModuleMapper.toResponseSoftwareModules(createdSoftwareModules), @@ -237,7 +241,7 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi { @PathVariable("metadataKey") final String metadataKey, @RequestBody final MgmtMetadata metadata) { final SoftwareModule sw = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null); final SoftwareModuleMetadata updated = softwareManagement.updateSoftwareModuleMetadata( - softwareManagement.generateSoftwareModuleMetadata(sw, metadataKey, metadata.getValue())); + entityFactory.generateSoftwareModuleMetadata(sw, metadataKey, metadata.getValue())); return ResponseEntity.ok(MgmtSoftwareModuleMapper.toResponseSwMetadata(updated)); } @@ -256,7 +260,7 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi { final SoftwareModule sw = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null); final List created = softwareManagement.createSoftwareModuleMetadata( - MgmtSoftwareModuleMapper.fromRequestSwMetadata(softwareManagement, sw, metadataRest)); + MgmtSoftwareModuleMapper.fromRequestSwMetadata(entityFactory, sw, metadataRest)); return new ResponseEntity<>(MgmtSoftwareModuleMapper.toResponseSwMetadata(created), HttpStatus.CREATED); diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeMapper.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeMapper.java index f52ea7f2a..565af7eb8 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeMapper.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeMapper.java @@ -18,7 +18,7 @@ import java.util.List; import org.eclipse.hawkbit.mgmt.json.model.softwaremoduletype.MgmtSoftwareModuleType; import org.eclipse.hawkbit.mgmt.json.model.softwaremoduletype.MgmtSoftwareModuleTypeRequestBodyPost; import org.eclipse.hawkbit.mgmt.rest.api.MgmtSoftwareModuleTypeRestApi; -import org.eclipse.hawkbit.repository.SoftwareManagement; +import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; /** @@ -36,19 +36,19 @@ final class MgmtSoftwareModuleTypeMapper { } - static List smFromRequest(final SoftwareManagement softwareManagement, + static List smFromRequest(final EntityFactory entityFactory, final Iterable smTypesRest) { final List mappedList = new ArrayList<>(); for (final MgmtSoftwareModuleTypeRequestBodyPost smRest : smTypesRest) { - mappedList.add(fromRequest(softwareManagement, smRest)); + mappedList.add(fromRequest(entityFactory, smRest)); } return mappedList; } - static SoftwareModuleType fromRequest(final SoftwareManagement softwareManagement, + static SoftwareModuleType fromRequest(final EntityFactory entityFactory, final MgmtSoftwareModuleTypeRequestBodyPost smsRest) { - final SoftwareModuleType result = softwareManagement.generateSoftwareModuleType(); + final SoftwareModuleType result = entityFactory.generateSoftwareModuleType(); result.setName(smsRest.getName()); result.setKey(smsRest.getKey()); result.setDescription(smsRest.getDescription()); diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResource.java index bbb61571c..353cf16e5 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResource.java @@ -16,6 +16,7 @@ import org.eclipse.hawkbit.mgmt.json.model.softwaremoduletype.MgmtSoftwareModule import org.eclipse.hawkbit.mgmt.json.model.softwaremoduletype.MgmtSoftwareModuleTypeRequestBodyPut; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.mgmt.rest.api.MgmtSoftwareModuleTypeRestApi; +import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; @@ -44,6 +45,9 @@ public class MgmtSoftwareModuleTypeResource implements MgmtSoftwareModuleTypeRes @Autowired private SoftwareManagement softwareManagement; + @Autowired + private EntityFactory entityFactory; + @Override public ResponseEntity> getTypes( @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, @@ -110,7 +114,7 @@ public class MgmtSoftwareModuleTypeResource implements MgmtSoftwareModuleTypeRes @RequestBody final List softwareModuleTypes) { final List createdSoftwareModules = this.softwareManagement.createSoftwareModuleType( - MgmtSoftwareModuleTypeMapper.smFromRequest(softwareManagement, softwareModuleTypes)); + MgmtSoftwareModuleTypeMapper.smFromRequest(entityFactory, softwareModuleTypes)); return new ResponseEntity<>(MgmtSoftwareModuleTypeMapper.toTypesResponse(createdSoftwareModules), HttpStatus.CREATED); diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTagMapper.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTagMapper.java index 7ede69658..bac21c2a5 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTagMapper.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTagMapper.java @@ -18,7 +18,7 @@ import org.eclipse.hawkbit.mgmt.json.model.tag.MgmtTag; import org.eclipse.hawkbit.mgmt.json.model.tag.MgmtTagRequestBodyPut; import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetTagRestApi; import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetTagRestApi; -import org.eclipse.hawkbit.repository.TagManagement; +import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.Tag; import org.eclipse.hawkbit.repository.model.TargetTag; @@ -96,21 +96,21 @@ final class MgmtTagMapper { return response; } - static List mapTargeTagFromRequest(final TagManagement tagManagement, + static List mapTargeTagFromRequest(final EntityFactory entityFactory, final Iterable tags) { final List mappedList = new ArrayList<>(); for (final MgmtTagRequestBodyPut targetTagRest : tags) { - mappedList.add(tagManagement.generateTargetTag(targetTagRest.getName(), targetTagRest.getDescription(), + mappedList.add(entityFactory.generateTargetTag(targetTagRest.getName(), targetTagRest.getDescription(), targetTagRest.getColour())); } return mappedList; } - static List mapDistributionSetTagFromRequest(final TagManagement tagManagement, + static List mapDistributionSetTagFromRequest(final EntityFactory entityFactory, final Iterable tags) { final List mappedList = new ArrayList<>(); for (final MgmtTagRequestBodyPut targetTagRest : tags) { - mappedList.add(tagManagement.generateDistributionSetTag(targetTagRest.getName(), + mappedList.add(entityFactory.generateDistributionSetTag(targetTagRest.getName(), targetTagRest.getDescription(), targetTagRest.getColour())); } return mappedList; diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetMapper.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetMapper.java index b377e95f7..f00998d29 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetMapper.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetMapper.java @@ -25,7 +25,7 @@ import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTargetRequestBody; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetRestApi; import org.eclipse.hawkbit.repository.ActionFields; -import org.eclipse.hawkbit.repository.TargetManagement; +import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.ActionStatus; import org.eclipse.hawkbit.repository.model.PollStatus; @@ -169,17 +169,17 @@ public final class MgmtTargetMapper { return targetRest; } - static List fromRequest(final TargetManagement targetManagement, + static List fromRequest(final EntityFactory entityFactory, final Iterable targetsRest) { final List mappedList = new ArrayList<>(); for (final MgmtTargetRequestBody targetRest : targetsRest) { - mappedList.add(fromRequest(targetManagement, targetRest)); + mappedList.add(fromRequest(entityFactory, targetRest)); } return mappedList; } - static Target fromRequest(final TargetManagement targetManagement, final MgmtTargetRequestBody targetRest) { - final Target target = targetManagement.generateTarget(targetRest.getControllerId()); + static Target fromRequest(final EntityFactory entityFactory, final MgmtTargetRequestBody targetRest) { + final Target target = entityFactory.generateTarget(targetRest.getControllerId()); target.setDescription(targetRest.getDescription()); target.setName(targetRest.getName()); return target; diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResource.java index e02072238..cc7bbcde6 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResource.java @@ -28,6 +28,7 @@ import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetRestApi; import org.eclipse.hawkbit.repository.ActionStatusFields; import org.eclipse.hawkbit.repository.DeploymentManagement; +import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; @@ -63,6 +64,9 @@ public class MgmtTargetResource implements MgmtTargetRestApi { @Autowired private DeploymentManagement deploymentManagement; + @Autowired + private EntityFactory entityFactory; + @Override public ResponseEntity getTarget(@PathVariable("targetId") final String targetId) { final Target findTarget = findTargetWithExceptionIfNotFound(targetId); @@ -105,7 +109,7 @@ public class MgmtTargetResource implements MgmtTargetRestApi { public ResponseEntity> createTargets(@RequestBody final List targets) { LOG.debug("creating {} targets", targets.size()); final Iterable createdTargets = this.targetManagement - .createTargets(MgmtTargetMapper.fromRequest(targetManagement, targets)); + .createTargets(MgmtTargetMapper.fromRequest(entityFactory, targets)); LOG.debug("{} targets created, return status {}", targets.size(), HttpStatus.CREATED); return new ResponseEntity<>(MgmtTargetMapper.toResponse(createdTargets), HttpStatus.CREATED); } diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResource.java index 7d1ba3f7f..c765c18cd 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResource.java @@ -19,6 +19,7 @@ import org.eclipse.hawkbit.mgmt.json.model.tag.MgmtTargetTagAssigmentResult; import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTarget; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetTagRestApi; +import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.TargetManagement; @@ -54,6 +55,9 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi { @Autowired private TargetManagement targetManagement; + @Autowired + private EntityFactory entityFactory; + @Override public ResponseEntity> getTargetTags( @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, @@ -93,7 +97,7 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi { public ResponseEntity> createTargetTags(@RequestBody final List tags) { LOG.debug("creating {} target tags", tags.size()); final List createdTargetTags = this.tagManagement - .createTargetTags(MgmtTagMapper.mapTargeTagFromRequest(tagManagement, tags)); + .createTargetTags(MgmtTagMapper.mapTargeTagFromRequest(entityFactory, tags)); return new ResponseEntity<>(MgmtTagMapper.toResponse(createdTargetTags), HttpStatus.CREATED); } diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java index 700a2735c..b4887c40c 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java @@ -28,13 +28,13 @@ import java.util.Set; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; -import org.eclipse.hawkbit.repository.jpa.TestDataUtil; -import org.eclipse.hawkbit.repository.jpa.WithUser; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetMetadata; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.Target; +import org.eclipse.hawkbit.repository.util.TestdataFactory; +import org.eclipse.hawkbit.repository.util.WithUser; import org.eclipse.hawkbit.rest.AbstractRestIntegrationTest; import org.eclipse.hawkbit.rest.util.JsonBuilder; import org.eclipse.hawkbit.rest.util.MockMvcResultPrinter; @@ -60,8 +60,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest @Description("This test verifies the call of all Software Modules that are assiged to a Distribution Set through the RESTful API.") public void getSoftwaremodules() throws Exception { // Create DistributionSet with three software modules - final DistributionSet set = TestDataUtil.generateDistributionSet("SMTest", softwareManagement, - distributionSetManagement); + final DistributionSet set = testdataFactory.createDistributionSet("SMTest"); mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + set.getId() + "/assignedSM")) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(jsonPath("$.size", equalTo(set.getModules().size()))); @@ -72,10 +71,9 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest public void deleteFailureWhenDistributionSetInUse() throws Exception { // create DisSet - final DistributionSet disSet = TestDataUtil.generateDistributionSetWithNoSoftwareModules("Eris", "560a", - distributionSetManagement); - final List smIDs = new ArrayList(); - SoftwareModule sm = softwareManagement.generateSoftwareModule(osType, "Dysnomia ", "15,772", null, null); + final DistributionSet disSet = testdataFactory.createDistributionSetWithNoSoftwareModules("Eris", "560a"); + final List smIDs = new ArrayList<>(); + SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "Dysnomia ", "15,772", null, null); sm = softwareManagement.createSoftwareModule(sm); smIDs.add(sm.getId()); final JSONArray smList = new JSONArray(); @@ -91,7 +89,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest final String[] knownTargetIds = new String[] { "1", "2" }; final JSONArray list = new JSONArray(); for (final String targetId : knownTargetIds) { - targetManagement.createTarget(targetManagement.generateTarget(targetId)); + targetManagement.createTarget(entityFactory.generateTarget(targetId)); list.put(new JSONObject().put("id", Long.valueOf(targetId))); } deploymentManagement.assignDistributionSet(disSet.getId(), knownTargetIds[0]); @@ -116,10 +114,9 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest public void assignmentFailureWhenAssigningToUsedDistributionSet() throws Exception { // create DisSet - final DistributionSet disSet = TestDataUtil.generateDistributionSetWithNoSoftwareModules("Mars", "686,980", - distributionSetManagement); + final DistributionSet disSet = testdataFactory.createDistributionSetWithNoSoftwareModules("Mars", "686,980"); final List smIDs = new ArrayList<>(); - SoftwareModule sm = softwareManagement.generateSoftwareModule(osType, "Phobos", "0,3189", null, null); + SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "Phobos", "0,3189", null, null); sm = softwareManagement.createSoftwareModule(sm); smIDs.add(sm.getId()); final JSONArray smList = new JSONArray(); @@ -135,7 +132,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest final String[] knownTargetIds = new String[] { "1", "2" }; final JSONArray list = new JSONArray(); for (final String targetId : knownTargetIds) { - targetManagement.createTarget(targetManagement.generateTarget(targetId)); + targetManagement.createTarget(entityFactory.generateTarget(targetId)); list.put(new JSONObject().put("id", Long.valueOf(targetId))); } // assign DisSet to target and test assignment @@ -150,7 +147,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest // Create another SM and post assignment final List smID2s = new ArrayList<>(); - SoftwareModule sm2 = softwareManagement.generateSoftwareModule(appType, "Deimos", "1,262", null, null); + SoftwareModule sm2 = entityFactory.generateSoftwareModule(appType, "Deimos", "1,262", null, null); sm2 = softwareManagement.createSoftwareModule(sm2); smID2s.add(sm2.getId()); final JSONArray smList2 = new JSONArray(); @@ -169,21 +166,20 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest public void assignSoftwaremoduleToDistributionSet() throws Exception { // create DisSet - final DistributionSet disSet = TestDataUtil.generateDistributionSetWithNoSoftwareModules("Jupiter", "398,88", - distributionSetManagement); + final DistributionSet disSet = testdataFactory.createDistributionSetWithNoSoftwareModules("Jupiter", "398,88"); // Test if size is 0 mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM")) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(jsonPath("$.size", equalTo(disSet.getModules().size()))); // create Software Modules - final List smIDs = new ArrayList(); - SoftwareModule sm = softwareManagement.generateSoftwareModule(osType, "Europa", "3,551", null, null); + final List smIDs = new ArrayList<>(); + SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "Europa", "3,551", null, null); sm = softwareManagement.createSoftwareModule(sm); smIDs.add(sm.getId()); - SoftwareModule sm2 = softwareManagement.generateSoftwareModule(appType, "Ganymed", "7,155", null, null); + SoftwareModule sm2 = entityFactory.generateSoftwareModule(appType, "Ganymed", "7,155", null, null); sm2 = softwareManagement.createSoftwareModule(sm2); smIDs.add(sm2.getId()); - SoftwareModule sm3 = softwareManagement.generateSoftwareModule(runtimeType, "Kallisto", "16,689", null, null); + SoftwareModule sm3 = entityFactory.generateSoftwareModule(runtimeType, "Kallisto", "16,689", null, null); sm3 = softwareManagement.createSoftwareModule(sm3); smIDs.add(sm3.getId()); final JSONArray list = new JSONArray(); @@ -205,8 +201,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest public void unassignSoftwaremoduleFromDistributionSet() throws Exception { // Create DistributionSet with three software modules - final DistributionSet set = TestDataUtil.generateDistributionSet("Venus", softwareManagement, - distributionSetManagement); + final DistributionSet set = testdataFactory.createDistributionSet("Venus"); int amountOfSM = set.getModules().size(); mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + set.getId() + "/assignedSM")) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) @@ -233,7 +228,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest final String[] knownTargetIds = new String[] { "1", "2", "3", "4", "5" }; final JSONArray list = new JSONArray(); for (final String targetId : knownTargetIds) { - targetManagement.createTarget(targetManagement.generateTarget(targetId)); + targetManagement.createTarget(entityFactory.generateTarget(targetId)); list.put(new JSONObject().put("id", Long.valueOf(targetId))); } // assign already one target to DS @@ -257,7 +252,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest final String knownTargetId = "knownTargetId1"; final Set createDistributionSetsAlphabetical = createDistributionSetsAlphabetical(1); final DistributionSet createdDs = createDistributionSetsAlphabetical.iterator().next(); - targetManagement.createTarget(targetManagement.generateTarget(knownTargetId)); + targetManagement.createTarget(entityFactory.generateTarget(knownTargetId)); deploymentManagement.assignDistributionSet(createdDs.getId(), knownTargetId); mvc.perform(get( @@ -284,15 +279,15 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest final String knownTargetId = "knownTargetId1"; final Set createDistributionSetsAlphabetical = createDistributionSetsAlphabetical(1); final DistributionSet createdDs = createDistributionSetsAlphabetical.iterator().next(); - final Target createTarget = targetManagement.createTarget(targetManagement.generateTarget(knownTargetId)); + final Target createTarget = targetManagement.createTarget(entityFactory.generateTarget(knownTargetId)); // create some dummy targets which are not assigned or installed - targetManagement.createTarget(targetManagement.generateTarget("dummy1")); - targetManagement.createTarget(targetManagement.generateTarget("dummy2")); + targetManagement.createTarget(entityFactory.generateTarget("dummy1")); + targetManagement.createTarget(entityFactory.generateTarget("dummy2")); // assign knownTargetId to distribution set deploymentManagement.assignDistributionSet(createdDs.getId(), knownTargetId); // make it in install state - TestDataUtil.sendUpdateActionStatusToTargets(controllerManagament, targetManagement, actionRepository, - createdDs, Lists.newArrayList(createTarget), Status.FINISHED, "some message"); + testdataFactory.sendUpdateActionStatusToTargets(Lists.newArrayList(createTarget), Status.FINISHED, + "some message"); mvc.perform(get( MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() + "/installedTargets")) @@ -350,8 +345,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true)) .hasSize(0); - DistributionSet set = TestDataUtil.generateDistributionSet("one", softwareManagement, - distributionSetManagement); + DistributionSet set = testdataFactory.createDistributionSet("one"); set.setRequiredMigrationStep(set.isRequiredMigrationStep()); set = distributionSetManagement.updateDistributionSet(set); @@ -393,8 +387,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest @WithUser(principal = "uploadTester", allSpPermissions = true) @Description("Ensures that single DS requested by ID is listed with expected payload.") public void getDistributionSet() throws Exception { - final DistributionSet set = TestDataUtil.createTestDistributionSet(softwareManagement, - distributionSetManagement); + final DistributionSet set = testdataFactory.createTestDistributionSet(); // perform request mvc.perform(get("/rest/v1/distributionsets/{dsId}", set.getId()).accept(MediaType.APPLICATION_JSON)) @@ -429,16 +422,16 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true)) .hasSize(0); - final SoftwareModule ah = softwareManagement.createSoftwareModule( - softwareManagement.generateSoftwareModule(appType, "agent-hub", "1.0.1", null, "")); - final SoftwareModule jvm = softwareManagement.createSoftwareModule( - softwareManagement.generateSoftwareModule(runtimeType, "oracle-jre", "1.7.2", null, "")); - final SoftwareModule os = softwareManagement - .createSoftwareModule(softwareManagement.generateSoftwareModule(osType, "poky", "3.0.2", null, "")); + final SoftwareModule ah = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_APP); + final SoftwareModule jvm = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_RT); + final SoftwareModule os = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_OS); - DistributionSet one = TestDataUtil.buildDistributionSet("one", "one", standardDsType, os, jvm, ah); - DistributionSet two = TestDataUtil.buildDistributionSet("two", "two", standardDsType, os, jvm, ah); - DistributionSet three = TestDataUtil.buildDistributionSet("three", "three", standardDsType, os, jvm, ah); + DistributionSet one = testdataFactory.generateDistributionSet("one", "one", standardDsType, + Lists.newArrayList(os, jvm, ah)); + DistributionSet two = testdataFactory.generateDistributionSet("two", "two", standardDsType, + Lists.newArrayList(os, jvm, ah)); + DistributionSet three = testdataFactory.generateDistributionSet("three", "three", standardDsType, + Lists.newArrayList(os, jvm, ah)); three.setRequiredMigrationStep(true); final List sets = new ArrayList<>(); @@ -547,8 +540,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true)) .hasSize(0); - final DistributionSet set = TestDataUtil.generateDistributionSet("one", softwareManagement, - distributionSetManagement); + final DistributionSet set = testdataFactory.createDistributionSet("one"); assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true)) .hasSize(1); @@ -560,7 +552,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest // check repository content assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true)) .isEmpty(); - assertThat(distributionSetRepository.findAll()).isEmpty(); + assertThat(distributionSetManagement.countDistributionSetsAll()).isEqualTo(0); } @Test @@ -570,9 +562,8 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true)) .hasSize(0); - final DistributionSet set = TestDataUtil.generateDistributionSet("one", softwareManagement, - distributionSetManagement); - targetManagement.createTarget(targetManagement.generateTarget("test")); + final DistributionSet set = testdataFactory.createDistributionSet("one"); + targetManagement.createTarget(entityFactory.generateTarget("test")); deploymentManagement.assignDistributionSet(set.getId(), "test"); assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true)) @@ -597,13 +588,12 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true)) .hasSize(0); - final DistributionSet set = TestDataUtil.generateDistributionSet("one", softwareManagement, - distributionSetManagement); + final DistributionSet set = testdataFactory.createDistributionSet("one"); assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true)) .hasSize(1); - final DistributionSet update = distributionSetManagement.generateDistributionSet(); + final DistributionSet update = entityFactory.generateDistributionSet(); update.setVersion("anotherVersion"); update.setName(null); update.setType(standardDsType); @@ -621,8 +611,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest @Test @Description("Ensures that the server reacts properly to invalid requests (URI, Media Type, Methods) with correct reponses.") public void invalidRequestsOnDistributionSetsResource() throws Exception { - final DistributionSet set = TestDataUtil.generateDistributionSet("one", softwareManagement, - distributionSetManagement); + final DistributionSet set = testdataFactory.createDistributionSet("one"); final List sets = new ArrayList<>(); sets.add(set); @@ -663,8 +652,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest @Test @Description("Ensures that the metadata creation through API is reflected by the repository.") public void createMetadata() throws Exception { - final DistributionSet testDS = TestDataUtil.generateDistributionSet("one", softwareManagement, - distributionSetManagement); + final DistributionSet testDS = testdataFactory.createDistributionSet("one"); final String knownKey1 = "knownKey1"; final String knownKey2 = "knownKey2"; @@ -699,10 +687,9 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest final String knownValue = "knownValue"; final String updateValue = "valueForUpdate"; - final DistributionSet testDS = TestDataUtil.generateDistributionSet("one", softwareManagement, - distributionSetManagement); + final DistributionSet testDS = testdataFactory.createDistributionSet("one"); distributionSetManagement.createDistributionSetMetadata( - distributionSetManagement.generateDistributionSetMetadata(testDS, knownKey, knownValue)); + entityFactory.generateDistributionSetMetadata(testDS, knownKey, knownValue)); final JSONObject jsonObject = new JSONObject().put("key", knownKey).put("value", updateValue); @@ -724,10 +711,9 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest final String knownKey = "knownKey"; final String knownValue = "knownValue"; - final DistributionSet testDS = TestDataUtil.generateDistributionSet("one", softwareManagement, - distributionSetManagement); + final DistributionSet testDS = testdataFactory.createDistributionSet("one"); distributionSetManagement.createDistributionSetMetadata( - distributionSetManagement.generateDistributionSetMetadata(testDS, knownKey, knownValue)); + entityFactory.generateDistributionSetMetadata(testDS, knownKey, knownValue)); mvc.perform(delete("/rest/v1/distributionsets/{dsId}/metadata/{key}", testDS.getId(), knownKey)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); @@ -746,10 +732,9 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest // prepare and create metadata final String knownKey = "knownKey"; final String knownValue = "knownValue"; - final DistributionSet testDS = TestDataUtil.generateDistributionSet("one", softwareManagement, - distributionSetManagement); + final DistributionSet testDS = testdataFactory.createDistributionSet("one"); distributionSetManagement.createDistributionSetMetadata( - distributionSetManagement.generateDistributionSetMetadata(testDS, knownKey, knownValue)); + entityFactory.generateDistributionSetMetadata(testDS, knownKey, knownValue)); mvc.perform(get("/rest/v1/distributionsets/{dsId}/metadata/{key}", testDS.getId(), knownKey)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) @@ -765,12 +750,11 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest final String offsetParam = "0"; final String knownKeyPrefix = "knownKey"; final String knownValuePrefix = "knownValue"; - final DistributionSet testDS = TestDataUtil.generateDistributionSet("one", softwareManagement, - distributionSetManagement); + final DistributionSet testDS = testdataFactory.createDistributionSet("one"); for (int index = 0; index < totalMetadata; index++) { - distributionSetManagement.createDistributionSetMetadata(distributionSetManagement - .generateDistributionSetMetadata(distributionSetManagement.findDistributionSetById(testDS.getId()), - knownKeyPrefix + index, knownValuePrefix + index)); + distributionSetManagement.createDistributionSetMetadata(entityFactory.generateDistributionSetMetadata( + distributionSetManagement.findDistributionSetById(testDS.getId()), knownKeyPrefix + index, + knownValuePrefix + index)); } mvc.perform(get("/rest/v1/distributionsets/{dsId}/metadata?offset=" + offsetParam + "&limit=" + limitParam, @@ -786,9 +770,9 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest public void searchDistributionSetRsql() throws Exception { final String dsSuffix = "test"; final int amount = 10; - TestDataUtil.generateDistributionSets(dsSuffix, amount, softwareManagement, distributionSetManagement); - TestDataUtil.generateDistributionSet("DS1test", softwareManagement, distributionSetManagement); - TestDataUtil.generateDistributionSet("DS2test", softwareManagement, distributionSetManagement); + testdataFactory.createDistributionSets(dsSuffix, amount); + testdataFactory.createDistributionSet("DS1test"); + testdataFactory.createDistributionSet("DS2test"); final String rsqlFindLikeDs1OrDs2 = "name==DS1test,name==DS2test"; @@ -803,9 +787,9 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest @Description("Ensures that a DS search with complete==true parameter returns only DS that are actually completely filled with mandatory modules.") public void filterDistributionSetComplete() throws Exception { final int amount = 10; - TestDataUtil.generateDistributionSets(amount, softwareManagement, distributionSetManagement); - distributionSetManagement.createDistributionSet(distributionSetManagement.generateDistributionSet("incomplete", - "2", "incomplete", distributionSetManagement.findDistributionSetTypeByKey("ecl_os"), null)); + testdataFactory.createDistributionSets(amount); + distributionSetManagement.createDistributionSet(entityFactory.generateDistributionSet("incomplete", "2", + "incomplete", distributionSetManagement.findDistributionSetTypeByKey("ecl_os"), null)); final String rsqlFindLikeDs1OrDs2 = "complete==" + Boolean.TRUE; @@ -824,7 +808,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest final String[] knownTargetIds = new String[] { "1", "2", "3", "4", "5" }; final JSONArray list = new JSONArray(); for (final String targetId : knownTargetIds) { - targetManagement.createTarget(targetManagement.generateTarget(targetId)); + targetManagement.createTarget(entityFactory.generateTarget(targetId)); list.put(new JSONObject().put("id", Long.valueOf(targetId))); } @@ -846,12 +830,11 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest final int totalMetadata = 10; final String knownKeyPrefix = "knownKey"; final String knownValuePrefix = "knownValue"; - final DistributionSet testDS = TestDataUtil.generateDistributionSet("one", softwareManagement, - distributionSetManagement); + final DistributionSet testDS = testdataFactory.createDistributionSet("one"); for (int index = 0; index < totalMetadata; index++) { - distributionSetManagement.createDistributionSetMetadata(distributionSetManagement - .generateDistributionSetMetadata(distributionSetManagement.findDistributionSetById(testDS.getId()), - knownKeyPrefix + index, knownValuePrefix + index)); + distributionSetManagement.createDistributionSetMetadata(entityFactory.generateDistributionSetMetadata( + distributionSetManagement.findDistributionSetById(testDS.getId()), knownKeyPrefix + index, + knownValuePrefix + index)); } final String rsqlSearchValue1 = "value==knownValue1"; @@ -867,7 +850,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest final Set created = new HashSet<>(); for (int index = 0; index < amount; index++) { final String str = String.valueOf(character); - created.add(TestDataUtil.generateDistributionSet(str, softwareManagement, distributionSetManagement)); + created.add(testdataFactory.createDistributionSet(str)); character++; } return created; diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResourceTest.java index d4596bde7..ad6be0854 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResourceTest.java @@ -24,10 +24,10 @@ import java.util.ArrayList; import java.util.List; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; -import org.eclipse.hawkbit.repository.jpa.WithUser; import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; +import org.eclipse.hawkbit.repository.util.WithUser; import org.eclipse.hawkbit.rest.AbstractRestIntegrationTest; import org.eclipse.hawkbit.rest.util.JsonBuilder; import org.eclipse.hawkbit.rest.util.MockMvcResultPrinter; @@ -58,10 +58,12 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration public void getDistributionSetTypes() throws Exception { DistributionSetType testType = distributionSetManagement.createDistributionSetType( - distributionSetManagement.generateDistributionSetType("test123", "TestName123", "Desc123")); + entityFactory.generateDistributionSetType("test123", "TestName123", "Desc123")); testType.setDescription("Desc1234"); testType = distributionSetManagement.updateDistributionSetType(testType); + // 4 types overall (2 hawkbit tenant default, 1 test default and 1 + // generated in this test) mvc.perform(get("/rest/v1/distributionsettypes").accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) @@ -96,7 +98,7 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration public void getDistributionSetTypesSortedByKey() throws Exception { DistributionSetType testType = distributionSetManagement.createDistributionSetType( - distributionSetManagement.generateDistributionSetType("zzzzz", "TestName123", "Desc123")); + entityFactory.generateDistributionSetType("zzzzz", "TestName123", "Desc123")); testType.setDescription("Desc1234"); testType = distributionSetManagement.updateDistributionSetType(testType); @@ -111,7 +113,8 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration .andExpect(jsonPath("$content.[0].createdAt", equalTo(testType.getCreatedAt()))) .andExpect(jsonPath("$content.[0].lastModifiedBy", equalTo("uploadTester"))) .andExpect(jsonPath("$content.[0].lastModifiedAt", equalTo(testType.getLastModifiedAt()))) - .andExpect(jsonPath("$content.[0].key", equalTo("zzzzz"))).andExpect(jsonPath("$total", equalTo(4))); + .andExpect(jsonPath("$content.[0].key", equalTo("zzzzz"))) + .andExpect(jsonPath("$total", equalTo(DEFAULT_DS_TYPES + 1))); // ascending mvc.perform(get("/rest/v1/distributionsettypes").accept(MediaType.APPLICATION_JSON) @@ -124,7 +127,8 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration .andExpect(jsonPath("$content.[3].createdAt", equalTo(testType.getCreatedAt()))) .andExpect(jsonPath("$content.[3].lastModifiedBy", equalTo("uploadTester"))) .andExpect(jsonPath("$content.[3].lastModifiedAt", equalTo(testType.getLastModifiedAt()))) - .andExpect(jsonPath("$content.[3].key", equalTo("zzzzz"))).andExpect(jsonPath("$total", equalTo(4))); + .andExpect(jsonPath("$content.[3].key", equalTo("zzzzz"))) + .andExpect(jsonPath("$total", equalTo(DEFAULT_DS_TYPES + 1))); } @Test @@ -132,14 +136,14 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration @Description("Checks the correct behaviour of /rest/v1/distributionsettypes POST requests.") public void createDistributionSetTypes() throws JSONException, Exception { - assertThat(distributionSetManagement.countDistributionSetTypesAll()).isEqualTo(3); + assertThat(distributionSetManagement.countDistributionSetTypesAll()).isEqualTo(DEFAULT_DS_TYPES); final List types = new ArrayList<>(); - types.add(distributionSetManagement.generateDistributionSetType("test1", "TestName1", "Desc1") + types.add(entityFactory.generateDistributionSetType("test1", "TestName1", "Desc1") .addMandatoryModuleType(osType).addOptionalModuleType(runtimeType)); - types.add(distributionSetManagement.generateDistributionSetType("test2", "TestName2", "Desc2") + types.add(entityFactory.generateDistributionSetType("test2", "TestName2", "Desc2") .addOptionalModuleType(osType).addOptionalModuleType(runtimeType).addOptionalModuleType(appType)); - types.add(distributionSetManagement.generateDistributionSetType("test3", "TestName3", "Desc3") + types.add(entityFactory.generateDistributionSetType("test3", "TestName3", "Desc3") .addMandatoryModuleType(osType).addMandatoryModuleType(runtimeType)); final MvcResult mvcResult = mvc @@ -205,7 +209,7 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration @Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID}/mandatorymoduletypes POST requests.") public void addMandatoryModuleToDistributionSetType() throws JSONException, Exception { DistributionSetType testType = distributionSetManagement.createDistributionSetType( - distributionSetManagement.generateDistributionSetType("test123", "TestName123", "Desc123")); + entityFactory.generateDistributionSetType("test123", "TestName123", "Desc123")); assertThat(testType.getOptLockRevision()).isEqualTo(1); mvc.perform(post("/rest/v1/distributionsettypes/{dstID}/mandatorymoduletypes", testType.getId()) @@ -224,7 +228,7 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration @Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID}/optionalmoduletypes POST requests.") public void addOptionalModuleToDistributionSetType() throws JSONException, Exception { DistributionSetType testType = distributionSetManagement.createDistributionSetType( - distributionSetManagement.generateDistributionSetType("test123", "TestName123", "Desc123")); + entityFactory.generateDistributionSetType("test123", "TestName123", "Desc123")); assertThat(testType.getOptLockRevision()).isEqualTo(1); mvc.perform(post("/rest/v1/distributionsettypes/{dstID}/optionalmoduletypes", testType.getId()) @@ -244,7 +248,7 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration @Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID}/mandatorymoduletypes GET requests.") public void getMandatoryModulesOfDistributionSetType() throws JSONException, Exception { final DistributionSetType testType = distributionSetManagement.createDistributionSetType( - distributionSetManagement.generateDistributionSetType("test123", "TestName123", "Desc123") + entityFactory.generateDistributionSetType("test123", "TestName123", "Desc123") .addMandatoryModuleType(osType).addOptionalModuleType(appType)); assertThat(testType.getOptLockRevision()).isEqualTo(1); assertThat(testType.getOptionalModuleTypes()).containsExactly(appType); @@ -263,7 +267,7 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration @Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID}/optionalmoduletypes GET requests.") public void getOptionalModulesOfDistributionSetType() throws JSONException, Exception { final DistributionSetType testType = distributionSetManagement.createDistributionSetType( - distributionSetManagement.generateDistributionSetType("test123", "TestName123", "Desc123") + entityFactory.generateDistributionSetType("test123", "TestName123", "Desc123") .addMandatoryModuleType(osType).addOptionalModuleType(appType)); assertThat(testType.getOptLockRevision()).isEqualTo(1); assertThat(testType.getOptionalModuleTypes()).containsExactly(appType); @@ -274,7 +278,7 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("[0].name", equalTo(appType.getName()))) .andExpect(jsonPath("[0].description", equalTo(appType.getDescription()))) - .andExpect(jsonPath("[0].maxAssignments", equalTo(1))) + .andExpect(jsonPath("[0].maxAssignments", equalTo(Integer.MAX_VALUE))) .andExpect(jsonPath("[0].key", equalTo("application"))); } @@ -283,7 +287,7 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration @Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID}/mandatorymoduletypes/{ID} GET requests.") public void getMandatoryModuleOfDistributionSetType() throws JSONException, Exception { final DistributionSetType testType = distributionSetManagement.createDistributionSetType( - distributionSetManagement.generateDistributionSetType("test123", "TestName123", "Desc123") + entityFactory.generateDistributionSetType("test123", "TestName123", "Desc123") .addMandatoryModuleType(osType).addOptionalModuleType(appType)); assertThat(testType.getOptLockRevision()).isEqualTo(1); assertThat(testType.getOptionalModuleTypes()).containsExactly(appType); @@ -305,7 +309,7 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration @Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID}/optionalmoduletypes/{ID} GET requests.") public void getOptionalModuleOfDistributionSetType() throws JSONException, Exception { final DistributionSetType testType = distributionSetManagement.createDistributionSetType( - distributionSetManagement.generateDistributionSetType("test123", "TestName123", "Desc123") + entityFactory.generateDistributionSetType("test123", "TestName123", "Desc123") .addMandatoryModuleType(osType).addOptionalModuleType(appType)); assertThat(testType.getOptLockRevision()).isEqualTo(1); assertThat(testType.getOptionalModuleTypes()).containsExactly(appType); @@ -327,7 +331,7 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration @Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID}/mandatorymoduletypes/{ID} DELETE requests.") public void removeMandatoryModuleToDistributionSetType() throws JSONException, Exception { DistributionSetType testType = distributionSetManagement.createDistributionSetType( - distributionSetManagement.generateDistributionSetType("test123", "TestName123", "Desc123") + entityFactory.generateDistributionSetType("test123", "TestName123", "Desc123") .addMandatoryModuleType(osType).addOptionalModuleType(appType)); assertThat(testType.getOptLockRevision()).isEqualTo(1); assertThat(testType.getOptionalModuleTypes()).containsExactly(appType); @@ -349,7 +353,7 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration @Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID}/optionalmoduletypes/{ID} DELETE requests.") public void removeOptionalModuleToDistributionSetType() throws JSONException, Exception { DistributionSetType testType = distributionSetManagement.createDistributionSetType( - distributionSetManagement.generateDistributionSetType("test123", "TestName123", "Desc123") + entityFactory.generateDistributionSetType("test123", "TestName123", "Desc123") .addMandatoryModuleType(osType).addOptionalModuleType(appType)); assertThat(testType.getOptLockRevision()).isEqualTo(1); assertThat(testType.getOptionalModuleTypes()).containsExactly(appType); @@ -372,7 +376,7 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration public void getDistributionSetType() throws Exception { DistributionSetType testType = distributionSetManagement.createDistributionSetType( - distributionSetManagement.generateDistributionSetType("test123", "TestName123", "Desc123")); + entityFactory.generateDistributionSetType("test123", "TestName123", "Desc123")); testType.setDescription("Desc1234"); testType = distributionSetManagement.updateDistributionSetType(testType); @@ -391,14 +395,14 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration @Description("Checks the correct behaviour of /rest/v1/DistributionSetTypes/{ID} DELETE requests (hard delete scenario).") public void deleteDistributionSetTypeUnused() throws Exception { final DistributionSetType testType = distributionSetManagement.createDistributionSetType( - distributionSetManagement.generateDistributionSetType("test123", "TestName123", "Desc123")); + entityFactory.generateDistributionSetType("test123", "TestName123", "Desc123")); - assertThat(distributionSetManagement.countDistributionSetTypesAll()).isEqualTo(4); + assertThat(distributionSetManagement.countDistributionSetTypesAll()).isEqualTo(DEFAULT_DS_TYPES + 1); mvc.perform(delete("/rest/v1/distributionsettypes/{dsId}", testType.getId())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); - assertThat(distributionSetManagement.countDistributionSetTypesAll()).isEqualTo(3); + assertThat(distributionSetManagement.countDistributionSetTypesAll()).isEqualTo(DEFAULT_DS_TYPES); } @Test @@ -406,25 +410,25 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration @Description("Checks the correct behaviour of /rest/v1/DistributionSetTypes/{ID} DELETE requests (soft delete scenario).") public void deleteDistributionSetTypeUsed() throws Exception { final DistributionSetType testType = distributionSetManagement.createDistributionSetType( - distributionSetManagement.generateDistributionSetType("test123", "TestName123", "Desc123")); + entityFactory.generateDistributionSetType("test123", "TestName123", "Desc123")); distributionSetManagement.createDistributionSet( - distributionSetManagement.generateDistributionSet("sdfsd", "dsfsdf", "sdfsdf", testType, null)); + entityFactory.generateDistributionSet("sdfsd", "dsfsdf", "sdfsdf", testType, null)); - assertThat(distributionSetManagement.countDistributionSetTypesAll()).isEqualTo(4); - assertThat(distributionSetTypeRepository.count()).isEqualTo(4); + assertThat(distributionSetManagement.countDistributionSetTypesAll()).isEqualTo(DEFAULT_DS_TYPES + 1); + assertThat(distributionSetManagement.countDistributionSetsAll()).isEqualTo(1); mvc.perform(delete("/rest/v1/distributionsettypes/{smId}", testType.getId())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); - assertThat(distributionSetTypeRepository.count()).isEqualTo(4); - assertThat(distributionSetManagement.countDistributionSetTypesAll()).isEqualTo(3); + assertThat(distributionSetManagement.countDistributionSetsAll()).isEqualTo(1); + assertThat(distributionSetManagement.countDistributionSetTypesAll()).isEqualTo(DEFAULT_DS_TYPES); } @Test @Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID} PUT requests.") public void updateDistributionSetTypeOnlyDescriptionAndNameUntouched() throws Exception { final DistributionSetType testType = distributionSetManagement.createDistributionSetType( - distributionSetManagement.generateDistributionSetType("test123", "TestName123", "Desc123")); + entityFactory.generateDistributionSetType("test123", "TestName123", "Desc123")); final String body = new JSONObject().put("id", testType.getId()).put("description", "foobardesc") .put("name", "nameShouldNotBeChanged").toString(); @@ -439,6 +443,8 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration @Test @Description("Checks the correct behaviour of /rest/v1/distributionsettypes GET requests with paging.") public void getDistributionSetTypesWithoutAddtionalRequestParameters() throws Exception { + + // 3 types overall (2 hawkbit tenant default, 1 test default final int types = 3; mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_REQUEST_MAPPING)).andDo(MockMvcResultPrinter.print()) .andExpect(status().isOk()) @@ -450,7 +456,8 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration @Test @Description("Checks the correct behaviour of /rest/v1/distributionsettypes GET requests with paging.") public void getDistributionSetTypesWithPagingLimitRequestParameter() throws Exception { - final int types = 3; + + final int types = DEFAULT_DS_TYPES; final int limitSize = 1; mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_REQUEST_MAPPING) .param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, String.valueOf(limitSize))) @@ -463,7 +470,8 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration @Test @Description("Checks the correct behaviour of /rest/v1/distributionsettypes GET requests with paging.") public void getDistributionSetTypesWithPagingLimitAndOffsetRequestParameter() throws Exception { - final int types = 3; + + final int types = DEFAULT_DS_TYPES; final int offsetParam = 2; final int expectedSize = types - offsetParam; mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_REQUEST_MAPPING) @@ -479,10 +487,10 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration @Description("Ensures that the server is behaving as expected on invalid requests (wrong media type, wrong ID etc.).") public void invalidRequestsOnDistributionSetTypesResource() throws Exception { final DistributionSetType testType = distributionSetManagement.createDistributionSetType( - distributionSetManagement.generateDistributionSetType("test123", "TestName123", "Desc123")); + entityFactory.generateDistributionSetType("test123", "TestName123", "Desc123")); final SoftwareModuleType testSmType = softwareManagement.createSoftwareModuleType( - softwareManagement.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5)); + entityFactory.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5)); final List types = new ArrayList<>(); types.add(testType); @@ -525,10 +533,10 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration // Modules types at creation time invalid - final DistributionSetType testNewType = distributionSetManagement.generateDistributionSetType("test123", + final DistributionSetType testNewType = entityFactory.generateDistributionSetType("test123", "TestName123", "Desc123"); testNewType.addMandatoryModuleType( - softwareManagement.generateSoftwareModuleType("foo", "bar", "test", Integer.MAX_VALUE)); + entityFactory.generateSoftwareModuleType("foo", "bar", "test", Integer.MAX_VALUE)); mvc.perform(post("/rest/v1/distributionsettypes") .content(JsonBuilder.distributionSetTypes(Lists.newArrayList(testNewType))) @@ -562,9 +570,9 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration @Description("Search erquest of software module types.") public void searchDistributionSetTypeRsql() throws Exception { final DistributionSetType testType = distributionSetManagement.createDistributionSetType( - distributionSetManagement.generateDistributionSetType("test123", "TestName123", "Desc123")); + entityFactory.generateDistributionSetType("test123", "TestName123", "Desc123")); final DistributionSetType testType2 = distributionSetManagement.createDistributionSetType( - distributionSetManagement.generateDistributionSetType("test1234", "TestName1234", "Desc123")); + entityFactory.generateDistributionSetType("test1234", "TestName1234", "Desc123")); final String rsqlFindLikeDs1OrDs2 = "name==TestName123,name==TestName1234"; @@ -578,7 +586,7 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration char character = 'a'; for (int index = 0; index < amount; index++) { final String str = String.valueOf(character); - final SoftwareModule softwareModule = softwareManagement.generateSoftwareModule(osType, str, str, str, str); + final SoftwareModule softwareModule = entityFactory.generateSoftwareModule(osType, str, str, str, str); softwareManagement.createSoftwareModule(softwareModule); character++; diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDownloadResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDownloadResourceTest.java index fcdbfa918..16cc82e75 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDownloadResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDownloadResourceTest.java @@ -15,7 +15,6 @@ import org.eclipse.hawkbit.cache.CacheConstants; import org.eclipse.hawkbit.cache.DownloadArtifactCache; import org.eclipse.hawkbit.cache.DownloadType; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; -import org.eclipse.hawkbit.repository.jpa.TestDataUtil; import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.SoftwareModule; @@ -46,11 +45,9 @@ public class MgmtDownloadResourceTest extends AbstractRestIntegrationTestWithMon @Before public void setupCache() { - final DistributionSet distributionSet = TestDataUtil.generateDistributionSet("Test", softwareManagement, - distributionSetManagement); + final DistributionSet distributionSet = testdataFactory.createDistributionSet("Test"); final SoftwareModule softwareModule = distributionSet.getModules().stream().findFirst().get(); - final Artifact artifact = TestDataUtil.generateArtifacts(artifactManagement, softwareModule.getId()).stream() - .findFirst().get(); + final Artifact artifact = testdataFactory.createLocalArtifacts(softwareModule.getId()).stream().findFirst().get(); downloadIdCache.put(downloadIdSha1, new DownloadArtifactCache(DownloadType.BY_SHA1, artifact.getSha1Hash())); } diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResourceTest.java index fd171b7da..ff49542ce 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResourceTest.java @@ -24,13 +24,12 @@ import java.util.concurrent.Callable; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.repository.RolloutGroupManagement; import org.eclipse.hawkbit.repository.RolloutManagement; -import org.eclipse.hawkbit.repository.jpa.TestDataUtil; -import org.eclipse.hawkbit.repository.jpa.WithUser; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.Rollout.RolloutStatus; import org.eclipse.hawkbit.repository.model.RolloutGroup; import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupSuccessCondition; +import org.eclipse.hawkbit.repository.util.WithUser; import org.eclipse.hawkbit.repository.model.RolloutGroupConditionBuilder; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.rest.AbstractRestIntegrationTest; @@ -73,8 +72,7 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest { @Description("Testing that creating rollout with insufficient permission returns forbidden") @WithUser(allSpPermissions = true, removeFromAllPermission = "ROLLOUT_MANAGEMENT") public void createRolloutWithInsufficientPermissionReturnsForbidden() throws Exception { - final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); + final DistributionSet dsA = testdataFactory.createDistributionSet(""); mvc.perform(post("/rest/v1/rollouts") .content(JsonBuilder.rollout("name", "desc", 10, dsA.getId(), "name==test", null)) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) @@ -92,8 +90,7 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest { @Test @Description("Testing that creating rollout with not valid formed target filter query returns bad request") public void createRolloutWithNotWellFormedFilterReturnsBadRequest() throws Exception { - final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); + final DistributionSet dsA = testdataFactory.createDistributionSet(""); mvc.perform(post("/rest/v1/rollouts") .content(JsonBuilder.rollout("name", "desc", 10, dsA.getId(), "name=test", null)) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) @@ -107,8 +104,7 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest { final String targetFilterQuery = null; - final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); + final DistributionSet dsA = testdataFactory.createDistributionSet(""); mvc.perform(post("/rest/v1/rollouts") .content(JsonBuilder.rollout("rollout1", "desc", 10, dsA.getId(), targetFilterQuery, null)) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) @@ -121,8 +117,7 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest { @Test @Description("Testing that rollout can be created") public void createRollout() throws Exception { - final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); + final DistributionSet dsA = testdataFactory.createDistributionSet(""); postRollout("rollout1", 10, dsA.getId(), "name==target1"); } @@ -137,8 +132,7 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest { @Test @Description("Testing that rollout paged list contains rollouts") public void rolloutPagedListContainsAllRollouts() throws Exception { - final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); + final DistributionSet dsA = testdataFactory.createDistributionSet(""); // setup - create 2 rollouts postRollout("rollout1", 10, dsA.getId(), "name==target1"); postRollout("rollout2", 5, dsA.getId(), "name==target2"); @@ -159,8 +153,7 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest { @Test @Description("Testing that rollout paged list is limited by the query param limit") public void rolloutPagedListIsLimitedToQueryParam() throws Exception { - final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); + final DistributionSet dsA = testdataFactory.createDistributionSet(""); // setup - create 2 rollouts postRollout("rollout1", 10, dsA.getId(), "name==target1"); postRollout("rollout2", 5, dsA.getId(), "name==target2"); @@ -175,9 +168,8 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest { public void retrieveRolloutGroupsForSpecificRollout() throws Exception { // setup final int amountTargets = 20; - targetManagement.createTargets(TestDataUtil.buildTargetFixtures(amountTargets, "rollout", "rollout")); - final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); + targetManagement.createTargets(testdataFactory.generateTargets(amountTargets, "rollout", "rollout")); + final DistributionSet dsA = testdataFactory.createDistributionSet(""); // create rollout including the created targets with prefix 'rollout' final Rollout rollout = createRollout("rollout1", 4, dsA.getId(), "controllerId==rollout*"); @@ -198,9 +190,8 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest { public void startingRolloutSwitchesIntoRunningState() throws Exception { // setup final int amountTargets = 20; - targetManagement.createTargets(TestDataUtil.buildTargetFixtures(amountTargets, "rollout", "rollout")); - final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); + targetManagement.createTargets(testdataFactory.generateTargets(amountTargets, "rollout", "rollout")); + final DistributionSet dsA = testdataFactory.createDistributionSet(""); // create rollout including the created targets with prefix 'rollout' final Rollout rollout = createRollout("rollout1", 4, dsA.getId(), "controllerId==rollout*"); @@ -221,9 +212,8 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest { public void pausingRolloutSwitchesIntoPausedState() throws Exception { // setup final int amountTargets = 20; - targetManagement.createTargets(TestDataUtil.buildTargetFixtures(amountTargets, "rollout", "rollout")); - final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); + targetManagement.createTargets(testdataFactory.generateTargets(amountTargets, "rollout", "rollout")); + final DistributionSet dsA = testdataFactory.createDistributionSet(""); // create rollout including the created targets with prefix 'rollout' final Rollout rollout = createRollout("rollout1", 4, dsA.getId(), "controllerId==rollout*"); @@ -248,9 +238,8 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest { public void resumingRolloutSwitchesIntoRunningState() throws Exception { // setup final int amountTargets = 20; - targetManagement.createTargets(TestDataUtil.buildTargetFixtures(amountTargets, "rollout", "rollout")); - final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); + targetManagement.createTargets(testdataFactory.generateTargets(amountTargets, "rollout", "rollout")); + final DistributionSet dsA = testdataFactory.createDistributionSet(""); // create rollout including the created targets with prefix 'rollout' final Rollout rollout = createRollout("rollout1", 4, dsA.getId(), "controllerId==rollout*"); @@ -279,9 +268,8 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest { public void startingAlreadyStartedRolloutReturnsBadRequest() throws Exception { // setup final int amountTargets = 20; - targetManagement.createTargets(TestDataUtil.buildTargetFixtures(amountTargets, "rollout", "rollout")); - final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); + targetManagement.createTargets(testdataFactory.generateTargets(amountTargets, "rollout", "rollout")); + final DistributionSet dsA = testdataFactory.createDistributionSet(""); // create rollout including the created targets with prefix 'rollout' final Rollout rollout = createRollout("rollout1", 4, dsA.getId(), "controllerId==rollout*"); @@ -301,9 +289,8 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest { public void resumingNotStartedRolloutReturnsBadRequest() throws Exception { // setup final int amountTargets = 20; - targetManagement.createTargets(TestDataUtil.buildTargetFixtures(amountTargets, "rollout", "rollout")); - final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); + targetManagement.createTargets(testdataFactory.generateTargets(amountTargets, "rollout", "rollout")); + final DistributionSet dsA = testdataFactory.createDistributionSet(""); // create rollout including the created targets with prefix 'rollout' final Rollout rollout = createRollout("rollout1", 4, dsA.getId(), "controllerId==rollout*"); @@ -319,9 +306,8 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest { public void startingRolloutFirstRolloutGroupIsInRunningState() throws Exception { // setup final int amountTargets = 10; - targetManagement.createTargets(TestDataUtil.buildTargetFixtures(amountTargets, "rollout", "rollout")); - final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); + targetManagement.createTargets(testdataFactory.generateTargets(amountTargets, "rollout", "rollout")); + final DistributionSet dsA = testdataFactory.createDistributionSet(""); // create rollout including the created targets with prefix 'rollout' final Rollout rollout = createRollout("rollout1", 2, dsA.getId(), "controllerId==rollout*"); @@ -345,9 +331,8 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest { public void retrieveSingleRolloutGroup() throws Exception { // setup final int amountTargets = 10; - targetManagement.createTargets(TestDataUtil.buildTargetFixtures(amountTargets, "rollout", "rollout")); - final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); + targetManagement.createTargets(testdataFactory.generateTargets(amountTargets, "rollout", "rollout")); + final DistributionSet dsA = testdataFactory.createDistributionSet(""); // create rollout including the created targets with prefix 'rollout' final Rollout rollout = createRollout("rollout1", 4, dsA.getId(), "controllerId==rollout*"); @@ -369,9 +354,8 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest { public void retrieveTargetsFromRolloutGroup() throws Exception { // setup final int amountTargets = 10; - targetManagement.createTargets(TestDataUtil.buildTargetFixtures(amountTargets, "rollout", "rollout")); - final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); + targetManagement.createTargets(testdataFactory.generateTargets(amountTargets, "rollout", "rollout")); + final DistributionSet dsA = testdataFactory.createDistributionSet(""); // create rollout including the created targets with prefix 'rollout' final Rollout rollout = createRollout("rollout1", 2, dsA.getId(), "controllerId==rollout*"); @@ -393,9 +377,8 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest { // setup final int amountTargets = 10; final List targets = targetManagement - .createTargets(TestDataUtil.buildTargetFixtures(amountTargets, "rollout", "rollout")); - final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); + .createTargets(testdataFactory.generateTargets(amountTargets, "rollout", "rollout")); + final DistributionSet dsA = testdataFactory.createDistributionSet(""); // create rollout including the created targets with prefix 'rollout' final Rollout rollout = createRollout("rollout1", 2, dsA.getId(), "controllerId==rollout*"); @@ -418,9 +401,8 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest { public void retrieveTargetsFromRolloutGroupAfterRolloutIsStarted() throws Exception { // setup final int amountTargets = 10; - targetManagement.createTargets(TestDataUtil.buildTargetFixtures(amountTargets, "rollout", "rollout")); - final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); + targetManagement.createTargets(testdataFactory.generateTargets(amountTargets, "rollout", "rollout")); + final DistributionSet dsA = testdataFactory.createDistributionSet(""); // create rollout including the created targets with prefix 'rollout' final Rollout rollout = createRollout("rollout1", 2, dsA.getId(), "controllerId==rollout*"); @@ -443,9 +425,8 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest { public void startingRolloutSwitchesIntoRunningStateAsync() throws Exception { final int amountTargets = 1000; - targetManagement.createTargets(TestDataUtil.buildTargetFixtures(amountTargets, "rollout", "rollout")); - final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); + targetManagement.createTargets(testdataFactory.generateTargets(amountTargets, "rollout", "rollout")); + final DistributionSet dsA = testdataFactory.createDistributionSet(""); // create rollout including the created targets with prefix 'rollout' final Rollout rollout = createRollout("rollout1", 4, dsA.getId(), "controllerId==rollout*"); @@ -468,12 +449,14 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest { final int amountTargetsRollout2 = 25; final int amountTargetsRollout3 = 25; final int amountTargetsOther = 25; - targetManagement.createTargets(TestDataUtil.buildTargetFixtures(amountTargetsRollout1, "rollout1", "rollout1")); - targetManagement.createTargets(TestDataUtil.buildTargetFixtures(amountTargetsRollout2, "rollout2", "rollout2")); - targetManagement.createTargets(TestDataUtil.buildTargetFixtures(amountTargetsRollout3, "rollout3", "rollout3")); - targetManagement.createTargets(TestDataUtil.buildTargetFixtures(amountTargetsOther, "other1", "other1")); - final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); + targetManagement + .createTargets(testdataFactory.generateTargets(amountTargetsRollout1, "rollout1", "rollout1")); + targetManagement + .createTargets(testdataFactory.generateTargets(amountTargetsRollout2, "rollout2", "rollout2")); + targetManagement + .createTargets(testdataFactory.generateTargets(amountTargetsRollout3, "rollout3", "rollout3")); + targetManagement.createTargets(testdataFactory.generateTargets(amountTargetsOther, "other1", "other1")); + final DistributionSet dsA = testdataFactory.createDistributionSet(""); createRollout("rollout1", 5, dsA.getId(), "controllerId==rollout1*"); final Rollout rollout2 = createRollout("rollout2", 5, dsA.getId(), "controllerId==rollout2*"); @@ -503,9 +486,8 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest { public void retrieveRolloutGroupsForSpecificRolloutWithRSQLParam() throws Exception { // setup final int amountTargets = 20; - targetManagement.createTargets(TestDataUtil.buildTargetFixtures(amountTargets, "rollout", "rollout")); - final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); + targetManagement.createTargets(testdataFactory.generateTargets(amountTargets, "rollout", "rollout")); + final DistributionSet dsA = testdataFactory.createDistributionSet(""); // create rollout including the created targets with prefix 'rollout' final Rollout rollout = createRollout("rollout1", 4, dsA.getId(), "controllerId==rollout*"); @@ -577,7 +559,7 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest { private Rollout createRollout(final String name, final int amountGroups, final long distributionSetId, final String targetFilterQuery) { - final Rollout rollout = rolloutManagement.generateRollout(); + final Rollout rollout = entityFactory.generateRollout(); rollout.setDistributionSet(distributionSetManagement.findDistributionSetById(distributionSetId)); rollout.setName(name); rollout.setTargetFilterQuery(targetFilterQuery); diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java index 2e9f1a47b..a0bf416c9 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java @@ -37,13 +37,12 @@ import org.eclipse.hawkbit.mgmt.json.model.artifact.MgmtArtifact; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.jpa.HashGeneratorUtils; -import org.eclipse.hawkbit.repository.jpa.TestDataUtil; -import org.eclipse.hawkbit.repository.jpa.WithUser; import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata; +import org.eclipse.hawkbit.repository.util.WithUser; import org.eclipse.hawkbit.rest.AbstractRestIntegrationTestWithMongoDB; import org.eclipse.hawkbit.rest.json.model.ExceptionInfo; import org.eclipse.hawkbit.rest.util.JsonBuilder; @@ -76,7 +75,6 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW public void assertPreparationOfRepo() { assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).as("no softwaremodule should be founded") .hasSize(0); - assertThat(artifactRepository.findAll()).as("no artifacts should be founded").hasSize(0); } @Test @@ -92,13 +90,13 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW final String updateDescription = "newDescription1"; softwareManagement.createSoftwareModule( - softwareManagement.generateSoftwareModule(appType, "agent-hub", "1.0.1", null, "")); + entityFactory.generateSoftwareModule(appType, "agent-hub", "1.0.1", null, "")); softwareManagement.createSoftwareModule( - softwareManagement.generateSoftwareModule(runtimeType, "oracle-jre", "1.7.2", null, "")); + entityFactory.generateSoftwareModule(runtimeType, "oracle-jre", "1.7.2", null, "")); softwareManagement - .createSoftwareModule(softwareManagement.generateSoftwareModule(osType, "poky", "3.0.2", null, "")); + .createSoftwareModule(entityFactory.generateSoftwareModule(osType, "poky", "3.0.2", null, "")); - SoftwareModule sm = softwareManagement.generateSoftwareModule(osType, knownSWName, knownSWVersion, + SoftwareModule sm = entityFactory.generateSoftwareModule(osType, knownSWName, knownSWVersion, knownSWDescription, knownSWVendor); sm = softwareManagement.createSoftwareModule(sm); @@ -125,9 +123,8 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW @Test @Description("Tests the uppload of an artifact binary. The upload is executed and the content checked in the repository for completenes.") public void uploadArtifact() throws Exception { - SoftwareModule sm = softwareManagement.generateSoftwareModule(osType, "name 1", "version 1", null, null); + SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null); sm = softwareManagement.createSoftwareModule(sm); - assertThat(artifactRepository.findAll()).hasSize(0); // create test file final byte random[] = RandomStringUtils.random(5 * 1024).getBytes(); @@ -166,7 +163,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW private void assertArtifact(final SoftwareModule sm, final byte[] random) throws IOException { // check result in db... // repo - assertThat(artifactRepository.findAll()).as("Wrong artifact size").hasSize(1); + assertThat(artifactManagement.countLocalArtifactsAll()).as("Wrong artifact size").isEqualTo(1); // binary assertTrue("Wrong artifact content", @@ -192,9 +189,9 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW @Description("Verfies that the system does not accept empty artifact uploads. Expected response: BAD REQUEST") public void emptyUploadArtifact() throws Exception { assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0); - assertThat(artifactRepository.findAll()).hasSize(0); + assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(0); - SoftwareModule sm = softwareManagement.generateSoftwareModule(osType, "name 1", "version 1", null, null); + SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null); sm = softwareManagement.createSoftwareModule(sm); final MockMultipartFile file = new MockMultipartFile("file", "orig", null, new byte[0]); @@ -207,7 +204,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW @Test @Description("Verfies that the system does not accept identical artifacts uploads for the same software module. Expected response: CONFLICT") public void duplicateUploadArtifact() throws Exception { - SoftwareModule sm = softwareManagement.generateSoftwareModule(osType, "name 1", "version 1", null, null); + SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null); sm = softwareManagement.createSoftwareModule(sm); final byte random[] = RandomStringUtils.random(5 * 1024).getBytes(); @@ -229,9 +226,9 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW @Test @Description("verfies that option to upload artifacts with a custom defined by metadata, i.e. not the file name of the binary itself.") public void uploadArtifactWithCustomName() throws Exception { - SoftwareModule sm = softwareManagement.generateSoftwareModule(osType, "name 1", "version 1", null, null); + SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null); sm = softwareManagement.createSoftwareModule(sm); - assertThat(artifactRepository.findAll()).hasSize(0); + assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(0); // create test file final byte random[] = RandomStringUtils.random(5 * 1024).getBytes(); @@ -246,7 +243,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW // check result in db... // repo - assertThat(artifactRepository.findAll()).as("Artifact size is wring").hasSize(1); + assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(1); // hashes assertThat(artifactManagement.findLocalArtifactByFilename("customFilename")).as("Local artifact is wrong") @@ -256,9 +253,9 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW @Test @Description("Verfies that the system refuses upload of an artifact where the provided hash sums do not match. Expected result: BAD REQUEST") public void uploadArtifactWithHashCheck() throws Exception { - SoftwareModule sm = softwareManagement.generateSoftwareModule(osType, "name 1", "version 1", null, null); + SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null); sm = softwareManagement.createSoftwareModule(sm); - assertThat(artifactRepository.findAll()).hasSize(0); + assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(0); // create test file final byte random[] = RandomStringUtils.random(5 * 1024).getBytes(); @@ -300,7 +297,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW @Test @Description("Tests binary download of an artifact including verfication that the downloaded binary is consistent and that the etag header is as expected identical to the SHA1 hash of the file.") public void downloadArtifact() throws Exception { - SoftwareModule sm = softwareManagement.generateSoftwareModule(osType, "name 1", "version 1", null, null); + SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null); sm = softwareManagement.createSoftwareModule(sm); final byte random[] = RandomStringUtils.random(5 * 1024).getBytes(); @@ -328,14 +325,14 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW Arrays.equals(result2.getResponse().getContentAsByteArray(), random)); assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).as("Softwaremodule size is wrong").hasSize(1); - assertThat(artifactRepository.findAll()).as("Wrong artifact repostiory").hasSize(2); + assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(2); } @Test @Description("Verifies the listing of one defined artifact assigned to a given software module. That includes the artifact metadata and download links.") public void getArtifact() throws Exception { // prepare data for test - SoftwareModule sm = softwareManagement.generateSoftwareModule(osType, "name 1", "version 1", null, null); + SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null); sm = softwareManagement.createSoftwareModule(sm); final byte random[] = RandomStringUtils.random(5 * 1024).getBytes(); @@ -361,7 +358,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW @Test @Description("Verifies the listing of all artifacts assigned to a software module. That includes the artifact metadata and download links.") public void getArtifacts() throws Exception { - SoftwareModule sm = softwareManagement.generateSoftwareModule(osType, "name 1", "version 1", null, null); + SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null); sm = softwareManagement.createSoftwareModule(sm); final byte random[] = RandomStringUtils.random(5 * 1024).getBytes(); @@ -404,7 +401,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW final byte random[] = RandomStringUtils.random(5 * 1024).getBytes(); final MockMultipartFile file = new MockMultipartFile("file", "orig", null, random); - SoftwareModule sm = softwareManagement.generateSoftwareModule(osType, "name 1", "version 1", null, null); + SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null); sm = softwareManagement.createSoftwareModule(sm); // no artifact available @@ -437,7 +434,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW @Test @Description("Verfies that the system refuses unsupported request types and answers as defined to them, e.g. NOT FOUND on a non existing resource. Or a HTTP POST for updating a resource results in METHOD NOT ALLOWED etc.") public void invalidRequestsOnSoftwaremodulesResource() throws Exception { - SoftwareModule sm = softwareManagement.generateSoftwareModule(osType, "name 1", "version 1", null, null); + SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null); sm = softwareManagement.createSoftwareModule(sm); final List modules = new ArrayList<>(); @@ -519,15 +516,15 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW @WithUser(principal = "uploadTester", allSpPermissions = true) @Description("Test retrieval of all software modules the user has access to.") public void getSoftwareModules() throws Exception { - SoftwareModule os = softwareManagement.generateSoftwareModule(osType, "name1", "version1", "description1", + SoftwareModule os = entityFactory.generateSoftwareModule(osType, "name1", "version1", "description1", "vendor1"); os = softwareManagement.createSoftwareModule(os); - SoftwareModule jvm = softwareManagement.generateSoftwareModule(runtimeType, "name1", "version1", "description1", + SoftwareModule jvm = entityFactory.generateSoftwareModule(runtimeType, "name1", "version1", "description1", "vendor1"); jvm = softwareManagement.createSoftwareModule(jvm); - SoftwareModule ah = softwareManagement.generateSoftwareModule(appType, "name1", "version1", "description1", + SoftwareModule ah = entityFactory.generateSoftwareModule(appType, "name1", "version1", "description1", "vendor1"); ah = softwareManagement.createSoftwareModule(ah); @@ -590,27 +587,27 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW @Test @Description("Test the various filter parameters, e.g. filter by name or type of the module.") public void getSoftwareModulesWithFilterParameters() throws Exception { - SoftwareModule os1 = softwareManagement.generateSoftwareModule(osType, "osName1", "1.0.0", "description1", + SoftwareModule os1 = entityFactory.generateSoftwareModule(osType, "osName1", "1.0.0", "description1", "vendor1"); os1 = softwareManagement.createSoftwareModule(os1); - SoftwareModule jvm1 = softwareManagement.generateSoftwareModule(runtimeType, "runtimeName1", "2.0.0", + SoftwareModule jvm1 = entityFactory.generateSoftwareModule(runtimeType, "runtimeName1", "2.0.0", "description1", "vendor1"); jvm1 = softwareManagement.createSoftwareModule(jvm1); - SoftwareModule ah1 = softwareManagement.generateSoftwareModule(appType, "appName1", "3.0.0", "description1", + SoftwareModule ah1 = entityFactory.generateSoftwareModule(appType, "appName1", "3.0.0", "description1", "vendor1"); ah1 = softwareManagement.createSoftwareModule(ah1); - SoftwareModule os2 = softwareManagement.generateSoftwareModule(osType, "osName2", "1.0.1", "description2", + SoftwareModule os2 = entityFactory.generateSoftwareModule(osType, "osName2", "1.0.1", "description2", "vendor2"); os2 = softwareManagement.createSoftwareModule(os2); - SoftwareModule jvm2 = softwareManagement.generateSoftwareModule(runtimeType, "runtimeName2", "2.0.1", + SoftwareModule jvm2 = entityFactory.generateSoftwareModule(runtimeType, "runtimeName2", "2.0.1", "description2", "vendor2"); jvm2 = softwareManagement.createSoftwareModule(jvm2); - SoftwareModule ah2 = softwareManagement.generateSoftwareModule(appType, "appName2", "3.0.1", "description2", + SoftwareModule ah2 = entityFactory.generateSoftwareModule(appType, "appName2", "3.0.1", "description2", "vendor2"); ah2 = softwareManagement.createSoftwareModule(ah2); @@ -688,7 +685,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW @WithUser(principal = "uploadTester", allSpPermissions = true) @Description("Tests GET request on /rest/v1/softwaremodules/{smId}.") public void getSoftareModule() throws Exception { - SoftwareModule os = softwareManagement.generateSoftwareModule(osType, "name1", "version1", "description1", + SoftwareModule os = entityFactory.generateSoftwareModule(osType, "name1", "version1", "description1", "vendor1"); os = softwareManagement.createSoftwareModule(os); @@ -708,7 +705,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW .andExpect(jsonPath("$_links.artifacts.href", equalTo("http://localhost/rest/v1/softwaremodules/" + os.getId() + "/artifacts"))); - SoftwareModule jvm = softwareManagement.generateSoftwareModule(runtimeType, "name1", "version1", "description1", + SoftwareModule jvm = entityFactory.generateSoftwareModule(runtimeType, "name1", "version1", "description1", "vendor1"); jvm = softwareManagement.createSoftwareModule(jvm); @@ -728,7 +725,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW .andExpect(jsonPath("$_links.artifacts.href", equalTo("http://localhost/rest/v1/softwaremodules/" + jvm.getId() + "/artifacts"))); - SoftwareModule ah = softwareManagement.generateSoftwareModule(appType, "name1", "version1", "description1", + SoftwareModule ah = entityFactory.generateSoftwareModule(appType, "name1", "version1", "description1", "vendor1"); ah = softwareManagement.createSoftwareModule(ah); @@ -755,11 +752,11 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW @WithUser(principal = "uploadTester", allSpPermissions = true) @Description("Verfies that the create request actually results in the creation of the modules in the repository.") public void createSoftwareModules() throws JSONException, Exception { - final SoftwareModule os = softwareManagement.generateSoftwareModule(osType, "name1", "version1", "description1", + final SoftwareModule os = entityFactory.generateSoftwareModule(osType, "name1", "version1", "description1", "vendor1"); - final SoftwareModule jvm = softwareManagement.generateSoftwareModule(runtimeType, "name2", "version1", + final SoftwareModule jvm = entityFactory.generateSoftwareModule(runtimeType, "name2", "version1", "description1", "vendor1"); - final SoftwareModule ah = softwareManagement.generateSoftwareModule(appType, "name3", "version1", + final SoftwareModule ah = entityFactory.generateSoftwareModule(appType, "name3", "version1", "description1", "vendor1"); final List modules = new ArrayList<>(); @@ -841,7 +838,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW @Description("Verifies successfull deletion of software modules that are not in use, i.e. assigned to a DS.") public void deleteUnassignedSoftwareModule() throws Exception { - SoftwareModule sm = softwareManagement.generateSoftwareModule(osType, "name 1", "version 1", null, null); + SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null); sm = softwareManagement.createSoftwareModule(sm); final byte random[] = RandomStringUtils.random(5 * 1024).getBytes(); @@ -849,24 +846,20 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", false); assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).as("Softwaremoudle size is wrong").hasSize(1); - assertThat(artifactRepository.findAll()).as("artifact site is wrong").hasSize(1); - assertThat(softwareModuleRepository.findAll()).as("Softwaremoudle size is wrong").hasSize(1); + assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(1); mvc.perform(delete("/rest/v1/softwaremodules/{smId}", sm.getId())).andDo(MockMvcResultPrinter.print()) .andExpect(status().isOk()); assertThat(softwareManagement.findSoftwareModulesAll(pageReq)) .as("After delete no softwarmodule should be available").isEmpty(); - assertThat(softwareModuleRepository.findAll()).as("After delete no softwarmodule should be available") - .isEmpty(); - assertThat(artifactRepository.findAll()).as("After delete no artifact should be available").isEmpty(); + assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(0); } @Test @Description("Verifies successfull deletion of software modules that are in use, i.e. assigned to a DS which should result in movinf the module to the archive.") public void deleteAssignedSoftwareModule() throws Exception { - final DistributionSet ds1 = TestDataUtil.generateDistributionSet("a", softwareManagement, - distributionSetManagement); + final DistributionSet ds1 = testdataFactory.createDistributionSet("a"); final byte random[] = RandomStringUtils.random(5 * 1024).getBytes(); @@ -874,8 +867,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW ds1.findFirstModuleByType(appType).getId(), "file1", false); assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(3); - assertThat(artifactRepository.findAll()).hasSize(1); - assertThat(softwareModuleRepository.findAll()).hasSize(3); + assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(1); mvc.perform(delete("/rest/v1/softwaremodules/{smId}", ds1.findFirstModuleByType(appType).getId())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); @@ -887,17 +879,14 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW // all 3 are now marked as deleted assertThat(softwareManagement.findSoftwareModulesAll(pageReq).getNumber()) .as("After delete no softwarmodule should be available").isEqualTo(0); - assertThat(softwareModuleRepository.findAll()).as("After delete no softwarmodule should marked as deleted") - .hasSize(3); - assertThat(artifactRepository.findAll()).as("After delete artifact should available for marked as deleted sm's") - .hasSize(1); + assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(1); } @Test @Description("Tests the deletion of an artifact including verfication that the artifact is actually erased in the repository and removed from the software module.") public void deleteArtifact() throws Exception { // Create 1 SM - SoftwareModule sm = softwareManagement.generateSoftwareModule(osType, "name 1", "version 1", null, null); + SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null); sm = softwareManagement.createSoftwareModule(sm); final byte random[] = RandomStringUtils.random(5 * 1024).getBytes(); @@ -911,7 +900,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(1); assertThat(softwareManagement.findSoftwareModuleWithDetails(sm.getId()).getArtifacts()).hasSize(2); - assertThat(artifactRepository.findAll()).hasSize(2); + assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(2); // delete mvc.perform(delete("/rest/v1/softwaremodules/{smId}/artifacts/{artId}", sm.getId(), artifact.getId())) @@ -920,8 +909,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW // check that only one artifact is still alive and still assigned assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).as("After the sm should be marked as deleted") .hasSize(1); - assertThat(artifactRepository.findAll()).as("After delete artifact should available for marked as deleted sm's") - .hasSize(1); + assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(1); assertThat(softwareManagement.findSoftwareModuleWithDetails(sm.getId()).getArtifacts()) .as("After delete artifact should available for marked as deleted sm's").hasSize(1); @@ -937,7 +925,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW final String knownValue2 = "knownValue1"; final SoftwareModule sm = softwareManagement.createSoftwareModule( - softwareManagement.generateSoftwareModule(osType, "name 1", "version 1", null, null)); + entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null)); final JSONArray jsonArray = new JSONArray(); jsonArray.put(new JSONObject().put("key", knownKey1).put("value", knownValue1)); @@ -966,9 +954,9 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW final String updateValue = "valueForUpdate"; final SoftwareModule sm = softwareManagement.createSoftwareModule( - softwareManagement.generateSoftwareModule(osType, "name 1", "version 1", null, null)); + entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null)); softwareManagement.createSoftwareModuleMetadata( - softwareManagement.generateSoftwareModuleMetadata(sm, knownKey, knownValue)); + entityFactory.generateSoftwareModuleMetadata(sm, knownKey, knownValue)); final JSONObject jsonObject = new JSONObject().put("key", knownKey).put("value", updateValue); @@ -990,9 +978,9 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW final String knownValue = "knownValue"; final SoftwareModule sm = softwareManagement.createSoftwareModule( - softwareManagement.generateSoftwareModule(osType, "name 1", "version 1", null, null)); + entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null)); softwareManagement.createSoftwareModuleMetadata( - softwareManagement.generateSoftwareModuleMetadata(sm, knownKey, knownValue)); + entityFactory.generateSoftwareModuleMetadata(sm, knownKey, knownValue)); mvc.perform(delete("/rest/v1/softwaremodules/{swId}/metadata/{key}", sm.getId(), knownKey)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); @@ -1012,10 +1000,10 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW final String knownKeyPrefix = "knownKey"; final String knownValuePrefix = "knownValue"; final SoftwareModule sm = softwareManagement.createSoftwareModule( - softwareManagement.generateSoftwareModule(osType, "name 1", "version 1", null, null)); + entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null)); for (int index = 0; index < totalMetadata; index++) { - softwareManagement.createSoftwareModuleMetadata(softwareManagement.generateSoftwareModuleMetadata( + softwareManagement.createSoftwareModuleMetadata(entityFactory.generateSoftwareModuleMetadata( softwareManagement.findSoftwareModuleById(sm.getId()), knownKeyPrefix + index, knownValuePrefix + index)); } @@ -1032,7 +1020,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW char character = 'a'; for (int index = 0; index < amount; index++) { final String str = String.valueOf(character); - final SoftwareModule softwareModule = softwareManagement.generateSoftwareModule(osType, str, str, str, str); + final SoftwareModule softwareModule = entityFactory.generateSoftwareModule(osType, str, str, str, str); softwareManagement.createSoftwareModule(softwareModule); character++; diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResourceTest.java index ae137e125..363b12cde 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResourceTest.java @@ -24,9 +24,9 @@ import java.util.ArrayList; import java.util.List; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; -import org.eclipse.hawkbit.repository.jpa.WithUser; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; +import org.eclipse.hawkbit.repository.util.WithUser; import org.eclipse.hawkbit.rest.AbstractRestIntegrationTest; import org.eclipse.hawkbit.rest.util.JsonBuilder; import org.eclipse.hawkbit.rest.util.MockMvcResultPrinter; @@ -55,7 +55,7 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT @Description("Checks the correct behaviour of /rest/v1/softwaremoduletypes GET requests.") public void getSoftwareModuleTypes() throws Exception { SoftwareModuleType testType = softwareManagement.createSoftwareModuleType( - softwareManagement.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5)); + entityFactory.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5)); testType.setDescription("Desc1234"); testType = softwareManagement.updateSoftwareModuleType(testType); @@ -77,7 +77,8 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT jsonPath("$content.[?(@.key==" + appType.getKey() + ")][0].name", equalTo(appType.getName()))) .andExpect(jsonPath("$content.[?(@.key==" + appType.getKey() + ")][0].description", equalTo(appType.getDescription()))) - .andExpect(jsonPath("$content.[?(@.key==" + appType.getKey() + ")][0].maxAssignments", equalTo(1))) + .andExpect(jsonPath("$content.[?(@.key==" + appType.getKey() + ")][0].maxAssignments", + equalTo(Integer.MAX_VALUE))) .andExpect(jsonPath("$content.[?(@.key==" + appType.getKey() + ")][0].key", equalTo("application"))) .andExpect(jsonPath("$content.[?(@.key==test123)][0].id", equalTo(testType.getId().intValue()))) .andExpect(jsonPath("$content.[?(@.key==test123)][0].name", equalTo("TestName123"))) @@ -96,8 +97,8 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT @WithUser(principal = "uploadTester", allSpPermissions = true) @Description("Checks the correct behaviour of /rest/v1/softwaremoduletypes GET requests with sorting by MAXASSIGNMENTS field.") public void getSoftwareModuleTypesSortedByMaxAssignments() throws Exception { - SoftwareModuleType testType = softwareManagement - .createSoftwareModuleType(softwareManagement.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5)); + SoftwareModuleType testType = softwareManagement.createSoftwareModuleType( + entityFactory.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5)); testType.setDescription("Desc1234"); testType = softwareManagement.updateSoftwareModuleType(testType); @@ -106,30 +107,30 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT .param(MgmtRestConstants.REQUEST_PARAMETER_SORTING, "MAXASSIGNMENTS:DESC")) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$content.[0].id", equalTo(testType.getId().intValue()))) - .andExpect(jsonPath("$content.[0].name", equalTo("TestName123"))) - .andExpect(jsonPath("$content.[0].description", equalTo("Desc1234"))) - .andExpect(jsonPath("$content.[0].createdBy", equalTo("uploadTester"))) - .andExpect(jsonPath("$content.[0].createdAt", equalTo(testType.getCreatedAt()))) - .andExpect(jsonPath("$content.[0].lastModifiedBy", equalTo("uploadTester"))) - .andExpect(jsonPath("$content.[0].lastModifiedAt", equalTo(testType.getLastModifiedAt()))) - .andExpect(jsonPath("$content.[0].maxAssignments", equalTo(5))) - .andExpect(jsonPath("$content.[0].key", equalTo("test123"))).andExpect(jsonPath("$total", equalTo(4))); + .andExpect(jsonPath("$content.[1].id", equalTo(testType.getId().intValue()))) + .andExpect(jsonPath("$content.[1].name", equalTo("TestName123"))) + .andExpect(jsonPath("$content.[1].description", equalTo("Desc1234"))) + .andExpect(jsonPath("$content.[1].createdBy", equalTo("uploadTester"))) + .andExpect(jsonPath("$content.[1].createdAt", equalTo(testType.getCreatedAt()))) + .andExpect(jsonPath("$content.[1].lastModifiedBy", equalTo("uploadTester"))) + .andExpect(jsonPath("$content.[1].lastModifiedAt", equalTo(testType.getLastModifiedAt()))) + .andExpect(jsonPath("$content.[1].maxAssignments", equalTo(5))) + .andExpect(jsonPath("$content.[1].key", equalTo("test123"))).andExpect(jsonPath("$total", equalTo(4))); // ascending mvc.perform(get("/rest/v1/softwaremoduletypes").accept(MediaType.APPLICATION_JSON) .param(MgmtRestConstants.REQUEST_PARAMETER_SORTING, "MAXASSIGNMENTS:ASC")) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$content.[3].id", equalTo(testType.getId().intValue()))) - .andExpect(jsonPath("$content.[3].name", equalTo("TestName123"))) - .andExpect(jsonPath("$content.[3].description", equalTo("Desc1234"))) - .andExpect(jsonPath("$content.[3].createdBy", equalTo("uploadTester"))) - .andExpect(jsonPath("$content.[3].createdAt", equalTo(testType.getCreatedAt()))) - .andExpect(jsonPath("$content.[3].lastModifiedBy", equalTo("uploadTester"))) - .andExpect(jsonPath("$content.[3].lastModifiedAt", equalTo(testType.getLastModifiedAt()))) - .andExpect(jsonPath("$content.[3].maxAssignments", equalTo(5))) - .andExpect(jsonPath("$content.[3].key", equalTo("test123"))).andExpect(jsonPath("$total", equalTo(4))); + .andExpect(jsonPath("$content.[2].id", equalTo(testType.getId().intValue()))) + .andExpect(jsonPath("$content.[2].name", equalTo("TestName123"))) + .andExpect(jsonPath("$content.[2].description", equalTo("Desc1234"))) + .andExpect(jsonPath("$content.[2].createdBy", equalTo("uploadTester"))) + .andExpect(jsonPath("$content.[2].createdAt", equalTo(testType.getCreatedAt()))) + .andExpect(jsonPath("$content.[2].lastModifiedBy", equalTo("uploadTester"))) + .andExpect(jsonPath("$content.[2].lastModifiedAt", equalTo(testType.getLastModifiedAt()))) + .andExpect(jsonPath("$content.[2].maxAssignments", equalTo(5))) + .andExpect(jsonPath("$content.[2].key", equalTo("test123"))).andExpect(jsonPath("$total", equalTo(4))); } @Test @@ -138,9 +139,9 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT public void createSoftwareModuleTypes() throws JSONException, Exception { final List types = new ArrayList<>(); - types.add(softwareManagement.generateSoftwareModuleType("test1", "TestName1", "Desc1", 1)); - types.add(softwareManagement.generateSoftwareModuleType("test2", "TestName2", "Desc2", 2)); - types.add(softwareManagement.generateSoftwareModuleType("test3", "TestName3", "Desc3", 3)); + types.add(entityFactory.generateSoftwareModuleType("test1", "TestName1", "Desc1", 1)); + types.add(entityFactory.generateSoftwareModuleType("test2", "TestName2", "Desc2", 2)); + types.add(entityFactory.generateSoftwareModuleType("test3", "TestName3", "Desc3", 3)); final MvcResult mvcResult = mvc .perform(post("/rest/v1/softwaremoduletypes/").content(JsonBuilder.softwareModuleTypes(types)) @@ -182,8 +183,8 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT @WithUser(principal = "uploadTester", allSpPermissions = true) @Description("Checks the correct behaviour of /rest/v1/softwaremoduletypes/{ID} GET requests.") public void getSoftwareModuleType() throws Exception { - SoftwareModuleType testType = softwareManagement - .createSoftwareModuleType(softwareManagement.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5)); + SoftwareModuleType testType = softwareManagement.createSoftwareModuleType( + entityFactory.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5)); testType.setDescription("Desc1234"); testType = softwareManagement.updateSoftwareModuleType(testType); @@ -203,8 +204,8 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT @WithUser(principal = "uploadTester", allSpPermissions = true) @Description("Checks the correct behaviour of /rest/v1/softwaremoduletypes/{ID} DELETE requests (hard delete scenario).") public void deleteSoftwareModuleTypeUnused() throws Exception { - final SoftwareModuleType testType = softwareManagement - .createSoftwareModuleType(softwareManagement.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5)); + final SoftwareModuleType testType = softwareManagement.createSoftwareModuleType( + entityFactory.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5)); assertThat(softwareManagement.countSoftwareModuleTypesAll()).isEqualTo(4); @@ -218,26 +219,24 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT @WithUser(principal = "uploadTester", allSpPermissions = true) @Description("Checks the correct behaviour of /rest/v1/softwaremoduletypes/{ID} DELETE requests (soft delete scenario).") public void deleteSoftwareModuleTypeUsed() throws Exception { - final SoftwareModuleType testType = softwareManagement - .createSoftwareModuleType(softwareManagement.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5)); + final SoftwareModuleType testType = softwareManagement.createSoftwareModuleType( + entityFactory.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5)); softwareManagement.createSoftwareModule( - softwareManagement.generateSoftwareModule(testType, "name", "version", "description", "vendor")); + entityFactory.generateSoftwareModule(testType, "name", "version", "description", "vendor")); assertThat(softwareManagement.countSoftwareModuleTypesAll()).isEqualTo(4); - assertThat(softwareModuleTypeRepository.count()).isEqualTo(4); mvc.perform(delete("/rest/v1/softwaremoduletypes/{smId}", testType.getId())).andDo(MockMvcResultPrinter.print()) .andExpect(status().isOk()); - assertThat(softwareModuleTypeRepository.count()).isEqualTo(4); assertThat(softwareManagement.countSoftwareModuleTypesAll()).isEqualTo(3); } @Test @Description("Checks the correct behaviour of /rest/v1/softwaremoduletypes/{ID} PUT requests.") public void updateSoftwareModuleTypeOnlyDescriptionAndNameUntouched() throws Exception { - final SoftwareModuleType testType = softwareManagement - .createSoftwareModuleType(softwareManagement.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5)); + final SoftwareModuleType testType = softwareManagement.createSoftwareModuleType( + entityFactory.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5)); final String body = new JSONObject().put("id", testType.getId()).put("description", "foobardesc") .put("name", "nameShouldNotBeChanged").toString(); @@ -292,8 +291,8 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT @Test @Description("Ensures that the server is behaving as expected on invalid requests (wrong media type, wrong ID etc.).") public void invalidRequestsOnSoftwaremoduleTypesResource() throws Exception { - final SoftwareModuleType testType = softwareManagement - .createSoftwareModuleType(softwareManagement.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5)); + final SoftwareModuleType testType = softwareManagement.createSoftwareModuleType( + entityFactory.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5)); final List types = new ArrayList<>(); types.add(testType); @@ -331,10 +330,10 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT @Test @Description("Search erquest of software module types.") public void searchSoftwareModuleTypeRsql() throws Exception { - final SoftwareModuleType testType = softwareManagement - .createSoftwareModuleType(softwareManagement.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5)); - final SoftwareModuleType testType2 = softwareManagement - .createSoftwareModuleType(softwareManagement.generateSoftwareModuleType("test1234", "TestName1234", "Desc123", 5)); + final SoftwareModuleType testType = softwareManagement.createSoftwareModuleType( + entityFactory.generateSoftwareModuleType("test123", "TestName123", "Desc123", 5)); + final SoftwareModuleType testType2 = softwareManagement.createSoftwareModuleType( + entityFactory.generateSoftwareModuleType("test1234", "TestName1234", "Desc123", 5)); final String rsqlFindLikeDs1OrDs2 = "name==TestName123,name==TestName1234"; @@ -349,7 +348,7 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT char character = 'a'; for (int index = 0; index < amount; index++) { final String str = String.valueOf(character); - final SoftwareModule softwareModule = softwareManagement.generateSoftwareModule(osType, str, str, str, str); + final SoftwareModule softwareModule = entityFactory.generateSoftwareModule(osType, str, str, str, str); softwareManagement.createSoftwareModule(softwareModule); character++; diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java index b1ed0eb26..6e50d1103 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java @@ -35,14 +35,12 @@ import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.repository.ActionFields; import org.eclipse.hawkbit.repository.ActionStatusFields; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; -import org.eclipse.hawkbit.repository.jpa.TestDataUtil; -import org.eclipse.hawkbit.repository.jpa.WithUser; -import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.ActionType; import org.eclipse.hawkbit.repository.model.Action.Status; +import org.eclipse.hawkbit.repository.util.WithUser; import org.eclipse.hawkbit.repository.model.ActionStatus; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.SoftwareModule; @@ -111,7 +109,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { final String knownTargetId = "targetId"; final List actions = generateTargetWithTwoUpdatesWithOneOverride(knownTargetId); actions.get(0).setStatus(Status.FINISHED); - controllerManagament.addUpdateActionStatus(controllerManagament.generateActionStatus(actions.get(0), + controllerManagament.addUpdateActionStatus(entityFactory.generateActionStatus(actions.get(0), Status.FINISHED, System.currentTimeMillis(), "testmessage")); final PageRequest pageRequest = new PageRequest(0, 1000, Direction.ASC, ActionFields.ID.getFieldName()); @@ -141,7 +139,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { public void securityTokenIsNotInResponseIfMissingPermission() throws Exception { final String knownControllerId = "knownControllerId"; - targetManagement.createTarget(targetManagement.generateTarget(knownControllerId)); + targetManagement.createTarget(entityFactory.generateTarget(knownControllerId)); mvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}", knownControllerId)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(jsonPath("securityToken").doesNotExist()); @@ -154,7 +152,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { public void securityTokenIsInResponseWithCorrectPermission() throws Exception { final String knownControllerId = "knownControllerId"; - final Target createTarget = targetManagement.createTarget(targetManagement.generateTarget(knownControllerId)); + final Target createTarget = targetManagement.createTarget(entityFactory.generateTarget(knownControllerId)); mvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}", knownControllerId)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(jsonPath("securityToken", equalTo(createTarget.getSecurityToken()))); @@ -185,7 +183,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { } private void createTarget(final String controllerId) { - final JpaTarget target = (JpaTarget) targetManagement.generateTarget(controllerId); + final JpaTarget target = (JpaTarget) entityFactory.generateTarget(controllerId); final JpaTargetInfo targetInfo = new JpaTargetInfo(target); targetInfo.setAddress(IpUtil.createHttpUri("127.0.0.1").toString()); target.setTargetInfo(targetInfo); @@ -197,9 +195,8 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { public void searchActionsRsql() throws Exception { // prepare test - final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); - final Target createTarget = targetManagement.createTarget(targetManagement.generateTarget("knownTargetId")); + final DistributionSet dsA = testdataFactory.createDistributionSet(""); + final Target createTarget = targetManagement.createTarget(entityFactory.generateTarget("knownTargetId")); deploymentManagement.assignDistributionSet(dsA, Lists.newArrayList(createTarget)); @@ -306,7 +303,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { @Description("Ensures that deletion is executed if permitted.") public void deleteTargetReturnsOK() throws Exception { final String knownControllerId = "knownControllerIdDelete"; - targetManagement.createTarget(targetManagement.generateTarget(knownControllerId)); + targetManagement.createTarget(entityFactory.generateTarget(knownControllerId)); mvc.perform(delete(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownControllerId)) .andExpect(status().isOk()); @@ -342,7 +339,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { final String body = new JSONObject().put("description", knownNewDescription).toString(); // prepare - final Target t = targetManagement.generateTarget(knownControllerId); + final Target t = entityFactory.generateTarget(knownControllerId); t.setDescription("old description"); t.setName(knownNameNotModiy); targetManagement.createTarget(t); @@ -525,8 +522,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { final String knownControllerId = "1"; final String knownName = "someName"; createSingleTarget(knownControllerId, knownName); - final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); + final DistributionSet ds = testdataFactory.createDistributionSet(""); deploymentManagement.assignDistributionSet(ds.getId(), knownControllerId); // test @@ -596,8 +592,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { final String knownControllerId = "1"; final String knownName = "someName"; createSingleTarget(knownControllerId, knownName); - final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); + final DistributionSet ds = testdataFactory.createDistributionSet(""); // assign ds to target final Long actionId = deploymentManagement.assignDistributionSet(ds.getId(), knownControllerId).getActions() .get(0); @@ -684,13 +679,13 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { @Test public void createTargetsListReturnsSuccessful() throws Exception { - final Target test1 = targetManagement.generateTarget("id1"); + final Target test1 = entityFactory.generateTarget("id1"); test1.setDescription("testid1"); test1.setName("testname1"); - final Target test2 = targetManagement.generateTarget("id2"); + final Target test2 = entityFactory.generateTarget("id2"); test2.setDescription("testid2"); test2.setName("testname2"); - final Target test3 = targetManagement.generateTarget("id3"); + final Target test3 = entityFactory.generateTarget("id3"); test3.setName("testname3"); test3.setDescription("testid3"); @@ -813,7 +808,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { @Test public void getActionWithEmptyResult() throws Exception { final String knownTargetId = "targetId"; - final Target target = targetManagement.generateTarget(knownTargetId); + final Target target = entityFactory.generateTarget(knownTargetId); targetManagement.createTarget(target); mvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownTargetId + "/" @@ -1028,13 +1023,12 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { final PageRequest pageRequest = new PageRequest(0, 100, Direction.ASC, ActionStatusFields.ID.getFieldName()); - Target target = targetManagement.generateTarget(knownTargetId); + Target target = entityFactory.generateTarget(knownTargetId); target = targetManagement.createTarget(target); final List targets = new ArrayList<>(); targets.add(target); - final Iterator sets = TestDataUtil - .generateDistributionSets(2, softwareManagement, distributionSetManagement).iterator(); + final Iterator sets = testdataFactory.createDistributionSets(2).iterator(); final DistributionSet one = sets.next(); final DistributionSet two = sets.next(); @@ -1074,9 +1068,8 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { @Test public void assignDistributionSetToTarget() throws Exception { - final Target target = targetManagement.createTarget(targetManagement.generateTarget("fsdfsd")); - final DistributionSet set = TestDataUtil.generateDistributionSet("one", softwareManagement, - distributionSetManagement); + final Target target = targetManagement.createTarget(entityFactory.generateTarget("fsdfsd")); + final DistributionSet set = testdataFactory.createDistributionSet("one"); mvc.perform(post(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/fsdfsd/assignedDS") .content("{\"id\":" + set.getId() + "}").contentType(MediaType.APPLICATION_JSON)) @@ -1088,9 +1081,8 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { @Test public void assignDistributionSetToTargetWithActionTimeForcedAndTime() throws Exception { - final Target target = targetManagement.createTarget(targetManagement.generateTarget("fsdfsd")); - final DistributionSet set = TestDataUtil.generateDistributionSet("one", softwareManagement, - distributionSetManagement); + final Target target = targetManagement.createTarget(entityFactory.generateTarget("fsdfsd")); + final DistributionSet set = testdataFactory.createDistributionSet("one"); final long forceTime = System.currentTimeMillis(); final String body = new JSONObject().put("id", set.getId()).put("type", "timeforced") @@ -1110,14 +1102,13 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { @Test public void invalidRequestsOnAssignDistributionSetToTarget() throws Exception { - final DistributionSet set = TestDataUtil.generateDistributionSet("one", softwareManagement, - distributionSetManagement); + final DistributionSet set = testdataFactory.createDistributionSet("one"); mvc.perform(post(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/fsdfsd/assignedDS") .content("{\"id\":" + set.getId() + "}").contentType(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isNotFound()); - targetManagement.createTarget(targetManagement.generateTarget("fsdfsd")); + targetManagement.createTarget(entityFactory.generateTarget("fsdfsd")); mvc.perform(post(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/fsdfsd/assignedDS") .content("{\"id\":" + set.getId() + "}").contentType(MediaType.APPLICATION_JSON)) @@ -1207,7 +1198,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { final Map knownControllerAttrs = new HashMap<>(); knownControllerAttrs.put("a", "1"); knownControllerAttrs.put("b", "2"); - final Target target = targetManagement.generateTarget(knownTargetId); + final Target target = entityFactory.generateTarget(knownTargetId); targetManagement.createTarget(target); controllerManagament.updateControllerAttributes(knownTargetId, knownControllerAttrs); @@ -1221,7 +1212,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { public void getControllerEmptyAttributesReturnsNoContent() throws Exception { // create target with attributes final String knownTargetId = "targetIdWithAttributes"; - final Target target = targetManagement.generateTarget(knownTargetId); + final Target target = entityFactory.generateTarget(knownTargetId); targetManagement.createTarget(target); // test query target over rest resource @@ -1255,7 +1246,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { } private void createSingleTarget(final String controllerId, final String name) { - final Target target = targetManagement.generateTarget(controllerId); + final Target target = entityFactory.generateTarget(controllerId); target.setName(name); target.setDescription(TARGET_DESCRIPTION_TEST); targetManagement.createTarget(target); @@ -1272,7 +1263,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { char character = 'a'; for (int index = 0; index < amount; index++) { final String str = String.valueOf(character); - final Target target = targetManagement.generateTarget(str); + final Target target = entityFactory.generateTarget(str); target.setName(str); target.setDescription(str); final Target savedTarget = targetManagement.createTarget(target); @@ -1288,7 +1279,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { private void feedbackToByInSync(final Long actionId) { final Action action = deploymentManagement.findAction(actionId); - final ActionStatus actionStatus = controllerManagement.generateActionStatus(action, Status.FINISHED, 0L); + final ActionStatus actionStatus = entityFactory.generateActionStatus(action, Status.FINISHED, 0L); controllerManagement.addUpdateActionStatus(actionStatus); } @@ -1299,10 +1290,9 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { */ private Target createTargetAndStartAction() { // prepare test - final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); + final DistributionSet dsA = testdataFactory.createDistributionSet(""); final Target tA = targetManagement - .createTarget(TestDataUtil.buildTargetFixture("target-id-A", "first description")); + .createTarget(testdataFactory.generateTarget("target-id-A", "first description")); // assign a distribution set so we get an active update action deploymentManagement.assignDistributionSet(dsA, Lists.newArrayList(tA)); // verify active action diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/SMRessourceMisingMongoDbConnectionTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/SMRessourceMisingMongoDbConnectionTest.java index 9e698e0af..de0411006 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/SMRessourceMisingMongoDbConnectionTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/SMRessourceMisingMongoDbConnectionTest.java @@ -14,8 +14,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. import org.apache.commons.lang3.RandomStringUtils; import org.eclipse.hawkbit.exception.SpServerError; -import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest; import org.eclipse.hawkbit.repository.model.SoftwareModule; +import org.eclipse.hawkbit.rest.AbstractRestIntegrationTest; import org.eclipse.hawkbit.rest.json.model.ExceptionInfo; import org.eclipse.hawkbit.rest.util.MockMvcResultPrinter; import org.junit.BeforeClass; @@ -34,7 +34,7 @@ import ru.yandex.qatools.allure.annotations.Stories; */ @Features("Component Tests - Management API") @Stories("Download Resource") -public class SMRessourceMisingMongoDbConnectionTest extends AbstractIntegrationTest { +public class SMRessourceMisingMongoDbConnectionTest extends AbstractRestIntegrationTest { @BeforeClass public static void initialize() { @@ -48,11 +48,11 @@ public class SMRessourceMisingMongoDbConnectionTest extends AbstractIntegrationT public void missingMongoDbConnectionResultsInErrorAtUpload() throws Exception { assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0); - assertThat(artifactRepository.findAll()).hasSize(0); - SoftwareModule sm = softwareManagement.generateSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1", - "version 1", null, null); + assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(0); + SoftwareModule sm = entityFactory.generateSoftwareModule( + softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1", "version 1", null, null); sm = softwareManagement.createSoftwareModule(sm); - assertThat(artifactRepository.findAll()).hasSize(0); + assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(0); // create test file final byte random[] = RandomStringUtils.random(5 * 1024).getBytes(); @@ -70,7 +70,7 @@ public class SMRessourceMisingMongoDbConnectionTest extends AbstractIntegrationT assertThat(exceptionInfo.getMessage()).isEqualTo(SpServerError.SP_ARTIFACT_UPLOAD_FAILED.getMessage()); // ensure that the JPA transaction was rolled back - assertThat(artifactRepository.findAll()).hasSize(0); + assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(0); } diff --git a/hawkbit-mgmt-resource/src/test/resources/log4j2.xml b/hawkbit-mgmt-resource/src/test/resources/log4j2.xml deleted file mode 100644 index 98ea99ac9..000000000 --- a/hawkbit-mgmt-resource/src/test/resources/log4j2.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/hawkbit-mgmt-resource/src/test/resources/logback.xml b/hawkbit-mgmt-resource/src/test/resources/logback.xml new file mode 100644 index 000000000..49ea574f2 --- /dev/null +++ b/hawkbit-mgmt-resource/src/test/resources/logback.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ArtifactManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ArtifactManagement.java index 7854640da..ee73a1354 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ArtifactManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ArtifactManagement.java @@ -60,6 +60,12 @@ public interface ArtifactManagement { ExternalArtifact createExternalArtifact(@NotNull ExternalArtifactProvider externalRepository, String urlSuffix, @NotNull Long moduleId); + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + Long countLocalArtifactsAll(); + + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) + Long countExternalArtifactsAll(); + /** * Persists {@link ExternalArtifactProvider} based on given properties. * diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/Constants.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/Constants.java index 114997fca..0e3f74730 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/Constants.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/Constants.java @@ -9,6 +9,7 @@ package org.eclipse.hawkbit.repository; import org.eclipse.hawkbit.repository.model.ActionStatus; +import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.Target; /** @@ -24,6 +25,12 @@ public final class Constants { */ public static final String SERVER_MESSAGE_PREFIX = "Update Server: "; + /** + * Number of {@link DistributionSetType}s that are generated as part of + * default tenant setup. + */ + public static final int DEFAULT_DS_TYPES_IN_TENANT = 2; + private Constants() { // Utility class. } diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java index cb325cbc9..90bb7068b 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java @@ -9,10 +9,8 @@ package org.eclipse.hawkbit.repository; import java.net.URI; -import java.util.Collection; import java.util.List; import java.util.Map; -import java.util.concurrent.TimeUnit; import javax.validation.constraints.NotNull; @@ -268,61 +266,4 @@ public interface ControllerManagement { TargetInfo updateTargetStatus(@NotNull TargetInfo targetInfo, TargetUpdateStatus status, Long lastTargetQuery, URI address); - /** - * Generates an empty {@link ActionStatus} object without persisting it. - * - * @return {@link ActionStatus} object - */ - ActionStatus generateActionStatus(); - - /** - * Generates an {@link ActionStatus} object without persisting it. - * - * @param action - * the {@link ActionStatus} belongs to. - * @param status - * as reflected by this {@link ActionStatus}. - * @param occurredAt - * time in {@link TimeUnit#MILLISECONDS} GMT when the status - * change happened. - * @param message - * optional comment - * - * @return {@link ActionStatus} object - */ - ActionStatus generateActionStatus(Action action, Status status, Long occurredAt, final String message); - - /** - * Generates an {@link ActionStatus} object without persisting it. - * - * @param action - * the {@link ActionStatus} belongs to. - * @param status - * as reflected by this {@link ActionStatus}. - * @param occurredAt - * time in {@link TimeUnit#MILLISECONDS} GMT when the status - * change happened. - * @param messages - * optional comments - * - * @return {@link ActionStatus} object - */ - ActionStatus generateActionStatus(Action action, final Status status, Long occurredAt, - final Collection messages); - - /** - * Generates an {@link ActionStatus} object without persisting it. - * - * @param action - * the {@link ActionStatus} belongs to. - * @param status - * as reflected by this {@link ActionStatus}. - * @param occurredAt - * time in {@link TimeUnit#MILLISECONDS} GMT when the status - * change happened. - * - * @return {@link ActionStatus} object - */ - ActionStatus generateActionStatus(Action action, Status status, Long occurredAt); - } diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java index 6a6c7851d..59518f854 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java @@ -187,6 +187,12 @@ public interface DeploymentManagement { @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) Long countActionsByTarget(@NotNull String rsqlParam, @NotNull Target target); + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + Long countActionStatusAll(); + + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + Long countActionsAll(); + /** * counts all actions associated to a specific target. * @@ -274,6 +280,9 @@ public interface DeploymentManagement { @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) Slice findActionsByTarget(@NotNull Pageable pageable, @NotNull Target target); + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + Slice findActionsByDistributionSet(@NotNull Pageable pageable, @NotNull DistributionSet ds); + /** * Retrieves all {@link Action}s assigned to a specific {@link Target} and a * given specification. @@ -453,13 +462,6 @@ public interface DeploymentManagement { + SpringEvalExpressions.IS_SYSTEM_CODE) Action startScheduledAction(@NotNull Action action); - /** - * Generates an empty {@link Action} without persisting it. - * - * @return {@link Action} object - */ - Action generateAction(); - /** * All {@link ActionStatus} entries in the repository. * diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java index 3e31a5a9c..a2e7e5213 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java @@ -473,26 +473,6 @@ public interface DistributionSetManagement { @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) DistributionSetMetadata findOne(@NotNull DistributionSet distributionSet, @NotNull String key); - /** - * Generates an empty {@link DistributionSet} without persisting it. - * - * @return {@link DistributionSet} object - */ - DistributionSet generateDistributionSet(); - - DistributionSetMetadata generateDistributionSetMetadata(); - - DistributionSetMetadata generateDistributionSetMetadata(DistributionSet distributionSet, String key, String value); - - /** - * Generates an empty {@link DistributionSetType} without persisting it. - * - * @return {@link DistributionSetType} object - */ - DistributionSetType generateDistributionSetType(); - - DistributionSetType generateDistributionSetType(String key, String name, String description); - /** * Checks if a {@link DistributionSet} is currently in use by a target in * the repository. @@ -615,7 +595,4 @@ public interface DistributionSetManagement { @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) DistributionSetType updateDistributionSetType(@NotNull DistributionSetType dsType); - DistributionSet generateDistributionSet(String name, String version, String description, DistributionSetType type, - Collection moduleList); - } diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/EntityFactory.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/EntityFactory.java new file mode 100644 index 000000000..85a2f5e76 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/EntityFactory.java @@ -0,0 +1,333 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository; + +import java.util.Collection; +import java.util.concurrent.TimeUnit; + +import org.eclipse.hawkbit.repository.model.Action; +import org.eclipse.hawkbit.repository.model.Action.Status; +import org.eclipse.hawkbit.repository.model.ActionStatus; +import org.eclipse.hawkbit.repository.model.BaseEntity; +import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.DistributionSetMetadata; +import org.eclipse.hawkbit.repository.model.DistributionSetTag; +import org.eclipse.hawkbit.repository.model.DistributionSetType; +import org.eclipse.hawkbit.repository.model.Rollout; +import org.eclipse.hawkbit.repository.model.RolloutGroup; +import org.eclipse.hawkbit.repository.model.SoftwareModule; +import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata; +import org.eclipse.hawkbit.repository.model.SoftwareModuleType; +import org.eclipse.hawkbit.repository.model.Target; +import org.eclipse.hawkbit.repository.model.TargetFilterQuery; +import org.eclipse.hawkbit.repository.model.TargetTag; +import org.hibernate.validator.constraints.NotEmpty; + +/** + * central {@link BaseEntity} generation service. Objects are created but not + * persisted. + * + */ +public interface EntityFactory { + + /** + * Generates an empty {@link Action} without persisting it. + * + * @return {@link Action} object + */ + Action generateAction(); + + /** + * Generates an empty {@link ActionStatus} object without persisting it. + * + * @return {@link ActionStatus} object + */ + ActionStatus generateActionStatus(); + + /** + * Generates an {@link ActionStatus} object without persisting it. + * + * @param action + * the {@link ActionStatus} belongs to. + * @param status + * as reflected by this {@link ActionStatus}. + * @param occurredAt + * time in {@link TimeUnit#MILLISECONDS} GMT when the status + * change happened. + * + * @return {@link ActionStatus} object + */ + ActionStatus generateActionStatus(Action action, Status status, Long occurredAt); + + /** + * Generates an {@link ActionStatus} object without persisting it. + * + * @param action + * the {@link ActionStatus} belongs to. + * @param status + * as reflected by this {@link ActionStatus}. + * @param occurredAt + * time in {@link TimeUnit#MILLISECONDS} GMT when the status + * change happened. + * @param messages + * optional comments + * + * @return {@link ActionStatus} object + */ + ActionStatus generateActionStatus(Action action, final Status status, Long occurredAt, + final Collection messages); + + /** + * Generates an {@link ActionStatus} object without persisting it. + * + * @param action + * the {@link ActionStatus} belongs to. + * @param status + * as reflected by this {@link ActionStatus}. + * @param occurredAt + * time in {@link TimeUnit#MILLISECONDS} GMT when the status + * change happened. + * @param message + * optional comment + * + * @return {@link ActionStatus} object + */ + ActionStatus generateActionStatus(Action action, Status status, Long occurredAt, final String message); + + /** + * Generates an empty {@link DistributionSet} without persisting it. + * + * @return {@link DistributionSet} object + */ + DistributionSet generateDistributionSet(); + + /** + * Generates an {@link DistributionSet} without persisting it. + * + * @param name + * {@link DistributionSet#getName()} + * @param version + * {@link DistributionSet#getVersion()} + * @param description + * {@link DistributionSet#getDescription()} + * @param type + * {@link DistributionSet#getType()} + * @param moduleList + * {@link DistributionSet#getModules()} + * + * @return {@link DistributionSet} object + */ + DistributionSet generateDistributionSet(String name, String version, String description, DistributionSetType type, + Collection moduleList); + + /** + * Generates an empty {@link DistributionSetMetadata} element without + * persisting it. + * + * @return {@link DistributionSetMetadata} object + */ + DistributionSetMetadata generateDistributionSetMetadata(); + + /** + * Generates an {@link DistributionSetMetadata} element without persisting + * it. + * + * @param distributionSet + * {@link DistributionSetMetadata#getDistributionSet()} + * @param key + * {@link DistributionSetMetadata#getKey()} + * @param value + * {@link DistributionSetMetadata#getValue()} + * + * @return {@link DistributionSetMetadata} object + */ + DistributionSetMetadata generateDistributionSetMetadata(DistributionSet distributionSet, String key, String value); + + /** + * Generates an empty {@link DistributionSetTag} without persisting it. + * + * @return {@link DistributionSetTag} object + */ + DistributionSetTag generateDistributionSetTag(); + + /** + * Generates a {@link DistributionSetTag} without persisting it. + * + * @param name + * of the tag + * @return {@link DistributionSetTag} object + */ + DistributionSetTag generateDistributionSetTag(String name); + + /** + * Generates a {@link DistributionSetTag} without persisting it. + * + * @param name + * of the tag + * @param description + * of the tag + * @param colour + * of the tag + * @return {@link DistributionSetTag} object + */ + DistributionSetTag generateDistributionSetTag(String name, String description, String colour); + + /** + * Generates an empty {@link DistributionSetType} without persisting it. + * + * @return {@link DistributionSetType} object + */ + DistributionSetType generateDistributionSetType(); + + /** + * Generates a {@link DistributionSetType} without persisting it. + * + * @param key + * {@link DistributionSetType#getKey()} + * @param name + * {@link DistributionSetType#getName()} + * @param description + * {@link DistributionSetType#getDescription()} + * + * @return {@link DistributionSetType} object + */ + DistributionSetType generateDistributionSetType(String key, String name, String description); + + /** + * Generates an empty {@link Rollout} without persisting it. + * + * @return {@link Rollout} object + */ + Rollout generateRollout(); + + /** + * Generates an empty {@link RolloutGroup} without persisting it. + * + * @return {@link RolloutGroup} object + */ + RolloutGroup generateRolloutGroup(); + + /** + * Generates an empty {@link SoftwareModule} without persisting it. + * + * @return {@link SoftwareModule} object + */ + SoftwareModule generateSoftwareModule(); + + /** + * Generates a {@link SoftwareModule} without persisting it. + * + * @param type + * of the {@link SoftwareModule} + * @param name + * abstract name of the {@link SoftwareModule} + * @param version + * of the {@link SoftwareModule} + * @param description + * of the {@link SoftwareModule} + * @param vendor + * of the {@link SoftwareModule} + * + * @return {@link SoftwareModule} object + */ + SoftwareModule generateSoftwareModule(SoftwareModuleType type, String name, String version, String description, + String vendor); + + /** + * Generates an empty {@link SoftwareModuleMetadata} pair without persisting + * it. + * + * @return {@link SoftwareModuleMetadata} object + */ + SoftwareModuleMetadata generateSoftwareModuleMetadata(); + + /** + * Generates a {@link SoftwareModuleMetadata} pair without persisting it. + * + * @param softwareModule + * {@link SoftwareModuleMetadata#getSoftwareModule()} + * @param key + * {@link SoftwareModuleMetadata#getKey()} + * @param value + * {@link SoftwareModuleMetadata#getValue()} + * + * @return {@link SoftwareModuleMetadata} object + */ + SoftwareModuleMetadata generateSoftwareModuleMetadata(SoftwareModule softwareModule, String key, String value); + + /** + * Generates an empty {@link SoftwareModuleType} without persisting it. + * + * @return {@link SoftwareModuleType} object + */ + SoftwareModuleType generateSoftwareModuleType(); + + /** + * Generates a {@link SoftwareModuleType} without persisting it. + * + * @param key + * {@link SoftwareModuleType#getKey()} + * @param name + * {@link SoftwareModuleType#getName()} + * @param description + * {@link SoftwareModuleType#getDescription()} + * @param maxAssignments + * {@link SoftwareModuleType#getMaxAssignments()} + * + * @return {@link SoftwareModuleType} object + */ + SoftwareModuleType generateSoftwareModuleType(String key, String name, String description, int maxAssignments); + + /** + * Generates an empty {@link Target} without persisting it. + * + * @param controllerID + * of the {@link Target} + * + * @return {@link Target} object + */ + Target generateTarget(@NotEmpty String controllerID); + + /** + * Generates an empty {@link TargetFilterQuery} without persisting it. + * + * @return {@link TargetFilterQuery} object + */ + TargetFilterQuery generateTargetFilterQuery(); + + /** + * Generates an empty {@link TargetTag} without persisting it. + * + * @return {@link TargetTag} object + */ + TargetTag generateTargetTag(); + + /** + * Generates a {@link TargetTag} without persisting it. + * + * @param name + * of the tag + * @return {@link TargetTag} object + */ + TargetTag generateTargetTag(String name); + + /** + * Generates a {@link TargetTag} without persisting it. + * + * @param name + * of the tag + * @param description + * of the tag + * @param colour + * of the tag + * @return {@link TargetTag} object + */ + TargetTag generateTargetTag(String name, String description, String colour); + +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/OffsetBasedPageRequest.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/OffsetBasedPageRequest.java index f28047666..bf7807db0 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/OffsetBasedPageRequest.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/OffsetBasedPageRequest.java @@ -62,4 +62,31 @@ public final class OffsetBasedPageRequest extends PageRequest { return "OffsetBasedPageRequest [offset=" + offset + ", getPageSize()=" + getPageSize() + ", getPageNumber()=" + getPageNumber() + "]"; } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + offset; + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (!super.equals(obj)) { + return false; + } + if (!(obj instanceof OffsetBasedPageRequest)) { + return false; + } + final OffsetBasedPageRequest other = (OffsetBasedPageRequest) obj; + if (offset != other.offset) { + return false; + } + return true; + } + } diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupManagement.java index d1d3678f5..512b9af3c 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutGroupManagement.java @@ -150,11 +150,4 @@ public interface RolloutGroupManagement { */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_READ) RolloutGroup findRolloutGroupWithDetailedStatus(@NotNull Long rolloutGroupId); - - /** - * Generates an empty {@link RolloutGroup} without persisting it. - * - * @return {@link RolloutGroup} object - */ - RolloutGroup generateRolloutGroup(); } \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java index 4753e70ef..2c6e85dda 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java @@ -341,11 +341,4 @@ public interface RolloutManagement { @PreAuthorize(SpringEvalExpressions.HAS_AUTH_ROLLOUT_MANAGEMENT_WRITE) Rollout updateRollout(@NotNull Rollout rollout); - /** - * Generates an empty {@link Rollout} without persisting it. - * - * @return {@link Rollout} object - */ - Rollout generateRollout(); - } diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java index 9723dfd73..0934e871e 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java @@ -483,50 +483,4 @@ public interface SoftwareManagement { @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) SoftwareModuleType updateSoftwareModuleType(@NotNull SoftwareModuleType sm); - /** - * Generates an empty {@link SoftwareModuleType} without persisting it. - * - * @return {@link SoftwareModuleType} object - */ - SoftwareModuleType generateSoftwareModuleType(); - - /** - * Generates an empty {@link SoftwareModule} without persisting it. - * - * @return {@link SoftwareModule} object - */ - SoftwareModule generateSoftwareModule(); - - /** - * Generates a {@link SoftwareModule} without persisting it. - * - * @param type - * of the {@link SoftwareModule} - * @param name - * abstract name of the {@link SoftwareModule} - * @param version - * of the {@link SoftwareModule} - * @param description - * of the {@link SoftwareModule} - * @param vendor - * of the {@link SoftwareModule} - * - * @return {@link SoftwareModule} object - */ - SoftwareModule generateSoftwareModule(SoftwareModuleType type, String name, String version, String description, - String vendor); - - /** - * Generates an empty {@link SoftwareModuleMetadata} pair without persisting - * it. - * - * @return {@link SoftwareModuleMetadata} object - */ - SoftwareModuleMetadata generateSoftwareModuleMetadata(); - - SoftwareModuleMetadata generateSoftwareModuleMetadata(SoftwareModule softwareModule, String key, String value); - - SoftwareModuleType generateSoftwareModuleType(final String key, final String name, final String description, - final int maxAssignments); - } diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java index 19138ae9b..5cc17e09b 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java @@ -13,6 +13,8 @@ import java.util.List; import javax.validation.constraints.NotNull; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; +import org.eclipse.hawkbit.repository.model.DistributionSetType; +import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.repository.model.TenantMetaData; import org.eclipse.hawkbit.repository.report.model.SystemUsageReport; import org.eclipse.hawkbit.tenancy.TenantAware; @@ -39,7 +41,8 @@ public interface SystemManagement { * @param tenant * to delete */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_SYSTEM_ADMIN) + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_SYSTEM_ADMIN + SpringEvalExpressions.HAS_AUTH_OR + + SpringEvalExpressions.IS_SYSTEM_CODE) void deleteTenant(@NotNull String tenant); /** @@ -69,7 +72,10 @@ public interface SystemManagement { KeyGenerator currentTenantKeyGenerator(); /** - * Returns {@link TenantMetaData} of given and current tenant. + * Returns {@link TenantMetaData} of given and current tenant. Creates for + * new tenants also two {@link SoftwareModuleType} (os and app) and + * {@link Constants#DEFAULT_DS_TYPES_IN_TENANT} {@link DistributionSetType}s + * (os and os_app). * * DISCLAIMER: this variant is used during initial login (where the tenant * is not yet in the session). Please user {@link #getTenantMetadata()} for diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TagManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TagManagement.java index 85e5d0273..1b80444b5 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TagManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TagManagement.java @@ -245,62 +245,4 @@ public interface TagManagement { @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET) TargetTag updateTargetTag(@NotNull TargetTag targetTag); - /** - * Generates an empty {@link TargetTag} without persisting it. - * - * @return {@link TargetTag} object - */ - TargetTag generateTargetTag(); - - /** - * Generates an empty {@link DistributionSetTag} without persisting it. - * - * @return {@link DistributionSetTag} object - */ - DistributionSetTag generateDistributionSetTag(); - - /** - * Generates a {@link TargetTag} without persisting it. - * - * @param name - * of the tag - * @param description - * of the tag - * @param colour - * of the tag - * @return {@link TargetTag} object - */ - TargetTag generateTargetTag(String name, String description, String colour); - - /** - * Generates a {@link TargetTag} without persisting it. - * - * @param name - * of the tag - * @return {@link TargetTag} object - */ - TargetTag generateTargetTag(String name); - - /** - * Generates a {@link DistributionSetTag} without persisting it. - * - * @param name - * of the tag - * @param description - * of the tag - * @param colour - * of the tag - * @return {@link DistributionSetTag} object - */ - DistributionSetTag generateDistributionSetTag(String name, String description, String colour); - - /** - * Generates a {@link DistributionSetTag} without persisting it. - * - * @param name - * of the tag - * @return {@link DistributionSetTag} object - */ - DistributionSetTag generateDistributionSetTag(String name); - } diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagement.java index 127e22e63..48018b9ec 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagement.java @@ -95,11 +95,4 @@ public interface TargetFilterQueryManagement { */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET) TargetFilterQuery updateTargetFilterQuery(@NotNull TargetFilterQuery targetFilterQuery); - - /** - * Generates an empty {@link TargetFilterQuery} without persisting it. - * - * @return {@link TargetFilterQuery} object - */ - TargetFilterQuery generateTargetFilterQuery(); } \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java index 7ebb3e4b4..9280e065d 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java @@ -601,14 +601,4 @@ public interface TargetManagement { + SpringEvalExpressions.IS_CONTROLLER) List updateTargets(@NotNull Collection targets); - /** - * Generates an empty {@link Target} without persisting it. - * - * @param controllerID - * of the {@link Target} - * - * @return {@link Target} object - */ - Target generateTarget(@NotEmpty String controllerID); - } \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TenantStatsManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TenantStatsManagement.java index 32ecdcce4..6d390c03c 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TenantStatsManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TenantStatsManagement.java @@ -16,6 +16,7 @@ import org.springframework.security.access.prepost.PreAuthorize; * Management service for statistics of a single tenant. * */ +@FunctionalInterface public interface TenantStatsManagement { /** diff --git a/hawkbit-repository/hawkbit-repository-core/pom.xml b/hawkbit-repository/hawkbit-repository-core/pom.xml new file mode 100644 index 000000000..77e20cf3c --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-core/pom.xml @@ -0,0 +1,29 @@ + + + 4.0.0 + + org.eclipse.hawkbit + hawkbit-repository + 0.2.0-SNAPSHOT + + hawkbit-repository-core + hawkBit :: Repository Core Implementation Support + + + + org.eclipse.hawkbit + hawkbit-repository-api + ${project.version} + + + + \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/SystemManagementHolder.java b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/SystemManagementHolder.java similarity index 100% rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/SystemManagementHolder.java rename to hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/SystemManagementHolder.java diff --git a/hawkbit-repository/hawkbit-repository-jpa/pom.xml b/hawkbit-repository/hawkbit-repository-jpa/pom.xml index e61ad8325..49a19530f 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/pom.xml +++ b/hawkbit-repository/hawkbit-repository-jpa/pom.xml @@ -52,19 +52,20 @@ hawkbit-repository-api ${project.version} + + org.eclipse.hawkbit + hawkbit-repository-core + ${project.version} + org.eclipse.hawkbit hawkbit-artifact-repository-mongo ${project.version} - + com.google.guava guava - - net._01001111 - jlorem - org.springframework.boot spring-boot @@ -96,6 +97,12 @@ + + org.eclipse.hawkbit + hawkbit-repository-test + ${project.version} + test + com.h2database h2 @@ -121,21 +128,11 @@ allure-junit-adaptor test - - - - - org.springframework.security spring-security-aspects test - - - org.springframework.boot - spring-boot-starter-test - test - +
org.springframework spring-test @@ -150,12 +147,7 @@ org.easytesting fest-assert test - - - de.flapdoodle.embed - de.flapdoodle.embed.mongo - test - + org.springframework.security spring-security-config @@ -170,7 +162,6 @@ cz.jirutka.rsql rsql-parser - diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/fbExcludeFilter.xml b/hawkbit-repository/hawkbit-repository-jpa/src/fbExcludeFilter.xml deleted file mode 100644 index bd85e5e73..000000000 --- a/hawkbit-repository/hawkbit-repository-jpa/src/fbExcludeFilter.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/EnableJpaRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/EnableJpaRepository.java new file mode 100644 index 000000000..f15ec8c82 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/EnableJpaRepository.java @@ -0,0 +1,33 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; +import org.springframework.stereotype.Controller; + +/** + * Annotation to enable {@link ComponentScan} in the resource package to setup + * all {@link Controller} annotated classes and setup the REST-Resources for the + * Management API. + */ +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Configuration +@ComponentScan +@Import(RepositoryApplicationConfiguration.class) +public @interface EnableJpaRepository { + +} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java index afb6f4245..5f5a46c0b 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java @@ -47,11 +47,10 @@ import org.springframework.validation.beanvalidation.MethodValidationPostProcess @EnableTransactionManagement @EnableJpaAuditing @EnableAspectJAutoProxy -@Configuration @ComponentScan +@Configuration @EnableAutoConfiguration public class RepositoryApplicationConfiguration extends JpaBaseConfiguration { - /** * @return the {@link SystemSecurityContext} singleton bean which make it * accessible in beans which cannot access the service directly, diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaArtifactManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaArtifactManagement.java index 93e0afc00..ea0e5c34f 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaArtifactManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaArtifactManagement.java @@ -288,4 +288,14 @@ public class JpaArtifactManagement implements ArtifactManagement { final boolean overrideExisting, final String contentType) { return createLocalArtifact(inputStream, moduleId, filename, null, null, overrideExisting, contentType); } + + @Override + public Long countLocalArtifactsAll() { + return localArtifactRepository.count(); + } + + @Override + public Long countExternalArtifactsAll() { + return externalArtifactRepository.count(); + } } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java index 653d02870..43b8534af 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java @@ -10,7 +10,6 @@ package org.eclipse.hawkbit.repository.jpa; import java.net.URI; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import java.util.Map; @@ -55,7 +54,6 @@ import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.repository.Modifying; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Isolation; -import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; @@ -438,33 +436,4 @@ public class JpaControllerManagement implements ControllerManagement { return updateTargetStatus(target, null, System.currentTimeMillis(), address); } - @Override - @Transactional(propagation = Propagation.SUPPORTS) - public ActionStatus generateActionStatus() { - return new JpaActionStatus(); - } - - @Override - @Transactional(propagation = Propagation.SUPPORTS) - public ActionStatus generateActionStatus(final Action action, final Status status, final Long occurredAt, - final String message) { - return new JpaActionStatus((JpaAction) action, status, occurredAt, message); - } - - @Override - @Transactional(propagation = Propagation.SUPPORTS) - public ActionStatus generateActionStatus(final Action action, final Status status, final Long occurredAt, - final Collection messages) { - - final ActionStatus result = new JpaActionStatus((JpaAction) action, status, occurredAt, null); - messages.forEach(result::addMessage); - - return result; - } - - @Override - @Transactional(propagation = Propagation.SUPPORTS) - public ActionStatus generateActionStatus(final Action action, final Status status, final Long occurredAt) { - return new JpaActionStatus(action, status, occurredAt); - } } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java index aa843d8fc..cefa5e937 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java @@ -84,7 +84,6 @@ import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.repository.Modifying; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Isolation; -import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; @@ -155,7 +154,8 @@ public class JpaDeploymentManagement implements DeploymentManagement { @Transactional(isolation = Isolation.READ_COMMITTED) @CacheEvict(value = { "distributionUsageAssigned" }, allEntries = true) public DistributionSetAssignmentResult assignDistributionSet(final Long dsID, final String... targetIDs) { - return assignDistributionSet(dsID, ActionType.FORCED, org.eclipse.hawkbit.repository.model.Constants.NO_FORCE_TIME, targetIDs); + return assignDistributionSet(dsID, ActionType.FORCED, + org.eclipse.hawkbit.repository.model.Constants.NO_FORCE_TIME, targetIDs); } @Override @@ -683,12 +683,6 @@ public class JpaDeploymentManagement implements DeploymentManagement { return actionRepository.findByRolloutAndStatus((JpaRollout) rollout, actionStatus); } - @Override - @Transactional(propagation = Propagation.SUPPORTS) - public Action generateAction() { - return new JpaAction(); - } - @Override public Page findActionStatusAll(final Pageable pageable) { return convertAcSPage(actionStatusRepository.findAll(pageable), pageable); @@ -697,4 +691,19 @@ public class JpaDeploymentManagement implements DeploymentManagement { private static Page convertAcSPage(final Page findAll, final Pageable pageable) { return new PageImpl<>(new ArrayList<>(findAll.getContent()), pageable, findAll.getTotalElements()); } + + @Override + public Long countActionStatusAll() { + return actionStatusRepository.count(); + } + + @Override + public Long countActionsAll() { + return actionRepository.count(); + } + + @Override + public Slice findActionsByDistributionSet(final Pageable pageable, final DistributionSet ds) { + return actionRepository.findByDistributionSet(pageable, (JpaDistributionSet) ds); + } } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java index 426733bcc..e5a38cf51 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java @@ -62,7 +62,6 @@ import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.repository.Modifying; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Isolation; -import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; @@ -739,45 +738,6 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { return toggleTagAssignment(sets.stream().map(ds -> ds.getId()).collect(Collectors.toList()), tag.getName()); } - @Override - @Transactional(propagation = Propagation.SUPPORTS) - public DistributionSetType generateDistributionSetType() { - return new JpaDistributionSetType(); - } - - @Override - @Transactional(propagation = Propagation.SUPPORTS) - public DistributionSet generateDistributionSet() { - return new JpaDistributionSet(); - } - - @Override - @Transactional(propagation = Propagation.SUPPORTS) - public DistributionSetMetadata generateDistributionSetMetadata() { - return new JpaDistributionSetMetadata(); - } - - @Override - @Transactional(propagation = Propagation.SUPPORTS) - public DistributionSetMetadata generateDistributionSetMetadata(final DistributionSet distributionSet, - final String key, final String value) { - return new JpaDistributionSetMetadata(key, distributionSet, value); - } - - @Override - @Transactional(propagation = Propagation.SUPPORTS) - public DistributionSetType generateDistributionSetType(final String key, final String name, - final String description) { - return new JpaDistributionSetType(key, name, description); - } - - @Override - @Transactional(propagation = Propagation.SUPPORTS) - public DistributionSet generateDistributionSet(final String name, final String version, final String description, - final DistributionSetType type, final Collection moduleList) { - return new JpaDistributionSet(name, version, description, type, moduleList); - } - @Override public Long countDistributionSetsByType(final DistributionSetType type) { return distributionSetRepository.countByType((JpaDistributionSetType) type); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaEntityFactory.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaEntityFactory.java new file mode 100644 index 000000000..88c34ad11 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaEntityFactory.java @@ -0,0 +1,201 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.jpa; + +import java.util.Collection; + +import org.eclipse.hawkbit.repository.EntityFactory; +import org.eclipse.hawkbit.repository.jpa.model.JpaAction; +import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetMetadata; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag; +import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType; +import org.eclipse.hawkbit.repository.jpa.model.JpaRollout; +import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup; +import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; +import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleMetadata; +import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType; +import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; +import org.eclipse.hawkbit.repository.jpa.model.JpaTargetFilterQuery; +import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag; +import org.eclipse.hawkbit.repository.model.Action; +import org.eclipse.hawkbit.repository.model.Action.Status; +import org.eclipse.hawkbit.repository.model.ActionStatus; +import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.DistributionSetMetadata; +import org.eclipse.hawkbit.repository.model.DistributionSetTag; +import org.eclipse.hawkbit.repository.model.DistributionSetType; +import org.eclipse.hawkbit.repository.model.Rollout; +import org.eclipse.hawkbit.repository.model.RolloutGroup; +import org.eclipse.hawkbit.repository.model.SoftwareModule; +import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata; +import org.eclipse.hawkbit.repository.model.SoftwareModuleType; +import org.eclipse.hawkbit.repository.model.Target; +import org.eclipse.hawkbit.repository.model.TargetFilterQuery; +import org.eclipse.hawkbit.repository.model.TargetTag; +import org.springframework.stereotype.Service; + +/** + * JPA Implementation of {@link EntityFactory}. + * + */ +@Service +public class JpaEntityFactory implements EntityFactory { + + @Override + public DistributionSetType generateDistributionSetType() { + return new JpaDistributionSetType(); + } + + @Override + public DistributionSet generateDistributionSet() { + return new JpaDistributionSet(); + } + + @Override + public DistributionSetMetadata generateDistributionSetMetadata() { + return new JpaDistributionSetMetadata(); + } + + @Override + public DistributionSetMetadata generateDistributionSetMetadata(final DistributionSet distributionSet, + final String key, final String value) { + return new JpaDistributionSetMetadata(key, distributionSet, value); + } + + @Override + public DistributionSetType generateDistributionSetType(final String key, final String name, + final String description) { + return new JpaDistributionSetType(key, name, description); + } + + @Override + public DistributionSet generateDistributionSet(final String name, final String version, final String description, + final DistributionSetType type, final Collection moduleList) { + return new JpaDistributionSet(name, version, description, type, moduleList); + } + + @Override + public Target generateTarget(final String controllerId) { + return new JpaTarget(controllerId); + } + + @Override + public TargetTag generateTargetTag() { + return new JpaTargetTag(); + } + + @Override + public DistributionSetTag generateDistributionSetTag() { + return new JpaDistributionSetTag(); + } + + @Override + public TargetTag generateTargetTag(final String name, final String description, final String colour) { + return new JpaTargetTag(name, description, colour); + } + + @Override + public DistributionSetTag generateDistributionSetTag(final String name, final String description, + final String colour) { + return new JpaDistributionSetTag(name, description, colour); + } + + @Override + public TargetTag generateTargetTag(final String name) { + return new JpaTargetTag(name); + } + + @Override + public DistributionSetTag generateDistributionSetTag(final String name) { + return new JpaDistributionSetTag(name); + } + + @Override + public TargetFilterQuery generateTargetFilterQuery() { + return new JpaTargetFilterQuery(); + } + + @Override + public SoftwareModuleType generateSoftwareModuleType() { + return new JpaSoftwareModuleType(); + } + + @Override + public SoftwareModule generateSoftwareModule() { + return new JpaSoftwareModule(); + } + + @Override + public SoftwareModule generateSoftwareModule(final SoftwareModuleType type, final String name, final String version, + final String description, final String vendor) { + + return new JpaSoftwareModule(type, name, version, description, vendor); + } + + @Override + public SoftwareModuleMetadata generateSoftwareModuleMetadata() { + return new JpaSoftwareModuleMetadata(); + } + + @Override + public SoftwareModuleMetadata generateSoftwareModuleMetadata(final SoftwareModule softwareModule, final String key, + final String value) { + return new JpaSoftwareModuleMetadata(key, softwareModule, value); + } + + @Override + public SoftwareModuleType generateSoftwareModuleType(final String key, final String name, final String description, + final int maxAssignments) { + return new JpaSoftwareModuleType(key, name, description, maxAssignments); + } + + @Override + public Rollout generateRollout() { + return new JpaRollout(); + } + + @Override + public RolloutGroup generateRolloutGroup() { + return new JpaRolloutGroup(); + } + + @Override + public Action generateAction() { + return new JpaAction(); + } + + @Override + public ActionStatus generateActionStatus() { + return new JpaActionStatus(); + } + + @Override + public ActionStatus generateActionStatus(final Action action, final Status status, final Long occurredAt, + final String message) { + return new JpaActionStatus((JpaAction) action, status, occurredAt, message); + } + + @Override + public ActionStatus generateActionStatus(final Action action, final Status status, final Long occurredAt, + final Collection messages) { + + final ActionStatus result = new JpaActionStatus((JpaAction) action, status, occurredAt, null); + messages.forEach(result::addMessage); + + return result; + } + + @Override + public ActionStatus generateActionStatus(final Action action, final Status status, final Long occurredAt) { + return new JpaActionStatus(action, status, occurredAt); + } + +} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutGroupManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutGroupManagement.java index ea6214824..7d176d40a 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutGroupManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutGroupManagement.java @@ -49,7 +49,6 @@ import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Isolation; -import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; @@ -201,9 +200,4 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement { return new PageImpl<>(targetWithActionStatus, pageRequest, totalCount); } - @Override - @Transactional(propagation = Propagation.SUPPORTS) - public RolloutGroup generateRolloutGroup() { - return new JpaRolloutGroup(); - } } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java index b3e451932..d412d2164 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java @@ -667,9 +667,4 @@ public class JpaRolloutManagement implements RolloutManagement { return ((float) finished / (float) totalGroup) * 100; } - @Override - @Transactional(propagation = Propagation.SUPPORTS) - public Rollout generateRollout() { - return new JpaRollout(); - } } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java index eceec20d1..2fc057aec 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java @@ -62,7 +62,6 @@ import org.springframework.data.jpa.repository.Modifying; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Isolation; -import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; @@ -663,44 +662,4 @@ public class JpaSoftwareManagement implements SoftwareManagement { return types.stream().map(this::createSoftwareModuleType).collect(Collectors.toList()); } - @Override - @Transactional(propagation = Propagation.SUPPORTS) - public SoftwareModuleType generateSoftwareModuleType() { - return new JpaSoftwareModuleType(); - } - - @Override - @Transactional(propagation = Propagation.SUPPORTS) - public SoftwareModule generateSoftwareModule() { - return new JpaSoftwareModule(); - } - - @Override - @Transactional(propagation = Propagation.SUPPORTS) - public SoftwareModule generateSoftwareModule(final SoftwareModuleType type, final String name, final String version, - final String description, final String vendor) { - - return new JpaSoftwareModule(type, name, version, description, vendor); - } - - @Override - @Transactional(propagation = Propagation.SUPPORTS) - public SoftwareModuleMetadata generateSoftwareModuleMetadata() { - return new JpaSoftwareModuleMetadata(); - } - - @Override - @Transactional(propagation = Propagation.SUPPORTS) - public SoftwareModuleMetadata generateSoftwareModuleMetadata(final SoftwareModule softwareModule, final String key, - final String value) { - return new JpaSoftwareModuleMetadata(key, softwareModule, value); - } - - @Override - @Transactional(propagation = Propagation.SUPPORTS) - public SoftwareModuleType generateSoftwareModuleType(final String key, final String name, final String description, - final int maxAssignments) { - return new JpaSoftwareModuleType(key, name, description, maxAssignments); - } - } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java index 05d5d486e..be46362a5 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java @@ -259,28 +259,6 @@ public class JpaSystemManagement implements SystemManagement { return tenantMetaDataRepository.save((JpaTenantMetaData) metaData); } - private DistributionSetType createStandardSoftwareDataSetup() { - final SoftwareModuleType eclApp = softwareModuleTypeRepository.save(new JpaSoftwareModuleType("application", - "ECL Application", "Edge Controller Linux base application type", 1)); - final SoftwareModuleType eclOs = softwareModuleTypeRepository.save( - new JpaSoftwareModuleType("os", "ECL OS", "Edge Controller Linux operation system image type", 1)); - final SoftwareModuleType eclJvm = softwareModuleTypeRepository.save( - new JpaSoftwareModuleType("runtime", "ECL JVM", "Edge Controller Linux java virtual machine type.", 1)); - - distributionSetTypeRepository.save((JpaDistributionSetType) new JpaDistributionSetType("ecl_os", "OS only", - "Standard Edge Controller Linux distribution set type.").addMandatoryModuleType(eclOs)); - - distributionSetTypeRepository.save((JpaDistributionSetType) new JpaDistributionSetType("ecl_os_app", - "OS with optional app", "Standard Edge Controller Linux distribution set type. OS only.") - .addMandatoryModuleType(eclOs).addOptionalModuleType(eclApp)); - - return distributionSetTypeRepository.save( - (JpaDistributionSetType) new JpaDistributionSetType("ecl_os_app_jvm", "OS with optional app and jvm", - "Standard Edge Controller Linux distribution set type. OS with optional application.") - .addMandatoryModuleType(eclOs).addOptionalModuleType(eclApp) - .addOptionalModuleType(eclJvm)); - } - /** * A implementation of the {@link KeyGenerator} to generate a key based on * either the {@code createInitialTenant} thread local and the @@ -303,4 +281,18 @@ public class JpaSystemManagement implements SystemManagement { initialTenantCreation.toUpperCase()); } } + + private DistributionSetType createStandardSoftwareDataSetup() { + final SoftwareModuleType app = softwareModuleTypeRepository + .save(new JpaSoftwareModuleType("application", "Application", "Application Addons", Integer.MAX_VALUE)); + final SoftwareModuleType os = softwareModuleTypeRepository + .save(new JpaSoftwareModuleType("os", "Firmware", "Core firmware or operationg system", 1)); + + distributionSetTypeRepository.save((JpaDistributionSetType) new JpaDistributionSetType("os_app", "With app(s)", + "Default type with Firmware/OS and optional app(s).").addMandatoryModuleType(os) + .addOptionalModuleType(app)); + + return distributionSetTypeRepository.save((JpaDistributionSetType) new JpaDistributionSetType("os", "OS only", + "Default type with Firmware/OS only.").addMandatoryModuleType(os)); + } } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTagManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTagManagement.java index 9a44f1319..29fbb8a2b 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTagManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTagManagement.java @@ -41,7 +41,6 @@ import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.repository.Modifying; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Isolation; -import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; @@ -287,41 +286,4 @@ public class JpaTagManagement implements TagManagement { return convertDsPage(distributionSetTagRepository.findAll(spec, pageable), pageable); } - @Override - @Transactional(propagation = Propagation.SUPPORTS) - public TargetTag generateTargetTag() { - return new JpaTargetTag(); - } - - @Override - @Transactional(propagation = Propagation.SUPPORTS) - public DistributionSetTag generateDistributionSetTag() { - return new JpaDistributionSetTag(); - } - - @Override - @Transactional(propagation = Propagation.SUPPORTS) - public TargetTag generateTargetTag(final String name, final String description, final String colour) { - return new JpaTargetTag(name, description, colour); - } - - @Override - @Transactional(propagation = Propagation.SUPPORTS) - public DistributionSetTag generateDistributionSetTag(final String name, final String description, - final String colour) { - return new JpaDistributionSetTag(name, description, colour); - } - - @Override - @Transactional(propagation = Propagation.SUPPORTS) - public TargetTag generateTargetTag(final String name) { - return new JpaTargetTag(name); - } - - @Override - @Transactional(propagation = Propagation.SUPPORTS) - public DistributionSetTag generateDistributionSetTag(final String name) { - return new JpaDistributionSetTag(name); - } - } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetFilterQueryManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetFilterQueryManagement.java index 8bc4a0833..296483bf8 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetFilterQueryManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetFilterQueryManagement.java @@ -109,9 +109,4 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme return targetFilterQueryRepository.save((JpaTargetFilterQuery) targetFilterQuery); } - @Override - public TargetFilterQuery generateTargetFilterQuery() { - return new JpaTargetFilterQuery(); - } - } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetManagement.java index 8d2fabac7..892ddc771 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetManagement.java @@ -61,7 +61,6 @@ import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.repository.Modifying; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Isolation; -import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.Assert; import org.springframework.validation.annotation.Validated; @@ -403,7 +402,6 @@ public class JpaTargetManagement implements TargetManagement { @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) public Target unAssignTag(final String controllerID, final TargetTag targetTag) { - // TODO : optimize this, findone? final List allTargets = new ArrayList<>(targetRepository .findAll(TargetSpecifications.byControllerIdWithStatusAndTagsInJoin(Arrays.asList(controllerID)))); final List unAssignTag = unAssignTag(allTargets, targetTag); @@ -673,9 +671,4 @@ public class JpaTargetManagement implements TargetManagement { return resultList; } - @Override - @Transactional(propagation = Propagation.SUPPORTS) - public Target generateTarget(final String controllerId) { - return new JpaTarget(controllerId); - } } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/CacheFieldEntityListener.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/CacheFieldEntityListener.java index dddc01d91..b303f33a4 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/CacheFieldEntityListener.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/CacheFieldEntityListener.java @@ -53,16 +53,11 @@ public class CacheFieldEntityListener { @SuppressWarnings("rawtypes") final String id = ((Identifiable) target).getId().toString(); final Class type = target.getClass(); - findCacheFields(type, id, new CacheFieldCallback() { - @Override - public void fromCache(final Field field, final String cacheKey, final Serializable id) - throws IllegalAccessException { - final Cache cache = cacheManager.getCache(type.getName()); - final ValueWrapper valueWrapper = cache - .get(CacheKeys.entitySpecificCacheKey(id.toString(), cacheKey)); - if (valueWrapper != null && valueWrapper.get() != null) { - FieldUtils.writeField(field, target, valueWrapper.get(), true); - } + findCacheFields(type, id, (field, cacheKey, id1) -> { + final Cache cache = cacheManager.getCache(type.getName()); + final ValueWrapper valueWrapper = cache.get(CacheKeys.entitySpecificCacheKey(id1.toString(), cacheKey)); + if (valueWrapper != null && valueWrapper.get() != null) { + FieldUtils.writeField(field, target, valueWrapper.get(), true); } }); } @@ -82,13 +77,9 @@ public class CacheFieldEntityListener { @SuppressWarnings("rawtypes") final String id = ((Identifiable) target).getId().toString(); final Class type = target.getClass(); - findCacheFields(type, id, new CacheFieldCallback() { - @Override - public void fromCache(final Field field, final String cacheKey, final Serializable id) - throws IllegalAccessException { - final Cache cache = cacheManager.getCache(type.getName()); - cache.evict(CacheKeys.entitySpecificCacheKey(id.toString(), cacheKey)); - } + findCacheFields(type, id, (field, cacheKey, id1) -> { + final Cache cache = cacheManager.getCache(type.getName()); + cache.evict(CacheKeys.entitySpecificCacheKey(id1.toString(), cacheKey)); }); } } @@ -109,6 +100,7 @@ public class CacheFieldEntityListener { } } + @FunctionalInterface private interface CacheFieldCallback { /** * callback methods which is called by the diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rollout/condition/RolloutGroupConditionEvaluator.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rollout/condition/RolloutGroupConditionEvaluator.java index 642386c69..0690f72ec 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rollout/condition/RolloutGroupConditionEvaluator.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rollout/condition/RolloutGroupConditionEvaluator.java @@ -12,8 +12,9 @@ import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.RolloutGroup; /** - * + * Verifies {@link RolloutGroup#getErrorConditionExp()}. */ +@FunctionalInterface public interface RolloutGroupConditionEvaluator { default boolean verifyExpression(final String expression) { diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTest.java new file mode 100644 index 000000000..342e0792b --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTest.java @@ -0,0 +1,104 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.jpa; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; + +import org.eclipse.hawkbit.cache.TenantAwareCacheManager; +import org.eclipse.hawkbit.repository.util.AbstractIntegrationTest; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.data.mongodb.gridfs.GridFsOperations; + +@SpringApplicationConfiguration(classes = { org.eclipse.hawkbit.RepositoryApplicationConfiguration.class, + TestConfiguration.class }) +public abstract class AbstractJpaIntegrationTest extends AbstractIntegrationTest { + + @PersistenceContext + protected EntityManager entityManager; + + @Autowired + protected TargetRepository targetRepository; + + @Autowired + protected ActionRepository actionRepository; + + @Autowired + protected DistributionSetRepository distributionSetRepository; + + @Autowired + protected SoftwareModuleRepository softwareModuleRepository; + + @Autowired + protected TenantMetaDataRepository tenantMetaDataRepository; + + @Autowired + protected DistributionSetTypeRepository distributionSetTypeRepository; + + @Autowired + protected SoftwareModuleTypeRepository softwareModuleTypeRepository; + + @Autowired + protected TargetTagRepository targetTagRepository; + + @Autowired + protected DistributionSetTagRepository distributionSetTagRepository; + + @Autowired + protected SoftwareModuleMetadataRepository softwareModuleMetadataRepository; + + @Autowired + protected ActionStatusRepository actionStatusRepository; + + @Autowired + protected ExternalArtifactRepository externalArtifactRepository; + + @Autowired + protected LocalArtifactRepository artifactRepository; + + @Autowired + protected TargetInfoRepository targetInfoRepository; + + @Autowired + protected GridFsOperations operations; + + @Autowired + protected RolloutGroupRepository rolloutGroupRepository; + + @Autowired + protected RolloutRepository rolloutRepository; + + @Autowired + protected TenantAwareCacheManager cacheManager; + + private static CIMySqlTestDatabase tesdatabase; + + @BeforeClass + public static void beforeClass() { + createTestdatabaseAndStart(); + } + + private static void createTestdatabaseAndStart() { + if ("MYSQL".equals(System.getProperty("spring.jpa.database"))) { + tesdatabase = new CIMySqlTestDatabase(); + tesdatabase.before(); + } + } + + @AfterClass + public static void afterClass() { + if (tesdatabase != null) { + tesdatabase.after(); + } + } + +} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTestWithMongoDB.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTestWithMongoDB.java new file mode 100644 index 000000000..38a02c213 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTestWithMongoDB.java @@ -0,0 +1,104 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.jpa; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; + +import org.eclipse.hawkbit.cache.TenantAwareCacheManager; +import org.eclipse.hawkbit.repository.util.AbstractIntegrationTestWithMongoDB; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.data.mongodb.gridfs.GridFsOperations; + +@SpringApplicationConfiguration(classes = { org.eclipse.hawkbit.RepositoryApplicationConfiguration.class, + TestConfiguration.class }) +public abstract class AbstractJpaIntegrationTestWithMongoDB extends AbstractIntegrationTestWithMongoDB { + + @PersistenceContext + protected EntityManager entityManager; + + @Autowired + protected TargetRepository targetRepository; + + @Autowired + protected ActionRepository actionRepository; + + @Autowired + protected DistributionSetRepository distributionSetRepository; + + @Autowired + protected SoftwareModuleRepository softwareModuleRepository; + + @Autowired + protected TenantMetaDataRepository tenantMetaDataRepository; + + @Autowired + protected DistributionSetTypeRepository distributionSetTypeRepository; + + @Autowired + protected SoftwareModuleTypeRepository softwareModuleTypeRepository; + + @Autowired + protected TargetTagRepository targetTagRepository; + + @Autowired + protected DistributionSetTagRepository distributionSetTagRepository; + + @Autowired + protected SoftwareModuleMetadataRepository softwareModuleMetadataRepository; + + @Autowired + protected ActionStatusRepository actionStatusRepository; + + @Autowired + protected ExternalArtifactRepository externalArtifactRepository; + + @Autowired + protected LocalArtifactRepository artifactRepository; + + @Autowired + protected TargetInfoRepository targetInfoRepository; + + @Autowired + protected GridFsOperations operations; + + @Autowired + protected RolloutGroupRepository rolloutGroupRepository; + + @Autowired + protected RolloutRepository rolloutRepository; + + @Autowired + protected TenantAwareCacheManager cacheManager; + + private static CIMySqlTestDatabase tesdatabase; + + @BeforeClass + public static void beforeClass() { + createTestdatabaseAndStart(); + } + + private static void createTestdatabaseAndStart() { + if ("MYSQL".equals(System.getProperty("spring.jpa.database"))) { + tesdatabase = new CIMySqlTestDatabase(); + tesdatabase.before(); + } + } + + @AfterClass + public static void afterClass() { + if (tesdatabase != null) { + tesdatabase.after(); + } + } + +} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementNoMongoDbTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementNoMongoDbTest.java index fd91a2158..42b759b74 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementNoMongoDbTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementNoMongoDbTest.java @@ -29,7 +29,7 @@ import ru.yandex.qatools.allure.annotations.Stories; */ @Features("Component Tests - Repository") @Stories("Artifact Management") -public class ArtifactManagementNoMongoDbTest extends AbstractIntegrationTest { +public class ArtifactManagementNoMongoDbTest extends AbstractJpaIntegrationTest { @BeforeClass public static void initialize() { diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementTest.java index 4c37c00e3..ea6e8e01b 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementTest.java @@ -32,6 +32,7 @@ import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.ExternalArtifactProvider; import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; +import org.eclipse.hawkbit.repository.util.WithUser; import org.junit.Test; import org.slf4j.LoggerFactory; import org.springframework.data.mongodb.core.query.Criteria; @@ -50,7 +51,7 @@ import ru.yandex.qatools.allure.annotations.Stories; */ @Features("Component Tests - Repository") @Stories("Artifact Management") -public class ArtifactManagementTest extends AbstractIntegrationTestWithMongoDB { +public class ArtifactManagementTest extends AbstractJpaIntegrationTestWithMongoDB { public ArtifactManagementTest() { LOG = LoggerFactory.getLogger(ArtifactManagementTest.class); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ControllerManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ControllerManagementTest.java index c79c47af9..f33c5c170 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ControllerManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ControllerManagementTest.java @@ -33,14 +33,13 @@ import ru.yandex.qatools.allure.annotations.Stories; @Features("Component Tests - Repository") @Stories("Controller Management") -public class ControllerManagementTest extends AbstractIntegrationTest { +public class ControllerManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Controller adds a new action status.") public void controllerAddsActionStatus() { final Target target = new JpaTarget("4712"); - final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); + final DistributionSet ds = testdataFactory.createDistributionSet(""); Target savedTarget = targetManagement.createTarget(target); final List toAssign = new ArrayList<>(); @@ -99,8 +98,7 @@ public class ControllerManagementTest extends AbstractIntegrationTest { // mock final Target target = new JpaTarget("Rabbit"); - final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); + final DistributionSet ds = testdataFactory.createDistributionSet(""); Target savedTarget = targetManagement.createTarget(target); final List toAssign = new ArrayList<>(); toAssign.add(savedTarget); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DeploymentManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DeploymentManagementTest.java index 0900973d0..3d0114d67 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DeploymentManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DeploymentManagementTest.java @@ -67,7 +67,7 @@ import ru.yandex.qatools.allure.annotations.Stories; */ @Features("Component Tests - Repository") @Stories("Deployment Management") -public class DeploymentManagementTest extends AbstractIntegrationTest { +public class DeploymentManagementTest extends AbstractJpaIntegrationTest { @Autowired private EventBus eventBus; @@ -75,9 +75,9 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { @Test @Description("Test verifies that the repistory retrieves the action including all defined (lazy) details.") public void findActionWithLazyDetails() { - final DistributionSet testDs = TestDataUtil.generateDistributionSet("TestDs", "1.0", softwareManagement, - distributionSetManagement, new ArrayList()); - final List testTarget = targetManagement.createTargets(TestDataUtil.generateTargets(1)); + final DistributionSet testDs = testdataFactory.createDistributionSet("TestDs", "1.0", + new ArrayList()); + final List testTarget = testdataFactory.createTargets(1); // one action with one action status is generated final Long actionId = deploymentManagement.assignDistributionSet(testDs, testTarget).getActions().get(0); final Action action = deploymentManagement.findActionWithDetails(actionId); @@ -91,9 +91,9 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { @Test @Description("Test verifies that the custom query to find all actions include the count of action status is working correctly") public void findActionsWithStatusCountByTarget() { - final DistributionSet testDs = TestDataUtil.generateDistributionSet("TestDs", "1.0", softwareManagement, - distributionSetManagement, new ArrayList()); - final List testTarget = targetManagement.createTargets(TestDataUtil.generateTargets(1)); + final DistributionSet testDs = testdataFactory.createDistributionSet("TestDs", "1.0", + new ArrayList()); + final List testTarget = testdataFactory.createTargets(1); // one action with one action status is generated final Action action = deploymentManagement.findActionWithDetails( deploymentManagement.assignDistributionSet(testDs, testTarget).getActions().get(0)); @@ -114,8 +114,8 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { public void assignAndUnassignDistributionSetToTag() { final List assignDS = new ArrayList<>(); for (int i = 0; i < 4; i++) { - assignDS.add(TestDataUtil.generateDistributionSet("DS" + i, "1.0", softwareManagement, - distributionSetManagement, new ArrayList()).getId()); + assignDS.add(testdataFactory.createDistributionSet("DS" + i, "1.0", new ArrayList()) + .getId()); } // not exists assignDS.add(Long.valueOf(100)); @@ -154,14 +154,13 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { @Description("Test verifies that an assignment with automatic cancelation works correctly even if the update is split into multiple partitions on the database.") public void multiAssigmentHistoryOverMultiplePagesResultsInTwoActiveAction() { - final DistributionSet cancelDs = TestDataUtil.generateDistributionSet("Canceled DS", "1.0", softwareManagement, - distributionSetManagement, new ArrayList()); + final DistributionSet cancelDs = testdataFactory.createDistributionSet("Canceled DS", "1.0", + new ArrayList()); - final DistributionSet cancelDs2 = TestDataUtil.generateDistributionSet("Canceled DS", "1.2", softwareManagement, - distributionSetManagement, new ArrayList()); + final DistributionSet cancelDs2 = testdataFactory.createDistributionSet("Canceled DS", "1.2", + new ArrayList()); - List targets = targetManagement - .createTargets(TestDataUtil.generateTargets(Constants.MAX_ENTRIES_IN_STATEMENT + 10)); + List targets = testdataFactory.createTargets(Constants.MAX_ENTRIES_IN_STATEMENT + 10); targets = deploymentManagement.assignDistributionSet(cancelDs, targets).getAssignedEntity(); targets = deploymentManagement.assignDistributionSet(cancelDs2, targets).getAssignedEntity(); @@ -179,15 +178,12 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { + "also the target goes back to IN_SYNC as no open action is left.") public void manualCancelWithMultipleAssignmentsCancelLastOneFirst() { JpaTarget target = new JpaTarget("4712"); - final JpaDistributionSet dsFirst = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement, true); + final DistributionSet dsFirst = testdataFactory.createDistributionSet("", true); dsFirst.setRequiredMigrationStep(true); - final JpaDistributionSet dsSecond = TestDataUtil.generateDistributionSet("2", softwareManagement, - distributionSetManagement, true); - final JpaDistributionSet dsInstalled = TestDataUtil.generateDistributionSet("installed", softwareManagement, - distributionSetManagement, true); + final DistributionSet dsSecond = testdataFactory.createDistributionSet("2", true); + final DistributionSet dsInstalled = testdataFactory.createDistributionSet("installed", true); - ((JpaTargetInfo) target.getTargetInfo()).setInstalledDistributionSet(dsInstalled); + ((JpaTargetInfo) target.getTargetInfo()).setInstalledDistributionSet((JpaDistributionSet) dsInstalled); target = (JpaTarget) targetManagement.createTarget(target); // check initial status @@ -236,15 +232,12 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { + "also the target goes back to IN_SYNC as no open action is left.") public void manualCancelWithMultipleAssignmentsCancelMiddleOneFirst() { JpaTarget target = new JpaTarget("4712"); - final JpaDistributionSet dsFirst = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement, true); + final DistributionSet dsFirst = testdataFactory.createDistributionSet("", true); dsFirst.setRequiredMigrationStep(true); - final JpaDistributionSet dsSecond = TestDataUtil.generateDistributionSet("2", softwareManagement, - distributionSetManagement, true); - final JpaDistributionSet dsInstalled = TestDataUtil.generateDistributionSet("installed", softwareManagement, - distributionSetManagement, true); + final DistributionSet dsSecond = testdataFactory.createDistributionSet("2", true); + final DistributionSet dsInstalled = testdataFactory.createDistributionSet("installed", true); - ((JpaTargetInfo) target.getTargetInfo()).setInstalledDistributionSet(dsInstalled); + ((JpaTargetInfo) target.getTargetInfo()).setInstalledDistributionSet((JpaDistributionSet) dsInstalled); target = (JpaTarget) targetManagement.createTarget(target); // check initial status @@ -295,13 +288,11 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { public void forceQuitSetActionToInactive() throws InterruptedException { JpaTarget target = new JpaTarget("4712"); - final JpaDistributionSet dsInstalled = TestDataUtil.generateDistributionSet("installed", softwareManagement, - distributionSetManagement, true); - ((JpaTargetInfo) target.getTargetInfo()).setInstalledDistributionSet(dsInstalled); + final DistributionSet dsInstalled = testdataFactory.createDistributionSet("installed", true); + ((JpaTargetInfo) target.getTargetInfo()).setInstalledDistributionSet((JpaDistributionSet) dsInstalled); target = (JpaTarget) targetManagement.createTarget(target); - final JpaDistributionSet ds = TestDataUtil.generateDistributionSet("newDS", softwareManagement, - distributionSetManagement, true); + final DistributionSet ds = testdataFactory.createDistributionSet("newDS", true); ds.setRequiredMigrationStep(true); // verify initial status @@ -336,14 +327,12 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { @Description("Force Quit an not canceled Assignment. Expected behaviour is that the action can not be force quit and there is thrown an exception.") public void forceQuitNotAllowedThrowsException() { - JpaTarget target = new JpaTarget("4712"); - final JpaDistributionSet dsInstalled = TestDataUtil.generateDistributionSet("installed", softwareManagement, - distributionSetManagement, true); - ((JpaTargetInfo) target.getTargetInfo()).setInstalledDistributionSet(dsInstalled); - target = (JpaTarget) targetManagement.createTarget(target); + Target target = new JpaTarget("4712"); + final DistributionSet dsInstalled = testdataFactory.createDistributionSet("installed", true); + ((JpaTargetInfo) target.getTargetInfo()).setInstalledDistributionSet((JpaDistributionSet) dsInstalled); + target = targetManagement.createTarget(target); - final JpaDistributionSet ds = TestDataUtil.generateDistributionSet("newDS", softwareManagement, - distributionSetManagement, true); + final DistributionSet ds = testdataFactory.createDistributionSet("newDS", true); ds.setRequiredMigrationStep(true); // verify initial status @@ -364,14 +353,16 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { } } - private Action assignSet(final JpaTarget target, final JpaDistributionSet ds) { + private Action assignSet(final Target target, final DistributionSet ds) { deploymentManagement.assignDistributionSet(ds.getId(), new String[] { target.getControllerId() }); assertThat( targetManagement.findTargetByControllerID(target.getControllerId()).getTargetInfo().getUpdateStatus()) .as("wrong update status").isEqualTo(TargetUpdateStatus.PENDING); assertThat(targetManagement.findTargetByControllerID(target.getControllerId()).getAssignedDistributionSet()) .as("wrong assigned ds").isEqualTo(ds); - final Action action = actionRepository.findByTargetAndDistributionSet(pageReq, target, ds).getContent().get(0); + final Action action = actionRepository + .findByTargetAndDistributionSet(pageReq, (JpaTarget) target, (JpaDistributionSet) ds).getContent() + .get(0); assertThat(action).as("action should not be null").isNotNull(); return action; } @@ -392,14 +383,13 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { final String myCtrlIDPref = "myCtrlID"; final Iterable savedNakedTargets = targetManagement - .createTargets(TestDataUtil.buildTargetFixtures(10, myCtrlIDPref, "first description")); + .createTargets(testdataFactory.generateTargets(10, myCtrlIDPref, "first description")); final String myDeployedCtrlIDPref = "myDeployedCtrlID"; List savedDeployedTargets = targetManagement - .createTargets(TestDataUtil.buildTargetFixtures(20, myDeployedCtrlIDPref, "first description")); + .createTargets(testdataFactory.generateTargets(20, myDeployedCtrlIDPref, "first description")); - final DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); + final DistributionSet ds = testdataFactory.createDistributionSet(""); deploymentManagement.assignDistributionSet(ds, savedDeployedTargets); @@ -446,7 +436,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { final EventHandlerMock eventHandlerMock = new EventHandlerMock(0); eventBus.register(eventHandlerMock); - final List targets = targetManagement.createTargets(TestDataUtil.generateTargets(10)); + final List targets = testdataFactory.createTargets(10); final SoftwareModule ah = softwareManagement .createSoftwareModule(new JpaSoftwareModule(appType, "agent-hub", "1.0.1", null, "")); @@ -657,7 +647,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { final DeploymentResult deploymentResult = prepareComplexRepo(undeployedTargetPrefix, noOfUndeployedTargets, deployedTargetPrefix, noOfDeployedTargets, noOfDistributionSets, "myTestDS"); - DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement, distributionSetManagement); + DistributionSet dsA = testdataFactory.createDistributionSet(""); distributionSetManagement.deleteDistributionSet(dsA.getId()); dsA = distributionSetManagement.findDistributionSetById(dsA.getId()); @@ -761,12 +751,9 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { @Description("Testing if changing target and the status without refreshing the entities from the DB (e.g. concurrent changes from UI and from controller) works") public void alternatingAssignmentAndAddUpdateActionStatus() { - final JpaDistributionSet dsA = TestDataUtil.generateDistributionSet("a", softwareManagement, - distributionSetManagement); - final JpaDistributionSet dsB = TestDataUtil.generateDistributionSet("b", softwareManagement, - distributionSetManagement); - Target targ = targetManagement - .createTarget(TestDataUtil.buildTargetFixture("target-id-A", "first description")); + final DistributionSet dsA = testdataFactory.createDistributionSet("a"); + final DistributionSet dsB = testdataFactory.createDistributionSet("b"); + Target targ = targetManagement.createTarget(testdataFactory.generateTarget("target-id-A", "first description")); List targs = new ArrayList<>(); targs.add(targ); @@ -793,7 +780,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { assertThat(deploymentManagement.findActiveActionsByTarget(targ).get(0).getDistributionSet()) .as("Installed distribution set of action should be null").isNotNull(); - final Page updAct = actionRepository.findByDistributionSet(pageReq, dsA); + final Page updAct = actionRepository.findByDistributionSet(pageReq, (JpaDistributionSet) dsA); final Action action = updAct.getContent().get(0); action.setStatus(Status.FINISHED); final ActionStatus statusMessage = new JpaActionStatus((JpaAction) action, Status.FINISHED, @@ -831,11 +818,9 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { @Description("The test verfies that the DS itself is not changed because of an target assignment" + " which is a relationship but not a changed on the entity itself..") public void checkThatDsRevisionsIsNotChangedWithTargetAssignment() { - final DistributionSet dsA = TestDataUtil.generateDistributionSet("a", softwareManagement, - distributionSetManagement); - TestDataUtil.generateDistributionSet("b", softwareManagement, distributionSetManagement); - Target targ = targetManagement - .createTarget(TestDataUtil.buildTargetFixture("target-id-A", "first description")); + final DistributionSet dsA = testdataFactory.createDistributionSet("a"); + testdataFactory.createDistributionSet("b"); + Target targ = targetManagement.createTarget(testdataFactory.generateTarget("target-id-A", "first description")); assertThat(dsA.getOptLockRevision()).as("lock revision is wrong").isEqualTo( distributionSetManagement.findDistributionSetByIdWithDetails(dsA.getId()).getOptLockRevision()); @@ -854,8 +839,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { public void forceSoftAction() { // prepare final Target target = targetManagement.createTarget(new JpaTarget("knownControllerId")); - final DistributionSet ds = TestDataUtil.generateDistributionSet("a", softwareManagement, - distributionSetManagement); + final DistributionSet ds = testdataFactory.createDistributionSet("a"); // assign ds to create an action final DistributionSetAssignmentResult assignDistributionSet = deploymentManagement.assignDistributionSet( ds.getId(), ActionType.SOFT, org.eclipse.hawkbit.repository.model.Constants.NO_FORCE_TIME, @@ -878,8 +862,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { public void forceAlreadyForcedActionNothingChanges() { // prepare final Target target = targetManagement.createTarget(new JpaTarget("knownControllerId")); - final DistributionSet ds = TestDataUtil.generateDistributionSet("a", softwareManagement, - distributionSetManagement); + final DistributionSet ds = testdataFactory.createDistributionSet("a"); // assign ds to create an action final DistributionSetAssignmentResult assignDistributionSet = deploymentManagement.assignDistributionSet( ds.getId(), ActionType.FORCED, org.eclipse.hawkbit.repository.model.Constants.NO_FORCE_TIME, @@ -926,14 +909,14 @@ public class DeploymentManagementTest extends AbstractIntegrationTest { final String deployedTargetPrefix, final int noOfDeployedTargets, final int noOfDistributionSets, final String distributionSetPrefix) { final Iterable nakedTargets = targetManagement.createTargets( - TestDataUtil.buildTargetFixtures(noOfUndeployedTargets, undeployedTargetPrefix, "first description")); + testdataFactory.generateTargets(noOfUndeployedTargets, undeployedTargetPrefix, "first description")); List deployedTargets = targetManagement.createTargets( - TestDataUtil.buildTargetFixtures(noOfDeployedTargets, deployedTargetPrefix, "first description")); + testdataFactory.generateTargets(noOfDeployedTargets, deployedTargetPrefix, "first description")); // creating 10 DistributionSets - final Collection dsList = (Collection) TestDataUtil.generateDistributionSets( - distributionSetPrefix, noOfDistributionSets, softwareManagement, distributionSetManagement); + final Collection dsList = testdataFactory.createDistributionSets(distributionSetPrefix, + noOfDistributionSets); String time = String.valueOf(System.currentTimeMillis()); time = time.substring(time.length() - 5); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DistributionSetManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DistributionSetManagementTest.java index f102ac86c..d26474bb4 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DistributionSetManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DistributionSetManagementTest.java @@ -31,14 +31,15 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; -import org.eclipse.hawkbit.repository.model.DistributionSetFilter.DistributionSetFilterBuilder; import org.eclipse.hawkbit.repository.model.ActionStatus; import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.DistributionSetFilter.DistributionSetFilterBuilder; import org.eclipse.hawkbit.repository.model.DistributionSetMetadata; import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.Target; +import org.eclipse.hawkbit.repository.util.WithUser; import org.fest.assertions.core.Condition; import org.junit.Test; import org.springframework.data.domain.Page; @@ -56,7 +57,7 @@ import ru.yandex.qatools.allure.annotations.Stories; */ @Features("Component Tests - Repository") @Stories("DistributionSet Management") -public class DistributionSetManagementTest extends AbstractIntegrationTest { +public class DistributionSetManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Tests the successfull module update of unused distribution set type which is in fact allowed.") @@ -178,10 +179,10 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest { @Test @Description("Ensures that it is not possible to create a DS that already exists (unique constraint is on name,version for DS).") public void createDuplicateDistributionSetsFailsWithException() { - TestDataUtil.generateDistributionSet("a", softwareManagement, distributionSetManagement); + testdataFactory.createDistributionSet("a"); try { - TestDataUtil.generateDistributionSet("a", softwareManagement, distributionSetManagement); + testdataFactory.createDistributionSet("a"); fail("Should not have worked as DS with same UK already exists."); } catch (final EntityAlreadyExistsException e) { @@ -239,8 +240,7 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest { final String knownKey = "dsMetaKnownKey"; final String knownValue = "dsMetaKnownValue"; - final DistributionSet ds = TestDataUtil.generateDistributionSet("testDs", softwareManagement, - distributionSetManagement); + final DistributionSet ds = testdataFactory.createDistributionSet("testDs"); final DistributionSetMetadata metadata = new JpaDistributionSetMetadata(knownKey, ds, knownValue); final JpaDistributionSetMetadata createdMetadata = (JpaDistributionSetMetadata) distributionSetManagement @@ -262,8 +262,7 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest { SoftwareModule ah2 = new JpaSoftwareModule(appType, "agent-hub2", "1.0.5", null, ""); SoftwareModule os2 = new JpaSoftwareModule(osType, "poky2", "3.0.3", null, ""); - DistributionSet ds = TestDataUtil.generateDistributionSet("ds-1", softwareManagement, - distributionSetManagement); + DistributionSet ds = testdataFactory.createDistributionSet("ds-1"); ah2 = softwareManagement.createSoftwareModule(ah2); os2 = softwareManagement.createSoftwareModule(os2); @@ -348,7 +347,7 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest { SoftwareModule os2 = new JpaSoftwareModule(osType, "poky2", "3.0.3", null, ""); final SoftwareModule app2 = new JpaSoftwareModule(appType, "app2", "3.0.3", null, ""); - DistributionSet ds = TestDataUtil.generateDistributionSet("", softwareManagement, distributionSetManagement); + DistributionSet ds = testdataFactory.createDistributionSet(""); os2 = softwareManagement.createSoftwareModule(os2); @@ -387,8 +386,7 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest { final String knownUpdateValue = "myNewUpdatedValue"; // create a DS - final DistributionSet ds = TestDataUtil.generateDistributionSet("testDs", softwareManagement, - distributionSetManagement); + final DistributionSet ds = testdataFactory.createDistributionSet("testDs"); // initial opt lock revision must be zero assertThat(ds.getOptLockRevision()).isEqualTo(1L); @@ -427,13 +425,12 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest { @Description("Tests that a DS queue is possible where the result is ordered by the target assignment, i.e. assigned first in the list.") public void findDistributionSetsAllOrderedByLinkTarget() { - final List buildDistributionSets = TestDataUtil.generateDistributionSets("dsOrder", 10, - softwareManagement, distributionSetManagement); + final List buildDistributionSets = testdataFactory.createDistributionSets("dsOrder", 10); final List buildTargetFixtures = targetManagement - .createTargets(TestDataUtil.buildTargetFixtures(5, "tOrder", "someDesc")); + .createTargets(testdataFactory.generateTargets(5, "tOrder", "someDesc")); - final Iterator dsIterator = buildDistributionSets.iterator(); + final Iterator dsIterator = buildDistributionSets.iterator(); final Iterator tIterator = buildTargetFixtures.iterator(); final DistributionSet dsFirst = dsIterator.next(); final DistributionSet dsSecond = dsIterator.next(); @@ -482,12 +479,9 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest { final DistributionSetTag dsTagD = tagManagement .createDistributionSetTag(new JpaDistributionSetTag("DistributionSetTag-D")); - Collection ds100Group1 = (Collection) TestDataUtil.generateDistributionSets("", 100, - softwareManagement, distributionSetManagement); - Collection ds100Group2 = (Collection) TestDataUtil.generateDistributionSets("test2", 100, - softwareManagement, distributionSetManagement); - DistributionSet dsDeleted = TestDataUtil.generateDistributionSet("deleted", softwareManagement, - distributionSetManagement); + Collection ds100Group1 = testdataFactory.createDistributionSets("", 100); + Collection ds100Group2 = testdataFactory.createDistributionSets("test2", 100); + DistributionSet dsDeleted = testdataFactory.createDistributionSet("deleted"); final DistributionSet dsInComplete = distributionSetManagement .createDistributionSet(new JpaDistributionSet("notcomplete", "1", "", standardDsType, null)); @@ -498,8 +492,7 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest { final DistributionSet dsNewType = distributionSetManagement .createDistributionSet(new JpaDistributionSet("newtype", "1", "", newType, dsDeleted.getModules())); - deploymentManagement.assignDistributionSet(dsDeleted, - targetManagement.createTargets(Lists.newArrayList(TestDataUtil.generateTargets(5)))); + deploymentManagement.assignDistributionSet(dsDeleted, Lists.newArrayList(testdataFactory.createTargets(5))); distributionSetManagement.deleteDistributionSet(dsDeleted); dsDeleted = distributionSetManagement.findDistributionSetById(dsDeleted.getId()); @@ -724,7 +717,7 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest { @Test @Description("Simple DS load without the related data that should be loaded lazy.") public void findDistributionSetsWithoutLazy() { - TestDataUtil.generateDistributionSets(20, softwareManagement, distributionSetManagement); + testdataFactory.createDistributionSets(20); assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true)) .hasSize(20); @@ -733,10 +726,8 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest { @Test @Description("Deltes a DS that is no in use. Expected behaviour is a hard delete on the database.") public void deleteUnassignedDistributionSet() { - DistributionSet ds1 = TestDataUtil.generateDistributionSet("ds-1", softwareManagement, - distributionSetManagement); - DistributionSet ds2 = TestDataUtil.generateDistributionSet("ds-2", softwareManagement, - distributionSetManagement); + DistributionSet ds1 = testdataFactory.createDistributionSet("ds-1"); + DistributionSet ds2 = testdataFactory.createDistributionSet("ds-2"); ds1 = distributionSetManagement.findDistributionSetByNameAndVersion(ds1.getName(), ds1.getVersion()); ds2 = distributionSetManagement.findDistributionSetByNameAndVersion(ds2.getName(), ds2.getVersion()); @@ -755,10 +746,8 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest { @Description("Queries and loads the metadata related to a given software module.") public void findAllDistributionSetMetadataByDsId() { // create a DS - DistributionSet ds1 = TestDataUtil.generateDistributionSet("testDs1", softwareManagement, - distributionSetManagement); - DistributionSet ds2 = TestDataUtil.generateDistributionSet("testDs2", softwareManagement, - distributionSetManagement); + DistributionSet ds1 = testdataFactory.createDistributionSet("testDs1"); + DistributionSet ds2 = testdataFactory.createDistributionSet("testDs2"); for (int index = 0; index < 10; index++) { @@ -791,12 +780,9 @@ public class DistributionSetManagementTest extends AbstractIntegrationTest { @Description("Deltes a DS that is no in use. Expected behaviour is a soft delete on the database, i.e. only marked as " + "deleted, kept eas refernce and unavailable for future use..") public void deleteAssignedDistributionSet() { - DistributionSet ds1 = TestDataUtil.generateDistributionSet("ds-1", softwareManagement, - distributionSetManagement); - DistributionSet ds2 = TestDataUtil.generateDistributionSet("ds-2", softwareManagement, - distributionSetManagement); - DistributionSet dsAssigned = TestDataUtil.generateDistributionSet("ds-3", softwareManagement, - distributionSetManagement); + DistributionSet ds1 = testdataFactory.createDistributionSet("ds-1"); + DistributionSet ds2 = testdataFactory.createDistributionSet("ds-2"); + DistributionSet dsAssigned = testdataFactory.createDistributionSet("ds-3"); ds1 = distributionSetManagement.findDistributionSetByNameAndVersion(ds1.getName(), ds1.getVersion()); ds2 = distributionSetManagement.findDistributionSetByNameAndVersion(ds2.getName(), ds2.getVersion()); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/JpaTestRepositoryManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/JpaTestRepositoryManagement.java new file mode 100644 index 000000000..5c4b0efcc --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/JpaTestRepositoryManagement.java @@ -0,0 +1,109 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.jpa; + +import java.util.List; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; + +import org.eclipse.hawkbit.cache.TenantAwareCacheManager; +import org.eclipse.hawkbit.repository.SystemManagement; +import org.eclipse.hawkbit.repository.util.TestRepositoryManagement; +import org.eclipse.hawkbit.security.SystemSecurityContext; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.mongodb.gridfs.GridFsOperations; +import org.springframework.transaction.annotation.Transactional; + +public class JpaTestRepositoryManagement implements TestRepositoryManagement { + + @PersistenceContext + private EntityManager entityManager; + + @Autowired + private TargetRepository targetRepository; + + @Autowired + private ActionRepository actionRepository; + + @Autowired + private DistributionSetRepository distributionSetRepository; + + @Autowired + private SoftwareModuleRepository softwareModuleRepository; + + @Autowired + private TenantMetaDataRepository tenantMetaDataRepository; + + @Autowired + private DistributionSetTypeRepository distributionSetTypeRepository; + + @Autowired + private SoftwareModuleTypeRepository softwareModuleTypeRepository; + + @Autowired + private TargetTagRepository targetTagRepository; + + @Autowired + private DistributionSetTagRepository distributionSetTagRepository; + + @Autowired + private SoftwareModuleMetadataRepository softwareModuleMetadataRepository; + + @Autowired + private ActionStatusRepository actionStatusRepository; + + @Autowired + private ExternalArtifactRepository externalArtifactRepository; + + @Autowired + private LocalArtifactRepository artifactRepository; + + @Autowired + private TargetInfoRepository targetInfoRepository; + + @Autowired + private GridFsOperations operations; + + @Autowired + private RolloutGroupRepository rolloutGroupRepository; + + @Autowired + private RolloutRepository rolloutRepository; + + @Autowired + private TenantAwareCacheManager cacheManager; + + @Autowired + private SystemSecurityContext systemSecurityContext; + + @Autowired + private SystemManagement systemManagement; + + @Override + public void clearTestRepository() { + deleteAllRepos(); + cacheManager.getDirectCacheNames().forEach(name -> cacheManager.getDirectCache(name).clear()); + } + + @Transactional + public void deleteAllRepos() { + final List tenants = systemSecurityContext.runAsSystem(() -> systemManagement.findTenants()); + tenants.forEach(tenant -> { + try { + systemSecurityContext.runAsSystem(() -> { + systemManagement.deleteTenant(tenant); + return null; + }); + } catch (final Exception e) { + e.printStackTrace(); + } + }); + } +} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ReportManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ReportManagementTest.java index 57fc13379..4fba80616 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ReportManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ReportManagementTest.java @@ -24,7 +24,6 @@ import org.eclipse.hawkbit.repository.DistributionSetAssignmentResult; import org.eclipse.hawkbit.repository.ReportManagement; import org.eclipse.hawkbit.repository.ReportManagement.DateTypes; import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus; -import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo; import org.eclipse.hawkbit.repository.model.Action; @@ -38,6 +37,9 @@ import org.eclipse.hawkbit.repository.report.model.DataReportSeries; import org.eclipse.hawkbit.repository.report.model.DataReportSeriesItem; import org.eclipse.hawkbit.repository.report.model.InnerOuterDataReportSeries; import org.eclipse.hawkbit.repository.report.model.SeriesTime; +import org.eclipse.hawkbit.repository.util.TestdataFactory; +import org.eclipse.hawkbit.repository.util.WithSpringAuthorityRule; +import org.eclipse.hawkbit.repository.util.WithUser; import org.junit.After; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -55,7 +57,7 @@ import ru.yandex.qatools.allure.annotations.Stories; @Features("Component Tests - Repository") @Stories("Report Management") -public class ReportManagementTest extends AbstractIntegrationTest { +public class ReportManagementTest extends AbstractJpaIntegrationTest { @Autowired private ReportManagement reportManagement; @@ -128,8 +130,7 @@ public class ReportManagementTest extends AbstractIntegrationTest { final LocalDateTime to = LocalDateTime.now(); final LocalDateTime from = to.minusMonths(maxMonthBackAmountReportTargets); - final DistributionSet distributionSet = TestDataUtil.generateDistributionSet("ds", softwareManagement, - distributionSetManagement); + final DistributionSet distributionSet = testdataFactory.createDistributionSet("ds"); final DynamicDateTimeProvider dynamicDateTimeProvider = new DynamicDateTimeProvider(); auditingHandler.setDateTimeProvider(dynamicDateTimeProvider); @@ -181,21 +182,18 @@ public class ReportManagementTest extends AbstractIntegrationTest { final Target knownTarget4 = targetManagement.createTarget(new JpaTarget("t4")); final Target knownTarget5 = targetManagement.createTarget(new JpaTarget("t5")); - final SoftwareModule ah = softwareManagement - .createSoftwareModule(new JpaSoftwareModule(appType, "agent-hub", "1.0.1", null, "")); - final SoftwareModule jvm = softwareManagement - .createSoftwareModule(new JpaSoftwareModule(runtimeType, "oracle-jre", "1.7.2", null, "")); - final SoftwareModule os = softwareManagement - .createSoftwareModule(new JpaSoftwareModule(osType, "poky", "3.0.2", null, "")); + final SoftwareModule ah = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_APP); + final SoftwareModule jvm = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_RT); + final SoftwareModule os = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_OS); - final DistributionSet distributionSet1 = distributionSetManagement - .createDistributionSet(TestDataUtil.buildDistributionSet("ds1", "0.0.0", standardDsType, os, jvm, ah)); - final DistributionSet distributionSet11 = distributionSetManagement - .createDistributionSet(TestDataUtil.buildDistributionSet("ds1", "0.0.1", standardDsType, os, jvm, ah)); - final DistributionSet distributionSet2 = distributionSetManagement - .createDistributionSet(TestDataUtil.buildDistributionSet("ds2", "0.0.2", standardDsType, os, jvm, ah)); - final DistributionSet distributionSet3 = distributionSetManagement - .createDistributionSet(TestDataUtil.buildDistributionSet("ds3", "0.0.3", standardDsType, os, jvm, ah)); + final DistributionSet distributionSet1 = distributionSetManagement.createDistributionSet(testdataFactory + .generateDistributionSet("ds1", "0.0.0", standardDsType, Lists.newArrayList(os, jvm, ah))); + final DistributionSet distributionSet11 = distributionSetManagement.createDistributionSet(testdataFactory + .generateDistributionSet("ds1", "0.0.1", standardDsType, Lists.newArrayList(os, jvm, ah))); + final DistributionSet distributionSet2 = distributionSetManagement.createDistributionSet(testdataFactory + .generateDistributionSet("ds2", "0.0.2", standardDsType, Lists.newArrayList(os, jvm, ah))); + final DistributionSet distributionSet3 = distributionSetManagement.createDistributionSet(testdataFactory + .generateDistributionSet("ds3", "0.0.3", standardDsType, Lists.newArrayList(os, jvm, ah))); // ds1(0.0.0)=[target1,target2], ds1(0.0.1)=[target3] deploymentManagement.assignDistributionSet(distributionSet1.getId(), knownTarget1.getControllerId()); @@ -355,21 +353,18 @@ public class ReportManagementTest extends AbstractIntegrationTest { final Target knownTarget3 = targetManagement.createTarget(new JpaTarget("t3")); final Target knownTarget4 = targetManagement.createTarget(new JpaTarget("t4")); - final SoftwareModule ah = softwareManagement - .createSoftwareModule(new JpaSoftwareModule(appType, "agent-hub", "1.0.1", null, "")); - final SoftwareModule jvm = softwareManagement - .createSoftwareModule(new JpaSoftwareModule(runtimeType, "oracle-jre", "1.7.2", null, "")); - final SoftwareModule os = softwareManagement - .createSoftwareModule(new JpaSoftwareModule(osType, "poky", "3.0.2", null, "")); + final SoftwareModule ah = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_APP); + final SoftwareModule jvm = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_RT); + final SoftwareModule os = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_OS); - final DistributionSet distributionSet1 = distributionSetManagement - .createDistributionSet(TestDataUtil.buildDistributionSet("ds1", "0.0.0", standardDsType, os, jvm, ah)); - final DistributionSet distributionSet11 = distributionSetManagement - .createDistributionSet(TestDataUtil.buildDistributionSet("ds1", "0.0.1", standardDsType, os, jvm, ah)); - final DistributionSet distributionSet2 = distributionSetManagement - .createDistributionSet(TestDataUtil.buildDistributionSet("ds2", "0.0.2", standardDsType, os, jvm, ah)); - final DistributionSet distributionSet3 = distributionSetManagement - .createDistributionSet(TestDataUtil.buildDistributionSet("ds3", "0.0.3", standardDsType, os, jvm, ah)); + final DistributionSet distributionSet1 = distributionSetManagement.createDistributionSet(testdataFactory + .generateDistributionSet("ds1", "0.0.0", standardDsType, Lists.newArrayList(os, jvm, ah))); + final DistributionSet distributionSet11 = distributionSetManagement.createDistributionSet(testdataFactory + .generateDistributionSet("ds1", "0.0.1", standardDsType, Lists.newArrayList(os, jvm, ah))); + final DistributionSet distributionSet2 = distributionSetManagement.createDistributionSet(testdataFactory + .generateDistributionSet("ds2", "0.0.2", standardDsType, Lists.newArrayList(os, jvm, ah))); + final DistributionSet distributionSet3 = distributionSetManagement.createDistributionSet(testdataFactory + .generateDistributionSet("ds3", "0.0.3", standardDsType, Lists.newArrayList(os, jvm, ah))); // ds1(0.0.0)=[target1,target2], ds1(0.0.1)=[target3] deploymentManagement.assignDistributionSet(distributionSet1.getId(), knownTarget1.getControllerId()); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/RolloutManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/RolloutManagementTest.java index 28ece9239..42e5de498 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/RolloutManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/RolloutManagementTest.java @@ -22,7 +22,6 @@ import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.jpa.model.JpaAction; import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus; import org.eclipse.hawkbit.repository.jpa.model.JpaRollout; -import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; import org.eclipse.hawkbit.repository.jpa.utils.MultipleInvokeHelper; import org.eclipse.hawkbit.repository.jpa.utils.SuccessCondition; import org.eclipse.hawkbit.repository.model.Action; @@ -41,6 +40,7 @@ import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; +import org.eclipse.hawkbit.repository.util.TestdataFactory; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Description; @@ -49,6 +49,8 @@ import org.springframework.data.domain.Slice; import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort.Direction; +import com.google.common.collect.Lists; + import ru.yandex.qatools.allure.annotations.Features; import ru.yandex.qatools.allure.annotations.Stories; @@ -60,7 +62,7 @@ import ru.yandex.qatools.allure.annotations.Stories; */ @Features("Component Tests - Repository") @Stories("Rollout Management") -public class RolloutManagementTest extends AbstractIntegrationTest { +public class RolloutManagementTest extends AbstractJpaIntegrationTest { @Autowired private RolloutManagement rolloutManagement; @@ -455,8 +457,7 @@ public class RolloutManagementTest extends AbstractIntegrationTest { targetToCancel.add(targetList.get(0)); targetToCancel.add(targetList.get(1)); targetToCancel.add(targetList.get(2)); - final DistributionSet dsForCancelTest = TestDataUtil.generateDistributionSet("dsForTest", softwareManagement, - distributionSetManagement); + final DistributionSet dsForCancelTest = testdataFactory.createDistributionSet("dsForTest"); deploymentManagement.assignDistributionSet(dsForCancelTest, targetToCancel); // 5 targets are canceling but still have the status running and 5 are // still in SCHEDULED @@ -480,8 +481,7 @@ public class RolloutManagementTest extends AbstractIntegrationTest { rolloutManagement.startRollout(rolloutOne); rolloutOne = rolloutManagement.findRolloutById(rolloutOne.getId()); - final DistributionSet dsForRolloutTwo = TestDataUtil.generateDistributionSet("dsForRolloutTwo", - softwareManagement, distributionSetManagement); + final DistributionSet dsForRolloutTwo = testdataFactory.createDistributionSet("dsForRolloutTwo"); final Rollout rolloutTwo = createRolloutByVariables("rolloutTwo", "This is the description for rollout two", 1, "controllerId==rollout-*", dsForRolloutTwo, "50", "80"); @@ -834,7 +834,7 @@ public class RolloutManagementTest extends AbstractIntegrationTest { Rollout myRollout = createTestRolloutWithTargetsAndDistributionSet(amountTargetsForRollout, amountGroups, successCondition, errorCondition, rolloutName, rolloutName); - targetManagement.createTargets(TestDataUtil.buildTargetFixtures(amountOtherTargets, "others-", "rollout")); + targetManagement.createTargets(testdataFactory.generateTargets(amountOtherTargets, "others-", "rollout")); final String rsqlParam = "controllerId==*MyRoll*"; @@ -872,10 +872,9 @@ public class RolloutManagementTest extends AbstractIntegrationTest { final String errorCondition = "80"; final String rolloutName = "rolloutTest"; final String targetPrefixName = rolloutName; - final DistributionSet distributionSet = TestDataUtil.generateDistributionSet("dsFor" + rolloutName, - softwareManagement, distributionSetManagement); + final DistributionSet distributionSet = testdataFactory.createDistributionSet("dsFor" + rolloutName); targetManagement.createTargets( - TestDataUtil.buildTargetFixtures(amountTargetsForRollout, targetPrefixName + "-", targetPrefixName)); + testdataFactory.generateTargets(amountTargetsForRollout, targetPrefixName + "-", targetPrefixName)); final RolloutGroupConditions conditions = new RolloutGroupConditionBuilder() .successCondition(RolloutGroupSuccessCondition.THRESHOLD, successCondition) .errorCondition(RolloutGroupErrorCondition.THRESHOLD, errorCondition) @@ -933,17 +932,14 @@ public class RolloutManagementTest extends AbstractIntegrationTest { private Rollout createSimpleTestRolloutWithTargetsAndDistributionSet(final int amountTargetsForRollout, final int amountOtherTargets, final int groupSize, final String successCondition, final String errorCondition) { - final SoftwareModule ah = softwareManagement - .createSoftwareModule(new JpaSoftwareModule(appType, "agent-hub", "1.0.1", null, "")); - final SoftwareModule jvm = softwareManagement - .createSoftwareModule(new JpaSoftwareModule(runtimeType, "oracle-jre", "1.7.2", null, "")); - final SoftwareModule os = softwareManagement - .createSoftwareModule(new JpaSoftwareModule(osType, "poky", "3.0.2", null, "")); - final DistributionSet rolloutDS = distributionSetManagement.createDistributionSet( - TestDataUtil.buildDistributionSet("rolloutDS", "0.0.0", standardDsType, os, jvm, ah)); - targetManagement - .createTargets(TestDataUtil.buildTargetFixtures(amountTargetsForRollout, "rollout-", "rollout")); - targetManagement.createTargets(TestDataUtil.buildTargetFixtures(amountOtherTargets, "others-", "rollout")); + final SoftwareModule ah = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_APP); + final SoftwareModule jvm = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_RT); + final SoftwareModule os = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_OS); + + final DistributionSet rolloutDS = distributionSetManagement.createDistributionSet(testdataFactory + .generateDistributionSet("rolloutDS", "0.0.0", standardDsType, Lists.newArrayList(os, jvm, ah))); + targetManagement.createTargets(testdataFactory.generateTargets(amountTargetsForRollout, "rollout-", "rollout")); + targetManagement.createTargets(testdataFactory.generateTargets(amountOtherTargets, "others-", "rollout")); final String filterQuery = "controllerId==rollout-*"; return createRolloutByVariables("test-rollout-name-1", "test-rollout-description-1", groupSize, filterQuery, rolloutDS, successCondition, errorCondition); @@ -952,10 +948,9 @@ public class RolloutManagementTest extends AbstractIntegrationTest { private Rollout createTestRolloutWithTargetsAndDistributionSet(final int amountTargetsForRollout, final int groupSize, final String successCondition, final String errorCondition, final String rolloutName, final String targetPrefixName) { - final DistributionSet dsForRolloutTwo = TestDataUtil.generateDistributionSet("dsFor" + rolloutName, - softwareManagement, distributionSetManagement); + final DistributionSet dsForRolloutTwo = testdataFactory.createDistributionSet("dsFor" + rolloutName); targetManagement.createTargets( - TestDataUtil.buildTargetFixtures(amountTargetsForRollout, targetPrefixName + "-", targetPrefixName)); + testdataFactory.generateTargets(amountTargetsForRollout, targetPrefixName + "-", targetPrefixName)); return createRolloutByVariables(rolloutName, rolloutName + "description", groupSize, "controllerId==" + targetPrefixName + "-*", dsForRolloutTwo, successCondition, errorCondition); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SoftwareManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SoftwareManagementTest.java index 69e19ea3a..366dd6ec7 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SoftwareManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SoftwareManagementTest.java @@ -39,6 +39,7 @@ import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; +import org.eclipse.hawkbit.repository.util.WithUser; import org.junit.Test; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; @@ -54,7 +55,7 @@ import ru.yandex.qatools.allure.annotations.Stories; @Features("Component Tests - Repository") @Stories("Software Management") -public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { +public class SoftwareManagementTest extends AbstractJpaIntegrationTestWithMongoDB { @Test @Description("Try to update non updatable fields results in repository doing nothing.") @@ -227,8 +228,8 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { final SoftwareModule ah2 = softwareManagement .createSoftwareModule(new JpaSoftwareModule(appType, "agent-hub", "1.0.2", null, "")); - JpaDistributionSet ds = (JpaDistributionSet) distributionSetManagement.createDistributionSet( - TestDataUtil.buildDistributionSet("ds-1", "1.0.1", standardDsType, os, jvm, ah2)); + JpaDistributionSet ds = (JpaDistributionSet) distributionSetManagement.createDistributionSet(testdataFactory + .generateDistributionSet("ds-1", "1.0.1", standardDsType, Lists.newArrayList(os, jvm, ah2))); final JpaTarget target = (JpaTarget) targetManagement.createTarget(new JpaTarget("test123")); ds = (JpaDistributionSet) assignSet(target, ds).getDistributionSet(); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SystemManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SystemManagementTest.java index 185416984..e697f65d8 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SystemManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SystemManagementTest.java @@ -18,6 +18,7 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.report.model.TenantUsage; +import org.eclipse.hawkbit.repository.util.WithSpringAuthorityRule; import org.junit.Test; import ru.yandex.qatools.allure.annotations.Description; @@ -26,7 +27,7 @@ import ru.yandex.qatools.allure.annotations.Stories; @Features("Component Tests - Repository") @Stories("System Management") -public class SystemManagementTest extends AbstractIntegrationTestWithMongoDB { +public class SystemManagementTest extends AbstractJpaIntegrationTestWithMongoDB { @Test @Description("Ensures that findTenants returns all tenants and not only restricted to the tenant which currently is logged in") @@ -108,8 +109,8 @@ public class SystemManagementTest extends AbstractIntegrationTestWithMongoDB { final List createdTargets = createTestTargets(targets); if (updates > 0) { for (int x = 0; x < updates; x++) { - final DistributionSet ds = TestDataUtil.generateDistributionSet("to be deployed" + x, - softwareManagement, distributionSetManagement, true); + final DistributionSet ds = testdataFactory.createDistributionSet("to be deployed" + x, + true); deploymentManagement.assignDistributionSet(ds, createdTargets); } @@ -125,7 +126,7 @@ public class SystemManagementTest extends AbstractIntegrationTestWithMongoDB { private List createTestTargets(final int targets) { return targetManagement - .createTargets(TestDataUtil.buildTargetFixtures(targets, "testTargetOfTenant", "testTargetOfTenant")); + .createTargets(testdataFactory.generateTargets(targets, "testTargetOfTenant", "testTargetOfTenant")); } private void createTestArtifact(final byte[] random) { @@ -137,8 +138,7 @@ public class SystemManagementTest extends AbstractIntegrationTestWithMongoDB { } private void createDeletedTestArtifact(final byte[] random) { - final DistributionSet ds = TestDataUtil.generateDistributionSet("deleted garbage", softwareManagement, - distributionSetManagement, true); + final DistributionSet ds = testdataFactory.createDistributionSet("deleted garbage", true); ds.getModules().stream().forEach(module -> { artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), module.getId(), "file1", false); softwareManagement.deleteSoftwareModule(module); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TagManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TagManagementTest.java index 25437b0ed..5f2fe3fbd 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TagManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TagManagementTest.java @@ -23,13 +23,13 @@ import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag; import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag; import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.DistributionSetFilter.DistributionSetFilterBuilder; import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult; import org.eclipse.hawkbit.repository.model.Tag; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetTag; import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult; -import org.eclipse.hawkbit.repository.model.DistributionSetFilter.DistributionSetFilterBuilder; import org.junit.Before; import org.junit.Test; import org.slf4j.LoggerFactory; @@ -46,7 +46,7 @@ import ru.yandex.qatools.allure.annotations.Stories; */ @Features("Component Tests - Repository") @Stories("Tag Management") -public class TagManagementTest extends AbstractIntegrationTest { +public class TagManagementTest extends AbstractJpaIntegrationTest { public TagManagementTest() { LOG = LoggerFactory.getLogger(TagManagementTest.class); } @@ -59,20 +59,13 @@ public class TagManagementTest extends AbstractIntegrationTest { @Test @Description("Full DS tag lifecycle tested. Create tags, assign them to sets and delete the tags.") public void createAndAssignAndDeleteDistributionSetTags() { - final Collection dsAs = (Collection) TestDataUtil.generateDistributionSets("DS-A", 20, - softwareManagement, distributionSetManagement); - final Collection dsBs = (Collection) TestDataUtil.generateDistributionSets("DS-B", 10, - softwareManagement, distributionSetManagement); - final Collection dsCs = (Collection) TestDataUtil.generateDistributionSets("DS-C", 25, - softwareManagement, distributionSetManagement); - final Collection dsABs = (Collection) TestDataUtil.generateDistributionSets("DS-AB", 5, - softwareManagement, distributionSetManagement); - final Collection dsACs = (Collection) TestDataUtil.generateDistributionSets("DS-AC", 11, - softwareManagement, distributionSetManagement); - final Collection dsBCs = (Collection) TestDataUtil.generateDistributionSets("DS-BC", 13, - softwareManagement, distributionSetManagement); - final Collection dsABCs = (Collection) TestDataUtil.generateDistributionSets("DS-ABC", 9, - softwareManagement, distributionSetManagement); + final Collection dsAs = testdataFactory.createDistributionSets("DS-A", 20); + final Collection dsBs = testdataFactory.createDistributionSets("DS-B", 10); + final Collection dsCs = testdataFactory.createDistributionSets("DS-C", 25); + final Collection dsABs = testdataFactory.createDistributionSets("DS-AB", 5); + final Collection dsACs = testdataFactory.createDistributionSets("DS-AC", 11); + final Collection dsBCs = testdataFactory.createDistributionSets("DS-BC", 13); + final Collection dsABCs = testdataFactory.createDistributionSets("DS-ABC", 9); final DistributionSetTag tagA = tagManagement.createDistributionSetTag(new JpaDistributionSetTag("A")); final DistributionSetTag tagB = tagManagement.createDistributionSetTag(new JpaDistributionSetTag("B")); @@ -169,10 +162,8 @@ public class TagManagementTest extends AbstractIntegrationTest { @Description("Verifies the toogle mechanism by means on assigning tag if at least on DS in the list does not have" + "the tag yet. Unassign if all of them have the tag already.") public void assignAndUnassignDistributionSetTags() { - final Collection groupA = (Collection) TestDataUtil.generateDistributionSets(20, - softwareManagement, distributionSetManagement); - final Collection groupB = (Collection) TestDataUtil.generateDistributionSets("unassigned", 20, - softwareManagement, distributionSetManagement); + final Collection groupA = testdataFactory.createDistributionSets(20); + final Collection groupB = testdataFactory.createDistributionSets("unassigned", 20); final DistributionSetTag tag = tagManagement .createDistributionSetTag(new JpaDistributionSetTag("tag1", "tagdesc1", "")); @@ -213,8 +204,8 @@ public class TagManagementTest extends AbstractIntegrationTest { @Description("Verifies the toogle mechanism by means on assigning tag if at least on target in the list does not have" + "the tag yet. Unassign if all of them have the tag already.") public void assignAndUnassignTargetTags() { - final List groupA = targetManagement.createTargets(TestDataUtil.generateTargets(20, "")); - final List groupB = targetManagement.createTargets(TestDataUtil.generateTargets(20, "groupb")); + final List groupA = targetManagement.createTargets(testdataFactory.generateTargets(20, "")); + final List groupB = targetManagement.createTargets(testdataFactory.generateTargets(20, "groupb")); final TargetTag tag = tagManagement.createTargetTag(new JpaTargetTag("tag1", "tagdesc1", "")); @@ -451,8 +442,8 @@ public class TagManagementTest extends AbstractIntegrationTest { } private List createTargetsWithTags() { - final List targets = targetManagement.createTargets(TestDataUtil.generateTargets(20)); - final Iterable tags = tagManagement.createTargetTags(TestDataUtil.generateTargetTags(20)); + final List targets = testdataFactory.createTargets(20); + final Iterable tags = tagManagement.createTargetTags(testdataFactory.generateTargetTags(20)); tags.forEach(tag -> targetManagement.toggleTagAssignment(targets, tag)); @@ -461,10 +452,8 @@ public class TagManagementTest extends AbstractIntegrationTest { private List createDsSetsWithTags() { - final Collection sets = (Collection) TestDataUtil.generateDistributionSets(20, - softwareManagement, distributionSetManagement); - final Iterable tags = tagManagement - .createDistributionSetTags(TestDataUtil.generateDistributionSetTags(20)); + final Collection sets = testdataFactory.createDistributionSets(20); + final Iterable tags = testdataFactory.createDistributionSetTags(20); tags.forEach(tag -> distributionSetManagement.toggleTagAssignment(sets, tag)); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetFilterQueryManagenmentTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetFilterQueryManagenmentTest.java index e2a06d5fc..07b92ebeb 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetFilterQueryManagenmentTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetFilterQueryManagenmentTest.java @@ -27,7 +27,7 @@ import ru.yandex.qatools.allure.annotations.Stories; */ @Features("Component Tests - Repository") @Stories("Target Filter Query Management") -public class TargetFilterQueryManagenmentTest extends AbstractIntegrationTest { +public class TargetFilterQueryManagenmentTest extends AbstractJpaIntegrationTest { @Test @Description("Test creation of target filter query.") diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetManagementSearchTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetManagementSearchTest.java index 7b128de3b..1e8f102c7 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetManagementSearchTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetManagementSearchTest.java @@ -44,7 +44,7 @@ import ru.yandex.qatools.allure.annotations.Stories; @Features("Component Tests - Repository") @Stories("Target Management Searches") -public class TargetManagementSearchTest extends AbstractIntegrationTest { +public class TargetManagementSearchTest extends AbstractJpaIntegrationTest { @Test @Description("Tests different parameter combinations for target search operations. " @@ -56,32 +56,30 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest { final TargetTag targTagZ = tagManagement.createTargetTag(new JpaTargetTag("TargTag-Z")); final TargetTag targTagW = tagManagement.createTargetTag(new JpaTargetTag("TargTag-W")); - final DistributionSet setA = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); + final DistributionSet setA = testdataFactory.createDistributionSet(""); - final DistributionSet installedSet = TestDataUtil.generateDistributionSet("another", softwareManagement, - distributionSetManagement); + final DistributionSet installedSet = testdataFactory.createDistributionSet("another"); final String targetDsAIdPref = "targ-A"; List targAs = targetManagement.createTargets( - TestDataUtil.buildTargetFixtures(100, targetDsAIdPref, targetDsAIdPref.concat(" description"))); + testdataFactory.generateTargets(100, targetDsAIdPref, targetDsAIdPref.concat(" description"))); targAs = targetManagement.toggleTagAssignment(targAs, targTagX).getAssignedEntity(); final String targetDsBIdPref = "targ-B"; List targBs = targetManagement.createTargets( - TestDataUtil.buildTargetFixtures(100, targetDsBIdPref, targetDsBIdPref.concat(" description"))); + testdataFactory.generateTargets(100, targetDsBIdPref, targetDsBIdPref.concat(" description"))); targBs = targetManagement.toggleTagAssignment(targBs, targTagY).getAssignedEntity(); targBs = targetManagement.toggleTagAssignment(targBs, targTagW).getAssignedEntity(); final String targetDsCIdPref = "targ-C"; List targCs = targetManagement.createTargets( - TestDataUtil.buildTargetFixtures(100, targetDsCIdPref, targetDsCIdPref.concat(" description"))); + testdataFactory.generateTargets(100, targetDsCIdPref, targetDsCIdPref.concat(" description"))); targCs = targetManagement.toggleTagAssignment(targCs, targTagZ).getAssignedEntity(); targCs = targetManagement.toggleTagAssignment(targCs, targTagW).getAssignedEntity(); final String targetDsDIdPref = "targ-D"; final List targDs = targetManagement.createTargets( - TestDataUtil.buildTargetFixtures(100, targetDsDIdPref, targetDsDIdPref.concat(" description"))); + testdataFactory.generateTargets(100, targetDsDIdPref, targetDsDIdPref.concat(" description"))); final String assignedC = targCs.iterator().next().getControllerId(); deploymentManagement.assignDistributionSet(setA.getId(), assignedC); @@ -680,14 +678,13 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest { public void targetSearchWithVariousFilterCombinationsAndOrderByDistributionSet() { final List notAssigned = targetManagement - .createTargets(TestDataUtil.buildTargetFixtures(3, "not", "first description")); + .createTargets(testdataFactory.generateTargets(3, "not", "first description")); List targAssigned = targetManagement - .createTargets(TestDataUtil.buildTargetFixtures(3, "assigned", "first description")); + .createTargets(testdataFactory.generateTargets(3, "assigned", "first description")); List targInstalled = targetManagement - .createTargets(TestDataUtil.buildTargetFixtures(3, "installed", "first description")); + .createTargets(testdataFactory.generateTargets(3, "installed", "first description")); - final DistributionSet ds = TestDataUtil.generateDistributionSet("a", softwareManagement, - distributionSetManagement); + final DistributionSet ds = testdataFactory.createDistributionSet("a"); targAssigned = deploymentManagement.assignDistributionSet(ds, targAssigned).getAssignedEntity(); targInstalled = deploymentManagement.assignDistributionSet(ds, targInstalled).getAssignedEntity(); @@ -714,10 +711,9 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest { @Test @Description("Verfies that targets with given assigned DS are returned from repository.") public void findTargetByAssignedDistributionSet() { - final DistributionSet assignedSet = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); - targetManagement.createTargets(TestDataUtil.generateTargets(10, "unassigned")); - List assignedtargets = targetManagement.createTargets(TestDataUtil.generateTargets(10, "assigned")); + final DistributionSet assignedSet = testdataFactory.createDistributionSet(""); + targetManagement.createTargets(testdataFactory.generateTargets(10, "unassigned")); + List assignedtargets = targetManagement.createTargets(testdataFactory.generateTargets(10, "assigned")); deploymentManagement.assignDistributionSet(assignedSet, assignedtargets); @@ -734,12 +730,10 @@ public class TargetManagementSearchTest extends AbstractIntegrationTest { @Test @Description("Verfies that targets with given installed DS are returned from repository.") public void findTargetByInstalledDistributionSet() { - final DistributionSet assignedSet = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); - final DistributionSet installedSet = TestDataUtil.generateDistributionSet("another", softwareManagement, - distributionSetManagement); - targetManagement.createTargets(TestDataUtil.generateTargets(10, "unassigned")); - List installedtargets = targetManagement.createTargets(TestDataUtil.generateTargets(10, "assigned")); + final DistributionSet assignedSet = testdataFactory.createDistributionSet(""); + final DistributionSet installedSet = testdataFactory.createDistributionSet("another"); + targetManagement.createTargets(testdataFactory.generateTargets(10, "unassigned")); + List installedtargets = targetManagement.createTargets(testdataFactory.generateTargets(10, "assigned")); // set on installed and assign another one deploymentManagement.assignDistributionSet(installedSet, installedtargets).getActions().forEach(actionId -> { diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetManagementTest.java index 10f614caa..79a7ad89f 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetManagementTest.java @@ -43,6 +43,8 @@ import org.eclipse.hawkbit.repository.model.Tag; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetIdName; import org.eclipse.hawkbit.repository.model.TargetTag; +import org.eclipse.hawkbit.repository.util.WithSpringAuthorityRule; +import org.eclipse.hawkbit.repository.util.WithUser; import org.junit.Test; import org.springframework.data.domain.PageRequest; @@ -54,7 +56,7 @@ import ru.yandex.qatools.allure.annotations.Stories; @Features("Component Tests - Repository") @Stories("Target Management") -public class TargetManagementTest extends AbstractIntegrationTest { +public class TargetManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Ensures that retrieving the target security is only permitted with the necessary permissions.") @@ -193,10 +195,8 @@ public class TargetManagementTest extends AbstractIntegrationTest { @Test @Description("Finds a target by given ID and checks if all data is in the reponse (including the data defined as lazy).") public void findTargetByControllerIDWithDetails() { - final DistributionSet set = TestDataUtil.generateDistributionSet("test", softwareManagement, - distributionSetManagement); - final DistributionSet set2 = TestDataUtil.generateDistributionSet("test2", softwareManagement, - distributionSetManagement); + final DistributionSet set = testdataFactory.createDistributionSet("test"); + final DistributionSet set2 = testdataFactory.createDistributionSet("test2"); assertThat(targetManagement.countTargetByAssignedDistributionSet(set.getId())).as("Target count is wrong") .isEqualTo(0); @@ -248,7 +248,7 @@ public class TargetManagementTest extends AbstractIntegrationTest { @Test @Description("Checks if the EntityAlreadyExistsException is thrown if the targets with the same controller ID are created twice.") public void createMultipleTargetsDuplicate() { - final List targets = TestDataUtil.buildTargetFixtures(5, "mySimpleTargs", "my simple targets"); + final List targets = testdataFactory.generateTargets(5, "mySimpleTargs", "my simple targets"); targetManagement.createTargets(targets); try { targetManagement.createTargets(targets); @@ -323,7 +323,7 @@ public class TargetManagementTest extends AbstractIntegrationTest { public void singleTargetIsInsertedIntoRepo() throws Exception { final String myCtrlID = "myCtrlID"; - final Target target = TestDataUtil.buildTargetFixture(myCtrlID, "the description!"); + final Target target = testdataFactory.generateTarget(myCtrlID, "the description!"); Target savedTarget = targetManagement.createTarget(target); assertNotNull("The target should not be null", savedTarget); @@ -360,9 +360,9 @@ public class TargetManagementTest extends AbstractIntegrationTest { @Description("Create multiple tragets as bulk operation and delete them in bulk.") public void bulkTargetCreationAndDelete() throws Exception { final String myCtrlID = "myCtrlID"; - final List firstList = TestDataUtil.buildTargetFixtures(100, myCtrlID, "first description"); + final List firstList = testdataFactory.generateTargets(100, myCtrlID, "first description"); - final Target extra = TestDataUtil.buildTargetFixture("myCtrlID-00081XX", "first description"); + final Target extra = testdataFactory.generateTarget("myCtrlID-00081XX", "first description"); List firstSaved = targetManagement.createTargets(firstList); @@ -432,7 +432,7 @@ public class TargetManagementTest extends AbstractIntegrationTest { @Description("Stores target attributes and verfies existence in the repository.") public void savingTargetControllerAttributes() { Iterable ts = targetManagement - .createTargets(TestDataUtil.buildTargetFixtures(100, "myCtrlID", "first description")); + .createTargets(testdataFactory.generateTargets(100, "myCtrlID", "first description")); final Map attribs = new HashMap<>(); attribs.put("a.b.c", "abc"); @@ -541,17 +541,17 @@ public class TargetManagementTest extends AbstractIntegrationTest { @Test @Description("Tests the assigment of tags to the a single target.") public void targetTagAssignment() { - Target t1 = TestDataUtil.buildTargetFixture("id-1", "blablub"); + Target t1 = testdataFactory.generateTarget("id-1", "blablub"); final int noT2Tags = 4; final int noT1Tags = 3; final List t1Tags = tagManagement - .createTargetTags(TestDataUtil.buildTargetTagFixtures(noT1Tags, "tag1")); + .createTargetTags(testdataFactory.generateTargetTags(noT1Tags, "tag1")); t1.getTags().addAll(t1Tags); t1 = targetManagement.createTarget(t1); - Target t2 = TestDataUtil.buildTargetFixture("id-2", "blablub"); + Target t2 = testdataFactory.generateTarget("id-2", "blablub"); final List t2Tags = tagManagement - .createTargetTags(TestDataUtil.buildTargetTagFixtures(noT2Tags, "tag2")); + .createTargetTags(testdataFactory.generateTargetTags(noT2Tags, "tag2")); t2.getTags().addAll(t2Tags); t2 = targetManagement.createTarget(t2); @@ -570,17 +570,17 @@ public class TargetManagementTest extends AbstractIntegrationTest { @Description("Tests the assigment of tags to multiple targets.") public void targetTagBulkAssignments() { final List tagATargets = targetManagement - .createTargets(TestDataUtil.buildTargetFixtures(10, "tagATargets", "first description")); + .createTargets(testdataFactory.generateTargets(10, "tagATargets", "first description")); final List tagBTargets = targetManagement - .createTargets(TestDataUtil.buildTargetFixtures(10, "tagBTargets", "first description")); + .createTargets(testdataFactory.generateTargets(10, "tagBTargets", "first description")); final List tagCTargets = targetManagement - .createTargets(TestDataUtil.buildTargetFixtures(10, "tagCTargets", "first description")); + .createTargets(testdataFactory.generateTargets(10, "tagCTargets", "first description")); final List tagABTargets = targetManagement - .createTargets(TestDataUtil.buildTargetFixtures(10, "tagABTargets", "first description")); + .createTargets(testdataFactory.generateTargets(10, "tagABTargets", "first description")); final List tagABCTargets = targetManagement - .createTargets(TestDataUtil.buildTargetFixtures(10, "tagABCTargets", "first description")); + .createTargets(testdataFactory.generateTargets(10, "tagABCTargets", "first description")); final TargetTag tagA = tagManagement.createTargetTag(new JpaTargetTag("A")); final TargetTag tagB = tagManagement.createTargetTag(new JpaTargetTag("B")); @@ -645,20 +645,20 @@ public class TargetManagementTest extends AbstractIntegrationTest { final TargetTag targTagC = tagManagement.createTargetTag(new JpaTargetTag("Targ-C-Tag")); final List targAs = targetManagement - .createTargets(TestDataUtil.buildTargetFixtures(25, "target-id-A", "first description")); + .createTargets(testdataFactory.generateTargets(25, "target-id-A", "first description")); final List targBs = targetManagement - .createTargets(TestDataUtil.buildTargetFixtures(20, "target-id-B", "first description")); + .createTargets(testdataFactory.generateTargets(20, "target-id-B", "first description")); final List targCs = targetManagement - .createTargets(TestDataUtil.buildTargetFixtures(15, "target-id-C", "first description")); + .createTargets(testdataFactory.generateTargets(15, "target-id-C", "first description")); final List targABs = targetManagement - .createTargets(TestDataUtil.buildTargetFixtures(12, "target-id-AB", "first description")); + .createTargets(testdataFactory.generateTargets(12, "target-id-AB", "first description")); final List targACs = targetManagement - .createTargets(TestDataUtil.buildTargetFixtures(13, "target-id-AC", "first description")); + .createTargets(testdataFactory.generateTargets(13, "target-id-AC", "first description")); final List targBCs = targetManagement - .createTargets(TestDataUtil.buildTargetFixtures(7, "target-id-BC", "first description")); + .createTargets(testdataFactory.generateTargets(7, "target-id-BC", "first description")); final List targABCs = targetManagement - .createTargets(TestDataUtil.buildTargetFixtures(17, "target-id-ABC", "first description")); + .createTargets(testdataFactory.generateTargets(17, "target-id-ABC", "first description")); targetManagement.toggleTagAssignment(targAs, targTagA); targetManagement.toggleTagAssignment(targABs, targTagA); @@ -706,7 +706,7 @@ public class TargetManagementTest extends AbstractIntegrationTest { final TargetTag targTagA = tagManagement.createTargetTag(new JpaTargetTag("Targ-A-Tag")); final List targAs = targetManagement - .createTargets(TestDataUtil.buildTargetFixtures(25, "target-id-A", "first description")); + .createTargets(testdataFactory.generateTargets(25, "target-id-A", "first description")); targetManagement.toggleTagAssignment(targAs, targTagA); @@ -726,7 +726,7 @@ public class TargetManagementTest extends AbstractIntegrationTest { @Description("Test the optimized quere for retrieving all ID/name pairs of targets.") public void findAllTargetIdNamePaiss() { final List targAs = targetManagement - .createTargets(TestDataUtil.buildTargetFixtures(25, "target-id-A", "first description")); + .createTargets(testdataFactory.generateTargets(25, "target-id-A", "first description")); final String[] createdTargetIds = targAs.stream().map(t -> t.getControllerId()) .toArray(size -> new String[size]); @@ -743,10 +743,10 @@ public class TargetManagementTest extends AbstractIntegrationTest { final TargetTag targTagA = tagManagement.createTargetTag(new JpaTargetTag("Targ-A-Tag")); final List targAs = targetManagement - .createTargets(TestDataUtil.buildTargetFixtures(25, "target-id-A", "first description")); + .createTargets(testdataFactory.generateTargets(25, "target-id-A", "first description")); targetManagement.toggleTagAssignment(targAs, targTagA); - targetManagement.createTargets(TestDataUtil.buildTargetFixtures(25, "target-id-B", "first description")); + targetManagement.createTargets(testdataFactory.generateTargets(25, "target-id-B", "first description")); final String[] tagNames = null; final List targetsListWithNoTag = targetManagement diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TenantConfigurationManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TenantConfigurationManagementTest.java index 0e0d50bbc..73feda1c2 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TenantConfigurationManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TenantConfigurationManagementTest.java @@ -29,7 +29,7 @@ import ru.yandex.qatools.allure.annotations.Stories; @Features("Component Tests - Repository") @Stories("Tenant Configuration Management") -public class TenantConfigurationManagementTest extends AbstractIntegrationTestWithMongoDB { +public class TenantConfigurationManagementTest extends AbstractJpaIntegrationTestWithMongoDB { @Test @Description("Tests that tenant specific configuration can be persisted and in case the tenant does not have specific configuration the default from environment is used instead.") diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TestConfiguration.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TestConfiguration.java index 5339ceef2..8ea794f6a 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TestConfiguration.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TestConfiguration.java @@ -16,8 +16,8 @@ import org.eclipse.hawkbit.cache.CacheConstants; import org.eclipse.hawkbit.cache.TenancyCacheManager; import org.eclipse.hawkbit.cache.TenantAwareCacheManager; import org.eclipse.hawkbit.repository.jpa.model.helper.EventBusHolder; -import org.eclipse.hawkbit.repository.jpa.utils.RepositoryDataGenerator; -import org.eclipse.hawkbit.repository.jpa.utils.RepositoryDataGenerator.DatabaseCleanupUtil; +import org.eclipse.hawkbit.repository.util.TestRepositoryManagement; +import org.eclipse.hawkbit.repository.util.TestdataFactory; import org.eclipse.hawkbit.security.DdiSecurityProperties; import org.eclipse.hawkbit.security.SecurityContextTenantAware; import org.eclipse.hawkbit.security.SpringSecurityAuditorAware; @@ -52,14 +52,14 @@ import com.mongodb.MongoClientOptions; @Profile("test") public class TestConfiguration implements AsyncConfigurer { - /** - * DB cleanup utility bean is created. - * - * @return the {@link DatabaseCleanupUtil} bean - */ @Bean - public DatabaseCleanupUtil createDatabaseCleanupUtil() { - return new RepositoryDataGenerator.DatabaseCleanupUtil(); + public TestRepositoryManagement testRepositoryManagement() { + return new JpaTestRepositoryManagement(); + } + + @Bean + public TestdataFactory testdataFactory() { + return new TestdataFactory(); } @Bean diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TestDataUtil.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TestDataUtil.java deleted file mode 100644 index 296fb98ea..000000000 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TestDataUtil.java +++ /dev/null @@ -1,435 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.jpa; - -import static org.fest.assertions.api.Assertions.assertThat; - -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Random; -import java.util.UUID; - -import org.apache.commons.io.IOUtils; -import org.eclipse.hawkbit.repository.ArtifactManagement; -import org.eclipse.hawkbit.repository.ControllerManagement; -import org.eclipse.hawkbit.repository.DistributionSetManagement; -import org.eclipse.hawkbit.repository.SoftwareManagement; -import org.eclipse.hawkbit.repository.TargetManagement; -import org.eclipse.hawkbit.repository.jpa.model.AbstractJpaArtifact; -import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus; -import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; -import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag; -import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType; -import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; -import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType; -import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; -import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag; -import org.eclipse.hawkbit.repository.model.Action; -import org.eclipse.hawkbit.repository.model.Action.Status; -import org.eclipse.hawkbit.repository.model.ActionStatus; -import org.eclipse.hawkbit.repository.model.DistributionSet; -import org.eclipse.hawkbit.repository.model.DistributionSetTag; -import org.eclipse.hawkbit.repository.model.DistributionSetType; -import org.eclipse.hawkbit.repository.model.SoftwareModule; -import org.eclipse.hawkbit.repository.model.SoftwareModuleType; -import org.eclipse.hawkbit.repository.model.Target; -import org.eclipse.hawkbit.repository.model.TargetTag; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; - -import com.google.common.base.Strings; -import com.google.common.collect.Lists; - -import net._01001111.text.LoremIpsum; - -/** - * Data generator utility for tests. - * - * - * - */ -public class TestDataUtil { - private static final LoremIpsum LOREM = new LoremIpsum(); - - public static DistributionSet createTestDistributionSet(final SoftwareManagement softwareManagement, - final DistributionSetManagement distributionSetManagement) { - final Pageable pageReq = new PageRequest(0, 400); - DistributionSet set = TestDataUtil.generateDistributionSet("one", softwareManagement, - distributionSetManagement); - set.setVersion("anotherVersion"); - set = distributionSetManagement.updateDistributionSet(set); - - set.getModules().forEach(module -> { - module.setDescription("updated description"); - softwareManagement.updateSoftwareModule(module); - }); - - // load also lazy stuff - set = distributionSetManagement.findDistributionSetByIdWithDetails(set.getId()); - - assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true)).hasSize(1); - return set; - } - - public static List sendUpdateActionStatusToTargets(final ControllerManagement controllerManagament, - final TargetManagement targetManagement, final ActionRepository actionRepository, final DistributionSet dsA, - final Iterable targs, final Status status, final String... msgs) { - final List result = new ArrayList<>(); - for (final Target t : targs) { - final List findByTarget = actionRepository.findByTarget((JpaTarget) t); - for (final Action action : findByTarget) { - result.add(sendUpdateActionStatusToTarget(controllerManagament, targetManagement, status, action, t, - msgs)); - } - } - return result; - } - - private static Target sendUpdateActionStatusToTarget(final ControllerManagement controllerManagament, - final TargetManagement targetManagement, final Status status, final Action updActA, final Target t, - final String... msgs) { - updActA.setStatus(status); - - final ActionStatus statusMessages = new JpaActionStatus(); - statusMessages.setAction(updActA); - statusMessages.setOccurredAt(System.currentTimeMillis()); - statusMessages.setStatus(status); - for (final String msg : msgs) { - statusMessages.addMessage(msg); - } - controllerManagament.addUpdateActionStatus(statusMessages); - return targetManagement.findTargetByControllerID(t.getControllerId()); - } - - public static List generateDistributionSets(final String suffix, final int number, - final SoftwareManagement softwareManagement, final DistributionSetManagement distributionSetManagement) { - - final List sets = new ArrayList<>(); - for (int i = 0; i < number; i++) { - sets.add(generateDistributionSet(suffix, "v1." + i, softwareManagement, distributionSetManagement, false)); - } - - return sets; - } - - public static DistributionSet generateDistributionSetWithNoSoftwareModules(final String name, final String version, - final DistributionSetManagement distributionSetManagement) { - - final DistributionSet dis = new JpaDistributionSet(); - dis.setName(name); - dis.setVersion(version); - dis.setDescription("Test describtion for " + name); - return distributionSetManagement.createDistributionSet(dis); - } - - public static List generateDistributionSets(final int number, - final SoftwareManagement softwareManagement, final DistributionSetManagement distributionSetManagement) { - - return generateDistributionSets("", number, softwareManagement, distributionSetManagement); - } - - public static JpaDistributionSet generateDistributionSet(final String suffix, final String version, - final SoftwareManagement softwareManagement, final DistributionSetManagement distributionSetManagement, - final boolean isRequiredMigrationStep) { - - final SoftwareModule ah = softwareManagement.createSoftwareModule(new JpaSoftwareModule( - findOrCreateSoftwareModuleType(softwareManagement, "application"), suffix + "application", - version + "." + new Random().nextInt(100), LOREM.words(20), suffix + " vendor Limited, California")); - final SoftwareModule jvm = softwareManagement.createSoftwareModule( - new JpaSoftwareModule(findOrCreateSoftwareModuleType(softwareManagement, "runtime"), - suffix + "app runtime", version + "." + new Random().nextInt(100), LOREM.words(20), - suffix + " vendor GmbH, Stuttgart, Germany")); - final SoftwareModule os = softwareManagement - .createSoftwareModule(new JpaSoftwareModule(findOrCreateSoftwareModuleType(softwareManagement, "os"), - suffix + " Firmware", version + "." + new Random().nextInt(100), LOREM.words(20), - suffix + " vendor Limited Inc, California")); - - final List mand = new ArrayList<>(); - mand.add(findOrCreateSoftwareModuleType(softwareManagement, "os")); - - final List opt = new ArrayList<>(); - opt.add(findOrCreateSoftwareModuleType(softwareManagement, "application")); - opt.add(findOrCreateSoftwareModuleType(softwareManagement, "runtime")); - - return (JpaDistributionSet) distributionSetManagement.createDistributionSet( - buildDistributionSet(suffix != null && suffix.length() > 0 ? suffix : "DS", version, - findOrCreateDistributionSetType(distributionSetManagement, "ecl_os_app_jvm", - "OS mandatory App/JVM optional", mand, opt), - os, jvm, ah).setRequiredMigrationStep(isRequiredMigrationStep)); - } - - public static DistributionSet generateDistributionSet(final String suffix, final String version, - final SoftwareManagement softwareManagement, final DistributionSetManagement distributionSetManagement, - final Collection tags) { - - final DistributionSet set = generateDistributionSet(suffix, version, softwareManagement, - distributionSetManagement, false); - - final List sets = new ArrayList(); - sets.add(set); - - tags.forEach(tag -> distributionSetManagement.toggleTagAssignment(sets, tag)); - - return distributionSetManagement.findDistributionSetById(set.getId()); - - } - - public static List generateTargets(final int number) { - return generateTargets(0, number, "Test target "); - } - - public static List generateTargets(final int number, final String prefix) { - return generateTargets(0, number, prefix); - } - - public static List generateTargets(final int start, final int number, final String prefix) { - final List targets = new ArrayList<>(); - for (int i = start; i < start + number; i++) { - targets.add(new JpaTarget(prefix + i)); - } - - return targets; - } - - public static List generateTargetTags(final int number) { - final List result = new ArrayList<>(); - - for (int i = 0; i < number; i++) { - result.add(new JpaTargetTag("tag" + i, "tagdesc" + i, "" + i)); - } - - return result; - } - - public static List generateDistributionSetTags(final int number) { - final List result = new ArrayList<>(); - - for (int i = 0; i < number; i++) { - result.add(new JpaDistributionSetTag("tag" + i, "tagdesc" + i, "" + i)); - } - - return result; - } - - public static JpaDistributionSet generateDistributionSet(final String suffix, - final SoftwareManagement softwareManagement, final DistributionSetManagement distributionSetManagement, - final boolean isRequiredMigrationStep) { - return generateDistributionSet(suffix, "v1.0", softwareManagement, distributionSetManagement, - isRequiredMigrationStep); - } - - public static JpaDistributionSet generateDistributionSet(final String suffix, - final SoftwareManagement softwareManagement, final DistributionSetManagement distributionSetManagement) { - return generateDistributionSet(suffix, "v1.0", softwareManagement, distributionSetManagement, false); - } - - public static List generateArtifacts(final ArtifactManagement artifactManagement, - final Long moduleId) { - final List artifacts = new ArrayList<>(); - for (int i = 0; i < 3; i++) { - final InputStream stubInputStream = IOUtils.toInputStream("some test data" + i); - artifacts.add((AbstractJpaArtifact) artifactManagement.createLocalArtifact(stubInputStream, moduleId, - "filename" + i, false)); - - } - - return artifacts; - } - - public static Target createTarget(final TargetManagement targetManagement) { - final String targetExist = "targetExist"; - final Target target = new JpaTarget(targetExist); - targetManagement.createTarget(target); - return target; - } - - public static DistributionSet generateDistributionSet(final String suffix, - final SoftwareManagement softwareManagement, final DistributionSetManagement distributionSetManagement, - final Collection tags) { - return generateDistributionSet(suffix, "v1.0", softwareManagement, distributionSetManagement, tags); - } - - public static SoftwareModuleType findOrCreateSoftwareModuleType(final SoftwareManagement softwareManagement, - final String softwareModuleType) { - final SoftwareModuleType findSoftwareModuleTypeByKey = softwareManagement - .findSoftwareModuleTypeByKey(softwareModuleType); - if (findSoftwareModuleTypeByKey != null) { - return findSoftwareModuleTypeByKey; - } - return softwareManagement.createSoftwareModuleType(new JpaSoftwareModuleType(softwareModuleType, - softwareModuleType, "Standard type " + softwareManagement, 1)); - } - - public static DistributionSetType findOrCreateDistributionSetType( - final DistributionSetManagement distributionSetManagement, final String dsTypeKey, final String dsTypeName, - final Collection mandatory, final Collection optional) { - final DistributionSetType findDistributionSetTypeByname = distributionSetManagement - .findDistributionSetTypeByKey(dsTypeKey); - - if (findDistributionSetTypeByname != null) { - return findDistributionSetTypeByname; - } - - final DistributionSetType type = new JpaDistributionSetType(dsTypeKey, dsTypeName, - "Standard type" + dsTypeName); - mandatory.forEach(entry -> type.addMandatoryModuleType(entry)); - optional.forEach(entry -> type.addOptionalModuleType(entry)); - - return distributionSetManagement.createDistributionSetType(type); - } - - /** - * builds a set of {@link Target} fixtures from the given parameters. - * - * @param noOfTgts - * number of targets to create - * @param ctlrIDPrefix - * prefix used for the controller ID - * @param descriptionPrefix - * prefix used for the description - * @return set of {@link Target} - */ - public static List buildTargetFixtures(final int noOfTgts, final String ctlrIDPrefix, - final String descriptionPrefix) { - return buildTargetFixtures(noOfTgts, ctlrIDPrefix, descriptionPrefix, null); - } - - /** - * method creates set of targets by by generating the controller ID and the - * description like: prefix + no of target. - * - * @param noOfTgts - * number of targets which should be created - * @param ctlrIDPrefix - * prefix of the controllerID which is concatenated with the - * number of the target - * @param descriptionPrefix - * prefix of the target description which is concatenated with - * the number of the target - * @param tags - * tags which should be added to the created {@link Target}s - * @return set of created targets - */ - public static List buildTargetFixtures(final int noOfTgts, final String ctlrIDPrefix, - final String descriptionPrefix, final TargetTag[] tags) { - final List list = new ArrayList(); - for (int i = 0; i < noOfTgts; i++) { - String ctrlID = ctlrIDPrefix; - if (Strings.isNullOrEmpty(ctrlID)) { - ctrlID = UUID.randomUUID().toString(); - } - ctrlID = String.format("%s-%05d", ctrlID, i); - - final String description = String.format("the description of ProvisioningTarget: [%s]", ctrlID); - - final Target target = buildTargetFixture(ctrlID, description, tags); - list.add(target); - - } - return list; - } - - /** - * builds a single {@link Target} fixture from the given parameters. - * - * @param ctrlID - * controllerID - * @param description - * the description of the target - * @param tags - * assigned {@link TargetTag}s - * @return the created {@link Target} - */ - public static Target buildTargetFixture(final String ctrlID, final String description, final TargetTag[] tags) { - final Target target = new JpaTarget(ctrlID); - target.setName("Prov.Target ".concat(ctrlID)); - target.setDescription(description); - if (tags != null && tags.length > 0) { - for (final TargetTag t : tags) { - target.getTags().add(t); - } - } - return target; - } - - /** - * builder method for creating a single target object. - * - * @param ctrlID - * the ID of the target - * @param description - * of the target - * @return the created target object - */ - public static Target buildTargetFixture(final String ctrlID, final String description) { - return buildTargetFixture(ctrlID, description, null); - } - - /** - * builder method for creating a {@link DistributionSet}. - * - * @param name - * of the DS - * @param version - * of the DS - * @param os - * operating system of the DS - * @param jvm - * java virtual machine of the DS - * @param agentHub - * of the DS - * @return the created {@link DistributionSet} - */ - public static DistributionSet buildDistributionSet(final String name, final String version, - final DistributionSetType type, final SoftwareModule os, final SoftwareModule jvm, - final SoftwareModule agentHub) { - final DistributionSet distributionSet = new JpaDistributionSet(name, version, null, type, - Lists.newArrayList(os, jvm, agentHub)); - distributionSet.setDescription( - String.format("description of DistributionSet; name = '%s', version = '%s'", name, version)); - return distributionSet; - } - - /** - * builder method for creating a set of {@link TargetTag}. - * - * @param noOfTags - * number of {@link TargetTag}. to be created - * @param tagPrefix - * prefix for the {@link TargetTag.getName()} - * @return the created set of {@link TargetTag}s - */ - public static List buildTargetTagFixtures(final int noOfTags, final String tagPrefix) { - final List list = new ArrayList<>(); - for (int i = 0; i < noOfTags; i++) { - String tagName = "myTag"; - if (!Strings.isNullOrEmpty(tagPrefix)) { - tagName = tagPrefix; - } - tagName = String.format("%s-%05d", tagName, i); - - final TargetTag targetTag = buildTargetTagFixture(tagName); - list.add(targetTag); - } - return list; - } - - /** - * builder method for creating a simple {@link TargetTag}. - * - * @param tagName - * name of the Tag - * @return the {@link TargetTag} - */ - public static TargetTag buildTargetTagFixture(final String tagName) { - return new JpaTargetTag(tagName); - } -} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/model/ModelEqualsHashcodeTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/model/ModelEqualsHashcodeTest.java index 2114afc42..9f4cefa5d 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/model/ModelEqualsHashcodeTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/model/ModelEqualsHashcodeTest.java @@ -10,7 +10,7 @@ package org.eclipse.hawkbit.repository.jpa.model; import static org.fest.assertions.api.Assertions.assertThat; -import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest; +import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.junit.Test; @@ -20,7 +20,7 @@ import ru.yandex.qatools.allure.annotations.Stories; @Features("Unit Tests - Repository") @Stories("Repository Model") -public class ModelEqualsHashcodeTest extends AbstractIntegrationTest { +public class ModelEqualsHashcodeTest extends AbstractJpaIntegrationTest { @Test @Description("Verfies that different objects even with identical primary key, version and tenant " diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLActionFieldsTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLActionFieldsTest.java index 949e278ab..3138c9f86 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLActionFieldsTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLActionFieldsTest.java @@ -13,7 +13,7 @@ import static org.junit.Assert.fail; import org.eclipse.hawkbit.repository.ActionFields; import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException; -import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest; +import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest; import org.eclipse.hawkbit.repository.jpa.model.JpaAction; import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; import org.eclipse.hawkbit.repository.model.Action; @@ -30,7 +30,7 @@ import ru.yandex.qatools.allure.annotations.Stories; @Features("Component Tests - Repository") @Stories("RSQL filter actions") -public class RSQLActionFieldsTest extends AbstractIntegrationTest { +public class RSQLActionFieldsTest extends AbstractJpaIntegrationTest { private Target target; private JpaAction action; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLDistributionSetFieldTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLDistributionSetFieldTest.java index 2c3747586..6604e3152 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLDistributionSetFieldTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLDistributionSetFieldTest.java @@ -15,12 +15,12 @@ import java.util.Arrays; import org.eclipse.hawkbit.repository.DistributionSetFields; import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException; -import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest; -import org.eclipse.hawkbit.repository.jpa.TestDataUtil; +import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetMetadata; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetTag; +import org.eclipse.hawkbit.repository.util.TestdataFactory; import org.junit.Before; import org.junit.Test; import org.springframework.data.domain.Page; @@ -32,19 +32,18 @@ import ru.yandex.qatools.allure.annotations.Stories; @Features("Component Tests - Repository") @Stories("RSQL filter distribution set") -public class RSQLDistributionSetFieldTest extends AbstractIntegrationTest { +public class RSQLDistributionSetFieldTest extends AbstractJpaIntegrationTest { @Before public void seuptBeforeTest() { - DistributionSet ds = TestDataUtil.generateDistributionSet("DS", softwareManagement, distributionSetManagement); + DistributionSet ds = testdataFactory.createDistributionSet("DS"); ds.setDescription("DS"); ds = distributionSetManagement.updateDistributionSet(ds); distributionSetManagement .createDistributionSetMetadata(new JpaDistributionSetMetadata("metaKey", ds, "metaValue")); - DistributionSet ds2 = TestDataUtil - .generateDistributionSets("NewDS", 3, softwareManagement, distributionSetManagement).get(0); + DistributionSet ds2 = testdataFactory.createDistributionSets("NewDS", 3).get(0); ds2.setDescription("DS%"); ds2 = distributionSetManagement.updateDistributionSet(ds2); @@ -89,10 +88,12 @@ public class RSQLDistributionSetFieldTest extends AbstractIntegrationTest { @Test @Description("Test filter distribution set by version") public void testFilterByParameterVersion() { - assertRSQLQuery(DistributionSetFields.VERSION.name() + "==v1.0", 2); - assertRSQLQuery(DistributionSetFields.VERSION.name() + "!=v1.0", 2); - assertRSQLQuery(DistributionSetFields.VERSION.name() + "=in=(v1.0,v1.1)", 3); - assertRSQLQuery(DistributionSetFields.VERSION.name() + "=out=(v1.0,error)", 2); + assertRSQLQuery(DistributionSetFields.VERSION.name() + "==" + TestdataFactory.DEFAULT_VERSION, 1); + assertRSQLQuery(DistributionSetFields.VERSION.name() + "!=" + TestdataFactory.DEFAULT_VERSION, 3); + assertRSQLQuery( + DistributionSetFields.VERSION.name() + "=in=(" + TestdataFactory.DEFAULT_VERSION + ",1.0.0,1.0.1)", 3); + assertRSQLQuery(DistributionSetFields.VERSION.name() + "=out=(" + TestdataFactory.DEFAULT_VERSION + ",error)", + 3); } @Test @@ -121,10 +122,10 @@ public class RSQLDistributionSetFieldTest extends AbstractIntegrationTest { @Test @Description("Test filter distribution set by type") public void testFilterByType() { - assertRSQLQuery(DistributionSetFields.TYPE.name() + "==ecl_os_app_jvm", 4); + assertRSQLQuery(DistributionSetFields.TYPE.name() + "==" + TestdataFactory.DS_TYPE_DEFAULT, 4); assertRSQLQuery(DistributionSetFields.TYPE.name() + "==noExist*", 0); - assertRSQLQuery(DistributionSetFields.TYPE.name() + "=in=(ecl_os_app_jvm,ecl)", 4); - assertRSQLQuery(DistributionSetFields.TYPE.name() + "=out=(ecl_os_app_jvm)", 0); + assertRSQLQuery(DistributionSetFields.TYPE.name() + "=in=(" + TestdataFactory.DS_TYPE_DEFAULT + ",ecl)", 4); + assertRSQLQuery(DistributionSetFields.TYPE.name() + "=out=(" + TestdataFactory.DS_TYPE_DEFAULT + ")", 0); } @Test diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLDistributionSetMetadataFieldsTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLDistributionSetMetadataFieldsTest.java index af96da86f..65b677693 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLDistributionSetMetadataFieldsTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLDistributionSetMetadataFieldsTest.java @@ -14,8 +14,7 @@ import java.util.ArrayList; import java.util.List; import org.eclipse.hawkbit.repository.DistributionSetMetadataFields; -import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest; -import org.eclipse.hawkbit.repository.jpa.TestDataUtil; +import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetMetadata; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetMetadata; @@ -30,14 +29,13 @@ import ru.yandex.qatools.allure.annotations.Stories; @Features("Component Tests - Repository") @Stories("RSQL filter distribution set metadata") -public class RSQLDistributionSetMetadataFieldsTest extends AbstractIntegrationTest { +public class RSQLDistributionSetMetadataFieldsTest extends AbstractJpaIntegrationTest { private Long distributionSetId; @Before public void setupBeforeTest() { - final DistributionSet distributionSet = TestDataUtil.generateDistributionSet("DS", softwareManagement, - distributionSetManagement); + final DistributionSet distributionSet = testdataFactory.createDistributionSet("DS"); distributionSetId = distributionSet.getId(); final List metadata = new ArrayList<>(); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLRolloutGroupFields.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLRolloutGroupFields.java index 408c1847e..fd48aed94 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLRolloutGroupFields.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLRolloutGroupFields.java @@ -11,8 +11,7 @@ package org.eclipse.hawkbit.repository.jpa.rsql; import static org.fest.assertions.api.Assertions.assertThat; import org.eclipse.hawkbit.repository.RolloutGroupFields; -import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest; -import org.eclipse.hawkbit.repository.jpa.TestDataUtil; +import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest; import org.eclipse.hawkbit.repository.jpa.model.JpaRollout; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Rollout; @@ -30,7 +29,7 @@ import ru.yandex.qatools.allure.annotations.Stories; @Features("Component Tests - Repository") @Stories("RSQL filter rollout group") -public class RSQLRolloutGroupFields extends AbstractIntegrationTest { +public class RSQLRolloutGroupFields extends AbstractJpaIntegrationTest { private Long rolloutGroupId; private Rollout rollout; @@ -38,9 +37,8 @@ public class RSQLRolloutGroupFields extends AbstractIntegrationTest { @Before public void seuptBeforeTest() { final int amountTargets = 20; - targetManagement.createTargets(TestDataUtil.buildTargetFixtures(amountTargets, "rollout", "rollout")); - final DistributionSet dsA = TestDataUtil.generateDistributionSet("", softwareManagement, - distributionSetManagement); + targetManagement.createTargets(testdataFactory.generateTargets(amountTargets, "rollout", "rollout")); + final DistributionSet dsA = testdataFactory.createDistributionSet(""); rollout = createRollout("rollout1", 4, dsA.getId(), "controllerId==rollout*"); rollout = rolloutManagement.findRolloutById(rollout.getId()); this.rolloutGroupId = rollout.getRolloutGroups().get(0).getId(); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleFieldTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleFieldTest.java index 6fb220880..d55de383f 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleFieldTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleFieldTest.java @@ -11,7 +11,7 @@ package org.eclipse.hawkbit.repository.jpa.rsql; import static org.fest.assertions.api.Assertions.assertThat; import org.eclipse.hawkbit.repository.SoftwareModuleFields; -import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest; +import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleMetadata; import org.eclipse.hawkbit.repository.model.SoftwareModule; @@ -27,7 +27,7 @@ import ru.yandex.qatools.allure.annotations.Stories; @Features("Component Tests - Repository") @Stories("RSQL filter software module") -public class RSQLSoftwareModuleFieldTest extends AbstractIntegrationTest { +public class RSQLSoftwareModuleFieldTest extends AbstractJpaIntegrationTest { @Before public void setupBeforeTest() { diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleMetadataFieldsTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleMetadataFieldsTest.java index 87f151873..3f843bffc 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleMetadataFieldsTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleMetadataFieldsTest.java @@ -14,12 +14,11 @@ import java.util.ArrayList; import java.util.List; import org.eclipse.hawkbit.repository.SoftwareModuleMetadataFields; -import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest; -import org.eclipse.hawkbit.repository.jpa.TestDataUtil; -import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; +import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleMetadata; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata; +import org.eclipse.hawkbit.repository.util.TestdataFactory; import org.junit.Before; import org.junit.Test; import org.springframework.data.domain.Page; @@ -31,15 +30,14 @@ import ru.yandex.qatools.allure.annotations.Stories; @Features("Component Tests - Repository") @Stories("RSQL filter software module metadata") -public class RSQLSoftwareModuleMetadataFieldsTest extends AbstractIntegrationTest { +public class RSQLSoftwareModuleMetadataFieldsTest extends AbstractJpaIntegrationTest { private Long softwareModuleId; @Before public void setupBeforeTest() { - final SoftwareModule softwareModule = softwareManagement.createSoftwareModule( - new JpaSoftwareModule(TestDataUtil.findOrCreateSoftwareModuleType(softwareManagement, "application"), - "application", "1.0.0", "Desc", "vendor Limited, California")); + final SoftwareModule softwareModule = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_APP); + softwareModuleId = softwareModule.getId(); final List metadata = new ArrayList<>(); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleTypeFieldsTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleTypeFieldsTest.java index 3254ee4f6..e1538aaee 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleTypeFieldsTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleTypeFieldsTest.java @@ -11,7 +11,7 @@ package org.eclipse.hawkbit.repository.jpa.rsql; import static org.fest.assertions.api.Assertions.assertThat; import org.eclipse.hawkbit.repository.SoftwareModuleTypeFields; -import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest; +import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.junit.Test; import org.springframework.data.domain.Page; @@ -23,7 +23,7 @@ import ru.yandex.qatools.allure.annotations.Stories; @Features("Component Tests - Repository") @Stories("RSQL filter software module test type") -public class RSQLSoftwareModuleTypeFieldsTest extends AbstractIntegrationTest { +public class RSQLSoftwareModuleTypeFieldsTest extends AbstractJpaIntegrationTest { @Test @Description("Test filter software module test type by id") @@ -34,7 +34,7 @@ public class RSQLSoftwareModuleTypeFieldsTest extends AbstractIntegrationTest { @Test @Description("Test filter software module test type by name") public void testFilterByParameterName() { - assertRSQLQuery(SoftwareModuleTypeFields.NAME.name() + "==ECL*", 3); + assertRSQLQuery(SoftwareModuleTypeFields.NAME.name() + "==Firmware", 1); } @Test @@ -55,7 +55,7 @@ public class RSQLSoftwareModuleTypeFieldsTest extends AbstractIntegrationTest { @Test @Description("Test filter software module test type by max") public void testFilterByMaxAssignment() { - assertRSQLQuery(SoftwareModuleTypeFields.MAXASSIGNMENTS.name() + "==1", 3); + assertRSQLQuery(SoftwareModuleTypeFields.MAXASSIGNMENTS.name() + "==1", 2); } private void assertRSQLQuery(final String rsqlParam, final long excpectedEntity) { diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLTagFieldsTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLTagFieldsTest.java index a60d17818..3772bb372 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLTagFieldsTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLTagFieldsTest.java @@ -11,7 +11,7 @@ package org.eclipse.hawkbit.repository.jpa.rsql; import static org.fest.assertions.api.Assertions.assertThat; import org.eclipse.hawkbit.repository.TagFields; -import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest; +import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag; import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag; import org.eclipse.hawkbit.repository.model.DistributionSetTag; @@ -27,7 +27,7 @@ import ru.yandex.qatools.allure.annotations.Stories; @Features("Component Tests - Repository") @Stories("RSQL filter target and distribution set tags") -public class RSQLTagFieldsTest extends AbstractIntegrationTest { +public class RSQLTagFieldsTest extends AbstractJpaIntegrationTest { @Before public void seuptBeforeTest() { diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLTargetFieldTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLTargetFieldTest.java index 2e4f0346f..f21e4c938 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLTargetFieldTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLTargetFieldTest.java @@ -15,8 +15,7 @@ import java.util.Arrays; import org.eclipse.hawkbit.repository.TargetFields; import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException; -import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest; -import org.eclipse.hawkbit.repository.jpa.TestDataUtil; +import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest; import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo; import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag; @@ -25,6 +24,7 @@ import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetInfo; import org.eclipse.hawkbit.repository.model.TargetTag; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; +import org.eclipse.hawkbit.repository.util.TestdataFactory; import org.junit.Before; import org.junit.Test; import org.springframework.data.domain.Page; @@ -36,19 +36,17 @@ import ru.yandex.qatools.allure.annotations.Stories; @Features("Component Tests - Repository") @Stories("RSQL filter target") -public class RSQLTargetFieldTest extends AbstractIntegrationTest { +public class RSQLTargetFieldTest extends AbstractJpaIntegrationTest { @Before public void seuptBeforeTest() { - final DistributionSet ds = TestDataUtil.generateDistributionSet("AssignedDs", softwareManagement, - distributionSetManagement); + final DistributionSet ds = testdataFactory.createDistributionSet("AssignedDs"); - final JpaTarget target = new JpaTarget("targetId123"); + final Target target = entityFactory.generateTarget("targetId123"); target.setDescription("targetId123"); - final TargetInfo targetInfo = new JpaTargetInfo(target); + final TargetInfo targetInfo = target.getTargetInfo(); targetInfo.getControllerAttributes().put("revision", "1.1"); - target.setTargetInfo(targetInfo); ((JpaTargetInfo) target.getTargetInfo()).setUpdateStatus(TargetUpdateStatus.PENDING); targetManagement.createTarget(target); @@ -149,11 +147,13 @@ public class RSQLTargetFieldTest extends AbstractIntegrationTest { @Test @Description("Test filter target by assigned ds version") public void testFilterByAssignedDsVersion() { - assertRSQLQuery(TargetFields.ASSIGNEDDS.name() + ".version==v1.0", 1); + assertRSQLQuery(TargetFields.ASSIGNEDDS.name() + ".version==" + TestdataFactory.DEFAULT_VERSION, 1); assertRSQLQuery(TargetFields.ASSIGNEDDS.name() + ".version==*1*", 1); assertRSQLQuery(TargetFields.ASSIGNEDDS.name() + ".version==noExist*", 0); - assertRSQLQuery(TargetFields.ASSIGNEDDS.name() + ".version=in=(v1.0,notexist)", 1); - assertRSQLQuery(TargetFields.ASSIGNEDDS.name() + ".version=out=(v1.0,notexist)", 0); + assertRSQLQuery( + TargetFields.ASSIGNEDDS.name() + ".version=in=(" + TestdataFactory.DEFAULT_VERSION + ",notexist)", 1); + assertRSQLQuery( + TargetFields.ASSIGNEDDS.name() + ".version=out=(" + TestdataFactory.DEFAULT_VERSION + ",notexist)", 0); } @Test diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/tenancy/MultiTenancyEntityTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/tenancy/MultiTenancyEntityTest.java index 1c0beeabf..86a0389d5 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/tenancy/MultiTenancyEntityTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/tenancy/MultiTenancyEntityTest.java @@ -10,14 +10,14 @@ package org.eclipse.hawkbit.repository.jpa.tenancy; import static org.fest.assertions.api.Assertions.assertThat; -import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest; -import org.eclipse.hawkbit.repository.jpa.WithSpringAuthorityRule; -import org.eclipse.hawkbit.repository.jpa.WithUser; +import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType; import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Target; +import org.eclipse.hawkbit.repository.util.WithSpringAuthorityRule; +import org.eclipse.hawkbit.repository.util.WithUser; import org.junit.Test; import org.springframework.data.domain.Page; import org.springframework.data.domain.Slice; @@ -34,7 +34,7 @@ import ru.yandex.qatools.allure.annotations.Stories; */ @Features("Component Tests - Repository") @Stories("Multi Tenancy") -public class MultiTenancyEntityTest extends AbstractIntegrationTest { +public class MultiTenancyEntityTest extends AbstractJpaIntegrationTest { @Test @Description(value = "Ensures that multiple targets with same controller-ID can be created for different tenants.") diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/utils/RepositoryDataGenerator.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/utils/RepositoryDataGenerator.java deleted file mode 100644 index 9d41ecb65..000000000 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/utils/RepositoryDataGenerator.java +++ /dev/null @@ -1,485 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.jpa.utils; - -import java.net.URI; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Calendar; -import java.util.List; -import java.util.Random; -import java.util.UUID; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.stream.IntStream; - -import javax.persistence.EntityManager; -import javax.persistence.Query; -import javax.transaction.Transactional; - -import org.eclipse.hawkbit.im.authentication.SpPermission; -import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; -import org.eclipse.hawkbit.im.authentication.TenantAwareAuthenticationDetails; -import org.eclipse.hawkbit.repository.ControllerManagement; -import org.eclipse.hawkbit.repository.DeploymentManagement; -import org.eclipse.hawkbit.repository.DistributionSetAssignmentResult; -import org.eclipse.hawkbit.repository.DistributionSetManagement; -import org.eclipse.hawkbit.repository.SoftwareManagement; -import org.eclipse.hawkbit.repository.TagManagement; -import org.eclipse.hawkbit.repository.TargetManagement; -import org.eclipse.hawkbit.repository.jpa.TestDataUtil; -import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus; -import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag; -import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; -import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType; -import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; -import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag; -import org.eclipse.hawkbit.repository.model.Action; -import org.eclipse.hawkbit.repository.model.Action.Status; -import org.eclipse.hawkbit.repository.model.ActionStatus; -import org.eclipse.hawkbit.repository.model.DistributionSet; -import org.eclipse.hawkbit.repository.model.DistributionSetTag; -import org.eclipse.hawkbit.repository.model.SoftwareModuleType; -import org.eclipse.hawkbit.repository.model.Target; -import org.eclipse.hawkbit.repository.model.TargetTag; -import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; -import org.eclipse.hawkbit.util.IpUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.data.auditing.AuditingHandler; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.security.authentication.TestingAuthenticationToken; -import org.springframework.security.core.context.SecurityContext; -import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.security.core.context.SecurityContextImpl; - -import net._01001111.text.LoremIpsum; - -/** - * Generates test data for setting up the repository for test or demonstration - * purpose. - * - * - * - */ -public final class RepositoryDataGenerator { - private static final Logger LOG = LoggerFactory.getLogger(RepositoryDataGenerator.class); - - public static void initDemoRepo(final ConfigurableApplicationContext context) { - final PersistentInitDemoDataBuilder initDemoDataBuilder = new PersistentInitDemoDataBuilder(context); - initDemoDataBuilder.initDemoRepo(20, 0); - } - - public static void initLoadRepo(final ConfigurableApplicationContext context) { - final PersistentInitDemoDataBuilder initDemoDataBuilder = new PersistentInitDemoDataBuilder(context); - initDemoDataBuilder.initDemoRepo(200, 200); - } - - /** - * builder which build initial demo data and stores it to the repos. - * - */ - private static final class PersistentInitDemoDataBuilder { - - private final SoftwareManagement softwareManagement; - private final TargetManagement targetManagement; - private final DeploymentManagement deploymentManagement; - private final TagManagement tagManagement; - private final ControllerManagement controllerManagement; - private final DistributionSetManagement distributionSetManagement; - - private final DatabaseCleanupUtil dbCleanupUtil; - - private final AuditingHandler auditingHandler; - - final LoremIpsum jlorem = new LoremIpsum(); - - PersistentInitDemoDataBuilder(final ConfigurableApplicationContext context) { - softwareManagement = context.getBean(SoftwareManagement.class); - targetManagement = context.getBean(TargetManagement.class); - tagManagement = context.getBean(TagManagement.class); - deploymentManagement = context.getBean(DeploymentManagement.class); - controllerManagement = context.getBean(ControllerManagement.class); - distributionSetManagement = context.getBean(DistributionSetManagement.class); - - dbCleanupUtil = context.getBean(DatabaseCleanupUtil.class); - - auditingHandler = context.getBean(AuditingHandler.class); - } - - private void runAsAllAuthorityContext(final Runnable runnable) { - final SecurityContext oldContext = SecurityContextHolder.getContext(); - try { - final SecurityContextImpl securityContextImpl = new SecurityContextImpl(); - final TestingAuthenticationToken authentication = new TestingAuthenticationToken("repogenator", - "repogenator", SpPermission.CREATE_REPOSITORY, SpPermission.CREATE_TARGET, - SpPermission.DELETE_REPOSITORY, SpPermission.DELETE_TARGET, SpPermission.READ_REPOSITORY, - SpPermission.READ_TARGET, SpPermission.UPDATE_REPOSITORY, SpPermission.UPDATE_TARGET, - SpringEvalExpressions.CONTROLLER_ROLE); - securityContextImpl.setAuthentication(authentication); - authentication.setDetails(new TenantAwareAuthenticationDetails("default", false)); - SecurityContextHolder.setContext(securityContextImpl); - runnable.run(); - } finally { - SecurityContextHolder.setContext(oldContext); - } - } - - public void generateTestTagetGroup(final String group, final int sizeMultiplikator) { - final DistributionSetTag dsTag = tagManagement - .createDistributionSetTag(new JpaDistributionSetTag("For " + group + "s")); - - auditingHandler.setDateTimeProvider(() -> { - final Calendar instance = Calendar.getInstance(); - instance.add(Calendar.MONTH, -new Random().nextInt(7)); - - return instance; - }); - - final List targets = createTargetTestGroup(group, 20 * sizeMultiplikator); - - auditingHandler.setDateTimeProvider(() -> { - final Calendar instance = Calendar.getInstance(); - return instance; - }); - - LOG.debug("initDemoRepo - start now real action history for group: {}", group); - - // Old history of succesfully finished operations - IntStream.range(0, 10).forEach(idx -> { - final DistributionSet dsReal = TestDataUtil.generateDistributionSet(group + " Release", "v1." + idx, - softwareManagement, distributionSetManagement, - Arrays.asList(new DistributionSetTag[] { dsTag })); - - final DistributionSetAssignmentResult result = deploymentManagement.assignDistributionSet(dsReal, - targets); - - createSimpleActionStatusHistory(result.getActions()); - }); - - final List> targetGroups = splitIntoGroups(targets); - - IntStream.range(0, targetGroups.size()).forEach(idx -> { - final DistributionSet dsReal = TestDataUtil.generateDistributionSet(group + " Release", "v2." + idx, - softwareManagement, distributionSetManagement, - Arrays.asList(new DistributionSetTag[] { dsTag })); - - final DistributionSetAssignmentResult result = deploymentManagement.assignDistributionSet(dsReal, - targetGroups.get(idx)); - - createActionStatusHistory(result.getActions(), sizeMultiplikator); - }); - - LOG.debug("initDemoRepo - real action history finished for group: {}", group); - } - - private List> splitIntoGroups(final List allTargets) { - - final int elements = allTargets.size(); - - final int group1 = elements * (5 + new Random().nextInt(5)) / 100; - final int group2 = elements * (15 + new Random().nextInt(5)) / 100; - - final List> result = new ArrayList>(); - - result.add(allTargets.subList(0, group1)); - result.add(allTargets.subList(group1, group2)); - result.add(allTargets.subList(group2, elements)); - - return result; - - } - - private void createActionStatusHistory(final List actions, final int sizeMultiplikator) { - final AtomicInteger counter = new AtomicInteger(); - - int index = 0; - for (final Long actionGiven : actions) { - // retrieved - Action action = controllerManagement.registerRetrieved( - deploymentManagement.findActionWithDetails(actionGiven), - "Controller retrieved update action and should start now the download."); - - // download - final ActionStatus download = new JpaActionStatus(); - download.setAction(action); - download.setStatus(Status.DOWNLOAD); - download.addMessage("Controller started download."); - action = controllerManagement.addUpdateActionStatus(download); - - // warning - final ActionStatus warning = new JpaActionStatus(); - warning.setAction(action); - warning.setStatus(Status.WARNING); - warning.addMessage("Some warning: " + jlorem.words(new Random().nextInt(50))); - action = controllerManagement.addUpdateActionStatus(warning); - - // garbage - for (int i = 0; i < new Random().nextInt(10); i++) { - final ActionStatus running = new JpaActionStatus(); - running.setAction(action); - running.setStatus(Status.RUNNING); - running.addMessage("Still running: " + jlorem.words(new Random().nextInt(50))); - action = controllerManagement.addUpdateActionStatus(running); - for (int g = 0; g < new Random().nextInt(5); g++) { - final ActionStatus rand = new JpaActionStatus(); - rand.setAction(action); - rand.setStatus(Status.RUNNING); - rand.addMessage(jlorem.words(new Random().nextInt(50))); - action = controllerManagement.addUpdateActionStatus(rand); - } - } - - // close - final ActionStatus close = new JpaActionStatus(); - close.setAction(action); - - // with error - final int incrementAndGet = counter.incrementAndGet(); - if (incrementAndGet % 5 == 0) { - close.setStatus(Status.ERROR); - close.addMessage("Controller reported CLOSED with ERROR!"); - action = controllerManagement.addUpdateActionStatus(close); - } - // with OK - else { - close.setStatus(Status.FINISHED); - close.addMessage("Controller reported CLOSED with OK!"); - action = controllerManagement.addUpdateActionStatus(close); - } - - index++; - } - } - - private void createSimpleActionStatusHistory(final List actions) { - for (final Long actionGiven : actions) { - // retrieved - Action action = controllerManagement.registerRetrieved( - deploymentManagement.findActionWithDetails(actionGiven), - "Controller retrieved update action and should start now the download."); - - // close - final ActionStatus close = new JpaActionStatus(); - close.setAction(action); - close.setStatus(Status.FINISHED); - close.addMessage("Controller reported CLOSED with OK!"); - action = controllerManagement.addUpdateActionStatus(close); - - } - } - - private List createTargetTestGroup(final String group, final int targets) { - LOG.debug("createTargetTestGroup: create group {}", group); - - final TargetTag targTag = tagManagement.createTargetTag(new JpaTargetTag(group)); - - final List targAs = targetManagement.createTargets(buildTargets(targets, group), - TargetUpdateStatus.REGISTERED, System.currentTimeMillis() - new Random().nextInt(50_000_000), - generateIPAddress()); - LOG.debug("createTargetTestGroup: {} created", group); - - LOG.debug("createTargetTestGroup: {} targets status updated including IP", group); - - return targetManagement.toggleTagAssignment(targAs, targTag).getAssignedEntity(); - } - - private List buildTargets(final int noOfTgts, final String descriptionPrefix) { - - final List result = new ArrayList(noOfTgts); - - for (int i = 0; i < noOfTgts; i++) { - final Target target = new JpaTarget(UUID.randomUUID().toString()); - - final StringBuilder builder = new StringBuilder(); - builder.append(descriptionPrefix); - builder.append(jlorem.words(5)); - - target.setDescription(builder.toString()); - target.getTargetInfo().getControllerAttributes().put("revision", "1.1"); - target.getTargetInfo().getControllerAttributes().put("capacity", "128M"); - target.getTargetInfo().getControllerAttributes().put("serial", - String.valueOf(System.currentTimeMillis())); - - result.add(target); - - } - - return result; - } - - /** - * method writes initial test/demo data to the repositories. - * - * @param sizeMultiplikator - * the entire scenario - * @param loadtestgroups - * packages of 1_000 targets - */ - private void initDemoRepo(final int sizeMultiplikator, final int loadtestgroups) { - final LoremIpsum jlorem = new LoremIpsum(); - - runAsAllAuthorityContext(() -> { - dbCleanupUtil.cleanupDB(null); - - // generate targets and assign DS - // 5 groups - 100 targets each -> 500 - final String[] targetTestGroups = { "SHC", "CCU", "Vehicle", "Vending machine", "ECU" }; - - final String[] modulesTypes = { "HeadUnit_FW", "EDC17_FW", "OSGi_Bundle" }; - - final DistributionSetTag depTag = tagManagement - .createDistributionSetTag(new JpaDistributionSetTag("deprecated")); - - Arrays.stream(targetTestGroups).forEach(group -> { - generateTestTagetGroup(group, sizeMultiplikator); - }); - - // garbage DS - LOG.debug("initDemoRepo - start now DS garbage"); - TestDataUtil.generateDistributionSets("Generic Software Package", sizeMultiplikator, softwareManagement, - distributionSetManagement); - LOG.debug("initDemoRepo - DS garbage finished"); - - LOG.debug("initDemoRepo - start now Extra Software Modules and types"); - Arrays.stream(modulesTypes).forEach(typeName -> { - final SoftwareModuleType smtype = softwareManagement.createSoftwareModuleType( - new JpaSoftwareModuleType(typeName.toLowerCase().replaceAll("\\s+", ""), typeName, - jlorem.words(5), Integer.MAX_VALUE)); - - for (int i1 = 0; i1 < sizeMultiplikator; i1++) { - softwareManagement.createSoftwareModule(new JpaSoftwareModule(smtype, typeName + i1, "1.0." + i1, - jlorem.words(5), "the " + typeName + " vendor Inc.")); - } - - }); - LOG.debug("initDemoRepo - Extra Software Modules and types finished"); - - LOG.debug("initDemoRepo - start now target garbage"); - - // garbage targets - // unknown - targetManagement - .createTargets(TestDataUtil.generateTargets(targetTestGroups.length * sizeMultiplikator)); - - // registered - targetManagement.createTargets( - TestDataUtil.generateTargets(targetTestGroups.length * sizeMultiplikator, "registered"), - TargetUpdateStatus.REGISTERED, System.currentTimeMillis(), generateIPAddress()); - - // pending - final DistributionSetTag dsTag = tagManagement - .createDistributionSetTag(new JpaDistributionSetTag("OnlyAssignedTag")); - final DistributionSet ds = TestDataUtil.generateDistributionSet("Pending DS", "v1.0", - softwareManagement, distributionSetManagement, - Arrays.asList(new DistributionSetTag[] { dsTag })); - deploymentManagement.assignDistributionSet(ds, targetManagement.createTargets( - TestDataUtil.generateTargets(targetTestGroups.length * sizeMultiplikator, "pending"))); - - // Load test means additional 1_000_000 target - - for (int i2 = 0; i2 < loadtestgroups; i2++) { - targetManagement.createTargets(TestDataUtil.generateTargets(i2 * 1_000, 1_000, "loadtest-")); - } - - LOG.debug("initDemoRepo complete"); - }); - } - /** - * Adding controller attributes for given {@link Target}. - */ - // private Target setControllerAttributes( final String targetId ) { - // final Target target = - // targetManagement.findTargetByControllerIDWithDetails( targetId ); - // target.getTargetStatus().getControllerAttributes().put( "revision", - // "1.1" ); - // target.getTargetStatus().getControllerAttributes().put( "capacity", - // "128M" ); - // target.getTargetStatus().getControllerAttributes().put( "serial", - // String.valueOf( - // System.currentTimeMillis()) ); - // return targetManagement.updateTarget( target ); - // } - } - - /** - * - * Data clean up class. - * - * - * - */ - public static class DatabaseCleanupUtil { - - private static final Logger LOG = LoggerFactory.getLogger(DatabaseCleanupUtil.class); - @Autowired - private EntityManager entityManager; - - private static final String[] CLEAN_UP_SQLS = new String[] { "sp_tenant", "sp_tenant_configuration", - "sp_artifact", "sp_external_artifact", "sp_external_provider", "sp_target_target_tag", - "sp_target_attributes", "sp_target_tag", "sp_action_status_messages", "sp_action_status", "sp_action", - "sp_ds_dstag", "sp_distributionset_tag", "sp_target_info", "sp_target", "sp_sw_metadata", - "sp_ds_metadata", "sp_ds_module", "sp_distribution_set", "sp_base_software_module", - "sp_ds_type_element", "sp_distribution_set_type", "sp_software_module_type" }; - - /** - * delete all entries from the DB tables. - */ - @Transactional - @Modifying - public void cleanupDB(final String database) { - LOG.debug("Data clean up is started..."); - final boolean isMySql = "MYSQL".equals(database); - if (isMySql) { - // disable foreign key check because otherwise mysql cannot - // delete sp_active_actions due - // the self constraint within the table, stupid MySql - entityManager.createNativeQuery("SET FOREIGN_KEY_CHECKS = 0").executeUpdate(); - } - try { - final String[] dbCmds = new String[] { "delete from" }; - for (final String dbCmd : dbCmds) { - for (final String table : CLEAN_UP_SQLS) { - final String sql = String.format("%s %s", dbCmd, table); - final Query query = entityManager.createNativeQuery(sql); - try { - LOG.debug("cleanup table: {}", sql); - LOG.debug("cleaned table: {}; deleted {} records", sql, query.executeUpdate()); - } catch (final Exception ex) { - LOG.error(String.format("error on executing cleanup statement '%s'", sql), ex); - throw ex; - } - } - } - - LOG.debug("Data clean up is finished..."); - } finally { - if (isMySql) { - // enable foreign key check again! - entityManager.createNativeQuery("SET FOREIGN_KEY_CHECKS = 1").executeUpdate(); - } - } - } - } - - /** - * @return a generated IPv4 address string. - */ - private static URI generateIPAddress() { - final Random r = new Random(); - return IpUtil - .createHttpUri(r.nextInt(256) + "." + r.nextInt(256) + "." + r.nextInt(256) + "." + r.nextInt(256)); - } - - private RepositoryDataGenerator() { - super(); - } - -} diff --git a/hawkbit-repository/hawkbit-repository-test/pom.xml b/hawkbit-repository/hawkbit-repository-test/pom.xml new file mode 100644 index 000000000..6b421c8ab --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-test/pom.xml @@ -0,0 +1,59 @@ + + + 4.0.0 + + org.eclipse.hawkbit + hawkbit-repository + 0.2.0-SNAPSHOT + + hawkbit-repository-test + hawkBit :: Repository Test Utilities + + + + org.eclipse.hawkbit + hawkbit-repository-api + ${project.version} + + + org.eclipse.hawkbit + hawkbit-repository-core + ${project.version} + + + org.eclipse.hawkbit + hawkbit-artifact-repository-mongo + ${project.version} + + + de.flapdoodle.embed + de.flapdoodle.embed.mongo + + + net._01001111 + jlorem + + + commons-io + commons-io + 2.5 + + + org.springframework.boot + spring-boot-starter-test + + + org.springframework.security + spring-security-config + + + \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractIntegrationTest.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/AbstractIntegrationTest.java similarity index 51% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractIntegrationTest.java rename to hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/AbstractIntegrationTest.java index a1eff3fae..29bf02fa0 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractIntegrationTest.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/AbstractIntegrationTest.java @@ -6,22 +6,15 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.jpa; - -import static org.fest.assertions.api.Assertions.assertThat; - -import java.util.List; - -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; +package org.eclipse.hawkbit.repository.util; import org.eclipse.hawkbit.ExcludePathAwareShallowETagFilter; -import org.eclipse.hawkbit.RepositoryApplicationConfiguration; -import org.eclipse.hawkbit.cache.TenantAwareCacheManager; import org.eclipse.hawkbit.repository.ArtifactManagement; +import org.eclipse.hawkbit.repository.Constants; import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement; +import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.RolloutGroupManagement; import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.SoftwareManagement; @@ -30,32 +23,13 @@ import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.TargetFilterQueryManagement; import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; -import org.eclipse.hawkbit.repository.jpa.ActionRepository; -import org.eclipse.hawkbit.repository.jpa.ActionStatusRepository; -import org.eclipse.hawkbit.repository.jpa.DistributionSetRepository; -import org.eclipse.hawkbit.repository.jpa.DistributionSetTagRepository; -import org.eclipse.hawkbit.repository.jpa.DistributionSetTypeRepository; -import org.eclipse.hawkbit.repository.jpa.ExternalArtifactRepository; -import org.eclipse.hawkbit.repository.jpa.LocalArtifactRepository; -import org.eclipse.hawkbit.repository.jpa.RolloutGroupRepository; -import org.eclipse.hawkbit.repository.jpa.RolloutRepository; -import org.eclipse.hawkbit.repository.jpa.SoftwareModuleMetadataRepository; -import org.eclipse.hawkbit.repository.jpa.SoftwareModuleRepository; -import org.eclipse.hawkbit.repository.jpa.SoftwareModuleTypeRepository; -import org.eclipse.hawkbit.repository.jpa.TargetInfoRepository; -import org.eclipse.hawkbit.repository.jpa.TargetRepository; -import org.eclipse.hawkbit.repository.jpa.TargetTagRepository; -import org.eclipse.hawkbit.repository.jpa.TenantMetaDataRepository; -import org.eclipse.hawkbit.repository.jpa.utils.RepositoryDataGenerator.DatabaseCleanupUtil; import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.security.DosFilter; import org.eclipse.hawkbit.security.SystemSecurityContext; import org.eclipse.hawkbit.tenancy.TenantAware; import org.junit.After; -import org.junit.AfterClass; import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Rule; import org.junit.rules.MethodRule; import org.junit.rules.TestWatchman; @@ -63,13 +37,11 @@ import org.junit.runner.RunWith; import org.junit.runners.model.FrameworkMethod; import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.context.EnvironmentAware; import org.springframework.core.env.Environment; import org.springframework.data.auditing.AuditingHandler; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; -import org.springframework.data.mongodb.gridfs.GridFsOperations; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext.ClassMode; import org.springframework.test.context.ActiveProfiles; @@ -78,12 +50,10 @@ import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder; import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import org.springframework.transaction.annotation.Transactional; import org.springframework.web.context.WebApplicationContext; @RunWith(SpringJUnit4ClassRunner.class) @WebAppConfiguration -@SpringApplicationConfiguration(classes = { RepositoryApplicationConfiguration.class, TestConfiguration.class }) @ActiveProfiles({ "test" }) @WithUser(principal = "bumlux", allSpPermissions = true, authorities = "ROLE_CONTROLLER") // destroy the context after each test class because otherwise we get problem @@ -96,44 +66,16 @@ public abstract class AbstractIntegrationTest implements EnvironmentAware { protected static final Pageable pageReq = new PageRequest(0, 400); - @PersistenceContext - protected EntityManager entityManager; + /** + * Number of {@link DistributionSetType}s that exist in every test case. One + * generated by using + * {@link TestdataFactory#findOrCreateDefaultTestDsType()} and two + * {@link SystemManagement#getTenantMetadata()}; + */ + protected static final int DEFAULT_DS_TYPES = Constants.DEFAULT_DS_TYPES_IN_TENANT + 1; @Autowired - protected TargetRepository targetRepository; - - @Autowired - protected ActionRepository actionRepository; - - @Autowired - protected DistributionSetRepository distributionSetRepository; - - @Autowired - protected SoftwareModuleRepository softwareModuleRepository; - - @Autowired - protected TenantMetaDataRepository tenantMetaDataRepository; - - @Autowired - protected DistributionSetTypeRepository distributionSetTypeRepository; - - @Autowired - protected SoftwareModuleTypeRepository softwareModuleTypeRepository; - - @Autowired - protected TargetTagRepository targetTagRepository; - - @Autowired - protected DistributionSetTagRepository distributionSetTagRepository; - - @Autowired - protected SoftwareModuleMetadataRepository softwareModuleMetadataRepository; - - @Autowired - protected ActionStatusRepository actionStatusRepository; - - @Autowired - protected ExternalArtifactRepository externalArtifactRepository; + protected EntityFactory entityFactory; @Autowired protected SoftwareManagement softwareManagement; @@ -159,15 +101,6 @@ public abstract class AbstractIntegrationTest implements EnvironmentAware { @Autowired protected ArtifactManagement artifactManagement; - @Autowired - protected LocalArtifactRepository artifactRepository; - - @Autowired - protected TargetInfoRepository targetInfoRepository; - - @Autowired - protected GridFsOperations operations; - @Autowired protected WebApplicationContext context; @@ -183,9 +116,6 @@ public abstract class AbstractIntegrationTest implements EnvironmentAware { @Autowired protected SystemManagement systemManagement; - @Autowired - protected TenantAwareCacheManager cacheManager; - @Autowired protected TenantConfigurationManagement tenantConfigurationManagement; @@ -195,19 +125,13 @@ public abstract class AbstractIntegrationTest implements EnvironmentAware { @Autowired protected RolloutGroupManagement rolloutGroupManagement; - @Autowired - protected RolloutGroupRepository rolloutGroupRepository; - - @Autowired - protected RolloutRepository rolloutRepository; - @Autowired protected SystemSecurityContext systemSecurityContext; - protected MockMvc mvc; - @Autowired - protected DatabaseCleanupUtil dbCleanupUtil; + protected TestRepositoryManagement testRepositoryManagement; + + protected MockMvc mvc; protected SoftwareModuleType osType; protected SoftwareModuleType appType; @@ -215,13 +139,14 @@ public abstract class AbstractIntegrationTest implements EnvironmentAware { protected DistributionSetType standardDsType; + @Autowired + protected TestdataFactory testdataFactory; + @Rule public final WithSpringAuthorityRule securityRule = new WithSpringAuthorityRule(); protected Environment environment = null; - private static CIMySqlTestDatabase tesdatabase; - @Override public void setEnvironment(final Environment environment) { this.environment = environment; @@ -230,20 +155,29 @@ public abstract class AbstractIntegrationTest implements EnvironmentAware { @Before public void before() throws Exception { mvc = createMvcWebAppContext().build(); + final String description = "Updated description to have lastmodified available in tests"; - standardDsType = securityRule.runAsPrivileged(() -> systemManagement.getTenantMetadata().getDefaultDsType()); - - osType = securityRule.runAsPrivileged(() -> softwareManagement.findSoftwareModuleTypeByKey("os")); - osType.setDescription("Updated description to have lastmodified available in tests"); + osType = securityRule + .runAsPrivileged(() -> testdataFactory.findOrCreateSoftwareModuleType(TestdataFactory.SM_TYPE_OS)); + osType.setDescription(description); osType = securityRule.runAsPrivileged(() -> softwareManagement.updateSoftwareModuleType(osType)); - appType = securityRule.runAsPrivileged(() -> softwareManagement.findSoftwareModuleTypeByKey("application")); - appType.setDescription("Updated description to have lastmodified available in tests"); + appType = securityRule.runAsPrivileged( + () -> testdataFactory.findOrCreateSoftwareModuleType(TestdataFactory.SM_TYPE_APP, Integer.MAX_VALUE)); + appType.setDescription(description); appType = securityRule.runAsPrivileged(() -> softwareManagement.updateSoftwareModuleType(appType)); - runtimeType = securityRule.runAsPrivileged(() -> softwareManagement.findSoftwareModuleTypeByKey("runtime")); - runtimeType.setDescription("Updated description to have lastmodified available in tests"); + runtimeType = securityRule + .runAsPrivileged(() -> testdataFactory.findOrCreateSoftwareModuleType(TestdataFactory.SM_TYPE_RT)); + runtimeType.setDescription(description); runtimeType = securityRule.runAsPrivileged(() -> softwareManagement.updateSoftwareModuleType(runtimeType)); + + standardDsType = securityRule.runAsPrivileged(() -> testdataFactory.findOrCreateDefaultTestDsType()); + } + + @After + public void after() { + testRepositoryManagement.clearTestRepository(); } protected DefaultMockMvcBuilder createMvcWebAppContext() { @@ -254,59 +188,6 @@ public abstract class AbstractIntegrationTest implements EnvironmentAware { "/rest/v1/softwaremodules/{smId}/artifacts/{artId}/download", "/*/controller/artifacts/**")); } - @BeforeClass - public static void beforeClass() { - createTestdatabaseAndStart(); - } - - private static void createTestdatabaseAndStart() { - if ("MYSQL".equals(System.getProperty("spring.jpa.database"))) { - tesdatabase = new CIMySqlTestDatabase(); - tesdatabase.before(); - } - } - - @AfterClass - public static void afterClass() { - if (tesdatabase != null) { - tesdatabase.after(); - } - } - - @After - public void after() throws Exception { - deleteAllRepos(); - cacheManager.getDirectCacheNames().forEach(name -> cacheManager.getDirectCache(name).clear()); - assertThat(actionStatusRepository.findAll()).isEmpty(); - assertThat(targetRepository.findAll()).isEmpty(); - assertThat(actionRepository.findAll()).isEmpty(); - assertThat(distributionSetRepository.findAll()).isEmpty(); - assertThat(targetTagRepository.findAll()).isEmpty(); - assertThat(distributionSetTagRepository.findAll()).isEmpty(); - assertThat(softwareModuleRepository.findAll()).isEmpty(); - assertThat(softwareModuleTypeRepository.findAll()).isEmpty(); - assertThat(distributionSetTypeRepository.findAll()).isEmpty(); - assertThat(tenantMetaDataRepository.findAll()).isEmpty(); - assertThat(rolloutGroupRepository.findAll()).isEmpty(); - assertThat(rolloutRepository.findAll()).isEmpty(); - } - - @Transactional - protected void deleteAllRepos() throws Exception { - final List tenants = securityRule.runAs(WithSpringAuthorityRule.withUser(false), - () -> systemManagement.findTenants()); - tenants.forEach(tenant -> { - try { - securityRule.runAs(WithSpringAuthorityRule.withUser(false), () -> { - systemManagement.deleteTenant(tenant); - return null; - }); - } catch (final Exception e) { - e.printStackTrace(); - } - }); - } - @Rule public MethodRule watchman = new TestWatchman() { @Override diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractIntegrationTestWithMongoDB.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/AbstractIntegrationTestWithMongoDB.java similarity index 89% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractIntegrationTestWithMongoDB.java rename to hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/AbstractIntegrationTestWithMongoDB.java index d83f2e5cf..28d8add3a 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractIntegrationTestWithMongoDB.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/AbstractIntegrationTestWithMongoDB.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.jpa; +package org.eclipse.hawkbit.repository.util; import java.io.IOException; import java.net.UnknownHostException; @@ -15,7 +15,9 @@ import java.util.concurrent.atomic.AtomicInteger; import org.junit.After; import org.junit.AfterClass; import org.junit.BeforeClass; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.mongodb.core.query.Query; +import org.springframework.data.mongodb.gridfs.GridFsOperations; import de.flapdoodle.embed.mongo.Command; import de.flapdoodle.embed.mongo.MongodExecutable; @@ -38,10 +40,14 @@ import de.flapdoodle.embed.process.runtime.Network; * */ public abstract class AbstractIntegrationTestWithMongoDB extends AbstractIntegrationTest { + protected static volatile MongodExecutable mongodExecutable = null; private static final AtomicInteger mongoLease = new AtomicInteger(0); private static volatile Integer port; + @Autowired + protected GridFsOperations operations; + @BeforeClass public static void setupMongo() throws UnknownHostException, IOException { mongoLease.incrementAndGet(); @@ -67,8 +73,8 @@ public abstract class AbstractIntegrationTestWithMongoDB extends AbstractIntegra new ArtifactStoreBuilder().defaults(command) .download(new DownloadConfigBuilder().defaultsForCommand(command) .proxyFactory(new HttpProxyFactory( - System.getProperty("http.proxyHost").trim(), - Integer.valueOf(System.getProperty("http.proxyPort")))))); + System.getProperty("http.proxyHost").trim(), Integer + .valueOf(System.getProperty("http.proxyPort")))))); } final IMongodConfig mongodConfig = new MongodConfigBuilder().version(version) @@ -86,7 +92,7 @@ public abstract class AbstractIntegrationTestWithMongoDB extends AbstractIntegra operations.delete(new Query()); } - public void internalShutDownMongo() { + public static void internalShutDownMongo() { if (mongodExecutable != null && mongoLease.decrementAndGet() <= 0) { mongodExecutable.stop(); mongodExecutable = null; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/FreePortFileWriter.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/FreePortFileWriter.java similarity index 97% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/FreePortFileWriter.java rename to hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/FreePortFileWriter.java index 8d900a593..383722a75 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/FreePortFileWriter.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/FreePortFileWriter.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.jpa; +package org.eclipse.hawkbit.repository.util; import java.io.File; import java.net.InetSocketAddress; diff --git a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/TestRepositoryManagement.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/TestRepositoryManagement.java new file mode 100644 index 000000000..ddad59990 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/TestRepositoryManagement.java @@ -0,0 +1,22 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.util; + +/** + * Repository support for tests. + * + */ +@FunctionalInterface +public interface TestRepositoryManagement { + /** + * Empty the test repository. + */ + void clearTestRepository(); + +} diff --git a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/TestdataFactory.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/TestdataFactory.java new file mode 100644 index 000000000..0597a30cb --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/TestdataFactory.java @@ -0,0 +1,737 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.util; + +import java.io.InputStream; +import java.nio.charset.Charset; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Random; +import java.util.UUID; + +import org.apache.commons.io.IOUtils; +import org.eclipse.hawkbit.repository.ArtifactManagement; +import org.eclipse.hawkbit.repository.ControllerManagement; +import org.eclipse.hawkbit.repository.DeploymentManagement; +import org.eclipse.hawkbit.repository.DistributionSetManagement; +import org.eclipse.hawkbit.repository.EntityFactory; +import org.eclipse.hawkbit.repository.SoftwareManagement; +import org.eclipse.hawkbit.repository.TagManagement; +import org.eclipse.hawkbit.repository.TargetManagement; +import org.eclipse.hawkbit.repository.model.Action; +import org.eclipse.hawkbit.repository.model.Action.Status; +import org.eclipse.hawkbit.repository.model.ActionStatus; +import org.eclipse.hawkbit.repository.model.Artifact; +import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.DistributionSetTag; +import org.eclipse.hawkbit.repository.model.DistributionSetType; +import org.eclipse.hawkbit.repository.model.LocalArtifact; +import org.eclipse.hawkbit.repository.model.NamedEntity; +import org.eclipse.hawkbit.repository.model.NamedVersionedEntity; +import org.eclipse.hawkbit.repository.model.SoftwareModule; +import org.eclipse.hawkbit.repository.model.SoftwareModuleType; +import org.eclipse.hawkbit.repository.model.Target; +import org.eclipse.hawkbit.repository.model.TargetTag; +import org.springframework.beans.factory.annotation.Autowired; + +import com.google.common.base.Strings; +import com.google.common.collect.Lists; + +import net._01001111.text.LoremIpsum; + +/** + * Data generator utility for tests. + */ +public class TestdataFactory { + private static final LoremIpsum LOREM = new LoremIpsum(); + + /** + * default {@link Target#getControllerId()}. + */ + public static final String DEFAULT_CONTROLLER_ID = "targetExist"; + + /** + * Default {@link SoftwareModule#getVendor()}. + */ + public static final String DEFAULT_VENDOR = "Vendor Limited, California"; + + /** + * Default {@link NamedVersionedEntity#getVersion()}. + */ + public static final String DEFAULT_VERSION = "1.0"; + + /** + * Default {@link NamedEntity#getDescription()}. + */ + public static final String DEFAULT_DESCRIPTION = "Desc: " + LOREM.words(10); + + /** + * Key of test default {@link DistributionSetType}. + */ + public static final String DS_TYPE_DEFAULT = "test_default_ds_type"; + + /** + * Key of test "os" {@link SoftwareModuleType} -> mandatory firmware in + * {@link #DS_TYPE_DEFAULT}. + */ + public static final String SM_TYPE_OS = "os"; + + /** + * Key of test "runtime" {@link SoftwareModuleType} -> optional firmware in + * {@link #DS_TYPE_DEFAULT}. + */ + public static final String SM_TYPE_RT = "runtime"; + + /** + * Key of test "application" {@link SoftwareModuleType} -> optional software + * in {@link #DS_TYPE_DEFAULT}. + */ + public static final String SM_TYPE_APP = "application"; + + @Autowired + private ControllerManagement controllerManagament; + + @Autowired + private SoftwareManagement softwareManagement; + + @Autowired + private DistributionSetManagement distributionSetManagement; + + @Autowired + private TargetManagement targetManagement; + + @Autowired + private DeploymentManagement deploymentManagement; + + @Autowired + private TagManagement tagManagement; + + @Autowired + private EntityFactory entityFactory; + + @Autowired + private ArtifactManagement artifactManagement; + + /** + * Creates {@link DistributionSet} in repository including three + * {@link SoftwareModule}s of types {@link #SM_TYPE_OS}, {@link #SM_TYPE_RT} + * , {@link #SM_TYPE_APP} with {@link #DEFAULT_VERSION} and + * {@link DistributionSet#isRequiredMigrationStep()} false. + * + * @param prefix + * for {@link SoftwareModule}s and {@link DistributionSet}s name, + * vendor and description. + * + * @return {@link DistributionSet} entity. + */ + public DistributionSet createDistributionSet(final String prefix) { + return createDistributionSet(prefix, DEFAULT_VERSION, false); + } + + /** + * Creates {@link DistributionSet} in repository including three + * {@link SoftwareModule}s of types {@link #SM_TYPE_OS}, {@link #SM_TYPE_RT} + * , {@link #SM_TYPE_APP} with {@link #DEFAULT_VERSION}. + * + * @param prefix + * for {@link SoftwareModule}s and {@link DistributionSet}s name, + * vendor and description. + * @param isRequiredMigrationStep + * for {@link DistributionSet#isRequiredMigrationStep()} + * + * @return {@link DistributionSet} entity. + */ + public DistributionSet createDistributionSet(final String prefix, final boolean isRequiredMigrationStep) { + return createDistributionSet(prefix, DEFAULT_VERSION, isRequiredMigrationStep); + } + + /** + * Creates {@link DistributionSet} in repository including three + * {@link SoftwareModule}s of types {@link #SM_TYPE_OS}, {@link #SM_TYPE_RT} + * , {@link #SM_TYPE_APP} with {@link #DEFAULT_VERSION} and + * {@link DistributionSet#isRequiredMigrationStep()} false. + * + * @param prefix + * for {@link SoftwareModule}s and {@link DistributionSet}s name, + * vendor and description. + * @param tags + * {@link DistributionSet#getTags()} + * + * @return {@link DistributionSet} entity. + */ + public DistributionSet createDistributionSet(final String prefix, final Collection tags) { + return createDistributionSet(prefix, DEFAULT_VERSION, tags); + } + + /** + * Creates {@link DistributionSet} in repository including three + * {@link SoftwareModule}s of types {@link #SM_TYPE_OS}, {@link #SM_TYPE_RT} + * , {@link #SM_TYPE_APP}. + * + * @param prefix + * for {@link SoftwareModule}s and {@link DistributionSet}s name, + * vendor and description. + * @param version + * {@link DistributionSet#getVersion()} and + * {@link SoftwareModule#getVersion()} extended by a random + * number. + * @param isRequiredMigrationStep + * for {@link DistributionSet#isRequiredMigrationStep()} + * + * @return {@link DistributionSet} entity. + */ + public DistributionSet createDistributionSet(final String prefix, final String version, + final boolean isRequiredMigrationStep) { + + final SoftwareModule appMod = softwareManagement.createSoftwareModule(entityFactory.generateSoftwareModule( + findOrCreateSoftwareModuleType(SM_TYPE_APP, Integer.MAX_VALUE), prefix + SM_TYPE_APP, + version + "." + new Random().nextInt(100), LOREM.words(20), prefix + " vendor Limited, California")); + final SoftwareModule runtimeMod = softwareManagement + .createSoftwareModule(entityFactory.generateSoftwareModule(findOrCreateSoftwareModuleType(SM_TYPE_RT), + prefix + "app runtime", version + "." + new Random().nextInt(100), LOREM.words(20), + prefix + " vendor GmbH, Stuttgart, Germany")); + final SoftwareModule osMod = softwareManagement + .createSoftwareModule(entityFactory.generateSoftwareModule(findOrCreateSoftwareModuleType(SM_TYPE_OS), + prefix + " Firmware", version + "." + new Random().nextInt(100), LOREM.words(20), + prefix + " vendor Limited Inc, California")); + + return distributionSetManagement + .createDistributionSet(generateDistributionSet(prefix != null && prefix.length() > 0 ? prefix : "DS", + version, findOrCreateDefaultTestDsType(), Lists.newArrayList(osMod, runtimeMod, appMod)) + .setRequiredMigrationStep(isRequiredMigrationStep)); + } + + /** + * Creates {@link DistributionSet} in repository including three + * {@link SoftwareModule}s of types {@link #SM_TYPE_OS}, {@link #SM_TYPE_RT} + * , {@link #SM_TYPE_APP}. + * + * @param prefix + * for {@link SoftwareModule}s and {@link DistributionSet}s name, + * vendor and description. + * @param version + * {@link DistributionSet#getVersion()} and + * {@link SoftwareModule#getVersion()} extended by a random + * number. + * @param tags + * {@link DistributionSet#getTags()} + * + * @return {@link DistributionSet} entity. + */ + public DistributionSet createDistributionSet(final String prefix, final String version, + final Collection tags) { + + final DistributionSet set = createDistributionSet(prefix, version, false); + + final List sets = new ArrayList<>(); + sets.add(set); + + tags.forEach(tag -> distributionSetManagement.toggleTagAssignment(sets, tag)); + + return distributionSetManagement.findDistributionSetById(set.getId()); + + } + + /** + * Creates {@link DistributionSet}s in repository including three + * {@link SoftwareModule}s of types {@link #SM_TYPE_OS}, {@link #SM_TYPE_RT} + * , {@link #SM_TYPE_APP} with {@link #DEFAULT_VERSION} followed by an + * iterative number and {@link DistributionSet#isRequiredMigrationStep()} + * false. + * + * @param number + * of {@link DistributionSet}s to create + * + * @return {@link List} of {@link DistributionSet} entities + */ + public List createDistributionSets(final int number) { + + return createDistributionSets("", number); + } + + /** + * Creates {@link DistributionSet}s in repository including three + * {@link SoftwareModule}s of types {@link #SM_TYPE_OS}, {@link #SM_TYPE_RT} + * , {@link #SM_TYPE_APP} with {@link #DEFAULT_VERSION} followed by an + * iterative number and {@link DistributionSet#isRequiredMigrationStep()} + * false. + * + * @param prefix + * for {@link SoftwareModule}s and {@link DistributionSet}s name, + * vendor and description. + * @param number + * of {@link DistributionSet}s to create + * + * @return {@link List} of {@link DistributionSet} entities + */ + public List createDistributionSets(final String prefix, final int number) { + + final List sets = new ArrayList<>(); + for (int i = 0; i < number; i++) { + sets.add(createDistributionSet(prefix, DEFAULT_VERSION + "." + i, false)); + } + + return sets; + } + + /** + * Creates {@link DistributionSet}s in repository with + * {@link #DEFAULT_DESCRIPTION} and + * {@link DistributionSet#isRequiredMigrationStep()} false. + * + * @param name + * {@link DistributionSet#getName()} + * @param version + * {@link DistributionSet#getVersion()} + * + * @return {@link DistributionSet} entity + */ + public DistributionSet createDistributionSetWithNoSoftwareModules(final String name, final String version) { + + final DistributionSet dis = entityFactory.generateDistributionSet(); + dis.setName(name); + dis.setVersion(version); + dis.setDescription(DEFAULT_DESCRIPTION); + dis.setType(findOrCreateDefaultTestDsType()); + return distributionSetManagement.createDistributionSet(dis); + } + + /** + * Creates {@link LocalArtifact}s for given {@link SoftwareModule} with a + * small text payload. + * + * @param moduleId + * the {@link Artifact}s belong to. + * + * @return {@link LocalArtifact} entity. + */ + public List createLocalArtifacts(final Long moduleId) { + final List artifacts = new ArrayList<>(); + for (int i = 0; i < 3; i++) { + final InputStream stubInputStream = IOUtils.toInputStream("some test data" + i, Charset.forName("UTF-8")); + artifacts.add(artifactManagement.createLocalArtifact(stubInputStream, moduleId, "filename" + i, false)); + + } + + return artifacts; + } + + /** + * Creates {@link SoftwareModule} with {@link #DEFAULT_VENDOR} and + * {@link #DEFAULT_VERSION} and random generated + * {@link Target#getDescription()} in the repository. + * + * @param typeKey + * of the {@link SoftwareModuleType} + * + * @return persisted {@link SoftwareModule}. + */ + public SoftwareModule createSoftwareModule(final String typeKey) { + return softwareManagement.createSoftwareModule(entityFactory.generateSoftwareModule( + findOrCreateSoftwareModuleType(typeKey), typeKey, DEFAULT_VERSION, LOREM.words(10), DEFAULT_VENDOR)); + } + + /** + * @return persisted {@link Target} with {@link #DEFAULT_CONTROLLER_ID}. + */ + public Target createTarget() { + return targetManagement.createTarget(entityFactory.generateTarget(DEFAULT_CONTROLLER_ID)); + } + + /** + * Creates {@link DistributionSet}s in repository including three + * {@link SoftwareModule}s of types {@link #SM_TYPE_OS}, {@link #SM_TYPE_RT} + * , {@link #SM_TYPE_APP} with {@link #DEFAULT_VERSION} followed by an + * iterative number and {@link DistributionSet#isRequiredMigrationStep()} + * false. + * + * @return persisted {@link DistributionSet}. + */ + public DistributionSet createTestDistributionSet() { + DistributionSet set = createDistributionSet(""); + set.setVersion(DEFAULT_VERSION); + set = distributionSetManagement.updateDistributionSet(set); + + set.getModules().forEach(module -> { + module.setDescription("Updated " + DEFAULT_DESCRIPTION); + softwareManagement.updateSoftwareModule(module); + }); + + // load also lazy stuff + set = distributionSetManagement.findDistributionSetByIdWithDetails(set.getId()); + + return set; + } + + /** + * @return {@link DistributionSetType} with key {@link #DS_TYPE_DEFAULT} and + * {@link SoftwareModuleType}s {@link #SM_TYPE_OS}, + * {@link #SM_TYPE_RT} , {@link #SM_TYPE_APP}. + */ + public DistributionSetType findOrCreateDefaultTestDsType() { + final List mand = new ArrayList<>(); + mand.add(findOrCreateSoftwareModuleType(SM_TYPE_OS)); + + final List opt = new ArrayList<>(); + opt.add(findOrCreateSoftwareModuleType(SM_TYPE_APP, Integer.MAX_VALUE)); + opt.add(findOrCreateSoftwareModuleType(SM_TYPE_RT)); + + return findOrCreateDistributionSetType(DS_TYPE_DEFAULT, "OS (FW) mandatory, runtime (FW) and app (SW) optional", + mand, opt); + } + + /** + * Creates {@link DistributionSetType} in repository. + * + * @param dsTypeKey + * {@link DistributionSetType#getKey()} + * @param dsTypeName + * {@link DistributionSetType#getName()} + * + * @return persisted {@link DistributionSetType} + */ + public DistributionSetType findOrCreateDistributionSetType(final String dsTypeKey, final String dsTypeName) { + final DistributionSetType findDistributionSetTypeByname = distributionSetManagement + .findDistributionSetTypeByKey(dsTypeKey); + + if (findDistributionSetTypeByname != null) { + return findDistributionSetTypeByname; + } + + final DistributionSetType type = entityFactory.generateDistributionSetType(dsTypeKey, dsTypeName, + LOREM.words(10)); + + return distributionSetManagement.createDistributionSetType(type); + } + + /** + * Finds {@link DistributionSetType} in repository with given + * {@link DistributionSetType#getKey()} or creates if it does not exist yet. + * + * @param dsTypeKey + * {@link DistributionSetType#getKey()} + * @param dsTypeName + * {@link DistributionSetType#getName()} + * @param mandatory + * {@link DistributionSetType#getMandatoryModuleTypes()} + * @param optional + * {@link DistributionSetType#getOptionalModuleTypes()} + * + * @return persisted {@link DistributionSetType} + */ + public DistributionSetType findOrCreateDistributionSetType(final String dsTypeKey, final String dsTypeName, + final Collection mandatory, final Collection optional) { + final DistributionSetType findDistributionSetTypeByname = distributionSetManagement + .findDistributionSetTypeByKey(dsTypeKey); + + if (findDistributionSetTypeByname != null) { + return findDistributionSetTypeByname; + } + + final DistributionSetType type = entityFactory.generateDistributionSetType(dsTypeKey, dsTypeName, + LOREM.words(10)); + mandatory.forEach(type::addMandatoryModuleType); + optional.forEach(type::addOptionalModuleType); + + return distributionSetManagement.createDistributionSetType(type); + } + + /** + * Finds {@link SoftwareModuleType} in repository with given + * {@link SoftwareModuleType#getKey()} or creates if it does not exist yet + * with {@link SoftwareModuleType#getMaxAssignments()} = 1. + * + * @param key + * {@link SoftwareModuleType#getKey()} + * + * @return persisted {@link SoftwareModuleType} + */ + public SoftwareModuleType findOrCreateSoftwareModuleType(final String key) { + return findOrCreateSoftwareModuleType(key, 1); + } + + /** + * Finds {@link SoftwareModuleType} in repository with given + * {@link SoftwareModuleType#getKey()} or creates if it does not exist yet. + * + * @param key + * {@link SoftwareModuleType#getKey()} + * @param maxAssignments + * {@link SoftwareModuleType#getMaxAssignments()} + * + * @return persisted {@link SoftwareModuleType} + */ + public SoftwareModuleType findOrCreateSoftwareModuleType(final String key, final int maxAssignments) { + final SoftwareModuleType findSoftwareModuleTypeByKey = softwareManagement.findSoftwareModuleTypeByKey(key); + if (findSoftwareModuleTypeByKey != null) { + return findSoftwareModuleTypeByKey; + } + return softwareManagement.createSoftwareModuleType( + entityFactory.generateSoftwareModuleType(key, key, LOREM.words(10), maxAssignments)); + } + + /** + * builder method for creating a {@link DistributionSet}. + * + * @param name + * {@link DistributionSet#getName()} + * @param version + * {@link DistributionSet#getVersion()} + * @param type + * {@link DistributionSet#getType()} + * @param modules + * {@link DistributionSet#getModules()} + * + * @return the created {@link DistributionSet} + */ + public DistributionSet generateDistributionSet(final String name, final String version, + final DistributionSetType type, final Collection modules) { + final DistributionSet distributionSet = entityFactory.generateDistributionSet(name, version, null, type, + modules); + distributionSet.setDescription(LOREM.words(10)); + return distributionSet; + } + + /** + * Creates {@link DistributionSetTag}s in repository. + * + * @param number + * of {@link DistributionSetTag}s + * + * @return the persisted {@link DistributionSetTag}s + */ + public List createDistributionSetTags(final int number) { + final List result = new ArrayList<>(); + + for (int i = 0; i < number; i++) { + result.add(entityFactory.generateDistributionSetTag("tag" + i, "tagdesc" + i, String.valueOf(i))); + } + + return tagManagement.createDistributionSetTags(result); + } + + /** + * builder method for creating a single target object. + * + * @param ctrlID + * the ID of the target + * @param description + * of the target + * @return the created target object + */ + public Target generateTarget(final String ctrlID, final String description) { + return generateTarget(ctrlID, description, null); + } + + /** + * Builds a single {@link Target} from the given parameters. + * + * @param ctrlID + * controllerID + * @param description + * the description of the target + * @param tags + * assigned {@link TargetTag}s + * @return the generated {@link Target} + */ + private Target generateTarget(final String ctrlID, final String description, final TargetTag[] tags) { + final Target target = entityFactory.generateTarget(ctrlID); + target.setName("Prov.Target ".concat(ctrlID)); + target.setDescription(description); + if (tags != null && tags.length > 0) { + for (final TargetTag t : tags) { + target.getTags().add(t); + } + } + return target; + } + + /** + * Creates {@link Target}s in repository and with + * {@link #DEFAULT_CONTROLLER_ID} as prefix for + * {@link Target#getControllerId()}. + * + * @param number + * of {@link Target}s to create + * + * @return {@link List} of {@link Target} entities + */ + public List createTargets(final int number) { + return targetManagement.createTargets(generateTargets(0, number, DEFAULT_CONTROLLER_ID)); + } + + /** + * Builds {@link Target} objects with given prefix for + * {@link Target#getControllerId()} followed by a number suffix. + * + * @param start + * value for the controllerId suffix + * @param numberOfTargets + * of {@link Target}s to generate + * @param controllerIdPrefix + * for {@link Target#getControllerId()} generation. + * @return list of {@link Target} objects + */ + private List generateTargets(final int start, final int numberOfTargets, final String controllerIdPrefix) { + final List targets = new ArrayList<>(); + for (int i = start; i < start + numberOfTargets; i++) { + targets.add(entityFactory.generateTarget(controllerIdPrefix + i)); + } + + return targets; + } + + /** + * Builds {@link Target} objects with given prefix for + * {@link Target#getControllerId()} followed by a number suffix starting + * with 0. + * + * @param numberOfTargets + * of {@link Target}s to generate + * @param controllerIdPrefix + * for {@link Target#getControllerId()} generation. + * @return list of {@link Target} objects + */ + public List generateTargets(final int numberOfTargets, final String controllerIdPrefix) { + return generateTargets(0, numberOfTargets, controllerIdPrefix); + } + + /** + * builds a set of {@link Target} fixtures from the given parameters. + * + * @param numberOfTargets + * number of targets to create + * @param controllerIdPrefix + * prefix used for the controller ID + * @param descriptionPrefix + * prefix used for the description + * @return set of {@link Target} + */ + public List generateTargets(final int numberOfTargets, final String controllerIdPrefix, + final String descriptionPrefix) { + return generateTargets(numberOfTargets, controllerIdPrefix, descriptionPrefix, null); + } + + /** + * method creates set of targets by by generating the controller ID and the + * description like: prefix + no of target. + * + * @param noOfTgts + * number of targets which should be created + * @param controllerIdPrefix + * prefix of the controllerID which is concatenated with the + * number of the target. Randomly generated if null. + * @param descriptionPrefix + * prefix of the target description which is concatenated with + * the number of the target + * @param tags + * tags which should be added to the created {@link Target}s + * @return set of created targets + */ + private List generateTargets(final int noOfTgts, final String controllerIdPrefix, + final String descriptionPrefix, final TargetTag[] tags) { + final List list = new ArrayList<>(); + for (int i = 0; i < noOfTgts; i++) { + String ctrlID = controllerIdPrefix; + if (Strings.isNullOrEmpty(ctrlID)) { + ctrlID = UUID.randomUUID().toString(); + } + ctrlID = String.format("%s-%05d", ctrlID, i); + + final String description = descriptionPrefix + DEFAULT_DESCRIPTION; + + final Target target = generateTarget(ctrlID, description, tags); + list.add(target); + + } + return list; + } + + /** + * Generates {@link TargetTag}s. + * + * @param number + * of {@link TargetTag}s to generate. + * + * @return generated {@link TargetTag}s. + */ + public List generateTargetTags(final int number) { + final List result = new ArrayList<>(); + + for (int i = 0; i < number; i++) { + result.add(entityFactory.generateTargetTag("tag" + i, "tagdesc" + i, String.valueOf(i))); + } + + return result; + } + + /** + * Create a set of {@link TargetTag}s. + * + * @param noOfTags + * number of {@link TargetTag}. to be created + * @param tagPrefix + * prefix for the {@link TargetTag#getName()} + * @return the created set of {@link TargetTag}s + */ + public List generateTargetTags(final int noOfTags, final String tagPrefix) { + final List list = new ArrayList<>(); + for (int i = 0; i < noOfTags; i++) { + String tagName = "myTag"; + if (!Strings.isNullOrEmpty(tagPrefix)) { + tagName = tagPrefix; + } + tagName = String.format("%s-%05d", tagName, i); + + final TargetTag targetTag = entityFactory.generateTargetTag(tagName); + list.add(targetTag); + } + return list; + } + + private Action sendUpdateActionStatusToTarget(final Status status, final Action updActA, final String... msgs) { + updActA.setStatus(status); + + final ActionStatus statusMessages = entityFactory.generateActionStatus(); + statusMessages.setAction(updActA); + statusMessages.setOccurredAt(System.currentTimeMillis()); + statusMessages.setStatus(status); + for (final String msg : msgs) { + statusMessages.addMessage(msg); + } + + return controllerManagament.addUpdateActionStatus(statusMessages); + } + + /** + * Append {@link ActionStatus} to all {@link Action}s of given + * {@link Target}s. + * + * @param targets + * to add {@link ActionStatus} + * @param status + * to add + * @param msgs + * to add + * + * @return updated {@link Action}. + */ + public List sendUpdateActionStatusToTargets(final Collection targets, final Status status, + final String... msgs) { + final List result = new ArrayList<>(); + for (final Target target : targets) { + final List findByTarget = deploymentManagement.findActionsByTarget(target); + for (final Action action : findByTarget) { + result.add(sendUpdateActionStatusToTarget(status, action, msgs)); + } + } + return result; + } +} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/WithSpringAuthorityRule.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/WithSpringAuthorityRule.java similarity index 99% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/WithSpringAuthorityRule.java rename to hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/WithSpringAuthorityRule.java index e61215973..b456cc32b 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/WithSpringAuthorityRule.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/WithSpringAuthorityRule.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.jpa; +package org.eclipse.hawkbit.repository.util; import java.lang.annotation.Annotation; import java.lang.reflect.Field; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/WithUser.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/WithUser.java similarity index 97% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/WithUser.java rename to hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/WithUser.java index 0a936f1c0..04af9196b 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/WithUser.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/WithUser.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.jpa; +package org.eclipse.hawkbit.repository.util; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; diff --git a/hawkbit-repository/pom.xml b/hawkbit-repository/pom.xml index 9d95d0a43..981f3225a 100644 --- a/hawkbit-repository/pom.xml +++ b/hawkbit-repository/pom.xml @@ -23,6 +23,8 @@ hawkbit-repository-jpa hawkbit-repository-api + hawkbit-repository-test + hawkbit-repository-core diff --git a/hawkbit-rest-core/pom.xml b/hawkbit-rest-core/pom.xml index 66fb1655a..0b5f39272 100644 --- a/hawkbit-rest-core/pom.xml +++ b/hawkbit-rest-core/pom.xml @@ -44,6 +44,12 @@ + + org.eclipse.hawkbit + hawkbit-repository-test + ${project.version} + test + org.easytesting fest-assert diff --git a/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTest.java b/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTest.java index e86f78d68..1b54eed3e 100644 --- a/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTest.java +++ b/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTest.java @@ -8,7 +8,7 @@ */ package org.eclipse.hawkbit.rest; -import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTest; +import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest; import org.eclipse.hawkbit.rest.configuration.RestConfiguration; import org.eclipse.hawkbit.rest.util.FilterHttpResponse; import org.springframework.beans.factory.annotation.Autowired; @@ -19,7 +19,7 @@ import org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder; * Abstract Test for Rest tests. */ @SpringApplicationConfiguration(classes = { RestConfiguration.class }) -public abstract class AbstractRestIntegrationTest extends AbstractIntegrationTest { +public abstract class AbstractRestIntegrationTest extends AbstractJpaIntegrationTest { @Autowired private FilterHttpResponse filterHttpResponse; @@ -29,5 +29,4 @@ public abstract class AbstractRestIntegrationTest extends AbstractIntegrationTes final DefaultMockMvcBuilder createMvcWebAppContext = super.createMvcWebAppContext(); return createMvcWebAppContext.addFilter(filterHttpResponse); } - } diff --git a/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTestWithMongoDB.java b/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTestWithMongoDB.java index d3da40035..81e2c3d16 100644 --- a/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTestWithMongoDB.java +++ b/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTestWithMongoDB.java @@ -8,7 +8,7 @@ */ package org.eclipse.hawkbit.rest; -import org.eclipse.hawkbit.repository.jpa.AbstractIntegrationTestWithMongoDB; +import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTestWithMongoDB; import org.eclipse.hawkbit.rest.configuration.RestConfiguration; import org.eclipse.hawkbit.rest.util.FilterHttpResponse; import org.springframework.beans.factory.annotation.Autowired; @@ -19,14 +19,14 @@ import org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder; * Abstract Test for Rest tests. */ @SpringApplicationConfiguration(classes = { RestConfiguration.class }) -public abstract class AbstractRestIntegrationTestWithMongoDB extends AbstractIntegrationTestWithMongoDB { +public abstract class AbstractRestIntegrationTestWithMongoDB extends AbstractJpaIntegrationTestWithMongoDB { @Autowired private FilterHttpResponse filterHttpResponse; @Override protected DefaultMockMvcBuilder createMvcWebAppContext() { - DefaultMockMvcBuilder createMvcWebAppContext = super.createMvcWebAppContext(); + final DefaultMockMvcBuilder createMvcWebAppContext = super.createMvcWebAppContext(); return createMvcWebAppContext.addFilter(filterHttpResponse); } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleAddUpdateWindow.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleAddUpdateWindow.java index d6fbada89..49b2dfada 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleAddUpdateWindow.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleAddUpdateWindow.java @@ -10,6 +10,7 @@ package org.eclipse.hawkbit.ui.artifacts.smtable; import java.io.Serializable; +import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; @@ -66,6 +67,9 @@ public class SoftwareModuleAddUpdateWindow implements Serializable { @Autowired private transient SoftwareManagement softwareManagement; + @Autowired + private transient EntityFactory entityFactory; + private Label madatoryLabel; private TextField nameTextField; @@ -277,8 +281,8 @@ public class SoftwareModuleAddUpdateWindow implements Serializable { uiNotifcation.displayValidationError( i18n.get("message.duplicate.softwaremodule", new Object[] { name, version })); } else { - final SoftwareModule newBaseSoftwareModule = HawkbitCommonUtil.addNewBaseSoftware(softwareManagement, - name, version, vendor, softwareManagement.findSoftwareModuleTypeByName(type), description); + final SoftwareModule newBaseSoftwareModule = HawkbitCommonUtil.addNewBaseSoftware(entityFactory, name, + version, vendor, softwareManagement.findSoftwareModuleTypeByName(type), description); if (newBaseSoftwareModule != null) { /* display success message */ uiNotifcation.displaySuccess(i18n.get("message.save.success", new Object[] { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/CreateUpdateSoftwareTypeLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/CreateUpdateSoftwareTypeLayout.java index c71b06671..eb915aef3 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/CreateUpdateSoftwareTypeLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtype/CreateUpdateSoftwareTypeLayout.java @@ -13,6 +13,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; @@ -93,6 +94,9 @@ public class CreateUpdateSoftwareTypeLayout extends CustomComponent implements C @Autowired private transient SoftwareManagement swTypeManagementService; + @Autowired + private transient EntityFactory entityFactory; + @Autowired private transient EventBus.SessionEventBus eventBus; @@ -625,8 +629,8 @@ public class CreateUpdateSoftwareTypeLayout extends CustomComponent implements C } if (null != typeNameValue && null != typeKeyValue) { - SoftwareModuleType newSWType = swTypeManagementService.generateSoftwareModuleType(typeKeyValue, - typeNameValue, typeDescValue, assignNumber); + SoftwareModuleType newSWType = entityFactory.generateSoftwareModuleType(typeKeyValue, typeNameValue, + typeDescValue, assignNumber); newSWType.setColour(colorPicked); if (null != typeDescValue) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/DistributionSetTypeBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/DistributionSetTypeBeanQuery.java index 04200208b..ded26b254 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/DistributionSetTypeBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/DistributionSetTypeBeanQuery.java @@ -13,6 +13,7 @@ import java.util.List; import java.util.Map; import org.eclipse.hawkbit.repository.DistributionSetManagement; +import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; @@ -41,6 +42,7 @@ public class DistributionSetTypeBeanQuery extends AbstractBeanQuery firstPageDistSetType = null; private transient DistributionSetManagement distributionSetManagement; + private transient EntityFactory entityFactory; /** * Parametric constructor. @@ -57,7 +59,7 @@ public class DistributionSetTypeBeanQuery extends AbstractBeanQuery loadBeans(final int startIndex, final int count) { Page typeBeans; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/SoftwareModuleTypeBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/SoftwareModuleTypeBeanQuery.java index 9dcdeb12b..8705f7aa9 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/SoftwareModuleTypeBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/SoftwareModuleTypeBeanQuery.java @@ -11,6 +11,7 @@ package org.eclipse.hawkbit.ui.common; import java.util.List; import java.util.Map; +import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; @@ -31,6 +32,7 @@ public class SoftwareModuleTypeBeanQuery extends AbstractBeanQuery firstPageSwModuleType = null; private transient SoftwareManagement softwareManagement; + private transient EntityFactory entityFactory; /** * Parametric constructor. @@ -47,7 +49,14 @@ public class SoftwareModuleTypeBeanQuery extends AbstractBeanQuery itemIds = (List) selectedTable.getItemIds(); if (null != typeNameValue && null != typeKeyValue && null != itemIds && !itemIds.isEmpty()) { - DistributionSetType newDistType = distributionSetManagement.generateDistributionSetType(typeKeyValue, - typeNameValue, typeDescValue); + DistributionSetType newDistType = entityFactory.generateDistributionSetType(typeKeyValue, typeNameValue, + typeDescValue); for (final Long id : itemIds) { final Item item = selectedTable.getItem(id); final String distTypeName = (String) item.getItemProperty(DIST_TYPE_NAME).getValue(); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterHeader.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterHeader.java index a89e98d56..50e89371a 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterHeader.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/CreateOrUpdateFilterHeader.java @@ -13,6 +13,7 @@ import java.util.concurrent.Executor; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; +import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.repository.TargetFilterQueryManagement; import org.eclipse.hawkbit.repository.model.TargetFilterQuery; @@ -95,6 +96,9 @@ public class CreateOrUpdateFilterHeader extends VerticalLayout implements Button @Qualifier("uiExecutor") private transient Executor executor; + @Autowired + private transient EntityFactory entityFactory; + private HorizontalLayout breadcrumbLayout; private Button breadcrumbButton; @@ -503,7 +507,7 @@ public class CreateOrUpdateFilterHeader extends VerticalLayout implements Button } private void createTargetFilterQuery() { - final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement.generateTargetFilterQuery(); + final TargetFilterQuery targetFilterQuery = entityFactory.generateTargetFilterQuery(); targetFilterQuery.setName(nameTextField.getValue()); targetFilterQuery.setQuery(queryTextField.getValue()); targetFilterQueryManagement.createTargetFilterQuery(targetFilterQuery); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionAddUpdateWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionAddUpdateWindowLayout.java index cc52ce795..90b3ad597 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionAddUpdateWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionAddUpdateWindowLayout.java @@ -16,6 +16,7 @@ import java.util.Map; import javax.annotation.PostConstruct; import org.eclipse.hawkbit.repository.DistributionSetManagement; +import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.jpa.TenantMetaDataRepository; @@ -94,6 +95,9 @@ public class DistributionAddUpdateWindowLayout extends VerticalLayout { @Autowired private transient TenantMetaDataRepository tenantMetaDataRepository; + @Autowired + private transient EntityFactory entityFactory; + private Button saveDistributionBtn; private Button discardDistributionBtn; private TextField distNameTextField; @@ -145,12 +149,12 @@ public class DistributionAddUpdateWindowLayout extends VerticalLayout { setSizeUndefined(); addComponents(madatoryLabel, distsetTypeNameComboBox, distNameTextField, distVersionTextField, descTextArea, reqMigStepCheckbox); - + addComponent(buttonsLayout); setComponentAlignment(madatoryLabel, Alignment.MIDDLE_LEFT); distNameTextField.focus(); - - } + + } /** * Create required UI components. @@ -297,7 +301,7 @@ public class DistributionAddUpdateWindowLayout extends VerticalLayout { if (mandatoryCheck(name, version, distSetTypeName) && duplicateCheck(name, version)) { final String desc = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue()); final boolean isMigStepReq = reqMigStepCheckbox.getValue(); - DistributionSet newDist = distributionSetManagement.generateDistributionSet(); + DistributionSet newDist = entityFactory.generateDistributionSet(); setDistributionValues(newDist, name, version, distSetTypeName, desc, isMigStepReq); newDist = distributionSetManagement.createDistributionSet(newDist); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/CreateUpdateDistributionTagLayoutWindow.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/CreateUpdateDistributionTagLayoutWindow.java index 56ba4183b..e37086e65 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/CreateUpdateDistributionTagLayoutWindow.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/CreateUpdateDistributionTagLayoutWindow.java @@ -11,6 +11,7 @@ package org.eclipse.hawkbit.ui.management.dstag; import java.util.ArrayList; import java.util.List; +import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetTagCreatedBulkEvent; import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetTagDeletedEvent; import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetTagUpdateEvent; @@ -48,6 +49,9 @@ public class CreateUpdateDistributionTagLayoutWindow extends CreateUpdateTagLayo @Autowired private transient UINotification uiNotification; + @Autowired + private transient EntityFactory entityFactory; + private static final String MISSING_TAG_NAME = "message.error.missing.tagname"; private static final String TARGET_TAG_NAME_DYNAMIC_STYLE = "new-target-tag-name"; private static final String MSG_TEXTFIELD_NAME = "textfield.name"; @@ -98,7 +102,7 @@ public class CreateUpdateDistributionTagLayoutWindow extends CreateUpdateTagLayo final String tagDescValue = HawkbitCommonUtil.trimAndNullIfEmpty(tagDesc.getValue()); if (null != tagNameValue) { - DistributionSetTag newDistTag = tagManagement.generateDistributionSetTag(tagNameValue, tagDescValue, + DistributionSetTag newDistTag = entityFactory.generateDistributionSetTag(tagNameValue, tagDescValue, new Color(0, 146, 58).getCSS()); if (colorPicked != null) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagButtons.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagButtons.java index 003700df5..9080a433f 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagButtons.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstag/DistributionTagButtons.java @@ -11,7 +11,7 @@ package org.eclipse.hawkbit.ui.management.dstag; import java.util.HashMap; import java.util.Map; -import org.eclipse.hawkbit.repository.TagManagement; +import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetTagCreatedBulkEvent; import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetTagDeletedEvent; import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetTagUpdateEvent; @@ -53,15 +53,15 @@ public class DistributionTagButtons extends AbstractFilterButtons { private DistributionTagDropEvent spDistTagDropEvent; @Autowired - private TagManagement tagManagement; + private ManagementUIState managementUIState; @Autowired - private ManagementUIState managementUIState; + private transient EntityFactory entityFactory; @Override public void init(final AbstractFilterButtonClickBehaviour filterButtonClickBehaviour) { super.init(filterButtonClickBehaviour); - addNewTag(tagManagement.generateDistributionSetTag("NO TAG")); + addNewTag(entityFactory.generateDistributionSetTag("NO TAG")); } @EventBusListenerMethod(scope = EventScope.SESSION) @@ -143,7 +143,7 @@ public class DistributionTagButtons extends AbstractFilterButtons { private void refreshTagTable() { ((LazyQueryContainer) getContainerDataSource()).refresh(); removeGeneratedColumn(FILTER_BUTTON_COLUMN); - addNewTag(tagManagement.generateDistributionSetTag("NO TAG")); + addNewTag(entityFactory.generateDistributionSetTag("NO TAG")); addColumn(); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java index 23a82da0f..d6a613cf7 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/BulkUploadHandler.java @@ -26,6 +26,7 @@ import java.util.concurrent.Executor; import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement; +import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.model.Action.ActionType; @@ -97,6 +98,8 @@ public class BulkUploadHandler extends CustomComponent final TargetBulkUpdateWindowLayout targetBulkUpdateWindowLayout; + private final EntityFactory entityFactory; + /** * * @param targetBulkUpdateWindowLayout @@ -124,6 +127,7 @@ public class BulkUploadHandler extends CustomComponent this.eventBus = targetBulkUpdateWindowLayout.getEventBus(); distributionSetManagement = SpringContextHelper.getBean(DistributionSetManagement.class); tagManagement = SpringContextHelper.getBean(TagManagement.class); + entityFactory = SpringContextHelper.getBean(EntityFactory.class); } /** @@ -380,7 +384,7 @@ public class BulkUploadHandler extends CustomComponent final String newDesc = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue()); /* create new target entity */ - final Target newTarget = targetManagement.generateTarget(newControllerId); + final Target newTarget = entityFactory.generateTarget(newControllerId); setTargetValues(newTarget, newName, newDesc); targetManagement.createTarget(newTarget); managementUIState.getTargetTableFilters().getBulkUpload().getTargetsCreated().add(newControllerId); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetAddUpdateWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetAddUpdateWindowLayout.java index ddf109773..be17beb18 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetAddUpdateWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetAddUpdateWindowLayout.java @@ -11,6 +11,7 @@ package org.eclipse.hawkbit.ui.management.targettable; import java.util.HashSet; import java.util.Set; +import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetIdName; @@ -69,6 +70,9 @@ public class TargetAddUpdateWindowLayout extends CustomComponent { @Autowired private transient UINotification uINotification; + + @Autowired + private transient EntityFactory entityFactory; private TextField controllerIDTextField; private TextField nameTextField; @@ -245,7 +249,7 @@ public class TargetAddUpdateWindowLayout extends CustomComponent { final String newDesc = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue()); /* create new target entity */ - Target newTarget = targetManagement.generateTarget(newControlllerId); + Target newTarget = entityFactory.generateTarget(newControlllerId); /* set values to the new target entity */ setTargetValues(newTarget, newName, newDesc); /* save new target */ diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/CreateUpdateTargetTagLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/CreateUpdateTargetTagLayout.java index e5990be49..80de83982 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/CreateUpdateTargetTagLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/CreateUpdateTargetTagLayout.java @@ -11,6 +11,7 @@ package org.eclipse.hawkbit.ui.management.targettag; import java.util.ArrayList; import java.util.List; +import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.eventbus.event.TargetTagCreatedBulkEvent; import org.eclipse.hawkbit.repository.eventbus.event.TargetTagDeletedEvent; import org.eclipse.hawkbit.repository.eventbus.event.TargetTagUpdateEvent; @@ -49,6 +50,9 @@ public class CreateUpdateTargetTagLayout extends CreateUpdateTagLayout { @Autowired private transient UINotification uiNotification; + @Autowired + private transient EntityFactory entityFactory; + private Window targetTagWindow; @Override @@ -193,7 +197,7 @@ public class CreateUpdateTargetTagLayout extends CreateUpdateTagLayout { final String tagNameValue = HawkbitCommonUtil.trimAndNullIfEmpty(tagName.getValue()); final String tagDescValue = HawkbitCommonUtil.trimAndNullIfEmpty(tagDesc.getValue()); if (null != tagNameValue) { - TargetTag newTargetTag = tagManagement.generateTargetTag(tagNameValue); + TargetTag newTargetTag = entityFactory.generateTargetTag(tagNameValue); if (null != tagDescValue) { newTargetTag.setDescription(tagDescValue); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java index eeac79728..e7e9c64b1 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettag/TargetTagFilterButtons.java @@ -12,8 +12,8 @@ import java.util.List; import java.util.Set; import java.util.stream.Collectors; +import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.SpPermissionChecker; -import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.eventbus.event.TargetTagCreatedBulkEvent; import org.eclipse.hawkbit.repository.eventbus.event.TargetTagDeletedEvent; @@ -77,7 +77,7 @@ public class TargetTagFilterButtons extends AbstractFilterButtons { private SpPermissionChecker permChecker; @Autowired - private TagManagement tagManagement; + private transient EntityFactory entityFactory; @Autowired private transient TargetManagement targetManagement; @@ -94,7 +94,7 @@ public class TargetTagFilterButtons extends AbstractFilterButtons { public void init(final TargetTagFilterButtonClick filterButtonClickBehaviour) { this.filterButtonClickBehaviour = filterButtonClickBehaviour; super.init(filterButtonClickBehaviour); - addNewTargetTag(tagManagement.generateTargetTag("NO TAG")); + addNewTargetTag(entityFactory.generateTargetTag("NO TAG")); } @EventBusListenerMethod(scope = EventScope.SESSION) @@ -294,7 +294,7 @@ public class TargetTagFilterButtons extends AbstractFilterButtons { private void refreshContainer() { removeGeneratedColumn(FILTER_BUTTON_COLUMN); ((LazyQueryContainer) getContainerDataSource()).refresh(); - addNewTargetTag(tagManagement.generateTargetTag("NO TAG")); + addNewTargetTag(entityFactory.generateTargetTag("NO TAG")); addColumn(); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java index f0329e3fe..c909c9c5d 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java @@ -13,6 +13,7 @@ import java.util.Date; import java.util.List; import org.eclipse.hawkbit.repository.DistributionSetManagement; +import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.model.Action.ActionType; @@ -108,6 +109,9 @@ public class AddUpdateRolloutWindowLayout extends CustomComponent { @Autowired private transient UiProperties uiProperties; + @Autowired + private transient EntityFactory entityFactory; + @Autowired private I18N i18n; @@ -479,7 +483,7 @@ public class AddUpdateRolloutWindowLayout extends CustomComponent { } private Rollout saveRollout() { - Rollout rolloutToCreate = rolloutManagement.generateRollout(); + Rollout rolloutToCreate = entityFactory.generateRollout(); final int amountGroup = Integer.parseInt(noOfGroups.getValue()); final String targetFilter = getTargetFilterQuery(); final int errorThresoldPercent = getErrorThresoldPercentage(amountGroup); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java index 7ed9c81dd..da0e3e828 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtil.java @@ -19,6 +19,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.TimeZone; +import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.model.AssignmentResult; import org.eclipse.hawkbit.repository.model.DistributionSet; @@ -430,7 +431,7 @@ public final class HawkbitCommonUtil { return trimAndNullIfEmpty(orgText) == null ? SPUIDefinitions.SPACE : orgText; } - /** + /** * Find extra height required to increase by all the components to utilize * the full height of browser for the responsive UI. * @@ -760,10 +761,10 @@ public final class HawkbitCommonUtil { * base software module description * @return BaseSoftwareModule new base software module */ - public static SoftwareModule addNewBaseSoftware(final SoftwareManagement softwareManagement, final String bsname, + public static SoftwareModule addNewBaseSoftware(final EntityFactory entityFactory, final String bsname, final String bsversion, final String bsvendor, final SoftwareModuleType bstype, final String description) { final SoftwareManagement swMgmtService = SpringContextHelper.getBean(SoftwareManagement.class); - SoftwareModule newSWModule = softwareManagement.generateSoftwareModule(); + SoftwareModule newSWModule = entityFactory.generateSoftwareModule(); newSWModule.setType(bstype); newSWModule.setName(bsname); newSWModule.setVersion(bsversion); diff --git a/pom.xml b/pom.xml index 58e7b56dc..add09a1d9 100644 --- a/pom.xml +++ b/pom.xml @@ -553,7 +553,6 @@ de.flapdoodle.embed de.flapdoodle.embed.mongo ${embedded-mongo.version} - test org.easytesting From b369369c2cdf6d79b528b5511f3e1562c5e0bc34 Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Tue, 31 May 2016 08:52:09 +0200 Subject: [PATCH 28/54] add javadoc Signed-off-by: Michael Hirsch --- .../repository/model/SoftwareModule.java | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModule.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModule.java index 67e1027a1..cb01219f4 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModule.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModule.java @@ -49,8 +49,17 @@ public interface SoftwareModule extends NamedVersionedEntity { */ List getLocalArtifacts(); + /** + * @return the vendor of this software module + */ String getVendor(); + /** + * @param vendor + * the vendor of this software module to set + */ + void setVendor(String vendor); + /** * @param artifact * is removed from the assigned {@link LocalArtifact}s. @@ -63,14 +72,30 @@ public interface SoftwareModule extends NamedVersionedEntity { */ void removeArtifact(ExternalArtifact artifact); - void setVendor(String vendor); - + /** + * @return the type of the software module + */ SoftwareModuleType getType(); + /** + * @return {@code true} if this software module is marked as deleted + * otherwise {@code false} + */ boolean isDeleted(); + /** + * Marks or un-marks this software module as deleted. + * + * @param deleted + * {@code true} if the software module should be marked as + * deleted otherwise {@code false} + */ void setDeleted(boolean deleted); + /** + * @param type + * the module type for this software module + */ void setType(SoftwareModuleType type); /** From b1a2a583e96acb85218139c1c88e9c441b4d52b4 Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Tue, 31 May 2016 09:21:40 +0200 Subject: [PATCH 29/54] fix mock test by mocking action and target Signed-off-by: Michael Hirsch --- .../amqp/AmqpMessageHandlerServiceTest.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java index 283b08eed..a0515a871 100644 --- a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java +++ b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java @@ -50,6 +50,7 @@ import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; +import org.eclipse.hawkbit.repository.model.TargetInfo; import org.eclipse.hawkbit.security.SecurityTokenGenerator; import org.junit.Before; import org.junit.Test; @@ -429,14 +430,18 @@ public class AmqpMessageHandlerServiceTest { initalizeSecurityTokenGenerator(); // Mock - final JpaAction action = new JpaAction(); - action.setId(targetId); - action.setStatus(status); - action.setTenant("DEFAULT"); - final JpaTarget target = new JpaTarget("target1"); - action.setTarget(target); - - return action; + final JpaAction actionMock = mock(JpaAction.class); + final JpaTarget targetMock = mock(JpaTarget.class); + final TargetInfo targetInfoMock = mock(TargetInfo.class); + when(actionMock.getId()).thenReturn(targetId); + when(actionMock.getStatus()).thenReturn(status); + when(actionMock.getTenant()).thenReturn("DEFAULT"); + when(actionMock.getTarget()).thenReturn(targetMock); + when(targetMock.getControllerId()).thenReturn("target1"); + when(targetMock.getSecurityToken()).thenReturn("securityToken"); + when(targetMock.getTargetInfo()).thenReturn(targetInfoMock); + when(targetInfoMock.getAddress()).thenReturn(null); + return actionMock; } private void initalizeSecurityTokenGenerator() throws IllegalAccessException { From a0ec726fd0feafdc832857a6a31ee6c0a66685c4 Mon Sep 17 00:00:00 2001 From: SirWayne Date: Tue, 31 May 2016 10:48:56 +0200 Subject: [PATCH 30/54] Small fixes Signed-off-by: SirWayne --- .../resource/DdiArtifactStoreController.java | 6 +++--- .../ddi/rest/resource/DdiRootController.java | 20 +++++++++---------- .../rest/resource/DdiDeploymentBaseTest.java | 6 +++--- .../amqp/AmqpMessageDispatcherService.java | 10 +++------- ...onstants.java => RepositoryConstants.java} | 4 ++-- .../hawkbit/repository/SystemManagement.java | 2 +- .../hawkbit/repository/TargetManagement.java | 2 +- .../model/ActionWithStatusCount.java | 2 +- .../hawkbit/repository/model/Artifact.java | 2 +- .../hawkbit/repository/model/BaseEntity.java | 2 +- .../repository/model/DistributionSet.java | 2 +- .../model/DistributionSetMetadata.java | 2 +- .../repository/model/DistributionSetTag.java | 2 +- .../repository/model/DistributionSetType.java | 2 +- .../repository/model/ExternalArtifact.java | 2 +- .../hawkbit/repository/model/MetaData.java | 2 +- .../model/NamedVersionedEntity.java | 2 +- ...nts.java => RepositoryModelConstants.java} | 4 ++-- .../hawkbit/repository/model/Rollout.java | 2 +- .../repository/model/SoftwareModule.java | 2 +- .../model/SoftwareModuleMetadata.java | 2 +- .../repository/model/SoftwareModuleType.java | 2 +- .../eclipse/hawkbit/repository/model/Tag.java | 2 +- .../repository/model/TargetFilterQuery.java | 2 +- .../hawkbit/repository/model/TargetInfo.java | 2 +- .../hawkbit/repository/model/TargetTag.java | 2 +- .../model/TargetWithActionStatus.java | 2 +- .../model/TargetWithActionType.java | 2 +- .../model/TenantAwareBaseEntity.java | 2 +- .../repository/model/TenantConfiguration.java | 2 +- .../repository/model/TenantMetaData.java | 2 +- .../jpa/JpaControllerManagement.java | 6 +++--- .../jpa/JpaDeploymentManagement.java | 4 ++-- .../repository/jpa/cache/CacheKeys.java | 2 +- .../jpa/DeploymentManagementTest.java | 4 ++-- .../util/AbstractIntegrationTest.java | 4 ++-- .../ManangementConfirmationWindowLayout.java | 4 ++-- .../rollout/AddUpdateRolloutWindowLayout.java | 4 ++-- .../ui/utils/SPUIButtonDefinitions.java | 2 +- .../ui/utils/SPUILabelDefinitions.java | 2 +- .../ui/utils/SPUIStyleDefinitions.java | 2 +- .../ui/utils/SPUITargetDefinitions.java | 2 +- 42 files changed, 66 insertions(+), 70 deletions(-) rename hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/{Constants.java => RepositoryConstants.java} (92%) rename hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/{Constants.java => RepositoryModelConstants.java} (88%) diff --git a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java index 9d690f9d2..5bed44295 100644 --- a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java +++ b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java @@ -17,7 +17,7 @@ import javax.servlet.http.HttpServletRequest; import org.eclipse.hawkbit.artifact.repository.model.DbArtifact; import org.eclipse.hawkbit.ddi.dl.rest.api.DdiDlArtifactStoreControllerRestApi; import org.eclipse.hawkbit.repository.ArtifactManagement; -import org.eclipse.hawkbit.repository.Constants; +import org.eclipse.hawkbit.repository.RepositoryConstants; import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.jpa.cache.CacheWriteNotify; @@ -149,10 +149,10 @@ public class DdiArtifactStoreController implements DdiDlArtifactStoreControllerR actionStatus.setStatus(Status.DOWNLOAD); if (range != null) { - actionStatus.addMessage(Constants.SERVER_MESSAGE_PREFIX + "Target downloads range " + range + " of: " + actionStatus.addMessage(RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target downloads range " + range + " of: " + request.getRequestURI()); } else { - actionStatus.addMessage(Constants.SERVER_MESSAGE_PREFIX + "Target downloads: " + request.getRequestURI()); + actionStatus.addMessage(RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target downloads: " + request.getRequestURI()); } controllerManagement.addInformationalActionStatus(actionStatus); return action; diff --git a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java index 656835e95..0c6fa4386 100644 --- a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java +++ b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java @@ -29,7 +29,7 @@ import org.eclipse.hawkbit.ddi.json.model.DdiDeploymentBase; import org.eclipse.hawkbit.ddi.json.model.DdiResult.FinalResult; import org.eclipse.hawkbit.ddi.rest.api.DdiRootControllerRestApi; import org.eclipse.hawkbit.repository.ArtifactManagement; -import org.eclipse.hawkbit.repository.Constants; +import org.eclipse.hawkbit.repository.RepositoryConstants; import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.SoftwareManagement; @@ -185,10 +185,10 @@ public class DdiRootController implements DdiRootControllerRestApi { statusMessage.setStatus(Status.DOWNLOAD); if (range != null) { - statusMessage.addMessage(Constants.SERVER_MESSAGE_PREFIX + "Target downloads range " + range + " of: " + statusMessage.addMessage(RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target downloads range " + range + " of: " + request.getRequestURI()); } else { - statusMessage.addMessage(Constants.SERVER_MESSAGE_PREFIX + "Target downloads " + request.getRequestURI()); + statusMessage.addMessage(RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target downloads " + request.getRequestURI()); } controllerManagement.addInformationalActionStatus(statusMessage); return action; @@ -251,7 +251,7 @@ public class DdiRootController implements DdiRootControllerRestApi { LOG.debug("Found an active UpdateAction for target {}. returning deyploment: {}", targetid, base); - controllerManagement.registerRetrieved(action, Constants.SERVER_MESSAGE_PREFIX + controllerManagement.registerRetrieved(action, RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target retrieved update action and should start now the download."); return new ResponseEntity<>(base, HttpStatus.OK); @@ -306,13 +306,13 @@ public class DdiRootController implements DdiRootControllerRestApi { LOG.debug("Controller confirmed cancel (actionid: {}, targetid: {}) as we got {} report.", actionid, targetid, feedback.getStatus().getExecution()); actionStatus.setStatus(Status.CANCELED); - actionStatus.addMessage(Constants.SERVER_MESSAGE_PREFIX + "Target confirmed cancelation."); + actionStatus.addMessage(RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target confirmed cancelation."); break; case REJECTED: LOG.info("Controller reported internal error (actionid: {}, targetid: {}) as we got {} report.", actionid, targetid, feedback.getStatus().getExecution()); actionStatus.setStatus(Status.WARNING); - actionStatus.addMessage(Constants.SERVER_MESSAGE_PREFIX + "Target REJECTED update."); + actionStatus.addMessage(RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target REJECTED update."); break; case CLOSED: handleClosedUpdateStatus(feedback, targetid, actionid, actionStatus); @@ -340,7 +340,7 @@ public class DdiRootController implements DdiRootControllerRestApi { targetid, feedback.getStatus().getExecution()); actionStatus.setStatus(Status.RUNNING); actionStatus - .addMessage(Constants.SERVER_MESSAGE_PREFIX + "Target reported " + feedback.getStatus().getExecution()); + .addMessage(RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target reported " + feedback.getStatus().getExecution()); } private static void handleClosedUpdateStatus(final DdiActionFeedback feedback, final String targetid, @@ -349,10 +349,10 @@ public class DdiRootController implements DdiRootControllerRestApi { feedback.getStatus().getExecution()); if (feedback.getStatus().getResult().getFinished() == FinalResult.FAILURE) { actionStatus.setStatus(Status.ERROR); - actionStatus.addMessage(Constants.SERVER_MESSAGE_PREFIX + "Target reported CLOSED with ERROR!"); + actionStatus.addMessage(RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target reported CLOSED with ERROR!"); } else { actionStatus.setStatus(Status.FINISHED); - actionStatus.addMessage(Constants.SERVER_MESSAGE_PREFIX + "Target reported CLOSED with OK!"); + actionStatus.addMessage(RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target reported CLOSED with OK!"); } } @@ -390,7 +390,7 @@ public class DdiRootController implements DdiRootControllerRestApi { LOG.debug("Found an active CancelAction for target {}. returning cancel: {}", targetid, cancel); - controllerManagement.registerRetrieved(action, Constants.SERVER_MESSAGE_PREFIX + controllerManagement.registerRetrieved(action, RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target retrieved cancel action and should start now the cancelation."); return new ResponseEntity<>(cancel, HttpStatus.OK); diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java index 124d8e38d..33d470b3d 100644 --- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java +++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java @@ -29,7 +29,7 @@ import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.ActionType; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; -import org.eclipse.hawkbit.repository.model.Constants; +import org.eclipse.hawkbit.repository.model.RepositoryModelConstants; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.Target; @@ -113,7 +113,7 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(0); List saved = deploymentManagement.assignDistributionSet(ds.getId(), ActionType.FORCED, - Constants.NO_FORCE_TIME, savedTarget.getControllerId()).getAssignedEntity(); + RepositoryModelConstants.NO_FORCE_TIME, savedTarget.getControllerId()).getAssignedEntity(); assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(1); final Action action = deploymentManagement.findActiveActionsByTarget(savedTarget).get(0); @@ -250,7 +250,7 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(0); List saved = deploymentManagement.assignDistributionSet(ds.getId(), ActionType.SOFT, - Constants.NO_FORCE_TIME, savedTarget.getControllerId()).getAssignedEntity(); + RepositoryModelConstants.NO_FORCE_TIME, savedTarget.getControllerId()).getAssignedEntity(); assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(1); final Action action = deploymentManagement.findActiveActionsByTarget(savedTarget).get(0); diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java index 3b05c96a6..b643be322 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java +++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java @@ -25,7 +25,6 @@ import org.eclipse.hawkbit.dmf.json.model.DownloadAndUpdateRequest; import org.eclipse.hawkbit.dmf.json.model.SoftwareModule; import org.eclipse.hawkbit.eventbus.EventSubscriber; import org.eclipse.hawkbit.eventbus.event.CancelTargetAssignmentEvent; -import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.eventbus.event.TargetAssignDistributionSetEvent; import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.util.IpUtil; @@ -53,14 +52,11 @@ public class AmqpMessageDispatcherService extends BaseAmqpService { @Autowired private AmqpSenderService amqpSenderService; - @Autowired - private SoftwareManagement softwareManagement; - /** * Constructor. * - * @param messageConverter - * message converter + * @param rabbitTemplate + * the rabbitTemplate */ @Autowired public AmqpMessageDispatcherService(final RabbitTemplate rabbitTemplate) { @@ -118,7 +114,7 @@ public class AmqpMessageDispatcherService extends BaseAmqpService { } - private MessageProperties createConnectorMessageProperties(final String tenant, final String controllerId, + private static MessageProperties createConnectorMessageProperties(final String tenant, final String controllerId, final EventTopic topic) { final MessageProperties messageProperties = createMessageProperties(); messageProperties.setHeader(MessageHeaderKey.TOPIC, topic); diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/Constants.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RepositoryConstants.java similarity index 92% rename from hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/Constants.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RepositoryConstants.java index fcfd6ab5e..f2cd3f9f6 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/Constants.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RepositoryConstants.java @@ -15,7 +15,7 @@ import org.eclipse.hawkbit.repository.model.DistributionSetType; * Repository constants. * */ -public final class Constants { +public final class RepositoryConstants { /** * Prefix that the server puts in front of @@ -30,7 +30,7 @@ public final class Constants { */ public static final int DEFAULT_DS_TYPES_IN_TENANT = 2; - private Constants() { + private RepositoryConstants() { // Utility class. } diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java index 5cc17e09b..8ee3b7600 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java @@ -74,7 +74,7 @@ public interface SystemManagement { /** * Returns {@link TenantMetaData} of given and current tenant. Creates for * new tenants also two {@link SoftwareModuleType} (os and app) and - * {@link Constants#DEFAULT_DS_TYPES_IN_TENANT} {@link DistributionSetType}s + * {@link RepositoryConstants#DEFAULT_DS_TYPES_IN_TENANT} {@link DistributionSetType}s * (os and os_app). * * DISCLAIMER: this variant is used during initial login (where the tenant diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java index 9280e065d..ee10883ec 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java @@ -601,4 +601,4 @@ public interface TargetManagement { + SpringEvalExpressions.IS_CONTROLLER) List updateTargets(@NotNull Collection targets); -} \ No newline at end of file +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/ActionWithStatusCount.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/ActionWithStatusCount.java index c497783e2..268c37853 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/ActionWithStatusCount.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/ActionWithStatusCount.java @@ -45,4 +45,4 @@ public interface ActionWithStatusCount { */ String getRolloutName(); -} \ No newline at end of file +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Artifact.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Artifact.java index 95689a9d9..cc726839d 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Artifact.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Artifact.java @@ -39,4 +39,4 @@ public interface Artifact extends TenantAwareBaseEntity { */ Long getSize(); -} \ No newline at end of file +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/BaseEntity.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/BaseEntity.java index f23b226c6..2a9948bc5 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/BaseEntity.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/BaseEntity.java @@ -46,4 +46,4 @@ public interface BaseEntity extends Serializable, Identifiable { */ long getOptLockRevision(); -} \ No newline at end of file +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSet.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSet.java index c6532b339..5747b38f3 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSet.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSet.java @@ -129,4 +129,4 @@ public interface DistributionSet extends NamedVersionedEntity { */ boolean isComplete(); -} \ No newline at end of file +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetMetadata.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetMetadata.java index dfa9b9716..87a62e9ba 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetMetadata.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetMetadata.java @@ -19,4 +19,4 @@ public interface DistributionSetMetadata extends MetaData { */ DistributionSet getDistributionSet(); -} \ No newline at end of file +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTag.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTag.java index 31f909348..05089d138 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTag.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTag.java @@ -22,4 +22,4 @@ public interface DistributionSetTag extends Tag { */ List getAssignedToDistributionSet(); -} \ No newline at end of file +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetType.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetType.java index 5546a9f6d..cf5da40b2 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetType.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetType.java @@ -170,4 +170,4 @@ public interface DistributionSetType extends NamedEntity { */ void setColour(final String colour); -} \ No newline at end of file +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifact.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifact.java index 4ff3ab5a8..7e1a965e7 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifact.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifact.java @@ -38,4 +38,4 @@ public interface ExternalArtifact extends Artifact { */ void setUrlSuffix(String urlSuffix); -} \ No newline at end of file +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/MetaData.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/MetaData.java index 4f3397b23..68b7349f9 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/MetaData.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/MetaData.java @@ -36,4 +36,4 @@ public interface MetaData extends Serializable { */ void setValue(String value); -} \ No newline at end of file +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/NamedVersionedEntity.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/NamedVersionedEntity.java index de6cded12..b66115082 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/NamedVersionedEntity.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/NamedVersionedEntity.java @@ -25,4 +25,4 @@ public interface NamedVersionedEntity extends NamedEntity { */ void setVersion(String version); -} \ No newline at end of file +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Constants.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/RepositoryModelConstants.java similarity index 88% rename from hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Constants.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/RepositoryModelConstants.java index b43ec6f88..66806915a 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Constants.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/RepositoryModelConstants.java @@ -12,7 +12,7 @@ package org.eclipse.hawkbit.repository.model; * Repository model constants. * */ -public final class Constants { +public final class RepositoryModelConstants { /** * indicating that target action has no force time which is only needed in @@ -20,7 +20,7 @@ public final class Constants { */ public static final Long NO_FORCE_TIME = 0L; - private Constants() { + private RepositoryModelConstants() { // Utility class. } diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Rollout.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Rollout.java index 5094c1af8..37185a8e2 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Rollout.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Rollout.java @@ -156,4 +156,4 @@ public interface Rollout extends NamedEntity { ERROR_STARTING; } -} \ No newline at end of file +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModule.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModule.java index cb01219f4..3c3a24fd0 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModule.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModule.java @@ -108,4 +108,4 @@ public interface SoftwareModule extends NamedVersionedEntity { */ List getAssignedTo(); -} \ No newline at end of file +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleMetadata.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleMetadata.java index bb0f877ce..ebfea9c28 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleMetadata.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleMetadata.java @@ -25,4 +25,4 @@ public interface SoftwareModuleMetadata extends MetaData { */ void setSoftwareModule(SoftwareModule softwareModule); -} \ No newline at end of file +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleType.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleType.java index 313525199..4bd52f3f0 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleType.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleType.java @@ -57,4 +57,4 @@ public interface SoftwareModuleType extends NamedEntity { */ void setColour(final String colour); -} \ No newline at end of file +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Tag.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Tag.java index e57763920..bfade80e8 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Tag.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Tag.java @@ -24,4 +24,4 @@ public interface Tag extends NamedEntity { */ void setColour(String colour); -} \ No newline at end of file +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetFilterQuery.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetFilterQuery.java index 9cc200d0d..5052a0060 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetFilterQuery.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetFilterQuery.java @@ -56,4 +56,4 @@ public interface TargetFilterQuery extends TenantAwareBaseEntity { */ void setQuery(String query); -} \ No newline at end of file +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetInfo.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetInfo.java index d2e96664c..6317f9783 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetInfo.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetInfo.java @@ -68,4 +68,4 @@ public interface TargetInfo extends Serializable { */ boolean isRequestControllerAttributes(); -} \ No newline at end of file +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetTag.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetTag.java index 585bf8c12..f222e9e90 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetTag.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetTag.java @@ -21,4 +21,4 @@ public interface TargetTag extends Tag { */ List getAssignedToTargets(); -} \ No newline at end of file +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetWithActionStatus.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetWithActionStatus.java index f775a3879..9193b47ef 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetWithActionStatus.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetWithActionStatus.java @@ -19,7 +19,7 @@ public class TargetWithActionStatus { private Target target; - private Status status = null; + private Status status; public TargetWithActionStatus(final Target target) { this.target = target; diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetWithActionType.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetWithActionType.java index c05f1ec3f..a9cfa81d1 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetWithActionType.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetWithActionType.java @@ -51,7 +51,7 @@ public class TargetWithActionType { if (actionType == ActionType.TIMEFORCED) { return forceTime; } - return Constants.NO_FORCE_TIME; + return RepositoryModelConstants.NO_FORCE_TIME; } /** diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TenantAwareBaseEntity.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TenantAwareBaseEntity.java index f79306d75..8c19db236 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TenantAwareBaseEntity.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TenantAwareBaseEntity.java @@ -19,4 +19,4 @@ public interface TenantAwareBaseEntity extends BaseEntity { */ String getTenant(); -} \ No newline at end of file +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TenantConfiguration.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TenantConfiguration.java index fa9962eec..fdbc5c8d3 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TenantConfiguration.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TenantConfiguration.java @@ -37,4 +37,4 @@ public interface TenantConfiguration extends TenantAwareBaseEntity { */ void setValue(String value); -} \ No newline at end of file +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TenantMetaData.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TenantMetaData.java index 23f81ae6f..0b40d9939 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TenantMetaData.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TenantMetaData.java @@ -31,4 +31,4 @@ public interface TenantMetaData extends BaseEntity { */ String getTenant(); -} \ No newline at end of file +} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java index 43b8534af..9fcd646b5 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java @@ -19,7 +19,7 @@ import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.Root; import javax.validation.constraints.NotNull; -import org.eclipse.hawkbit.repository.Constants; +import org.eclipse.hawkbit.repository.RepositoryConstants; import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; @@ -216,7 +216,7 @@ public class JpaControllerManagement implements ControllerManagement { handleFinishedCancelation(actionStatus, action); break; case RETRIEVED: - actionStatus.addMessage(Constants.SERVER_MESSAGE_PREFIX + "Cancellation request retrieved."); + actionStatus.addMessage(RepositoryConstants.SERVER_MESSAGE_PREFIX + "Cancellation request retrieved."); break; default: // do nothing @@ -230,7 +230,7 @@ public class JpaControllerManagement implements ControllerManagement { private void handleFinishedCancelation(final ActionStatus actionStatus, final JpaAction action) { // in case of successful cancellation we also report the success at // the canceled action itself. - actionStatus.addMessage(Constants.SERVER_MESSAGE_PREFIX + "Cancellation completion is finished sucessfully."); + actionStatus.addMessage(RepositoryConstants.SERVER_MESSAGE_PREFIX + "Cancellation completion is finished sucessfully."); DeploymentHelper.successCancellation(action, actionRepository, targetManagement, targetInfoRepository, entityManager); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java index cefa5e937..6f3a876b8 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java @@ -145,7 +145,7 @@ public class JpaDeploymentManagement implements DeploymentManagement { return assignDistributionSetByTargetId((JpaDistributionSet) pset, targets.stream().map(target -> target.getControllerId()).collect(Collectors.toList()), - ActionType.FORCED, org.eclipse.hawkbit.repository.model.Constants.NO_FORCE_TIME); + ActionType.FORCED, org.eclipse.hawkbit.repository.model.RepositoryModelConstants.NO_FORCE_TIME); } @@ -155,7 +155,7 @@ public class JpaDeploymentManagement implements DeploymentManagement { @CacheEvict(value = { "distributionUsageAssigned" }, allEntries = true) public DistributionSetAssignmentResult assignDistributionSet(final Long dsID, final String... targetIDs) { return assignDistributionSet(dsID, ActionType.FORCED, - org.eclipse.hawkbit.repository.model.Constants.NO_FORCE_TIME, targetIDs); + org.eclipse.hawkbit.repository.model.RepositoryModelConstants.NO_FORCE_TIME, targetIDs); } @Override diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/cache/CacheKeys.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/cache/CacheKeys.java index fdfe7a263..021a17a9d 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/cache/CacheKeys.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/cache/CacheKeys.java @@ -11,7 +11,7 @@ package org.eclipse.hawkbit.repository.jpa.cache; import org.eclipse.hawkbit.repository.jpa.model.CacheFieldEntityListener; /** - * Constants for cache keys used in multiple classes. + * RepositoryConstants for cache keys used in multiple classes. * * * diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DeploymentManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DeploymentManagementTest.java index 3d0114d67..565513107 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DeploymentManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DeploymentManagementTest.java @@ -842,7 +842,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { final DistributionSet ds = testdataFactory.createDistributionSet("a"); // assign ds to create an action final DistributionSetAssignmentResult assignDistributionSet = deploymentManagement.assignDistributionSet( - ds.getId(), ActionType.SOFT, org.eclipse.hawkbit.repository.model.Constants.NO_FORCE_TIME, + ds.getId(), ActionType.SOFT, org.eclipse.hawkbit.repository.model.RepositoryModelConstants.NO_FORCE_TIME, target.getControllerId()); final Action action = deploymentManagement.findActionWithDetails(assignDistributionSet.getActions().get(0)); // verify preparation @@ -865,7 +865,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { final DistributionSet ds = testdataFactory.createDistributionSet("a"); // assign ds to create an action final DistributionSetAssignmentResult assignDistributionSet = deploymentManagement.assignDistributionSet( - ds.getId(), ActionType.FORCED, org.eclipse.hawkbit.repository.model.Constants.NO_FORCE_TIME, + ds.getId(), ActionType.FORCED, org.eclipse.hawkbit.repository.model.RepositoryModelConstants.NO_FORCE_TIME, target.getControllerId()); final Action action = deploymentManagement.findActionWithDetails(assignDistributionSet.getActions().get(0)); // verify perparation diff --git a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/AbstractIntegrationTest.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/AbstractIntegrationTest.java index 29bf02fa0..f8c147c61 100644 --- a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/AbstractIntegrationTest.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/AbstractIntegrationTest.java @@ -10,7 +10,7 @@ package org.eclipse.hawkbit.repository.util; import org.eclipse.hawkbit.ExcludePathAwareShallowETagFilter; import org.eclipse.hawkbit.repository.ArtifactManagement; -import org.eclipse.hawkbit.repository.Constants; +import org.eclipse.hawkbit.repository.RepositoryConstants; import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement; @@ -72,7 +72,7 @@ public abstract class AbstractIntegrationTest implements EnvironmentAware { * {@link TestdataFactory#findOrCreateDefaultTestDsType()} and two * {@link SystemManagement#getTenantMetadata()}; */ - protected static final int DEFAULT_DS_TYPES = Constants.DEFAULT_DS_TYPES_IN_TENANT + 1; + protected static final int DEFAULT_DS_TYPES = RepositoryConstants.DEFAULT_DS_TYPES_IN_TENANT + 1; @Autowired protected EntityFactory entityFactory; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/ManangementConfirmationWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/ManangementConfirmationWindowLayout.java index fa8a41f07..db1be1ae5 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/ManangementConfirmationWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/ManangementConfirmationWindowLayout.java @@ -24,7 +24,7 @@ import org.eclipse.hawkbit.repository.DistributionSetAssignmentResult; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.model.Action.ActionType; -import org.eclipse.hawkbit.repository.model.Constants; +import org.eclipse.hawkbit.repository.model.RepositoryModelConstants; import org.eclipse.hawkbit.repository.model.TargetIdName; import org.eclipse.hawkbit.ui.common.DistributionSetIdName; import org.eclipse.hawkbit.ui.common.confirmwindow.layout.AbstractConfirmationWindowLayout; @@ -148,7 +148,7 @@ public class ManangementConfirmationWindowLayout extends AbstractConfirmationWin final long forcedTimeStamp = (((ActionTypeOptionGroupLayout.ActionTypeOption) actionTypeOptionGroupLayout .getActionTypeOptionGroup().getValue()) == ActionTypeOption.AUTO_FORCED) ? actionTypeOptionGroupLayout.getForcedTimeDateField().getValue().getTime() - : Constants.NO_FORCE_TIME; + : RepositoryModelConstants.NO_FORCE_TIME; final Map> saveAssignedList = new HashMap<>(); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java index c909c9c5d..5248a1836 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java @@ -17,7 +17,7 @@ import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.model.Action.ActionType; -import org.eclipse.hawkbit.repository.model.Constants; +import org.eclipse.hawkbit.repository.model.RepositoryModelConstants; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.Rollout.RolloutStatus; import org.eclipse.hawkbit.repository.model.RolloutGroup; @@ -465,7 +465,7 @@ public class AddUpdateRolloutWindowLayout extends CustomComponent { return (((ActionTypeOptionGroupLayout.ActionTypeOption) actionTypeOptionGroupLayout.getActionTypeOptionGroup() .getValue()) == ActionTypeOption.AUTO_FORCED) ? actionTypeOptionGroupLayout.getForcedTimeDateField().getValue().getTime() - : Constants.NO_FORCE_TIME; + : RepositoryModelConstants.NO_FORCE_TIME; } private ActionType getActionType() { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIButtonDefinitions.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIButtonDefinitions.java index 8ab9318cf..0b727ce2a 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIButtonDefinitions.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIButtonDefinitions.java @@ -9,7 +9,7 @@ package org.eclipse.hawkbit.ui.utils; /** - * Constants required for Button. + * RepositoryConstants required for Button. * * * diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUILabelDefinitions.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUILabelDefinitions.java index 937a53adc..5e6feceb2 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUILabelDefinitions.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUILabelDefinitions.java @@ -11,7 +11,7 @@ package org.eclipse.hawkbit.ui.utils; import com.vaadin.ui.themes.ValoTheme; /** - * Constants required for Label. + * RepositoryConstants required for Label. * * * diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIStyleDefinitions.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIStyleDefinitions.java index c50135251..f5f857d60 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIStyleDefinitions.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIStyleDefinitions.java @@ -9,7 +9,7 @@ package org.eclipse.hawkbit.ui.utils; /** - * Constants required for Style. + * RepositoryConstants required for Style. * * * diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUITargetDefinitions.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUITargetDefinitions.java index 2474fb36c..1fd17b9e6 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUITargetDefinitions.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUITargetDefinitions.java @@ -9,7 +9,7 @@ package org.eclipse.hawkbit.ui.utils; /** - * Constants required for Target. + * RepositoryConstants required for Target. * * * From c2cb42df618405a8085bd76ddbbb24356898c497 Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Tue, 31 May 2016 09:48:43 +0200 Subject: [PATCH 31/54] add javadoc Signed-off-by: Michael Hirsch --- .../repository/ArtifactManagement.java | 8 ++ .../repository/DeploymentManagement.java | 32 +++++- .../repository/model/RolloutGroup.java | 105 +++++++++++++++++- 3 files changed, 141 insertions(+), 4 deletions(-) diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ArtifactManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ArtifactManagement.java index ee73a1354..167b6019f 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ArtifactManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ArtifactManagement.java @@ -60,9 +60,17 @@ public interface ArtifactManagement { ExternalArtifact createExternalArtifact(@NotNull ExternalArtifactProvider externalRepository, String urlSuffix, @NotNull Long moduleId); + /** + * @return the total amount of local artifacts stored in the artifact + * management + */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) Long countLocalArtifactsAll(); + /** + * @return the total amount of external artifacts stored in the artifact + * management + */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) Long countExternalArtifactsAll(); diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java index 59518f854..1c2c71f8e 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java @@ -187,9 +187,15 @@ public interface DeploymentManagement { @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) Long countActionsByTarget(@NotNull String rsqlParam, @NotNull Target target); + /** + * @return the total amount of stored action status + */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) Long countActionStatusAll(); + /** + * @return the total amount of stored actions + */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) Long countActionsAll(); @@ -280,8 +286,20 @@ public interface DeploymentManagement { @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) Slice findActionsByTarget(@NotNull Pageable pageable, @NotNull Target target); + /** + * Retrieves all {@link Action} which assigned to a specific + * {@link DistributionSet}. + * + * @param pageable + * the page request parameter for paging and sorting the result + * @param distributionSet + * the distribution set which should be assigned to the actions + * in the result + * @return a list of {@link Action} which are assigned to a specific + * {@link DistributionSet} + */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - Slice findActionsByDistributionSet(@NotNull Pageable pageable, @NotNull DistributionSet ds); + Slice findActionsByDistributionSet(@NotNull Pageable pageable, @NotNull DistributionSet distributionSet); /** * Retrieves all {@link Action}s assigned to a specific {@link Target} and a @@ -345,8 +363,18 @@ public interface DeploymentManagement { @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) Page findActionStatusByAction(@NotNull Pageable pageReq, @NotNull Action action); + /** + * Retrieves all {@link ActionStatus} inclusive their messages by a specific + * {@link Action}. + * + * @param pageable + * the page request parameter for paging and sorting the result + * @param action + * the {@link Action} to retrieve the {@link ActionStatus} from + * @return a page of {@link ActionStatus} by a speciifc {@link Action} + */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) - Page findActionStatusByActionWithMessages(@NotNull Pageable pageReq, @NotNull Action action); + Page findActionStatusByActionWithMessages(@NotNull Pageable pageable, @NotNull Action action); /** * Retrieves all {@link Action}s of a specific target ordered by action ID. diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/RolloutGroup.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/RolloutGroup.java index e4d9f5bb7..3180fdb6a 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/RolloutGroup.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/RolloutGroup.java @@ -16,44 +16,145 @@ package org.eclipse.hawkbit.repository.model; */ public interface RolloutGroup extends NamedEntity { + /** + * @return the corresponding {@link Rollout} of this group + */ Rollout getRollout(); + /** + * @param rollout + * sets the {@link Rollout} for this group + */ void setRollout(Rollout rollout); + /** + * @return the current {@link RolloutGroupStatus} for this group + */ RolloutGroupStatus getStatus(); + /** + * @param status + * the {@link RolloutGroupStatus} to set for this group + */ void setStatus(RolloutGroupStatus status); + /** + * @return the parent group of this group, in case the group is the root + * group it does not have a parent and so return {@code null} + */ RolloutGroup getParent(); + /** + * @return the {@link RolloutGroupSuccessCondition} for this group to + * indicate when a group is successful + */ RolloutGroupSuccessCondition getSuccessCondition(); - void setSuccessCondition(RolloutGroupSuccessCondition finishCondition); + /** + * @param successCondition + * the {@link RolloutGroupSuccessCondition} to be set for this + * group to indicate when a group is successfully and a next + * group might be started + */ + void setSuccessCondition(RolloutGroupSuccessCondition successCondition); + /** + * @return a String representation of the expression to be evaluated by the + * {@link RolloutGroupSuccessCondition} to indicate if the condition + * is true, might be {@code null} if no expression must be set for + * the {@link RolloutGroupSuccessCondition} + */ String getSuccessConditionExp(); - void setSuccessConditionExp(String finishExp); + /** + * @param successConditionExp + * sets a String represented expression which is evaluated by the + * {@link RolloutGroupSuccessCondition}, might be {@code null} if + * the set {@link RolloutGroupSuccessCondition} can handle + * {@code null} value + */ + void setSuccessConditionExp(String successConditionExp); + /** + * @return the {@link RolloutGroupErrorCondition} for this group to indicate + * when a group should marked as failed + */ RolloutGroupErrorCondition getErrorCondition(); + /** + * + * @param errorCondition + * the {@link RolloutGroupErrorCondition} to be set for this + * group to indicate when a group is marked as failed and the + * corresponding {@link RolloutGroupErrorAction} should be + * executed + */ void setErrorCondition(RolloutGroupErrorCondition errorCondition); + /** + * @return a String representation of the expression to be evaluated by the + * {@link RolloutGroupErrorCondition} to indicate if the condition + * is true, might be {@code null} if no expression must be set for + * the {@link RolloutGroupErrorCondition} + */ String getErrorConditionExp(); + /** + * @param errorExp + * sets a String represented expression which is evaluated by the + * {@link RolloutGroupErrorCondition}, might be {@code null} if + * the set {@link RolloutGroupErrorCondition} can handle + * {@code null} value + */ void setErrorConditionExp(String errorExp); + /** + * @return a {@link RolloutGroupErrorAction} which is executed when the + * given {@link RolloutGroupErrorCondition} is met, might be + * {@code null} if no error action is set + */ RolloutGroupErrorAction getErrorAction(); + /** + * @param errorAction + * the {@link RolloutGroupErrorAction} to be set which should be + * executed if the {@link RolloutGroupErrorCondition} is met, + * might be {@code null} if no error action should be executed + */ void setErrorAction(RolloutGroupErrorAction errorAction); + /** + * @return a String representation of the expression to be evaluated by the + * {@link RolloutGroupErrorAction} might be {@code null} if no + * expression must be set for the {@link RolloutGroupErrorAction} + */ String getErrorActionExp(); + /** + * @param errorActionExp + * sets a String represented expression which is evaluated by the + * {@link RolloutGroupErrorAction}, might be {@code null} if the + * set {@link RolloutGroupErrorAction} can handle {@code null} + * value + */ void setErrorActionExp(String errorActionExp); + /** + * @return the {@link RolloutGroupSuccessAction} which is executed if the + * {@link RolloutGroupSuccessCondition} is met + */ RolloutGroupSuccessAction getSuccessAction(); + /** + * @return a String representation of the expression to be evaluated by the + * {@link RolloutGroupSuccessAction} might be {@code null} if no + * expression must be set for the {@link RolloutGroupSuccessAction} + */ String getSuccessActionExp(); + /** + * @return the total amount of targets containing in this group + */ long getTotalTargets(); /** From 14cb962f4212652a4d936ad848169778ef528750 Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Tue, 31 May 2016 10:38:38 +0200 Subject: [PATCH 32/54] fix sonar rule don't use generic wildcard Signed-off-by: Michael Hirsch --- .../hawkbit/repository/TenantConfigurationManagement.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TenantConfigurationManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TenantConfigurationManagement.java index 9937084eb..734704f05 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TenantConfigurationManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TenantConfigurationManagement.java @@ -89,7 +89,7 @@ public interface TenantConfigurationManagement { */ @PreAuthorize(value = SpringEvalExpressions.HAS_AUTH_TENANT_CONFIGURATION + SpringEvalExpressions.HAS_AUTH_OR + SpringEvalExpressions.IS_SYSTEM_CODE) - TenantConfigurationValue getConfigurationValue(TenantConfigurationKey configurationKey); + TenantConfigurationValue getConfigurationValue(TenantConfigurationKey configurationKey); /** * Retrieves a configuration value from the e.g. tenant overwritten From b14d3bbd3c0afe67700c3b1024f1443a82ec3ca3 Mon Sep 17 00:00:00 2001 From: SirWayne Date: Tue, 31 May 2016 10:48:56 +0200 Subject: [PATCH 33/54] Small fixes Signed-off-by: SirWayne --- .../resource/DdiArtifactStoreController.java | 6 +++--- .../ddi/rest/resource/DdiRootController.java | 20 +++++++++---------- .../rest/resource/DdiDeploymentBaseTest.java | 6 +++--- .../amqp/AmqpMessageDispatcherService.java | 10 +++------- ...onstants.java => RepositoryConstants.java} | 4 ++-- .../hawkbit/repository/SystemManagement.java | 2 +- .../hawkbit/repository/TargetManagement.java | 2 +- .../model/ActionWithStatusCount.java | 2 +- .../hawkbit/repository/model/Artifact.java | 2 +- .../hawkbit/repository/model/BaseEntity.java | 2 +- .../repository/model/DistributionSet.java | 2 +- .../model/DistributionSetMetadata.java | 2 +- .../repository/model/DistributionSetTag.java | 2 +- .../repository/model/DistributionSetType.java | 2 +- .../repository/model/ExternalArtifact.java | 2 +- .../hawkbit/repository/model/MetaData.java | 2 +- .../model/NamedVersionedEntity.java | 2 +- ...nts.java => RepositoryModelConstants.java} | 4 ++-- .../hawkbit/repository/model/Rollout.java | 2 +- .../repository/model/SoftwareModule.java | 2 +- .../model/SoftwareModuleMetadata.java | 2 +- .../repository/model/SoftwareModuleType.java | 2 +- .../eclipse/hawkbit/repository/model/Tag.java | 2 +- .../repository/model/TargetFilterQuery.java | 2 +- .../hawkbit/repository/model/TargetInfo.java | 2 +- .../hawkbit/repository/model/TargetTag.java | 2 +- .../model/TargetWithActionStatus.java | 2 +- .../model/TargetWithActionType.java | 2 +- .../model/TenantAwareBaseEntity.java | 2 +- .../repository/model/TenantConfiguration.java | 2 +- .../repository/model/TenantMetaData.java | 2 +- .../jpa/JpaControllerManagement.java | 6 +++--- .../jpa/JpaDeploymentManagement.java | 4 ++-- .../repository/jpa/cache/CacheKeys.java | 2 +- .../jpa/DeploymentManagementTest.java | 4 ++-- .../util/AbstractIntegrationTest.java | 4 ++-- .../ManangementConfirmationWindowLayout.java | 4 ++-- .../rollout/AddUpdateRolloutWindowLayout.java | 4 ++-- .../ui/utils/SPUIButtonDefinitions.java | 2 +- .../ui/utils/SPUILabelDefinitions.java | 2 +- .../ui/utils/SPUIStyleDefinitions.java | 2 +- .../ui/utils/SPUITargetDefinitions.java | 2 +- 42 files changed, 66 insertions(+), 70 deletions(-) rename hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/{Constants.java => RepositoryConstants.java} (92%) rename hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/{Constants.java => RepositoryModelConstants.java} (88%) diff --git a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java index 9d690f9d2..5bed44295 100644 --- a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java +++ b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java @@ -17,7 +17,7 @@ import javax.servlet.http.HttpServletRequest; import org.eclipse.hawkbit.artifact.repository.model.DbArtifact; import org.eclipse.hawkbit.ddi.dl.rest.api.DdiDlArtifactStoreControllerRestApi; import org.eclipse.hawkbit.repository.ArtifactManagement; -import org.eclipse.hawkbit.repository.Constants; +import org.eclipse.hawkbit.repository.RepositoryConstants; import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.jpa.cache.CacheWriteNotify; @@ -149,10 +149,10 @@ public class DdiArtifactStoreController implements DdiDlArtifactStoreControllerR actionStatus.setStatus(Status.DOWNLOAD); if (range != null) { - actionStatus.addMessage(Constants.SERVER_MESSAGE_PREFIX + "Target downloads range " + range + " of: " + actionStatus.addMessage(RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target downloads range " + range + " of: " + request.getRequestURI()); } else { - actionStatus.addMessage(Constants.SERVER_MESSAGE_PREFIX + "Target downloads: " + request.getRequestURI()); + actionStatus.addMessage(RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target downloads: " + request.getRequestURI()); } controllerManagement.addInformationalActionStatus(actionStatus); return action; diff --git a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java index 656835e95..0c6fa4386 100644 --- a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java +++ b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java @@ -29,7 +29,7 @@ import org.eclipse.hawkbit.ddi.json.model.DdiDeploymentBase; import org.eclipse.hawkbit.ddi.json.model.DdiResult.FinalResult; import org.eclipse.hawkbit.ddi.rest.api.DdiRootControllerRestApi; import org.eclipse.hawkbit.repository.ArtifactManagement; -import org.eclipse.hawkbit.repository.Constants; +import org.eclipse.hawkbit.repository.RepositoryConstants; import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.SoftwareManagement; @@ -185,10 +185,10 @@ public class DdiRootController implements DdiRootControllerRestApi { statusMessage.setStatus(Status.DOWNLOAD); if (range != null) { - statusMessage.addMessage(Constants.SERVER_MESSAGE_PREFIX + "Target downloads range " + range + " of: " + statusMessage.addMessage(RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target downloads range " + range + " of: " + request.getRequestURI()); } else { - statusMessage.addMessage(Constants.SERVER_MESSAGE_PREFIX + "Target downloads " + request.getRequestURI()); + statusMessage.addMessage(RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target downloads " + request.getRequestURI()); } controllerManagement.addInformationalActionStatus(statusMessage); return action; @@ -251,7 +251,7 @@ public class DdiRootController implements DdiRootControllerRestApi { LOG.debug("Found an active UpdateAction for target {}. returning deyploment: {}", targetid, base); - controllerManagement.registerRetrieved(action, Constants.SERVER_MESSAGE_PREFIX + controllerManagement.registerRetrieved(action, RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target retrieved update action and should start now the download."); return new ResponseEntity<>(base, HttpStatus.OK); @@ -306,13 +306,13 @@ public class DdiRootController implements DdiRootControllerRestApi { LOG.debug("Controller confirmed cancel (actionid: {}, targetid: {}) as we got {} report.", actionid, targetid, feedback.getStatus().getExecution()); actionStatus.setStatus(Status.CANCELED); - actionStatus.addMessage(Constants.SERVER_MESSAGE_PREFIX + "Target confirmed cancelation."); + actionStatus.addMessage(RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target confirmed cancelation."); break; case REJECTED: LOG.info("Controller reported internal error (actionid: {}, targetid: {}) as we got {} report.", actionid, targetid, feedback.getStatus().getExecution()); actionStatus.setStatus(Status.WARNING); - actionStatus.addMessage(Constants.SERVER_MESSAGE_PREFIX + "Target REJECTED update."); + actionStatus.addMessage(RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target REJECTED update."); break; case CLOSED: handleClosedUpdateStatus(feedback, targetid, actionid, actionStatus); @@ -340,7 +340,7 @@ public class DdiRootController implements DdiRootControllerRestApi { targetid, feedback.getStatus().getExecution()); actionStatus.setStatus(Status.RUNNING); actionStatus - .addMessage(Constants.SERVER_MESSAGE_PREFIX + "Target reported " + feedback.getStatus().getExecution()); + .addMessage(RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target reported " + feedback.getStatus().getExecution()); } private static void handleClosedUpdateStatus(final DdiActionFeedback feedback, final String targetid, @@ -349,10 +349,10 @@ public class DdiRootController implements DdiRootControllerRestApi { feedback.getStatus().getExecution()); if (feedback.getStatus().getResult().getFinished() == FinalResult.FAILURE) { actionStatus.setStatus(Status.ERROR); - actionStatus.addMessage(Constants.SERVER_MESSAGE_PREFIX + "Target reported CLOSED with ERROR!"); + actionStatus.addMessage(RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target reported CLOSED with ERROR!"); } else { actionStatus.setStatus(Status.FINISHED); - actionStatus.addMessage(Constants.SERVER_MESSAGE_PREFIX + "Target reported CLOSED with OK!"); + actionStatus.addMessage(RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target reported CLOSED with OK!"); } } @@ -390,7 +390,7 @@ public class DdiRootController implements DdiRootControllerRestApi { LOG.debug("Found an active CancelAction for target {}. returning cancel: {}", targetid, cancel); - controllerManagement.registerRetrieved(action, Constants.SERVER_MESSAGE_PREFIX + controllerManagement.registerRetrieved(action, RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target retrieved cancel action and should start now the cancelation."); return new ResponseEntity<>(cancel, HttpStatus.OK); diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java index 124d8e38d..33d470b3d 100644 --- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java +++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java @@ -29,7 +29,7 @@ import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.ActionType; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; -import org.eclipse.hawkbit.repository.model.Constants; +import org.eclipse.hawkbit.repository.model.RepositoryModelConstants; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.Target; @@ -113,7 +113,7 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(0); List saved = deploymentManagement.assignDistributionSet(ds.getId(), ActionType.FORCED, - Constants.NO_FORCE_TIME, savedTarget.getControllerId()).getAssignedEntity(); + RepositoryModelConstants.NO_FORCE_TIME, savedTarget.getControllerId()).getAssignedEntity(); assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(1); final Action action = deploymentManagement.findActiveActionsByTarget(savedTarget).get(0); @@ -250,7 +250,7 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(0); List saved = deploymentManagement.assignDistributionSet(ds.getId(), ActionType.SOFT, - Constants.NO_FORCE_TIME, savedTarget.getControllerId()).getAssignedEntity(); + RepositoryModelConstants.NO_FORCE_TIME, savedTarget.getControllerId()).getAssignedEntity(); assertThat(deploymentManagement.findActiveActionsByTarget(savedTarget)).hasSize(1); final Action action = deploymentManagement.findActiveActionsByTarget(savedTarget).get(0); diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java index 3b05c96a6..b643be322 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java +++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java @@ -25,7 +25,6 @@ import org.eclipse.hawkbit.dmf.json.model.DownloadAndUpdateRequest; import org.eclipse.hawkbit.dmf.json.model.SoftwareModule; import org.eclipse.hawkbit.eventbus.EventSubscriber; import org.eclipse.hawkbit.eventbus.event.CancelTargetAssignmentEvent; -import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.eventbus.event.TargetAssignDistributionSetEvent; import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.util.IpUtil; @@ -53,14 +52,11 @@ public class AmqpMessageDispatcherService extends BaseAmqpService { @Autowired private AmqpSenderService amqpSenderService; - @Autowired - private SoftwareManagement softwareManagement; - /** * Constructor. * - * @param messageConverter - * message converter + * @param rabbitTemplate + * the rabbitTemplate */ @Autowired public AmqpMessageDispatcherService(final RabbitTemplate rabbitTemplate) { @@ -118,7 +114,7 @@ public class AmqpMessageDispatcherService extends BaseAmqpService { } - private MessageProperties createConnectorMessageProperties(final String tenant, final String controllerId, + private static MessageProperties createConnectorMessageProperties(final String tenant, final String controllerId, final EventTopic topic) { final MessageProperties messageProperties = createMessageProperties(); messageProperties.setHeader(MessageHeaderKey.TOPIC, topic); diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/Constants.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RepositoryConstants.java similarity index 92% rename from hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/Constants.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RepositoryConstants.java index fcfd6ab5e..f2cd3f9f6 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/Constants.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RepositoryConstants.java @@ -15,7 +15,7 @@ import org.eclipse.hawkbit.repository.model.DistributionSetType; * Repository constants. * */ -public final class Constants { +public final class RepositoryConstants { /** * Prefix that the server puts in front of @@ -30,7 +30,7 @@ public final class Constants { */ public static final int DEFAULT_DS_TYPES_IN_TENANT = 2; - private Constants() { + private RepositoryConstants() { // Utility class. } diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java index 5cc17e09b..8ee3b7600 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java @@ -74,7 +74,7 @@ public interface SystemManagement { /** * Returns {@link TenantMetaData} of given and current tenant. Creates for * new tenants also two {@link SoftwareModuleType} (os and app) and - * {@link Constants#DEFAULT_DS_TYPES_IN_TENANT} {@link DistributionSetType}s + * {@link RepositoryConstants#DEFAULT_DS_TYPES_IN_TENANT} {@link DistributionSetType}s * (os and os_app). * * DISCLAIMER: this variant is used during initial login (where the tenant diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java index 9280e065d..ee10883ec 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java @@ -601,4 +601,4 @@ public interface TargetManagement { + SpringEvalExpressions.IS_CONTROLLER) List updateTargets(@NotNull Collection targets); -} \ No newline at end of file +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/ActionWithStatusCount.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/ActionWithStatusCount.java index c497783e2..268c37853 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/ActionWithStatusCount.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/ActionWithStatusCount.java @@ -45,4 +45,4 @@ public interface ActionWithStatusCount { */ String getRolloutName(); -} \ No newline at end of file +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Artifact.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Artifact.java index 95689a9d9..cc726839d 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Artifact.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Artifact.java @@ -39,4 +39,4 @@ public interface Artifact extends TenantAwareBaseEntity { */ Long getSize(); -} \ No newline at end of file +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/BaseEntity.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/BaseEntity.java index f23b226c6..2a9948bc5 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/BaseEntity.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/BaseEntity.java @@ -46,4 +46,4 @@ public interface BaseEntity extends Serializable, Identifiable { */ long getOptLockRevision(); -} \ No newline at end of file +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSet.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSet.java index c6532b339..5747b38f3 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSet.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSet.java @@ -129,4 +129,4 @@ public interface DistributionSet extends NamedVersionedEntity { */ boolean isComplete(); -} \ No newline at end of file +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetMetadata.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetMetadata.java index dfa9b9716..87a62e9ba 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetMetadata.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetMetadata.java @@ -19,4 +19,4 @@ public interface DistributionSetMetadata extends MetaData { */ DistributionSet getDistributionSet(); -} \ No newline at end of file +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTag.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTag.java index 31f909348..05089d138 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTag.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTag.java @@ -22,4 +22,4 @@ public interface DistributionSetTag extends Tag { */ List getAssignedToDistributionSet(); -} \ No newline at end of file +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetType.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetType.java index 5546a9f6d..cf5da40b2 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetType.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetType.java @@ -170,4 +170,4 @@ public interface DistributionSetType extends NamedEntity { */ void setColour(final String colour); -} \ No newline at end of file +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifact.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifact.java index 4ff3ab5a8..7e1a965e7 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifact.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifact.java @@ -38,4 +38,4 @@ public interface ExternalArtifact extends Artifact { */ void setUrlSuffix(String urlSuffix); -} \ No newline at end of file +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/MetaData.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/MetaData.java index 4f3397b23..68b7349f9 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/MetaData.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/MetaData.java @@ -36,4 +36,4 @@ public interface MetaData extends Serializable { */ void setValue(String value); -} \ No newline at end of file +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/NamedVersionedEntity.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/NamedVersionedEntity.java index de6cded12..b66115082 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/NamedVersionedEntity.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/NamedVersionedEntity.java @@ -25,4 +25,4 @@ public interface NamedVersionedEntity extends NamedEntity { */ void setVersion(String version); -} \ No newline at end of file +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Constants.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/RepositoryModelConstants.java similarity index 88% rename from hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Constants.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/RepositoryModelConstants.java index b43ec6f88..66806915a 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Constants.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/RepositoryModelConstants.java @@ -12,7 +12,7 @@ package org.eclipse.hawkbit.repository.model; * Repository model constants. * */ -public final class Constants { +public final class RepositoryModelConstants { /** * indicating that target action has no force time which is only needed in @@ -20,7 +20,7 @@ public final class Constants { */ public static final Long NO_FORCE_TIME = 0L; - private Constants() { + private RepositoryModelConstants() { // Utility class. } diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Rollout.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Rollout.java index 5094c1af8..37185a8e2 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Rollout.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Rollout.java @@ -156,4 +156,4 @@ public interface Rollout extends NamedEntity { ERROR_STARTING; } -} \ No newline at end of file +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModule.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModule.java index cb01219f4..3c3a24fd0 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModule.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModule.java @@ -108,4 +108,4 @@ public interface SoftwareModule extends NamedVersionedEntity { */ List getAssignedTo(); -} \ No newline at end of file +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleMetadata.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleMetadata.java index bb0f877ce..ebfea9c28 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleMetadata.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleMetadata.java @@ -25,4 +25,4 @@ public interface SoftwareModuleMetadata extends MetaData { */ void setSoftwareModule(SoftwareModule softwareModule); -} \ No newline at end of file +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleType.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleType.java index 313525199..4bd52f3f0 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleType.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModuleType.java @@ -57,4 +57,4 @@ public interface SoftwareModuleType extends NamedEntity { */ void setColour(final String colour); -} \ No newline at end of file +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Tag.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Tag.java index e57763920..bfade80e8 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Tag.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Tag.java @@ -24,4 +24,4 @@ public interface Tag extends NamedEntity { */ void setColour(String colour); -} \ No newline at end of file +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetFilterQuery.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetFilterQuery.java index 9cc200d0d..5052a0060 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetFilterQuery.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetFilterQuery.java @@ -56,4 +56,4 @@ public interface TargetFilterQuery extends TenantAwareBaseEntity { */ void setQuery(String query); -} \ No newline at end of file +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetInfo.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetInfo.java index d2e96664c..6317f9783 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetInfo.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetInfo.java @@ -68,4 +68,4 @@ public interface TargetInfo extends Serializable { */ boolean isRequestControllerAttributes(); -} \ No newline at end of file +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetTag.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetTag.java index 585bf8c12..f222e9e90 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetTag.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetTag.java @@ -21,4 +21,4 @@ public interface TargetTag extends Tag { */ List getAssignedToTargets(); -} \ No newline at end of file +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetWithActionStatus.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetWithActionStatus.java index f775a3879..9193b47ef 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetWithActionStatus.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetWithActionStatus.java @@ -19,7 +19,7 @@ public class TargetWithActionStatus { private Target target; - private Status status = null; + private Status status; public TargetWithActionStatus(final Target target) { this.target = target; diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetWithActionType.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetWithActionType.java index c05f1ec3f..a9cfa81d1 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetWithActionType.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TargetWithActionType.java @@ -51,7 +51,7 @@ public class TargetWithActionType { if (actionType == ActionType.TIMEFORCED) { return forceTime; } - return Constants.NO_FORCE_TIME; + return RepositoryModelConstants.NO_FORCE_TIME; } /** diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TenantAwareBaseEntity.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TenantAwareBaseEntity.java index f79306d75..8c19db236 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TenantAwareBaseEntity.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TenantAwareBaseEntity.java @@ -19,4 +19,4 @@ public interface TenantAwareBaseEntity extends BaseEntity { */ String getTenant(); -} \ No newline at end of file +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TenantConfiguration.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TenantConfiguration.java index fa9962eec..fdbc5c8d3 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TenantConfiguration.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TenantConfiguration.java @@ -37,4 +37,4 @@ public interface TenantConfiguration extends TenantAwareBaseEntity { */ void setValue(String value); -} \ No newline at end of file +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TenantMetaData.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TenantMetaData.java index 23f81ae6f..0b40d9939 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TenantMetaData.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TenantMetaData.java @@ -31,4 +31,4 @@ public interface TenantMetaData extends BaseEntity { */ String getTenant(); -} \ No newline at end of file +} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java index 43b8534af..9fcd646b5 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java @@ -19,7 +19,7 @@ import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.Root; import javax.validation.constraints.NotNull; -import org.eclipse.hawkbit.repository.Constants; +import org.eclipse.hawkbit.repository.RepositoryConstants; import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; @@ -216,7 +216,7 @@ public class JpaControllerManagement implements ControllerManagement { handleFinishedCancelation(actionStatus, action); break; case RETRIEVED: - actionStatus.addMessage(Constants.SERVER_MESSAGE_PREFIX + "Cancellation request retrieved."); + actionStatus.addMessage(RepositoryConstants.SERVER_MESSAGE_PREFIX + "Cancellation request retrieved."); break; default: // do nothing @@ -230,7 +230,7 @@ public class JpaControllerManagement implements ControllerManagement { private void handleFinishedCancelation(final ActionStatus actionStatus, final JpaAction action) { // in case of successful cancellation we also report the success at // the canceled action itself. - actionStatus.addMessage(Constants.SERVER_MESSAGE_PREFIX + "Cancellation completion is finished sucessfully."); + actionStatus.addMessage(RepositoryConstants.SERVER_MESSAGE_PREFIX + "Cancellation completion is finished sucessfully."); DeploymentHelper.successCancellation(action, actionRepository, targetManagement, targetInfoRepository, entityManager); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java index cefa5e937..6f3a876b8 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java @@ -145,7 +145,7 @@ public class JpaDeploymentManagement implements DeploymentManagement { return assignDistributionSetByTargetId((JpaDistributionSet) pset, targets.stream().map(target -> target.getControllerId()).collect(Collectors.toList()), - ActionType.FORCED, org.eclipse.hawkbit.repository.model.Constants.NO_FORCE_TIME); + ActionType.FORCED, org.eclipse.hawkbit.repository.model.RepositoryModelConstants.NO_FORCE_TIME); } @@ -155,7 +155,7 @@ public class JpaDeploymentManagement implements DeploymentManagement { @CacheEvict(value = { "distributionUsageAssigned" }, allEntries = true) public DistributionSetAssignmentResult assignDistributionSet(final Long dsID, final String... targetIDs) { return assignDistributionSet(dsID, ActionType.FORCED, - org.eclipse.hawkbit.repository.model.Constants.NO_FORCE_TIME, targetIDs); + org.eclipse.hawkbit.repository.model.RepositoryModelConstants.NO_FORCE_TIME, targetIDs); } @Override diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/cache/CacheKeys.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/cache/CacheKeys.java index fdfe7a263..021a17a9d 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/cache/CacheKeys.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/cache/CacheKeys.java @@ -11,7 +11,7 @@ package org.eclipse.hawkbit.repository.jpa.cache; import org.eclipse.hawkbit.repository.jpa.model.CacheFieldEntityListener; /** - * Constants for cache keys used in multiple classes. + * RepositoryConstants for cache keys used in multiple classes. * * * diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DeploymentManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DeploymentManagementTest.java index 3d0114d67..565513107 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DeploymentManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DeploymentManagementTest.java @@ -842,7 +842,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { final DistributionSet ds = testdataFactory.createDistributionSet("a"); // assign ds to create an action final DistributionSetAssignmentResult assignDistributionSet = deploymentManagement.assignDistributionSet( - ds.getId(), ActionType.SOFT, org.eclipse.hawkbit.repository.model.Constants.NO_FORCE_TIME, + ds.getId(), ActionType.SOFT, org.eclipse.hawkbit.repository.model.RepositoryModelConstants.NO_FORCE_TIME, target.getControllerId()); final Action action = deploymentManagement.findActionWithDetails(assignDistributionSet.getActions().get(0)); // verify preparation @@ -865,7 +865,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { final DistributionSet ds = testdataFactory.createDistributionSet("a"); // assign ds to create an action final DistributionSetAssignmentResult assignDistributionSet = deploymentManagement.assignDistributionSet( - ds.getId(), ActionType.FORCED, org.eclipse.hawkbit.repository.model.Constants.NO_FORCE_TIME, + ds.getId(), ActionType.FORCED, org.eclipse.hawkbit.repository.model.RepositoryModelConstants.NO_FORCE_TIME, target.getControllerId()); final Action action = deploymentManagement.findActionWithDetails(assignDistributionSet.getActions().get(0)); // verify perparation diff --git a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/AbstractIntegrationTest.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/AbstractIntegrationTest.java index 29bf02fa0..f8c147c61 100644 --- a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/AbstractIntegrationTest.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/AbstractIntegrationTest.java @@ -10,7 +10,7 @@ package org.eclipse.hawkbit.repository.util; import org.eclipse.hawkbit.ExcludePathAwareShallowETagFilter; import org.eclipse.hawkbit.repository.ArtifactManagement; -import org.eclipse.hawkbit.repository.Constants; +import org.eclipse.hawkbit.repository.RepositoryConstants; import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement; @@ -72,7 +72,7 @@ public abstract class AbstractIntegrationTest implements EnvironmentAware { * {@link TestdataFactory#findOrCreateDefaultTestDsType()} and two * {@link SystemManagement#getTenantMetadata()}; */ - protected static final int DEFAULT_DS_TYPES = Constants.DEFAULT_DS_TYPES_IN_TENANT + 1; + protected static final int DEFAULT_DS_TYPES = RepositoryConstants.DEFAULT_DS_TYPES_IN_TENANT + 1; @Autowired protected EntityFactory entityFactory; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/ManangementConfirmationWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/ManangementConfirmationWindowLayout.java index fa8a41f07..db1be1ae5 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/ManangementConfirmationWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/ManangementConfirmationWindowLayout.java @@ -24,7 +24,7 @@ import org.eclipse.hawkbit.repository.DistributionSetAssignmentResult; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.model.Action.ActionType; -import org.eclipse.hawkbit.repository.model.Constants; +import org.eclipse.hawkbit.repository.model.RepositoryModelConstants; import org.eclipse.hawkbit.repository.model.TargetIdName; import org.eclipse.hawkbit.ui.common.DistributionSetIdName; import org.eclipse.hawkbit.ui.common.confirmwindow.layout.AbstractConfirmationWindowLayout; @@ -148,7 +148,7 @@ public class ManangementConfirmationWindowLayout extends AbstractConfirmationWin final long forcedTimeStamp = (((ActionTypeOptionGroupLayout.ActionTypeOption) actionTypeOptionGroupLayout .getActionTypeOptionGroup().getValue()) == ActionTypeOption.AUTO_FORCED) ? actionTypeOptionGroupLayout.getForcedTimeDateField().getValue().getTime() - : Constants.NO_FORCE_TIME; + : RepositoryModelConstants.NO_FORCE_TIME; final Map> saveAssignedList = new HashMap<>(); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java index c909c9c5d..5248a1836 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/AddUpdateRolloutWindowLayout.java @@ -17,7 +17,7 @@ import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.model.Action.ActionType; -import org.eclipse.hawkbit.repository.model.Constants; +import org.eclipse.hawkbit.repository.model.RepositoryModelConstants; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.Rollout.RolloutStatus; import org.eclipse.hawkbit.repository.model.RolloutGroup; @@ -465,7 +465,7 @@ public class AddUpdateRolloutWindowLayout extends CustomComponent { return (((ActionTypeOptionGroupLayout.ActionTypeOption) actionTypeOptionGroupLayout.getActionTypeOptionGroup() .getValue()) == ActionTypeOption.AUTO_FORCED) ? actionTypeOptionGroupLayout.getForcedTimeDateField().getValue().getTime() - : Constants.NO_FORCE_TIME; + : RepositoryModelConstants.NO_FORCE_TIME; } private ActionType getActionType() { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIButtonDefinitions.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIButtonDefinitions.java index 8ab9318cf..0b727ce2a 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIButtonDefinitions.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIButtonDefinitions.java @@ -9,7 +9,7 @@ package org.eclipse.hawkbit.ui.utils; /** - * Constants required for Button. + * RepositoryConstants required for Button. * * * diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUILabelDefinitions.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUILabelDefinitions.java index 937a53adc..5e6feceb2 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUILabelDefinitions.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUILabelDefinitions.java @@ -11,7 +11,7 @@ package org.eclipse.hawkbit.ui.utils; import com.vaadin.ui.themes.ValoTheme; /** - * Constants required for Label. + * RepositoryConstants required for Label. * * * diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIStyleDefinitions.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIStyleDefinitions.java index c50135251..f5f857d60 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIStyleDefinitions.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIStyleDefinitions.java @@ -9,7 +9,7 @@ package org.eclipse.hawkbit.ui.utils; /** - * Constants required for Style. + * RepositoryConstants required for Style. * * * diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUITargetDefinitions.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUITargetDefinitions.java index 2474fb36c..1fd17b9e6 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUITargetDefinitions.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUITargetDefinitions.java @@ -9,7 +9,7 @@ package org.eclipse.hawkbit.ui.utils; /** - * Constants required for Target. + * RepositoryConstants required for Target. * * * From 62a2e2cdb498e5dd970eb8c2a8ea5db6eab6f353 Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Tue, 31 May 2016 10:49:03 +0200 Subject: [PATCH 34/54] introduce own interfaces for registering the currentTenantKeyGenerator Signed-off-by: Michael Hirsch --- .../hawkbit/repository/SystemManagement.java | 6 --- .../jpa/CurrentTenantCacheKeyGenerator.java | 40 +++++++++++++++++++ .../repository/jpa/JpaSystemManagement.java | 2 +- 3 files changed, 41 insertions(+), 7 deletions(-) create mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/CurrentTenantCacheKeyGenerator.java diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java index 8ee3b7600..039e4ae13 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java @@ -18,8 +18,6 @@ import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.repository.model.TenantMetaData; import org.eclipse.hawkbit.repository.report.model.SystemUsageReport; import org.eclipse.hawkbit.tenancy.TenantAware; -import org.springframework.cache.interceptor.KeyGenerator; -import org.springframework.context.annotation.Bean; import org.springframework.security.access.prepost.PreAuthorize; /** @@ -67,10 +65,6 @@ public interface SystemManagement { */ TenantMetaData getTenantMetadata(); - // TODO figure out why this is necessary and clean this up - @Bean - KeyGenerator currentTenantKeyGenerator(); - /** * Returns {@link TenantMetaData} of given and current tenant. Creates for * new tenants also two {@link SoftwareModuleType} (os and app) and diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/CurrentTenantCacheKeyGenerator.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/CurrentTenantCacheKeyGenerator.java new file mode 100644 index 000000000..029246d2d --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/CurrentTenantCacheKeyGenerator.java @@ -0,0 +1,40 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.jpa; + +import org.springframework.cache.interceptor.KeyGenerator; +import org.springframework.context.annotation.Bean; +import org.springframework.stereotype.Service; + +/** + * Defines the interfaces to register the {@link KeyGenerator} as bean which is + * used by spring caching framework to resolve the key-generator. The + * key-generator must registered as bean so spring can resolve the key-generator + * by its name. + * + * When using the {@link Service} annotation e.g. by {@link JpaSystemManagement} + * the bean registration must be declared by the interface due spring registers + * the bean by the implemented interfaces. So introduce a single interface for + * the {@link JpaSystemManagement} implementation to allow it to register the + * key-generator bean. + * + */ +@FunctionalInterface +public interface CurrentTenantCacheKeyGenerator { + + /** + * Bean declaration to register a {@code currentTenantKeyGenerator} bean + * which is used by the caching framework. + * + * @return the {@link KeyGenerator} to be used to cache the values of the + * current used tenant in the {@link JpaSystemManagement} + */ + @Bean + KeyGenerator currentTenantKeyGenerator(); +} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java index be46362a5..8f9e8c5f9 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java @@ -49,7 +49,7 @@ import org.springframework.validation.annotation.Validated; @Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) @Validated @Service -public class JpaSystemManagement implements SystemManagement { +public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, SystemManagement { @Autowired private EntityManager entityManager; From f1e3406b978c9165089fffddf4c66c8938664361 Mon Sep 17 00:00:00 2001 From: SirWayne Date: Tue, 31 May 2016 10:56:10 +0200 Subject: [PATCH 35/54] Move jackson dependendy from repo to rest-core Signed-off-by: SirWayne --- .../hawkbit-repository-jpa/pom.xml | 18 ++++-------------- hawkbit-rest-core/pom.xml | 8 ++++++++ 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/hawkbit-repository/hawkbit-repository-jpa/pom.xml b/hawkbit-repository/hawkbit-repository-jpa/pom.xml index 49a19530f..0a5f65957 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/pom.xml +++ b/hawkbit-repository/hawkbit-repository-jpa/pom.xml @@ -36,16 +36,6 @@ - - - com.fasterxml.jackson.core - jackson-core - - - com.fasterxml.jackson.core - jackson-databind - - org.eclipse.hawkbit @@ -95,6 +85,10 @@ spring-boot-configuration-processor true + + cz.jirutka.rsql + rsql-parser + @@ -158,10 +152,6 @@ spring-security-web test - - cz.jirutka.rsql - rsql-parser - diff --git a/hawkbit-rest-core/pom.xml b/hawkbit-rest-core/pom.xml index 0b5f39272..1a74f4b3e 100644 --- a/hawkbit-rest-core/pom.xml +++ b/hawkbit-rest-core/pom.xml @@ -32,6 +32,14 @@ ${project.version} + + com.fasterxml.jackson.core + jackson-core + + + com.fasterxml.jackson.core + jackson-databind + javax.servlet javax.servlet-api From 252f409912ba1835d7ee5208fb27925fb203e84a Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Tue, 31 May 2016 11:01:04 +0200 Subject: [PATCH 36/54] fix generic wildcard Signed-off-by: Michael Hirsch --- .../configuration/TenantConfigurationKey.java | 38 ++++++------------- .../jpa/JpaTenantConfigurationManagement.java | 3 +- 2 files changed, 14 insertions(+), 27 deletions(-) diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/tenancy/configuration/TenantConfigurationKey.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/tenancy/configuration/TenantConfigurationKey.java index 402185be3..d68e963be 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/tenancy/configuration/TenantConfigurationKey.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/tenancy/configuration/TenantConfigurationKey.java @@ -30,60 +30,45 @@ public enum TenantConfigurationKey { /** * boolean value {@code true} {@code false}. */ - AUTHENTICATION_MODE_HEADER_ENABLED("authentication.header.enabled", - "hawkbit.server.ddi.security.authentication.header.enabled", Boolean.class, Boolean.FALSE.toString(), - TenantConfigurationBooleanValidator.class), + AUTHENTICATION_MODE_HEADER_ENABLED("authentication.header.enabled", "hawkbit.server.ddi.security.authentication.header.enabled", Boolean.class, Boolean.FALSE.toString(), TenantConfigurationBooleanValidator.class), /** * */ - AUTHENTICATION_MODE_HEADER_AUTHORITY_NAME("authentication.header.authority", - "hawkbit.server.ddi.security.authentication.header.authority", String.class, Boolean.FALSE.toString(), - TenantConfigurationStringValidator.class), + AUTHENTICATION_MODE_HEADER_AUTHORITY_NAME("authentication.header.authority", "hawkbit.server.ddi.security.authentication.header.authority", String.class, Boolean.FALSE.toString(), TenantConfigurationStringValidator.class), /** * boolean value {@code true} {@code false}. */ - AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED("authentication.targettoken.enabled", - "hawkbit.server.ddi.security.authentication.targettoken.enabled", Boolean.class, Boolean.FALSE.toString(), - TenantConfigurationBooleanValidator.class), + AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED("authentication.targettoken.enabled", "hawkbit.server.ddi.security.authentication.targettoken.enabled", Boolean.class, Boolean.FALSE.toString(), TenantConfigurationBooleanValidator.class), /** * boolean value {@code true} {@code false}. */ - AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_ENABLED("authentication.gatewaytoken.enabled", - "hawkbit.server.ddi.security.authentication.gatewaytoken.enabled", Boolean.class, Boolean.FALSE.toString(), - TenantConfigurationBooleanValidator.class), + AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_ENABLED("authentication.gatewaytoken.enabled", "hawkbit.server.ddi.security.authentication.gatewaytoken.enabled", Boolean.class, Boolean.FALSE.toString(), TenantConfigurationBooleanValidator.class), /** * string value which holds the name of the security token key. */ - AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_NAME("authentication.gatewaytoken.name", - "hawkbit.server.ddi.security.authentication.gatewaytoken.name", String.class, null, - TenantConfigurationStringValidator.class), + AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_NAME("authentication.gatewaytoken.name", "hawkbit.server.ddi.security.authentication.gatewaytoken.name", String.class, null, TenantConfigurationStringValidator.class), /** * string value which holds the actual security-key of the gateway security * token. */ - AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_KEY("authentication.gatewaytoken.key", - "hawkbit.server.ddi.security.authentication.gatewaytoken.key", String.class, null, - TenantConfigurationStringValidator.class), + AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_KEY("authentication.gatewaytoken.key", "hawkbit.server.ddi.security.authentication.gatewaytoken.key", String.class, null, TenantConfigurationStringValidator.class), /** * string value which holds the polling time interval in the format HH:mm:ss */ - POLLING_TIME_INTERVAL("pollingTime", "hawkbit.controller.pollingTime", String.class, null, - TenantConfigurationPollingDurationValidator.class), + POLLING_TIME_INTERVAL("pollingTime", "hawkbit.controller.pollingTime", String.class, null, TenantConfigurationPollingDurationValidator.class), /** * string value which holds the polling time interval in the format HH:mm:ss */ - POLLING_OVERDUE_TIME_INTERVAL("pollingOverdueTime", "hawkbit.controller.pollingOverdueTime", String.class, null, - TenantConfigurationPollingDurationValidator.class), + POLLING_OVERDUE_TIME_INTERVAL("pollingOverdueTime", "hawkbit.controller.pollingOverdueTime", String.class, null, TenantConfigurationPollingDurationValidator.class), /** * boolean value {@code true} {@code false}. */ - ANONYMOUS_DOWNLOAD_MODE_ENABLED("anonymous.download.enabled", "hawkbit.server.download.anonymous.enabled", - Boolean.class, Boolean.FALSE.toString(), TenantConfigurationBooleanValidator.class); + ANONYMOUS_DOWNLOAD_MODE_ENABLED("anonymous.download.enabled", "hawkbit.server.download.anonymous.enabled", Boolean.class, Boolean.FALSE.toString(), TenantConfigurationBooleanValidator.class); private final String keyName; private final String defaultKeyName; @@ -140,8 +125,9 @@ public enum TenantConfigurationKey { * @return the data type of the tenant configuration value. (e.g. * Integer.class, String.class) */ - public Class getDataType() { - return dataType; + @SuppressWarnings("unchecked") + public Class getDataType() { + return (Class) dataType; } /** diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTenantConfigurationManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTenantConfigurationManagement.java index ec5f3e843..9f65091a4 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTenantConfigurationManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTenantConfigurationManagement.java @@ -97,7 +97,7 @@ public class JpaTenantConfigurationManagement implements EnvironmentAware, Tenan } @Override - public TenantConfigurationValue getConfigurationValue(final TenantConfigurationKey configurationKey) { + public TenantConfigurationValue getConfigurationValue(final TenantConfigurationKey configurationKey) { return getConfigurationValue(configurationKey, configurationKey.getDataType()); } @@ -147,6 +147,7 @@ public class JpaTenantConfigurationManagement implements EnvironmentAware, Tenan final JpaTenantConfiguration updatedTenantConfiguration = tenantConfigurationRepository .save(tenantConfiguration); + @SuppressWarnings("unchecked") final Class clazzT = (Class) value.getClass(); return TenantConfigurationValue. builder().global(false).createdBy(updatedTenantConfiguration.getCreatedBy()) From a8bca3dc1232b4f60904dd25d7cd2075f8f1aaed Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Tue, 31 May 2016 11:07:02 +0200 Subject: [PATCH 37/54] fix sonar issue unused local variable Signed-off-by: Michael Hirsch --- .../hawkbit/artifact/repository/ArtifactStore.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/hawkbit-artifact-repository-mongo/src/main/java/org/eclipse/hawkbit/artifact/repository/ArtifactStore.java b/hawkbit-artifact-repository-mongo/src/main/java/org/eclipse/hawkbit/artifact/repository/ArtifactStore.java index 5f12498ff..af60a39c8 100644 --- a/hawkbit-artifact-repository-mongo/src/main/java/org/eclipse/hawkbit/artifact/repository/ArtifactStore.java +++ b/hawkbit-artifact-repository-mongo/src/main/java/org/eclipse/hawkbit/artifact/repository/ArtifactStore.java @@ -124,11 +124,9 @@ public class ArtifactStore implements ArtifactRepository { try { LOGGER.debug("storing file {} of content {}", filename, contentType); tempFile = File.createTempFile("uploadFile", null); - try (final FileOutputStream os = new FileOutputStream(tempFile)) { - try (BufferedOutputStream bos = new BufferedOutputStream(os)) { - try (BufferedInputStream bis = new BufferedInputStream(content)) { - return store(content, contentType, bos, tempFile, hash); - } + try (final BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(tempFile))) { + try (BufferedInputStream bis = new BufferedInputStream(content)) { + return store(bis, contentType, bos, tempFile, hash); } } } catch (final IOException | MongoException e1) { From 1117bbebbbcb4d446ce5654724582820de6e3bfc Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Tue, 31 May 2016 11:29:41 +0200 Subject: [PATCH 38/54] re-add json dependency for tests Signed-off-by: Michael Hirsch --- .../hawkbit-repository-jpa/pom.xml | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/hawkbit-repository/hawkbit-repository-jpa/pom.xml b/hawkbit-repository/hawkbit-repository-jpa/pom.xml index 0a5f65957..d234f5f57 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/pom.xml +++ b/hawkbit-repository/hawkbit-repository-jpa/pom.xml @@ -8,8 +8,7 @@ http://www.eclipse.org/legal/epl-v10.html --> - + 4.0.0 org.eclipse.hawkbit @@ -51,7 +50,7 @@ org.eclipse.hawkbit hawkbit-artifact-repository-mongo ${project.version} - + com.google.guava guava @@ -75,7 +74,7 @@ org.springframework.security spring-security-core - + org.flywaydb flyway-core @@ -97,6 +96,16 @@ ${project.version} test + + com.fasterxml.jackson.core + jackson-core + test + + + com.fasterxml.jackson.core + jackson-databind + test + com.h2database h2 @@ -126,7 +135,7 @@ org.springframework.security spring-security-aspects test - + org.springframework spring-test @@ -141,7 +150,7 @@ org.easytesting fest-assert test - + org.springframework.security spring-security-config From 91fd94b3562f7d367879d01bcbdebbc05543daf0 Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Tue, 31 May 2016 12:28:24 +0200 Subject: [PATCH 39/54] Migrated MySQL schema creation to test package. Small doc improvements on testdatafactory. Signed-off-by: Kai Zimmermann --- .../MgmtDistributionSetResourceTest.java | 2 +- .../src/test/resources/logback.xml | 2 +- .../jpa/AbstractJpaIntegrationTest.java | 24 ---- ...AbstractJpaIntegrationTestWithMongoDB.java | 27 ---- .../repository/jpa/LocalH2TestDatabase.java | 118 ------------------ .../util/AbstractIntegrationTest.java | 23 ++++ .../repository/util}/CIMySqlTestDatabase.java | 28 +++-- .../repository/util/TestdataFactory.java | 10 +- .../repository/util}/Testdatabase.java | 2 +- 9 files changed, 52 insertions(+), 184 deletions(-) delete mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/LocalH2TestDatabase.java rename hawkbit-repository/{hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa => hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util}/CIMySqlTestDatabase.java (70%) rename hawkbit-repository/{hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa => hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util}/Testdatabase.java (91%) diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java index b4887c40c..8c15e0a8c 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java @@ -387,7 +387,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest @WithUser(principal = "uploadTester", allSpPermissions = true) @Description("Ensures that single DS requested by ID is listed with expected payload.") public void getDistributionSet() throws Exception { - final DistributionSet set = testdataFactory.createTestDistributionSet(); + final DistributionSet set = testdataFactory.createUpdatedDistributionSet(); // perform request mvc.perform(get("/rest/v1/distributionsets/{dsId}", set.getId()).accept(MediaType.APPLICATION_JSON)) diff --git a/hawkbit-mgmt-resource/src/test/resources/logback.xml b/hawkbit-mgmt-resource/src/test/resources/logback.xml index 49ea574f2..30060d1c6 100644 --- a/hawkbit-mgmt-resource/src/test/resources/logback.xml +++ b/hawkbit-mgmt-resource/src/test/resources/logback.xml @@ -23,7 +23,7 @@ - + diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTest.java index 342e0792b..ecb7f2d37 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTest.java @@ -13,8 +13,6 @@ import javax.persistence.PersistenceContext; import org.eclipse.hawkbit.cache.TenantAwareCacheManager; import org.eclipse.hawkbit.repository.util.AbstractIntegrationTest; -import org.junit.AfterClass; -import org.junit.BeforeClass; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.data.mongodb.gridfs.GridFsOperations; @@ -79,26 +77,4 @@ public abstract class AbstractJpaIntegrationTest extends AbstractIntegrationTest @Autowired protected TenantAwareCacheManager cacheManager; - - private static CIMySqlTestDatabase tesdatabase; - - @BeforeClass - public static void beforeClass() { - createTestdatabaseAndStart(); - } - - private static void createTestdatabaseAndStart() { - if ("MYSQL".equals(System.getProperty("spring.jpa.database"))) { - tesdatabase = new CIMySqlTestDatabase(); - tesdatabase.before(); - } - } - - @AfterClass - public static void afterClass() { - if (tesdatabase != null) { - tesdatabase.after(); - } - } - } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTestWithMongoDB.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTestWithMongoDB.java index 38a02c213..6650d1e3c 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTestWithMongoDB.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTestWithMongoDB.java @@ -13,11 +13,8 @@ import javax.persistence.PersistenceContext; import org.eclipse.hawkbit.cache.TenantAwareCacheManager; import org.eclipse.hawkbit.repository.util.AbstractIntegrationTestWithMongoDB; -import org.junit.AfterClass; -import org.junit.BeforeClass; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.SpringApplicationConfiguration; -import org.springframework.data.mongodb.gridfs.GridFsOperations; @SpringApplicationConfiguration(classes = { org.eclipse.hawkbit.RepositoryApplicationConfiguration.class, TestConfiguration.class }) @@ -68,9 +65,6 @@ public abstract class AbstractJpaIntegrationTestWithMongoDB extends AbstractInte @Autowired protected TargetInfoRepository targetInfoRepository; - @Autowired - protected GridFsOperations operations; - @Autowired protected RolloutGroupRepository rolloutGroupRepository; @@ -80,25 +74,4 @@ public abstract class AbstractJpaIntegrationTestWithMongoDB extends AbstractInte @Autowired protected TenantAwareCacheManager cacheManager; - private static CIMySqlTestDatabase tesdatabase; - - @BeforeClass - public static void beforeClass() { - createTestdatabaseAndStart(); - } - - private static void createTestdatabaseAndStart() { - if ("MYSQL".equals(System.getProperty("spring.jpa.database"))) { - tesdatabase = new CIMySqlTestDatabase(); - tesdatabase.before(); - } - } - - @AfterClass - public static void afterClass() { - if (tesdatabase != null) { - tesdatabase.after(); - } - } - } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/LocalH2TestDatabase.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/LocalH2TestDatabase.java deleted file mode 100644 index 7812527c8..000000000 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/LocalH2TestDatabase.java +++ /dev/null @@ -1,118 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.jpa; - -import java.io.IOException; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.SQLException; -import java.util.UUID; - -import org.h2.tools.Server; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * - * - */ -public class LocalH2TestDatabase implements Testdatabase { - - private final static Logger LOG = LoggerFactory.getLogger(LocalH2TestDatabase.class); - private final int port; - private Server h2server; - private boolean dbStarted; - private String uri; - - public LocalH2TestDatabase(final int port) { - super(); - this.port = port; - createUri(); - initSystemProperties(); - } - - private final void initSystemProperties() { - System.setProperty("spring.datasource.driverClassName", getDriverClassName()); - System.setProperty("spring.datasource.username", ""); - System.setProperty("spring.datasource.password", ""); - System.setProperty("hawkbit.server.database", "H2"); - } - - private void dropAllObjects() { - try (Connection connection = DriverManager.getConnection(uri)) { - connection.prepareCall("DROP ALL OBJECTS;").execute(); - } catch (final SQLException e) { - e.printStackTrace(); - } - } - - @Override - public void before() { - try { - startDatabase(); - } catch (ClassNotFoundException | SQLException | IOException e) { - e.printStackTrace(); - } - } - - @Override - public void after() { - try { - stopDatabase(); - } catch (ClassNotFoundException | SQLException | IOException e) { - e.printStackTrace(); - } - } - - private void startDatabase() throws SQLException, ClassNotFoundException, IOException { - if (dbStarted) { - return; - } - - // Start H2 database for OpenFire - h2server = Server - .createTcpServer( - new String[] { "-tcpPort", String.valueOf(port), "-tcpAllowOthers", "-tcpShutdownForce" }) - .start(); - dbStarted = true; - LOG.info("H2 Database started on port {} and uri {}", port, uri); - dropAllObjects(); - } - - private final void createUri() { - this.uri = "jdbc:h2:tcp://localhost:" + port + "/mem:SP" + UUID.randomUUID().toString() + ";MVCC=TRUE;" - + "DB_CLOSE_DELAY=-1"; - System.setProperty("spring.datasource.url", uri); - } - - private void stopDatabase() throws SQLException, ClassNotFoundException, IOException { - if (!dbStarted) { - return; - } - - h2server.stop(); - h2server = null; - dbStarted = false; - try { - Thread.sleep(1000); - } catch (final InterruptedException e) { - } - } - - @Override - public String getDriverClassName() { - return "org.h2.Driver"; - } - - @Override - public String getUri() { - return uri; - } - -} diff --git a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/AbstractIntegrationTest.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/AbstractIntegrationTest.java index 29bf02fa0..901827d32 100644 --- a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/AbstractIntegrationTest.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/AbstractIntegrationTest.java @@ -29,7 +29,9 @@ import org.eclipse.hawkbit.security.DosFilter; import org.eclipse.hawkbit.security.SystemSecurityContext; import org.eclipse.hawkbit.tenancy.TenantAware; import org.junit.After; +import org.junit.AfterClass; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Rule; import org.junit.rules.MethodRule; import org.junit.rules.TestWatchman; @@ -211,4 +213,25 @@ public abstract class AbstractIntegrationTest implements EnvironmentAware { } } }; + + private static CIMySqlTestDatabase tesdatabase; + + @BeforeClass + public static void beforeClass() { + createTestdatabaseAndStart(); + } + + private static void createTestdatabaseAndStart() { + if ("MYSQL".equals(System.getProperty("spring.jpa.database"))) { + tesdatabase = new CIMySqlTestDatabase(); + tesdatabase.before(); + } + } + + @AfterClass + public static void afterClass() { + if (tesdatabase != null) { + tesdatabase.after(); + } + } } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/CIMySqlTestDatabase.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/CIMySqlTestDatabase.java similarity index 70% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/CIMySqlTestDatabase.java rename to hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/CIMySqlTestDatabase.java index c0a8b161c..e6bbe1f6a 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/CIMySqlTestDatabase.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/CIMySqlTestDatabase.java @@ -6,10 +6,11 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.jpa; +package org.eclipse.hawkbit.repository.util; import java.sql.Connection; import java.sql.DriverManager; +import java.sql.PreparedStatement; import java.sql.SQLException; import org.apache.commons.lang3.RandomStringUtils; @@ -17,17 +18,20 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * + * {@link Testdatabase} implementation for MySQL. * */ public class CIMySqlTestDatabase implements Testdatabase { - private final static Logger LOG = LoggerFactory.getLogger(CIMySqlTestDatabase.class); + private static final Logger LOG = LoggerFactory.getLogger(CIMySqlTestDatabase.class); private String schemaName; private String uri; private final String username; private final String password; + /** + * Constructor. + */ public CIMySqlTestDatabase() { this.username = System.getProperty("spring.datasource.username"); this.password = System.getProperty("spring.datasource.password"); @@ -43,7 +47,7 @@ public class CIMySqlTestDatabase implements Testdatabase { private void createSchemaUri() { schemaName = "SP" + RandomStringUtils.randomAlphanumeric(10); - this.uri = this.uri.substring(0, uri.lastIndexOf("/") + 1); + this.uri = this.uri.substring(0, uri.lastIndexOf('/') + 1); System.setProperty("spring.datasource.url", uri + schemaName); } @@ -55,10 +59,12 @@ public class CIMySqlTestDatabase implements Testdatabase { private void createSchema() { try (Connection connection = DriverManager.getConnection(uri, username, password)) { - connection.prepareStatement("CREATE SCHEMA " + schemaName + ";").execute(); - LOG.info("Schema {} created on uri {}", schemaName, uri); + try (PreparedStatement statement = connection.prepareStatement("CREATE SCHEMA " + schemaName + ";")) { + statement.execute(); + LOG.info("Schema {} created on uri {}", schemaName, uri); + } } catch (final SQLException e) { - e.printStackTrace(); + LOG.error("Schema creation failed!", e); } } @@ -70,10 +76,12 @@ public class CIMySqlTestDatabase implements Testdatabase { private void dropSchema() { try (Connection connection = DriverManager.getConnection(uri, username, password)) { - connection.prepareStatement("DROP SCHEMA " + schemaName + ";").execute(); - LOG.info("Schema {} dropped on uri {}", schemaName, uri); + try (PreparedStatement statement = connection.prepareStatement("DROP SCHEMA " + schemaName + ";")) { + statement.execute(); + LOG.info("Schema {} dropped on uri {}", schemaName, uri); + } } catch (final SQLException e) { - e.printStackTrace(); + LOG.error("Schema drop failed!", e); } } diff --git a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/TestdataFactory.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/TestdataFactory.java index 0597a30cb..1ed5679c8 100644 --- a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/TestdataFactory.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/TestdataFactory.java @@ -29,6 +29,7 @@ import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; import org.eclipse.hawkbit.repository.model.Artifact; +import org.eclipse.hawkbit.repository.model.BaseEntity; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.DistributionSetType; @@ -219,7 +220,7 @@ public class TestdataFactory { * @param version * {@link DistributionSet#getVersion()} and * {@link SoftwareModule#getVersion()} extended by a random - * number. + * number.updat * @param tags * {@link DistributionSet#getTags()} * @@ -352,9 +353,14 @@ public class TestdataFactory { * iterative number and {@link DistributionSet#isRequiredMigrationStep()} * false. * + * In addition it updates the ccreated {@link DistributionSet}s and + * {@link SoftwareModule}s to ensure that + * {@link BaseEntity#getLastModifiedAt()} and + * {@link BaseEntity#getLastModifiedBy()} is filled. + * * @return persisted {@link DistributionSet}. */ - public DistributionSet createTestDistributionSet() { + public DistributionSet createUpdatedDistributionSet() { DistributionSet set = createDistributionSet(""); set.setVersion(DEFAULT_VERSION); set = distributionSetManagement.updateDistributionSet(set); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/Testdatabase.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/Testdatabase.java similarity index 91% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/Testdatabase.java rename to hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/Testdatabase.java index 38133c800..b24d34533 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/Testdatabase.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/Testdatabase.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.jpa; +package org.eclipse.hawkbit.repository.util; /** * From 13f9791891388b601ab2802c39bf4a0662762748 Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Tue, 31 May 2016 20:50:22 +0200 Subject: [PATCH 40/54] Removed JPA dependencies from runtime. Test only now. Signed-off-by: Kai Zimmermann --- examples/hawkbit-custom-theme-example/pom.xml | 5 + .../java/org/eclipse/hawkbit/app/Start.java | 2 + examples/hawkbit-example-app/pom.xml | 5 + .../java/org/eclipse/hawkbit/app/Start.java | 2 + hawkbit-ddi-resource/pom.xml | 8 +- .../resource/DdiArtifactStoreController.java | 16 +- .../ddi/rest/resource/DdiRootController.java | 20 ++- hawkbit-dmf-amqp/pom.xml | 10 +- .../AmqpMessageDispatcherServiceTest.java | 6 +- .../PropertyBasedArtifactUrlHandlerTest.java | 28 ++-- .../resources/application-test.properties | 38 +++++ .../src/test/resources/logback.xml | 35 +++++ hawkbit-http-security/pom.xml | 2 +- hawkbit-mgmt-resource/pom.xml | 17 +- .../rest/resource/MgmtRolloutResource.java | 8 +- .../MgmtSoftwareModuleResourceTest.java | 2 +- .../resources/application-test.properties | 14 -- .../hawkbit-repository-api/pom.xml | 4 + .../repository/ControllerManagement.java | 15 ++ .../hawkbit/repository/EntityFactory.java | 8 + .../TargetFilterQueryManagement.java | 19 +++ .../hawkbit/repository/TargetManagement.java | 13 ++ .../jpa/model/helper/EventBusHolder.java | 3 +- .../hawkbit-repository-jpa/pom.xml | 27 +--- .../eclipse/hawkbit/EnableJpaRepository.java | 1 - .../RepositoryApplicationConfiguration.java | 2 +- .../jpa/JpaControllerManagement.java | 14 +- .../repository/jpa/JpaEntityFactory.java | 7 + .../jpa/JpaTargetFilterQueryManagement.java | 8 + .../AbstractJpaTenantAwareBaseEntity.java | 2 + .../jpa/model/JpaDistributionSetMetadata.java | 2 + .../jpa/AbstractJpaIntegrationTest.java | 3 +- ...AbstractJpaIntegrationTestWithMongoDB.java | 3 +- .../jpa/ArtifactManagementTest.java | 1 + .../hawkbit-repository-test/pom.xml | 18 ++- .../util/AbstractIntegrationTest.java | 4 +- .../repository/util}/HashGeneratorUtils.java | 22 +-- .../util}/JpaTestRepositoryManagement.java | 61 +------- .../repository/util}/TestConfiguration.java | 4 +- hawkbit-rest-core/pom.xml | 13 +- .../util/RestResourceConversionHelper.java | 37 ++--- .../rest/AbstractRestIntegrationTest.java | 7 +- ...bstractRestIntegrationTestWithMongoDB.java | 7 +- hawkbit-security-integration/pom.xml | 8 +- hawkbit-ui/pom.xml | 8 +- .../artifacts/details/ArtifactBeanQuery.java | 12 +- .../smtable/ProxyBaseSoftwareModuleItem.java | 41 ++++- .../ui/common/DistributionSetIdName.java | 7 +- .../ui/components/ProxyDistribution.java | 42 ++++- .../ui/components/ProxyTargetFilter.java | 50 +++++- .../DistributionAddUpdateWindowLayout.java | 7 +- .../ui/rollout/rollout/ProxyRollout.java | 96 +++++++++++- .../ui/rollout/rollout/RolloutBeanQuery.java | 2 - .../rolloutgroup/ProxyRolloutGroup.java | 146 +++++++++++++++++- 54 files changed, 699 insertions(+), 243 deletions(-) create mode 100644 hawkbit-dmf-amqp/src/test/resources/application-test.properties create mode 100644 hawkbit-dmf-amqp/src/test/resources/logback.xml rename hawkbit-repository/{hawkbit-repository-jpa => hawkbit-repository-core}/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/EventBusHolder.java (90%) rename hawkbit-repository/{hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa => hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util}/HashGeneratorUtils.java (74%) rename hawkbit-repository/{hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa => hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util}/JpaTestRepositoryManagement.java (50%) rename hawkbit-repository/{hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa => hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util}/TestConfiguration.java (95%) diff --git a/examples/hawkbit-custom-theme-example/pom.xml b/examples/hawkbit-custom-theme-example/pom.xml index 7caa99ba2..875db18e3 100644 --- a/examples/hawkbit-custom-theme-example/pom.xml +++ b/examples/hawkbit-custom-theme-example/pom.xml @@ -79,6 +79,11 @@ hawkbit-http-security ${project.version} + + org.eclipse.hawkbit + hawkbit-repository-jpa + ${project.version} + diff --git a/examples/hawkbit-custom-theme-example/src/main/java/org/eclipse/hawkbit/app/Start.java b/examples/hawkbit-custom-theme-example/src/main/java/org/eclipse/hawkbit/app/Start.java index fdad8a999..7f80eb05b 100644 --- a/examples/hawkbit-custom-theme-example/src/main/java/org/eclipse/hawkbit/app/Start.java +++ b/examples/hawkbit-custom-theme-example/src/main/java/org/eclipse/hawkbit/app/Start.java @@ -8,6 +8,7 @@ package org.eclipse.hawkbit.app; * http://www.eclipse.org/legal/epl-v10.html */ +import org.eclipse.hawkbit.EnableJpaRepository; import org.eclipse.hawkbit.autoconfigure.security.EnableHawkbitManagedSecurityConfiguration; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -21,6 +22,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; @EnableHawkbitManagedSecurityConfiguration // Exception squid:S1118 - Spring boot standard behavior @SuppressWarnings({ "squid:S1118" }) +@EnableJpaRepository public class Start { /** * Main method to start the spring-boot application. diff --git a/examples/hawkbit-example-app/pom.xml b/examples/hawkbit-example-app/pom.xml index 957ba8d6a..f501d5529 100644 --- a/examples/hawkbit-example-app/pom.xml +++ b/examples/hawkbit-example-app/pom.xml @@ -92,6 +92,11 @@ hawkbit-http-security ${project.version} + + org.eclipse.hawkbit + hawkbit-repository-jpa + ${project.version} + diff --git a/examples/hawkbit-example-app/src/main/java/org/eclipse/hawkbit/app/Start.java b/examples/hawkbit-example-app/src/main/java/org/eclipse/hawkbit/app/Start.java index d22d6f4a1..95fb39147 100644 --- a/examples/hawkbit-example-app/src/main/java/org/eclipse/hawkbit/app/Start.java +++ b/examples/hawkbit-example-app/src/main/java/org/eclipse/hawkbit/app/Start.java @@ -8,6 +8,7 @@ */ package org.eclipse.hawkbit.app; +import org.eclipse.hawkbit.EnableJpaRepository; import org.eclipse.hawkbit.autoconfigure.security.EnableHawkbitManagedSecurityConfiguration; import org.eclipse.hawkbit.ddi.EnableDdiApi; import org.eclipse.hawkbit.mgmt.EnableMgmtApi; @@ -23,6 +24,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; @EnableHawkbitManagedSecurityConfiguration @EnableMgmtApi @EnableDdiApi +@EnableJpaRepository // Exception squid:S1118 - Spring boot standard behavior @SuppressWarnings({ "squid:S1118" }) public class Start { diff --git a/hawkbit-ddi-resource/pom.xml b/hawkbit-ddi-resource/pom.xml index 35aff47f5..cb85f8c8c 100644 --- a/hawkbit-ddi-resource/pom.xml +++ b/hawkbit-ddi-resource/pom.xml @@ -38,7 +38,7 @@ org.eclipse.hawkbit - hawkbit-repository-jpa + hawkbit-repository-api ${project.version} @@ -54,6 +54,12 @@ ${project.version} test + + org.eclipse.hawkbit + hawkbit-repository-jpa + ${project.version} + test + org.eclipse.hawkbit hawkbit-rest-core diff --git a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java index 5bed44295..85a326f9a 100644 --- a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java +++ b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java @@ -17,10 +17,9 @@ import javax.servlet.http.HttpServletRequest; import org.eclipse.hawkbit.artifact.repository.model.DbArtifact; import org.eclipse.hawkbit.ddi.dl.rest.api.DdiDlArtifactStoreControllerRestApi; import org.eclipse.hawkbit.repository.ArtifactManagement; -import org.eclipse.hawkbit.repository.RepositoryConstants; import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.EntityFactory; -import org.eclipse.hawkbit.repository.jpa.cache.CacheWriteNotify; +import org.eclipse.hawkbit.repository.RepositoryConstants; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; @@ -60,9 +59,6 @@ public class DdiArtifactStoreController implements DdiDlArtifactStoreControllerR @Autowired private ControllerManagement controllerManagement; - @Autowired - private CacheWriteNotify cacheWriteNotify; - @Autowired private HawkbitSecurityProperties securityProperties; @@ -101,7 +97,8 @@ public class DdiArtifactStoreController implements DdiDlArtifactStoreControllerR requestResponseContextHolder.getHttpServletRequest(), targetid, artifact); result = RestResourceConversionHelper.writeFileResponse(artifact, requestResponseContextHolder.getHttpServletResponse(), - requestResponseContextHolder.getHttpServletRequest(), file, cacheWriteNotify, action.getId()); + requestResponseContextHolder.getHttpServletRequest(), file, controllerManagement, + action.getId()); } else { result = RestResourceConversionHelper.writeFileResponse(artifact, requestResponseContextHolder.getHttpServletResponse(), @@ -149,10 +146,11 @@ public class DdiArtifactStoreController implements DdiDlArtifactStoreControllerR actionStatus.setStatus(Status.DOWNLOAD); if (range != null) { - actionStatus.addMessage(RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target downloads range " + range + " of: " - + request.getRequestURI()); + actionStatus.addMessage(RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target downloads range " + range + + " of: " + request.getRequestURI()); } else { - actionStatus.addMessage(RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target downloads: " + request.getRequestURI()); + actionStatus.addMessage( + RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target downloads: " + request.getRequestURI()); } controllerManagement.addInformationalActionStatus(actionStatus); return action; diff --git a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java index 0c6fa4386..20d1b2e29 100644 --- a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java +++ b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java @@ -29,12 +29,11 @@ import org.eclipse.hawkbit.ddi.json.model.DdiDeploymentBase; import org.eclipse.hawkbit.ddi.json.model.DdiResult.FinalResult; import org.eclipse.hawkbit.ddi.rest.api.DdiRootControllerRestApi; import org.eclipse.hawkbit.repository.ArtifactManagement; -import org.eclipse.hawkbit.repository.RepositoryConstants; import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.EntityFactory; +import org.eclipse.hawkbit.repository.RepositoryConstants; import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; -import org.eclipse.hawkbit.repository.jpa.cache.CacheWriteNotify; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; @@ -83,9 +82,6 @@ public class DdiRootController implements DdiRootControllerRestApi { @Autowired private ArtifactManagement artifactManagement; - @Autowired - private CacheWriteNotify cacheWriteNotify; - @Autowired private HawkbitSecurityProperties securityProperties; @@ -167,7 +163,8 @@ public class DdiRootController implements DdiRootControllerRestApi { module); result = RestResourceConversionHelper.writeFileResponse(artifact, requestResponseContextHolder.getHttpServletResponse(), - requestResponseContextHolder.getHttpServletRequest(), file, cacheWriteNotify, action.getId()); + requestResponseContextHolder.getHttpServletRequest(), file, controllerManagement, + action.getId()); } } return result; @@ -185,10 +182,11 @@ public class DdiRootController implements DdiRootControllerRestApi { statusMessage.setStatus(Status.DOWNLOAD); if (range != null) { - statusMessage.addMessage(RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target downloads range " + range + " of: " - + request.getRequestURI()); + statusMessage.addMessage(RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target downloads range " + range + + " of: " + request.getRequestURI()); } else { - statusMessage.addMessage(RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target downloads " + request.getRequestURI()); + statusMessage.addMessage( + RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target downloads " + request.getRequestURI()); } controllerManagement.addInformationalActionStatus(statusMessage); return action; @@ -339,8 +337,8 @@ public class DdiRootController implements DdiRootControllerRestApi { LOG.debug("Controller reported intermediate status (actionid: {}, targetid: {}) as we got {} report.", actionid, targetid, feedback.getStatus().getExecution()); actionStatus.setStatus(Status.RUNNING); - actionStatus - .addMessage(RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target reported " + feedback.getStatus().getExecution()); + actionStatus.addMessage( + RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target reported " + feedback.getStatus().getExecution()); } private static void handleClosedUpdateStatus(final DdiActionFeedback feedback, final String targetid, diff --git a/hawkbit-dmf-amqp/pom.xml b/hawkbit-dmf-amqp/pom.xml index bcebc9628..c2ed7c213 100644 --- a/hawkbit-dmf-amqp/pom.xml +++ b/hawkbit-dmf-amqp/pom.xml @@ -23,10 +23,10 @@ org.eclipse.hawkbit - hawkbit-repository-jpa + hawkbit-repository-api ${project.version} - + org.eclipse.hawkbit hawkbit-core ${project.version} @@ -41,6 +41,10 @@ hawkbit-dmf-api ${project.version} + + org.springframework.boot + spring-boot-autoconfigure + org.springframework.amqp spring-rabbit @@ -98,7 +102,7 @@ org.eclipse.hawkbit hawkbit-repository-jpa ${project.version} - tests + test ru.yandex.qatools.allure diff --git a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java index 480948683..5faaa74f0 100644 --- a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java +++ b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java @@ -33,11 +33,11 @@ import org.eclipse.hawkbit.dmf.amqp.api.MessageType; import org.eclipse.hawkbit.dmf.json.model.DownloadAndUpdateRequest; import org.eclipse.hawkbit.eventbus.event.CancelTargetAssignmentEvent; import org.eclipse.hawkbit.repository.eventbus.event.TargetAssignDistributionSetEvent; -import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTestWithMongoDB; import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; +import org.eclipse.hawkbit.repository.util.AbstractIntegrationTestWithMongoDB; import org.eclipse.hawkbit.util.IpUtil; import org.junit.Test; import org.mockito.ArgumentCaptor; @@ -47,6 +47,7 @@ import org.springframework.amqp.core.MessageProperties; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.amqp.support.converter.AbstractJavaTypeMapper; import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; +import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.test.context.ActiveProfiles; import ru.yandex.qatools.allure.annotations.Description; @@ -56,7 +57,8 @@ import ru.yandex.qatools.allure.annotations.Stories; @ActiveProfiles({ "test" }) @Features("Component Tests - Device Management Federation API") @Stories("AmqpMessage Dispatcher Service Test") -public class AmqpMessageDispatcherServiceTest extends AbstractJpaIntegrationTestWithMongoDB { +@SpringApplicationConfiguration(classes = { org.eclipse.hawkbit.RepositoryApplicationConfiguration.class }) +public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTestWithMongoDB { private static final String TENANT = "default"; diff --git a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/util/PropertyBasedArtifactUrlHandlerTest.java b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/util/PropertyBasedArtifactUrlHandlerTest.java index 8f855da68..c67d6cf47 100644 --- a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/util/PropertyBasedArtifactUrlHandlerTest.java +++ b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/util/PropertyBasedArtifactUrlHandlerTest.java @@ -11,15 +11,12 @@ package org.eclipse.hawkbit.util; import static org.junit.Assert.assertEquals; import org.eclipse.hawkbit.AmqpTestConfiguration; -import org.eclipse.hawkbit.RepositoryApplicationConfiguration; import org.eclipse.hawkbit.api.ArtifactUrlHandler; import org.eclipse.hawkbit.api.UrlProtocol; -import org.eclipse.hawkbit.repository.jpa.TestConfiguration; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.util.AbstractIntegrationTestWithMongoDB; -import org.eclipse.hawkbit.tenancy.TenantAware; import org.junit.Before; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -34,18 +31,18 @@ import ru.yandex.qatools.allure.annotations.Stories; */ @Features("Component Tests - Artifact URL Handler") @Stories("Test to generate the artifact download URL") -@SpringApplicationConfiguration(classes = { RepositoryApplicationConfiguration.class, TestConfiguration.class, - AmqpTestConfiguration.class }) +@SpringApplicationConfiguration(classes = { AmqpTestConfiguration.class, + org.eclipse.hawkbit.RepositoryApplicationConfiguration.class }) public class PropertyBasedArtifactUrlHandlerTest extends AbstractIntegrationTestWithMongoDB { private static final String HTTPS_LOCALHOST = "https://localhost:8080/"; private static final String HTTP_LOCALHOST = "http://localhost:8080/"; + @Autowired private ArtifactUrlHandler urlHandlerProperties; - @Autowired - private TenantAware tenantAware; + private LocalArtifact localArtifact; - private final String controllerId = "Test"; + private static final String CONTROLLER_ID = "Test"; private String fileName; private Long softwareModuleId; private String sha1Hash; @@ -65,21 +62,22 @@ public class PropertyBasedArtifactUrlHandlerTest extends AbstractIntegrationTest @Description("Tests the generation of http download url.") public void testHttpUrl() { - final String url = urlHandlerProperties.getUrl(controllerId, softwareModuleId, fileName, sha1Hash, + final String url = urlHandlerProperties.getUrl(CONTROLLER_ID, softwareModuleId, fileName, sha1Hash, UrlProtocol.HTTP); assertEquals("http is build incorrect", - HTTP_LOCALHOST + tenantAware.getCurrentTenant() + "/controller/v1/" + controllerId + "/softwaremodules/" - + localArtifact.getSoftwareModule().getId() + "/artifacts/" + localArtifact.getFilename(), + HTTP_LOCALHOST + tenantAware.getCurrentTenant() + "/controller/v1/" + CONTROLLER_ID + + "/softwaremodules/" + localArtifact.getSoftwareModule().getId() + "/artifacts/" + + localArtifact.getFilename(), url); } @Test @Description("Tests the generation of https download url.") public void testHttpsUrl() { - final String url = urlHandlerProperties.getUrl(controllerId, softwareModuleId, fileName, sha1Hash, + final String url = urlHandlerProperties.getUrl(CONTROLLER_ID, softwareModuleId, fileName, sha1Hash, UrlProtocol.HTTPS); assertEquals("https is build incorrect", - HTTPS_LOCALHOST + tenantAware.getCurrentTenant() + "/controller/v1/" + controllerId + HTTPS_LOCALHOST + tenantAware.getCurrentTenant() + "/controller/v1/" + CONTROLLER_ID + "/softwaremodules/" + localArtifact.getSoftwareModule().getId() + "/artifacts/" + localArtifact.getFilename(), url); @@ -88,10 +86,10 @@ public class PropertyBasedArtifactUrlHandlerTest extends AbstractIntegrationTest @Test @Description("Tests the generation of coap download url.") public void testCoapUrl() { - final String url = urlHandlerProperties.getUrl(controllerId, softwareModuleId, fileName, sha1Hash, + final String url = urlHandlerProperties.getUrl(CONTROLLER_ID, softwareModuleId, fileName, sha1Hash, UrlProtocol.COAP); assertEquals("coap is build incorrect", "coap://127.0.0.1:5683/fw/" + tenantAware.getCurrentTenant() + "/" - + controllerId + "/sha1/" + localArtifact.getSha1Hash(), url); + + CONTROLLER_ID + "/sha1/" + localArtifact.getSha1Hash(), url); } } diff --git a/hawkbit-dmf-amqp/src/test/resources/application-test.properties b/hawkbit-dmf-amqp/src/test/resources/application-test.properties new file mode 100644 index 000000000..79b1fe78f --- /dev/null +++ b/hawkbit-dmf-amqp/src/test/resources/application-test.properties @@ -0,0 +1,38 @@ +# +# Copyright (c) 2015 Bosch Software Innovations GmbH and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# + + + +# supported: H2, MYSQL +hawkbit.server.database=H2 + +spring.jpa.database=${hawkbit.server.database} + + +flyway.sqlMigrationSuffix=${spring.jpa.database}.sql + +# effective DB setting +spring.datasource.url=${${hawkbit.server.database}.spring.datasource.url} +spring.datasource.driverClassName=${${hawkbit.server.database}.spring.datasource.driverClassName} +spring.datasource.username=${${hawkbit.server.database}.spring.datasource.username} +spring.datasource.password=${${hawkbit.server.database}.spring.datasource.password} + +# H2 +##;AUTOCOMMIT=ON +H2.spring.datasource.url=jdbc:h2:mem:sp-db;DB_CLOSE_ON_EXIT=FALSE +#H2.spring.datasource.url=jdbc:h2:./db/sp-db;AUTO_SERVER=TRUE;DB_CLOSE_ON_EXIT=FALSE;MVCC=TRUE +H2.spring.datasource.driverClassName=org.h2.Driver +H2.spring.datasource.username=sa +H2.spring.datasource.password=sa + +# MYSQL +MYSQL.spring.datasource.url=jdbc:mysql://localhost:3306/sp_test +MYSQL.spring.datasource.driverClassName=org.mariadb.jdbc.Driver +MYSQL.spring.datasource.username=root +MYSQL.spring.datasource.password= diff --git a/hawkbit-dmf-amqp/src/test/resources/logback.xml b/hawkbit-dmf-amqp/src/test/resources/logback.xml new file mode 100644 index 000000000..30060d1c6 --- /dev/null +++ b/hawkbit-dmf-amqp/src/test/resources/logback.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/hawkbit-http-security/pom.xml b/hawkbit-http-security/pom.xml index 03a9b6678..bb77df454 100644 --- a/hawkbit-http-security/pom.xml +++ b/hawkbit-http-security/pom.xml @@ -22,7 +22,7 @@ org.eclipse.hawkbit - hawkbit-repository-jpa + hawkbit-repository-api ${project.version} diff --git a/hawkbit-mgmt-resource/pom.xml b/hawkbit-mgmt-resource/pom.xml index fb0167793..007c6789b 100644 --- a/hawkbit-mgmt-resource/pom.xml +++ b/hawkbit-mgmt-resource/pom.xml @@ -23,9 +23,9 @@ org.eclipse.hawkbit - hawkbit-repository-jpa + hawkbit-repository-api ${project.version} - + org.eclipse.hawkbit hawkbit-mgmt-api @@ -53,6 +53,12 @@ ${project.version} test + + org.eclipse.hawkbit + hawkbit-repository-jpa + ${project.version} + test + org.eclipse.hawkbit hawkbit-rest-core @@ -96,13 +102,6 @@ spring-security-config test - - org.eclipse.hawkbit - hawkbit-repository-jpa - ${project.version} - tests - test - org.eclipse.hawkbit hawkbit-http-security diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResource.java index 623241981..7144316b8 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResource.java @@ -22,9 +22,8 @@ import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.RolloutGroupManagement; import org.eclipse.hawkbit.repository.RolloutManagement; -import org.eclipse.hawkbit.repository.TargetFields; +import org.eclipse.hawkbit.repository.TargetFilterQueryManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; -import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.RolloutGroup; @@ -64,6 +63,9 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi { @Autowired private DistributionSetManagement distributionSetManagement; + @Autowired + private TargetFilterQueryManagement targetFilterQueryManagement; + @Autowired private EntityFactory entityFactory; @@ -103,7 +105,7 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi { // first check the given RSQL query if it's well formed, otherwise and // exception is thrown - RSQLUtility.parse(rolloutRequestBody.getTargetFilterQuery(), TargetFields.class); + targetFilterQueryManagement.verifyTargetFilterQuerySyntax(rolloutRequestBody.getTargetFilterQuery()); final DistributionSet distributionSet = findDistributionSetOrThrowException(rolloutRequestBody); diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java index a0bf416c9..e7397dd49 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java @@ -36,12 +36,12 @@ import org.eclipse.hawkbit.exception.SpServerError; import org.eclipse.hawkbit.mgmt.json.model.artifact.MgmtArtifact; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; -import org.eclipse.hawkbit.repository.jpa.HashGeneratorUtils; import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata; +import org.eclipse.hawkbit.repository.util.HashGeneratorUtils; import org.eclipse.hawkbit.repository.util.WithUser; import org.eclipse.hawkbit.rest.AbstractRestIntegrationTestWithMongoDB; import org.eclipse.hawkbit.rest.json.model.ExceptionInfo; diff --git a/hawkbit-mgmt-resource/src/test/resources/application-test.properties b/hawkbit-mgmt-resource/src/test/resources/application-test.properties index 92506caa4..cd98bb23f 100644 --- a/hawkbit-mgmt-resource/src/test/resources/application-test.properties +++ b/hawkbit-mgmt-resource/src/test/resources/application-test.properties @@ -7,22 +7,8 @@ # http://www.eclipse.org/legal/epl-v10.html # -# used if IM profile is disabled -security.ignored=true - -# IM required for integration tests -spring.profiles.active=im,suiteembedded,artifactrepository,redis - -server.port=12222 - -spring.data.mongodb.uri=mongodb://localhost/spArtifactRepository${random.value} -spring.data.mongodb.port=28017 - - # supported: H2, MYSQL hawkbit.server.database=H2 -hawkbit.server.database.env=TEST -spring.main.show_banner=false hawkbit.server.ddi.security.authentication.header=true diff --git a/hawkbit-repository/hawkbit-repository-api/pom.xml b/hawkbit-repository/hawkbit-repository-api/pom.xml index 076ae8cd8..050a9a070 100644 --- a/hawkbit-repository/hawkbit-repository-api/pom.xml +++ b/hawkbit-repository/hawkbit-repository-api/pom.xml @@ -31,6 +31,10 @@ org.hibernate hibernate-validator + + + cz.jirutka.rsql + rsql-parser org.springframework.hateoas diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java index 90bb7068b..f8615bcc3 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java @@ -14,6 +14,7 @@ import java.util.Map; import javax.validation.constraints.NotNull; +import org.eclipse.hawkbit.eventbus.event.DownloadProgressEvent; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; @@ -32,6 +33,8 @@ import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; import org.hibernate.validator.constraints.NotEmpty; import org.springframework.security.access.prepost.PreAuthorize; +import com.google.common.eventbus.EventBus; + /** * Service layer for all operations of the DDI API (with access permissions only * for the controller). @@ -54,6 +57,18 @@ public interface ControllerManagement { @PreAuthorize(SpringEvalExpressions.IS_CONTROLLER) Action addCancelActionStatus(@NotNull ActionStatus actionStatus); + /** + * Sends the download progress in percentage and notifies the + * {@link EventBus} with a {@link DownloadProgressEvent}. + * + * @param statusId + * the ID of the {@link ActionStatus} + * @param progressPercent + * the progress in percentage which must be between 0-100 + */ + @PreAuthorize(SpringEvalExpressions.IS_CONTROLLER) + void downloadProgressPercent(long statusId, int progressPercent); + /** * Simple addition of a new {@link ActionStatus} entry to the {@link Action} * . No state changes. diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/EntityFactory.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/EntityFactory.java index 85a2f5e76..7542cd2ce 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/EntityFactory.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/EntityFactory.java @@ -19,6 +19,7 @@ import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetMetadata; import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.DistributionSetType; +import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.RolloutGroup; import org.eclipse.hawkbit.repository.model.SoftwareModule; @@ -330,4 +331,11 @@ public interface EntityFactory { */ TargetTag generateTargetTag(String name, String description, String colour); + /** + * Generates an empty {@link LocalArtifact} without persisting it. + * + * @return {@link LocalArtifact} object + */ + LocalArtifact generateLocalArtifact(); + } diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagement.java index 48018b9ec..d748ed470 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagement.java @@ -11,6 +11,8 @@ package org.eclipse.hawkbit.repository; import javax.validation.constraints.NotNull; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; +import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException; +import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException; import org.eclipse.hawkbit.repository.model.TargetFilterQuery; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -40,6 +42,23 @@ public interface TargetFilterQueryManagement { @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_TARGET) void deleteTargetFilterQuery(@NotNull Long targetFilterQueryId); + /** + * Verifies provided filter syntax. + * + * @param query + * to verify + * + * @return true if syntax is valid + * + * @throws RSQLParameterUnsupportedFieldException + * if a field in the RSQL string is used but not provided by the + * given {@code fieldNameProvider} + * @throws RSQLParameterSyntaxException + * if the RSQL syntax is wrong + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + boolean verifyTargetFilterQuerySyntax(String query); + /** * * Retrieves all target filter query{@link TargetFilterQuery}. diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java index ee10883ec..9054127ef 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java @@ -439,7 +439,14 @@ public interface TargetManagement { * in string notation * @param pageable * pagination parameter + * * @return the found {@link Target}s, never {@code null} + * + * @throws RSQLParameterUnsupportedFieldException + * if a field in the RSQL string is used but not provided by the + * given {@code fieldNameProvider} + * @throws RSQLParameterSyntaxException + * if the RSQL syntax is wrong */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) Page findTargetsAll(@NotNull String targetFilterQuery, @NotNull Pageable pageable); @@ -455,6 +462,12 @@ public interface TargetManagement { * pagination parameter * * @return the found {@link Target}s, never {@code null} + * + * @throws RSQLParameterUnsupportedFieldException + * if a field in the RSQL string is used but not provided by the + * given {@code fieldNameProvider} + * @throws RSQLParameterSyntaxException + * if the RSQL syntax is wrong */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) Slice findTargetsAll(@NotNull TargetFilterQuery targetFilterQuery, @NotNull Pageable pageable); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/EventBusHolder.java b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/EventBusHolder.java similarity index 90% rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/EventBusHolder.java rename to hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/EventBusHolder.java index 5196283d1..3829d639b 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/EventBusHolder.java +++ b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/EventBusHolder.java @@ -8,7 +8,6 @@ */ package org.eclipse.hawkbit.repository.jpa.model.helper; -import org.eclipse.hawkbit.repository.jpa.model.CacheFieldEntityListener; import org.springframework.beans.factory.annotation.Autowired; import com.google.common.eventbus.EventBus; @@ -16,7 +15,7 @@ import com.google.common.eventbus.EventBus; /** * A singleton bean which holds the {@link EventBus} to have to the cache * manager in beans not instantiated by spring e.g. JPA entities or - * {@link CacheFieldEntityListener} which cannot be autowired. + * CacheFieldEntityListener which cannot be autowired. * */ public final class EventBusHolder { diff --git a/hawkbit-repository/hawkbit-repository-jpa/pom.xml b/hawkbit-repository/hawkbit-repository-jpa/pom.xml index d234f5f57..bd56e9ca5 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/pom.xml +++ b/hawkbit-repository/hawkbit-repository-jpa/pom.xml @@ -120,27 +120,12 @@ javax.el javax.el-api test - - - org.springframework - spring-context-support - test - + ru.yandex.qatools.allure allure-junit-adaptor test - - org.springframework.security - spring-security-aspects - test - - - org.springframework - spring-test - test - org.easytesting fest-assert-core @@ -151,16 +136,6 @@ fest-assert test - - org.springframework.security - spring-security-config - test - - - org.springframework.security - spring-security-web - test - diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/EnableJpaRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/EnableJpaRepository.java index f15ec8c82..55fd4a111 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/EnableJpaRepository.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/EnableJpaRepository.java @@ -26,7 +26,6 @@ import org.springframework.stereotype.Controller; @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Configuration -@ComponentScan @Import(RepositoryApplicationConfiguration.class) public @interface EnableJpaRepository { diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java index 5f5a46c0b..50207037a 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java @@ -47,8 +47,8 @@ import org.springframework.validation.beanvalidation.MethodValidationPostProcess @EnableTransactionManagement @EnableJpaAuditing @EnableAspectJAutoProxy -@ComponentScan @Configuration +@ComponentScan @EnableAutoConfiguration public class RepositoryApplicationConfiguration extends JpaBaseConfiguration { /** diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java index 9fcd646b5..80de385c8 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java @@ -19,13 +19,14 @@ import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.Root; import javax.validation.constraints.NotNull; -import org.eclipse.hawkbit.repository.RepositoryConstants; import org.eclipse.hawkbit.repository.ControllerManagement; +import org.eclipse.hawkbit.repository.RepositoryConstants; import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.exception.ToManyAttributeEntriesException; import org.eclipse.hawkbit.repository.exception.ToManyStatusEntriesException; +import org.eclipse.hawkbit.repository.jpa.cache.CacheWriteNotify; import org.eclipse.hawkbit.repository.jpa.model.JpaAction; import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus; import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus_; @@ -98,6 +99,9 @@ public class JpaControllerManagement implements ControllerManagement { @Autowired private TenantConfigurationManagement tenantConfigurationManagement; + @Autowired + private CacheWriteNotify cacheWriteNotify; + @Override public String getPollingTime() { final TenantConfigurationKey configurationKey = TenantConfigurationKey.POLLING_TIME_INTERVAL; @@ -230,7 +234,8 @@ public class JpaControllerManagement implements ControllerManagement { private void handleFinishedCancelation(final ActionStatus actionStatus, final JpaAction action) { // in case of successful cancellation we also report the success at // the canceled action itself. - actionStatus.addMessage(RepositoryConstants.SERVER_MESSAGE_PREFIX + "Cancellation completion is finished sucessfully."); + actionStatus.addMessage( + RepositoryConstants.SERVER_MESSAGE_PREFIX + "Cancellation completion is finished sucessfully."); DeploymentHelper.successCancellation(action, actionRepository, targetManagement, targetInfoRepository, entityManager); } @@ -436,4 +441,9 @@ public class JpaControllerManagement implements ControllerManagement { return updateTargetStatus(target, null, System.currentTimeMillis(), address); } + @Override + public void downloadProgressPercent(final long statusId, final int progressPercent) { + cacheWriteNotify.downloadProgressPercent(statusId, progressPercent); + } + } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaEntityFactory.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaEntityFactory.java index 88c34ad11..afa3b4dc6 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaEntityFactory.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaEntityFactory.java @@ -17,6 +17,7 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetMetadata; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType; +import org.eclipse.hawkbit.repository.jpa.model.JpaLocalArtifact; import org.eclipse.hawkbit.repository.jpa.model.JpaRollout; import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; @@ -32,6 +33,7 @@ import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetMetadata; import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.DistributionSetType; +import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.RolloutGroup; import org.eclipse.hawkbit.repository.model.SoftwareModule; @@ -198,4 +200,9 @@ public class JpaEntityFactory implements EntityFactory { return new JpaActionStatus(action, status, occurredAt); } + @Override + public LocalArtifact generateLocalArtifact() { + return new JpaLocalArtifact(); + } + } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetFilterQueryManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetFilterQueryManagement.java index 296483bf8..f418f5f4b 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetFilterQueryManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetFilterQueryManagement.java @@ -11,9 +11,11 @@ package org.eclipse.hawkbit.repository.jpa; import java.util.ArrayList; import java.util.List; +import org.eclipse.hawkbit.repository.TargetFields; import org.eclipse.hawkbit.repository.TargetFilterQueryManagement; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.jpa.model.JpaTargetFilterQuery; +import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility; import org.eclipse.hawkbit.repository.jpa.specifications.SpecificationsBuilder; import org.eclipse.hawkbit.repository.jpa.specifications.TargetFilterQuerySpecification; import org.eclipse.hawkbit.repository.model.TargetFilterQuery; @@ -109,4 +111,10 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme return targetFilterQueryRepository.save((JpaTargetFilterQuery) targetFilterQuery); } + @Override + public boolean verifyTargetFilterQuerySyntax(final String query) { + RSQLUtility.parse(query, TargetFields.class); + return true; + } + } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaTenantAwareBaseEntity.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaTenantAwareBaseEntity.java index 880a51167..ccd4a30b1 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaTenantAwareBaseEntity.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaTenantAwareBaseEntity.java @@ -97,6 +97,8 @@ public abstract class AbstractJpaTenantAwareBaseEntity extends AbstractJpaBaseEn * @see org.eclipse.hawkbit.repository.model.BaseEntity#equals(java.lang.Object) */ @Override + // exception squid:S2259 - obj is checked for null in super + @SuppressWarnings("squid:S2259") public boolean equals(final Object obj) { if (!super.equals(obj)) { return false; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetMetadata.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetMetadata.java index 5d176b4a9..3f4323bbe 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetMetadata.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetMetadata.java @@ -67,6 +67,8 @@ public class JpaDistributionSetMetadata extends AbstractJpaMetaData implements D } @Override + // exception squid:S2259 - obj is checked for null in super + @SuppressWarnings("squid:S2259") public boolean equals(final Object obj) { if (!super.equals(obj)) { return false; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTest.java index ecb7f2d37..b4b451ecd 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTest.java @@ -17,8 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.data.mongodb.gridfs.GridFsOperations; -@SpringApplicationConfiguration(classes = { org.eclipse.hawkbit.RepositoryApplicationConfiguration.class, - TestConfiguration.class }) +@SpringApplicationConfiguration(classes = { org.eclipse.hawkbit.RepositoryApplicationConfiguration.class }) public abstract class AbstractJpaIntegrationTest extends AbstractIntegrationTest { @PersistenceContext diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTestWithMongoDB.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTestWithMongoDB.java index 6650d1e3c..d1c433cc4 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTestWithMongoDB.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTestWithMongoDB.java @@ -16,8 +16,7 @@ import org.eclipse.hawkbit.repository.util.AbstractIntegrationTestWithMongoDB; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.SpringApplicationConfiguration; -@SpringApplicationConfiguration(classes = { org.eclipse.hawkbit.RepositoryApplicationConfiguration.class, - TestConfiguration.class }) +@SpringApplicationConfiguration(classes = { org.eclipse.hawkbit.RepositoryApplicationConfiguration.class }) public abstract class AbstractJpaIntegrationTestWithMongoDB extends AbstractIntegrationTestWithMongoDB { @PersistenceContext diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementTest.java index ea6e8e01b..faf7649d0 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementTest.java @@ -32,6 +32,7 @@ import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.ExternalArtifactProvider; import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; +import org.eclipse.hawkbit.repository.util.HashGeneratorUtils; import org.eclipse.hawkbit.repository.util.WithUser; import org.junit.Test; import org.slf4j.LoggerFactory; diff --git a/hawkbit-repository/hawkbit-repository-test/pom.xml b/hawkbit-repository/hawkbit-repository-test/pom.xml index 6b421c8ab..4a05735ac 100644 --- a/hawkbit-repository/hawkbit-repository-test/pom.xml +++ b/hawkbit-repository/hawkbit-repository-test/pom.xml @@ -33,7 +33,11 @@ org.eclipse.hawkbit hawkbit-artifact-repository-mongo ${project.version} - + + + org.springframework + spring-context-support + de.flapdoodle.embed de.flapdoodle.embed.mongo @@ -55,5 +59,17 @@ org.springframework.security spring-security-config + + org.springframework.security + spring-security-aspects + + + org.springframework + spring-test + + + org.springframework.security + spring-security-web + \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/AbstractIntegrationTest.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/AbstractIntegrationTest.java index b8690bc74..c2bd61676 100644 --- a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/AbstractIntegrationTest.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/AbstractIntegrationTest.java @@ -10,11 +10,11 @@ package org.eclipse.hawkbit.repository.util; import org.eclipse.hawkbit.ExcludePathAwareShallowETagFilter; import org.eclipse.hawkbit.repository.ArtifactManagement; -import org.eclipse.hawkbit.repository.RepositoryConstants; import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.EntityFactory; +import org.eclipse.hawkbit.repository.RepositoryConstants; import org.eclipse.hawkbit.repository.RolloutGroupManagement; import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.SoftwareManagement; @@ -39,6 +39,7 @@ import org.junit.runner.RunWith; import org.junit.runners.model.FrameworkMethod; import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.context.EnvironmentAware; import org.springframework.core.env.Environment; import org.springframework.data.auditing.AuditingHandler; @@ -58,6 +59,7 @@ import org.springframework.web.context.WebApplicationContext; @WebAppConfiguration @ActiveProfiles({ "test" }) @WithUser(principal = "bumlux", allSpPermissions = true, authorities = "ROLE_CONTROLLER") +@SpringApplicationConfiguration(classes = { TestConfiguration.class }) // destroy the context after each test class because otherwise we get problem // when context is // refreshed we e.g. get two instances of CacheManager which leads to very diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/HashGeneratorUtils.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/HashGeneratorUtils.java similarity index 74% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/HashGeneratorUtils.java rename to hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/HashGeneratorUtils.java index a94807958..e222007f1 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/HashGeneratorUtils.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/HashGeneratorUtils.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.jpa; +package org.eclipse.hawkbit.repository.util; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; @@ -14,13 +14,10 @@ import java.security.NoSuchAlgorithmException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.google.common.io.BaseEncoding; + /** - * Hash utility calls copied from - * http://www.codejava.net/coding/how-to-calculate-md5-and-sha-hash-values-in- - * java. - * - * - * + * Hash digest utility. */ public final class HashGeneratorUtils { @@ -68,18 +65,11 @@ public final class HashGeneratorUtils { try { final MessageDigest digest = MessageDigest.getInstance(algorithm); final byte[] hashedBytes = digest.digest(message); - return convertByteArrayToHexString(hashedBytes); + return BaseEncoding.base16().lowerCase().encode(hashedBytes); } catch (final NoSuchAlgorithmException e) { - LOG.error("Algorithm could not be find", e); + LOG.error("Algorithm could not be found", e); } return null; } - private static String convertByteArrayToHexString(final byte[] arrayBytes) { - final StringBuilder builder = new StringBuilder(); - for (int i = 0; i < arrayBytes.length; i++) { - builder.append(Integer.toString((arrayBytes[i] & 0xff) + 0x100, 16).substring(1)); - } - return builder.toString(); - } } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/JpaTestRepositoryManagement.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/JpaTestRepositoryManagement.java similarity index 50% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/JpaTestRepositoryManagement.java rename to hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/JpaTestRepositoryManagement.java index 5c4b0efcc..7ec5bb407 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/JpaTestRepositoryManagement.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/JpaTestRepositoryManagement.java @@ -6,77 +6,18 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.jpa; +package org.eclipse.hawkbit.repository.util; import java.util.List; -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; - import org.eclipse.hawkbit.cache.TenantAwareCacheManager; import org.eclipse.hawkbit.repository.SystemManagement; -import org.eclipse.hawkbit.repository.util.TestRepositoryManagement; import org.eclipse.hawkbit.security.SystemSecurityContext; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.mongodb.gridfs.GridFsOperations; import org.springframework.transaction.annotation.Transactional; public class JpaTestRepositoryManagement implements TestRepositoryManagement { - @PersistenceContext - private EntityManager entityManager; - - @Autowired - private TargetRepository targetRepository; - - @Autowired - private ActionRepository actionRepository; - - @Autowired - private DistributionSetRepository distributionSetRepository; - - @Autowired - private SoftwareModuleRepository softwareModuleRepository; - - @Autowired - private TenantMetaDataRepository tenantMetaDataRepository; - - @Autowired - private DistributionSetTypeRepository distributionSetTypeRepository; - - @Autowired - private SoftwareModuleTypeRepository softwareModuleTypeRepository; - - @Autowired - private TargetTagRepository targetTagRepository; - - @Autowired - private DistributionSetTagRepository distributionSetTagRepository; - - @Autowired - private SoftwareModuleMetadataRepository softwareModuleMetadataRepository; - - @Autowired - private ActionStatusRepository actionStatusRepository; - - @Autowired - private ExternalArtifactRepository externalArtifactRepository; - - @Autowired - private LocalArtifactRepository artifactRepository; - - @Autowired - private TargetInfoRepository targetInfoRepository; - - @Autowired - private GridFsOperations operations; - - @Autowired - private RolloutGroupRepository rolloutGroupRepository; - - @Autowired - private RolloutRepository rolloutRepository; - @Autowired private TenantAwareCacheManager cacheManager; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TestConfiguration.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/TestConfiguration.java similarity index 95% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TestConfiguration.java rename to hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/TestConfiguration.java index 8ea794f6a..acbaae2b4 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TestConfiguration.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/TestConfiguration.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.jpa; +package org.eclipse.hawkbit.repository.util; import java.util.concurrent.Executor; import java.util.concurrent.Executors; @@ -16,8 +16,6 @@ import org.eclipse.hawkbit.cache.CacheConstants; import org.eclipse.hawkbit.cache.TenancyCacheManager; import org.eclipse.hawkbit.cache.TenantAwareCacheManager; import org.eclipse.hawkbit.repository.jpa.model.helper.EventBusHolder; -import org.eclipse.hawkbit.repository.util.TestRepositoryManagement; -import org.eclipse.hawkbit.repository.util.TestdataFactory; import org.eclipse.hawkbit.security.DdiSecurityProperties; import org.eclipse.hawkbit.security.SecurityContextTenantAware; import org.eclipse.hawkbit.security.SpringSecurityAuditorAware; diff --git a/hawkbit-rest-core/pom.xml b/hawkbit-rest-core/pom.xml index 1a74f4b3e..bb511839c 100644 --- a/hawkbit-rest-core/pom.xml +++ b/hawkbit-rest-core/pom.xml @@ -21,6 +21,11 @@ + + org.eclipse.hawkbit + hawkbit-repository-api + ${project.version} + org.eclipse.hawkbit hawkbit-repository-jpa @@ -62,13 +67,7 @@ org.easytesting fest-assert test - - - org.eclipse.hawkbit - hawkbit-repository-jpa - ${project.version} - tests - + ru.yandex.qatools.allure allure-junit-adaptor diff --git a/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/util/RestResourceConversionHelper.java b/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/util/RestResourceConversionHelper.java index baa18edb2..875152e0e 100644 --- a/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/util/RestResourceConversionHelper.java +++ b/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/util/RestResourceConversionHelper.java @@ -22,7 +22,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.eclipse.hawkbit.artifact.repository.model.DbArtifact; -import org.eclipse.hawkbit.repository.jpa.cache.CacheWriteNotify; +import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -84,7 +84,7 @@ public final class RestResourceConversionHelper { * from the client * @param file * to be write to the client response - * @param cacheWriteNotify + * @param controllerManagement * to write progress updates to * @param statusId * of the UpdateActionStatus @@ -95,9 +95,9 @@ public final class RestResourceConversionHelper { */ public static ResponseEntity writeFileResponse(final LocalArtifact artifact, final HttpServletResponse response, final HttpServletRequest request, final DbArtifact file, - final CacheWriteNotify cacheWriteNotify, final Long statusId) { + final ControllerManagement controllerManagement, final Long statusId) { - ResponseEntity result = null; + ResponseEntity result; final String etag = artifact.getSha1Hash(); final Long lastModified = artifact.getLastModifiedAt() != null ? artifact.getLastModifiedAt() @@ -143,19 +143,19 @@ public final class RestResourceConversionHelper { // full request - no range if (ranges.isEmpty() || ranges.get(0).equals(full)) { LOG.debug("filename ({}) results into a full request: ", artifact.getFilename()); - fullfileRequest(artifact, response, file, cacheWriteNotify, statusId, full); + fullfileRequest(artifact, response, file, controllerManagement, statusId, full); result = new ResponseEntity<>(HttpStatus.OK); } // standard range request else if (ranges.size() == 1) { LOG.debug("filename ({}) results into a standard range request: ", artifact.getFilename()); - standardRangeRequest(artifact, response, file, cacheWriteNotify, statusId, ranges); + standardRangeRequest(artifact, response, file, controllerManagement, statusId, ranges); result = new ResponseEntity<>(HttpStatus.PARTIAL_CONTENT); } // multipart range request else { LOG.debug("filename ({}) results into a multipart range request: ", artifact.getFilename()); - multipartRangeRequest(artifact, response, file, cacheWriteNotify, statusId, ranges); + multipartRangeRequest(artifact, response, file, controllerManagement, statusId, ranges); result = new ResponseEntity<>(HttpStatus.PARTIAL_CONTENT); } @@ -164,14 +164,15 @@ public final class RestResourceConversionHelper { } private static void fullfileRequest(final LocalArtifact artifact, final HttpServletResponse response, - final DbArtifact file, final CacheWriteNotify cacheWriteNotify, final Long statusId, final ByteRange full) { + final DbArtifact file, final ControllerManagement controllerManagement, final Long statusId, + final ByteRange full) { final ByteRange r = full; response.setHeader(HttpHeaders.CONTENT_RANGE, "bytes " + r.getStart() + "-" + r.getEnd() + "/" + r.getTotal()); response.setHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(r.getLength())); try { - copyStreams(file.getFileInputStream(), response.getOutputStream(), cacheWriteNotify, statusId, r.getStart(), - r.getLength()); + copyStreams(file.getFileInputStream(), response.getOutputStream(), controllerManagement, statusId, + r.getStart(), r.getLength()); } catch (final IOException e) { LOG.error("fullfileRequest of file ({}) failed!", artifact.getFilename(), e); throw new FileSteamingFailedException(artifact.getFilename()); @@ -231,7 +232,7 @@ public final class RestResourceConversionHelper { } private static void multipartRangeRequest(final LocalArtifact artifact, final HttpServletResponse response, - final DbArtifact file, final CacheWriteNotify cacheWriteNotify, final Long statusId, + final DbArtifact file, final ControllerManagement controllerManagement, final Long statusId, final List ranges) { response.setContentType("multipart/byteranges; boundary=" + ByteRange.MULTIPART_BOUNDARY); response.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT); @@ -245,7 +246,7 @@ public final class RestResourceConversionHelper { .println("Content-Range: bytes " + r.getStart() + "-" + r.getEnd() + "/" + r.getTotal()); // Copy single part range of multi part range. - copyStreams(file.getFileInputStream(), response.getOutputStream(), cacheWriteNotify, statusId, + copyStreams(file.getFileInputStream(), response.getOutputStream(), controllerManagement, statusId, r.getStart(), r.getLength()); } @@ -259,7 +260,7 @@ public final class RestResourceConversionHelper { } private static void standardRangeRequest(final LocalArtifact artifact, final HttpServletResponse response, - final DbArtifact file, final CacheWriteNotify cacheWriteNotify, final Long statusId, + final DbArtifact file, final ControllerManagement controllerManagement, final Long statusId, final List ranges) { final ByteRange r = ranges.get(0); response.setHeader(HttpHeaders.CONTENT_RANGE, "bytes " + r.getStart() + "-" + r.getEnd() + "/" + r.getTotal()); @@ -267,8 +268,8 @@ public final class RestResourceConversionHelper { response.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT); try { - copyStreams(file.getFileInputStream(), response.getOutputStream(), cacheWriteNotify, statusId, r.getStart(), - r.getLength()); + copyStreams(file.getFileInputStream(), response.getOutputStream(), controllerManagement, statusId, + r.getStart(), r.getLength()); } catch (final IOException e) { LOG.error("standardRangeRequest of file ({}) failed!", artifact.getFilename(), e); throw new FileSteamingFailedException(artifact.getFilename()); @@ -276,7 +277,7 @@ public final class RestResourceConversionHelper { } private static long copyStreams(final InputStream from, final OutputStream to, - final CacheWriteNotify cacheWriteNotify, final Long statusId, final long start, final long length) + final ControllerManagement controllerManagement, final Long statusId, final long start, final long length) throws IOException { checkNotNull(from); checkNotNull(to); @@ -309,13 +310,13 @@ public final class RestResourceConversionHelper { toContinue = false; } - if (cacheWriteNotify != null) { + if (controllerManagement != null) { final int newPercent = DoubleMath.roundToInt(total * 100.0 / length, RoundingMode.DOWN); // every 10 percent an event if (newPercent == 100 || newPercent > progressPercent + 10) { progressPercent = newPercent; - cacheWriteNotify.downloadProgressPercent(statusId, progressPercent); + controllerManagement.downloadProgressPercent(statusId, progressPercent); } } } diff --git a/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTest.java b/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTest.java index 1b54eed3e..14ba8556e 100644 --- a/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTest.java +++ b/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTest.java @@ -8,7 +8,7 @@ */ package org.eclipse.hawkbit.rest; -import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest; +import org.eclipse.hawkbit.repository.util.AbstractIntegrationTest; import org.eclipse.hawkbit.rest.configuration.RestConfiguration; import org.eclipse.hawkbit.rest.util.FilterHttpResponse; import org.springframework.beans.factory.annotation.Autowired; @@ -18,8 +18,9 @@ import org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder; /** * Abstract Test for Rest tests. */ -@SpringApplicationConfiguration(classes = { RestConfiguration.class }) -public abstract class AbstractRestIntegrationTest extends AbstractJpaIntegrationTest { +@SpringApplicationConfiguration(classes = { RestConfiguration.class, + org.eclipse.hawkbit.RepositoryApplicationConfiguration.class }) +public abstract class AbstractRestIntegrationTest extends AbstractIntegrationTest { @Autowired private FilterHttpResponse filterHttpResponse; diff --git a/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTestWithMongoDB.java b/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTestWithMongoDB.java index 81e2c3d16..4d952434d 100644 --- a/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTestWithMongoDB.java +++ b/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTestWithMongoDB.java @@ -8,7 +8,7 @@ */ package org.eclipse.hawkbit.rest; -import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTestWithMongoDB; +import org.eclipse.hawkbit.repository.util.AbstractIntegrationTestWithMongoDB; import org.eclipse.hawkbit.rest.configuration.RestConfiguration; import org.eclipse.hawkbit.rest.util.FilterHttpResponse; import org.springframework.beans.factory.annotation.Autowired; @@ -18,8 +18,9 @@ import org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder; /** * Abstract Test for Rest tests. */ -@SpringApplicationConfiguration(classes = { RestConfiguration.class }) -public abstract class AbstractRestIntegrationTestWithMongoDB extends AbstractJpaIntegrationTestWithMongoDB { +@SpringApplicationConfiguration(classes = { RestConfiguration.class, + org.eclipse.hawkbit.RepositoryApplicationConfiguration.class }) +public abstract class AbstractRestIntegrationTestWithMongoDB extends AbstractIntegrationTestWithMongoDB { @Autowired private FilterHttpResponse filterHttpResponse; diff --git a/hawkbit-security-integration/pom.xml b/hawkbit-security-integration/pom.xml index 194a5e3cb..455e3ece1 100644 --- a/hawkbit-security-integration/pom.xml +++ b/hawkbit-security-integration/pom.xml @@ -23,7 +23,7 @@ org.eclipse.hawkbit - hawkbit-repository-jpa + hawkbit-repository-api ${project.version} @@ -37,6 +37,12 @@ + + org.eclipse.hawkbit + hawkbit-repository-jpa + ${project.version} + test + junit junit diff --git a/hawkbit-ui/pom.xml b/hawkbit-ui/pom.xml index a9cd5aca3..dadcb264a 100644 --- a/hawkbit-ui/pom.xml +++ b/hawkbit-ui/pom.xml @@ -151,7 +151,7 @@ org.eclipse.hawkbit - hawkbit-repository-jpa + hawkbit-repository-api ${project.version} @@ -229,6 +229,12 @@ + + org.eclipse.hawkbit + hawkbit-repository-jpa + ${project.version} + test + org.mockito mockito-core diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/details/ArtifactBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/details/ArtifactBeanQuery.java index b9bceda3a..80e8a2f4f 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/details/ArtifactBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/details/ArtifactBeanQuery.java @@ -12,8 +12,8 @@ import java.util.List; import java.util.Map; import org.eclipse.hawkbit.repository.ArtifactManagement; +import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; -import org.eclipse.hawkbit.repository.jpa.model.JpaLocalArtifact; import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; @@ -38,6 +38,7 @@ public class ArtifactBeanQuery extends AbstractBeanQuery { private static final long serialVersionUID = -333786310371208962L; private Sort sort = new Sort(Direction.DESC, "filename"); private transient ArtifactManagement artifactManagement = null; + private transient EntityFactory entityFactory; private transient Page firstPagetArtifacts = null; private Long baseSwModuleId = null; @@ -73,7 +74,7 @@ public class ArtifactBeanQuery extends AbstractBeanQuery { @Override protected LocalArtifact constructBean() { - return new JpaLocalArtifact(); + return entityFactory.generateLocalArtifact(); } @Override @@ -116,4 +117,11 @@ public class ArtifactBeanQuery extends AbstractBeanQuery { } return artifactManagement; } + + private EntityFactory getEntityFactory() { + if (entityFactory == null) { + entityFactory = SpringContextHelper.getBean(EntityFactory.class); + } + return entityFactory; + } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/ProxyBaseSoftwareModuleItem.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/ProxyBaseSoftwareModuleItem.java index 14568c307..1559a9bec 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/ProxyBaseSoftwareModuleItem.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/ProxyBaseSoftwareModuleItem.java @@ -10,8 +10,6 @@ package org.eclipse.hawkbit.ui.artifacts.smtable; import java.security.SecureRandom; -import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; - /** * * Proxy for software module to display details in Software modules table. @@ -19,7 +17,7 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; * * */ -public class ProxyBaseSoftwareModuleItem extends JpaSoftwareModule { +public class ProxyBaseSoftwareModuleItem { private static final long serialVersionUID = -1555306616599140635L; @@ -39,6 +37,11 @@ public class ProxyBaseSoftwareModuleItem extends JpaSoftwareModule { private String modifiedByUser; + private String name; + private String version; + private String vendor; + private String description; + /** * Default constructor. */ @@ -47,6 +50,38 @@ public class ProxyBaseSoftwareModuleItem extends JpaSoftwareModule { swId = RANDOM_OBJ.nextLong(); } + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + public String getVersion() { + return version; + } + + public void setVersion(final String version) { + this.version = version; + } + + public String getVendor() { + return vendor; + } + + public void setVendor(final String vendor) { + this.vendor = vendor; + } + + public String getDescription() { + return description; + } + + public void setDescription(final String description) { + this.description = description; + } + public String getCreatedByUser() { return createdByUser; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/DistributionSetIdName.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/DistributionSetIdName.java index c499babcd..66101fbd4 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/DistributionSetIdName.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/DistributionSetIdName.java @@ -22,13 +22,18 @@ public class DistributionSetIdName implements Serializable { private final Long id; private final String name; private final String version; - + public static DistributionSetIdName generate(final DistributionSet distributionSet) { return new DistributionSetIdName(distributionSet.getId(), distributionSet.getName(), distributionSet.getVersion()); } + public static DistributionSetIdName generate(final Long id, final String name, final String version) { + return new DistributionSetIdName(id, name, version); + + } + /** * @param id * the {@link DistributionSet#getId()} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/ProxyDistribution.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/ProxyDistribution.java index a8e7fe9d1..0420f9e4b 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/ProxyDistribution.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/ProxyDistribution.java @@ -8,7 +8,6 @@ */ package org.eclipse.hawkbit.ui.components; -import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.ui.common.DistributionSetIdName; @@ -17,7 +16,7 @@ import org.eclipse.hawkbit.ui.common.DistributionSetIdName; * * */ -public class ProxyDistribution extends JpaDistributionSet { +public class ProxyDistribution { private static final long serialVersionUID = -8891449133620645310L; @@ -35,6 +34,11 @@ public class ProxyDistribution extends JpaDistributionSet { private String nameVersion; + private Long id; + private String name; + private String version; + private String description; + /** * @return the nameVersion */ @@ -43,7 +47,7 @@ public class ProxyDistribution extends JpaDistributionSet { } public DistributionSetIdName getDistributionSetIdName() { - return DistributionSetIdName.generate(this); + return DistributionSetIdName.generate(id, name, version); } /** @@ -102,4 +106,36 @@ public class ProxyDistribution extends JpaDistributionSet { this.modifiedByUser = modifiedByUser; } + public Long getId() { + return id; + } + + public void setId(final Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + public String getVersion() { + return version; + } + + public void setVersion(final String version) { + this.version = version; + } + + public String getDescription() { + return description; + } + + public void setDescription(final String description) { + this.description = description; + } + } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/ProxyTargetFilter.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/ProxyTargetFilter.java index eb3f22dce..9faf501e0 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/ProxyTargetFilter.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/ProxyTargetFilter.java @@ -8,14 +8,12 @@ */ package org.eclipse.hawkbit.ui.components; -import org.eclipse.hawkbit.repository.jpa.model.JpaTargetFilterQuery; - /** * * * */ -public class ProxyTargetFilter extends JpaTargetFilterQuery { +public class ProxyTargetFilter { private static final long serialVersionUID = 6622060929679084419L; @@ -23,6 +21,12 @@ public class ProxyTargetFilter extends JpaTargetFilterQuery { private String modifiedDate; + private String name; + private Long id; + private String createdBy; + private String lastModifiedBy; + private String query; + public String getCreatedDate() { return createdDate; } @@ -46,4 +50,44 @@ public class ProxyTargetFilter extends JpaTargetFilterQuery { this.modifiedDate = modifiedDate; } + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + public Long getId() { + return id; + } + + public void setId(final Long id) { + this.id = id; + } + + public String getLastModifiedBy() { + return lastModifiedBy; + } + + public void setLastModifiedBy(final String lastModifiedBy) { + this.lastModifiedBy = lastModifiedBy; + } + + public String getQuery() { + return query; + } + + public void setQuery(final String query) { + this.query = query; + } + + public String getCreatedBy() { + return createdBy; + } + + public void setCreatedBy(final String createdBy) { + this.createdBy = createdBy; + } + } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionAddUpdateWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionAddUpdateWindowLayout.java index 90b3ad597..2a4e63466 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionAddUpdateWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionAddUpdateWindowLayout.java @@ -19,7 +19,6 @@ import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; -import org.eclipse.hawkbit.repository.jpa.TenantMetaDataRepository; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.TenantMetaData; @@ -92,9 +91,6 @@ public class DistributionAddUpdateWindowLayout extends VerticalLayout { @Autowired private transient SystemManagement systemManagement; - @Autowired - private transient TenantMetaDataRepository tenantMetaDataRepository; - @Autowired private transient EntityFactory entityFactory; @@ -225,8 +221,7 @@ public class DistributionAddUpdateWindowLayout extends VerticalLayout { } private DistributionSetType getDefaultDistributionSetType() { - final TenantMetaData tenantMetaData = tenantMetaDataRepository - .findByTenantIgnoreCase(systemManagement.currentTenant()); + final TenantMetaData tenantMetaData = systemManagement.getTenantMetadata(); return tenantMetaData.getDefaultDsType(); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java index 4074edb55..88e7204aa 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java @@ -10,8 +10,10 @@ package org.eclipse.hawkbit.ui.rollout.rollout; import java.util.Set; -import org.eclipse.hawkbit.repository.jpa.model.JpaRollout; +import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.Rollout.RolloutStatus; import org.eclipse.hawkbit.repository.model.SoftwareModule; +import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RolloutRendererData; import com.vaadin.server.FontAwesome; @@ -20,7 +22,7 @@ import com.vaadin.server.FontAwesome; * Proxy rollout with custom properties. * */ -public class ProxyRollout extends JpaRollout { +public class ProxyRollout { private static final long serialVersionUID = 4539849939617681918L; @@ -46,6 +48,17 @@ public class ProxyRollout extends JpaRollout { private Set swModules; + private Long id; + private String name; + private String version; + private String description; + private DistributionSet distributionSet; + private String createdBy; + private String lastModifiedBy; + private long forcedTime; + private RolloutStatus status; + private TotalTargetCountStatus totalTargetCountStatus; + /** * @return the isRequiredMigrationStep */ @@ -214,4 +227,83 @@ public class ProxyRollout extends JpaRollout { return FontAwesome.CIRCLE_O.getHtml(); } + public Long getId() { + return id; + } + + public void setId(final Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + public String getVersion() { + return version; + } + + public void setVersion(final String version) { + this.version = version; + } + + public String getDescription() { + return description; + } + + public void setDescription(final String description) { + this.description = description; + } + + public DistributionSet getDistributionSet() { + return distributionSet; + } + + public void setDistributionSet(final DistributionSet distributionSet) { + this.distributionSet = distributionSet; + } + + public String getCreatedBy() { + return createdBy; + } + + public void setCreatedBy(final String createdBy) { + this.createdBy = createdBy; + } + + public String getLastModifiedBy() { + return lastModifiedBy; + } + + public void setLastModifiedBy(final String lastModifiedBy) { + this.lastModifiedBy = lastModifiedBy; + } + + public long getForcedTime() { + return forcedTime; + } + + public void setForcedTime(final long forcedTime) { + this.forcedTime = forcedTime; + } + + public RolloutStatus getStatus() { + return status; + } + + public void setStatus(final RolloutStatus status) { + this.status = status; + } + + public TotalTargetCountStatus getTotalTargetCountStatus() { + return totalTargetCountStatus; + } + + public void setTotalTargetCountStatus(final TotalTargetCountStatus totalTargetCountStatus) { + this.totalTargetCountStatus = totalTargetCountStatus; + } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java index 8a9675564..0bfa349d0 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java @@ -138,8 +138,6 @@ public class RolloutBeanQuery extends AbstractBeanQuery { final TotalTargetCountStatus totalTargetCountActionStatus = rollout.getTotalTargetCountStatus(); proxyRollout.setTotalTargetCountStatus(totalTargetCountActionStatus); proxyRollout.setTotalTargetsCount(String.valueOf(rollout.getTotalTargets())); - - proxyRollout.setDescription(distributionSet.getDescription()); proxyRollout.setType(distributionSet.getType().getName()); proxyRollout.setIsRequiredMigrationStep(distributionSet.isRequiredMigrationStep()); proxyRollout.setSwModules(distributionSet.getModules()); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java index f6653d971..05a6ec410 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java @@ -8,14 +8,19 @@ */ package org.eclipse.hawkbit.ui.rollout.rolloutgroup; -import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup; +import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupErrorAction; +import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupErrorCondition; +import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupStatus; +import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupSuccessAction; +import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupSuccessCondition; +import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RolloutRendererData; /** * Proxy rollout group with renderer properties. * */ -public class ProxyRolloutGroup extends JpaRolloutGroup { +public class ProxyRolloutGroup { private static final long serialVersionUID = -2745056813306692356L; @@ -41,6 +46,23 @@ public class ProxyRolloutGroup extends JpaRolloutGroup { private String totalTargetsCount; + private Long id; + private String name; + private String description; + private String createdBy; + private String lastModifiedBy; + private RolloutGroupStatus status; + private TotalTargetCountStatus totalTargetCountStatus; + + private RolloutGroupSuccessCondition successCondition; + private String successConditionExp; + private RolloutGroupSuccessAction successAction; + private String successActionExp; + private RolloutGroupErrorCondition errorCondition; + private String errorConditionExp; + private RolloutGroupErrorAction errorAction; + private String errorActionExp; + private RolloutRendererData rolloutRendererData; public RolloutRendererData getRolloutRendererData() { @@ -216,4 +238,124 @@ public class ProxyRolloutGroup extends JpaRolloutGroup { this.totalTargetsCount = totalTargetsCount; } + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + public Long getId() { + return id; + } + + public void setId(final Long id) { + this.id = id; + } + + public String getDescription() { + return description; + } + + public void setDescription(final String description) { + this.description = description; + } + + public String getCreatedBy() { + return createdBy; + } + + public void setCreatedBy(final String createdBy) { + this.createdBy = createdBy; + } + + public String getLastModifiedBy() { + return lastModifiedBy; + } + + public void setLastModifiedBy(final String lastModifiedBy) { + this.lastModifiedBy = lastModifiedBy; + } + + public RolloutGroupStatus getStatus() { + return status; + } + + public void setStatus(final RolloutGroupStatus status) { + this.status = status; + } + + public TotalTargetCountStatus getTotalTargetCountStatus() { + return totalTargetCountStatus; + } + + public void setTotalTargetCountStatus(final TotalTargetCountStatus totalTargetCountStatus) { + this.totalTargetCountStatus = totalTargetCountStatus; + } + + public RolloutGroupSuccessCondition getSuccessCondition() { + return successCondition; + } + + public void setSuccessCondition(final RolloutGroupSuccessCondition successCondition) { + this.successCondition = successCondition; + } + + public String getSuccessConditionExp() { + return successConditionExp; + } + + public void setSuccessConditionExp(final String successConditionExp) { + this.successConditionExp = successConditionExp; + } + + public RolloutGroupSuccessAction getSuccessAction() { + return successAction; + } + + public void setSuccessAction(final RolloutGroupSuccessAction successAction) { + this.successAction = successAction; + } + + public String getSuccessActionExp() { + return successActionExp; + } + + public void setSuccessActionExp(final String successActionExp) { + this.successActionExp = successActionExp; + } + + public RolloutGroupErrorCondition getErrorCondition() { + return errorCondition; + } + + public void setErrorCondition(final RolloutGroupErrorCondition errorCondition) { + this.errorCondition = errorCondition; + } + + public String getErrorConditionExp() { + return errorConditionExp; + } + + public void setErrorConditionExp(final String errorConditionExp) { + this.errorConditionExp = errorConditionExp; + } + + public RolloutGroupErrorAction getErrorAction() { + return errorAction; + } + + public void setErrorAction(final RolloutGroupErrorAction errorAction) { + this.errorAction = errorAction; + } + + public String getErrorActionExp() { + return errorActionExp; + } + + public void setErrorActionExp(final String errorActionExp) { + this.errorActionExp = errorActionExp; + } + } From 1881880cd95877013ff464448cf8744acd1b6947 Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Wed, 1 Jun 2016 09:21:51 +0200 Subject: [PATCH 41/54] Added findactions method. Signed-off-by: Kai Zimmermann --- .../hawkbit/repository/DeploymentManagement.java | 10 ++++++++++ .../repository/jpa/JpaDeploymentManagement.java | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java index 1c2c71f8e..9dc5f74c8 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java @@ -286,6 +286,16 @@ public interface DeploymentManagement { @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) Slice findActionsByTarget(@NotNull Pageable pageable, @NotNull Target target); + /** + * Retrieves all {@link Action}s from repository. + * + * @param pageable + * pagination parameter + * @return a paged list of {@link Action}s + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + Slice findActionsAll(@NotNull Pageable pageable); + /** * Retrieves all {@link Action} which assigned to a specific * {@link DistributionSet}. diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java index 6f3a876b8..4739f16a7 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java @@ -706,4 +706,9 @@ public class JpaDeploymentManagement implements DeploymentManagement { public Slice findActionsByDistributionSet(final Pageable pageable, final DistributionSet ds) { return actionRepository.findByDistributionSet(pageable, (JpaDistributionSet) ds); } + + @Override + public Slice findActionsAll(final Pageable pageable) { + return convertAcPage(actionRepository.findAll(pageable), pageable); + } } From 615cbe230843cb3185f0f35ec4aa58fdc7075347 Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Wed, 1 Jun 2016 13:17:40 +0200 Subject: [PATCH 42/54] Added null check for selected target --- .../hawkbit-repository-jpa/.gitignore | 1 + .../actionhistory/ActionHistoryTable.java | 22 +++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) create mode 100644 hawkbit-repository/hawkbit-repository-jpa/.gitignore diff --git a/hawkbit-repository/hawkbit-repository-jpa/.gitignore b/hawkbit-repository/hawkbit-repository-jpa/.gitignore new file mode 100644 index 000000000..ae3c17260 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-jpa/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/actionhistory/ActionHistoryTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/actionhistory/ActionHistoryTable.java index b571bb3df..f4cf633cb 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/actionhistory/ActionHistoryTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/actionhistory/ActionHistoryTable.java @@ -69,14 +69,15 @@ import com.vaadin.ui.UI; import com.vaadin.ui.themes.ValoTheme; /** - * + * Table for {@link Target#getActions()} history. * */ - @SpringComponent @ViewScope public class ActionHistoryTable extends TreeTable implements Handler { + private static final String BUTTON_CANCEL = "button.cancel"; + private static final String BUTTON_OK = "button.ok"; private static final long serialVersionUID = -1631514704696786653L; @Autowired private I18N i18n; @@ -241,11 +242,14 @@ public class ActionHistoryTable extends TreeTable implements Handler { private void getcontainerData() { hierarchicalContainer.removeAllItems(); - /* service method to create action history for target */ - final List actionHistory = deploymentManagement + + if (target != null) { + /* service method to create action history for target */ + final List actionHistory = deploymentManagement .findActionsWithStatusCountByTargetOrderByIdDesc(target); - - addDetailsToContainer(actionHistory); + + addDetailsToContainer(actionHistory); + } } /** @@ -751,7 +755,7 @@ public class ActionHistoryTable extends TreeTable implements Handler { private void confirmAndForceAction(final Long actionId) { /* Display the confirmation */ final ConfirmationDialog confirmDialog = new ConfirmationDialog(i18n.get("caption.force.action.confirmbox"), - i18n.get("message.force.action.confirm"), i18n.get("button.ok"), i18n.get("button.cancel"), ok -> { + i18n.get("message.force.action.confirm"), i18n.get(BUTTON_OK), i18n.get(BUTTON_CANCEL), ok -> { if (ok) { /* cancel the action */ deploymentManagement.forceTargetAction(actionId); @@ -773,7 +777,7 @@ public class ActionHistoryTable extends TreeTable implements Handler { private void confirmAndForceQuitAction(final Long actionId) { /* Display the confirmation */ final ConfirmationDialog confirmDialog = new ConfirmationDialog(i18n.get("caption.forcequit.action.confirmbox"), - i18n.get("message.forcequit.action.confirm"), i18n.get("button.ok"), i18n.get("button.cancel"), ok -> { + i18n.get("message.forcequit.action.confirm"), i18n.get(BUTTON_OK), i18n.get(BUTTON_CANCEL), ok -> { if (ok) { final boolean cancelResult = forceQuitActiveAction(actionId); if (cancelResult) { @@ -801,7 +805,7 @@ public class ActionHistoryTable extends TreeTable implements Handler { */ private void confirmAndCancelAction(final Long actionId) { final ConfirmationDialog confirmDialog = new ConfirmationDialog(i18n.get("caption.cancel.action.confirmbox"), - i18n.get("message.cancel.action.confirm"), i18n.get("button.ok"), i18n.get("button.cancel"), ok -> { + i18n.get("message.cancel.action.confirm"), i18n.get(BUTTON_OK), i18n.get(BUTTON_CANCEL), ok -> { if (ok) { final boolean cancelResult = cancelActiveAction(actionId); if (cancelResult) { From 561e6b970676badda3bd70b634d686376d7ae074 Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Wed, 1 Jun 2016 13:51:42 +0200 Subject: [PATCH 43/54] Fixed event processing. Signed-off-by: Kai Zimmermann --- .../repository/jpa/model/EntityPropertyChangeListener.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/EntityPropertyChangeListener.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/EntityPropertyChangeListener.java index cc0041646..2dd0fdb40 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/EntityPropertyChangeListener.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/EntityPropertyChangeListener.java @@ -52,13 +52,13 @@ public class EntityPropertyChangeListener extends DescriptorEventAdapter { @Override public void postUpdate(final DescriptorEvent event) { - if (event.getObject().getClass().equals(Action.class)) { + if (event.getObject().getClass().equals(JpaAction.class)) { getAfterTransactionCommmitExecutor().afterCommit(() -> getEventBus().post( new ActionPropertyChangeEvent((Action) event.getObject(), getChangeSet(Action.class, event)))); - } else if (event.getObject().getClass().equals(Rollout.class)) { + } else if (event.getObject().getClass().equals(JpaRollout.class)) { getAfterTransactionCommmitExecutor().afterCommit(() -> getEventBus().post( new RolloutPropertyChangeEvent((Rollout) event.getObject(), getChangeSet(Rollout.class, event)))); - } else if (event.getObject().getClass().equals(RolloutGroup.class)) { + } else if (event.getObject().getClass().equals(JpaRolloutGroup.class)) { getAfterTransactionCommmitExecutor().afterCommit( () -> getEventBus().post(new RolloutGroupPropertyChangeEvent((RolloutGroup) event.getObject(), getChangeSet(RolloutGroup.class, event)))); From 935ca2f963ceaf783a536ddb53b564e7926670b7 Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Thu, 2 Jun 2016 08:20:55 +0200 Subject: [PATCH 44/54] Fixed broken repo access security checks. Signed-off-by: Kai Zimmermann --- .../eclipse/hawkbit/repository/ControllerManagement.java | 1 - .../hawkbit/repository/jpa/JpaControllerManagement.java | 9 +++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java index f8615bcc3..531da8819 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java @@ -177,7 +177,6 @@ public interface ControllerManagement { * @return the security context of the target, in case no target exists for * the given controllerId {@code null} is returned */ - @PreAuthorize(SpringEvalExpressions.IS_CONTROLLER) String getSecurityTokenByControllerId(@NotEmpty String controllerId); /** diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java index 80de385c8..77b71e661 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java @@ -47,6 +47,7 @@ import org.eclipse.hawkbit.repository.model.TargetInfo; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; import org.eclipse.hawkbit.repository.model.TenantConfiguration; import org.eclipse.hawkbit.security.HawkbitSecurityProperties; +import org.eclipse.hawkbit.security.SystemSecurityContext; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -102,6 +103,9 @@ public class JpaControllerManagement implements ControllerManagement { @Autowired private CacheWriteNotify cacheWriteNotify; + @Autowired + private SystemSecurityContext systemSecurityContext; + @Override public String getPollingTime() { final TenantConfigurationKey configurationKey = TenantConfigurationKey.POLLING_TIME_INTERVAL; @@ -109,8 +113,9 @@ public class JpaControllerManagement implements ControllerManagement { JpaTenantConfigurationManagement.validateTenantConfigurationDataType(configurationKey, propertyType); final TenantConfiguration tenantConfiguration = tenantConfigurationRepository .findByKey(configurationKey.getKeyName()); - return tenantConfigurationManagement - .buildTenantConfigurationValueByKey(configurationKey, propertyType, tenantConfiguration).getValue(); + + return systemSecurityContext.runAsSystem(() -> tenantConfigurationManagement + .buildTenantConfigurationValueByKey(configurationKey, propertyType, tenantConfiguration).getValue()); } @Override From 5d17a7d5c3b764d7a1594c09525debe6d6d90fcc Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Thu, 2 Jun 2016 08:50:37 +0200 Subject: [PATCH 45/54] Added sonar exceptions. Signed-off-by: Kai Zimmermann --- .../org/eclipse/hawkbit/simulator/DeviceSimulatorUpdater.java | 4 ++++ .../eclipse/hawkbit/artifact/repository/ArtifactStore.java | 3 +++ .../AfterTransactionCommitDefaultServiceExecutor.java | 3 +++ .../repository/jpa/model/JpaSoftwareModuleMetadata.java | 2 ++ .../org/eclipse/hawkbit/security/SystemSecurityContext.java | 2 ++ 5 files changed, 14 insertions(+) diff --git a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/DeviceSimulatorUpdater.java b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/DeviceSimulatorUpdater.java index 34c5f548e..0931f6f3e 100644 --- a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/DeviceSimulatorUpdater.java +++ b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/DeviceSimulatorUpdater.java @@ -236,6 +236,10 @@ public class DeviceSimulatorUpdater { } final File tempFile = File.createTempFile("uploadFile", null); + + // Exception squid:S2070 - not used for hashing sensitive + // data + @SuppressWarnings("squid:S2070") final MessageDigest md = MessageDigest.getInstance("SHA-1"); try (final DigestOutputStream dos = new DigestOutputStream(new FileOutputStream(tempFile), md)) { diff --git a/hawkbit-artifact-repository-mongo/src/main/java/org/eclipse/hawkbit/artifact/repository/ArtifactStore.java b/hawkbit-artifact-repository-mongo/src/main/java/org/eclipse/hawkbit/artifact/repository/ArtifactStore.java index af60a39c8..aa9ff3409 100644 --- a/hawkbit-artifact-repository-mongo/src/main/java/org/eclipse/hawkbit/artifact/repository/ArtifactStore.java +++ b/hawkbit-artifact-repository-mongo/src/main/java/org/eclipse/hawkbit/artifact/repository/ArtifactStore.java @@ -205,6 +205,9 @@ public class ArtifactStore implements ArtifactRepository { throws NoSuchAlgorithmException, IOException { String sha1Hash; // compute digest + // Exception squid:S2070 - not used for hashing sensitive + // data + @SuppressWarnings("squid:S2070") final MessageDigest md = MessageDigest.getInstance("SHA-1"); try (final DigestOutputStream dos = new DigestOutputStream(os, md)) { ByteStreams.copy(stream, dos); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/executor/AfterTransactionCommitDefaultServiceExecutor.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/executor/AfterTransactionCommitDefaultServiceExecutor.java index 687c1e3d4..6c58a0207 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/executor/AfterTransactionCommitDefaultServiceExecutor.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/executor/AfterTransactionCommitDefaultServiceExecutor.java @@ -45,6 +45,8 @@ public class AfterTransactionCommitDefaultServiceExecutor extends TransactionSyn } @Override + // Exception squid:S1217 - we want to run this synchronous + @SuppressWarnings("squid:S1217") public void afterCommit(final Runnable runnable) { LOGGER.debug("Submitting new runnable {} to run after transaction commit", runnable); if (TransactionSynchronizationManager.isSynchronizationActive()) { @@ -58,6 +60,7 @@ public class AfterTransactionCommitDefaultServiceExecutor extends TransactionSyn return; } LOGGER.info("Transaction synchronization is NOT ACTIVE/ INACTIVE. Executing right now runnable {}", runnable); + runnable.run(); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModuleMetadata.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModuleMetadata.java index 53ce08ca9..e8972eb97 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModuleMetadata.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModuleMetadata.java @@ -68,6 +68,8 @@ public class JpaSoftwareModuleMetadata extends AbstractJpaMetaData implements So } @Override + // exception squid:S2259 - obj is checked for null in super + @SuppressWarnings("squid:S2259") public boolean equals(final Object obj) { if (!super.equals(obj)) { return false; diff --git a/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/security/SystemSecurityContext.java b/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/security/SystemSecurityContext.java index f849eb541..78fb5818d 100644 --- a/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/security/SystemSecurityContext.java +++ b/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/security/SystemSecurityContext.java @@ -64,6 +64,8 @@ public class SystemSecurityContext { * the callable to call within the system security context * @return the return value of the {@link Callable#call()} method. */ + // Exception squid:S2221 - Callable declares Exception + @SuppressWarnings("squid:S2221") public T runAsSystem(final Callable callable) { final SecurityContext oldContext = SecurityContextHolder.getContext(); try { From 8c904f900eb46627651f86bd75b18765aa34ea0e Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Thu, 2 Jun 2016 08:51:31 +0200 Subject: [PATCH 46/54] Ignoring springBeans meta file. Signed-off-by: Kai Zimmermann --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 8cd3d476e..e49219859 100644 --- a/.gitignore +++ b/.gitignore @@ -53,3 +53,5 @@ local.properties # Maven maven.properties /*/maven.properties + +hawkbit-repository/hawkbit-repository-jpa/.springBeans From 1fe267c5c35f05615a1c49df552faa62cca4bcd2 Mon Sep 17 00:00:00 2001 From: Asharani Date: Thu, 2 Jun 2016 15:50:29 +0530 Subject: [PATCH 47/54] Re-added component id's in SPUIComponenetIdProvider Signed-off-by: Asharani --- .../ui/artifacts/upload/UploadLayout.java | 2 +- .../upload/UploadStatusInfoWindow.java | 10 ++++---- .../ui/utils/SPUIComponentIdProvider.java | 24 +++++++++++++++++++ 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java index 3be271e3c..05c175ead 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java @@ -793,7 +793,7 @@ public class UploadLayout extends VerticalLayout { } private void createUploadStatusButton() { - uploadStatusButton = SPUIComponentProvider.getButton(SPUIComponetIdProvider.UPLOAD_STATUS_BUTTON, "", "", "", + uploadStatusButton = SPUIComponentProvider.getButton(SPUIComponentIdProvider.UPLOAD_STATUS_BUTTON, "", "", "", false, null, SPUIButtonStyleSmall.class); uploadStatusButton.setStyleName(SPUIStyleDefinitions.ACTION_BUTTON); uploadStatusButton.addStyleName(SPUIStyleDefinitions.UPLOAD_PROGRESS_INDICATOR_STYLE); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusInfoWindow.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusInfoWindow.java index e4ab8d474..a58c6ea14 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusInfoWindow.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusInfoWindow.java @@ -24,7 +24,7 @@ import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.I18N; -import org.eclipse.hawkbit.ui.utils.SPUIComponetIdProvider; +import org.eclipse.hawkbit.ui.utils.SPUIComponentIdProvider; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; import org.springframework.beans.factory.annotation.Autowired; @@ -190,7 +190,7 @@ public class UploadStatusInfoWindow extends Window { } private void setPopupProperties() { - setId(SPUIComponetIdProvider.UPLOAD_STATUS_POPUP_ID); + setId(SPUIComponentIdProvider.UPLOAD_STATUS_POPUP_ID); addStyleName(SPUIStyleDefinitions.UPLOAD_INFO); setImmediate(true); setResizable(false); @@ -411,7 +411,7 @@ public class UploadStatusInfoWindow extends Window { private Button getMinimizeButton() { final Button minimizeBtn = SPUIComponentProvider.getButton( - SPUIComponetIdProvider.UPLOAD_STATUS_POPUP_MINIMIZE_BUTTON_ID, "", "", "", true, FontAwesome.MINUS, + SPUIComponentIdProvider.UPLOAD_STATUS_POPUP_MINIMIZE_BUTTON_ID, "", "", "", true, FontAwesome.MINUS, SPUIButtonStyleSmallNoBorder.class); minimizeBtn.addStyleName(ValoTheme.BUTTON_BORDERLESS); minimizeBtn.addClickListener(event -> minimizeWindow()); @@ -421,7 +421,7 @@ public class UploadStatusInfoWindow extends Window { private Button getResizeButton() { final Button resizeBtn = SPUIComponentProvider.getButton( - SPUIComponetIdProvider.UPLOAD_STATUS_POPUP_RESIZE_BUTTON_ID, "", "", "", true, FontAwesome.EXPAND, + SPUIComponentIdProvider.UPLOAD_STATUS_POPUP_RESIZE_BUTTON_ID, "", "", "", true, FontAwesome.EXPAND, SPUIButtonStyleSmallNoBorder.class); resizeBtn.addStyleName(ValoTheme.BUTTON_BORDERLESS); resizeBtn.addClickListener(event -> resizeWindow(event)); @@ -455,7 +455,7 @@ public class UploadStatusInfoWindow extends Window { private Button getCloseButton() { final Button closeBtn = SPUIComponentProvider.getButton( - SPUIComponetIdProvider.UPLOAD_STATUS_POPUP_CLOSE_BUTTON_ID, "", "", "", true, FontAwesome.TIMES, + SPUIComponentIdProvider.UPLOAD_STATUS_POPUP_CLOSE_BUTTON_ID, "", "", "", true, FontAwesome.TIMES, SPUIButtonStyleSmallNoBorder.class); closeBtn.addStyleName(ValoTheme.BUTTON_BORDERLESS); closeBtn.addClickListener(event -> onClose()); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIComponentIdProvider.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIComponentIdProvider.java index 80d40104a..6649b12fe 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIComponentIdProvider.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/utils/SPUIComponentIdProvider.java @@ -888,6 +888,30 @@ public final class SPUIComponentIdProvider { */ public static final String VALIDATION_STATUS_ICON_ID = "validation.status.icon"; + /** + * Artifact upload status popup - minimize button id. + */ + public static final String UPLOAD_STATUS_POPUP_MINIMIZE_BUTTON_ID = "artifact.upload.minimize.button.id"; + + /** + * Artifact upload status popup - close button id. + */ + public static final String UPLOAD_STATUS_POPUP_CLOSE_BUTTON_ID = "artifact.upload.close.button.id"; + + /** + * Artifact upload status popup - resize button id. + */ + public static final String UPLOAD_STATUS_POPUP_RESIZE_BUTTON_ID = "artifact.upload.resize.button.id"; + + /** + * Artifact upload view - upload status button id. + */ + public static final String UPLOAD_STATUS_BUTTON = "artficat.upload.status.button.id"; + + /** + * Artifact uplaod view - uplod status popup id. + */ + public static final String UPLOAD_STATUS_POPUP_ID = "artifact.upload.status.popup.id"; /** * /* Private Constructor. */ From e12fcd804efec0dec28dae37e102a5d74f6c14ff Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Thu, 2 Jun 2016 14:08:37 +0200 Subject: [PATCH 48/54] Fixed default ds gen. Signed-off-by: Kai Zimmermann --- .../rest/resource/MgmtDistributionSetResourceTest.java | 2 +- .../hawkbit/repository/jpa/JpaSystemManagement.java | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java index 8c15e0a8c..ad72aa55d 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java @@ -789,7 +789,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest final int amount = 10; testdataFactory.createDistributionSets(amount); distributionSetManagement.createDistributionSet(entityFactory.generateDistributionSet("incomplete", "2", - "incomplete", distributionSetManagement.findDistributionSetTypeByKey("ecl_os"), null)); + "incomplete", distributionSetManagement.findDistributionSetTypeByKey("os"), null)); final String rsqlFindLikeDs1OrDs2 = "complete==" + Boolean.TRUE; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java index 8f9e8c5f9..ab5fc1b41 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java @@ -288,11 +288,11 @@ public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, Syst final SoftwareModuleType os = softwareModuleTypeRepository .save(new JpaSoftwareModuleType("os", "Firmware", "Core firmware or operationg system", 1)); - distributionSetTypeRepository.save((JpaDistributionSetType) new JpaDistributionSetType("os_app", "With app(s)", - "Default type with Firmware/OS and optional app(s).").addMandatoryModuleType(os) - .addOptionalModuleType(app)); - - return distributionSetTypeRepository.save((JpaDistributionSetType) new JpaDistributionSetType("os", "OS only", + distributionSetTypeRepository.save((JpaDistributionSetType) new JpaDistributionSetType("os", "OS only", "Default type with Firmware/OS only.").addMandatoryModuleType(os)); + + return distributionSetTypeRepository.save((JpaDistributionSetType) new JpaDistributionSetType("os_app", + "OS with app(s)", "Default type with Firmware/OS and optional app(s).").addMandatoryModuleType(os) + .addOptionalModuleType(app)); } } From 2769170c47ec52d83d506f5b3d8aa7340fde738e Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Thu, 2 Jun 2016 15:13:49 +0200 Subject: [PATCH 49/54] Created constants in API for default tenant type setup. Signed-off-by: Kai Zimmermann --- .../hawkbit-example-mgmt-simulator/.gitignore | 1 + .../softwaremodule/MgmtSoftwareModule.java | 13 ----- hawkbit-repository/.gitignore | 1 + .../eclipse/hawkbit/repository/Constants.java | 58 +++++++++++++++++++ .../repository/jpa/JpaSystemManagement.java | 22 ++++--- .../jpa/rsql/RSQLSoftwareModuleFieldTest.java | 7 ++- 6 files changed, 77 insertions(+), 25 deletions(-) create mode 100644 hawkbit-repository/.gitignore create mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/Constants.java diff --git a/examples/hawkbit-example-mgmt-simulator/.gitignore b/examples/hawkbit-example-mgmt-simulator/.gitignore index 4b9b73073..b5c3eb864 100644 --- a/examples/hawkbit-example-mgmt-simulator/.gitignore +++ b/examples/hawkbit-example-mgmt-simulator/.gitignore @@ -1,3 +1,4 @@ /target/ /bin/ /.apt_generated/ +/.springBeans diff --git a/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/json/model/softwaremodule/MgmtSoftwareModule.java b/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/json/model/softwaremodule/MgmtSoftwareModule.java index ec4a48e89..08b723198 100644 --- a/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/json/model/softwaremodule/MgmtSoftwareModule.java +++ b/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/json/model/softwaremodule/MgmtSoftwareModule.java @@ -23,19 +23,6 @@ import com.fasterxml.jackson.annotation.JsonProperty; @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) public class MgmtSoftwareModule extends MgmtNamedEntity { - /** - * API definition for Software module type#RUNTIME. - */ - public static final String SM_RUNTIME = "runtime"; - /** - * API definition for for Software module type#OS. - */ - public static final String SM_OS = "os"; - /** - * API definition for for Software module type#APPLICATION. - */ - public static final String SM_APPLICATION = "application"; - @JsonProperty(value = "id", required = true) private Long moduleId; diff --git a/hawkbit-repository/.gitignore b/hawkbit-repository/.gitignore new file mode 100644 index 000000000..6a3b2b405 --- /dev/null +++ b/hawkbit-repository/.gitignore @@ -0,0 +1 @@ +/.springBeans diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/Constants.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/Constants.java new file mode 100644 index 000000000..6ccb4bc82 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/Constants.java @@ -0,0 +1,58 @@ +/** + * Copyright (c) 2011-2016 Bosch Software Innovations GmbH, Germany. All rights reserved. + */ +package org.eclipse.hawkbit.repository; + +import org.eclipse.hawkbit.repository.model.DistributionSetType; +import org.eclipse.hawkbit.repository.model.SoftwareModuleType; + +/** + * Repository API constants. + * + */ +public final class Constants { + /** + * Default {@link SoftwareModuleType} generated by repository for every new + * account for Firmware/Operating System. + */ + public static final String SMT_DEFAULT_OS_KEY = "os"; + /** + * Default {@link SoftwareModuleType} generated by repository for every new + * account for applications. + */ + public static final String SMT_DEFAULT_APP_KEY = "application"; + + /** + * {@link DistributionSetType#getKey()} of a {@link DistributionSetType} + * generated by repository for every new account that includes + * {@link #SMT_DEFAULT_OS_KEY} as mandatory module and optional + * {@link #SMT_DEFAULT_APP_KEY}s. + */ + public static final String DST_DEFAULT_OS_WITH_APPS_KEY = "os_app"; + + /** + * {@link DistributionSetType#getName()} of a {@link DistributionSetType} + * generated by repository for every new account that includes + * {@link #SMT_DEFAULT_OS_KEY} as mandatory module and optional + * {@link #SMT_DEFAULT_APP_KEY}s. + */ + public static final String DST_DEFAULT_OS_WITH_APPS_NAME = "OS with app(s)"; + + /** + * {@link DistributionSetType#getKey()} of a {@link DistributionSetType} + * generated by repository for every new account that includes only + * {@link #SMT_DEFAULT_OS_KEY} as mandatory module. + */ + public static final String DST_DEFAULT_OS_ONLY_KEY = "os"; + + /** + * {@link DistributionSetType#getName()} of a {@link DistributionSetType} + * generated by repository for every new account that includes only + * {@link #SMT_DEFAULT_OS_KEY} as mandatory module. + */ + public static final String DST_DEFAULT_OS_ONLY_NAME = "OS only"; + + private Constants() { + // Utility class. + } +} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java index ab5fc1b41..a2865c4b0 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java @@ -16,6 +16,7 @@ import java.util.stream.Collectors; import javax.persistence.EntityManager; import org.eclipse.hawkbit.cache.TenancyCacheManager; +import org.eclipse.hawkbit.repository.Constants; import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.repository.TenantStatsManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; @@ -283,16 +284,19 @@ public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, Syst } private DistributionSetType createStandardSoftwareDataSetup() { - final SoftwareModuleType app = softwareModuleTypeRepository - .save(new JpaSoftwareModuleType("application", "Application", "Application Addons", Integer.MAX_VALUE)); - final SoftwareModuleType os = softwareModuleTypeRepository - .save(new JpaSoftwareModuleType("os", "Firmware", "Core firmware or operationg system", 1)); + final SoftwareModuleType app = softwareModuleTypeRepository.save(new JpaSoftwareModuleType( + Constants.SMT_DEFAULT_APP_KEY, "Application", "Application Addons", Integer.MAX_VALUE)); + final SoftwareModuleType os = softwareModuleTypeRepository.save(new JpaSoftwareModuleType( + Constants.SMT_DEFAULT_OS_KEY, "Firmware", "Core firmware or operationg system", 1)); - distributionSetTypeRepository.save((JpaDistributionSetType) new JpaDistributionSetType("os", "OS only", - "Default type with Firmware/OS only.").addMandatoryModuleType(os)); + distributionSetTypeRepository + .save((JpaDistributionSetType) new JpaDistributionSetType(Constants.DST_DEFAULT_OS_ONLY_KEY, + Constants.DST_DEFAULT_OS_ONLY_NAME, "Default type with Firmware/OS only.") + .addMandatoryModuleType(os)); - return distributionSetTypeRepository.save((JpaDistributionSetType) new JpaDistributionSetType("os_app", - "OS with app(s)", "Default type with Firmware/OS and optional app(s).").addMandatoryModuleType(os) - .addOptionalModuleType(app)); + return distributionSetTypeRepository + .save((JpaDistributionSetType) new JpaDistributionSetType(Constants.DST_DEFAULT_OS_WITH_APPS_KEY, + Constants.DST_DEFAULT_OS_WITH_APPS_NAME, "Default type with Firmware/OS and optional app(s).") + .addMandatoryModuleType(os).addOptionalModuleType(app)); } } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleFieldTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleFieldTest.java index d55de383f..47732dac2 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleFieldTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleFieldTest.java @@ -16,6 +16,7 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleMetadata; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata; +import org.eclipse.hawkbit.repository.util.TestdataFactory; import org.junit.Before; import org.junit.Test; import org.springframework.data.domain.Page; @@ -84,10 +85,10 @@ public class RSQLSoftwareModuleFieldTest extends AbstractJpaIntegrationTest { @Test @Description("Test filter software module by type") public void testFilterByType() { - assertRSQLQuery(SoftwareModuleFields.TYPE.name() + "==application", 2); + assertRSQLQuery(SoftwareModuleFields.TYPE.name() + "==" + TestdataFactory.SM_TYPE_APP, 2); assertRSQLQuery(SoftwareModuleFields.TYPE.name() + "==noExist*", 0); - assertRSQLQuery(SoftwareModuleFields.TYPE.name() + "=in=(application)", 2); - assertRSQLQuery(SoftwareModuleFields.TYPE.name() + "=out=(application)", 2); + assertRSQLQuery(SoftwareModuleFields.TYPE.name() + "=in=(" + TestdataFactory.SM_TYPE_APP + ")", 2); + assertRSQLQuery(SoftwareModuleFields.TYPE.name() + "=out=(" + TestdataFactory.SM_TYPE_APP + ")", 2); } @Test From 223e0f6c857a55e6392ec1fd8ef27a055030b459 Mon Sep 17 00:00:00 2001 From: AMU7KOR Date: Fri, 3 Jun 2016 10:02:50 +0530 Subject: [PATCH 50/54] Fix: Interupt upload if software moudle is not selected Signed-off-by: AMU7KOR --- .../ui/artifacts/upload/UploadHandler.java | 45 ++++++++++++------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java index 61f68f397..78a6fd9a9 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java @@ -133,7 +133,6 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene */ @Override public OutputStream receiveUpload(final String fileName, final String mimeType) { - uploadInterrupted = false; aborted = false; failureReason = null; this.fileName = fileName; @@ -214,17 +213,23 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene */ @Override public void uploadStarted(final StartedEvent event) { - selectedSwForUpload = artifactUploadState.getSelectedBaseSoftwareModule().get(); + uploadInterrupted = false; + selectedSwForUpload = artifactUploadState.getSelectedBaseSoftwareModule().isPresent() ? artifactUploadState + .getSelectedBaseSoftwareModule().get() : null; - // single file session - if (view.isSoftwareModuleSelected() && !view.checkIfFileIsDuplicate(event.getFilename(), selectedSwForUpload)) { - LOG.debug("Upload started for file :{}", event.getFilename()); - eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_STARTED, new UploadFileStatus( - event.getFilename(), 0, 0, selectedSwForUpload))); - } else { + if (view.isSoftwareModuleSelected()) { + // single file session + if (!view.checkIfFileIsDuplicate(event.getFilename(), selectedSwForUpload)) { + LOG.debug("Upload started for file :{}", event.getFilename()); + eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_STARTED, + new UploadFileStatus(event.getFilename(), 0, 0, selectedSwForUpload))); + } + } + else { failureReason = i18n.get("message.upload.failed"); upload.interruptUpload(); - // actual interrupt will happen a bit late so setting the below flag + // actual interrupt will happen a bit late so setting the below + // flag uploadInterrupted = true; } } @@ -319,14 +324,20 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene */ @Override public void uploadFailed(final FailedEvent event) { - if (failureReason == null) { - failureReason = event.getReason().getMessage(); - } - eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_FAILED, new UploadFileStatus( - fileName, failureReason, selectedSwForUpload))); - if (!aborted) { - LOG.info("Upload failed for file :{}", event.getFilename()); - LOG.info("Upload failed for file :{}", event.getReason()); + /** + * If upload failed due to no selected software UPLOAD_FAILED event need + * not be published. + */ + if (selectedSwForUpload != null) { + if (failureReason == null) { + failureReason = event.getReason().getMessage(); + } + eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_FAILED, new UploadFileStatus( + fileName, failureReason, selectedSwForUpload))); + if (!aborted) { + LOG.info("Upload failed for file :{}", event.getFilename()); + LOG.info("Upload failed for file :{}", event.getReason()); + } } } From 92e1d78df377dcf41070cfb8b9c269997f313a43 Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Fri, 3 Jun 2016 07:47:22 +0200 Subject: [PATCH 51/54] exclude .sonar directory from license check Signed-off-by: Michael Hirsch --- pom.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pom.xml b/pom.xml index 0e4fec71d..49ef805b3 100644 --- a/pom.xml +++ b/pom.xml @@ -168,6 +168,8 @@ eclipse_codeformatter.xml **/addons.scss **/VAADIN/widgetsets/** + .sonar + **/.sonar/** JAVADOC_STYLE From 7468d8961ef982b01ac4b3e0c28b060a45cbd7c6 Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Fri, 3 Jun 2016 12:34:09 +0200 Subject: [PATCH 52/54] Completed constants. Signed-off-by: Kai Zimmermann --- .../eclipse/hawkbit/repository/Constants.java | 28 +++++++++++++++---- .../repository/jpa/JpaSystemManagement.java | 9 +++--- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/Constants.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/Constants.java index 6ccb4bc82..9a1e442b0 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/Constants.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/Constants.java @@ -1,5 +1,10 @@ /** - * Copyright (c) 2011-2016 Bosch Software Innovations GmbH, Germany. All rights reserved. + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html */ package org.eclipse.hawkbit.repository; @@ -12,16 +17,29 @@ import org.eclipse.hawkbit.repository.model.SoftwareModuleType; */ public final class Constants { /** - * Default {@link SoftwareModuleType} generated by repository for every new - * account for Firmware/Operating System. + * {@link SoftwareModuleType#getKey()} of a {@link SoftwareModuleType} + * generated by repository for every new account for Firmware/Operating + * System. */ public static final String SMT_DEFAULT_OS_KEY = "os"; /** - * Default {@link SoftwareModuleType} generated by repository for every new - * account for applications. + * {@link SoftwareModuleType#getKey()} of a {@link SoftwareModuleType} + * generated by repository for every new account for applications. */ public static final String SMT_DEFAULT_APP_KEY = "application"; + /** + * {@link SoftwareModuleType#getName()} of a {@link SoftwareModuleType} + * generated by repository for every new account for "Firmware/Operating + * System" . + */ + public static final String SMT_DEFAULT_OS_NAME = "Firmware"; + /** + * {@link SoftwareModuleType#getName()} of a {@link SoftwareModuleType} + * generated by repository for every new account for "applications/apps". + */ + public static final String SMT_DEFAULT_APP_NAME = "Application"; + /** * {@link DistributionSetType#getKey()} of a {@link DistributionSetType} * generated by repository for every new account that includes diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java index a2865c4b0..3fed3d858 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java @@ -284,10 +284,11 @@ public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, Syst } private DistributionSetType createStandardSoftwareDataSetup() { - final SoftwareModuleType app = softwareModuleTypeRepository.save(new JpaSoftwareModuleType( - Constants.SMT_DEFAULT_APP_KEY, "Application", "Application Addons", Integer.MAX_VALUE)); + final SoftwareModuleType app = softwareModuleTypeRepository + .save(new JpaSoftwareModuleType(Constants.SMT_DEFAULT_APP_KEY, Constants.SMT_DEFAULT_APP_NAME, + "Application Addons", Integer.MAX_VALUE)); final SoftwareModuleType os = softwareModuleTypeRepository.save(new JpaSoftwareModuleType( - Constants.SMT_DEFAULT_OS_KEY, "Firmware", "Core firmware or operationg system", 1)); + Constants.SMT_DEFAULT_OS_KEY, Constants.SMT_DEFAULT_OS_NAME, "Core firmware or operationg system", 1)); distributionSetTypeRepository .save((JpaDistributionSetType) new JpaDistributionSetType(Constants.DST_DEFAULT_OS_ONLY_KEY, @@ -299,4 +300,4 @@ public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, Syst Constants.DST_DEFAULT_OS_WITH_APPS_NAME, "Default type with Firmware/OS and optional app(s).") .addMandatoryModuleType(os).addOptionalModuleType(app)); } -} +} \ No newline at end of file From 706c825909d15c0111eda2c27b51e48b60a5629a Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Fri, 3 Jun 2016 18:09:46 +0200 Subject: [PATCH 53/54] Added test for DoSFilter. Signed-off-by: Kai Zimmermann --- .../ddi/rest/resource/DosFilterTest.java | 157 ++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DosFilterTest.java diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DosFilterTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DosFilterTest.java new file mode 100644 index 000000000..2c1d0ba08 --- /dev/null +++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DosFilterTest.java @@ -0,0 +1,157 @@ +/** + * Copyright (c) 2011-2015 Bosch Software Innovations GmbH, Germany. All rights reserved. + */ +package org.eclipse.hawkbit.ddi.rest.resource; + +import static org.fest.assertions.api.Assertions.assertThat; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.hawkbit.repository.model.Action; +import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.Target; +import org.eclipse.hawkbit.rest.AbstractRestIntegrationTest; +import org.eclipse.hawkbit.rest.util.JsonBuilder; +import org.junit.Test; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.web.servlet.MvcResult; + +import com.google.common.net.HttpHeaders; + +import ru.yandex.qatools.allure.annotations.Description; +import ru.yandex.qatools.allure.annotations.Features; +import ru.yandex.qatools.allure.annotations.Stories; + +/** + * Test potential DOS attack scenarios and check if the filter prevents them. + * + */ +@ActiveProfiles({ "test" }) +@Features("Component Tests - REST Security") +@Stories("Denial of Service protection filter") +public class DosFilterTest extends AbstractRestIntegrationTest { + + @Test + @Description("Ensures that clients that are on the blacklist are forbidded ") + public void blackListedClientIsForbidden() throws Exception { + mvc.perform(get("/{tenant}/controller/v1/4711", tenantAware.getCurrentTenant()) + .header(HttpHeaders.X_FORWARDED_FOR, "192.168.0.4 , 10.0.0.1 ")).andExpect(status().isForbidden()); + } + + @Test + @Description("Ensures that a READ DoS attempt is blocked ") + public void getFloddingAttackThatisPrevented() throws Exception { + + MvcResult result = null; + + int requests = 0; + do { + result = mvc.perform(get("/{tenant}/controller/v1/4711", tenantAware.getCurrentTenant()) + .header(HttpHeaders.X_FORWARDED_FOR, "10.0.0.1")).andReturn(); + requests++; + + // we give up after 10.000 requests + assertThat(requests).isLessThan(10_000); + } while (result.getResponse().getStatus() != HttpStatus.TOO_MANY_REQUESTS.value()); + + // the filter shuts down after 100 GET requests + assertThat(requests).isGreaterThanOrEqualTo(100); + } + + @Test + @Description("Ensures that an assumed READ DoS attempt is not blocked as the client (with IPv4 address) is on a whitelist") + public void unacceptableGetLoadButOnWhitelistIPv4() throws Exception { + for (int i = 0; i < 1_000; i++) { + mvc.perform(get("/{tenant}/controller/v1/4711", tenantAware.getCurrentTenant()) + .header(HttpHeaders.X_FORWARDED_FOR, "127.0.0.1")).andExpect(status().isOk()); + } + } + + @Test + @Description("Ensures that an assumed READ DoS attempt is not blocked as the client (with IPv6 address) is on a whitelist") + public void unacceptableGetLoadButOnWhitelistIPv6() throws Exception { + for (int i = 0; i < 1_000; i++) { + mvc.perform(get("/{tenant}/controller/v1/4711", tenantAware.getCurrentTenant()) + .header(HttpHeaders.X_FORWARDED_FOR, "0:0:0:0:0:0:0:1")).andExpect(status().isOk()); + } + } + + @Test + @Description("Ensures that a relatively high number of READ requests is allowed if it is below the DoS detection threshold") + public void acceptableGetLoad() throws Exception { + + for (int x = 0; x < 3; x++) { + // sleep for one second + Thread.sleep(1100); + for (int i = 0; i < 99; i++) { + mvc.perform(get("/{tenant}/controller/v1/4711", tenantAware.getCurrentTenant()) + .header(HttpHeaders.X_FORWARDED_FOR, "10.0.0.1")).andExpect(status().isOk()); + } + } + } + + @Test + @Description("Ensures that a WRITE DoS attempt is blocked ") + public void putPostFloddingAttackThatisPrevented() throws Exception { + final Long actionId = prepareDeploymentBase(); + final String feedback = JsonBuilder.deploymentActionFeedback(actionId.toString(), "proceeding"); + + MvcResult result = null; + int requests = 0; + do { + result = mvc.perform(post("/{tenant}/controller/v1/4711/deploymentBase/" + actionId + "/feedback", + tenantAware.getCurrentTenant()).header(HttpHeaders.X_FORWARDED_FOR, "10.0.0.1").content(feedback) + .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) + .andReturn(); + requests++; + + // we give up after 500 requests + assertThat(requests).isLessThan(500); + } while (result.getResponse().getStatus() != HttpStatus.TOO_MANY_REQUESTS.value()); + + // the filter shuts down after 10 POST requests + assertThat(requests).isGreaterThanOrEqualTo(10); + + } + + @Test + @Description("Ensures that a relatively high number of WRITE requests is allowed if it is below the DoS detection threshold") + public void acceptablePutPostLoad() throws Exception { + final Long actionId = prepareDeploymentBase(); + final String feedback = JsonBuilder.deploymentActionFeedback(actionId.toString(), "proceeding"); + + for (int x = 0; x < 5; x++) { + // sleep for one second + Thread.sleep(1100); + + for (int i = 0; i < 9; i++) { + mvc.perform(post("/{tenant}/controller/v1/4711/deploymentBase/" + actionId + "/feedback", + tenantAware.getCurrentTenant()).header(HttpHeaders.X_FORWARDED_FOR, "10.0.0.1") + .content(feedback).contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()); + } + } + } + + private Long prepareDeploymentBase() { + final DistributionSet ds = testdataFactory.createDistributionSet("test"); + final Target target = targetManagement.createTarget(entityFactory.generateTarget("4711")); + final List toAssign = new ArrayList<>(); + toAssign.add(target); + + final Iterable saved = deploymentManagement.assignDistributionSet(ds, toAssign).getAssignedEntity(); + assertThat(deploymentManagement.findActiveActionsByTarget(target)).hasSize(1); + + final Action uaction = deploymentManagement.findActiveActionsByTarget(target).get(0); + + return uaction.getId(); + } + +} From a73d72bf582a2b9e57b5c4ed0bdd4beec8a759f7 Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Fri, 3 Jun 2016 18:13:44 +0200 Subject: [PATCH 54/54] Fixed header. Signed-off-by: Kai Zimmermann --- .../eclipse/hawkbit/ddi/rest/resource/DosFilterTest.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DosFilterTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DosFilterTest.java index 2c1d0ba08..d63d9efc1 100644 --- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DosFilterTest.java +++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DosFilterTest.java @@ -1,5 +1,10 @@ /** - * Copyright (c) 2011-2015 Bosch Software Innovations GmbH, Germany. All rights reserved. + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html */ package org.eclipse.hawkbit.ddi.rest.resource;