Package net.pterodactylus.sone.data

Examples of net.pterodactylus.sone.data.Sone


    assertThat(response.getReplyParameters().get("Sone"), is("LocalSone"));
  }

  @Test(expected = FcpException.class)
  public void testLockingARemoteSone() throws FcpException {
    Sone removeSone = mock(Sone.class);
    Core core = mock(Core.class);
    when(core.getSone(eq("RemoteSone"))).thenReturn(Optional.of(removeSone));
    SimpleFieldSet fields = new SimpleFieldSetBuilder().put("Sone", "RemoteSone").get();

    LockSoneCommand lockSoneCommand = new LockSoneCommand(core);
View Full Code Here


   * {@inheritDoc}
   */
  @Override
  protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
    super.processTemplate(request, templateContext);
    Sone currentSone = getCurrentSone(request.getToadletContext(), false);
    templateContext.set("core", webInterface.getCore());
    templateContext.set("currentSone", currentSone);
    templateContext.set("localSones", webInterface.getCore().getLocalSones());
    templateContext.set("request", request);
    templateContext.set("currentVersion", SonePlugin.VERSION);
View Full Code Here

*/
public class UnlockSoneCommandTest {

  @Test
  public void testUnlockingALocalSone() throws FcpException {
    Sone localSone = mock(Sone.class);
    when(localSone.getId()).thenReturn("LocalSone");
    when(localSone.isLocal()).thenReturn(true);
    Core core = mock(Core.class);
    when(core.getSone(eq("LocalSone"))).thenReturn(Optional.of(localSone));
    when(core.getLocalSone(eq("LocalSone"), anyBoolean())).thenReturn(localSone);
    SimpleFieldSet fields = new SimpleFieldSetBuilder().put("Sone", "LocalSone").get();

View Full Code Here

    assertThat(response.getReplyParameters().get("Sone"), is("LocalSone"));
  }

  @Test(expected = FcpException.class)
  public void testUnlockingARemoteSone() throws FcpException {
    Sone removeSone = mock(Sone.class);
    Core core = mock(Core.class);
    when(core.getSone(eq("RemoteSone"))).thenReturn(Optional.of(removeSone));
    SimpleFieldSet fields = new SimpleFieldSetBuilder().put("Sone", "RemoteSone").get();

    UnlockSoneCommand unlockSoneCommand = new UnlockSoneCommand(core);
View Full Code Here

   */
  @Override
  protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
    super.processTemplate(request, templateContext);
    if (request.getMethod() == Method.POST) {
      Sone currentSone = getCurrentSone(request.getToadletContext());
      String parentId = request.getHttpRequest().getPartAsStringFailsafe("parent", 36);
      Album parent = webInterface.getCore().getAlbum(parentId, false);
      if (parent == null) {
        /* TODO - signal error */
        return;
      }
      if (!currentSone.equals(parent.getSone())) {
        /* TODO - signal error. */
        return;
      }
      String name = request.getHttpRequest().getPartAsStringFailsafe("title", 200);
      String description = request.getHttpRequest().getPartAsStringFailsafe("description", 4000);
View Full Code Here

      if (!post.isPresent()) {
        throw new RedirectException("noPermission.html");
      }
      if (text.length() > 0) {
        String senderId = request.getHttpRequest().getPartAsStringFailsafe("sender", 43);
        Sone sender = webInterface.getCore().getLocalSone(senderId, false);
        if (sender == null) {
          sender = getCurrentSone(request.getToadletContext());
        }
        text = TextFilter.filter(request.getHttpRequest().getHeader("host"), text);
        webInterface.getCore().createReply(sender, post.get(), text);
View Full Code Here

    List<Sone> localSones = new ArrayList<Sone>(webInterface.getCore().getLocalSones());
    Collections.sort(localSones, Sone.NICE_NAME_COMPARATOR);
    templateContext.set("sones", localSones);
    if (request.getMethod() == Method.POST) {
      String soneId = request.getHttpRequest().getPartAsStringFailsafe("sone-id", 100);
      Sone selectedSone = webInterface.getCore().getLocalSone(soneId, false);
      if (selectedSone != null) {
        setCurrentSone(request.getToadletContext(), selectedSone);
        String target = request.getHttpRequest().getParam("target");
        if ((target == null) || (target.length() == 0)) {
          target = "index.html";
View Full Code Here

   */
  @Override
  protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
    super.processTemplate(request, templateContext);
    Preferences preferences = webInterface.getCore().getPreferences();
    Sone currentSone = webInterface.getCurrentSone(request.getToadletContext(), false);
    if (request.getMethod() == Method.POST) {
      List<String> fieldErrors = new ArrayList<String>();
      if (currentSone != null) {
        boolean autoFollow = request.getHttpRequest().isPartSet("auto-follow");
        currentSone.getOptions().getBooleanOption("AutoFollow").set(autoFollow);
        boolean enableSoneInsertNotifications = request.getHttpRequest().isPartSet("enable-sone-insert-notifications");
        currentSone.getOptions().getBooleanOption("EnableSoneInsertNotifications").set(enableSoneInsertNotifications);
        boolean showNotificationNewSones = request.getHttpRequest().isPartSet("show-notification-new-sones");
        currentSone.getOptions().getBooleanOption("ShowNotification/NewSones").set(showNotificationNewSones);
        boolean showNotificationNewPosts = request.getHttpRequest().isPartSet("show-notification-new-posts");
        currentSone.getOptions().getBooleanOption("ShowNotification/NewPosts").set(showNotificationNewPosts);
        boolean showNotificationNewReplies = request.getHttpRequest().isPartSet("show-notification-new-replies");
        currentSone.getOptions().getBooleanOption("ShowNotification/NewReplies").set(showNotificationNewReplies);
        String showCustomAvatars = request.getHttpRequest().getPartAsStringFailsafe("show-custom-avatars", 32);
        currentSone.getOptions().<ShowCustomAvatars> getEnumOption("ShowCustomAvatars").set(ShowCustomAvatars.valueOf(showCustomAvatars));
        webInterface.getCore().touchConfiguration();
      }
      Integer insertionDelay = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("insertion-delay", 16));
      if (!preferences.validateInsertionDelay(insertionDelay)) {
        fieldErrors.add("insertion-delay");
      } else {
        preferences.setInsertionDelay(insertionDelay);
      }
      Integer postsPerPage = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("posts-per-page", 4), null);
      if (!preferences.validatePostsPerPage(postsPerPage)) {
        fieldErrors.add("posts-per-page");
      } else {
        preferences.setPostsPerPage(postsPerPage);
      }
      Integer imagesPerPage = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("images-per-page", 4), null);
      if (!preferences.validateImagesPerPage(imagesPerPage)) {
        fieldErrors.add("images-per-page");
      } else {
        preferences.setImagesPerPage(imagesPerPage);
      }
      Integer charactersPerPost = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("characters-per-post", 10), null);
      if (!preferences.validateCharactersPerPost(charactersPerPost)) {
        fieldErrors.add("characters-per-post");
      } else {
        preferences.setCharactersPerPost(charactersPerPost);
      }
      Integer postCutOffLength = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("post-cut-off-length", 10), null);
      if (!preferences.validatePostCutOffLength(postCutOffLength)) {
        fieldErrors.add("post-cut-off-length");
      } else {
        preferences.setPostCutOffLength(postCutOffLength);
      }
      boolean requireFullAccess = request.getHttpRequest().isPartSet("require-full-access");
      preferences.setRequireFullAccess(requireFullAccess);
      Integer positiveTrust = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("positive-trust", 3));
      if (!preferences.validatePositiveTrust(positiveTrust)) {
        fieldErrors.add("positive-trust");
      } else {
        preferences.setPositiveTrust(positiveTrust);
      }
      Integer negativeTrust = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("negative-trust", 4));
      if (!preferences.validateNegativeTrust(negativeTrust)) {
        fieldErrors.add("negative-trust");
      } else {
        preferences.setNegativeTrust(negativeTrust);
      }
      String trustComment = request.getHttpRequest().getPartAsStringFailsafe("trust-comment", 256);
      if (trustComment.trim().length() == 0) {
        trustComment = null;
      }
      preferences.setTrustComment(trustComment);
      boolean fcpInterfaceActive = request.getHttpRequest().isPartSet("fcp-interface-active");
      preferences.setFcpInterfaceActive(fcpInterfaceActive);
      Integer fcpFullAccessRequiredInteger = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("fcp-full-access-required", 1), preferences.getFcpFullAccessRequired().ordinal());
      FullAccessRequired fcpFullAccessRequired = FullAccessRequired.values()[fcpFullAccessRequiredInteger];
      preferences.setFcpFullAccessRequired(fcpFullAccessRequired);
      webInterface.getCore().touchConfiguration();
      if (fieldErrors.isEmpty()) {
        throw new RedirectException(getPath());
      }
      templateContext.set("fieldErrors", fieldErrors);
    }
    if (currentSone != null) {
      templateContext.set("auto-follow", currentSone.getOptions().getBooleanOption("AutoFollow").get());
      templateContext.set("enable-sone-insert-notifications", currentSone.getOptions().getBooleanOption("EnableSoneInsertNotifications").get());
      templateContext.set("show-notification-new-sones", currentSone.getOptions().getBooleanOption("ShowNotification/NewSones").get());
      templateContext.set("show-notification-new-posts", currentSone.getOptions().getBooleanOption("ShowNotification/NewPosts").get());
      templateContext.set("show-notification-new-replies", currentSone.getOptions().getBooleanOption("ShowNotification/NewReplies").get());
      templateContext.set("show-custom-avatars", currentSone.getOptions().<ShowCustomAvatars> getEnumOption("ShowCustomAvatars").get().name());
    }
    templateContext.set("insertion-delay", preferences.getInsertionDelay());
    templateContext.set("posts-per-page", preferences.getPostsPerPage());
    templateContext.set("images-per-page", preferences.getImagesPerPage());
    templateContext.set("characters-per-post", preferences.getCharactersPerPost());
