io.kaif.model.zone.ZoneInfo类的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(10.7k)|赞(0)|评价(0)|浏览(142)

本文整理了Java中io.kaif.model.zone.ZoneInfo类的一些代码示例,展示了ZoneInfo类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZoneInfo类的具体详情如下:
包路径:io.kaif.model.zone.ZoneInfo
类名称:ZoneInfo

ZoneInfo介绍

[英]Although authorities has lots of combination, but valid cases are:

  1. default -- CITIZEN allow: upVote, write, debate

  2. kaif -- CITIZEN allow: upVote, debate, zoneAdmin allow write

  3. kVoting -- CITIZEN allow: debate, SUFFRAGE allow upVote, zoneAdmins allow write

  4. vote -- CITIZEN allow: upVote, debate, zoneAdmins allow write

CITIZEN allow up/down vote on PEOPLE, regardless ZoneInfo settings
[中]虽然当局有很多组合,但有效的案例有:
1) 默认——公民允许:投票、写作、辩论
2) kaif——公民允许:投票、辩论、分区允许写作
3) 公民允许:辩论,选举权允许上升投票,分区允许写作
4) 投票——公民允许:投票、辩论、分区允许写
无论ZoneInfo设置如何,公民都允许对人进行上/下投票

代码示例

代码示例来源:origin: kaif-open/kaif

private ZoneInfo checkVoteAuthority(Zone zone, Authorization authorization) {
 // relax verification when voting, no check zone and account in Database because voting
 // is not critical
 ZoneInfo zoneInfo = zoneDao.loadZoneWithCache(zone);
 if (!zoneInfo.canUpVote(authorization)) {
  throw new AccessDeniedException("not allow vote in zone: " + zone + " auth:" + authorization);
 }
 return zoneInfo;
}

代码示例来源:origin: kaif-open/kaif

@Override
public ZoneInfo createByUser(String zone, String aliasName, Authorization creator)
  throws CreditNotEnoughException {
 Account account = verifyAuthority(creator).flatMap(this::verifyCredit).get();
 ZoneInfo zoneInfo = ZoneInfo.createDefault(zone, aliasName, Instant.now())
   .withAdmins(singletonList(account.getAccountId()));
 zoneDao.create(zoneInfo);
 return zoneInfo;
}

代码示例来源:origin: kaif-open/kaif

@Override
public ZoneInfo createKaif(String zone, String aliasName) {
 return zoneDao.create(ZoneInfo.createKaif(zone, aliasName, Instant.now()));
}

代码示例来源:origin: kaif-open/kaif

public V1ZoneDto toV1Dto() {
  return new V1ZoneDto(getName(), getAliasName());
 }
}

代码示例来源:origin: kaif-open/kaif

private void createZoneAdmin(ZoneInfo zoneInfo) {
 List<Object[]> batchArgs = zoneInfo.getAdminAccountIds()
   .stream()
   .map(uuid -> new Object[] { uuid, zoneInfo.getName(),
     Timestamp.from(zoneInfo.getCreateTime()) })
   .collect(toList());
 jdbc().batchUpdate(""
   + " INSERT "
   + "   INTO ZoneAdmin "
   + "        (accountId, zone, createTime) "
   + " VALUES "
   + questions(3), batchArgs);
}

代码示例来源:origin: kaif-open/kaif

@RequestMapping(value = "/all", method = RequestMethod.GET)
public List<ZoneDto> listCitizenZones() {
 return zoneService.listCitizenZones()
   .stream()
   .map(z -> new ZoneDto(z.getZone().value(), z.getAliasName()))
   .collect(toList());
}

代码示例来源:origin: kaif-open/kaif

@CacheEvict(value = "listAdministrators", key = "#a0.zone")
public ZoneInfo create(ZoneInfo zoneInfo) {
 jdbc().update(""
     + " INSERT "
     + "   INTO ZoneInfo "
     + "        (zone, aliasName, theme, voteAuthority, debateAuthority, writeAuthority, "
     + "         createTime, adminAccountIds, hideFromTop) "
     + " VALUES "
     + questions(9),
   zoneInfo.getZone().value(),
   zoneInfo.getAliasName(),
   zoneInfo.getTheme(),
   zoneInfo.getVoteAuthority().name(),
   zoneInfo.getDebateAuthority().name(),
   zoneInfo.getWriteAuthority().name(),
   Timestamp.from(zoneInfo.getCreateTime()),
   createUuidArray(zoneInfo.getAdminAccountIds().stream()),
   zoneInfo.isHideFromTop());
 createZoneAdmin(zoneInfo);
 return zoneInfo;
}

代码示例来源:origin: kaif-open/kaif

