Merge pull request #322 from bsinno/fix_optimize_repository
Removed external artifact from repository.
This commit is contained in:
@@ -19,7 +19,7 @@ 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.model.LocalArtifact;
|
||||
import org.eclipse.hawkbit.repository.model.Artifact;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.SpringContextHelper;
|
||||
import org.springframework.data.domain.Page;
|
||||
@@ -33,12 +33,12 @@ import org.vaadin.addons.lazyquerycontainer.QueryDefinition;
|
||||
* Simple implementation of generics bean query which dynamically loads artifact
|
||||
* beans.
|
||||
*/
|
||||
public class ArtifactBeanQuery extends AbstractBeanQuery<LocalArtifact> {
|
||||
public class ArtifactBeanQuery extends AbstractBeanQuery<Artifact> {
|
||||
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<LocalArtifact> firstPagetArtifacts = null;
|
||||
private transient Page<Artifact> firstPagetArtifacts = null;
|
||||
private Long baseSwModuleId = null;
|
||||
|
||||
/**
|
||||
@@ -72,26 +72,26 @@ public class ArtifactBeanQuery extends AbstractBeanQuery<LocalArtifact> {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LocalArtifact constructBean() {
|
||||
return getEntityFactory().generateLocalArtifact();
|
||||
protected Artifact constructBean() {
|
||||
return getEntityFactory().generateArtifact();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<LocalArtifact> loadBeans(final int startIndex, final int count) {
|
||||
Page<LocalArtifact> artifactBeans;
|
||||
protected List<Artifact> loadBeans(final int startIndex, final int count) {
|
||||
Page<Artifact> artifactBeans;
|
||||
if (startIndex == 0 && firstPagetArtifacts != null) {
|
||||
artifactBeans = firstPagetArtifacts;
|
||||
} else {
|
||||
artifactBeans = getArtifactManagement().findLocalArtifactBySoftwareModule(
|
||||
new OffsetBasedPageRequest(startIndex, count, sort), baseSwModuleId);
|
||||
artifactBeans = getArtifactManagement()
|
||||
.findArtifactBySoftwareModule(new OffsetBasedPageRequest(startIndex, count, sort), baseSwModuleId);
|
||||
}
|
||||
|
||||
return artifactBeans.getContent();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveBeans(final List<LocalArtifact> addedTargets, final List<LocalArtifact> modifiedTargets,
|
||||
final List<LocalArtifact> removedTargets) {
|
||||
protected void saveBeans(final List<Artifact> addedTargets, final List<Artifact> modifiedTargets,
|
||||
final List<Artifact> removedTargets) {
|
||||
// CRUD operations on Target will be done through repository methods
|
||||
}
|
||||
|
||||
@@ -99,8 +99,8 @@ public class ArtifactBeanQuery extends AbstractBeanQuery<LocalArtifact> {
|
||||
public int size() {
|
||||
long size = 0;
|
||||
if (baseSwModuleId != null) {
|
||||
firstPagetArtifacts = getArtifactManagement().findLocalArtifactBySoftwareModule(
|
||||
new PageRequest(0, SPUIDefinitions.PAGE_SIZE, sort), baseSwModuleId);
|
||||
firstPagetArtifacts = getArtifactManagement()
|
||||
.findArtifactBySoftwareModule(new PageRequest(0, SPUIDefinitions.PAGE_SIZE, sort), baseSwModuleId);
|
||||
size = firstPagetArtifacts.getTotalElements();
|
||||
}
|
||||
if (size > Integer.MAX_VALUE) {
|
||||
|
||||
@@ -278,7 +278,7 @@ public class ArtifactDetailsLayout extends VerticalLayout {
|
||||
if (ok) {
|
||||
final ArtifactManagement artifactManagement = SpringContextHelper
|
||||
.getBean(ArtifactManagement.class);
|
||||
artifactManagement.deleteLocalArtifact(id);
|
||||
artifactManagement.deleteArtifact(id);
|
||||
uINotification.displaySuccess(i18n.get("message.artifact.deleted", fileName));
|
||||
if (artifactUploadState.getSelectedBaseSwModuleId().isPresent()) {
|
||||
populateArtifactDetails(artifactUploadState.getSelectedBaseSwModuleId().get(),
|
||||
|
||||
@@ -8,9 +8,10 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.ui.artifacts.smtable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.hawkbit.repository.OffsetBasedPageRequest;
|
||||
import org.eclipse.hawkbit.repository.SoftwareManagement;
|
||||
@@ -37,8 +38,8 @@ import com.google.common.base.Strings;
|
||||
public class BaseSwModuleBeanQuery extends AbstractBeanQuery<ProxyBaseSoftwareModuleItem> {
|
||||
private static final long serialVersionUID = 4362142538539335466L;
|
||||
private transient SoftwareManagement softwareManagementService;
|
||||
private SoftwareModuleType type;
|
||||
private String searchText = null;
|
||||
private Long type;
|
||||
private String searchText;
|
||||
private final Sort sort = new Sort(Direction.ASC, "name", "version");
|
||||
|
||||
/**
|
||||
@@ -57,7 +58,8 @@ public class BaseSwModuleBeanQuery extends AbstractBeanQuery<ProxyBaseSoftwareMo
|
||||
final Object[] sortIds, final boolean[] sortStates) {
|
||||
super(definition, queryConfig, sortIds, sortStates);
|
||||
if (HawkbitCommonUtil.isNotNullOrEmpty(queryConfig)) {
|
||||
type = (SoftwareModuleType) queryConfig.get(SPUIDefinitions.BY_SOFTWARE_MODULE_TYPE);
|
||||
type = Optional.ofNullable((SoftwareModuleType) queryConfig.get(SPUIDefinitions.BY_SOFTWARE_MODULE_TYPE))
|
||||
.map(t -> t.getId()).orElse(null);
|
||||
searchText = (String) queryConfig.get(SPUIDefinitions.FILTER_BY_TEXT);
|
||||
if (!Strings.isNullOrEmpty(searchText)) {
|
||||
searchText = String.format("%%%s%%", searchText);
|
||||
@@ -73,7 +75,6 @@ public class BaseSwModuleBeanQuery extends AbstractBeanQuery<ProxyBaseSoftwareMo
|
||||
@Override
|
||||
protected List<ProxyBaseSoftwareModuleItem> loadBeans(final int startIndex, final int count) {
|
||||
final Slice<SoftwareModule> swModuleBeans;
|
||||
final List<ProxyBaseSoftwareModuleItem> proxyBeans = new ArrayList<>();
|
||||
|
||||
if (type == null && Strings.isNullOrEmpty(searchText)) {
|
||||
swModuleBeans = getSoftwareManagementService()
|
||||
@@ -84,11 +85,7 @@ public class BaseSwModuleBeanQuery extends AbstractBeanQuery<ProxyBaseSoftwareMo
|
||||
.findSoftwareModuleByFilters(new OffsetBasedPageRequest(startIndex, count, sort), searchText, type);
|
||||
}
|
||||
|
||||
for (final SoftwareModule swModule : swModuleBeans) {
|
||||
proxyBeans.add(getProxyBean(swModule));
|
||||
}
|
||||
|
||||
return proxyBeans;
|
||||
return swModuleBeans.getContent().stream().map(this::getProxyBean).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private ProxyBaseSoftwareModuleItem getProxyBean(final SoftwareModule bean) {
|
||||
|
||||
@@ -209,7 +209,7 @@ public class SoftwareModuleDetails extends AbstractNamedVersionedEntityTableDeta
|
||||
|
||||
@Override
|
||||
protected void showMetadata(final ClickEvent event) {
|
||||
final SoftwareModule swmodule = softwareManagement.findSoftwareModuleWithDetails(getSelectedBaseEntityId());
|
||||
final SoftwareModule swmodule = softwareManagement.findSoftwareModuleById(getSelectedBaseEntityId());
|
||||
/* display the window */
|
||||
UI.getCurrent().addWindow(swMetadataPopupLayout.getWindow(swmodule, null));
|
||||
}
|
||||
|
||||
@@ -245,7 +245,7 @@ public class SoftwareModuleTable extends AbstractNamedVersionTable<SoftwareModul
|
||||
}
|
||||
|
||||
private void showMetadataDetails(final Long itemId) {
|
||||
final SoftwareModule swmodule = softwareManagement.findSoftwareModuleWithDetails(itemId);
|
||||
final SoftwareModule swmodule = softwareManagement.findSoftwareModuleById(itemId);
|
||||
/* display the window */
|
||||
UI.getCurrent().addWindow(swMetadataPopupLayout.getWindow(swmodule, null));
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.eclipse.hawkbit.repository.ArtifactManagement;
|
||||
import org.eclipse.hawkbit.repository.exception.ArtifactUploadFailedException;
|
||||
import org.eclipse.hawkbit.repository.exception.InvalidMD5HashException;
|
||||
import org.eclipse.hawkbit.repository.exception.InvalidSHA1HashException;
|
||||
import org.eclipse.hawkbit.repository.model.LocalArtifact;
|
||||
import org.eclipse.hawkbit.repository.model.Artifact;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState;
|
||||
import org.eclipse.hawkbit.ui.artifacts.state.CustomFile;
|
||||
@@ -191,8 +191,7 @@ public class UploadConfirmationWindow implements Button.ClickListener {
|
||||
final ArtifactManagement artifactManagement = SpringContextHelper.getBean(ArtifactManagement.class);
|
||||
if (HawkbitCommonUtil.trimAndNullIfEmpty(fileName) != null) {
|
||||
final Long baseSwId = (Long) item.getItemProperty(BASE_SOFTWARE_ID).getValue();
|
||||
final List<LocalArtifact> artifactList = artifactManagement.findByFilenameAndSoftwareModule(fileName,
|
||||
baseSwId);
|
||||
final List<Artifact> artifactList = artifactManagement.findByFilenameAndSoftwareModule(fileName, baseSwId);
|
||||
if (!artifactList.isEmpty()) {
|
||||
warningIconLabel.setVisible(true);
|
||||
if (isErrorIcon(warningIconLabel)) {
|
||||
@@ -434,7 +433,7 @@ public class UploadConfirmationWindow implements Button.ClickListener {
|
||||
final Label errorLabel, final String oldFileName, final Long currentSwId) {
|
||||
if (warningLabel == null && (errorLabelCount > 1 || (duplicateCount == 1 && errorLabelCount == 1))) {
|
||||
final ArtifactManagement artifactManagement = SpringContextHelper.getBean(ArtifactManagement.class);
|
||||
final List<LocalArtifact> artifactList = artifactManagement.findByFilenameAndSoftwareModule(oldFileName,
|
||||
final List<Artifact> artifactList = artifactManagement.findByFilenameAndSoftwareModule(oldFileName,
|
||||
currentSwId);
|
||||
errorLabel.removeStyleName(SPUIStyleDefinitions.ERROR_LABEL);
|
||||
errorLabel.setDescription(i18n.get(ALREADY_EXISTS_MSG));
|
||||
@@ -591,7 +590,7 @@ public class UploadConfirmationWindow implements Button.ClickListener {
|
||||
customFile.getBaseSoftwareModuleName(), customFile.getBaseSoftwareModuleVersion());
|
||||
if (customFile.getFileName().equals(fileName)
|
||||
&& baseSwModuleNameVersion.equals(baseSoftwareModuleNameVersion)) {
|
||||
createLocalArtifact(itemId, customFile.getFilePath(), artifactManagement, bSoftwareModule);
|
||||
createArtifact(itemId, customFile.getFilePath(), artifactManagement, bSoftwareModule);
|
||||
}
|
||||
}
|
||||
refreshArtifactDetailsLayout = checkIfArtifactDetailsDispalyed(bSoftwareModule.getId());
|
||||
@@ -619,8 +618,8 @@ public class UploadConfirmationWindow implements Button.ClickListener {
|
||||
currentUploadResultWindow = null;
|
||||
}
|
||||
|
||||
private void createLocalArtifact(final String itemId, final String filePath,
|
||||
final ArtifactManagement artifactManagement, final SoftwareModule baseSw) {
|
||||
private void createArtifact(final String itemId, final String filePath, final ArtifactManagement artifactManagement,
|
||||
final SoftwareModule baseSw) {
|
||||
|
||||
final File newFile = new File(filePath);
|
||||
final Item item = tabelContainer.getItem(itemId);
|
||||
@@ -633,7 +632,7 @@ public class UploadConfirmationWindow implements Button.ClickListener {
|
||||
|
||||
try (FileInputStream fis = new FileInputStream(newFile)) {
|
||||
|
||||
artifactManagement.createLocalArtifact(fis, baseSw.getId(), providedFileName,
|
||||
artifactManagement.createArtifact(fis, baseSw.getId(), providedFileName,
|
||||
HawkbitCommonUtil.trimAndNullIfEmpty(md5Checksum),
|
||||
HawkbitCommonUtil.trimAndNullIfEmpty(sha1Checksum), true, customFile.getMimeType());
|
||||
saveUploadStatus(providedFileName, swModuleNameVersion, SUCCESS, "");
|
||||
|
||||
@@ -43,7 +43,7 @@ public class SwMetadataPopupLayout extends AbstractMetadataPopupLayout<SoftwareM
|
||||
|
||||
@Override
|
||||
protected void checkForDuplicate(final SoftwareModule entity, final String value) {
|
||||
softwareManagement.findSoftwareModuleMetadata(entity, value);
|
||||
softwareManagement.findSoftwareModuleMetadata(entity.getId(), value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,7 +71,7 @@ public class SwMetadataPopupLayout extends AbstractMetadataPopupLayout<SoftwareM
|
||||
|
||||
@Override
|
||||
protected List<SoftwareModuleMetadata> getMetadataList() {
|
||||
return getSelectedEntity().getMetadata();
|
||||
return softwareManagement.findSoftwareModuleMetadataBySoftwareModuleId(getSelectedEntity().getId());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,7 +80,7 @@ public class SwMetadataPopupLayout extends AbstractMetadataPopupLayout<SoftwareM
|
||||
@Override
|
||||
protected void deleteMetadata(final SoftwareModule entity, final String key, final String value) {
|
||||
final SoftwareModuleMetadata swMetadata = entityFactory.generateSoftwareModuleMetadata(entity, key, value);
|
||||
softwareManagement.deleteSoftwareModuleMetadata(entity, key);
|
||||
softwareManagement.deleteSoftwareModuleMetadata(entity.getId(), key);
|
||||
eventBus.publish(this, new MetadataEvent(MetadataUIEvent.DELETE_SOFTWARE_MODULE_METADATA, swMetadata));
|
||||
}
|
||||
|
||||
|
||||
@@ -8,9 +8,10 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.ui.distributions.smtable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.hawkbit.repository.OffsetBasedPageRequest;
|
||||
import org.eclipse.hawkbit.repository.SoftwareManagement;
|
||||
@@ -22,7 +23,6 @@ import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil;
|
||||
import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil;
|
||||
import org.eclipse.hawkbit.ui.utils.SPUIDefinitions;
|
||||
import org.eclipse.hawkbit.ui.utils.SpringContextHelper;
|
||||
import org.springframework.data.domain.Slice;
|
||||
import org.vaadin.addons.lazyquerycontainer.AbstractBeanQuery;
|
||||
import org.vaadin.addons.lazyquerycontainer.QueryDefinition;
|
||||
|
||||
@@ -36,9 +36,9 @@ import com.google.common.base.Strings;
|
||||
public class SwModuleBeanQuery extends AbstractBeanQuery<ProxyBaseSwModuleItem> {
|
||||
private static final long serialVersionUID = 4362142538539335466L;
|
||||
private transient SoftwareManagement softwareManagementService;
|
||||
private SoftwareModuleType type;
|
||||
private String searchText = null;
|
||||
private Long orderByDistId = 0L;
|
||||
private final Long type;
|
||||
private final String searchText;
|
||||
private final Long orderByDistId;
|
||||
|
||||
/**
|
||||
* Parametric Constructor.
|
||||
@@ -56,16 +56,22 @@ public class SwModuleBeanQuery extends AbstractBeanQuery<ProxyBaseSwModuleItem>
|
||||
final Object[] sortIds, final boolean[] sortStates) {
|
||||
super(definition, queryConfig, sortIds, sortStates);
|
||||
if (HawkbitCommonUtil.isNotNullOrEmpty(queryConfig)) {
|
||||
type = (SoftwareModuleType) queryConfig.get(SPUIDefinitions.BY_SOFTWARE_MODULE_TYPE);
|
||||
searchText = (String) queryConfig.get(SPUIDefinitions.FILTER_BY_TEXT);
|
||||
if (!Strings.isNullOrEmpty(searchText)) {
|
||||
searchText = String.format("%%%s%%", searchText);
|
||||
}
|
||||
orderByDistId = (Long) queryConfig.get(SPUIDefinitions.ORDER_BY_DISTRIBUTION);
|
||||
if (orderByDistId == null) {
|
||||
orderByDistId = 0L;
|
||||
type = Optional.ofNullable((SoftwareModuleType) queryConfig.get(SPUIDefinitions.BY_SOFTWARE_MODULE_TYPE))
|
||||
.map(t -> t.getId()).orElse(null);
|
||||
final String text = (String) queryConfig.get(SPUIDefinitions.FILTER_BY_TEXT);
|
||||
if (!Strings.isNullOrEmpty(text)) {
|
||||
searchText = String.format("%%%s%%", text);
|
||||
} else {
|
||||
searchText = null;
|
||||
}
|
||||
orderByDistId = Optional.ofNullable((Long) queryConfig.get(SPUIDefinitions.ORDER_BY_DISTRIBUTION))
|
||||
.orElse(0L);
|
||||
return;
|
||||
}
|
||||
|
||||
orderByDistId = 0L;
|
||||
type = null;
|
||||
searchText = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -75,20 +81,13 @@ public class SwModuleBeanQuery extends AbstractBeanQuery<ProxyBaseSwModuleItem>
|
||||
|
||||
@Override
|
||||
protected List<ProxyBaseSwModuleItem> loadBeans(final int startIndex, final int count) {
|
||||
final Slice<AssignedSoftwareModule> swModuleBeans;
|
||||
final List<ProxyBaseSwModuleItem> proxyBeans = new ArrayList<>();
|
||||
|
||||
swModuleBeans = getSoftwareManagement().findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(
|
||||
new OffsetBasedPageRequest(startIndex, count), orderByDistId, searchText, type);
|
||||
|
||||
for (final AssignedSoftwareModule swModule : swModuleBeans) {
|
||||
proxyBeans.add(getProxyBean(swModule));
|
||||
}
|
||||
|
||||
return proxyBeans;
|
||||
return getSoftwareManagement()
|
||||
.findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(
|
||||
new OffsetBasedPageRequest(startIndex, count), orderByDistId, searchText, type)
|
||||
.getContent().stream().map(SwModuleBeanQuery::getProxyBean).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private ProxyBaseSwModuleItem getProxyBean(final AssignedSoftwareModule customSoftwareModule) {
|
||||
private static ProxyBaseSwModuleItem getProxyBean(final AssignedSoftwareModule customSoftwareModule) {
|
||||
final SoftwareModule bean = customSoftwareModule.getSoftwareModule();
|
||||
final ProxyBaseSwModuleItem proxyItem = new ProxyBaseSwModuleItem();
|
||||
proxyItem.setSwId(bean.getId());
|
||||
|
||||
@@ -153,7 +153,7 @@ public class SwModuleDetails extends AbstractNamedVersionedEntityTableDetailsLay
|
||||
if (getSelectedBaseEntity().getType().getMaxAssignments() == 1) {
|
||||
maxAssign = getI18n().get("label.singleAssign.type");
|
||||
} else {
|
||||
maxAssign = getI18n().get("label.multiAssign.type");
|
||||
maxAssign = getI18n().get("label.multiAssign.type");
|
||||
}
|
||||
updateSwModuleDetailsLayout(getSelectedBaseEntity().getType().getName(),
|
||||
getSelectedBaseEntity().getVendor(), maxAssign);
|
||||
@@ -217,7 +217,7 @@ public class SwModuleDetails extends AbstractNamedVersionedEntityTableDetailsLay
|
||||
|
||||
@Override
|
||||
protected void showMetadata(final ClickEvent event) {
|
||||
final SoftwareModule swmodule = softwareManagement.findSoftwareModuleWithDetails(getSelectedBaseEntityId());
|
||||
final SoftwareModule swmodule = softwareManagement.findSoftwareModuleById(getSelectedBaseEntityId());
|
||||
UI.getCurrent().addWindow(swMetadataPopupLayout.getWindow(swmodule, null));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ public class SwModuleTable extends AbstractNamedVersionTable<SoftwareModule, Lon
|
||||
@EventBusListenerMethod(scope = EventScope.SESSION)
|
||||
void onEvent(final SaveActionWindowEvent event) {
|
||||
if (event == SaveActionWindowEvent.DELETE_ALL_SOFWARE) {
|
||||
UI.getCurrent().access(() -> refreshFilter());
|
||||
UI.getCurrent().access(this::refreshFilter);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -400,7 +400,7 @@ public class SwModuleTable extends AbstractNamedVersionTable<SoftwareModule, Lon
|
||||
}
|
||||
|
||||
private void showMetadataDetails(final Long itemId) {
|
||||
final SoftwareModule swmodule = softwareManagement.findSoftwareModuleWithDetails(itemId);
|
||||
final SoftwareModule swmodule = softwareManagement.findSoftwareModuleById(itemId);
|
||||
UI.getCurrent().addWindow(swMetadataPopupLayout.getWindow(swmodule, null));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user