Search in sources :

Example 1 with UserVO

use of com.centurylink.mdw.model.value.user.UserVO in project mdw-designer by CenturyLinkCloud.

the class Importer method main.

public static void main(String[] args) {
    if (args.length == 1 && "-h".equals(args[0])) {
        System.out.println("Example Usage: ");
        System.out.println("java com.centurylink.mdw.designer.Importer appcuid apppassword " + "jdbc:oracle:thin:mdwdemo/mdwdemo@mdwdevdb.dev.qintra.com:1594:mdwdev (or /path/to/root/storage) " + "http://lxdenvmtc143.dev.qintra.com:7021/maven/repository/mdw/com/centurylink/mdw/assets/camel/5.5.11/com.centurylink.mdw.camel-5.5.11.xml " + "overwrite=true");
        System.exit(0);
    }
    if (args.length != 4 && args.length != 5) {
        System.err.println("arguments: <user> <password> <jdbcUrl|fileBasedRootDir> <xmlFile|xmlFileUrl> <overwrite=(true|FALSE)>");
        System.err.println("(-h for example usage)");
        System.exit(-1);
    }
    String user = args[0];
    String password = args[1];
    // either jdbcUrl or local file path
    String arg2 = args[2];
    String xmlFile = args[3];
    boolean overwrite = (args.length == 5 && "overwrite=true".equalsIgnoreCase(args[4])) ? true : false;
    try {
        DesignerDataAccess.getAuthenticator().authenticate(user, password);
        boolean local = !arg2.startsWith("jdbc:");
        RestfulServer restfulServer = new RestfulServer(local ? "jdbc://dummy" : arg2, user, "http://dummy");
        DesignerDataAccess dataAccess;
        if (local) {
            VersionControl versionControl = new VersionControlGit();
            versionControl.connect(null, null, null, new File(arg2));
            restfulServer.setVersionControl(versionControl);
            restfulServer.setRootDirectory(new File(arg2));
            dataAccess = new DesignerDataAccess(restfulServer, null, user, false);
        } else {
            dataAccess = new DesignerDataAccess(restfulServer, null, user, true);
            UserVO userVO = dataAccess.getUser(user);
            if (userVO == null)
                throw new DataAccessException("User: '" + user + "' not found.");
            if (!userVO.hasRole(UserGroupVO.COMMON_GROUP, UserRoleVO.PROCESS_DESIGN))
                throw new DataAccessException("User: '" + user + "' not authorized for " + UserRoleVO.PROCESS_DESIGN + ".");
        }
        String xml;
        if ("http://".startsWith(xmlFile) || "https://".startsWith(xmlFile)) {
            xml = new HttpHelper(new URL(xmlFile)).get();
        } else {
            xml = readFile(xmlFile);
        }
        System.out.println("Importing with arguments: " + user + " ******* " + arg2 + " " + xmlFile);
        Importer importer = new Importer(dataAccess);
        long before = System.currentTimeMillis();
        importer.importPackage(xml, overwrite);
        long afterImport = System.currentTimeMillis();
        System.out.println("Time taken for import: " + ((afterImport - before) / 1000) + " s");
        System.out.println("Please restart your server or refresh the MDW asset cache.");
    } catch (Exception ex) {
        ex.printStackTrace();
        System.exit(-1);
    }
}
Also used : VersionControlGit(com.centurylink.mdw.dataaccess.file.VersionControlGit) RestfulServer(com.centurylink.mdw.designer.utils.RestfulServer) VersionControl(com.centurylink.mdw.dataaccess.VersionControl) URL(java.net.URL) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) XmlException(org.apache.xmlbeans.XmlException) ActionCancelledException(com.centurylink.mdw.common.utilities.timer.ActionCancelledException) UserVO(com.centurylink.mdw.model.value.user.UserVO) File(java.io.File) HttpHelper(com.centurylink.mdw.common.utilities.HttpHelper) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException) ProcessImporter(com.centurylink.mdw.dataaccess.ProcessImporter)

Example 2 with UserVO

use of com.centurylink.mdw.model.value.user.UserVO in project mdw-designer by CenturyLinkCloud.

the class UserDataAccessRest method getUser.

public UserVO getUser(String cuid) throws DataAccessException {
    try {
        String pathWithArgs = "Users/" + cuid;
        if (!getServer().isSchemaVersion61())
            pathWithArgs = "User?format=json&cuid=" + cuid + "&withRoles=true";
        String response = invokeResourceService(pathWithArgs);
        JSONObject jsonObj = new JSONObject(response);
        if (jsonObj.has("status"))
            // user not found -- no privileges
            return new UserVO(cuid);
        else
            return new UserVO(jsonObj);
    } catch (FileNotFoundException ex) {
        return null;
    } catch (IOException ex) {
        throw new DataAccessOfflineException(ex.getMessage(), ex);
    } catch (Exception ex) {
        throw new DataAccessException(ex.getMessage(), ex);
    }
}
Also used : DataAccessOfflineException(com.centurylink.mdw.dataaccess.DataAccessOfflineException) JSONObject(org.json.JSONObject) UserVO(com.centurylink.mdw.model.value.user.UserVO) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) DataAccessOfflineException(com.centurylink.mdw.dataaccess.DataAccessOfflineException) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException)

Example 3 with UserVO

use of com.centurylink.mdw.model.value.user.UserVO in project mdw-designer by CenturyLinkCloud.

the class DesignerDataModel method reloadPriviledges.

public void reloadPriviledges(DesignerDataAccess dao, String cuid) throws DataAccessException, RemoteException {
    if (dao.noDatabase()) {
        user = new UserVO();
        user.setCuid(cuid);
        user.setName(cuid);
        user.addRoleForGroup(UserGroupVO.COMMON_GROUP, UserRoleVO.PROCESS_DESIGN);
        user.addRoleForGroup(UserGroupVO.SITE_ADMIN_GROUP, UserRoleVO.PROCESS_DESIGN);
    } else {
        user = dao.getUser(cuid);
        if (user == null) {
            if (allowAnyUserToRead) {
                user = new UserVO();
                user.setCuid(cuid);
                user.setName(cuid);
                if (UserGroupVO.DEFAULT_ALL_ROLES)
                    user.addRoleForGroup(UserGroupVO.COMMON_GROUP, UserRoleVO.VIEW_ONLY);
            } else {
                throw new DataAccessException("You are not authorized to access this site");
            }
        }
    }
}
Also used : UserVO(com.centurylink.mdw.model.value.user.UserVO) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException)

Aggregations

DataAccessException (com.centurylink.mdw.common.exception.DataAccessException)3 UserVO (com.centurylink.mdw.model.value.user.UserVO)3 IOException (java.io.IOException)2 HttpHelper (com.centurylink.mdw.common.utilities.HttpHelper)1 ActionCancelledException (com.centurylink.mdw.common.utilities.timer.ActionCancelledException)1 DataAccessOfflineException (com.centurylink.mdw.dataaccess.DataAccessOfflineException)1 ProcessImporter (com.centurylink.mdw.dataaccess.ProcessImporter)1 VersionControl (com.centurylink.mdw.dataaccess.VersionControl)1 VersionControlGit (com.centurylink.mdw.dataaccess.file.VersionControlGit)1 RestfulServer (com.centurylink.mdw.designer.utils.RestfulServer)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 URL (java.net.URL)1 RemoteException (java.rmi.RemoteException)1 XmlException (org.apache.xmlbeans.XmlException)1 JSONObject (org.json.JSONObject)1