Search in sources :

Example 91 with Dataverse

use of edu.harvard.iq.dataverse.Dataverse in project dataverse by IQSS.

the class ExplicitGroupTest method recursiveStructuralContainment.

@Test
public void recursiveStructuralContainment() throws GroupException {
    Dataverse dvParent = makeDataverse();
    ExplicitGroup parentGroup = roleAssigneeSvc.add(makeExplicitGroup(prv));
    ExplicitGroup childGroup = roleAssigneeSvc.add(makeExplicitGroup(prv));
    ExplicitGroup grandChildGroup = roleAssigneeSvc.add(makeExplicitGroup(prv));
    parentGroup.setOwner(dvParent);
    childGroup.setOwner(dvParent);
    grandChildGroup.setOwner(dvParent);
    childGroup.add(grandChildGroup);
    parentGroup.add(childGroup);
    AuthenticatedUser au = roleAssigneeSvc.add(makeAuthenticatedUser("Jane", "Doe"));
    grandChildGroup.add(au);
    childGroup.add(GuestUser.get());
    assertTrue(grandChildGroup.structuralContains(au));
    assertTrue(childGroup.structuralContains(au));
    assertTrue(parentGroup.structuralContains(au));
    assertTrue(childGroup.structuralContains(GuestUser.get()));
    assertTrue(parentGroup.structuralContains(GuestUser.get()));
    grandChildGroup.remove(au);
    assertFalse(grandChildGroup.structuralContains(au));
    assertFalse(childGroup.structuralContains(au));
    assertFalse(parentGroup.structuralContains(au));
    childGroup.add(AuthenticatedUsers.get());
    assertFalse(grandChildGroup.structuralContains(au));
    assertFalse(childGroup.structuralContains(au));
    assertFalse(parentGroup.structuralContains(au));
    assertTrue(childGroup.structuralContains(AuthenticatedUsers.get()));
    final IpGroup ipGroup = new IpGroup(new IpGroupProvider(null));
    grandChildGroup.add(ipGroup);
    ipGroup.add(IpAddressRange.make(IpAddress.valueOf("0.0.1.1"), IpAddress.valueOf("0.0.255.255")));
    assertTrue(grandChildGroup.structuralContains(ipGroup));
    assertTrue(childGroup.structuralContains(ipGroup));
    assertTrue(parentGroup.structuralContains(ipGroup));
}
Also used : IpGroup(edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.IpGroup) IpGroupProvider(edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.IpGroupProvider) Dataverse(edu.harvard.iq.dataverse.Dataverse) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) Test(org.junit.Test)

Example 92 with Dataverse

use of edu.harvard.iq.dataverse.Dataverse in project dataverse by IQSS.

the class ExplicitGroupTest method adds.

@Test
public void adds() throws GroupException {
    Dataverse dvParent = makeDataverse();
    ExplicitGroup g1 = new ExplicitGroup(prv);
    g1.setOwner(dvParent);
    AuthenticatedUser au1 = makeAuthenticatedUser("Lauren", "Ipsum");
    g1.add(au1);
    g1.add(GuestUser.get());
    assertTrue(g1.structuralContains(GuestUser.get()));
    assertTrue(g1.structuralContains(au1));
    assertFalse(g1.structuralContains(makeAuthenticatedUser("Sima", "Kneidle")));
    assertFalse(g1.structuralContains(AllUsers.get()));
}
Also used : Dataverse(edu.harvard.iq.dataverse.Dataverse) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) Test(org.junit.Test)

Example 93 with Dataverse

use of edu.harvard.iq.dataverse.Dataverse in project dataverse by IQSS.

the class ExplicitGroupTest method recursiveLogicalContainment.

