Clean Code Refactoring
Signed-off-by: SirWayne <dennis.melzer@bosch-si.com>
This commit is contained in:
@@ -8,19 +8,22 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.report.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* A data report series which contains a list of {@link DataReportSeriesItem}.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param <T>
|
||||
* the type of the report series item
|
||||
*/
|
||||
public class DataReportSeries<T extends Object> extends AbstractReportSeries {
|
||||
public class DataReportSeries<T extends Serializable> extends AbstractReportSeries {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final List<DataReportSeriesItem<T>> data = new ArrayList<>();
|
||||
|
||||
@@ -47,7 +50,7 @@ public class DataReportSeries<T extends Object> extends AbstractReportSeries {
|
||||
|
||||
private void setData(final List<DataReportSeriesItem<T>> values) {
|
||||
this.data.clear();
|
||||
data.addAll(values);
|
||||
this.data.addAll(values);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,10 +58,10 @@ public class DataReportSeries<T extends Object> extends AbstractReportSeries {
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public DataReportSeriesItem<T>[] getData() {
|
||||
return data.toArray(new DataReportSeriesItem[data.size()]);
|
||||
return this.data.toArray(new DataReportSeriesItem[this.data.size()]);
|
||||
}
|
||||
|
||||
public Stream<DataReportSeriesItem<T>> getDataStream() {
|
||||
return data.stream();
|
||||
return this.data.stream();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.report.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* An data report series item which contains a type and a value.
|
||||
*
|
||||
@@ -16,8 +18,9 @@ package org.eclipse.hawkbit.report.model;
|
||||
* @param <T>
|
||||
* the type of the report series item
|
||||
*/
|
||||
public class DataReportSeriesItem<T extends Object> {
|
||||
public class DataReportSeriesItem<T extends Serializable> implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final T type;
|
||||
private final Number data;
|
||||
|
||||
@@ -36,13 +39,13 @@ public class DataReportSeriesItem<T extends Object> {
|
||||
* @return the type of the data report item
|
||||
*/
|
||||
public T getType() {
|
||||
return type;
|
||||
return this.type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the data of the data report item
|
||||
*/
|
||||
public Number getData() {
|
||||
return data;
|
||||
return this.data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.report.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* A double data series which contains an inner and an outer series ideal for
|
||||
* showing donut charts.
|
||||
@@ -17,7 +19,7 @@ package org.eclipse.hawkbit.report.model;
|
||||
* @param <T>
|
||||
* The type parameter for the report series data
|
||||
*/
|
||||
public class InnerOuterDataReportSeries<T> {
|
||||
public class InnerOuterDataReportSeries<T extends Serializable> {
|
||||
|
||||
private final DataReportSeries<T> innerSeries;
|
||||
private final DataReportSeries<T> outerSeries;
|
||||
@@ -37,13 +39,13 @@ public class InnerOuterDataReportSeries<T> {
|
||||
* @return the innerSeries
|
||||
*/
|
||||
public DataReportSeries<T> getInnerSeries() {
|
||||
return innerSeries;
|
||||
return this.innerSeries;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the outerSeries
|
||||
*/
|
||||
public DataReportSeries<T> getOuterSeries() {
|
||||
return outerSeries;
|
||||
return this.outerSeries;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,10 +22,6 @@ 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.Predicate;
|
||||
import javax.persistence.criteria.Root;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.eclipse.hawkbit.eventbus.event.DistributionSetTagAssigmentResultEvent;
|
||||
@@ -53,13 +49,13 @@ 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.domain.Specifications;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -121,7 +117,7 @@ public class DistributionSetManagement {
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
public DistributionSet findDistributionSetByIdWithDetails(@NotNull final Long distid) {
|
||||
return distributionSetRepository.findOne(DistributionSetSpecification.byId(distid));
|
||||
return this.distributionSetRepository.findOne(DistributionSetSpecification.byId(distid));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -134,7 +130,7 @@ public class DistributionSetManagement {
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
public DistributionSet findDistributionSetById(@NotNull final Long distid) {
|
||||
return distributionSetRepository.findOne(distid);
|
||||
return this.distributionSetRepository.findOne(distid);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -178,7 +174,7 @@ public class DistributionSetManagement {
|
||||
@NotNull final String tagName) {
|
||||
|
||||
final Iterable<DistributionSet> sets = findDistributionSetListWithDetails(dsIds);
|
||||
final DistributionSetTag myTag = tagManagement.findDistributionSetTag(tagName);
|
||||
final DistributionSetTag myTag = this.tagManagement.findDistributionSetTag(tagName);
|
||||
|
||||
DistributionSetTagAssigmentResult result = null;
|
||||
final List<DistributionSet> allDSs = new ArrayList<>();
|
||||
@@ -196,17 +192,18 @@ public class DistributionSetManagement {
|
||||
}
|
||||
}
|
||||
result = new DistributionSetTagAssigmentResult(dsIds.size() - allDSs.size(), 0, allDSs.size(),
|
||||
Collections.emptyList(), distributionSetRepository.save(allDSs), myTag);
|
||||
Collections.emptyList(), this.distributionSetRepository.save(allDSs), myTag);
|
||||
} else {
|
||||
result = new DistributionSetTagAssigmentResult(dsIds.size() - allDSs.size(), allDSs.size(), 0,
|
||||
distributionSetRepository.save(allDSs), Collections.emptyList(), myTag);
|
||||
this.distributionSetRepository.save(allDSs), Collections.emptyList(), myTag);
|
||||
}
|
||||
|
||||
final DistributionSetTagAssigmentResult resultAssignment = result;
|
||||
afterCommit.afterCommit(() -> eventBus.post(new DistributionSetTagAssigmentResultEvent(resultAssignment)));
|
||||
this.afterCommit
|
||||
.afterCommit(() -> this.eventBus.post(new DistributionSetTagAssigmentResultEvent(resultAssignment)));
|
||||
|
||||
// no reason to persist the tag
|
||||
entityManager.detach(myTag);
|
||||
this.entityManager.detach(myTag);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -221,7 +218,7 @@ public class DistributionSetManagement {
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
public List<DistributionSet> findDistributionSetListWithDetails(
|
||||
@NotEmpty final Collection<Long> distributionIdSet) {
|
||||
return distributionSetRepository.findAll(DistributionSetSpecification.byIds(distributionIdSet));
|
||||
return this.distributionSetRepository.findAll(DistributionSetSpecification.byIds(distributionIdSet));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -241,7 +238,7 @@ public class DistributionSetManagement {
|
||||
checkNotNull(ds.getId());
|
||||
final DistributionSet persisted = findDistributionSetByIdWithDetails(ds.getId());
|
||||
checkDistributionSetSoftwareModulesIsAllowedToModify(ds, persisted.getModules());
|
||||
return distributionSetRepository.save(ds);
|
||||
return this.distributionSetRepository.save(ds);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -280,11 +277,11 @@ public class DistributionSetManagement {
|
||||
public void deleteDistributionSet(@NotEmpty final Long... distributionSetIDs) {
|
||||
final List<Long> toHardDelete = new ArrayList<>();
|
||||
|
||||
final List<Long> assigned = distributionSetRepository.findAssignedDistributionSetsById(distributionSetIDs);
|
||||
final List<Long> assigned = this.distributionSetRepository.findAssignedDistributionSetsById(distributionSetIDs);
|
||||
|
||||
// soft delete assigned
|
||||
if (!assigned.isEmpty()) {
|
||||
distributionSetRepository.deleteDistributionSet(assigned.toArray(new Long[assigned.size()]));
|
||||
this.distributionSetRepository.deleteDistributionSet(assigned.toArray(new Long[assigned.size()]));
|
||||
}
|
||||
|
||||
// mark the rest as hard delete
|
||||
@@ -299,7 +296,7 @@ public class DistributionSetManagement {
|
||||
// don't give the delete statement an empty list, JPA/Oracle cannot
|
||||
// handle the empty list,
|
||||
// see MECS-403
|
||||
distributionSetRepository.deleteByIdIn(toHardDelete);
|
||||
this.distributionSetRepository.deleteByIdIn(toHardDelete);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -322,9 +319,9 @@ public class DistributionSetManagement {
|
||||
public DistributionSet createDistributionSet(@NotNull final DistributionSet dSet) {
|
||||
prepareDsSave(dSet);
|
||||
if (dSet.getType() == null) {
|
||||
dSet.setType(systemManagement.getTenantMetadata().getDefaultDsType());
|
||||
dSet.setType(this.systemManagement.getTenantMetadata().getDefaultDsType());
|
||||
}
|
||||
return distributionSetRepository.save(dSet);
|
||||
return this.distributionSetRepository.save(dSet);
|
||||
}
|
||||
|
||||
private void prepareDsSave(final DistributionSet dSet) {
|
||||
@@ -332,7 +329,7 @@ public class DistributionSetManagement {
|
||||
throw new EntityAlreadyExistsException("Parameter seems to be an existing, already persisted entity");
|
||||
}
|
||||
|
||||
if (distributionSetRepository.countByNameAndVersion(dSet.getName(), dSet.getVersion()) > 0) {
|
||||
if (this.distributionSetRepository.countByNameAndVersion(dSet.getName(), dSet.getVersion()) > 0) {
|
||||
throw new EntityAlreadyExistsException("DistributionSet with that name and version already exists.");
|
||||
}
|
||||
|
||||
@@ -357,7 +354,7 @@ public class DistributionSetManagement {
|
||||
for (final DistributionSet ds : distributionSets) {
|
||||
prepareDsSave(ds);
|
||||
}
|
||||
return distributionSetRepository.save(distributionSets);
|
||||
return this.distributionSetRepository.save(distributionSets);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -378,7 +375,7 @@ public class DistributionSetManagement {
|
||||
for (final SoftwareModule softwareModule : softwareModules) {
|
||||
ds.addModule(softwareModule);
|
||||
}
|
||||
return distributionSetRepository.save(ds);
|
||||
return this.distributionSetRepository.save(ds);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -400,7 +397,7 @@ public class DistributionSetManagement {
|
||||
softwareModules.add(softwareModule);
|
||||
ds.removeModule(softwareModule);
|
||||
checkDistributionSetSoftwareModulesIsAllowedToModify(ds, softwareModules);
|
||||
return distributionSetRepository.save(ds);
|
||||
return this.distributionSetRepository.save(ds);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -422,17 +419,17 @@ public class DistributionSetManagement {
|
||||
public DistributionSetType updateDistributionSetType(@NotNull final DistributionSetType dsType) {
|
||||
checkNotNull(dsType.getId());
|
||||
|
||||
final DistributionSetType persisted = distributionSetTypeRepository.findOne(dsType.getId());
|
||||
final DistributionSetType persisted = this.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) {
|
||||
if (!persisted.areModuleEntriesIdentical(dsType) && this.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);
|
||||
return this.distributionSetTypeRepository.save(dsType);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -448,7 +445,7 @@ public class DistributionSetManagement {
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
public Page<DistributionSetType> findDistributionSetTypesByPredicate(
|
||||
@NotNull final Specification<DistributionSetType> spec, @NotNull final Pageable pageable) {
|
||||
return distributionSetTypeRepository.findAll(spec, pageable);
|
||||
return this.distributionSetTypeRepository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -458,7 +455,7 @@ public class DistributionSetManagement {
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
public Page<DistributionSetType> findDistributionSetTypesAll(@NotNull final Pageable pageable) {
|
||||
return distributionSetTypeRepository.findByDeleted(pageable, false);
|
||||
return this.distributionSetTypeRepository.findByDeleted(pageable, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -488,15 +485,10 @@ public class DistributionSetManagement {
|
||||
private DistributionSet findDistributionSetsByFiltersAndInstalledOrAssignedTarget(
|
||||
final DistributionSetFilter distributionSetFilter) {
|
||||
final List<Specification<DistributionSet>> specList = buildDistributionSetSpecifications(distributionSetFilter);
|
||||
if (!specList.isEmpty()) {
|
||||
Specifications<DistributionSet> specs = Specifications.where(specList.get(0));
|
||||
specList.remove(0);
|
||||
for (final Specification<DistributionSet> s : specList) {
|
||||
specs = specs.and(s);
|
||||
}
|
||||
return distributionSetRepository.findOne(specs);
|
||||
if (specList == null || specList.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
return this.distributionSetRepository.findOne(SpecificationsBuilder.combineWithAnd(specList));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -627,17 +619,6 @@ public class DistributionSetManagement {
|
||||
return new PageImpl<>(resultSet, pageable, findDistributionSetsByFilters.getTotalElements());
|
||||
}
|
||||
|
||||
private Long countDistributionSetByCriteriaAPI(@NotEmpty final List<Specification<DistributionSet>> specList) {
|
||||
Specifications<DistributionSet> specs = Specifications.where(specList.get(0));
|
||||
if (specList.size() > 1) {
|
||||
for (final Specification<DistributionSet> s : specList.subList(1, specList.size())) {
|
||||
specs = specs.and(s);
|
||||
}
|
||||
}
|
||||
|
||||
return distributionSetRepository.count(specs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find distribution set by name and version.
|
||||
*
|
||||
@@ -652,7 +633,7 @@ public class DistributionSetManagement {
|
||||
@NotEmpty final String version) {
|
||||
final Specification<DistributionSet> spec = DistributionSetSpecification
|
||||
.equalsNameAndVersionIgnoreCase(distributionName, version);
|
||||
return distributionSetRepository.findOne(spec);
|
||||
return this.distributionSetRepository.findOne(spec);
|
||||
|
||||
}
|
||||
|
||||
@@ -669,7 +650,7 @@ public class DistributionSetManagement {
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
public Iterable<DistributionSet> findDistributionSetList(@NotEmpty final Collection<Long> dist) {
|
||||
return distributionSetRepository.findAll(dist);
|
||||
return this.distributionSetRepository.findAll(dist);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -686,7 +667,7 @@ public class DistributionSetManagement {
|
||||
final Specification<DistributionSet> spec = DistributionSetSpecification.isDeleted(Boolean.FALSE);
|
||||
specList.add(spec);
|
||||
|
||||
return countDistributionSetByCriteriaAPI(specList);
|
||||
return this.distributionSetRepository.count(SpecificationsBuilder.combineWithAnd(specList));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -694,7 +675,7 @@ public class DistributionSetManagement {
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
public Long countDistributionSetTypesAll() {
|
||||
return distributionSetTypeRepository.countByDeleted(false);
|
||||
return this.distributionSetTypeRepository.countByDeleted(false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -704,7 +685,7 @@ public class DistributionSetManagement {
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
public DistributionSetType findDistributionSetTypeByName(@NotNull final String name) {
|
||||
return distributionSetTypeRepository.findOne(DistributionSetTypeSpecification.byName(name));
|
||||
return this.distributionSetTypeRepository.findOne(DistributionSetTypeSpecification.byName(name));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -714,7 +695,7 @@ public class DistributionSetManagement {
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
public DistributionSetType findDistributionSetTypeById(@NotNull final Long id) {
|
||||
return distributionSetTypeRepository.findOne(DistributionSetTypeSpecification.byId(id));
|
||||
return this.distributionSetTypeRepository.findOne(DistributionSetTypeSpecification.byId(id));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -724,7 +705,7 @@ public class DistributionSetManagement {
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
public DistributionSetType findDistributionSetTypeByKey(@NotNull final String key) {
|
||||
return distributionSetTypeRepository.findOne(DistributionSetTypeSpecification.byKey(key));
|
||||
return this.distributionSetTypeRepository.findOne(DistributionSetTypeSpecification.byKey(key));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -742,7 +723,7 @@ public class DistributionSetManagement {
|
||||
throw new EntityAlreadyExistsException("Given type contains an Id!");
|
||||
}
|
||||
|
||||
return distributionSetTypeRepository.save(type);
|
||||
return this.distributionSetTypeRepository.save(type);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -756,12 +737,12 @@ public class DistributionSetManagement {
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY)
|
||||
public void deleteDistributionSetType(@NotNull final DistributionSetType type) {
|
||||
|
||||
if (distributionSetRepository.countByType(type) > 0) {
|
||||
final DistributionSetType toDelete = entityManager.merge(type);
|
||||
if (this.distributionSetRepository.countByType(type) > 0) {
|
||||
final DistributionSetType toDelete = this.entityManager.merge(type);
|
||||
toDelete.setDeleted(true);
|
||||
distributionSetTypeRepository.save(toDelete);
|
||||
this.distributionSetTypeRepository.save(toDelete);
|
||||
} else {
|
||||
distributionSetTypeRepository.delete(type.getId());
|
||||
this.distributionSetTypeRepository.delete(type.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -779,15 +760,15 @@ public class DistributionSetManagement {
|
||||
@Modifying
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
|
||||
public DistributionSetMetadata createDistributionSetMetadata(@NotNull final DistributionSetMetadata metadata) {
|
||||
if (distributionSetMetadataRepository.exists(metadata.getId())) {
|
||||
if (this.distributionSetMetadataRepository.exists(metadata.getId())) {
|
||||
throwMetadataKeyAlreadyExists(metadata.getId().getKey());
|
||||
}
|
||||
// merge base software module 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);
|
||||
this.entityManager.merge(metadata.getDistributionSet()).setLastModifiedAt(0L);
|
||||
return this.distributionSetMetadataRepository.save(metadata);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -808,8 +789,8 @@ public class DistributionSetManagement {
|
||||
for (final DistributionSetMetadata distributionSetMetadata : metadata) {
|
||||
checkAndThrowAlreadyIfDistributionSetMetadataExists(distributionSetMetadata.getId());
|
||||
}
|
||||
metadata.forEach(m -> entityManager.merge(m.getDistributionSet()).setLastModifiedAt(-1L));
|
||||
return (List<DistributionSetMetadata>) distributionSetMetadataRepository.save(metadata);
|
||||
metadata.forEach(m -> this.entityManager.merge(m.getDistributionSet()).setLastModifiedAt(-1L));
|
||||
return (List<DistributionSetMetadata>) this.distributionSetMetadataRepository.save(metadata);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -830,8 +811,8 @@ public class DistributionSetManagement {
|
||||
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);
|
||||
this.entityManager.merge(metadata.getDistributionSet()).setLastModifiedAt(0L);
|
||||
return this.distributionSetMetadataRepository.save(metadata);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -844,7 +825,7 @@ public class DistributionSetManagement {
|
||||
@Modifying
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
|
||||
public void deleteDistributionSetMetadata(@NotNull final DsMetadataCompositeKey id) {
|
||||
distributionSetMetadataRepository.delete(id);
|
||||
this.distributionSetMetadataRepository.delete(id);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -861,14 +842,10 @@ public class DistributionSetManagement {
|
||||
public Page<DistributionSetMetadata> findDistributionSetMetadataByDistributionSetId(
|
||||
@NotNull final Long distributionSetId, @NotNull final Pageable pageable) {
|
||||
|
||||
return distributionSetMetadataRepository.findAll(new Specification<DistributionSetMetadata>() {
|
||||
@Override
|
||||
public Predicate toPredicate(final Root<DistributionSetMetadata> root, final CriteriaQuery<?> query,
|
||||
final CriteriaBuilder cb) {
|
||||
return cb.equal(root.get(DistributionSetMetadata_.distributionSet).get(DistributionSet_.id),
|
||||
distributionSetId);
|
||||
}
|
||||
}, pageable);
|
||||
return this.distributionSetMetadataRepository.findAll(
|
||||
(Specification<DistributionSetMetadata>) (root, query, cb) -> cb.equal(
|
||||
root.get(DistributionSetMetadata_.distributionSet).get(DistributionSet_.id), distributionSetId),
|
||||
pageable);
|
||||
|
||||
}
|
||||
|
||||
@@ -888,14 +865,14 @@ public class DistributionSetManagement {
|
||||
public Page<DistributionSetMetadata> findDistributionSetMetadataByDistributionSetId(
|
||||
@NotNull final Long distributionSetId, @NotNull final Specification<DistributionSetMetadata> spec,
|
||||
@NotNull final Pageable pageable) {
|
||||
return distributionSetMetadataRepository.findAll(new Specification<DistributionSetMetadata>() {
|
||||
@Override
|
||||
public Predicate toPredicate(final Root<DistributionSetMetadata> root, final CriteriaQuery<?> query,
|
||||
final CriteriaBuilder cb) {
|
||||
return cb.and(cb.equal(root.get(DistributionSetMetadata_.distributionSet).get(DistributionSet_.id),
|
||||
distributionSetId), spec.toPredicate(root, query, cb));
|
||||
}
|
||||
}, pageable);
|
||||
return this.distributionSetMetadataRepository
|
||||
.findAll(
|
||||
(Specification<DistributionSetMetadata>) (root, query,
|
||||
cb) -> cb.and(
|
||||
cb.equal(root.get(DistributionSetMetadata_.distributionSet)
|
||||
.get(DistributionSet_.id), distributionSetId),
|
||||
spec.toPredicate(root, query, cb)),
|
||||
pageable);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -910,7 +887,7 @@ public class DistributionSetManagement {
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
public DistributionSetMetadata findOne(@NotNull final DsMetadataCompositeKey id) {
|
||||
final DistributionSetMetadata findOne = distributionSetMetadataRepository.findOne(id);
|
||||
final DistributionSetMetadata findOne = this.distributionSetMetadataRepository.findOne(id);
|
||||
if (findOne == null) {
|
||||
throw new EntityNotFoundException("Metadata with key '" + id.getKey() + "' does not exist");
|
||||
}
|
||||
@@ -926,7 +903,7 @@ public class DistributionSetManagement {
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
public DistributionSet findDistributionSetByAction(@NotNull final Action action) {
|
||||
return distributionSetRepository.findByAction(action);
|
||||
return this.distributionSetRepository.findByAction(action);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -945,7 +922,7 @@ public class DistributionSetManagement {
|
||||
|
||||
/**
|
||||
* Checking Distribution Set is already using while assign Software module.
|
||||
*
|
||||
*
|
||||
* @param distributionSet
|
||||
* @param softwareModules
|
||||
*/
|
||||
@@ -1001,7 +978,7 @@ public class DistributionSetManagement {
|
||||
private void checkDistributionSetSoftwareModulesIsAllowedToModify(final DistributionSet distributionSet,
|
||||
final Set<SoftwareModule> softwareModules) {
|
||||
if (!new HashSet<SoftwareModule>(distributionSet.getModules()).equals(softwareModules)
|
||||
&& actionRepository.countByDistributionSet(distributionSet) > 0) {
|
||||
&& this.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()));
|
||||
@@ -1009,7 +986,7 @@ public class DistributionSetManagement {
|
||||
}
|
||||
|
||||
private void checkDistributionSetSoftwareModulesIsAllowedToModify(final DistributionSet distributionSet) {
|
||||
if (actionRepository.countByDistributionSet(distributionSet) > 0) {
|
||||
if (this.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()));
|
||||
@@ -1042,25 +1019,16 @@ public class DistributionSetManagement {
|
||||
*/
|
||||
private Page<DistributionSet> findByCriteriaAPI(@NotNull final Pageable pageable,
|
||||
final List<Specification<DistributionSet>> specList) {
|
||||
Specifications<DistributionSet> specs = null;
|
||||
if (!specList.isEmpty()) {
|
||||
specs = Specifications.where(specList.get(0));
|
||||
}
|
||||
if (specList.size() > 1) {
|
||||
for (final Specification<DistributionSet> s : specList.subList(1, specList.size())) {
|
||||
specs = specs.and(s);
|
||||
}
|
||||
|
||||
if (specList == null || specList.isEmpty()) {
|
||||
return this.distributionSetRepository.findAll(pageable);
|
||||
}
|
||||
|
||||
if (specs == null) {
|
||||
return distributionSetRepository.findAll(pageable);
|
||||
} else {
|
||||
return distributionSetRepository.findAll(specs, pageable);
|
||||
}
|
||||
return this.distributionSetRepository.findAll(SpecificationsBuilder.combineWithAnd(specList), pageable);
|
||||
}
|
||||
|
||||
private void checkAndThrowAlreadyIfDistributionSetMetadataExists(final DsMetadataCompositeKey metadataId) {
|
||||
if (distributionSetMetadataRepository.exists(metadataId)) {
|
||||
if (this.distributionSetMetadataRepository.exists(metadataId)) {
|
||||
throw new EntityAlreadyExistsException(
|
||||
"Metadata entry with key '" + metadataId.getKey() + "' already exists");
|
||||
}
|
||||
@@ -1089,13 +1057,13 @@ public class DistributionSetManagement {
|
||||
final List<DistributionSet> allDs = findDistributionSetListWithDetails(dsIds);
|
||||
|
||||
allDs.forEach(ds -> ds.getTags().add(tag));
|
||||
final List<DistributionSet> save = distributionSetRepository.save(allDs);
|
||||
final List<DistributionSet> save = this.distributionSetRepository.save(allDs);
|
||||
|
||||
afterCommit.afterCommit(() -> {
|
||||
this.afterCommit.afterCommit(() -> {
|
||||
|
||||
final DistributionSetTagAssigmentResult result = new DistributionSetTagAssigmentResult(0, save.size(), 0,
|
||||
save, Collections.emptyList(), tag);
|
||||
eventBus.post(new DistributionSetTagAssigmentResultEvent(result));
|
||||
this.eventBus.post(new DistributionSetTagAssigmentResultEvent(result));
|
||||
});
|
||||
|
||||
return save;
|
||||
@@ -1139,6 +1107,6 @@ public class DistributionSetManagement {
|
||||
private List<DistributionSet> unAssignTag(final Collection<DistributionSet> distributionSets,
|
||||
final DistributionSetTag tag) {
|
||||
distributionSets.forEach(ds -> ds.getTags().remove(tag));
|
||||
return distributionSetRepository.save(distributionSets);
|
||||
return this.distributionSetRepository.save(distributionSets);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ public class ReportManagement {
|
||||
@Cacheable("targetStatus")
|
||||
public DataReportSeries<TargetUpdateStatus> targetStatus() {
|
||||
|
||||
final CriteriaBuilder cb = entityManager.getCriteriaBuilder();
|
||||
final CriteriaBuilder cb = this.entityManager.getCriteriaBuilder();
|
||||
final CriteriaQuery<Object[]> query = cb.createQuery(Object[].class);
|
||||
final Root<Target> targetRoot = query.from(Target.class);
|
||||
final Join<Target, TargetInfo> targetInfo = targetRoot.join(Target_.targetInfo);
|
||||
@@ -111,7 +111,7 @@ public class ReportManagement {
|
||||
|
||||
// | col1 | col2 |
|
||||
// | U_STATUS | COUNT |
|
||||
final List<Object[]> resultList = entityManager.createQuery(multiselect).getResultList();
|
||||
final List<Object[]> resultList = this.entityManager.createQuery(multiselect).getResultList();
|
||||
|
||||
final List<DataReportSeriesItem<TargetUpdateStatus>> reportSeriesItems = resultList.stream()
|
||||
.map(r -> new DataReportSeriesItem<TargetUpdateStatus>((TargetUpdateStatus) r[0], (Long) r[1]))
|
||||
@@ -140,7 +140,7 @@ public class ReportManagement {
|
||||
public List<InnerOuterDataReportSeries<String>> distributionUsageAssigned(final int topXEntries) {
|
||||
|
||||
// top X entries distribution usage
|
||||
final CriteriaBuilder cbTopX = entityManager.getCriteriaBuilder();
|
||||
final CriteriaBuilder cbTopX = this.entityManager.getCriteriaBuilder();
|
||||
final CriteriaQuery<Object[]> queryTopX = cbTopX.createQuery(Object[].class);
|
||||
final Root<DistributionSet> rootTopX = queryTopX.from(DistributionSet.class);
|
||||
final ListJoin<DistributionSet, Target> joinTopX = rootTopX.join(DistributionSet_.assignedToTargets,
|
||||
@@ -154,7 +154,7 @@ public class ReportManagement {
|
||||
.orderBy(cbTopX.desc(countColumn), cbTopX.asc(rootTopX.get(DistributionSet_.name)));
|
||||
// | col1 | col2 | col3 |
|
||||
// | NAME | VER | COUNT |
|
||||
final List<Object[]> resultListTop = entityManager.createQuery(groupBy).getResultList();
|
||||
final List<Object[]> resultListTop = this.entityManager.createQuery(groupBy).getResultList();
|
||||
// end of top X entries distribution usage
|
||||
|
||||
return mapDistirbutionUsageResultToDataReport(topXEntries, resultListTop);
|
||||
@@ -180,7 +180,7 @@ public class ReportManagement {
|
||||
@Cacheable("distributionUsageInstalled")
|
||||
public List<InnerOuterDataReportSeries<String>> distributionUsageInstalled(final int topXEntries) {
|
||||
// top X entries distribution usage
|
||||
final CriteriaBuilder cbTopX = entityManager.getCriteriaBuilder();
|
||||
final CriteriaBuilder cbTopX = this.entityManager.getCriteriaBuilder();
|
||||
final CriteriaQuery<Object[]> queryTopX = cbTopX.createQuery(Object[].class);
|
||||
final Root<DistributionSet> rootTopX = queryTopX.from(DistributionSet.class);
|
||||
final ListJoin<DistributionSet, TargetInfo> joinTopX = rootTopX.join(DistributionSet_.installedAtTargets,
|
||||
@@ -194,7 +194,7 @@ public class ReportManagement {
|
||||
.orderBy(cbTopX.desc(countColumn), cbTopX.asc(rootTopX.get(DistributionSet_.name)));
|
||||
// | col1 | col2 | col3 |
|
||||
// | NAME | VER | COUNT |
|
||||
final List<Object[]> resultListTop = entityManager.createQuery(groupBy).getResultList();
|
||||
final List<Object[]> resultListTop = this.entityManager.createQuery(groupBy).getResultList();
|
||||
// end of top X entries distribution usage
|
||||
|
||||
return mapDistirbutionUsageResultToDataReport(topXEntries, resultListTop);
|
||||
@@ -213,9 +213,9 @@ public class ReportManagement {
|
||||
* count
|
||||
*/
|
||||
@Cacheable("targetsCreatedOverPeriod")
|
||||
public <T> DataReportSeries<T> targetsCreatedOverPeriod(final DateType<T> dateType, final LocalDateTime from,
|
||||
final LocalDateTime to) {
|
||||
final Query createNativeQuery = entityManager
|
||||
public <T extends Serializable> DataReportSeries<T> targetsCreatedOverPeriod(final DateType<T> dateType,
|
||||
final LocalDateTime from, final LocalDateTime to) {
|
||||
final Query createNativeQuery = this.entityManager
|
||||
.createNativeQuery(getTargetsCreatedQueryTemplate(dateType, from, to));
|
||||
final List<Object[]> resultList = createNativeQuery.getResultList();
|
||||
|
||||
@@ -223,22 +223,21 @@ public class ReportManagement {
|
||||
.map(r -> new DataReportSeriesItem<>(dateType.format((String) r[0]), ((Number) r[1]).longValue()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
final DataReportSeries<T> report = new DataReportSeries<>("CreatedTargets", reportItems);
|
||||
return report;
|
||||
return new DataReportSeries<>("CreatedTargets", reportItems);
|
||||
}
|
||||
|
||||
private String getTargetsCreatedQueryTemplate(final DateType<?> dateType, final LocalDateTime from,
|
||||
final LocalDateTime to) {
|
||||
switch (databaseType) {
|
||||
switch (this.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(),
|
||||
to.format(DATE_FORMAT), dateTimeFormatToSqlFormat(dateType), this.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(),
|
||||
to.toString(), dateTimeFormatToSqlFormat(dateType), this.tenantAware.getCurrentTenant(),
|
||||
dateTimeFormatToSqlFormat(dateType));
|
||||
default:
|
||||
return null;
|
||||
@@ -247,16 +246,16 @@ public class ReportManagement {
|
||||
|
||||
private String getFeedbackReceivedQueryTemplate(final DateType<?> dateType, final LocalDateTime from,
|
||||
final LocalDateTime to) {
|
||||
switch (databaseType) {
|
||||
switch (this.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(),
|
||||
to.format(DATE_FORMAT), dateTimeFormatToSqlFormat(dateType), this.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(),
|
||||
to.toString(), dateTimeFormatToSqlFormat(dateType), this.tenantAware.getCurrentTenant(),
|
||||
dateTimeFormatToSqlFormat(dateType));
|
||||
default:
|
||||
return null;
|
||||
@@ -276,9 +275,9 @@ public class ReportManagement {
|
||||
* count
|
||||
*/
|
||||
@Cacheable("feedbackReceivedOverTime")
|
||||
public <T> DataReportSeries<T> feedbackReceivedOverTime(final DateType<T> dateType, final LocalDateTime from,
|
||||
final LocalDateTime to) {
|
||||
final Query createNativeQuery = entityManager
|
||||
public <T extends Serializable> DataReportSeries<T> feedbackReceivedOverTime(final DateType<T> dateType,
|
||||
final LocalDateTime from, final LocalDateTime to) {
|
||||
final Query createNativeQuery = this.entityManager
|
||||
.createNativeQuery(getFeedbackReceivedQueryTemplate(dateType, from, to));
|
||||
final List<Object[]> resultList = createNativeQuery.getResultList();
|
||||
|
||||
@@ -286,8 +285,7 @@ public class ReportManagement {
|
||||
.map(r -> new DataReportSeriesItem<>(dateType.format((String) r[0]), ((Number) r[1]).longValue()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
final DataReportSeries<T> report = new DataReportSeries<>("FeedbackRecieved", reportItems);
|
||||
return report;
|
||||
return new DataReportSeries<>("FeedbackRecieved", reportItems);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -313,30 +311,30 @@ public class ReportManagement {
|
||||
final LocalDateTime beforeMonth = now.minusMonths(1);
|
||||
final LocalDateTime beforeYear = now.minusYears(1);
|
||||
|
||||
final CriteriaBuilder cb = entityManager.getCriteriaBuilder();
|
||||
final CriteriaBuilder cb = this.entityManager.getCriteriaBuilder();
|
||||
final List<DataReportSeriesItem<SeriesTime>> resultList = new ArrayList<>();
|
||||
|
||||
// hours
|
||||
resultList.add(new DataReportSeriesItem<SeriesTime>(SeriesTime.HOUR,
|
||||
entityManager.createQuery(createCountSelectTargetsLastPoll(cb, beforeHour, now)).getSingleResult()));
|
||||
resultList.add(new DataReportSeriesItem<SeriesTime>(SeriesTime.HOUR, this.entityManager
|
||||
.createQuery(createCountSelectTargetsLastPoll(cb, beforeHour, now)).getSingleResult()));
|
||||
// days
|
||||
resultList.add(new DataReportSeriesItem<SeriesTime>(SeriesTime.DAY, entityManager
|
||||
resultList.add(new DataReportSeriesItem<SeriesTime>(SeriesTime.DAY, this.entityManager
|
||||
.createQuery(createCountSelectTargetsLastPoll(cb, beforeDay, beforeHour)).getSingleResult()));
|
||||
// weeks
|
||||
resultList.add(new DataReportSeriesItem<SeriesTime>(SeriesTime.WEEK, entityManager
|
||||
resultList.add(new DataReportSeriesItem<SeriesTime>(SeriesTime.WEEK, this.entityManager
|
||||
.createQuery(createCountSelectTargetsLastPoll(cb, beforeWeek, beforeDay)).getSingleResult()));
|
||||
// months
|
||||
resultList.add(new DataReportSeriesItem<SeriesTime>(SeriesTime.MONTH, entityManager
|
||||
resultList.add(new DataReportSeriesItem<SeriesTime>(SeriesTime.MONTH, this.entityManager
|
||||
.createQuery(createCountSelectTargetsLastPoll(cb, beforeMonth, beforeWeek)).getSingleResult()));
|
||||
// years
|
||||
resultList.add(new DataReportSeriesItem<SeriesTime>(SeriesTime.YEAR, entityManager
|
||||
resultList.add(new DataReportSeriesItem<SeriesTime>(SeriesTime.YEAR, this.entityManager
|
||||
.createQuery(createCountSelectTargetsLastPoll(cb, beforeYear, beforeMonth)).getSingleResult()));
|
||||
// years
|
||||
resultList.add(new DataReportSeriesItem<SeriesTime>(SeriesTime.MORE_THAN_YEAR,
|
||||
entityManager.createQuery(createCountSelectTargetsLastPoll(cb, null, beforeYear)).getSingleResult()));
|
||||
resultList.add(new DataReportSeriesItem<SeriesTime>(SeriesTime.MORE_THAN_YEAR, this.entityManager
|
||||
.createQuery(createCountSelectTargetsLastPoll(cb, null, beforeYear)).getSingleResult()));
|
||||
// never
|
||||
resultList.add(new DataReportSeriesItem<SeriesTime>(SeriesTime.NEVER,
|
||||
entityManager.createQuery(createCountSelectTargetsLastPoll(cb, null, null)).getSingleResult()));
|
||||
this.entityManager.createQuery(createCountSelectTargetsLastPoll(cb, null, null)).getSingleResult()));
|
||||
|
||||
return new DataReportSeries<>("TargetLastPoll", resultList);
|
||||
}
|
||||
@@ -417,23 +415,23 @@ public class ReportManagement {
|
||||
final List<InnerOuter> outer;
|
||||
|
||||
private InnerOuter(final DSName idName) {
|
||||
name = idName;
|
||||
outer = new ArrayList<>();
|
||||
this.name = idName;
|
||||
this.outer = new ArrayList<>();
|
||||
}
|
||||
|
||||
private InnerOuter(final DSName idName, final long count) {
|
||||
name = idName;
|
||||
this.name = idName;
|
||||
this.count = count;
|
||||
outer = new ArrayList<>();
|
||||
this.outer = new ArrayList<>();
|
||||
}
|
||||
|
||||
private void addOuter(final DSName idName, final long count) {
|
||||
outer.add(new InnerOuter(idName, count));
|
||||
this.outer.add(new InnerOuter(idName, count));
|
||||
this.count += count;
|
||||
}
|
||||
|
||||
private DataReportSeriesItem<String> toItem() {
|
||||
return new DataReportSeriesItem<String>(name.getName() != null ? name.getName() : "misc", count);
|
||||
return new DataReportSeriesItem<>(this.name.getName() != null ? this.name.getName() : "misc", this.count);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -462,7 +460,7 @@ public class ReportManagement {
|
||||
* @return the name
|
||||
*/
|
||||
private String getName() {
|
||||
return name;
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -474,7 +472,7 @@ public class ReportManagement {
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + (name == null ? 0 : name.hashCode());
|
||||
result = prime * result + (this.name == null ? 0 : this.name.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -496,11 +494,11 @@ public class ReportManagement {
|
||||
return false;
|
||||
}
|
||||
final DSName other = (DSName) obj;
|
||||
if (name == null) {
|
||||
if (this.name == null) {
|
||||
if (other.name != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!name.equals(other.name)) {
|
||||
} else if (!this.name.equals(other.name)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -513,12 +511,12 @@ public class ReportManagement {
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DSName [name=" + name + "]";
|
||||
return "DSName [name=" + this.name + "]";
|
||||
}
|
||||
}
|
||||
|
||||
private String dateTimeFormatToSqlFormat(final DateType<?> datatype) {
|
||||
switch (databaseType) {
|
||||
switch (this.databaseType) {
|
||||
case H2_DB_TYPE:
|
||||
return datatype.h2Format();
|
||||
case MYSQL_DB_TYPE:
|
||||
|
||||
@@ -40,6 +40,7 @@ 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.hibernate.validator.constraints.NotEmpty;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.AuditorAware;
|
||||
@@ -48,7 +49,6 @@ import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Slice;
|
||||
import org.springframework.data.domain.SliceImpl;
|
||||
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;
|
||||
@@ -117,7 +117,7 @@ public class SoftwareManagement {
|
||||
public SoftwareModule updateSoftwareModule(@NotNull final SoftwareModule sm) {
|
||||
checkNotNull(sm.getId());
|
||||
|
||||
final SoftwareModule module = softwareModuleRepository.findOne(sm.getId());
|
||||
final SoftwareModule module = this.softwareModuleRepository.findOne(sm.getId());
|
||||
|
||||
if (null == sm.getDescription() || !sm.getDescription().equals(module.getDescription())) {
|
||||
module.setDescription(sm.getDescription());
|
||||
@@ -125,7 +125,7 @@ public class SoftwareManagement {
|
||||
if (null == sm.getVendor() || !sm.getVendor().equals(module.getVendor())) {
|
||||
module.setVendor(sm.getVendor());
|
||||
}
|
||||
return softwareModuleRepository.save(module);
|
||||
return this.softwareModuleRepository.save(module);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -143,7 +143,7 @@ public class SoftwareManagement {
|
||||
public SoftwareModuleType updateSoftwareModuleType(@NotNull final SoftwareModuleType sm) {
|
||||
checkNotNull(sm.getId());
|
||||
|
||||
final SoftwareModuleType type = softwareModuleTypeRepository.findOne(sm.getId());
|
||||
final SoftwareModuleType type = this.softwareModuleTypeRepository.findOne(sm.getId());
|
||||
|
||||
if (sm.getDescription() != null && !sm.getDescription().equals(type.getDescription())) {
|
||||
type.setDescription(sm.getDescription());
|
||||
@@ -151,7 +151,7 @@ public class SoftwareManagement {
|
||||
if (sm.getColour() != null && !sm.getColour().equals(type.getColour())) {
|
||||
type.setColour(sm.getColour());
|
||||
}
|
||||
return softwareModuleTypeRepository.save(type);
|
||||
return this.softwareModuleTypeRepository.save(type);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -169,7 +169,7 @@ public class SoftwareManagement {
|
||||
if (null != swModule.getId()) {
|
||||
throw new EntityAlreadyExistsException();
|
||||
}
|
||||
return softwareModuleRepository.save(swModule);
|
||||
return this.softwareModuleRepository.save(swModule);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -191,14 +191,14 @@ public class SoftwareManagement {
|
||||
}
|
||||
});
|
||||
|
||||
return softwareModuleRepository.save(swModules);
|
||||
return this.softwareModuleRepository.save(swModules);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* retrieves the {@link SoftwareModule}s by their {@link SoftwareModuleType}
|
||||
* .
|
||||
*
|
||||
*
|
||||
* @param pageable
|
||||
* page parameters
|
||||
* @param type
|
||||
@@ -209,7 +209,7 @@ public class SoftwareManagement {
|
||||
public Slice<SoftwareModule> findSoftwareModulesByType(@NotNull final Pageable pageable,
|
||||
@NotNull final SoftwareModuleType type) {
|
||||
|
||||
final List<Specification<SoftwareModule>> specList = new ArrayList<Specification<SoftwareModule>>();
|
||||
final List<Specification<SoftwareModule>> specList = new ArrayList<>();
|
||||
|
||||
Specification<SoftwareModule> spec = SoftwareModuleSpecification.equalType(type);
|
||||
specList.add(spec);
|
||||
@@ -230,7 +230,7 @@ public class SoftwareManagement {
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
public Long countSoftwareModulesByType(@NotNull final SoftwareModuleType type) {
|
||||
|
||||
final List<Specification<SoftwareModule>> specList = new ArrayList<Specification<SoftwareModule>>();
|
||||
final List<Specification<SoftwareModule>> specList = new ArrayList<>();
|
||||
|
||||
Specification<SoftwareModule> spec = SoftwareModuleSpecification.equalType(type);
|
||||
specList.add(spec);
|
||||
@@ -252,12 +252,12 @@ public class SoftwareManagement {
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY + SpringEvalExpressions.HAS_AUTH_OR
|
||||
+ SpringEvalExpressions.IS_CONTROLLER)
|
||||
public SoftwareModule findSoftwareModuleById(@NotNull final Long id) {
|
||||
return artifactManagement.findSoftwareModuleById(id);
|
||||
return this.artifactManagement.findSoftwareModuleById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* retrieves {@link SoftwareModule}s by their name AND version.
|
||||
*
|
||||
*
|
||||
* @param name
|
||||
* of the {@link SoftwareModule}
|
||||
* @param version
|
||||
@@ -268,12 +268,12 @@ public class SoftwareManagement {
|
||||
public List<SoftwareModule> findSoftwareModuleByNameAndVersion(@NotEmpty final String name,
|
||||
@NotEmpty final String version) {
|
||||
|
||||
return softwareModuleRepository.findByNameAndVersion(name, version);
|
||||
return this.softwareModuleRepository.findByNameAndVersion(name, version);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the given {@link SoftwareModule} {@link Entity}.
|
||||
*
|
||||
*
|
||||
* @param bsm
|
||||
* is the {@link SoftwareModule} to be deleted
|
||||
*/
|
||||
@@ -286,42 +286,28 @@ public class SoftwareManagement {
|
||||
}
|
||||
|
||||
private boolean isUnassigned(final SoftwareModule bsmMerged) {
|
||||
return distributionSetRepository.findByModules(bsmMerged).isEmpty();
|
||||
return this.distributionSetRepository.findByModules(bsmMerged).isEmpty();
|
||||
}
|
||||
|
||||
private Slice<SoftwareModule> findSwModuleByCriteriaAPI(@NotNull final Pageable pageable,
|
||||
@NotEmpty final List<Specification<SoftwareModule>> specList) {
|
||||
|
||||
Specifications<SoftwareModule> specs = Specifications.where(specList.get(0));
|
||||
if (specList.size() > 1) {
|
||||
for (final Specification<SoftwareModule> s : specList.subList(1, specList.size())) {
|
||||
specs = specs.and(s);
|
||||
}
|
||||
}
|
||||
|
||||
return criteriaNoCountDao.findAll(specs, pageable, SoftwareModule.class);
|
||||
return this.criteriaNoCountDao.findAll(SpecificationsBuilder.combineWithAnd(specList), pageable,
|
||||
SoftwareModule.class);
|
||||
}
|
||||
|
||||
private Long countSwModuleByCriteriaAPI(@NotEmpty final List<Specification<SoftwareModule>> specList) {
|
||||
Specifications<SoftwareModule> specs = Specifications.where(specList.get(0));
|
||||
if (specList.size() > 1) {
|
||||
for (final Specification<SoftwareModule> s : specList.subList(1, specList.size())) {
|
||||
specs = specs.and(s);
|
||||
}
|
||||
}
|
||||
|
||||
return softwareModuleRepository.count(specs);
|
||||
return this.softwareModuleRepository.count(SpecificationsBuilder.combineWithAnd(specList));
|
||||
}
|
||||
|
||||
private void deleteGridFsArtifacts(final SoftwareModule swModule) {
|
||||
for (final LocalArtifact localArtifact : swModule.getLocalArtifacts()) {
|
||||
artifactManagement.deleteGridFsArtifact(localArtifact);
|
||||
this.artifactManagement.deleteGridFsArtifact(localArtifact);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes {@link SoftwareModule}s which is any if the given ids.
|
||||
*
|
||||
*
|
||||
* @param ids
|
||||
* of the Software Moduels to be deleted
|
||||
*/
|
||||
@@ -329,7 +315,7 @@ public class SoftwareManagement {
|
||||
@Transactional
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY)
|
||||
public void deleteSoftwareModules(@NotNull final Iterable<Long> ids) {
|
||||
final List<SoftwareModule> swModulesToDelete = softwareModuleRepository.findByIdIn(ids);
|
||||
final List<SoftwareModule> swModulesToDelete = this.softwareModuleRepository.findByIdIn(ids);
|
||||
final Set<Long> assignedModuleIds = new HashSet<>();
|
||||
swModulesToDelete.forEach(swModule -> {
|
||||
|
||||
@@ -338,7 +324,7 @@ public class SoftwareManagement {
|
||||
|
||||
if (isUnassigned(swModule)) {
|
||||
|
||||
softwareModuleRepository.delete(swModule);
|
||||
this.softwareModuleRepository.delete(swModule);
|
||||
|
||||
} else {
|
||||
|
||||
@@ -348,10 +334,10 @@ public class SoftwareManagement {
|
||||
|
||||
if (!assignedModuleIds.isEmpty()) {
|
||||
String currentUser = null;
|
||||
if (auditorProvider != null) {
|
||||
currentUser = auditorProvider.getCurrentAuditor();
|
||||
if (this.auditorProvider != null) {
|
||||
currentUser = this.auditorProvider.getCurrentAuditor();
|
||||
}
|
||||
softwareModuleRepository.deleteSoftwareModule(System.currentTimeMillis(), currentUser,
|
||||
this.softwareModuleRepository.deleteSoftwareModule(System.currentTimeMillis(), currentUser,
|
||||
assignedModuleIds.toArray(new Long[0]));
|
||||
}
|
||||
}
|
||||
@@ -366,20 +352,16 @@ public class SoftwareManagement {
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
public Slice<SoftwareModule> findSoftwareModulesAll(@NotNull final Pageable pageable) {
|
||||
|
||||
final List<Specification<SoftwareModule>> specList = new ArrayList<Specification<SoftwareModule>>();
|
||||
final List<Specification<SoftwareModule>> specList = new ArrayList<>();
|
||||
|
||||
Specification<SoftwareModule> spec = SoftwareModuleSpecification.isDeletedFalse();
|
||||
specList.add(spec);
|
||||
|
||||
spec = new Specification<SoftwareModule>() {
|
||||
@Override
|
||||
public Predicate toPredicate(final Root<SoftwareModule> root, final CriteriaQuery<?> query,
|
||||
final CriteriaBuilder cb) {
|
||||
if (!query.getResultType().isAssignableFrom(Long.class)) {
|
||||
root.fetch(SoftwareModule_.type);
|
||||
}
|
||||
return cb.conjunction();
|
||||
spec = (root, query, cb) -> {
|
||||
if (!query.getResultType().isAssignableFrom(Long.class)) {
|
||||
root.fetch(SoftwareModule_.type);
|
||||
}
|
||||
return cb.conjunction();
|
||||
};
|
||||
|
||||
specList.add(spec);
|
||||
@@ -396,7 +378,7 @@ public class SoftwareManagement {
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
public Long countSoftwareModulesAll() {
|
||||
|
||||
final List<Specification<SoftwareModule>> specList = new ArrayList<Specification<SoftwareModule>>();
|
||||
final List<Specification<SoftwareModule>> specList = new ArrayList<>();
|
||||
|
||||
final Specification<SoftwareModule> spec = SoftwareModuleSpecification.isDeletedFalse();
|
||||
specList.add(spec);
|
||||
@@ -416,7 +398,7 @@ public class SoftwareManagement {
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
public SoftwareModule findSoftwareModuleWithDetails(@NotNull final Long id) {
|
||||
return artifactManagement.findSoftwareModuleWithDetails(id);
|
||||
return this.artifactManagement.findSoftwareModuleWithDetails(id);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -431,7 +413,7 @@ public class SoftwareManagement {
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
public Page<SoftwareModule> findSoftwareModulesByPredicate(@NotNull final Specification<SoftwareModule> spec,
|
||||
@NotNull final Pageable pageable) {
|
||||
return softwareModuleRepository.findAll(spec, pageable);
|
||||
return this.softwareModuleRepository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -446,7 +428,7 @@ public class SoftwareManagement {
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
public Page<SoftwareModuleType> findSoftwareModuleTypesByPredicate(
|
||||
@NotNull final Specification<SoftwareModuleType> spec, @NotNull final Pageable pageable) {
|
||||
return softwareModuleTypeRepository.findAll(spec, pageable);
|
||||
return this.softwareModuleTypeRepository.findAll(spec, pageable);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -459,7 +441,7 @@ public class SoftwareManagement {
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
public List<SoftwareModule> findSoftwareModulesById(@NotEmpty final List<Long> ids) {
|
||||
return softwareModuleRepository.findByIdIn(ids);
|
||||
return this.softwareModuleRepository.findByIdIn(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -479,7 +461,7 @@ public class SoftwareManagement {
|
||||
public Slice<SoftwareModule> findSoftwareModuleByFilters(@NotNull final Pageable pageable, final String searchText,
|
||||
final SoftwareModuleType type) {
|
||||
|
||||
final List<Specification<SoftwareModule>> specList = new ArrayList<Specification<SoftwareModule>>();
|
||||
final List<Specification<SoftwareModule>> specList = new ArrayList<>();
|
||||
|
||||
Specification<SoftwareModule> spec = SoftwareModuleSpecification.isDeletedFalse();
|
||||
specList.add(spec);
|
||||
@@ -494,15 +476,11 @@ public class SoftwareManagement {
|
||||
specList.add(spec);
|
||||
}
|
||||
|
||||
spec = new Specification<SoftwareModule>() {
|
||||
@Override
|
||||
public Predicate toPredicate(final Root<SoftwareModule> root, final CriteriaQuery<?> query,
|
||||
final CriteriaBuilder cb) {
|
||||
if (!query.getResultType().isAssignableFrom(Long.class)) {
|
||||
root.fetch(SoftwareModule_.type);
|
||||
}
|
||||
return cb.conjunction();
|
||||
spec = (root, query, cb) -> {
|
||||
if (!query.getResultType().isAssignableFrom(Long.class)) {
|
||||
root.fetch(SoftwareModule_.type);
|
||||
}
|
||||
return cb.conjunction();
|
||||
};
|
||||
|
||||
specList.add(spec);
|
||||
@@ -531,7 +509,7 @@ public class SoftwareManagement {
|
||||
|
||||
final List<CustomSoftwareModule> resultList = new ArrayList<>();
|
||||
final int pageSize = pageable.getPageSize();
|
||||
final CriteriaBuilder cb = entityManager.getCriteriaBuilder();
|
||||
final CriteriaBuilder cb = this.entityManager.getCriteriaBuilder();
|
||||
|
||||
// get the assigned software modules
|
||||
final CriteriaQuery<SoftwareModule> assignedQuery = cb.createQuery(SoftwareModule.class);
|
||||
@@ -551,7 +529,8 @@ public class SoftwareManagement {
|
||||
// don't page the assigned query on database, we need all assigned
|
||||
// software modules to filter
|
||||
// them out in the unassigned query
|
||||
final List<SoftwareModule> assignedSoftwareModules = entityManager.createQuery(assignedQuery).getResultList();
|
||||
final List<SoftwareModule> assignedSoftwareModules = this.entityManager.createQuery(assignedQuery)
|
||||
.getResultList();
|
||||
// map result
|
||||
if (pageable.getOffset() < assignedSoftwareModules.size()) {
|
||||
assignedSoftwareModules
|
||||
@@ -581,7 +560,7 @@ public class SoftwareManagement {
|
||||
unassignedQuery.where(unassignedSpec);
|
||||
unassignedQuery.orderBy(cb.asc(unassignedRoot.get(SoftwareModule_.name)),
|
||||
cb.asc(unassignedRoot.get(SoftwareModule_.version)));
|
||||
final List<SoftwareModule> unassignedSoftwareModules = entityManager.createQuery(unassignedQuery)
|
||||
final List<SoftwareModule> unassignedSoftwareModules = this.entityManager.createQuery(unassignedQuery)
|
||||
.setFirstResult(Math.max(0, pageable.getOffset() - assignedSoftwareModules.size()))
|
||||
.setMaxResults(pageSize).getResultList();
|
||||
// map result
|
||||
@@ -592,7 +571,7 @@ public class SoftwareManagement {
|
||||
|
||||
private List<Specification<SoftwareModule>> buildSpecificationList(final String searchText,
|
||||
final SoftwareModuleType type) {
|
||||
final List<Specification<SoftwareModule>> specList = new ArrayList<Specification<SoftwareModule>>();
|
||||
final List<Specification<SoftwareModule>> specList = new ArrayList<>();
|
||||
if (!Strings.isNullOrEmpty(searchText)) {
|
||||
specList.add(SoftwareModuleSpecification.likeNameOrVersion(searchText));
|
||||
}
|
||||
@@ -631,7 +610,7 @@ public class SoftwareManagement {
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
public Long countSoftwareModuleByFilters(final String searchText, final SoftwareModuleType type) {
|
||||
|
||||
final List<Specification<SoftwareModule>> specList = new ArrayList<Specification<SoftwareModule>>();
|
||||
final List<Specification<SoftwareModule>> specList = new ArrayList<>();
|
||||
|
||||
Specification<SoftwareModule> spec = SoftwareModuleSpecification.isDeletedFalse();
|
||||
specList.add(spec);
|
||||
@@ -656,7 +635,7 @@ public class SoftwareManagement {
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
public Page<SoftwareModuleType> findSoftwareModuleTypesAll(@NotNull final Pageable pageable) {
|
||||
return softwareModuleTypeRepository.findByDeleted(pageable, false);
|
||||
return this.softwareModuleTypeRepository.findByDeleted(pageable, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -664,7 +643,7 @@ public class SoftwareManagement {
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
public Long countSoftwareModuleTypesAll() {
|
||||
return softwareModuleTypeRepository.countByDeleted(false);
|
||||
return this.softwareModuleTypeRepository.countByDeleted(false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -676,7 +655,7 @@ public class SoftwareManagement {
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
public SoftwareModuleType findSoftwareModuleTypeByKey(@NotNull final String key) {
|
||||
return softwareModuleTypeRepository.findByKey(key);
|
||||
return this.softwareModuleTypeRepository.findByKey(key);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -688,7 +667,7 @@ public class SoftwareManagement {
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
public SoftwareModuleType findSoftwareModuleTypeById(@NotNull final Long id) {
|
||||
return softwareModuleTypeRepository.findOne(id);
|
||||
return this.softwareModuleTypeRepository.findOne(id);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -700,7 +679,7 @@ public class SoftwareManagement {
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
public SoftwareModuleType findSoftwareModuleTypeByName(@NotNull final String name) {
|
||||
return softwareModuleTypeRepository.findByName(name);
|
||||
return this.softwareModuleTypeRepository.findByName(name);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -718,7 +697,7 @@ public class SoftwareManagement {
|
||||
throw new EntityAlreadyExistsException("Given type contains an Id!");
|
||||
}
|
||||
|
||||
return softwareModuleTypeRepository.save(type);
|
||||
return this.softwareModuleTypeRepository.save(type);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -746,13 +725,13 @@ public class SoftwareManagement {
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY)
|
||||
public void deleteSoftwareModuleType(@NotNull final SoftwareModuleType type) {
|
||||
|
||||
if (softwareModuleRepository.countByType(type) > 0
|
||||
|| distributionSetTypeRepository.countByElementsSmType(type) > 0) {
|
||||
final SoftwareModuleType toDelete = entityManager.merge(type);
|
||||
if (this.softwareModuleRepository.countByType(type) > 0
|
||||
|| this.distributionSetTypeRepository.countByElementsSmType(type) > 0) {
|
||||
final SoftwareModuleType toDelete = this.entityManager.merge(type);
|
||||
toDelete.setDeleted(true);
|
||||
softwareModuleTypeRepository.save(toDelete);
|
||||
this.softwareModuleTypeRepository.save(toDelete);
|
||||
} else {
|
||||
softwareModuleTypeRepository.delete(type.getId());
|
||||
this.softwareModuleTypeRepository.delete(type.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -767,7 +746,7 @@ public class SoftwareManagement {
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
public Page<SoftwareModule> findSoftwareModuleByAssignedTo(@NotNull final Pageable pageable,
|
||||
@NotNull final DistributionSet set) {
|
||||
return softwareModuleRepository.findByAssignedTo(pageable, set);
|
||||
return this.softwareModuleRepository.findByAssignedTo(pageable, set);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -783,12 +762,12 @@ public class SoftwareManagement {
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
public Page<SoftwareModule> findSoftwareModuleByAssignedToAndType(@NotNull final Pageable pageable,
|
||||
@NotNull final DistributionSet set, @NotNull final SoftwareModuleType type) {
|
||||
return softwareModuleRepository.findByAssignedToAndType(pageable, set, type);
|
||||
return this.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
|
||||
@@ -800,20 +779,20 @@ public class SoftwareManagement {
|
||||
@Modifying
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
|
||||
public SoftwareModuleMetadata createSoftwareModuleMetadata(@NotNull final SoftwareModuleMetadata metadata) {
|
||||
if (softwareModuleMetadataRepository.exists(metadata.getId())) {
|
||||
if (this.softwareModuleMetadataRepository.exists(metadata.getId())) {
|
||||
throwMetadataKeyAlreadyExists(metadata.getId().getKey());
|
||||
}
|
||||
// merge base software module so optLockRevision gets updated and audit
|
||||
// log written because
|
||||
// modifying metadata is modifying the base software module itself for
|
||||
// auditing purposes.
|
||||
entityManager.merge(metadata.getSoftwareModule()).setLastModifiedAt(-1L);
|
||||
return softwareModuleMetadataRepository.save(metadata);
|
||||
this.entityManager.merge(metadata.getSoftwareModule()).setLastModifiedAt(-1L);
|
||||
return this.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
|
||||
@@ -829,13 +808,13 @@ public class SoftwareManagement {
|
||||
for (final SoftwareModuleMetadata softwareModuleMetadata : metadata) {
|
||||
checkAndThrowAlreadyExistsIfSoftwareModuleMetadataExists(softwareModuleMetadata.getId());
|
||||
}
|
||||
metadata.forEach(m -> entityManager.merge(m.getSoftwareModule()).setLastModifiedAt(-1L));
|
||||
return softwareModuleMetadataRepository.save(metadata);
|
||||
metadata.forEach(m -> this.entityManager.merge(m.getSoftwareModule()).setLastModifiedAt(-1L));
|
||||
return this.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
|
||||
@@ -852,13 +831,13 @@ public class SoftwareManagement {
|
||||
// touch it to update the lock revision because we are modifying the
|
||||
// software module
|
||||
// indirectly
|
||||
entityManager.merge(metadata.getSoftwareModule()).setLastModifiedAt(-1L);
|
||||
return softwareModuleMetadataRepository.save(metadata);
|
||||
this.entityManager.merge(metadata.getSoftwareModule()).setLastModifiedAt(-1L);
|
||||
return this.softwareModuleMetadataRepository.save(metadata);
|
||||
}
|
||||
|
||||
/**
|
||||
* deletes a software module meta data entry.
|
||||
*
|
||||
*
|
||||
* @param id
|
||||
* the ID of the software module meta data to delete
|
||||
*/
|
||||
@@ -866,12 +845,12 @@ public class SoftwareManagement {
|
||||
@Modifying
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
|
||||
public void deleteSoftwareModuleMetadata(@NotNull final SwMetadataCompositeKey id) {
|
||||
softwareModuleMetadataRepository.delete(id);
|
||||
this.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
|
||||
@@ -882,12 +861,12 @@ public class SoftwareManagement {
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
public Page<SoftwareModuleMetadata> findSoftwareModuleMetadataBySoftwareModuleId(@NotNull final Long swId,
|
||||
@NotNull final Pageable pageable) {
|
||||
return softwareModuleMetadataRepository.findBySoftwareModuleId(swId, pageable);
|
||||
return this.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
|
||||
@@ -900,20 +879,19 @@ public class SoftwareManagement {
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
public Page<SoftwareModuleMetadata> findSoftwareModuleMetadataBySoftwareModuleId(final Long softwareModuleId,
|
||||
@NotNull final Specification<SoftwareModuleMetadata> spec, @NotNull final Pageable pageable) {
|
||||
return softwareModuleMetadataRepository.findAll(new Specification<SoftwareModuleMetadata>() {
|
||||
@Override
|
||||
public Predicate toPredicate(final Root<SoftwareModuleMetadata> root, final CriteriaQuery<?> query,
|
||||
final CriteriaBuilder cb) {
|
||||
|
||||
return cb.and(cb.equal(root.get(SoftwareModuleMetadata_.softwareModule).get(SoftwareModule_.id),
|
||||
softwareModuleId), spec.toPredicate(root, query, cb));
|
||||
}
|
||||
}, pageable);
|
||||
return this.softwareModuleMetadataRepository
|
||||
.findAll(
|
||||
(Specification<SoftwareModuleMetadata>) (root, query,
|
||||
cb) -> cb.and(
|
||||
cb.equal(root.get(SoftwareModuleMetadata_.softwareModule)
|
||||
.get(SoftwareModule_.id), softwareModuleId),
|
||||
spec.toPredicate(root, query, cb)),
|
||||
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
|
||||
@@ -923,7 +901,7 @@ public class SoftwareManagement {
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
public SoftwareModuleMetadata findOne(@NotNull final SwMetadataCompositeKey id) {
|
||||
final SoftwareModuleMetadata findOne = softwareModuleMetadataRepository.findOne(id);
|
||||
final SoftwareModuleMetadata findOne = this.softwareModuleMetadataRepository.findOne(id);
|
||||
if (findOne == null) {
|
||||
throw new EntityNotFoundException("Metadata with key '" + id.getKey() + "' does not exist");
|
||||
}
|
||||
@@ -931,7 +909,7 @@ public class SoftwareManagement {
|
||||
}
|
||||
|
||||
private void checkAndThrowAlreadyExistsIfSoftwareModuleMetadataExists(final SwMetadataCompositeKey metadataId) {
|
||||
if (softwareModuleMetadataRepository.exists(metadataId)) {
|
||||
if (this.softwareModuleMetadataRepository.exists(metadataId)) {
|
||||
throw new EntityAlreadyExistsException(
|
||||
"Metadata entry with key '" + metadataId.getKey() + "' already exists");
|
||||
}
|
||||
|
||||
@@ -77,13 +77,13 @@ public class Rollout extends NamedEntity {
|
||||
private int rolloutGroupsCreated = 0;
|
||||
|
||||
@Transient
|
||||
private TotalTargetCountStatus totalTargetCountStatus;
|
||||
private transient TotalTargetCountStatus totalTargetCountStatus;
|
||||
|
||||
/**
|
||||
* @return the distributionSet
|
||||
*/
|
||||
public DistributionSet getDistributionSet() {
|
||||
return distributionSet;
|
||||
return this.distributionSet;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,7 +98,7 @@ public class Rollout extends NamedEntity {
|
||||
* @return the rolloutGroups
|
||||
*/
|
||||
public List<RolloutGroup> getRolloutGroups() {
|
||||
return rolloutGroups;
|
||||
return this.rolloutGroups;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -113,7 +113,7 @@ public class Rollout extends NamedEntity {
|
||||
* @return the targetFilterQuery
|
||||
*/
|
||||
public String getTargetFilterQuery() {
|
||||
return targetFilterQuery;
|
||||
return this.targetFilterQuery;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -128,7 +128,7 @@ public class Rollout extends NamedEntity {
|
||||
* @return the status
|
||||
*/
|
||||
public RolloutStatus getStatus() {
|
||||
return status;
|
||||
return this.status;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -143,7 +143,7 @@ public class Rollout extends NamedEntity {
|
||||
* @return the lastCheck
|
||||
*/
|
||||
public long getLastCheck() {
|
||||
return lastCheck;
|
||||
return this.lastCheck;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -158,7 +158,7 @@ public class Rollout extends NamedEntity {
|
||||
* @return the actionType
|
||||
*/
|
||||
public ActionType getActionType() {
|
||||
return actionType;
|
||||
return this.actionType;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -173,7 +173,7 @@ public class Rollout extends NamedEntity {
|
||||
* @return the forcedTime
|
||||
*/
|
||||
public long getForcedTime() {
|
||||
return forcedTime;
|
||||
return this.forcedTime;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -188,7 +188,7 @@ public class Rollout extends NamedEntity {
|
||||
* @return the totalTargets
|
||||
*/
|
||||
public long getTotalTargets() {
|
||||
return totalTargets;
|
||||
return this.totalTargets;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -203,7 +203,7 @@ public class Rollout extends NamedEntity {
|
||||
* @return the rolloutGroupsTotal
|
||||
*/
|
||||
public int getRolloutGroupsTotal() {
|
||||
return rolloutGroupsTotal;
|
||||
return this.rolloutGroupsTotal;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -218,7 +218,7 @@ public class Rollout extends NamedEntity {
|
||||
* @return the rolloutGroupsCreated
|
||||
*/
|
||||
public int getRolloutGroupsCreated() {
|
||||
return rolloutGroupsCreated;
|
||||
return this.rolloutGroupsCreated;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -233,10 +233,10 @@ public class Rollout extends NamedEntity {
|
||||
* @return the totalTargetCountStatus
|
||||
*/
|
||||
public TotalTargetCountStatus getTotalTargetCountStatus() {
|
||||
if (totalTargetCountStatus == null) {
|
||||
this.totalTargetCountStatus = new TotalTargetCountStatus(totalTargets);
|
||||
if (this.totalTargetCountStatus == null) {
|
||||
this.totalTargetCountStatus = new TotalTargetCountStatus(this.totalTargets);
|
||||
}
|
||||
return totalTargetCountStatus;
|
||||
return this.totalTargetCountStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -249,17 +249,17 @@ public class Rollout extends NamedEntity {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Rollout [rolloutGroups=" + rolloutGroups + ", targetFilterQuery=" + targetFilterQuery
|
||||
+ ", distributionSet=" + distributionSet + ", status=" + status + ", lastCheck=" + lastCheck
|
||||
+ ", getName()=" + getName() + ", getId()=" + getId() + "]";
|
||||
return "Rollout [rolloutGroups=" + this.rolloutGroups + ", targetFilterQuery=" + this.targetFilterQuery
|
||||
+ ", distributionSet=" + this.distributionSet + ", status=" + this.status + ", lastCheck="
|
||||
+ this.lastCheck + ", getName()=" + getName() + ", getId()=" + getId() + "]";
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Michael Hirsch
|
||||
*
|
||||
*/
|
||||
public static enum RolloutStatus {
|
||||
public enum RolloutStatus {
|
||||
|
||||
/**
|
||||
* Rollouts is beeing created.
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
@@ -30,16 +31,18 @@ import javax.persistence.Table;
|
||||
@IdClass(RolloutTargetGroupId.class)
|
||||
@Entity
|
||||
@Table(name = "sp_rollouttargetgroup")
|
||||
public class RolloutTargetGroup {
|
||||
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"))
|
||||
@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"))
|
||||
@JoinColumn(name = "target_id", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_rollouttargetgroup_target") )
|
||||
private Target target;
|
||||
|
||||
@OneToMany(targetEntity = Action.class, fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST })
|
||||
@@ -60,6 +63,6 @@ public class RolloutTargetGroup {
|
||||
}
|
||||
|
||||
public RolloutTargetGroupId getId() {
|
||||
return new RolloutTargetGroupId(rolloutGroup, target);
|
||||
return new RolloutTargetGroupId(this.rolloutGroup, this.target);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,12 +9,12 @@
|
||||
package org.eclipse.hawkbit.repository.model;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Store all states with the target count of a rollout or rolloutgroup.
|
||||
*
|
||||
*/
|
||||
@@ -27,12 +27,12 @@ public class TotalTargetCountStatus {
|
||||
SCHEDULED, RUNNING, ERROR, FINISHED, CANCELLED, NOTSTARTED
|
||||
}
|
||||
|
||||
private final Map<Status, Long> statusTotalCountMap = new HashMap<>();
|
||||
private final Map<Status, Long> statusTotalCountMap = new EnumMap<>(Status.class);
|
||||
private final Long totalTargetCount;
|
||||
|
||||
/**
|
||||
* Create a new states map with the target count for each state.
|
||||
*
|
||||
*
|
||||
* @param targetCountActionStatus
|
||||
* the action state map
|
||||
* @param totalTargets
|
||||
@@ -46,7 +46,7 @@ public class TotalTargetCountStatus {
|
||||
|
||||
/**
|
||||
* Create a new states map with the target count for each state.
|
||||
*
|
||||
*
|
||||
* @param totalTargetCount
|
||||
* the total target count
|
||||
*/
|
||||
@@ -56,28 +56,28 @@ public class TotalTargetCountStatus {
|
||||
|
||||
/**
|
||||
* The current state mape which the total target count
|
||||
*
|
||||
*
|
||||
* @return the statusTotalCountMap the state map
|
||||
*/
|
||||
public Map<Status, Long> getStatusTotalCountMap() {
|
||||
return statusTotalCountMap;
|
||||
return this.statusTotalCountMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the total target count from a state.
|
||||
*
|
||||
*
|
||||
* @param status
|
||||
* the state key
|
||||
* @return the current target count cannot be <null>
|
||||
*/
|
||||
public Long getTotalTargetCountByStatus(final Status status) {
|
||||
final Long count = statusTotalCountMap.get(status);
|
||||
final Long count = this.statusTotalCountMap.get(status);
|
||||
return count == null ? 0L : count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Populate all target status to a the given map
|
||||
*
|
||||
*
|
||||
* @param statusTotalCountMap
|
||||
* the map
|
||||
* @param rolloutStatusCountItems
|
||||
@@ -87,39 +87,39 @@ public class TotalTargetCountStatus {
|
||||
private final void mapActionStatusToTotalTargetCountStatus(
|
||||
final List<TotalTargetCountActionStatus> targetCountActionStatus) {
|
||||
if (targetCountActionStatus == null) {
|
||||
statusTotalCountMap.put(TotalTargetCountStatus.Status.NOTSTARTED, totalTargetCount);
|
||||
this.statusTotalCountMap.put(TotalTargetCountStatus.Status.NOTSTARTED, this.totalTargetCount);
|
||||
return;
|
||||
}
|
||||
statusTotalCountMap.put(Status.RUNNING, 0L);
|
||||
Long notStartedTargetCount = totalTargetCount;
|
||||
this.statusTotalCountMap.put(Status.RUNNING, 0L);
|
||||
Long notStartedTargetCount = this.totalTargetCount;
|
||||
for (final TotalTargetCountActionStatus item : targetCountActionStatus) {
|
||||
switch (item.getStatus()) {
|
||||
case SCHEDULED:
|
||||
statusTotalCountMap.put(Status.SCHEDULED, item.getCount());
|
||||
this.statusTotalCountMap.put(Status.SCHEDULED, item.getCount());
|
||||
break;
|
||||
case ERROR:
|
||||
statusTotalCountMap.put(Status.ERROR, item.getCount());
|
||||
this.statusTotalCountMap.put(Status.ERROR, item.getCount());
|
||||
break;
|
||||
case FINISHED:
|
||||
statusTotalCountMap.put(Status.FINISHED, item.getCount());
|
||||
this.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);
|
||||
final Long runningItemsCount = this.statusTotalCountMap.get(Status.RUNNING) + item.getCount();
|
||||
this.statusTotalCountMap.put(Status.RUNNING, runningItemsCount);
|
||||
break;
|
||||
case CANCELED:
|
||||
statusTotalCountMap.put(Status.CANCELLED, item.getCount());
|
||||
this.statusTotalCountMap.put(Status.CANCELLED, item.getCount());
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("State " + item.getStatus() + "is not valid");
|
||||
}
|
||||
notStartedTargetCount -= item.getCount();
|
||||
}
|
||||
statusTotalCountMap.put(TotalTargetCountStatus.Status.NOTSTARTED, notStartedTargetCount);
|
||||
this.statusTotalCountMap.put(TotalTargetCountStatus.Status.NOTSTARTED, notStartedTargetCount);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,7 +16,19 @@ import org.eclipse.hawkbit.repository.model.RolloutGroup;
|
||||
*/
|
||||
public interface RolloutGroupConditionEvaluator {
|
||||
|
||||
boolean verifyExpression(final String expression);
|
||||
default boolean verifyExpression(final String expression) {
|
||||
// percentage value between 0 and 100
|
||||
try {
|
||||
final Integer value = Integer.valueOf(expression);
|
||||
if (value >= 0 || value <= 100) {
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
} catch (final NumberFormatException e) {
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
boolean eval(Rollout rollout, RolloutGroup rolloutGroup, final String expression);
|
||||
}
|
||||
|
||||
@@ -18,35 +18,20 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
@Component("thresholdRolloutGroupErrorCondition")
|
||||
public class ThresholdRolloutGroupErrorCondition implements RolloutGroupConditionEvaluator {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(ThresholdRolloutGroupErrorCondition.class);
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ThresholdRolloutGroupErrorCondition.class);
|
||||
|
||||
@Autowired
|
||||
private ActionRepository actionRepository;
|
||||
|
||||
@Override
|
||||
public boolean verifyExpression(final String expression) {
|
||||
// percentage value between 0 and 100
|
||||
try {
|
||||
final Integer value = Integer.valueOf(expression);
|
||||
if (value >= 0 || value <= 100) {
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
} catch (final RuntimeException e) {
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean eval(final Rollout rollout, final RolloutGroup rolloutGroup, final String expression) {
|
||||
final Long totalGroup = actionRepository.countByRolloutAndRolloutGroup(rollout, rolloutGroup);
|
||||
final Long error = actionRepository.countByRolloutIdAndRolloutGroupIdAndStatus(rollout.getId(),
|
||||
final Long totalGroup = this.actionRepository.countByRolloutAndRolloutGroup(rollout, rolloutGroup);
|
||||
final Long error = this.actionRepository.countByRolloutIdAndRolloutGroupIdAndStatus(rollout.getId(),
|
||||
rolloutGroup.getId(), Action.Status.ERROR);
|
||||
try {
|
||||
final Integer threshold = Integer.valueOf(expression);
|
||||
@@ -60,7 +45,7 @@ public class ThresholdRolloutGroupErrorCondition implements RolloutGroupConditio
|
||||
// calculate threshold
|
||||
return ((float) error / (float) totalGroup) > ((float) threshold / 100F);
|
||||
} catch (final NumberFormatException e) {
|
||||
logger.error("Cannot evaluate condition expression " + expression, e);
|
||||
LOGGER.error("Cannot evaluate condition expression " + expression, e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,47 +12,41 @@ import org.eclipse.hawkbit.repository.ActionRepository;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Rollout;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroup;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
@Component("thresholdRolloutGroupSuccessCondition")
|
||||
public class ThresholdRolloutGroupSuccessCondition implements RolloutGroupConditionEvaluator {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ThresholdRolloutGroupSuccessCondition.class);
|
||||
|
||||
@Autowired
|
||||
private ActionRepository actionRepository;
|
||||
|
||||
@Override
|
||||
public boolean verifyExpression(final String expression) {
|
||||
// percentage value between 0 and 100
|
||||
try {
|
||||
final Integer value = Integer.valueOf(expression);
|
||||
if (value >= 0 || value <= 100) {
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
} catch (final RuntimeException e) {
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean eval(final Rollout rollout, final RolloutGroup rolloutGroup, final String expression) {
|
||||
final Long totalGroup = rolloutGroup.getTotalTargets();
|
||||
final Long finished = actionRepository.countByRolloutIdAndRolloutGroupIdAndStatus(rollout.getId(),
|
||||
final Long finished = this.actionRepository.countByRolloutIdAndRolloutGroupIdAndStatus(rollout.getId(),
|
||||
rolloutGroup.getId(), Action.Status.FINISHED);
|
||||
final Integer threshold = Integer.valueOf(expression);
|
||||
try {
|
||||
final Integer threshold = Integer.valueOf(expression);
|
||||
|
||||
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 true;
|
||||
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 true;
|
||||
}
|
||||
// calculate threshold
|
||||
return ((float) finished / (float) totalGroup) >= ((float) threshold / 100F);
|
||||
} catch (final NumberFormatException e) {
|
||||
LOGGER.error("Cannot evaluate condition expression " + expression, e);
|
||||
return false;
|
||||
}
|
||||
// calculate threshold
|
||||
return ((float) finished / (float) totalGroup) >= ((float) threshold / 100F);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user