Package org.yaac.server.service

Source Code of org.yaac.server.service.MockStatisticsService

package org.yaac.server.service;

import java.util.Date;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.yaac.client.service.StatisticsService;
import org.yaac.shared.stat.StatDTO;
import org.yaac.shared.stat.StatDTO.KindWrapper;
import org.yaac.shared.stat.models.Kind;
import org.yaac.shared.stat.models.KindIsRootEntity;
import org.yaac.shared.stat.models.KindNonRootEntity;
import org.yaac.shared.stat.models.NSPropertyTypePropertyNameKind;
import org.yaac.shared.stat.models.NSTotal;
import org.yaac.shared.stat.models.PropertyType;
import org.yaac.shared.stat.models.Total;

/**
* since we don't have datastore statistics in local environment,
* this mock service will mock a set of statistics 
*
* @author Max Zhu (thebbsky@gmail.com)
*
*/
public class MockStatisticsService implements StatisticsService {

  @Override
  public StatDTO loadStat() {
    Date timestamp = new Date();
 
    Total total = new Total(1000L, 10L, timestamp);

    Map<String, Iterable<KindWrapper>> kindsMap = new HashMap<String, Iterable<KindWrapper>>();
   
    {
      List<KindWrapper> kinds = new LinkedList<KindWrapper>();
     
      {
        KindWrapper kind = new KindWrapper();
        kind.setKind(new Kind(500L, 5L, timestamp, "Kind_A"));
        kind.setNonRootKind(new KindNonRootEntity(400L, 3L, timestamp, "Kind_A"));
        kind.setRootKind(new KindIsRootEntity(100L, 2L, timestamp, "Kind_A"));
        kinds.add(kind);
      }
     
      {
        KindWrapper kind = new KindWrapper();
        kind.setKind(new Kind(400L, 3L, timestamp, "Kind_B"));
        kind.setNonRootKind(new KindNonRootEntity(400L, 3L, timestamp, "Kind_B"));
        kinds.add(kind);
      }
     
      {
        KindWrapper kind = new KindWrapper();
        kind.setKind(new Kind(100L, 2L, timestamp, "Kind_C"));
        kind.setRootKind(new KindIsRootEntity(100L, 2L, timestamp, "Kind_C"));
        kinds.add(kind);
      }
     
      kindsMap.put("", kinds);
    }
   
    {
      List<KindWrapper> kinds = new LinkedList<KindWrapper>();
     
      {
        KindWrapper kind = new KindWrapper();
        kind.setKind(new Kind(5000L, 42L, timestamp, "Kind_A"));
        kind.setNonRootKind(new KindNonRootEntity(4000L, 30L, timestamp, "Kind_A"));
        kind.setRootKind(new KindIsRootEntity(1000L, 12L, timestamp, "Kind_A"));
        kinds.add(kind);
      }
     
      {
        KindWrapper kind = new KindWrapper();
        kind.setKind(new Kind(50000L, 300L, timestamp, "Kind_B"));
        kind.setNonRootKind(new KindNonRootEntity(50000L, 300L, timestamp, "Kind_B"));
        kinds.add(kind);
      }
     
      kindsMap.put("namespace_A", kinds);
    }
   
   
    Map<String, Iterable<NSPropertyTypePropertyNameKind>> propMap =
      new HashMap<String, Iterable<NSPropertyTypePropertyNameKind>>();
   
    {
      List<NSPropertyTypePropertyNameKind> props = new LinkedList<NSPropertyTypePropertyNameKind>();
     
      props.add(new NSPropertyTypePropertyNameKind(1000L, 10L, timestamp, "Kind_A", "Prop_A", "INT"));
      props.add(new NSPropertyTypePropertyNameKind(2000L, 20L, timestamp, "Kind_A", "Prop_A", "COMPLEX"));
     
      props.add(new NSPropertyTypePropertyNameKind(2000L, 20L, timestamp, "Kind_B", "Prop_A", "INT"));
      props.add(new NSPropertyTypePropertyNameKind(2000L, 20L, timestamp, "Kind_B", "Prop_B", "INT"));
      props.add(new NSPropertyTypePropertyNameKind(2000L, 20L, timestamp, "Kind_B", "Prop_C", "INT"));
     
      propMap.put("", props);
    }
   
    {
      List<NSPropertyTypePropertyNameKind> props = new LinkedList<NSPropertyTypePropertyNameKind>();
     
      props.add(new NSPropertyTypePropertyNameKind(2000L, 10L, timestamp, "Kind_A", "Prop_A", "INT"));
      props.add(new NSPropertyTypePropertyNameKind(3000L, 20L, timestamp, "Kind_A", "Prop_A", "COMPLEX"));
     
      props.add(new NSPropertyTypePropertyNameKind(4000L, 20L, timestamp, "Kind_B", "Prop_A", "INT"));
      props.add(new NSPropertyTypePropertyNameKind(5000L, 20L, timestamp, "Kind_B", "Prop_B", "INT"));
      props.add(new NSPropertyTypePropertyNameKind(6000L, 20L, timestamp, "Kind_B", "Prop_C", "INT"));
     
      propMap.put("namespace_A", props);
    }
   
    return new StatDTO(total, kindsMap, propMap);
  }

  @SuppressWarnings("unused")
  private StatDTO oldVersionMockData() {
    Date timestamp = new Date();
   
    Total total = new Total(1000L, 10L, timestamp);
   
    Map<String, NSTotal> nsTotalsMap = new HashMap<String, NSTotal>();
    nsTotalsMap.put("", new NSTotal(500L, 3L, new Date()));
    nsTotalsMap.put("namespace_1", new NSTotal(200L, 3L, timestamp));
    nsTotalsMap.put("namespace_2", new NSTotal(300L, 4L, timestamp));

    List<PropertyType> propertyTypes = new LinkedList<PropertyType>();
    propertyTypes.add(new PropertyType(200L, 10L, timestamp, "Date/Time"));
    propertyTypes.add(new PropertyType(200L, 10L, timestamp, "Integer"));
    propertyTypes.add(new PropertyType(200L, 10L, timestamp, "String"));
    propertyTypes.add(new PropertyType(200L, 10L, timestamp, "Float"));
    propertyTypes.add(new PropertyType(200L, 10L, timestamp, "Category"));
   
    List<KindWrapper> kinds = new LinkedList<KindWrapper>();
   
    {
      KindWrapper kind = new KindWrapper();
      kind.setKind(new Kind(500L, 5L, timestamp, "Kind_A"));
      kind.setNonRootKind(new KindNonRootEntity(400L, 3L, timestamp, "Kind_A"));
      kind.setRootKind(new KindIsRootEntity(100L, 2L, timestamp, "Kind_A"));
      kinds.add(kind);
    }
   
    {
      KindWrapper kind = new KindWrapper();
      kind.setKind(new Kind(400L, 3L, timestamp, "Kind_B"));
      kind.setNonRootKind(new KindNonRootEntity(400L, 3L, timestamp, "Kind_B"));
      kinds.add(kind);
    }
   
    {
      KindWrapper kind = new KindWrapper();
      kind.setKind(new Kind(100L, 2L, timestamp, "Kind_C"));
      kind.setRootKind(new KindIsRootEntity(100L, 2L, timestamp, "Kind_C"));
      kinds.add(kind);
    }
   
//    return new StatDTO(total, nsTotalsMap, propertyTypes, kinds);
    return null;
  }
}
TOP

Related Classes of org.yaac.server.service.MockStatisticsService

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.