Search in sources :

Example 1 with ActionProvider

use of ddf.action.ActionProvider in project ddf by codice.

the class TestAtomTransformer method testNoResourceActionProvider.

@Test
public void testNoResourceActionProvider() throws CatalogTransformerException, IOException, XpathException, SAXException {
    // given
    MetacardTransformer metacardTransformer = getXmlMetacardTransformerStub();
    Action viewAction = mock(Action.class);
    when(viewAction.getUrl()).thenReturn(new URL("http://host:80/" + SAMPLE_ID));
    ActionProvider viewActionProvider = mock(ActionProvider.class);
    when(viewActionProvider.getAction(isA(Metacard.class))).thenReturn(viewAction);
    AtomTransformer transformer = new AtomTransformer();
    transformer.setViewMetacardActionProvider(viewActionProvider);
    transformer.setMetacardTransformer(metacardTransformer);
    setDefaultSystemConfiguration();
    SourceResponse response1 = mock(SourceResponse.class);
    when(response1.getHits()).thenReturn(new Long(1));
    when(response1.getRequest()).thenReturn(getStubRequest());
    ResultImpl result1 = new ResultImpl();
    MetacardStub metacard = new MetacardStub("");
    metacard.setId(SAMPLE_ID);
    metacard.setSourceId(SAMPLE_SOURCE_ID);
    metacard.setCreatedDate(SAMPLE_DATE_TIME.toDate());
    metacard.setModifiedDate(SAMPLE_DATE_TIME.toDate());
    result1.setMetacard(metacard);
    when(response1.getResults()).thenReturn(Arrays.asList((Result) result1));
    SourceResponse response = response1;
    Double relevanceScore = 0.3345;
    result1.setRelevanceScore(relevanceScore);
    // when
    BinaryContent binaryContent = transformer.transform(response, null);
    // then
    assertThat(binaryContent.getMimeType(), is(AtomTransformer.MIME_TYPE));
    byte[] bytes = binaryContent.getByteArray();
    /* used to visualize */
    IOUtils.write(bytes, new FileOutputStream(new File(TARGET_FOLDER + getMethodName() + ATOM_EXTENSION)));
    String output = new String(bytes);
    assertFeedCompliant(output);
    assertEntryCompliant(output);
    validateAgainstAtomSchema(bytes);
    /* feed */
    assertBasicFeedInfo(output, "1");
    /* entry */
    assertXpathEvaluatesTo(SAMPLE_SOURCE_ID, "/atom:feed/atom:entry/fs:resultSource/@fs:sourceId", output);
    assertXpathEvaluatesTo("", "/atom:feed/atom:entry/fs:resultSource", output);
    assertXpathEvaluatesTo(AtomTransformer.URN_CATALOG_ID + SAMPLE_ID, "/atom:feed/atom:entry/atom:id", output);
    assertXpathEvaluatesTo(MetacardStub.DEFAULT_TITLE, "/atom:feed/atom:entry/atom:title", output);
    assertXpathEvaluatesTo(Double.toString(relevanceScore), "/atom:feed/atom:entry/relevance:score", output);
    assertXpathExists("/atom:feed/atom:entry/atom:content", output);
    assertXpathEvaluatesTo(atomDateFormat.format(SAMPLE_DATE_TIME.toDate()), "/atom:feed/atom:entry/atom:published", output);
    assertXpathEvaluatesTo(atomDateFormat.format(SAMPLE_DATE_TIME.toDate()), "/atom:feed/atom:entry/atom:updated", output);
    assertXpathEvaluatesTo("application/xml", "/atom:feed/atom:entry/atom:content/@type", output);
    assertXpathEvaluatesTo(MetacardStub.DEFAULT_TYPE, "/atom:feed/atom:entry/atom:category/@term", output);
    assertXpathEvaluatesTo("1", "count(/atom:feed/atom:entry/georss:where)", output);
    assertXpathEvaluatesTo("1", "count(/atom:feed/atom:entry/georss:where/gml:Point)", output);
    assertXpathEvaluatesTo("56.3 13.3", "/atom:feed/atom:entry/georss:where/gml:Point", output);
    assertXpathEvaluatesTo("1", "count(/atom:feed/atom:entry/atom:link)", output);
    assertXpathExists("/atom:feed/atom:entry/atom:link[@rel='alternate']", output);
    assertXpathNotExists("/atom:feed/atom:entry/atom:link[@rel='related']", output);
    assertXpathEvaluatesTo("http://host:80/" + SAMPLE_ID, "/atom:feed/atom:entry/atom:link/@href", output);
}
Also used : ActionProvider(ddf.action.ActionProvider) Action(ddf.action.Action) MetacardTransformer(ddf.catalog.transform.MetacardTransformer) SourceResponse(ddf.catalog.operation.SourceResponse) ResultImpl(ddf.catalog.data.impl.ResultImpl) BinaryContent(ddf.catalog.data.BinaryContent) URL(java.net.URL) Result(ddf.catalog.data.Result) Metacard(ddf.catalog.data.Metacard) FileOutputStream(java.io.FileOutputStream) File(java.io.File) Test(org.junit.Test)

