refs 2251: Accounting Manager - Stacked column chart for tops

https://support.d4science.org/issues/2251

Added AccountingPeriod to FilterValueRequet

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/admin/accounting-manager@128727 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2016-05-20 08:58:56 +00:00
parent cc14eedb92
commit c564be1044
6 changed files with 229 additions and 18 deletions

View File

@ -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" <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class AccountingPeriodEvent extends
GwtEvent<AccountingPeriodEvent.AccountingPeriodEventHandler> {
public static Type<AccountingPeriodEventHandler> TYPE = new Type<AccountingPeriodEventHandler>();
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<AccountingPeriodEventHandler> getAssociatedType() {
return TYPE;
}
public static Type<AccountingPeriodEventHandler> 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
+ "]";
}
}

View File

@ -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" <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class AccountingPeriodRequestEvent
extends
GwtEvent<AccountingPeriodRequestEvent.AccountingPeriodRequestEventHandler> {
public static Type<AccountingPeriodRequestEventHandler> TYPE = new Type<AccountingPeriodRequestEventHandler>();
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<AccountingPeriodRequestEventHandler> getAssociatedType() {
return TYPE;
}
public static Type<AccountingPeriodRequestEventHandler> getType() {
return TYPE;
}
public static void fire(HasHandlers source,
AccountingPeriodRequestEvent event) {
source.fireEvent(event);
}
@Override
public String toString() {
return "AccountingPeriodRequestEvent []";
}
}

View File

@ -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(

View File

@ -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<FilterKey> {
@ -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<AccountingFilter> event) {
GridCell cell = event.getEditCell();

View File

@ -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<ArrayList<FilterValue>> {
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<Filter> filters = new ArrayList<>();
switch (filterValuesRequest.getAccountingType()) {

View File

@ -4,8 +4,8 @@ import java.io.Serializable;
/**
*
* @author giancarlo
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
* @author giancarlo email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
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 + "]";
}
}