X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=webapp-backend%2Fsrc%2Fmain%2Fjava%2Forg%2Foransc%2Fric%2Fportal%2Fdashboard%2Fportalapi%2FDashboardUserManager.java;h=1fb2b1f90b9e6adb86bc884cfdbb5802de906c37;hb=a1a3e0d2f8732570ad9688a842a86f513b40005b;hp=b02d026141a9cb6a639e80facd702200759a0bb8;hpb=3f812ea25d352ec33d07f5ffa4c2aa2a77e8e793;p=portal%2Fric-dashboard.git diff --git a/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/portalapi/DashboardUserManager.java b/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/portalapi/DashboardUserManager.java index b02d0261..1fb2b1f9 100644 --- a/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/portalapi/DashboardUserManager.java +++ b/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/portalapi/DashboardUserManager.java @@ -2,7 +2,7 @@ * ========================LICENSE_START================================= * O-RAN-SC * %% - * Copyright (C) 2019 AT&T Intellectual Property and Nokia + * Copyright (C) 2019 AT&T Intellectual Property * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,10 +23,14 @@ import java.io.File; import java.io.IOException; import java.lang.invoke.MethodHandles; 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.oransc.ric.portal.dashboard.DashboardConstants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -38,16 +42,47 @@ import com.fasterxml.jackson.databind.ObjectMapper; /** * Provides user-management services. * - * This first implementation serializes user details to a file. TODO: migrate to - * a database. + * This first implementation serializes user details to a file. + * + * TODO: migrate to a database. */ public class DashboardUserManager { private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + public static final String USER_FILE_PATH = "/tmp/dashboard-users.json"; + private final File userFile; private final List users; + /** + * convenience constructor that uses default file path + * + * @param clear + * If true, start empty and remove any existing file. + * + * @throws IOException + * On file error + */ + public DashboardUserManager(boolean clear) throws IOException { + this(USER_FILE_PATH); + if (clear) { + logger.debug("ctor: removing file {}", userFile.getAbsolutePath()); + File f = new File(DashboardUserManager.USER_FILE_PATH); + if (f.exists()) + f.delete(); + users.clear(); + } + } + + /** + * Uses specified file path + * + * @param userFilePath + * File path + * @throws IOException + * If file cannot be read + */ public DashboardUserManager(final String userFilePath) throws IOException { logger.debug("ctor: userfile {}", userFilePath); if (userFilePath == null) @@ -119,4 +154,22 @@ public class DashboardUserManager { } } + // 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 roles = new HashSet<>(); + roles.add(role); + user.setRoles(roles); + dum.createUser(user); + logger.debug("Created user {}", user); + } + }