Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RTGOV-402 #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.overlord.commons.gwt.server.filters.ResourceCacheControlFilter;
import org.overlord.commons.ui.header.OverlordHeaderDataJS;
import org.overlord.rtgov.ui.server.RtgovUI;
import org.overlord.rtgov.ui.server.servlet.SituationsExportServlet;

import com.google.common.collect.Lists;

Expand Down Expand Up @@ -156,6 +157,9 @@ protected void addModulesToJetty(DevServerEnvironment environment, ContextHandle
for (String fileType : fileTypes) {
rtgovUI.addServlet(resources, "*." + fileType);
}
ServletHolder servletHolder = new ServletHolder(SituationsExportServlet.class);
servletHolder.setInitOrder(2);
rtgovUI.addServlet(servletHolder, "/situations/export");

rtgovUI.setSecurityHandler(createSecurityHandler());
handlers.addHandler(rtgovUI);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.overlord.rtgov.ui.server.services.impl;

import java.io.OutputStream;
import java.util.Collections;

import javax.enterprise.context.ApplicationScoped;
Expand Down Expand Up @@ -192,4 +193,9 @@ public void updateResolutionState(String situationId,
ResolutionState resolutionState) throws UiException {
_provider.updateResolutionState(situationId, resolutionState);
}

@Override
public void export(SituationsFilterBean situationsFilterBean, OutputStream outputStream) {
_provider.export(situationsFilterBean, outputStream);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import javax.enterprise.context.Dependent;
import javax.inject.Inject;

import org.jboss.errai.bus.client.ErraiBus;
import org.jboss.errai.bus.client.api.base.MessageBuilder;
import org.jboss.errai.bus.client.api.messaging.Message;
import org.jboss.errai.bus.client.api.messaging.MessageCallback;
import org.jboss.errai.ui.nav.client.local.Page;
Expand Down Expand Up @@ -55,6 +57,8 @@
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.http.client.UrlBuilder;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Button;

Expand Down Expand Up @@ -89,6 +93,10 @@ public class SituationsPage extends AbstractPage {
@Inject
@DataField
protected Button retrySituations;
@Inject
@DataField
protected Button exportSituations;

private boolean applyActionToFilteredRowsOnly = true;

@Inject @DataField("btn-refresh")
Expand Down Expand Up @@ -360,4 +368,16 @@ public void doOnComplete(RpcResult<BatchRetryResult> result) {
});
}

@EventHandler("exportSituations")
public void onExportClick(ClickEvent event) {
SituationsFilterBean situationsFilterBean = applyActionToFilteredRowsOnly ? filtersPanel.getValue()
: new SituationsFilterBean();
String exportKey = String.valueOf(System.currentTimeMillis());
MessageBuilder.createMessage().toSubject("situations/export").with("exportKey", exportKey)
.with("exportFilter", situationsFilterBean).noErrorHandling().sendNowWith(ErraiBus.get());
UrlBuilder urlBuilder = Window.Location.createUrlBuilder();
String exportLocation = urlBuilder.setPath("rtgov-ui/situations/export")
.setParameter("_k", exportKey).buildString();
Window.open(exportLocation, "_blank", "");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package org.overlord.rtgov.ui.server.services;

import java.io.OutputStream;

import org.jboss.errai.bus.server.annotations.Remote;
import org.overlord.rtgov.ui.client.model.BatchRetryResult;
import org.overlord.rtgov.ui.client.model.ResolutionState;
Expand Down Expand Up @@ -86,4 +88,10 @@ public SituationResultSetBean search(SituationsFilterBean filters, int page, Str
*/
BatchRetryResult resubmit(SituationsFilterBean situationsFilterBean) throws UiException;

/**
* Export the content of all message's matching the given filter criteria.
* @param situationsFilterBean
*/
void export(SituationsFilterBean situationsFilterBean, OutputStream outputStream);

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import static java.lang.System.currentTimeMillis;
import static org.overlord.rtgov.ui.client.model.ResolutionState.RESOLVED;

import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
Expand Down Expand Up @@ -403,5 +405,21 @@ public BatchRetryResult resubmit(SituationsFilterBean situationsFilterBean) {
return batchRetryResult;
}

@Override
public void export(SituationsFilterBean situationsFilterBean, OutputStream outputStream) {
String situationId = idToSituation.keySet().iterator().next();
PrintWriter printWriter = new PrintWriter(outputStream);
try {
SituationBean situationBean = get(situationId);
printWriter.println(situationBean.getMessage().getContent());
} catch (UiException e) {
e.printStackTrace();
} finally {
if (null != printWriter) {
printWriter.close();
}
}
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package org.overlord.rtgov.ui.server.servlet;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;

import javax.inject.Inject;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.jboss.errai.bus.client.api.messaging.Message;
import org.jboss.errai.bus.client.api.messaging.MessageBus;
import org.jboss.errai.bus.client.api.messaging.MessageCallback;
import org.overlord.rtgov.ui.client.model.SituationsFilterBean;
import org.overlord.rtgov.ui.server.services.ISituationsServiceImpl;

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;

/**
* Used to export the message content of filtered Situations.
*/
public class SituationsExportServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private static final String DATE_TIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss";
@Inject
private ISituationsServiceImpl situationsServiceImpl;
private MessageBus messageBus;
private Cache<String, SituationsFilterBean> exportFilterCache = CacheBuilder.newBuilder()
.expireAfterWrite(1, TimeUnit.MINUTES).expireAfterAccess(1, TimeUnit.SECONDS)
.<String, SituationsFilterBean> build();

/**
* @param messageBus
* the messageBus to set
*/
@Inject
public void setMessageBus(MessageBus messageBus) {
this.messageBus = messageBus;
this.messageBus.subscribe("situations/export", new MessageCallback() {
@Override
public void callback(Message message) {
String exportKey = message.get(String.class, "exportKey");
SituationsFilterBean exportFilter = message.get(SituationsFilterBean.class, "exportFilter");
exportFilterCache.put(exportKey, exportFilter);
}
});
}

@Override
protected void doGet(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse)
throws ServletException, IOException {
httpServletResponse.setContentType("text/plain");
httpServletResponse.setHeader("Content-Disposition", "attachment; filename=situations_export_"
+ new SimpleDateFormat(DATE_TIME_FORMAT).format(new Date()) + ".txt");
String exportKey = httpServletRequest.getParameter("_k");
SituationsFilterBean situationsFilterBean = exportFilterCache.getIfPresent(exportKey);
if (situationsFilterBean != null) {
situationsServiceImpl.export(situationsFilterBean, httpServletResponse.getOutputStream());
}
}

}
9 changes: 9 additions & 0 deletions overlord-rtgov-ui-war/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@
<servlet-name>ErraiServlet</servlet-name>
<url-pattern>*.erraiBus</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>SituationsExportServlet</servlet-name>
<servlet-class>org.overlord.rtgov.ui.server.servlet.SituationsExportServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>SituationsExportServlet</servlet-name>
<url-pattern>/situations/export</url-pattern>
</servlet-mapping>
<resource-env-ref>
<description>Object factory for the CDI Bean Manager</description>
<resource-env-ref-name>BeanManager</resource-env-ref-name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package org.overlord.rtgov.ui.provider;

import java.io.OutputStream;

import org.overlord.rtgov.ui.client.model.BatchRetryResult;
import org.overlord.rtgov.ui.client.model.MessageBean;
import org.overlord.rtgov.ui.client.model.ResolutionState;
Expand Down Expand Up @@ -77,7 +79,16 @@ public interface SituationsProvider {
* @throws UiException
*/
public void resubmit(String situationId, MessageBean message) throws UiException;


/**
* This method export all situation's matching the given filter criteria
*
* @param situationsFilterBean
* @param outputStream
* Failed to search situations
*/
public void export(SituationsFilterBean situationsFilterBean, OutputStream outputStream);

/**
* This method resubmits all situation's matching the given filter criteria
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import static com.google.common.collect.Iterables.any;
import static com.google.common.collect.Iterables.tryFind;

import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -537,6 +539,31 @@ public BatchRetryResult resubmit(SituationsFilterBean situationsFilterBean) thro
return new BatchRetryResult(processedCount, failedCount, ignoredCount);
}


@Override
public void export(SituationsFilterBean situationsFilterBean, OutputStream outputStream) {
List<Situation> situationIdToactivityTypeIds = _situationStore
.getSituations(createQuery(situationsFilterBean));
PrintWriter printWriter = new PrintWriter(outputStream);
try {
for (Situation situation : situationIdToactivityTypeIds) {
MessageBean message = getMessage(situation);
if (message == null) {
continue;
}
printWriter.println(message.getContent());

}
} catch (UiException uiException) {
Throwables.propagate(uiException);
} finally {
if (null != printWriter) {
printWriter.close();
}
}

}

/**
* {@inheritDoc}
*/
Expand Down