Search in sources :

Example 1 with PrivateUrlUser

use of edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser in project dataverse by IQSS.

the class DatasetPage method init.

private String init(boolean initFull) {
    // System.out.println("_YE_OLDE_QUERY_COUNTER_");  // for debug purposes
    this.maxFileUploadSizeInBytes = systemConfig.getMaxFileUploadSize();
    setDataverseSiteUrl(systemConfig.getDataverseSiteUrl());
    guestbookResponse = new GuestbookResponse();
    String nonNullDefaultIfKeyNotFound = "";
    protocol = settingsWrapper.getValueForKey(SettingsServiceBean.Key.Protocol, nonNullDefaultIfKeyNotFound);
    authority = settingsWrapper.getValueForKey(SettingsServiceBean.Key.Authority, nonNullDefaultIfKeyNotFound);
    separator = settingsWrapper.getValueForKey(SettingsServiceBean.Key.DoiSeparator, nonNullDefaultIfKeyNotFound);
    if (dataset.getId() != null || versionId != null || persistentId != null) {
        // view mode for a dataset
        DatasetVersionServiceBean.RetrieveDatasetVersionResponse retrieveDatasetVersionResponse = null;
        // ---------------------------------------
        if (persistentId != null) {
            logger.fine("initializing DatasetPage with persistent ID " + persistentId);
            // Set Working Version and Dataset by PersistentID
            dataset = datasetService.findByGlobalId(persistentId);
            if (dataset == null) {
                logger.warning("No such dataset: " + persistentId);
                return permissionsWrapper.notFound();
            }
            logger.fine("retrieved dataset, id=" + dataset.getId());
            retrieveDatasetVersionResponse = datasetVersionService.selectRequestedVersion(dataset.getVersions(), version);
            // retrieveDatasetVersionResponse = datasetVersionService.retrieveDatasetVersionByPersistentId(persistentId, version);
            this.workingVersion = retrieveDatasetVersionResponse.getDatasetVersion();
            logger.fine("retrieved version: id: " + workingVersion.getId() + ", state: " + this.workingVersion.getVersionState());
        } else if (dataset.getId() != null) {
            // Set Working Version and Dataset by Datasaet Id and Version
            dataset = datasetService.find(dataset.getId());
            if (dataset == null) {
                logger.warning("No such dataset: " + dataset);
                return permissionsWrapper.notFound();
            }
            // retrieveDatasetVersionResponse = datasetVersionService.retrieveDatasetVersionById(dataset.getId(), version);
            retrieveDatasetVersionResponse = datasetVersionService.selectRequestedVersion(dataset.getVersions(), version);
            this.workingVersion = retrieveDatasetVersionResponse.getDatasetVersion();
            logger.info("retreived version: id: " + workingVersion.getId() + ", state: " + this.workingVersion.getVersionState());
        } else if (versionId != null) {
        // TODO: 4.2.1 - this method is broken as of now!
        // Set Working Version and Dataset by DatasaetVersion Id
        // retrieveDatasetVersionResponse = datasetVersionService.retrieveDatasetVersionByVersionId(versionId);
        }
        if (retrieveDatasetVersionResponse == null) {
            return permissionsWrapper.notFound();
        }
        // 
        if (workingVersion == null || this.dataset == null) {
            return permissionsWrapper.notFound();
        }
        // Is the Dataset harvested?
        if (dataset.isHarvested()) {
            // if so, we'll simply forward to the remote URL for the original
            // source of this harvested dataset:
            String originalSourceURL = dataset.getRemoteArchiveURL();
            if (originalSourceURL != null && !originalSourceURL.equals("")) {
                logger.fine("redirecting to " + originalSourceURL);
                try {
                    FacesContext.getCurrentInstance().getExternalContext().redirect(originalSourceURL);
                } catch (IOException ioex) {
                    // must be a bad URL...
                    // we don't need to do anything special here - we'll redirect
                    // to the local 404 page, below.
                    logger.warning("failed to issue a redirect to " + originalSourceURL);
                }
                return originalSourceURL;
            }
            return permissionsWrapper.notFound();
        }
        // Check permisisons
        if (!(workingVersion.isReleased() || workingVersion.isDeaccessioned()) && !this.canViewUnpublishedDataset()) {
            return permissionsWrapper.notAuthorized();
        }
        if (!retrieveDatasetVersionResponse.wasRequestedVersionRetrieved()) {
            // msg("checkit " + retrieveDatasetVersionResponse.getDifferentVersionMessage());
            // JH.localize("dataset.message.metadataSuccess"));
            JsfHelper.addWarningMessage(retrieveDatasetVersionResponse.getDifferentVersionMessage());
        }
        // init the citation
        displayCitation = dataset.getCitation(true, workingVersion);
        if (initFull) {
            // init the list of FileMetadatas
            if (workingVersion.isDraft() && canUpdateDataset()) {
                readOnly = false;
            } else {
                // an attempt to retreive both the filemetadatas and datafiles early on, so that
                // we don't have to do so later (possibly, many more times than necessary):
                datafileService.findFileMetadataOptimizedExperimental(dataset);
            }
            fileMetadatasSearch = workingVersion.getFileMetadatasSorted();
            ownerId = dataset.getOwner().getId();
            datasetNextMajorVersion = this.dataset.getNextMajorVersionString();
            datasetNextMinorVersion = this.dataset.getNextMinorVersionString();
            datasetVersionUI = datasetVersionUI.initDatasetVersionUI(workingVersion, false);
            updateDatasetFieldInputLevels();
            setExistReleasedVersion(resetExistRealeaseVersion());
            // moving setVersionTabList to tab change event
            // setVersionTabList(resetVersionTabList());
            // setReleasedVersionTabList(resetReleasedVersionTabList());
            // SEK - lazymodel may be needed for datascroller in future release
            // lazyModel = new LazyFileMetadataDataModel(workingVersion.getId(), datafileService );
            // populate MapLayerMetadata
            // A DataFile may have a related MapLayerMetadata object
            this.loadMapLayerMetadataLookup();
            this.guestbookResponse = guestbookResponseService.initGuestbookResponseForFragment(dataset, null, session);
            this.getFileDownloadHelper().setGuestbookResponse(guestbookResponse);
            logger.fine("Checking if rsync support is enabled.");
            if (DataCaptureModuleUtil.rsyncSupportEnabled(settingsWrapper.getValueForKey(SettingsServiceBean.Key.UploadMethods))) {
                try {
                    ScriptRequestResponse scriptRequestResponse = commandEngine.submit(new RequestRsyncScriptCommand(dvRequestService.getDataverseRequest(), dataset));
                    logger.fine("script: " + scriptRequestResponse.getScript());
                    if (scriptRequestResponse.getScript() != null && !scriptRequestResponse.getScript().isEmpty()) {
                        setHasRsyncScript(true);
                        setRsyncScript(scriptRequestResponse.getScript());
                        rsyncScriptFilename = "upload-" + workingVersion.getDataset().getIdentifier() + ".bash";
                    } else {
                        setHasRsyncScript(false);
                    }
                } catch (RuntimeException ex) {
                    logger.warning("Problem getting rsync script: " + ex.getLocalizedMessage());
                } catch (CommandException cex) {
                    logger.warning("Problem getting rsync script (Command Exception): " + cex.getLocalizedMessage());
                }
            }
        }
    } else if (ownerId != null) {
        // create mode for a new child dataset
        readOnly = false;
        editMode = EditMode.CREATE;
        dataset.setOwner(dataverseService.find(ownerId));
        dataset.setProtocol(protocol);
        dataset.setAuthority(authority);
        dataset.setDoiSeparator(separator);
        if (dataset.getOwner() == null) {
            return permissionsWrapper.notFound();
        } else if (!permissionService.on(dataset.getOwner()).has(Permission.AddDataset)) {
            return permissionsWrapper.notAuthorized();
        }
        dataverseTemplates = dataverseService.find(ownerId).getTemplates();
        if (!dataverseService.find(ownerId).isTemplateRoot()) {
            dataverseTemplates.addAll(dataverseService.find(ownerId).getParentTemplates());
        }
        defaultTemplate = dataverseService.find(ownerId).getDefaultTemplate();
        if (defaultTemplate != null) {
            selectedTemplate = defaultTemplate;
            for (Template testT : dataverseTemplates) {
                if (defaultTemplate.getId().equals(testT.getId())) {
                    selectedTemplate = testT;
                }
            }
            workingVersion = dataset.getEditVersion(selectedTemplate);
            updateDatasetFieldInputLevels();
        } else {
            workingVersion = dataset.getCreateVersion();
            updateDatasetFieldInputLevels();
        }
        if (settingsWrapper.isTrueForKey(SettingsServiceBean.Key.PublicInstall, false)) {
            JH.addMessage(FacesMessage.SEVERITY_WARN, BundleUtil.getStringFromBundle("dataset.message.publicInstall"));
        }
        resetVersionUI();
    // FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Add New Dataset", " - Enter metadata to create the dataset's citation. You can add more metadata about this dataset after it's created."));
    } else {
        return permissionsWrapper.notFound();
    }
    try {
        privateUrl = commandEngine.submit(new GetPrivateUrlCommand(dvRequestService.getDataverseRequest(), dataset));
        if (privateUrl != null) {
            JH.addMessage(FacesMessage.SEVERITY_INFO, BundleUtil.getStringFromBundle("dataset.privateurl.infoMessageAuthor", Arrays.asList(getPrivateUrlLink(privateUrl))));
        }
    } catch (CommandException ex) {
    // No big deal. The user simply doesn't have access to create or delete a Private URL.
    }
    if (session.getUser() instanceof PrivateUrlUser) {
        PrivateUrlUser privateUrlUser = (PrivateUrlUser) session.getUser();
        if (dataset != null && dataset.getId().equals(privateUrlUser.getDatasetId())) {
            JH.addMessage(FacesMessage.SEVERITY_INFO, BundleUtil.getStringFromBundle("dataset.privateurl.infoMessageReviewer"));
        }
    }
    // Various info messages, when the dataset is locked (for various reasons):
    if (dataset.isLocked()) {
        if (dataset.isLockedFor(DatasetLock.Reason.Workflow)) {
            JH.addMessage(FacesMessage.SEVERITY_WARN, BundleUtil.getStringFromBundle("dataset.locked.message"), BundleUtil.getStringFromBundle("dataset.publish.workflow.inprogress"));
        }
        if (dataset.isLockedFor(DatasetLock.Reason.InReview)) {
            JH.addMessage(FacesMessage.SEVERITY_WARN, BundleUtil.getStringFromBundle("dataset.locked.inReview.message"), BundleUtil.getStringFromBundle("dataset.inreview.infoMessage"));
        }
        if (dataset.isLockedFor(DatasetLock.Reason.DcmUpload)) {
            JH.addMessage(FacesMessage.SEVERITY_WARN, BundleUtil.getStringFromBundle("file.rsyncUpload.inProgressMessage.summary"), BundleUtil.getStringFromBundle("file.rsyncUpload.inProgressMessage.details"));
        }
    }
    configureTools = externalToolService.findByType(ExternalTool.Type.CONFIGURE);
    exploreTools = externalToolService.findByType(ExternalTool.Type.EXPLORE);
    return null;
}
Also used : ScriptRequestResponse(edu.harvard.iq.dataverse.datacapturemodule.ScriptRequestResponse) PrivateUrlUser(edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser) GetPrivateUrlCommand(edu.harvard.iq.dataverse.engine.command.impl.GetPrivateUrlCommand) IOException(java.io.IOException) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) IllegalCommandException(edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException) RequestRsyncScriptCommand(edu.harvard.iq.dataverse.engine.command.impl.RequestRsyncScriptCommand)

