Search in sources :

Example 1 with ExportedProjectPermission

use of de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedProjectPermission in project webanno by webanno.

the class PermissionsExporter method importData.

/**
 * Create {@link ProjectPermission} from the exported {@link ExportedProjectPermission}
 *
 * @param aExProject
 *            the imported project.
 * @param aProject
 *            the project.
 * @throws IOException
 *             if an I/O error occurs.
 */
@Override
public void importData(ProjectImportRequest aRequest, Project aProject, ExportedProject aExProject, ZipFile aZip) throws Exception {
    // permissions for other users unless permission import was requested.
    for (ExportedProjectPermission importedPermission : aExProject.getProjectPermissions()) {
        boolean isPermissionOfImportingUser = aRequest.getManager().map(User::getUsername).map(importedPermission.getUser()::equals).orElse(false);
        if (isPermissionOfImportingUser || aRequest.isImportPermissions()) {
            ProjectPermission permission = new ProjectPermission();
            permission.setLevel(importedPermission.getLevel());
            permission.setProject(aProject);
            permission.setUser(importedPermission.getUser());
            projectService.createProjectPermission(permission);
        }
    }
    // Give all permissions to the importing user if requested
    if (aRequest.getManager().isPresent()) {
        User user = aRequest.getManager().get();
        String username = user.getUsername();
        if (!projectService.isManager(aProject, user)) {
            projectService.createProjectPermission(new ProjectPermission(aProject, username, MANAGER));
        }
        if (!projectService.isCurator(aProject, user)) {
            projectService.createProjectPermission(new ProjectPermission(aProject, username, CURATOR));
        }
        if (!projectService.isAnnotator(aProject, user)) {
            projectService.createProjectPermission(new ProjectPermission(aProject, username, ANNOTATOR));
        }
    }
    // Users are added without passwords and disabled.
    if (aRequest.isCreateMissingUsers()) {
        Set<String> users = new HashSet<>();
        for (ExportedProjectPermission importedPermission : aExProject.getProjectPermissions()) {
            users.add(importedPermission.getUser());
        }
        for (String user : users) {
            if (!userService.exists(user)) {
                User u = new User();
                u.setUsername(user);
                u.setEnabled(false);
                userService.create(u);
            }
        }
    }
}
Also used : ExportedProjectPermission(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedProjectPermission) User(de.tudarmstadt.ukp.clarin.webanno.security.model.User) ProjectPermission(de.tudarmstadt.ukp.clarin.webanno.model.ProjectPermission) ExportedProjectPermission(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedProjectPermission) HashSet(java.util.HashSet)

Example 2 with ExportedProjectPermission

use of de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedProjectPermission in project webanno by webanno.

the class PermissionsExporter method exportData.

@Override
public void exportData(ProjectExportRequest aRequest, ProjectExportTaskMonitor aMonitor, ExportedProject aExProject, File aStage) throws Exception {
    Project project = aRequest.getProject();
    // add project permissions to the project
    List<ExportedProjectPermission> projectPermissions = new ArrayList<>();
    for (User user : projectService.listProjectUsersWithPermissions(project)) {
        for (ProjectPermission permission : projectService.listProjectPermissionLevel(user, project)) {
            ExportedProjectPermission permissionToExport = new ExportedProjectPermission();
            permissionToExport.setLevel(permission.getLevel());
            permissionToExport.setUser(user.getUsername());
            projectPermissions.add(permissionToExport);
        }
    }
    aExProject.setProjectPermissions(projectPermissions);
    LOG.info("Exported [{}] permissions for project [{}]", projectPermissions.size(), aRequest.getProject().getName());
}
Also used : ExportedProjectPermission(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedProjectPermission) Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) ExportedProject(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedProject) User(de.tudarmstadt.ukp.clarin.webanno.security.model.User) ProjectPermission(de.tudarmstadt.ukp.clarin.webanno.model.ProjectPermission) ExportedProjectPermission(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedProjectPermission) ArrayList(java.util.ArrayList)

Aggregations

ExportedProjectPermission (de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedProjectPermission)2 ProjectPermission (de.tudarmstadt.ukp.clarin.webanno.model.ProjectPermission)2 User (de.tudarmstadt.ukp.clarin.webanno.security.model.User)2 ExportedProject (de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedProject)1 Project (de.tudarmstadt.ukp.clarin.webanno.model.Project)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1