Ejemplo n.º 1
0
  protected void init() {
    super.init();

    // populate grid
    for (LinPos p : grid.getLinGrid()) {
      grid.set(p.i, new Square());
    }

    {
      Block block = new Block().setPos(2.3f, 3);
      blocks.add(block);
    }
    {
      follower = new Follower();
      follower.textureRegion = T.blockTextureRegion.get(4);
      follower.setPos(8f, 3);
      blocks.add(follower);
    }
    {
      Slider slider = new Slider();
      slider.textureRegion = T.blockTextureRegion.get(3);
      slider.setPos(5, 6.4f);
      slider.target.set(5, 6);
      blocks.add(slider);
    }

    {
      Slider slider = new Slider();
      slider.textureRegion = T.blockTextureRegion.get(3);
      slider.setPos(5, 6.4f);
      slider.target.set(2, 6);
      blocks.add(slider);
    }
  }
 @Override
 public Object Interpret(Object input) throws SFPL_RuntimeException {
   List<Object> lin = Caster.makeBunch(input);
   double attack = Caster.makeDouble(lin.get(1));
   double release = Caster.makeDouble(lin.get(2));
   SFSignal signal = Caster.makeSFSignal(lin.get(0));
   Follower fol = new Follower(attack, release);
   SFSignal ret = signal.replicateEmpty();
   for (int index = 0; index < signal.getLength(); ++index) {
     ret.setSample(index, fol.step(signal.getSample(index)));
   }
   return ret;
 }
Ejemplo n.º 3
0
 private void deleteCellsAtTimestamps(
     TransactionManager txManager,
     String tableName,
     Multimap<Cell, Long> cellToTimestamp,
     Transaction.TransactionType transactionType) {
   if (!cellToTimestamp.isEmpty()) {
     for (Follower follower : followers) {
       follower.run(txManager, tableName, cellToTimestamp.keySet(), transactionType);
     }
     keyValueService.addGarbageCollectionSentinelValues(tableName, cellToTimestamp.keySet());
     keyValueService.delete(tableName, cellToTimestamp);
   }
 }
Ejemplo n.º 4
0
 @Override
 public Long getKey(Follower entity) {
   if (entity != null) {
     return entity.getId();
   } else {
     return null;
   }
 }
Ejemplo n.º 5
0
  @Override
  protected final void bindValues(DatabaseStatement stmt, Follower entity) {
    stmt.clearBindings();

    Long id = entity.getId();
    if (id != null) {
      stmt.bindLong(1, id);
    }
    stmt.bindString(2, entity.getUid());
    stmt.bindString(3, entity.getTid());
    stmt.bindString(4, entity.getName());

    String pinyinName = entity.getPinyinName();
    if (pinyinName != null) {
      stmt.bindString(5, pinyinName);
    }

    String gender = entity.getGender();
    if (gender != null) {
      stmt.bindString(6, gender);
    }

    String description = entity.getDescription();
    if (description != null) {
      stmt.bindString(7, description);
    }

    String avatar = entity.getAvatar();
    if (avatar != null) {
      stmt.bindString(8, avatar);
    }

    Integer verified = entity.getVerified();
    if (verified != null) {
      stmt.bindLong(9, verified);
    }

    Integer verifiedType = entity.getVerifiedType();
    if (verifiedType != null) {
      stmt.bindLong(10, verifiedType);
    }

    Integer following = entity.getFollowing();
    if (following != null) {
      stmt.bindLong(11, following);
    }

    Integer followMe = entity.getFollowMe();
    if (followMe != null) {
      stmt.bindLong(12, followMe);
    }
  }
Ejemplo n.º 6
0
 @Override
 public boolean hasKey(Follower entity) {
   return entity.getId() != null;
 }
Ejemplo n.º 7
0
 @Override
 protected final Long updateKeyAfterInsert(Follower entity, long rowId) {
   entity.setId(rowId);
   return rowId;
 }
