diff --git a/devicehive-common-service/src/main/java/com/devicehive/service/BaseUserService.java b/devicehive-common-service/src/main/java/com/devicehive/service/BaseUserService.java index d6e0e9e4a..d5562d56d 100644 --- a/devicehive-common-service/src/main/java/com/devicehive/service/BaseUserService.java +++ b/devicehive-common-service/src/main/java/com/devicehive/service/BaseUserService.java @@ -180,6 +180,10 @@ public UserVO createUser(@NotNull UserVO user, String password) { if (user.getAllDeviceTypesAvailable() == null) { user.setAllDeviceTypesAvailable(true); } + + if (user.getAgreedToPersonalDataCollection() == null) { + user.setAgreedToPersonalDataCollection(false); + } userDao.persist(user); return user; } diff --git a/devicehive-common/src/main/java/com/devicehive/model/updates/UserUpdate.java b/devicehive-common/src/main/java/com/devicehive/model/updates/UserUpdate.java index f8571387e..707763993 100644 --- a/devicehive-common/src/main/java/com/devicehive/model/updates/UserUpdate.java +++ b/devicehive-common/src/main/java/com/devicehive/model/updates/UserUpdate.java @@ -60,6 +60,8 @@ public class UserUpdate implements HiveEntity { @ApiModelProperty(hidden = true) private Boolean allDeviceTypesAvailable; + private Boolean agreedToPersonalDataCollection; + public Optional getLogin() { return Optional.ofNullable(login); } @@ -116,6 +118,14 @@ public void setAllDeviceTypesAvailable(Boolean allDeviceTypesAvailable) { this.allDeviceTypesAvailable = allDeviceTypesAvailable; } + public Optional getAgreedToPersonalDataCollection() { + return Optional.ofNullable(agreedToPersonalDataCollection); + } + + public void setAgreedToPersonalDataCollection(Boolean agreedToPersonalDataCollection) { + this.agreedToPersonalDataCollection = agreedToPersonalDataCollection; + } + @ApiModelProperty(hidden = true) public UserRole getRoleEnum() { return getRole().map(UserRole::getValueForIndex).orElse(null); @@ -140,6 +150,9 @@ public UserVO convertTo() { if (allDeviceTypesAvailable != null) { result.setAllDeviceTypesAvailable(allDeviceTypesAvailable); } + if (agreedToPersonalDataCollection != null) { + result.setAgreedToPersonalDataCollection(agreedToPersonalDataCollection); + } result.setStatus(getStatusEnum()); result.setRole(getRoleEnum()); return result; diff --git a/devicehive-common/src/main/java/com/devicehive/vo/UserVO.java b/devicehive-common/src/main/java/com/devicehive/vo/UserVO.java index 9b3a751f1..b9d8d92f4 100644 --- a/devicehive-common/src/main/java/com/devicehive/vo/UserVO.java +++ b/devicehive-common/src/main/java/com/devicehive/vo/UserVO.java @@ -84,6 +84,10 @@ public class UserVO implements HiveEntity { @JsonPolicyDef({USER_PUBLISHED, USERS_LISTED, USER_SUBMITTED}) private Boolean allDeviceTypesAvailable; + @SerializedName("agreedToPersonalDataCollection") + @JsonPolicyDef({USER_PUBLISHED, USERS_LISTED, USER_SUBMITTED}) + private Boolean agreedToPersonalDataCollection; + /** * @return true, if user is admin */ @@ -180,6 +184,14 @@ public void setAllDeviceTypesAvailable(Boolean allDeviceTypesAvailable) { this.allDeviceTypesAvailable = allDeviceTypesAvailable; } + public Boolean getAgreedToPersonalDataCollection() { + return agreedToPersonalDataCollection; + } + + public void setAgreedToPersonalDataCollection(Boolean agreedToPersonalDataCollection) { + this.agreedToPersonalDataCollection = agreedToPersonalDataCollection; + } + @Override public boolean equals(Object o) { diff --git a/devicehive-common/src/main/java/com/devicehive/vo/UserWithDeviceTypeVO.java b/devicehive-common/src/main/java/com/devicehive/vo/UserWithDeviceTypeVO.java index 49d76d051..14e6abda5 100644 --- a/devicehive-common/src/main/java/com/devicehive/vo/UserWithDeviceTypeVO.java +++ b/devicehive-common/src/main/java/com/devicehive/vo/UserWithDeviceTypeVO.java @@ -57,6 +57,7 @@ public static UserWithDeviceTypeVO fromUserVO(UserVO dc) { vo.setStatus(dc.getStatus()); vo.setIntroReviewed(dc.getIntroReviewed()); vo.setAllDeviceTypesAvailable(dc.getAllDeviceTypesAvailable()); + vo.setAgreedToPersonalDataCollection(dc.getAgreedToPersonalDataCollection()); } return vo; diff --git a/devicehive-common/src/main/java/com/devicehive/vo/UserWithNetworkVO.java b/devicehive-common/src/main/java/com/devicehive/vo/UserWithNetworkVO.java index 655e35514..6022ce44d 100644 --- a/devicehive-common/src/main/java/com/devicehive/vo/UserWithNetworkVO.java +++ b/devicehive-common/src/main/java/com/devicehive/vo/UserWithNetworkVO.java @@ -58,6 +58,7 @@ public static UserWithNetworkVO fromUserVO(UserVO dc) { vo.setStatus(dc.getStatus()); vo.setIntroReviewed(dc.getIntroReviewed()); vo.setAllDeviceTypesAvailable(dc.getAllDeviceTypesAvailable()); + vo.setAgreedToPersonalDataCollection(dc.getAgreedToPersonalDataCollection()); } return vo; diff --git a/devicehive-frontend/src/main/java/com/devicehive/service/UserService.java b/devicehive-frontend/src/main/java/com/devicehive/service/UserService.java index 57e7b1e02..542777c4f 100644 --- a/devicehive-frontend/src/main/java/com/devicehive/service/UserService.java +++ b/devicehive-frontend/src/main/java/com/devicehive/service/UserService.java @@ -168,6 +168,10 @@ public UserVO updateUser(@NotNull Long id, UserUpdate userToUpdate, UserVO curUs existing.setIntroReviewed(userToUpdate.getIntroReviewed().get()); } + if (userToUpdate.getAgreedToPersonalDataCollection().isPresent()) { + existing.setAgreedToPersonalDataCollection(userToUpdate.getAgreedToPersonalDataCollection().get()); + } + hiveValidator.validate(existing); return userDao.merge(existing); } diff --git a/devicehive-rdbms-dao/src/main/java/com/devicehive/model/User.java b/devicehive-rdbms-dao/src/main/java/com/devicehive/model/User.java index 6715793c9..c7657b6d1 100644 --- a/devicehive-rdbms-dao/src/main/java/com/devicehive/model/User.java +++ b/devicehive-rdbms-dao/src/main/java/com/devicehive/model/User.java @@ -127,6 +127,11 @@ public class User implements HiveEntity { @JsonPolicyDef({USER_PUBLISHED, USERS_LISTED, USER_SUBMITTED}) private Boolean allDeviceTypesAvailable; + @Column(name = "agreed_to_personal_data_collection") + @SerializedName("agreedToPersonalDataCollection") + @JsonPolicyDef({USER_PUBLISHED, USERS_LISTED, USER_SUBMITTED}) + private Boolean agreedToPersonalDataCollection; + /** * @return true, if user is admin */ @@ -238,6 +243,14 @@ public void setAllDeviceTypesAvailable(Boolean allDeviceTypesAvailable) { this.allDeviceTypesAvailable = allDeviceTypesAvailable; } + public Boolean getAgreedToPersonalDataCollection() { + return agreedToPersonalDataCollection; + } + + public void setAgreedToPersonalDataCollection(Boolean agreedToPersonalDataCollection) { + this.agreedToPersonalDataCollection = agreedToPersonalDataCollection; + } + @Override public boolean equals(Object o) { @@ -276,6 +289,7 @@ public static UserVO convertToVo(User dc) { vo.setStatus(dc.getStatus()); vo.setIntroReviewed(dc.getIntroReviewed()); vo.setAllDeviceTypesAvailable(dc.getAllDeviceTypesAvailable()); + vo.setAgreedToPersonalDataCollection(dc.getAgreedToPersonalDataCollection()); } return vo; } @@ -296,6 +310,7 @@ public static User convertToEntity(UserVO dc) { vo.setStatus(dc.getStatus()); vo.setIntroReviewed(dc.getIntroReviewed()); vo.setAllDeviceTypesAvailable(dc.getAllDeviceTypesAvailable()); + vo.setAgreedToPersonalDataCollection(dc.getAgreedToPersonalDataCollection()); } return vo; } @@ -315,6 +330,7 @@ public static User convertToEntity(UserWithDeviceTypeVO dc) { vo.setStatus(dc.getStatus()); vo.setIntroReviewed(dc.getIntroReviewed()); vo.setAllDeviceTypesAvailable(dc.getAllDeviceTypesAvailable()); + vo.setAgreedToPersonalDataCollection(dc.getAgreedToPersonalDataCollection()); vo.setDeviceTypes(new HashSet<>()); diff --git a/devicehive-rdbms-dao/src/main/resources/db/migration/V3_4_12__add_agreed_to_personal_data_collection_column.sql b/devicehive-rdbms-dao/src/main/resources/db/migration/V3_4_12__add_agreed_to_personal_data_collection_column.sql new file mode 100644 index 000000000..915a03625 --- /dev/null +++ b/devicehive-rdbms-dao/src/main/resources/db/migration/V3_4_12__add_agreed_to_personal_data_collection_column.sql @@ -0,0 +1,25 @@ +--- +-- #%L +-- DeviceHive Dao RDBMS Implementation +-- %% +-- Copyright (C) 2016 DataArt +-- %% +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- #L% +--- + +-- Add agreedToPersonalDataCollection column to users +ALTER TABLE dh_user ADD COLUMN agreed_to_personal_data_collection BOOLEAN DEFAULT FALSE; + +-- Set agreedToPersonalDataCollection to false if it is null +UPDATE dh_user SET agreed_to_personal_data_collection = FALSE WHERE agreed_to_personal_data_collection IS NULL; \ No newline at end of file