Example 2 with PrivateUrlUser

use of edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser in project dataverse by IQSS.

the class CreatePrivateUrlCommandTest method setUp.

@Before
public void setUp() {
    dataset = new Dataset();
    testEngine = new TestDataverseEngine(new TestCommandContext() {

        @Override
        public PrivateUrlServiceBean privateUrl() {
            return new PrivateUrlServiceBean() {

                @Override
                public PrivateUrl getPrivateUrlFromDatasetId(long datasetId) {
                    if (datasetId == privateUrlAlreadyExists) {
                        Dataset dataset = new Dataset();
                        dataset.setId(privateUrlAlreadyExists);
                        String token = null;
                        PrivateUrlUser privateUrlUser = new PrivateUrlUser(datasetId);
                        RoleAssignment roleAssignment = new RoleAssignment(null, privateUrlUser, dataset, token);
                        return new PrivateUrl(roleAssignment, dataset, "FIXME");
                    } else if (datasetId == latestVersionIsNotDraft) {
                        return null;
                    } else {
                        return null;
                    }
                }
            };
        }

        @Override
        public DataverseRoleServiceBean roles() {
            return new DataverseRoleServiceBean() {

                @Override
                public DataverseRole findBuiltinRoleByAlias(String alias) {
                    return new DataverseRole();
                }

                @Override
                public RoleAssignment save(RoleAssignment assignment) {
                    // no-op
                    return assignment;
                }
            };
        }

        @Override
        public SystemConfig systemConfig() {
            return new SystemConfig() {

                @Override
                public String getDataverseSiteUrl() {
                    return "https://dataverse.example.edu";
                }
            };
        }
    });
}
Also used : DataverseRoleServiceBean(edu.harvard.iq.dataverse.DataverseRoleServiceBean) SystemConfig(edu.harvard.iq.dataverse.util.SystemConfig) TestCommandContext(edu.harvard.iq.dataverse.engine.TestCommandContext) PrivateUrl(edu.harvard.iq.dataverse.privateurl.PrivateUrl) Dataset(edu.harvard.iq.dataverse.Dataset) PrivateUrlUser(edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) PrivateUrlServiceBean(edu.harvard.iq.dataverse.privateurl.PrivateUrlServiceBean) TestDataverseEngine(edu.harvard.iq.dataverse.engine.TestDataverseEngine) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) Before(org.junit.Before)

