diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/client/event/AccountingPeriodEvent.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/event/AccountingPeriodEvent.java
new file mode 100644
index 0000000..001bb54
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/event/AccountingPeriodEvent.java
@@ -0,0 +1,64 @@
+package org.gcube.portlets.admin.accountingmanager.client.event;
+
+import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingPeriod;
+
+import com.google.gwt.event.shared.EventHandler;
+import com.google.gwt.event.shared.GwtEvent;
+import com.google.gwt.event.shared.HandlerRegistration;
+import com.google.gwt.event.shared.HasHandlers;
+
+/**
+ * Accounting Period Request Event
+ *
+ * @author "Giancarlo Panichi" g.panichi@isti.cnr.it
+ *
+ */
+public class AccountingPeriodEvent extends
+ GwtEvent {
+
+ public static Type TYPE = new Type();
+ private AccountingPeriod accountingPeriod;
+
+ public interface AccountingPeriodEventHandler extends EventHandler {
+ void onPeriod(AccountingPeriodEvent event);
+ }
+
+ public interface HasAccountingPeriodEventHandler extends HasHandlers {
+ public HandlerRegistration addAccountingPeriodEventHandler(
+ AccountingPeriodEventHandler handler);
+ }
+
+ public AccountingPeriodEvent(AccountingPeriod accountingPeriod) {
+ this.accountingPeriod = accountingPeriod;
+ }
+
+ @Override
+ protected void dispatch(AccountingPeriodEventHandler handler) {
+ handler.onPeriod(this);
+ }
+
+ @Override
+ public Type getAssociatedType() {
+ return TYPE;
+ }
+
+ public static Type getType() {
+ return TYPE;
+ }
+
+ public static void fire(HasHandlers source, AccountingPeriodEvent event) {
+ source.fireEvent(event);
+ }
+
+ public AccountingPeriod getAccountingPeriod() {
+ return accountingPeriod;
+ }
+
+ @Override
+ public String toString() {
+ return "AccountingPeriodEvent [accountingPeriod=" + accountingPeriod
+ + "]";
+ }
+
+}
diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/client/event/AccountingPeriodRequestEvent.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/event/AccountingPeriodRequestEvent.java
new file mode 100644
index 0000000..6c8e86d
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/event/AccountingPeriodRequestEvent.java
@@ -0,0 +1,57 @@
+package org.gcube.portlets.admin.accountingmanager.client.event;
+
+import com.google.gwt.event.shared.EventHandler;
+import com.google.gwt.event.shared.GwtEvent;
+import com.google.gwt.event.shared.HandlerRegistration;
+import com.google.gwt.event.shared.HasHandlers;
+
+/**
+ * Accounting Period Request Event
+ *
+ * @author "Giancarlo Panichi" g.panichi@isti.cnr.it
+ *
+ */
+public class AccountingPeriodRequestEvent
+ extends
+ GwtEvent {
+
+ public static Type TYPE = new Type();
+
+ public interface AccountingPeriodRequestEventHandler extends EventHandler {
+ void onRequest(AccountingPeriodRequestEvent event);
+ }
+
+ public interface HasAccountingPeriodRequestEventHandler extends HasHandlers {
+ public HandlerRegistration addAccountingPeriodRequestEventHandler(
+ AccountingPeriodRequestEventHandler handler);
+ }
+
+ public AccountingPeriodRequestEvent() {
+ }
+
+ @Override
+ protected void dispatch(AccountingPeriodRequestEventHandler handler) {
+ handler.onRequest(this);
+ }
+
+ @Override
+ public Type getAssociatedType() {
+ return TYPE;
+ }
+
+ public static Type getType() {
+ return TYPE;
+ }
+
+ public static void fire(HasHandlers source,
+ AccountingPeriodRequestEvent event) {
+ source.fireEvent(event);
+ }
+
+ @Override
+ public String toString() {
+ return "AccountingPeriodRequestEvent []";
+ }
+
+}
diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/client/filters/AccountingPeriodPanel.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/filters/AccountingPeriodPanel.java
index 9d4277e..dc3f8b8 100644
--- a/src/main/java/org/gcube/portlets/admin/accountingmanager/client/filters/AccountingPeriodPanel.java
+++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/filters/AccountingPeriodPanel.java
@@ -2,6 +2,8 @@ package org.gcube.portlets.admin.accountingmanager.client.filters;
import java.util.Date;
+import org.gcube.portlets.admin.accountingmanager.client.event.AccountingPeriodEvent;
+import org.gcube.portlets.admin.accountingmanager.client.event.AccountingPeriodRequestEvent;
import org.gcube.portlets.admin.accountingmanager.client.event.StateChangeEvent;
import org.gcube.portlets.admin.accountingmanager.client.properties.AccountingPeriodModePropertiesCombo;
import org.gcube.portlets.admin.accountingmanager.client.utils.UtilsGXT3;
@@ -249,6 +251,28 @@ public class AccountingPeriodPanel extends SimpleContainer {
}
});
+
+ eventBus.addHandler(AccountingPeriodRequestEvent.TYPE,
+ new AccountingPeriodRequestEvent.AccountingPeriodRequestEventHandler() {
+
+ @Override
+ public void onRequest(AccountingPeriodRequestEvent event) {
+ Log.debug("Catch Event Accounting Period Request Event");
+ manageAccountingPeriodRequestEvent(event);
+
+
+ }
+ });
+
+
+ }
+
+ private void manageAccountingPeriodRequestEvent(
+ AccountingPeriodRequestEvent event) {
+ AccountingPeriod accountingPeriod=getAccountingPeriod();
+ AccountingPeriodEvent accountingPeriodEvent=new AccountingPeriodEvent(accountingPeriod);
+ eventBus.fireEvent(accountingPeriodEvent);
+
}
private void addHandlersForComboPeriodMode(
diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/client/filters/ActiveFiltersPanel.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/filters/ActiveFiltersPanel.java
index 240971e..be58755 100644
--- a/src/main/java/org/gcube/portlets/admin/accountingmanager/client/filters/ActiveFiltersPanel.java
+++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/client/filters/ActiveFiltersPanel.java
@@ -3,6 +3,8 @@ package org.gcube.portlets.admin.accountingmanager.client.filters;
import java.util.ArrayList;
import java.util.List;
+import org.gcube.portlets.admin.accountingmanager.client.event.AccountingPeriodEvent;
+import org.gcube.portlets.admin.accountingmanager.client.event.AccountingPeriodRequestEvent;
import org.gcube.portlets.admin.accountingmanager.client.event.SessionExpiredEvent;
import org.gcube.portlets.admin.accountingmanager.client.event.StateChangeEvent;
import org.gcube.portlets.admin.accountingmanager.client.properties.AccountingFilterProperties;
@@ -104,6 +106,9 @@ public class ActiveFiltersPanel extends SimpleContainer {
private ToolBar toolBar;
private IntegerSpinnerField topNumber;
private FieldLabel topNumberLabel;
+
+ private FilterKey filterKey;
+ private boolean cancelValue;
public interface FilterKeyPropertiesCombo extends PropertyAccess {
@@ -460,13 +465,25 @@ public class ActiveFiltersPanel extends SimpleContainer {
@Override
public void onStateChange(StateChangeEvent event) {
- Log.debug("Catch Event State Change");
+ Log.debug("Catch State Change Event");
doStateChangeCommand(event);
}
});
+
+ eventBus.addHandler(AccountingPeriodEvent.TYPE,
+ new AccountingPeriodEvent.AccountingPeriodEventHandler() {
+
+ @Override
+ public void onPeriod(AccountingPeriodEvent event) {
+ Log.debug("Catch Accounting Period Event");
+ manageAccountingPeriodEvent(event);
+
+ }
+ });
}
+
private void doStateChangeCommand(StateChangeEvent event) {
if (event.getStateChangeType() == null) {
return;
@@ -739,8 +756,22 @@ public class ActiveFiltersPanel extends SimpleContainer {
private void retrieveFilterValuesByKey(FilterKey filterKey,
final boolean cancelValue) {
+ this.filterKey=filterKey;
+ this.cancelValue=cancelValue;
+ AccountingPeriodRequestEvent event=new AccountingPeriodRequestEvent();
+ eventBus.fireEvent(event);
+
+ }
+
+
+ private void manageAccountingPeriodEvent(AccountingPeriodEvent event) {
+ if(event==null|| event.getAccountingPeriod()==null){
+ Log.debug("AccountingPeriod not valid");
+ return;
+ }
+
FilterValuesRequest requestFilterValue = new FilterValuesRequest(
- filterKey, accountingStateData.getAccountingType());
+ filterKey, accountingStateData.getAccountingType(), event.getAccountingPeriod());
AccountingManagerServiceAsync.INSTANCE.getFilterValues(
requestFilterValue,
@@ -776,6 +807,7 @@ public class ActiveFiltersPanel extends SimpleContainer {
}
});
}
+
private void editingBeforeStart(BeforeStartEditEvent event) {
GridCell cell = event.getEditCell();
diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/command/AccountingCommandGetFilterValues.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/command/AccountingCommandGetFilterValues.java
index 6a319f5..3d93442 100644
--- a/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/command/AccountingCommandGetFilterValues.java
+++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/server/amservice/command/AccountingCommandGetFilterValues.java
@@ -1,6 +1,9 @@
package org.gcube.portlets.admin.accountingmanager.server.amservice.command;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
import java.util.ArrayList;
+import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Set;
@@ -8,12 +11,12 @@ import java.util.Set;
import org.gcube.accounting.analytics.Filter;
import org.gcube.accounting.analytics.NumberedFilter;
import org.gcube.accounting.analytics.TemporalConstraint;
-import org.gcube.accounting.analytics.TemporalConstraint.AggregationMode;
import org.gcube.accounting.analytics.persistence.AccountingPersistenceQuery;
import org.gcube.accounting.analytics.persistence.AccountingPersistenceQueryFactory;
import org.gcube.accounting.datamodel.aggregation.AggregatedJobUsageRecord;
import org.gcube.accounting.datamodel.aggregation.AggregatedServiceUsageRecord;
import org.gcube.accounting.datamodel.aggregation.AggregatedStorageUsageRecord;
+import org.gcube.portlets.admin.accountingmanager.server.amservice.PeriodModeMap;
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValue;
import org.gcube.portlets.admin.accountingmanager.shared.data.FilterValuesRequest;
import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerServiceException;
@@ -30,7 +33,7 @@ public class AccountingCommandGetFilterValues implements
AccountingCommand> {
private static final Logger logger = LoggerFactory
.getLogger(AccountingCommandGetFilterValues.class);
-
+ private SimpleDateFormat sdf = new SimpleDateFormat("yyyy MMMMM dd");
private FilterValuesRequest filterValuesRequest;
public AccountingCommandGetFilterValues(
@@ -60,15 +63,37 @@ public class AccountingCommandGetFilterValues implements
.getInstance();
+ Calendar startCalendar = GregorianCalendar
+ .getInstance(TemporalConstraint.DEFAULT_TIME_ZONE);
+ try {
+ startCalendar.setTime(sdf.parse(filterValuesRequest.getAccountingPeriod()
+ .getStartDate()));
+ } catch (ParseException e) {
+ e.printStackTrace();
+ throw new AccountingManagerServiceException("Start Date not valid!");
+ }
- GregorianCalendar startDate = new GregorianCalendar();
- GregorianCalendar endDate = new GregorianCalendar();
- endDate.add(GregorianCalendar.YEAR, -3);
+ Calendar endCalendar = GregorianCalendar
+ .getInstance(TemporalConstraint.DEFAULT_TIME_ZONE);
+ try {
+ endCalendar.setTime(sdf.parse(filterValuesRequest.getAccountingPeriod()
+ .getEndDate()));
+ } catch (ParseException e) {
+ e.printStackTrace();
+ throw new AccountingManagerServiceException("End Date not valid!");
+ }
+
+ endCalendar.set(GregorianCalendar.HOUR_OF_DAY, 23);
+ endCalendar.set(GregorianCalendar.MINUTE, 59);
+ endCalendar.set(GregorianCalendar.SECOND, 59);
+ endCalendar.set(GregorianCalendar.MILLISECOND, 999);
TemporalConstraint tc = new TemporalConstraint(
- startDate.getTimeInMillis(), endDate.getTimeInMillis(),
- AggregationMode.YEARLY);
+ startCalendar.getTimeInMillis(), endCalendar.getTimeInMillis(),
+ PeriodModeMap.getMode(filterValuesRequest.getAccountingPeriod()
+ .getPeriod()));
+
List filters = new ArrayList<>();
switch (filterValuesRequest.getAccountingType()) {
diff --git a/src/main/java/org/gcube/portlets/admin/accountingmanager/shared/data/FilterValuesRequest.java b/src/main/java/org/gcube/portlets/admin/accountingmanager/shared/data/FilterValuesRequest.java
index 724f991..a752019 100644
--- a/src/main/java/org/gcube/portlets/admin/accountingmanager/shared/data/FilterValuesRequest.java
+++ b/src/main/java/org/gcube/portlets/admin/accountingmanager/shared/data/FilterValuesRequest.java
@@ -4,8 +4,8 @@ import java.io.Serializable;
/**
*
- * @author giancarlo
- * email: g.panichi@isti.cnr.it
+ * @author giancarlo email: g.panichi@isti.cnr.it
*
*/
public class FilterValuesRequest implements Serializable {
@@ -13,16 +13,18 @@ public class FilterValuesRequest implements Serializable {
private static final long serialVersionUID = -3544245558153491901L;
private FilterKey filterKey;
private AccountingType accountingType;
-
- public FilterValuesRequest(){
+ private AccountingPeriod accountingPeriod;
+
+ public FilterValuesRequest() {
super();
}
public FilterValuesRequest(FilterKey filterKey,
- AccountingType accountingType) {
+ AccountingType accountingType, AccountingPeriod accountingPeriod) {
super();
this.filterKey = filterKey;
this.accountingType = accountingType;
+ this.accountingPeriod = accountingPeriod;
}
public FilterKey getFilterKey() {
@@ -41,12 +43,19 @@ public class FilterValuesRequest implements Serializable {
this.accountingType = accountingType;
}
+ public AccountingPeriod getAccountingPeriod() {
+ return accountingPeriod;
+ }
+
+ public void setAccountingPeriod(AccountingPeriod accountingPeriod) {
+ this.accountingPeriod = accountingPeriod;
+ }
+
@Override
public String toString() {
return "FilterValuesRequest [filterKey=" + filterKey
- + ", accountingType=" + accountingType + "]";
+ + ", accountingType=" + accountingType + ", accountingPeriod="
+ + accountingPeriod + "]";
}
-
-
-
+
}