Search in sources :

Example 6 with WorkspaceMetacardImpl

use of org.codice.ddf.catalog.ui.metacard.workspace.WorkspaceMetacardImpl in project ddf by codice.

the class TestAttributeMetacardFormatter method testFormatNonDefault.

@Test
public void testFormatNonDefault() {
    String template = "%[attribute=id]";
    String id = "the-id";
    WorkspaceMetacardImpl workspaceMetacard = new WorkspaceMetacardImpl(id);
    AttributeMetacardFormatter attributeMetacardFormatter = new AttributeMetacardFormatter("n/a");
    String result = attributeMetacardFormatter.format(template, workspaceMetacard, 0L);
    assertThat(result, is(id));
}
Also used : WorkspaceMetacardImpl(org.codice.ddf.catalog.ui.metacard.workspace.WorkspaceMetacardImpl) Test(org.junit.Test)

Example 7 with WorkspaceMetacardImpl

use of org.codice.ddf.catalog.ui.metacard.workspace.WorkspaceMetacardImpl in project ddf by codice.

the class TestWorkspaceServiceImpl method testGetWorkspaceMetacardsByWorkspaceId.

@Test
public void testGetWorkspaceMetacardsByWorkspaceId() throws UnsupportedQueryException, SourceUnavailableException, FederationException {
    String id = "123";
    String subject = "subject";
    mockCatalogFrameworkQuery(id, subject);
    Filter workspaceTagFilter = mockWorkspaceTagFilter();
    Filter metacardIdFilter = mock(Filter.class);
    when(filterService.buildMetacardIdFilter(id)).thenReturn(metacardIdFilter);
    And andFilter = mock(And.class);
    when(filterBuilder.allOf(metacardIdFilter, workspaceTagFilter)).thenReturn(andFilter);
    Or orFilter = mock(Or.class);
    when(filterBuilder.anyOf(Collections.singletonList(andFilter))).thenReturn(orFilter);
    List<WorkspaceMetacardImpl> workspaceMetacards = workspaceService.getWorkspaceMetacards(Collections.singleton(id));
    assertMetacardList(id, subject, workspaceMetacards);
}
Also used : Or(org.opengis.filter.Or) WorkspaceMetacardFilter(org.codice.ddf.catalog.ui.query.monitor.api.WorkspaceMetacardFilter) Filter(org.opengis.filter.Filter) And(org.opengis.filter.And) WorkspaceMetacardImpl(org.codice.ddf.catalog.ui.metacard.workspace.WorkspaceMetacardImpl) Test(org.junit.Test)

Example 8 with WorkspaceMetacardImpl

use of org.codice.ddf.catalog.ui.metacard.workspace.WorkspaceMetacardImpl in project ddf by codice.

the class WorkspaceAccessPluginTest method testStopProcessingWhenNotOwner.

@Test(expected = StopProcessingException.class)
public void testStopProcessingWhenNotOwner() throws Exception {
    String id = "0";
    WorkspaceMetacardImpl before = WorkspaceMetacardImpl.from(ImmutableMap.of(Metacard.ID, id, Core.METACARD_OWNER, "owner", WorkspaceAttributes.WORKSPACE_SHARING, ImmutableList.of()));
    WorkspaceMetacardImpl after = WorkspaceMetacardImpl.from(ImmutableMap.of(Metacard.ID, id, Core.METACARD_OWNER, "owner", WorkspaceAttributes.WORKSPACE_SHARING, ImmutableList.of("<xml/>")));
    UpdateRequest update = mockUpdateRequest(ImmutableMap.of(id, after));
    doReturn(false).when(subject).isPermitted(any(Permission.class));
    accessPlugin.processPreUpdate(update, ImmutableMap.of(id, before));
}
Also used : UpdateRequest(ddf.catalog.operation.UpdateRequest) KeyValuePermission(ddf.security.permission.KeyValuePermission) Permission(org.apache.shiro.authz.Permission) KeyValueCollectionPermission(ddf.security.permission.KeyValueCollectionPermission) WorkspaceMetacardImpl(org.codice.ddf.catalog.ui.metacard.workspace.WorkspaceMetacardImpl) Test(org.junit.Test)

Example 9 with WorkspaceMetacardImpl

use of org.codice.ddf.catalog.ui.metacard.workspace.WorkspaceMetacardImpl in project ddf by codice.

the class WorkspaceAccessPluginTest method testPermittedWhenOwnerOnUpdatedRoles.