Ejemplo n.º 8
0
 @Override
 public void readEntity(Cursor cursor, Follower entity, int offset) {
   entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
   entity.setUid(cursor.getString(offset + 1));
   entity.setTid(cursor.getString(offset + 2));
   entity.setName(cursor.getString(offset + 3));
   entity.setPinyinName(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
   entity.setGender(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
   entity.setDescription(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6));
   entity.setAvatar(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7));
   entity.setVerified(cursor.isNull(offset + 8) ? null : cursor.getInt(offset + 8));
   entity.setVerifiedType(cursor.isNull(offset + 9) ? null : cursor.getInt(offset + 9));
   entity.setFollowing(cursor.isNull(offset + 10) ? null : cursor.getInt(offset + 10));
   entity.setFollowMe(cursor.isNull(offset + 11) ? null : cursor.getInt(offset + 11));
 }
Ejemplo n.º 9
0
 @Override
 protected final void attachEntity(Follower entity) {
   super.attachEntity(entity);
   entity.__setDaoSession(daoSession);
 }
Ejemplo n.º 10
0
/** Created by eduardkhodoyan on 11/2/15. */
public class PostControllerTest {

  public static final String TEST_URL = Shared.TEST_URL;

  public static final SignupUser admin =
      SignupUser.makeUser(
          "admin",
          "pass",
          true,
          "admin_firstname",
          "admin_lastname",
          1,
          "admin_medical1",
          "admin_userpic1",
          SignupUser.Role.ADMIN);

  public static final SignupUser testUser0 =
      SignupUser.makeUser(
          "user0",
          "password0",
          true,
          "user0_firstname",
          "user0_lastname",
          1,
          "user0_medical1",
          "user0_userpic1",
          SignupUser.Role.PATIENT);

  public static final SignupUser testUser1 =
      SignupUser.makeUser(
          "user1",
          "password1",
          true,
          "user1_firstname",
          "user1_lastname",
          1,
          "user1_medical1",
          "user1_userpic1",
          SignupUser.Role.FOLLOWER);

  public static final Relation testRelation0 =
      new Relation(
          testUser1.getUsername(),
          testUser0.getUsername(),
          false, // isConfirmed
          true, // isFollowed
          true, // shareFeeling
          true, // shareBloodSugar
          true, // shareInsulin
          true // shareQuestionnaire
          );

  public static final Relation testRelation1 =
      new Relation(
          testUser0.getUsername(),
          testUser1.getUsername(),
          false, // isConfirmed
          true, // isFollowed
          true, // shareFeeling
          true, // shareBloodSugar
          true, // shareInsulin
          true // shareQuestionnaire
          );

  public static final Follower testFollower0 =
      Follower.makeFollower(testUser0.toUser(), testRelation0, false);
  public static final Follower testFollower1 =
      Follower.makeFollower(testUser1.toUser(), testRelation1, false);

  UserControllerTestServiceApi userServiceApi =
      new SecuredRestBuilder()
          .setClient(new ApacheClient())
          .setEndpoint(TEST_URL)
          .setLoginEndpoint(TEST_URL + OAuth2Configuration.TOKEN_PATH)
          .setClientId("mobile")
          .setUsername("admin")
          .setPassword("pass")
          .build()
          .create(UserControllerTestServiceApi.class);

  private FollowerControllerTestServiceApi getFollowerServiceApi(String username, String password) {
    return new SecuredRestBuilder()
        .setClient(new ApacheClient())
        .setEndpoint(TEST_URL)
        .setLoginEndpoint(TEST_URL + OAuth2Configuration.TOKEN_PATH)
        .setClientId("mobile")
        .setUsername(username)
        .setPassword(password)
        .build()
        .create(FollowerControllerTestServiceApi.class);
  }

  private PostControllerTestServiceApi getPostServiceApi(String username, String password) {
    return new SecuredRestBuilder()
        .setClient(new ApacheClient())
        .setEndpoint(TEST_URL)
        .setLoginEndpoint(TEST_URL + OAuth2Configuration.TOKEN_PATH)
        .setClientId("mobile")
        .setUsername(username)
        .setPassword(password)
        .build()
        .create(PostControllerTestServiceApi.class);
  }