Example 2 with ActionProvider

use of ddf.action.ActionProvider in project ddf by codice.

the class ActionProviderRegistryProxy method bind.

public void bind(ServiceReference<MetacardTransformer> reference) {
    LOGGER.info("New service registered [{}]", reference);
    String transformerId = null;
    if (reference.getProperty(Constants.SERVICE_ID) != null) {
        transformerId = reference.getProperty(Constants.SERVICE_ID).toString();
    // backwards compatibility
    }
    if (StringUtils.isBlank(transformerId) && reference.getProperty(Constants.SERVICE_SHORTNAME) != null) {
        transformerId = reference.getProperty(Constants.SERVICE_SHORTNAME).toString();
    }
    if (StringUtils.isBlank(transformerId)) {
        return;
    }
    String actionProviderId = ACTION_ID_PREFIX + transformerId;
    String attributeName = getAttributeName(reference);
    ActionProvider provider = actionFactory.createActionProvider(actionProviderId, transformerId, attributeName);
    Dictionary actionProviderProperties = new Hashtable<String, String>();
    actionProviderProperties.put(Constants.SERVICE_ID, actionProviderId);
    ServiceRegistration actionServiceRegistration = getBundleContext().registerService(PROVIDER_INTERFACE_NAME, provider, actionProviderProperties);
    LOGGER.info("Registered new {} [{}]", PROVIDER_INTERFACE_NAME, actionServiceRegistration);
    actionProviderRegistry.put(reference, actionServiceRegistration);
}
Also used : ActionProvider(ddf.action.ActionProvider) Dictionary(java.util.Dictionary) Hashtable(java.util.Hashtable) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 3 with ActionProvider

use of ddf.action.ActionProvider in project ddf by codice.

the class LogoutService method getActionProviders.

@GET
@Path("/actions")
public Response getActionProviders(@Context HttpServletRequest request) throws SecurityServiceException {
    HttpSession session = httpSessionFactory.getOrCreateSession(request);
    Map<String, SecurityToken> realmTokenMap = ((SecurityTokenHolder) session.getAttribute(SecurityConstants.SAML_ASSERTION)).getRealmTokenMap();
    Map<String, Subject> realmSubjectMap = new HashMap<>();
    for (Map.Entry<String, SecurityToken> entry : realmTokenMap.entrySet()) {
        realmSubjectMap.put(entry.getKey(), securityManager.getSubject(entry.getValue()));
    }
    List<Map<String, String>> realmToPropMaps = new ArrayList<>();
    for (ActionProvider actionProvider : logoutActionProviders) {
        Action action = actionProvider.getAction(realmSubjectMap);
        if (action != null) {
            String realm = StringUtils.substringAfterLast(action.getId(), ".");
            //if the user is logged in and isn't a guest, add them
            if (realmTokenMap.get(realm) != null) {
                Map<String, String> actionProperties = new HashMap<>();
                String displayName = SubjectUtils.getName(realmSubjectMap.get(realm), "", true);
                if (displayName != null && !displayName.equals(SubjectUtils.GUEST_DISPLAY_NAME)) {
                    actionProperties.put("title", action.getTitle());
                    actionProperties.put("realm", realm);
                    actionProperties.put("auth", displayName);
                    actionProperties.put("description", action.getDescription());
                    actionProperties.put("url", action.getUrl().toString());
                    realmToPropMaps.add(actionProperties);
                }
            }
        }
    }
    return Response.ok(new ByteArrayInputStream(toJson(realmToPropMaps).getBytes(StandardCharsets.UTF_8))).build();
}
Also used : ActionProvider(ddf.action.ActionProvider) Action(ddf.action.Action) HashMap(java.util.HashMap) HttpSession(javax.servlet.http.HttpSession) ArrayList(java.util.ArrayList) Subject(org.apache.shiro.subject.Subject) SecurityToken(org.apache.cxf.ws.security.tokenstore.SecurityToken) SecurityTokenHolder(ddf.security.common.SecurityTokenHolder) ByteArrayInputStream(java.io.ByteArrayInputStream) HashMap(java.util.HashMap) Map(java.util.Map) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 4 with ActionProvider