Example 3 with PrivateUrlUser

use of edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser in project dataverse by IQSS.

the class PrivateUrlServiceBean method getPrivateUrlRoleAssignmentFromDataset.

/**
 * @param dataset A non-null dataset;
 * @return A role assignment for a Private URL, if found, or null.
 *
 * @todo This might be a good place for Optional.
 */
private RoleAssignment getPrivateUrlRoleAssignmentFromDataset(Dataset dataset) {
    if (dataset == null) {
        return null;
    }
    TypedQuery<RoleAssignment> query = em.createNamedQuery("RoleAssignment.listByAssigneeIdentifier_DefinitionPointId", RoleAssignment.class);
    PrivateUrlUser privateUrlUser = new PrivateUrlUser(dataset.getId());
    query.setParameter("assigneeIdentifier", privateUrlUser.getIdentifier());
    query.setParameter("definitionPointId", dataset.getId());
    try {
        return query.getSingleResult();
    } catch (NoResultException | NonUniqueResultException ex) {
        return null;
    }
}
Also used : NonUniqueResultException(javax.persistence.NonUniqueResultException) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) PrivateUrlUser(edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser) NoResultException(javax.persistence.NoResultException)

Example 4 with PrivateUrlUser

use of edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser in project dataverse by IQSS.