  public static final Post[] posts =
      new Post[] {
        new Post(
            testUser1.getUsername(), // this.username = username;
            0, // this.updatedAt = updatedAt;
            0, // this.deletedAt = deletedAt;
            new java.util.Date().getTime(), // this.timestamp = timestamp;
            true, // this.isShared = isShared;
            Post.Feeling.GOOD, // this.feeling = feeling;
            1f, // this.bloodSugar = bloodSugar;
            true, // this.administeredInsulin = administeredInsulin;
            null // this.questionnaire = questionnaire;
            ),
        new Post(
            testUser1.getUsername(), // this.username = username;
            0, // this.updatedAt = updatedAt;
            0, // this.deletedAt = deletedAt;
            new java.util.Date().getTime(), // this.timestamp = timestamp;
            true, // this.isShared = isShared;
            Post.Feeling.GOOD, // this.feeling = feeling;
            2f, // this.bloodSugar = bloodSugar;
            true, // this.administeredInsulin = administeredInsulin;
            null // this.questionnaire = questionnaire;
            ),
        new Post(
            testUser1.getUsername(), // this.username = username;
            0, // this.updatedAt = updatedAt;
            0, // this.deletedAt = deletedAt;
            new java.util.Date().getTime(), // this.timestamp = timestamp;
            true, // this.isShared = isShared;
            Post.Feeling.GOOD, // this.feeling = feeling;
            3f, // this.bloodSugar = bloodSugar;
            true, // this.administeredInsulin = administeredInsulin;
            null // this.questionnaire = questionnaire;
            )
      };

  @Before
  public void initiate() {
    PostControllerTestServiceApi postService =
        getPostServiceApi(admin.getUsername(), admin.getPassword());
    postService.deleteAll();
    if (userServiceApi.getUser(testUser0.getUsername()) == null) userServiceApi.signup(testUser0);
    if (userServiceApi.getUser(testUser1.getUsername()) == null) userServiceApi.signup(testUser1);
    FollowerControllerTestServiceApi followerService =
        getFollowerServiceApi(testUser0.getUsername(), testUser0.getPassword());
    followerService.add(testFollower1);
  }

  @After
  public void finish() {
    FollowerControllerTestServiceApi followerService =
        getFollowerServiceApi(testUser0.getUsername(), testUser0.getPassword());
    followerService.delete(testUser1.getUsername());
    userServiceApi.delete(testUser0.getUsername());
    userServiceApi.delete(testUser1.getUsername());

    PostControllerTestServiceApi postService =
        getPostServiceApi(admin.getUsername(), admin.getPassword());
    postService.deleteAll();
  }

  @Test
  public void addPostTest() {
    PostControllerTestServiceApi service0 =
        getPostServiceApi(testUser0.getUsername(), testUser0.getPassword());
    PostControllerTestServiceApi service1 =
        getPostServiceApi(testUser1.getUsername(), testUser1.getPassword());

    // publish post as user1 and check it is okay
    Post post = service1.add(posts[1]);
    assertPostNoId(posts[1], post);

    // get post as user1 and check it is okay
    ArrayList<Post> postsList;
    postsList = service1.getByUser(testUser1.getUsername());
    assertPostNoId(posts[1], postsList.get(0));

    // try to get post as user0. Check you do not get it. There is no confirmed connection
    // postsList = service0.getByUser(testUser1.getUsername());
    // assertEquals(0, postsList.size());

    // confirm relation, get post, check you got it
    FollowerControllerTestServiceApi followerService1 =
        getFollowerServiceApi(testUser1.getUsername(), testUser1.getPassword());
    followerService1.confirm(
        testUser0.getUsername(), new FollowSettings(true, true, true, true, true));
    postsList = service0.getByUser(testUser1.getUsername());
    assertPostNoId(posts[1], postsList.get(0));
    long id = postsList.get(0).getId();
    service1.delete(id);
  }

  @Test
  public void addPostsBulkTest() {
    PostControllerTestServiceApi service0 =
        getPostServiceApi(testUser0.getUsername(), testUser0.getPassword());
    ArrayList<Post> addedPosts = service0.addBulk(new ArrayList<>(Arrays.asList(posts)));
    assertEquals(posts.length, addedPosts.size());
  }

