Make entities immutable and create proper update methods that state by signature what can be updated. (#342)

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
Kai Zimmermann
2016-11-17 20:07:23 +01:00
committed by GitHub
parent b6834e9ee2
commit ca63106d5c
314 changed files with 7699 additions and 6914 deletions

View File

@@ -11,7 +11,6 @@ package org.eclipse.hawkbit.repository;
import java.time.Duration;
import java.time.Instant;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.repository.model.helper.TenantConfigurationManagementHolder;
import org.eclipse.hawkbit.tenancy.configuration.DurationHelper;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;

View File

@@ -0,0 +1,68 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.repository.builder;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Optional;
import org.eclipse.hawkbit.repository.model.Action.Status;
/**
* Create and update builder DTO.
*
* @param <T>
* update or create builder interface
*/
public abstract class AbstractActionStatusCreate<T> {
protected Status status;
protected Long occurredAt;
protected Collection<String> messages;
protected Long actionId;
public Long getActionId() {
return actionId;
}
public T status(final Status status) {
this.status = status;
return (T) this;
}
public T occurredAt(final Long occurredAt) {
this.occurredAt = occurredAt;
return (T) this;
}
public T messages(final Collection<String> messages) {
if (this.messages == null) {
this.messages = messages;
} else {
this.messages.addAll(messages);
}
return (T) this;
}
public T message(final String message) {
if (this.messages == null) {
this.messages = new ArrayList<>();
}
this.messages.add(message);
return (T) this;
}
public Optional<Long> getOccurredAt() {
return Optional.ofNullable(occurredAt);
}
}

View File

@@ -0,0 +1,22 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.repository.builder;
import org.springframework.hateoas.Identifiable;
public abstract class AbstractBaseEntityBuilder implements Identifiable<Long> {
protected Long id;
@Override
public Long getId() {
return id;
}
}

View File

@@ -0,0 +1,72 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.repository.builder;
import java.util.Collection;
import java.util.Optional;
import org.springframework.util.CollectionUtils;
/**
* Create and update builder DTO.
*
* @param <T>
* update or create builder interface
*/
public abstract class AbstractDistributionSetTypeUpdateCreate<T> extends AbstractNamedEntityBuilder<T> {
protected String colour;
protected String key;
protected Collection<Long> mandatory;
protected Collection<Long> optional;
public T mandatory(final Collection<Long> mandatory) {
this.mandatory = mandatory;
return (T) this;
}
public T optional(final Collection<Long> optional) {
this.optional = optional;
return (T) this;
}
public Optional<Collection<Long>> getMandatory() {
if (CollectionUtils.isEmpty(mandatory)) {
return Optional.empty();
}
return Optional.ofNullable(mandatory);
}
public Optional<Collection<Long>> getOptional() {
if (CollectionUtils.isEmpty(optional)) {
return Optional.empty();
}
return Optional.ofNullable(optional);
}
public T colour(final String colour) {
this.colour = colour;
return (T) this;
}
public Optional<String> getColour() {
return Optional.ofNullable(colour);
}
public T key(final String key) {
this.key = key;
return (T) this;
}
public Optional<String> getKey() {
return Optional.ofNullable(key);
}
}

View File

@@ -0,0 +1,62 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.repository.builder;
import java.util.Collection;
import java.util.Optional;
/**
* Create and update builder DTO.
*
* @param <T>
* update or create builder interface
*/
public abstract class AbstractDistributionSetUpdateCreate<T> extends AbstractNamedEntityBuilder<T> {
protected String version;
protected Boolean requiredMigrationStep;
protected String type;
protected Collection<Long> modules;
public T modules(final Collection<Long> modules) {
this.modules = modules;
return (T) this;
}
public Collection<Long> getModules() {
return modules;
}
public T type(final String type) {
this.type = type;
return (T) this;
}
public String getType() {
return type;
}
public T requiredMigrationStep(final Boolean requiredMigrationStep) {
this.requiredMigrationStep = requiredMigrationStep;
return (T) this;
}
public Boolean isRequiredMigrationStep() {
return requiredMigrationStep;
}
public T version(final String version) {
this.version = version;
return (T) this;
}
public Optional<String> getVersion() {
return Optional.ofNullable(version);
}
}

View File

@@ -0,0 +1,36 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.repository.builder;
import java.util.Optional;
public abstract class AbstractNamedEntityBuilder<T> extends AbstractBaseEntityBuilder {
protected String name;
protected String description;
public T name(final String name) {
this.name = name;
return (T) this;
}
public T description(final String description) {
this.description = description;
return (T) this;
}
public Optional<String> getName() {
return Optional.ofNullable(name);
}
public Optional<String> getDescription() {
return Optional.ofNullable(description);
}
}

View File

@@ -0,0 +1,39 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.repository.builder;
import org.eclipse.hawkbit.repository.model.RolloutGroupConditions;
/**
* Create builder DTO.
*
* @param <T>
* update or create builder interface
*/
public abstract class AbstractRolloutGroupCreate<T> extends AbstractNamedEntityBuilder<T> {
protected String targetFilterQuery;
protected Float targetPercentage;
protected RolloutGroupConditions conditions;
public T targetFilterQuery(final String targetFilterQuery) {
this.targetFilterQuery = targetFilterQuery;
return (T) this;
}
public T targetPercentage(final Float targetPercentage) {
this.targetPercentage = targetPercentage;
return (T) this;
}
public T conditions(final RolloutGroupConditions conditions) {
this.conditions = conditions;
return (T) this;
}
}

View File

@@ -0,0 +1,45 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.repository.builder;
import org.eclipse.hawkbit.repository.model.Action.ActionType;
/**
* Create and update builder DTO.
*
* @param <T>
* update or create builder interface
*/
public abstract class AbstractRolloutUpdateCreate<T> extends AbstractNamedEntityBuilder<T> {
protected Long set;
protected String targetFilterQuery;
protected ActionType actionType;
protected Long forcedTime;
public T set(final long set) {
this.set = set;
return (T) this;
}
public T targetFilterQuery(final String targetFilterQuery) {
this.targetFilterQuery = targetFilterQuery;
return (T) this;
}
public T actionType(final ActionType actionType) {
this.actionType = actionType;
return (T) this;
}
public T forcedTime(final Long forcedTime) {
this.forcedTime = forcedTime;
return (T) this;
}
}

View File

@@ -0,0 +1,51 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.repository.builder;
import java.util.Optional;
/**
* Create and update builder DTO.
*
* @param <T>
* update or create builder interface
*/
public abstract class AbstractSoftwareModuleTypeUpdateCreate<T> extends AbstractNamedEntityBuilder<T> {
protected String colour;
protected String key;
protected int maxAssignments = 1;
public T maxAssignments(final int maxAssignments) {
this.maxAssignments = maxAssignments;
return (T) this;
}
public int getMaxAssignments() {
return maxAssignments;
}
public T colour(final String colour) {
this.colour = colour;
return (T) this;
}
public Optional<String> getColour() {
return Optional.ofNullable(colour);
}
public T key(final String key) {
this.key = key;
return (T) this;
}
public Optional<String> getKey() {
return Optional.ofNullable(key);
}
}

View File

@@ -0,0 +1,51 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.repository.builder;
import java.util.Optional;
/**
* Create and update builder DTO.
*
* @param <T>
* update or create builder interface
*/
public abstract class AbstractSoftwareModuleUpdateCreate<T> extends AbstractNamedEntityBuilder<T> {
protected String version;
protected String vendor;
protected String type;
public T type(final String type) {
this.type = type;
return (T) this;
}
public Optional<String> getType() {
return Optional.ofNullable(type);
}
public T vendor(final String vendor) {
this.vendor = vendor;
return (T) this;
}
public Optional<String> getVendor() {
return Optional.ofNullable(vendor);
}
public T version(final String version) {
this.version = version;
return (T) this;
}
public Optional<String> getVersion() {
return Optional.ofNullable(version);
}
}

View File

@@ -0,0 +1,31 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.repository.builder;
import java.util.Optional;
/**
* Create and update builder DTO.
*
* @param <T>
* update or create builder interface
*/
public class AbstractTagUpdateCreate<T> extends AbstractNamedEntityBuilder<T> {
protected String colour;
public T colour(final String colour) {
this.colour = colour;
return (T) this;
}
public Optional<String> getColour() {
return Optional.ofNullable(colour);
}
}

View File

@@ -0,0 +1,50 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.repository.builder;
import java.util.Optional;
/**
* Create and update builder DTO.
*
* @param <T>
* update or create builder interface
*/
public abstract class AbstractTargetFilterQueryUpdateCreate<T> extends AbstractBaseEntityBuilder {
protected String name;
protected String query;
protected Long set;
public T set(final long set) {
this.set = set;
return (T) this;
}
public Optional<Long> getSet() {
return Optional.ofNullable(set);
}
public T name(final String name) {
this.name = name;
return (T) this;
}
public Optional<String> getName() {
return Optional.ofNullable(name);
}
public T query(final String query) {
this.query = query;
return (T) this;
}
public Optional<String> getQuery() {
return Optional.ofNullable(query);
}
}

View File

@@ -0,0 +1,88 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.repository.builder;
import java.net.URI;
import java.util.Optional;
import org.eclipse.hawkbit.repository.exception.InvalidTargetAddressException;
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
/**
* Create and update builder DTO.
*
* @param <T>
* update or create builder interface
*/
public class AbstractTargetUpdateCreate<T> extends AbstractNamedEntityBuilder<T> {
protected String controllerId;
protected String address;
protected String securityToken;
protected Long lastTargetQuery;
protected TargetUpdateStatus status;
protected AbstractTargetUpdateCreate(final String controllerId) {
this.controllerId = controllerId;
}
public T status(final TargetUpdateStatus status) {
this.status = status;
return (T) this;
}
public T address(final String address) {
// check if this is a real URI
if (address != null) {
try {
URI.create(address);
} catch (final IllegalArgumentException e) {
throw new InvalidTargetAddressException(
"The given address " + address + " violates the RFC-2396 specification", e);
}
}
this.address = address;
return (T) this;
}
public T securityToken(final String securityToken) {
this.securityToken = securityToken;
return (T) this;
}
public T lastTargetQuery(final Long lastTargetQuery) {
this.lastTargetQuery = lastTargetQuery;
return (T) this;
}
public TargetCreate controllerId(final String controllerId) {
this.controllerId = controllerId;
return (TargetCreate) this;
}
public String getControllerId() {
return controllerId;
}
public Optional<String> getAddress() {
return Optional.ofNullable(address);
}
public Optional<String> getSecurityToken() {
return Optional.ofNullable(securityToken);
}
public Optional<Long> getLastTargetQuery() {
return Optional.ofNullable(lastTargetQuery);
}
public Optional<TargetUpdateStatus> getStatus() {
return Optional.ofNullable(status);
}
}

View File

@@ -0,0 +1,21 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.repository.builder;
/**
* Update implementation.
*/
public class GenericDistributionSetTypeUpdate extends AbstractDistributionSetTypeUpdateCreate<DistributionSetTypeUpdate>
implements DistributionSetTypeUpdate {
public GenericDistributionSetTypeUpdate(final Long id) {
super.id = id;
}
}

View File

@@ -0,0 +1,21 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.repository.builder;
/**
* Update implementation.
*/
public class GenericDistributionSetUpdate extends AbstractDistributionSetUpdateCreate<DistributionSetUpdate>
implements DistributionSetUpdate {
public GenericDistributionSetUpdate(final Long id) {
super.id = id;
}
}

View File

@@ -0,0 +1,20 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.repository.builder;
/**
* Update implementation.
*/
public class GenericRolloutUpdate extends AbstractRolloutUpdateCreate<RolloutUpdate> implements RolloutUpdate {
public GenericRolloutUpdate(final Long id) {
super.id = id;
}
}

View File

@@ -0,0 +1,21 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.repository.builder;
/**
* Update implementation.
*/
public class GenericSoftwareModuleTypeUpdate extends AbstractSoftwareModuleTypeUpdateCreate<SoftwareModuleTypeUpdate>
implements SoftwareModuleTypeUpdate {
public GenericSoftwareModuleTypeUpdate(final Long id) {
super.id = id;
}
}

View File

@@ -0,0 +1,21 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.repository.builder;
/**
* Update implementation.
*/
public class GenericSoftwareModuleUpdate extends AbstractSoftwareModuleUpdateCreate<SoftwareModuleUpdate>
implements SoftwareModuleUpdate {
public GenericSoftwareModuleUpdate(final Long id) {
super.id = id;
}
}

View File

@@ -0,0 +1,18 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.repository.builder;
/**
* Update implementation.
*/
public class GenericTagUpdate extends AbstractTagUpdateCreate<TagUpdate> implements TagUpdate {
public GenericTagUpdate(final Long id) {
super.id = id;
}
}

View File

@@ -0,0 +1,21 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.repository.builder;
/**
* Update implementation.
*/
public class GenericTargetFilterQueryUpdate extends AbstractTargetFilterQueryUpdateCreate<TargetFilterQueryUpdate>
implements TargetFilterQueryUpdate {
public GenericTargetFilterQueryUpdate(final Long id) {
super.id = id;
}
}

View File

@@ -13,7 +13,6 @@ import java.time.Instant;
import org.apache.commons.lang3.text.StrLookup;
import org.apache.commons.lang3.text.StrSubstitutor;
import org.eclipse.hawkbit.repository.TimestampCalculator;
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
/**
* Adds macro capabilities to RSQL expressions that are used to filter for