2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.asdctool.impl.migration.v1707.jsonmodel;
23 import fj.data.Either;
24 import org.openecomp.sdc.be.dao.api.ActionStatus;
25 import org.openecomp.sdc.be.dao.utils.UserStatusEnum;
26 import org.openecomp.sdc.be.model.User;
27 import org.openecomp.sdc.be.model.operations.api.IUserAdminOperation;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
31 import javax.annotation.Resource;
32 import java.util.List;
34 import static org.openecomp.sdc.asdctool.impl.migration.v1707.MigrationUtils.handleError;
36 public class UsersMigration extends JsonModelMigration<User> {
38 private static Logger LOGGER = LoggerFactory.getLogger(UsersMigration.class);
40 @Resource(name = "user-operation")
41 IUserAdminOperation userAdminOperation;
43 @Resource(name = "user-operation-migration")
44 IUserAdminOperation userAdminOperationMigration;
48 Either<List<User>, ActionStatus> getElementsToMigrate() {
49 LOGGER.debug("fetching users to migrate from old graph");
50 return userAdminOperation.getAllUsers();
54 Either<User, ActionStatus> getElementFromNewGraph(User user) {
55 LOGGER.debug(String.format("trying to load user %s from new graph", user.getUserId()));
56 return user.getStatus().equals(UserStatusEnum.ACTIVE) ? userAdminOperationMigration.getUserData(user.getUserId(), false) :
57 userAdminOperationMigration.getInactiveUserData(user.getUserId());
61 boolean save(User user) {
62 LOGGER.debug(String.format("trying to save user %s to new graph", user.getUserId()));
63 return userAdminOperationMigration.saveUserData(user)
64 .either(savedUser -> true,
65 err -> handleError(String.format("failed when saving user %s. error %s", user.getUserId(), err.name())));
69 public ActionStatus getNotFoundErrorStatus() {
70 return ActionStatus.USER_NOT_FOUND;
74 public String description() {
75 return "migrate users";