@Test
public void testPermittedWhenOwnerOnUpdatedRoles() throws Exception {
    String id = "0";
    WorkspaceMetacardImpl before = WorkspaceMetacardImpl.from(ImmutableMap.of(Metacard.ID, id, Core.METACARD_OWNER, "before", WorkspaceAttributes.WORKSPACE_SHARING, ImmutableList.of()));
    WorkspaceMetacardImpl after = WorkspaceMetacardImpl.from(ImmutableMap.of(Metacard.ID, id, Core.METACARD_OWNER, "after", WorkspaceAttributes.WORKSPACE_SHARING, ImmutableList.of("<xml/>")));
    UpdateRequest update = mockUpdateRequest(ImmutableMap.of(id, after));
    ArgumentCaptor<KeyValueCollectionPermission> args = ArgumentCaptor.forClass(KeyValueCollectionPermission.class);
    doReturn(true).when(subject).isPermitted(args.capture());
    accessPlugin.processPreUpdate(update, ImmutableMap.of(id, before));
    KeyValuePermission permission = (KeyValuePermission) args.getValue().getKeyValuePermissionList().get(0);
    assertThat(permission.getKey(), is(Constants.EMAIL_ADDRESS_CLAIM_URI));
    // NOTE: the permission should contain the owner of the before metacard, not after
    assertThat(permission.getValues(), is(ImmutableSet.of(before.getOwner())));
}
Also used : KeyValueCollectionPermission(ddf.security.permission.KeyValueCollectionPermission) UpdateRequest(ddf.catalog.operation.UpdateRequest) KeyValuePermission(ddf.security.permission.KeyValuePermission) WorkspaceMetacardImpl(org.codice.ddf.catalog.ui.metacard.workspace.WorkspaceMetacardImpl) Test(org.junit.Test)

Example 10 with WorkspaceMetacardImpl

use of org.codice.ddf.catalog.ui.metacard.workspace.WorkspaceMetacardImpl in project ddf by codice.

the class WorkspaceAccessPluginTest method testSetOwnerRole.

@Test
public void testSetOwnerRole() throws Exception {
    String id = "0";
    WorkspaceMetacardImpl before = WorkspaceMetacardImpl.from(ImmutableMap.of(Metacard.ID, id, Core.METACARD_OWNER, "user1"));
    WorkspaceMetacardImpl after = WorkspaceMetacardImpl.from(ImmutableMap.of(Metacard.ID, id, Core.METACARD_OWNER, "user2"));
    UpdateRequest update = mockUpdateRequest(ImmutableMap.of(id, after));
    ArgumentCaptor<KeyValueCollectionPermission> args = ArgumentCaptor.forClass(KeyValueCollectionPermission.class);
    doReturn(true).when(subject).isPermitted(any(Permission.class));
    accessPlugin.processPreUpdate(update, ImmutableMap.of(id, before));
}
Also used : KeyValueCollectionPermission(ddf.security.permission.KeyValueCollectionPermission) UpdateRequest(ddf.catalog.operation.UpdateRequest) KeyValuePermission(ddf.security.permission.KeyValuePermission) Permission(org.apache.shiro.authz.Permission) KeyValueCollectionPermission(ddf.security.permission.KeyValueCollectionPermission) WorkspaceMetacardImpl(org.codice.ddf.catalog.ui.metacard.workspace.WorkspaceMetacardImpl) Test(org.junit.Test)

Aggregations

WorkspaceMetacardImpl (org.codice.ddf.catalog.ui.metacard.workspace.WorkspaceMetacardImpl)15 Test (org.junit.Test)15 Filter (org.opengis.filter.Filter)4 UpdateRequest (ddf.catalog.operation.UpdateRequest)3 KeyValueCollectionPermission (ddf.security.permission.KeyValueCollectionPermission)3 KeyValuePermission (ddf.security.permission.KeyValuePermission)3 Permission (org.apache.shiro.authz.Permission)3 WorkspaceMetacardFilter (org.codice.ddf.catalog.ui.query.monitor.api.WorkspaceMetacardFilter)3 And (org.opengis.filter.And)3 Or (org.opengis.filter.Or)3 CreateRequestImpl (ddf.catalog.operation.impl.CreateRequestImpl)2 PolicyResponse (ddf.catalog.plugin.PolicyResponse)2 QueryMetacardImpl (org.codice.ddf.catalog.ui.metacard.workspace.QueryMetacardImpl)2 CatalogFramework (ddf.catalog.CatalogFramework)1 Attribute (ddf.catalog.data.Attribute)1 Metacard (ddf.catalog.data.Metacard)1 FederationException (ddf.catalog.federation.FederationException)1 FilterBuilder (ddf.catalog.filter.FilterBuilder)1 QueryResponse (ddf.catalog.operation.QueryResponse)1 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)1