import java.io.File;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
+import java.nio.file.Files;
import java.util.ArrayList;
-import java.util.HashSet;
import java.util.List;
-import java.util.Set;
import org.onap.portalsdk.core.onboarding.exception.PortalAPIException;
-import org.onap.portalsdk.core.restful.domain.EcompRole;
import org.onap.portalsdk.core.restful.domain.EcompUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
/**
*
* This first implementation serializes user details to a file.
*
- * TODO: migrate to a database.
+ * Migrate to a database someday?
*/
public class DashboardUserManager {
logger.debug("ctor: removing file {}", userFile.getAbsolutePath());
File f = new File(DashboardUserManager.USER_FILE_PATH);
if (f.exists())
- f.delete();
+ Files.delete(f.toPath());
users.clear();
}
}
return null;
}
- private void saveUsers() throws JsonGenerationException, JsonMappingException, IOException {
+ private void saveUsers() throws IOException {
final ObjectMapper mapper = new ObjectMapper();
mapper.writeValue(userFile, users);
}
* Allow at most one thread to create a user at one time.
*/
public synchronized void createUser(EcompUser user) throws PortalAPIException {
- logger.debug("createUser: loginId is " + user.getLoginId());
+ logger.debug("createUser: loginId {}", user.getLoginId());
if (users.contains(user))
throw new PortalAPIException("User exists: " + user.getLoginId());
users.add(user);
* last-edit-wins of course.
*/
public synchronized void updateUser(String loginId, EcompUser user) throws PortalAPIException {
- logger.debug("editUser: loginId is " + loginId);
+ logger.debug("editUser: loginId {}", loginId);
int index = users.indexOf(user);
if (index < 0)
throw new PortalAPIException("User does not exist: " + user.getLoginId());
}
}
- // Test infrastructure
- public static void main(String[] args) throws Exception {
- DashboardUserManager dum = new DashboardUserManager(false);
- EcompUser user = new EcompUser();
- user.setActive(true);
- user.setLoginId("demo");
- user.setFirstName("First");
- user.setLastName("Last");
- EcompRole role = new EcompRole();
- role.setId(1L);
- role.setName(DashboardConstants.ROLE_NAME_ADMIN);
- Set<EcompRole> roles = new HashSet<>();
- roles.add(role);
- user.setRoles(roles);
- dum.createUser(user);
- logger.debug("Created user {}", user);
- }
-
}