@Test
public void createDefault() throws Exception {
 ZoneInfo zoneInfo = service.createDefault("abc", "Abc");
 ZoneInfo loaded = zoneDao.loadZoneWithoutCache(Zone.valueOf("abc"));
 assertEquals(zoneInfo, loaded);
 assertEquals("abc", loaded.getName());
 assertEquals("Abc", loaded.getAliasName());
 assertEquals(Authority.CITIZEN, loaded.getVoteAuthority());
 assertEquals(Authority.CITIZEN, loaded.getWriteAuthority());
 assertEquals(Authority.CITIZEN, loaded.getDebateAuthority());
 assertEquals(ZoneInfo.THEME_DEFAULT, loaded.getTheme());
 assertFalse(loaded.isHideFromTop());
 assertEquals(0, loaded.getAdminAccountIds().size());
}

代码示例来源:origin: kaif-open/kaif

@Override
protected void buildFeedMetadata(Map<String, Object> model,
  Channel feed,
  HttpServletRequest request) {
 ZoneInfo zoneInfo = (ZoneInfo) model.get("zoneInfo");
 @SuppressWarnings("unchecked")
 List<Article> articles = (List<Article>) model.get("articles");
 if (zoneInfo != null) {
  feed.setTitle(zoneInfo.getName() + " kaif.io");
  feed.setLink(zoneUrl(zoneInfo.getZone()));
  feed.setDescription(zoneInfo.getAliasName() + " 熱門");
  feed.setPubDate(buildFeedUpdateTime(articles, zoneInfo.getCreateTime()));
 } else {
  feed.setTitle("熱門 kaif.io");
  feed.setLink(SCHEME_AND_HOST);
  feed.setDescription("綜合熱門");
  feed.setPubDate(buildFeedUpdateTime(articles, DEFAULT_INSTANT));
 }
}

代码示例来源:origin: kaif-open/kaif

@Test
public void canUpVote() throws Exception {
 ZoneInfo general = ZoneInfo.createDefault("general", "public", Instant.now());
 UUID accountId = UUID.randomUUID();
 assertTrue(general.canUpVote(auth(accountId, EnumSet.of(CITIZEN))));
 assertFalse(general.canUpVote(auth(accountId, EnumSet.of(TOURIST))));
 assertFalse(general.canUpVote(auth(accountId, EnumSet.of(SYSOP))));
 ZoneInfo managed = general.withAdmins(Arrays.asList(accountId));
 assertTrue("admin should ignore authority",
   managed.canUpVote(auth(accountId, EnumSet.noneOf(Authority.class))));
 assertFalse("not admin",
   managed.canUpVote(auth(UUID.randomUUID(), EnumSet.noneOf(Authority.class))));
}

代码示例来源:origin: kaif-open/kaif

@Test
public void canWriteArticle() throws Exception {
 ZoneInfo site = ZoneInfo.createKaif("site", "public", Instant.now());
 UUID accountId = UUID.randomUUID();
 assertFalse(site.canWriteArticle(auth(accountId, EnumSet.of(SYSOP))));
 assertFalse(site.canWriteArticle(auth(accountId, EnumSet.of(TOURIST))));
 assertFalse(site.canWriteArticle(auth(accountId, EnumSet.of(CITIZEN))));
 ZoneInfo managed = site.withAdmins(Arrays.asList(accountId));
 assertTrue("admin should ignore authority",
   managed.canWriteArticle(auth(accountId, EnumSet.noneOf(Authority.class))));
 assertFalse("not admin",
   managed.canWriteArticle(auth(UUID.randomUUID(), EnumSet.noneOf(Authority.class))));
}

代码示例来源:origin: kaif-open/kaif

@Test
public void canDebate() throws Exception {
 ZoneInfo general = ZoneInfo.createDefault("general", "public", Instant.now());
 UUID accountId = UUID.randomUUID();
 assertTrue(general.canDebate(auth(accountId, EnumSet.of(CITIZEN))));
 assertFalse(general.canDebate(auth(accountId, EnumSet.of(TOURIST))));
 assertFalse(general.canDebate(auth(accountId, EnumSet.of(SYSOP))));
 ZoneInfo managed = general.withAdmins(Arrays.asList(accountId));
 assertTrue("admin should ignore authority",
   managed.canDebate(auth(accountId, EnumSet.noneOf(Authority.class))));
 assertFalse("not admin",
   managed.canDebate(auth(UUID.randomUUID(), EnumSet.noneOf(Authority.class))));
}

代码示例来源:origin: kaif-open/kaif

@Test
public void rssFeed_no_articles() throws Exception {
 Zone z = zoneInfo.getZone();
 when(zoneService.loadZone(z)).thenReturn(zoneInfo);
 String pubDateStr = RFC1123_FORMATTER.format(zoneInfo.getCreateTime());
 when(articleService.listRssHotZoneArticlesWithCache(z)).thenReturn(Collections.emptyList());
 mockMvc.perform(get("/z/programming/hot.rss"))
   .andExpect(xpath("/rss/channel/title").string("programming kaif.io"))
   .andExpect(xpath("/rss/channel/description").string("programming-alias 熱門"))
   .andExpect(xpath("/rss/channel/pubDate").string(pubDateStr));
}