use of ddf.action.ActionProvider in project ddf by codice.

the class AbstractDownloadsStatusEventPublisherTest method setupPublisherWithNoNotifications.

private void setupPublisherWithNoNotifications() {
    actionProvider = mock(ActionProvider.class);
    eventAdmin = mock(EventAdmin.class);
    publisher = new DownloadsStatusEventPublisher(eventAdmin, ImmutableList.of(actionProvider));
    publisher.setSubjectOperations(new SubjectUtils());
    publisher.setNotificationEnabled(false);
    publisher.setActivityEnabled(false);
}
Also used : ActionProvider(ddf.action.ActionProvider) SubjectUtils(ddf.security.service.impl.SubjectUtils) EventAdmin(org.osgi.service.event.EventAdmin)

Example 5 with ActionProvider

use of ddf.action.ActionProvider in project ddf by codice.

the class KMLTransformerImplTest method setUp.

@BeforeClass
public static void setUp() throws IOException {
    metacardDate = new Date(metacardDate.getTime() + Calendar.getInstance().getTimeZone().getOffset(metacardDate.getTime()));
    when(mockContext.getBundle()).thenReturn(mockBundle);
    URL url = KMLTransformerImplTest.class.getResource(DEFAULT_STYLE_LOCATION);
    when(mockBundle.getResource(any(String.class))).thenReturn(url);
    dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
    ActionProvider mockActionProvider = mock(ActionProvider.class);
    Action mockAction = mock(Action.class);
    when(mockActionProvider.getAction(any(Metacard.class))).thenReturn(mockAction);
    when(mockAction.getUrl()).thenReturn(new URL(ACTION_URL));
    kmlTransformer = new KMLTransformerImpl(mockContext, DEFAULT_STYLE_LOCATION, new KmlStyleMap(), mockActionProvider, new KmlMarshaller());
}
Also used : ActionProvider(ddf.action.ActionProvider) Action(ddf.action.Action) Metacard(ddf.catalog.data.Metacard) LineString(de.micromata.opengis.kml.v_2_2_0.LineString) Date(java.util.Date) URL(java.net.URL) KmlMarshaller(org.codice.ddf.spatial.kml.util.KmlMarshaller) BeforeClass(org.junit.BeforeClass)

Aggregations

ActionProvider (ddf.action.ActionProvider)15 Action (ddf.action.Action)10 URL (java.net.URL)8 Metacard (ddf.catalog.data.Metacard)6 Test (org.junit.Test)6 BinaryContent (ddf.catalog.data.BinaryContent)4 Result (ddf.catalog.data.Result)4 ResultImpl (ddf.catalog.data.impl.ResultImpl)4 SourceResponse (ddf.catalog.operation.SourceResponse)4 MetacardTransformer (ddf.catalog.transform.MetacardTransformer)4 File (java.io.File)4 FileOutputStream (java.io.FileOutputStream)4 SubjectUtils (ddf.security.service.impl.SubjectUtils)3 Dictionary (java.util.Dictionary)3 AttributeMetacardTransformer (ddf.catalog.transformer.attribute.AttributeMetacardTransformer)2 LineString (de.micromata.opengis.kml.v_2_2_0.LineString)2 HashMap (java.util.HashMap)2 MimeType (javax.activation.MimeType)2 HttpSession (javax.servlet.http.HttpSession)2 Subject (org.apache.shiro.subject.Subject)2