@Test
public void recursiveLogicalContainment() throws GroupException {
    Dataverse dvParent = makeDataverse();
    ExplicitGroup parentGroup = roleAssigneeSvc.add(makeExplicitGroup("parent", prv));
    ExplicitGroup childGroup = roleAssigneeSvc.add(makeExplicitGroup("child", prv));
    ExplicitGroup grandChildGroup = roleAssigneeSvc.add(makeExplicitGroup("grandChild", prv));
    parentGroup.setOwner(dvParent);
    childGroup.setOwner(dvParent);
    grandChildGroup.setOwner(dvParent);
    childGroup.add(grandChildGroup);
    parentGroup.add(childGroup);
    AuthenticatedUser au = roleAssigneeSvc.add(makeAuthenticatedUser("Jane", "Doe"));
    grandChildGroup.add(au);
    childGroup.add(GuestUser.get());
    DataverseRequest auReq = makeRequest(au);
    DataverseRequest guestReq = makeRequest();
    assertTrue(grandChildGroup.contains(auReq));
    assertTrue(childGroup.contains(auReq));
    assertTrue(parentGroup.contains(auReq));
    assertTrue(childGroup.contains(guestReq));
    assertTrue(parentGroup.contains(guestReq));
    grandChildGroup.remove(au);
    assertFalse(grandChildGroup.contains(auReq));
    assertFalse(childGroup.contains(auReq));
    assertFalse(parentGroup.contains(auReq));
    childGroup.add(AuthenticatedUsers.get());
    assertFalse(grandChildGroup.contains(auReq));
    assertTrue(childGroup.contains(auReq));
    assertTrue(parentGroup.contains(auReq));
    final IpGroup ipGroup = roleAssigneeSvc.add(new IpGroup(new IpGroupProvider(null)));
    grandChildGroup.add(ipGroup);
    ipGroup.add(IpAddressRange.make(IpAddress.valueOf("0.0.1.1"), IpAddress.valueOf("0.0.255.255")));
    final IpAddress ip = IpAddress.valueOf("0.0.128.128");
    final DataverseRequest request = new DataverseRequest(GuestUser.get(), ip);
    assertTrue(ipGroup.contains(request));
    assertTrue(grandChildGroup.contains(request));
    assertTrue(parentGroup.contains(request));
    childGroup.add(GuestUser.get());
    assertTrue(childGroup.contains(guestReq));
    assertTrue(parentGroup.contains(guestReq));
    assertFalse(grandChildGroup.contains(guestReq));
}
Also used : DataverseRequest(edu.harvard.iq.dataverse.engine.command.DataverseRequest) IpAddress(edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.ip.IpAddress) IpGroup(edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.IpGroup) IpGroupProvider(edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.IpGroupProvider) Dataverse(edu.harvard.iq.dataverse.Dataverse) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) Test(org.junit.Test)

Example 94 with Dataverse

use of edu.harvard.iq.dataverse.Dataverse in project dataverse by IQSS.

the class SavedSearchServiceBean method makeLinksForSingleSavedSearch.

/**
 * The "Saved Search" and highly related "Linked Dataverses and Linked
 * Datasets" features can be thought of as periodic execution of the
 * LinkDataverseCommand and LinkDatasetCommand. As of this writing that
 * periodic execution can be triggered via a cron job but we'd like to put
 * it on an EJB timer as part of
 * https://github.com/IQSS/dataverse/issues/2543 .
 *
 * The commands are executed by the creator of the SavedSearch. What happens
 * if the users loses the permission that the command requires? Should the
 * commands continue to be executed periodically as some "system" user?
 *
 * @return Debug information in the form of a JSON object, which is much
 * more structured that a simple String.
 */