the class JsonPrinterTest method testJson_PrivateUrl.

@Test
public void testJson_PrivateUrl() {
    DataverseRole aRole = new DataverseRole();
    PrivateUrlUser privateUrlUserIn = new PrivateUrlUser(42);
    RoleAssignee anAssignee = privateUrlUserIn;
    Dataset dataset = new Dataset();
    String privateUrlToken = "e1d53cf6-794a-457a-9709-7c07629a8267";
    RoleAssignment ra = new RoleAssignment(aRole, anAssignee, dataset, privateUrlToken);
    String dataverseSiteUrl = "https://dataverse.example.edu";
    PrivateUrl privateUrl = new PrivateUrl(ra, dataset, dataverseSiteUrl);
    JsonObjectBuilder job = JsonPrinter.json(privateUrl);
    assertNotNull(job);
    JsonObject jsonObject = job.build();
    assertEquals("e1d53cf6-794a-457a-9709-7c07629a8267", jsonObject.getString("token"));
    assertEquals("https://dataverse.example.edu/privateurl.xhtml?token=e1d53cf6-794a-457a-9709-7c07629a8267", jsonObject.getString("link"));
    assertEquals("e1d53cf6-794a-457a-9709-7c07629a8267", jsonObject.getJsonObject("roleAssignment").getString("privateUrlToken"));
    assertEquals("#42", jsonObject.getJsonObject("roleAssignment").getString("assignee"));
}
Also used : PrivateUrl(edu.harvard.iq.dataverse.privateurl.PrivateUrl) Dataset(edu.harvard.iq.dataverse.Dataset) PrivateUrlUser(edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) JsonObject(javax.json.JsonObject) JsonObjectBuilder(javax.json.JsonObjectBuilder) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee) Test(org.junit.Test)