  @Test
  public void getAllTest() {
    PostControllerTestServiceApi service0 =
        getPostServiceApi(testUser0.getUsername(), testUser0.getPassword());
    PostControllerTestServiceApi service1 =
        getPostServiceApi(testUser1.getUsername(), testUser1.getPassword());
    service1.addBulk(new ArrayList<>(Arrays.asList(posts)));

    // check you can see own posts
    ArrayList<Post> addedPosts = service1.getAll();
    assertPostsNoId(posts, addedPosts);

    // check you can't see other's posts without confirmation
    addedPosts = service0.getAll();
    assertEquals(0, addedPosts.size());

    // confirm relation and check you can see posts and only the part, which is allowed by patient
    FollowerControllerTestServiceApi followerService1 =
        getFollowerServiceApi(testUser1.getUsername(), testUser1.getPassword());
    followerService1.confirm(
        testUser0.getUsername(), new FollowSettings(true, false, true, false, true));
    addedPosts = service0.getAll();
    assertEquals(3, addedPosts.size());

    for (int i = 0; i < addedPosts.size(); i++) {
      assertEquals(null, addedPosts.get(i).getFeeling());
      assertEquals(false, addedPosts.get(i).getAdministeredInsulin());
      assertEquals(posts[i].getBloodSugar(), addedPosts.get(i).getBloodSugar(), 0.01);
      assertEquals(posts[i].getQuestionnaire(), addedPosts.get(i).getQuestionnaire());
    }
  }

  @Test
  public void getPageTest() {
    // generate large set of data
    Post[] largeTestSet = new Post[100];
    for (int i = 0; i < 100; i++) {
      largeTestSet[i] = new Post(testUser1.getUsername(), 0, 0, 0, true, null, i * 1f, false, null);
    }

    // add posts
    PostControllerTestServiceApi service1 =
        getPostServiceApi(testUser1.getUsername(), testUser1.getPassword());
    service1.addBulk(new ArrayList<>(Arrays.asList(largeTestSet)));

    // get page and check number of items
    ArrayList<Post> page0 = service1.getPage(0);
    assertEquals(PostController.PAGE_SIZE, page0.size());
  }

  @Test
  public void getBloodSugarByUsername() {
    PostControllerTestServiceApi service1 =
        getPostServiceApi(testUser1.getUsername(), testUser1.getPassword());
    for (Post post : posts) service1.add(post);

    ArrayList<BloodSugar> result = service1.getBloodSugarByUser(testUser1.getUsername());

    for (int i = 0; i < posts.length; i++) {
      assertEquals(posts[i].getBloodSugar(), result.get(i).getBloodSugar(), 0.01);
    }
  }

  private void assertPostNoId(Post expected, Post actual) {
    if (expected == null || actual == null) assertEquals(expected, actual);
    else {
      assertEquals(expected.getUsername(), actual.getUsername()); // this.username = username;
      assertEquals(expected.getUpdatedAt(), actual.getUpdatedAt()); // this.updatedAt = updatedAt;
      assertEquals(expected.getDeletedAt(), actual.getDeletedAt()); // this.deletedAt = deletedAt;
      // assertEquals(expected.getTimestamp(), actual.getTimestamp()); // this.timestamp =
      // timestamp;
      assertEquals(expected.getIsShared(), actual.getIsShared()); // this.isShared = isShared;
      assertEquals(expected.getFeeling(), actual.getFeeling()); // this.feeling = feeling;
      assertEquals(
          expected.getBloodSugar(), actual.getBloodSugar(), 0.1f); // this.bloodSugar = bloodSugar;
      assertEquals(
          expected.getAdministeredInsulin(),
          actual.getAdministeredInsulin()); // this.administeredInsulin = administeredInsulin;
      assertEquals(
          expected.getQuestionnaire(),
          actual.getQuestionnaire()); // this.questionnaire = questionnaire;
    }
  }

  private void assertPostsNoId(Post[] expected, ArrayList<Post> actual) {
    for (int i = 0; i < posts.length; i++) {
      assertPostNoId(expected[i], actual.get(i));
    }
  }
}