public JsonObjectBuilder makeLinksForSingleSavedSearch(DataverseRequest dvReq, SavedSearch savedSearch, boolean debugFlag) throws SearchException, CommandException {
    JsonObjectBuilder response = Json.createObjectBuilder();
    JsonArrayBuilder savedSearchArrayBuilder = Json.createArrayBuilder();
    JsonArrayBuilder infoPerHit = Json.createArrayBuilder();
    SolrQueryResponse queryResponse = findHits(savedSearch);
    for (SolrSearchResult solrSearchResult : queryResponse.getSolrSearchResults()) {
        JsonObjectBuilder hitInfo = Json.createObjectBuilder();
        hitInfo.add("name", solrSearchResult.getNameSort());
        hitInfo.add("dvObjectId", solrSearchResult.getEntityId());
        DvObject dvObjectThatDefinitionPointWillLinkTo = dvObjectService.findDvObject(solrSearchResult.getEntityId());
        if (dvObjectThatDefinitionPointWillLinkTo == null) {
            hitInfo.add(resultString, "Could not find DvObject with id " + solrSearchResult.getEntityId());
            infoPerHit.add(hitInfo);
            break;
        }
        if (dvObjectThatDefinitionPointWillLinkTo.isInstanceofDataverse()) {
            Dataverse dataverseToLinkTo = (Dataverse) dvObjectThatDefinitionPointWillLinkTo;
            if (wouldResultInLinkingToItself(savedSearch.getDefinitionPoint(), dataverseToLinkTo)) {
                hitInfo.add(resultString, "Skipping because dataverse id " + dataverseToLinkTo.getId() + " would link to itself.");
            } else if (alreadyLinkedToTheDataverse(savedSearch.getDefinitionPoint(), dataverseToLinkTo)) {
                hitInfo.add(resultString, "Skipping because dataverse " + savedSearch.getDefinitionPoint().getId() + " already links to dataverse " + dataverseToLinkTo.getId() + ".");
            } else if (dataverseToLinkToIsAlreadyPartOfTheSubtree(savedSearch.getDefinitionPoint(), dataverseToLinkTo)) {
                hitInfo.add(resultString, "Skipping because " + dataverseToLinkTo + " is already part of the subtree for " + savedSearch.getDefinitionPoint());
            } else {
                DataverseLinkingDataverse link = commandEngine.submitInNewTransaction(new LinkDataverseCommand(dvReq, savedSearch.getDefinitionPoint(), dataverseToLinkTo));
                hitInfo.add(resultString, "Persisted DataverseLinkingDataverse id " + link.getId() + " link of " + dataverseToLinkTo + " to " + savedSearch.getDefinitionPoint());
            }
        } else if (dvObjectThatDefinitionPointWillLinkTo.isInstanceofDataset()) {
            Dataset datasetToLinkTo = (Dataset) dvObjectThatDefinitionPointWillLinkTo;
            if (alreadyLinkedToTheDataset(savedSearch.getDefinitionPoint(), datasetToLinkTo)) {
                hitInfo.add(resultString, "Skipping because dataverse " + savedSearch.getDefinitionPoint() + " already links to dataset " + datasetToLinkTo + ".");
            } else if (datasetToLinkToIsAlreadyPartOfTheSubtree(savedSearch.getDefinitionPoint(), datasetToLinkTo)) {
                // already there from normal search/browse
                hitInfo.add(resultString, "Skipping because dataset " + datasetToLinkTo.getId() + " is already part of the subtree for " + savedSearch.getDefinitionPoint().getAlias());
            } else if (datasetAncestorAlreadyLinked(savedSearch.getDefinitionPoint(), datasetToLinkTo)) {
                hitInfo.add(resultString, "FIXME: implement this?");
            } else {
                DatasetLinkingDataverse link = commandEngine.submitInNewTransaction(new LinkDatasetCommand(dvReq, savedSearch.getDefinitionPoint(), datasetToLinkTo));
                hitInfo.add(resultString, "Persisted DatasetLinkingDataverse id " + link.getId() + " link of " + link.getDataset() + " to " + link.getLinkingDataverse());
            }
        } else if (dvObjectThatDefinitionPointWillLinkTo.isInstanceofDataFile()) {
            hitInfo.add(resultString, "Skipping because the search matched a file. The matched file id was " + dvObjectThatDefinitionPointWillLinkTo.getId() + ".");
        } else {
            hitInfo.add(resultString, "Unexpected DvObject type.");
        }
        infoPerHit.add(hitInfo);
    }
    JsonObjectBuilder info = getInfo(savedSearch, infoPerHit);
    if (debugFlag) {
        info.add("debug", getDebugInfo(savedSearch));
    }
    savedSearchArrayBuilder.add(info);
    response.add("hits for saved search id " + savedSearch.getId(), savedSearchArrayBuilder);
    return response;
}
Also used : SolrSearchResult(edu.harvard.iq.dataverse.search.SolrSearchResult) SolrQueryResponse(edu.harvard.iq.dataverse.search.SolrQueryResponse) DataverseLinkingDataverse(edu.harvard.iq.dataverse.DataverseLinkingDataverse) DvObject(edu.harvard.iq.dataverse.DvObject) LinkDatasetCommand(edu.harvard.iq.dataverse.engine.command.impl.LinkDatasetCommand) Dataset(edu.harvard.iq.dataverse.Dataset) DatasetLinkingDataverse(edu.harvard.iq.dataverse.DatasetLinkingDataverse) JsonArrayBuilder(javax.json.JsonArrayBuilder) JsonObjectBuilder(javax.json.JsonObjectBuilder) DataverseLinkingDataverse(edu.harvard.iq.dataverse.DataverseLinkingDataverse) DatasetLinkingDataverse(edu.harvard.iq.dataverse.DatasetLinkingDataverse) Dataverse(edu.harvard.iq.dataverse.Dataverse) LinkDataverseCommand(edu.harvard.iq.dataverse.engine.command.impl.LinkDataverseCommand)

Aggregations

Dataverse (edu.harvard.iq.dataverse.Dataverse)94 Dataset (edu.harvard.iq.dataverse.Dataset)34 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)31 Test (org.junit.Test)27 DataverseRequest (edu.harvard.iq.dataverse.engine.command.DataverseRequest)22 DataFile (edu.harvard.iq.dataverse.DataFile)18 IOException (java.io.IOException)18 Path (javax.ws.rs.Path)16 JsonObject (javax.json.JsonObject)15 CommandException (edu.harvard.iq.dataverse.engine.command.exception.CommandException)11 ArrayList (java.util.ArrayList)11 EJBException (javax.ejb.EJBException)11 JsonObjectBuilder (javax.json.JsonObjectBuilder)11 InputStream (java.io.InputStream)10 Date (java.util.Date)10 JsonArrayBuilder (javax.json.JsonArrayBuilder)10 POST (javax.ws.rs.POST)10 DataverseRole (edu.harvard.iq.dataverse.authorization.DataverseRole)9 User (edu.harvard.iq.dataverse.authorization.users.User)9 SwordError (org.swordapp.server.SwordError)9