代码示例来源:origin: kaif-open/kaif

@Override
public ZoneInfo createDefault(String zone, String aliasName) {
 return zoneDao.create(ZoneInfo.createDefault(zone, aliasName, Instant.now()));
}

代码示例来源:origin: kaif-open/kaif

@Override
public Debate debate(FlakeId articleId,
  @Nullable FlakeId parentDebateId,
  Authorization debaterAuth,
  String content) {
 //creating debate should not use cache
 Article article = articleDao.loadArticleWithoutCache(articleId);
 ZoneInfo zoneInfo = zoneDao.loadZoneWithoutCache(article.getZone());
 Account debater = accountDao.strongVerifyAccount(debaterAuth)
   .filter(zoneInfo::canDebate)
   .orElseThrow(() -> new AccessDeniedException("no write to debate at zone:"
     + article.getZone()));
 Debate parent = Optional.ofNullable(parentDebateId).flatMap(debateDao::findDebate).orElse(null);
 Debate debate = debateDao.create(article, parent, content, debater, Instant.now(clock));
 //may improve later to make it async, but async has transaction problem
 articleDao.increaseDebateCount(article);
 if (zoneInfo.getDebateAuthority() == Authority.CITIZEN) {
  accountDao.increaseDebateCount(debater);
 }
 if (!debate.getReplyToAccountId().equals(debater.getAccountId())) {
  feedService.createReplyFeed(debate.getDebateId(), debate.getReplyToAccountId());
 }
 return debate;
}

代码示例来源:origin: kaif-open/kaif

@Test
public void updateTheme() throws Exception {
 service.createDefault("twfaq", "TW FAQ");
 service.loadZone(Zone.valueOf("twfaq"));//populate cache
 service.updateTheme(Zone.valueOf("twfaq"), ZoneInfo.THEME_KAIF);
 assertEquals(ZoneInfo.THEME_KAIF, service.loadZone(Zone.valueOf("twfaq")).getTheme());
}

代码示例来源:origin: kaif-open/kaif

@Test
public void createKaif() throws Exception {
 ZoneInfo zoneInfo = service.createKaif("faq", "FAQ");
 ZoneInfo loaded = zoneDao.loadZoneWithoutCache(Zone.valueOf("faq"));
 assertEquals(zoneInfo, loaded);
 assertEquals("faq", loaded.getZone().value());
 assertEquals("FAQ", loaded.getAliasName());
 assertEquals(Authority.CITIZEN, loaded.getVoteAuthority());
 assertEquals(Authority.CITIZEN, loaded.getDebateAuthority());
 assertEquals(Authority.FORBIDDEN, loaded.getWriteAuthority());
 assertEquals(ZoneInfo.THEME_KAIF, loaded.getTheme());
 assertTrue(loaded.isHideFromTop());
 assertEquals(0, loaded.getAdminAccountIds().size());
}

代码示例来源:origin: kaif-open/kaif

@Test
public void createByUser() throws Exception {
 accountDao.changeTotalVotedDebate(citizen.getAccountId(), 10, 0);
 ZoneInfo zoneInfo = service.createByUser("aaa", "this is aaa", citizen);
 ZoneInfo loaded = zoneDao.loadZoneWithoutCache(Zone.valueOf("aaa"));
 assertEquals(zoneInfo, loaded);
 assertEquals("aaa", loaded.getName());
 assertEquals("this is aaa", loaded.getAliasName());
 assertEquals(Authority.CITIZEN, loaded.getVoteAuthority());
 assertEquals(Authority.CITIZEN, loaded.getWriteAuthority());
 assertEquals(Authority.CITIZEN, loaded.getDebateAuthority());
 assertEquals(ZoneInfo.THEME_DEFAULT, loaded.getTheme());
 assertFalse(loaded.isHideFromTop());
 assertEquals(citizen.getAccountId(), loaded.getAdminAccountIds().get(0));
 List<ZoneInfo> zones = zoneDao.listZonesByAdmin(citizen.getAccountId());
 assertEquals(zoneInfo, zones.get(0));
}

代码示例来源:origin: kaif-open/kaif

public Article createSpeak(ZoneInfo zoneInfo,
  Account author,
  String title,
  String content,
  Instant now) {
 return insertArticle(Article.createSpeak(zoneInfo.getZone(),
   zoneInfo.getAliasName(),
   kaifIdGenerator.next(),
   author,
   title,
   content,
   now));
}

代码示例来源:origin: kaif-open/kaif

default ZoneInfo zoneDefault(String zone) {
 return ZoneInfo.createDefault(zone, zone + "-alias", Instant.now());
}

相关文章