View Full Code Here

  @Override
  protected void serviceRun() {
    long lastModificationTime = 0;
    String lastInsertedFingerprint = lastInsertFingerprint;
    String lastFingerprint = "";
    Sone sone;
    while (!shouldStop()) {
      try {
        /* check every seconds. */
        sleep(1000);

        /* don’t insert locked Sones. */
        sone = this.sone;
        if (core.isLocked(sone)) {
          /* trigger redetection when the Sone is unlocked. */
          synchronized (sone) {
            modified = !sone.getFingerprint().equals(lastInsertedFingerprint);
          }
          lastFingerprint = "";
          lastModificationTime = 0;
          continue;
        }

        InsertInformation insertInformation = null;
        synchronized (sone) {
          String fingerprint = sone.getFingerprint();
          if (!fingerprint.equals(lastFingerprint)) {
            if (fingerprint.equals(lastInsertedFingerprint)) {
              modified = false;
              lastModificationTime = 0;
              logger.log(Level.FINE, String.format("Sone %s has been reverted to last insert state.", sone));
            } else {
              lastModificationTime = System.currentTimeMillis();
              modified = true;
              logger.log(Level.FINE, String.format("Sone %s has been modified, waiting %d seconds before inserting.", sone.getName(), insertionDelay));
            }
            lastFingerprint = fingerprint;
          }
          if (modified && (lastModificationTime > 0) && ((System.currentTimeMillis() - lastModificationTime) > (insertionDelay * 1000))) {
            lastInsertedFingerprint = fingerprint;
            insertInformation = new InsertInformation(sone);
          }
        }

        if (insertInformation != null) {
          logger.log(Level.INFO, String.format("Inserting Sone “%s”…", sone.getName()));

          boolean success = false;
          try {
            sone.setStatus(SoneStatus.inserting);
            long insertTime = System.currentTimeMillis();
            insertInformation.setTime(insertTime);
            eventBus.post(new SoneInsertingEvent(sone));
            FreenetURI finalUri = freenetInterface.insertDirectory(insertInformation.getInsertUri(), insertInformation.generateManifestEntries(), "index.html");
            eventBus.post(new SoneInsertedEvent(sone, System.currentTimeMillis() - insertTime));
            /* at this point we might already be stopped. */
            if (shouldStop()) {
              /* if so, bail out, don’t change anything. */
              break;
            }
            sone.setTime(insertTime);
            sone.setLatestEdition(finalUri.getEdition());
            core.touchConfiguration();
            success = true;
            logger.log(Level.INFO, String.format("Inserted Sone “%s” at %s.", sone.getName(), finalUri));
          } catch (SoneException se1) {
            eventBus.post(new SoneInsertAbortedEvent(sone, se1));
            logger.log(Level.WARNING, String.format("Could not insert Sone “%s”!", sone.getName()), se1);
          } finally {
            sone.setStatus(SoneStatus.idle);
          }

          /*
           * reset modification counter if Sone has not been modified
           * while it was inserted.
           */
          if (success) {
            synchronized (sone) {
              if (lastInsertedFingerprint.equals(sone.getFingerprint())) {
                logger.log(Level.FINE, String.format("Sone “%s” was not modified further, resetting counter…", sone));
                lastModificationTime = 0;
                lastInsertFingerprint = lastInsertedFingerprint;
                core.touchConfiguration();
                modified = false;
View Full Code Here

   */
  @Override
  protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
    super.processTemplate(request, templateContext);
    String soneId = request.getHttpRequest().getPartAsStringFailsafe("sone", 44);
    Sone sone = webInterface.getCore().getLocalSone(soneId, false);
    if (sone != null) {
      webInterface.getCore().lockSone(sone);
    }
    String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256);
    throw new RedirectException(returnPage);
View Full Code Here

TOP

Related Classes of net.pterodactylus.sone.data.Sone

Copyright © 2018 www.massapicom. 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.