Example 5 with PrivateUrlUser

use of edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser in project dataverse by IQSS.

the class PrivateUrlUtilTest method testGetPrivateUrlUserFromRoleAssignmentAndAssigneeNonPrivateUrlUser.

@Test
public void testGetPrivateUrlUserFromRoleAssignmentAndAssigneeNonPrivateUrlUser() {
    DataverseRole aRole = null;
    RoleAssignee assignee = GuestUser.get();
    DvObject dataset = new Dataset();
    String privateUrlToken = "cd71e9d7-73a7-4ec8-b890-3d00499e8693";
    RoleAssignment assignment = new RoleAssignment(aRole, assignee, dataset, privateUrlToken);
    PrivateUrlUser privateUrl = PrivateUrlUtil.getPrivateUrlUserFromRoleAssignment(assignment, assignee);
    assertNull(privateUrl);
}
Also used : DvObject(edu.harvard.iq.dataverse.DvObject) Dataset(edu.harvard.iq.dataverse.Dataset) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) PrivateUrlUser(edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee) Test(org.junit.Test)

Aggregations

PrivateUrlUser (edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser)33 RoleAssignment (edu.harvard.iq.dataverse.RoleAssignment)22 Test (org.junit.Test)21 DataverseRole (edu.harvard.iq.dataverse.authorization.DataverseRole)18 RoleAssignee (edu.harvard.iq.dataverse.authorization.RoleAssignee)18 Dataset (edu.harvard.iq.dataverse.Dataset)14 DvObject (edu.harvard.iq.dataverse.DvObject)11 PrivateUrl (edu.harvard.iq.dataverse.privateurl.PrivateUrl)6 DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)5 CommandException (edu.harvard.iq.dataverse.engine.command.exception.CommandException)4 IllegalCommandException (edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException)4 ArrayList (java.util.ArrayList)3 JsonObject (javax.json.JsonObject)3 Dataverse (edu.harvard.iq.dataverse.Dataverse)2 DataverseRoleServiceBean (edu.harvard.iq.dataverse.DataverseRoleServiceBean)2 FileMetadata (edu.harvard.iq.dataverse.FileMetadata)2 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)2 GuestUser (edu.harvard.iq.dataverse.authorization.users.GuestUser)2 User (edu.harvard.iq.dataverse.authorization.users.User)2 TestCommandContext (edu.harvard.iq.dataverse.engine.TestCommandContext)2