}
}
- if (originalSone.getInsertUri() != null) {
- sone.setInsertUri(originalSone.getInsertUri());
- }
-
SimpleXML profileXml = soneXml.getNode("profile");
if (profileXml == null) {
/* TODO - mark Sone as bad. */
package net.pterodactylus.sone.core;
-import static com.google.common.base.Preconditions.checkArgument;
import static java.lang.String.format;
import static java.lang.System.currentTimeMillis;
import static net.pterodactylus.sone.data.Album.NOT_EMPTY;
sone.setStatus(SoneStatus.inserting);
long insertTime = currentTimeMillis();
eventBus.post(new SoneInsertingEvent(sone));
- FreenetURI finalUri = freenetInterface.insertDirectory(insertInformation.getInsertUri(), insertInformation.generateManifestEntries(), "index.html");
+ FreenetURI finalUri = freenetInterface.insertDirectory(sone.getInsertUri(), insertInformation.generateManifestEntries(), "index.html");
eventBus.post(new SoneInsertedEvent(sone, currentTimeMillis() - insertTime));
/* at this point we might already be stopped. */
if (shouldStop()) {
soneProperties.put("name", sone.getName());
soneProperties.put("time", currentTimeMillis());
soneProperties.put("requestUri", sone.getRequestUri());
- soneProperties.put("insertUri", sone.getInsertUri());
soneProperties.put("profile", sone.getProfile());
soneProperties.put("posts", Ordering.from(Post.TIME_COMPARATOR).sortedCopy(sone.getPosts()));
soneProperties.put("replies", Ordering.from(Reply.TIME_COMPARATOR).reverse().sortedCopy(sone.getReplies()));
return fingerprint;
}
- /**
- * Returns the insert URI of the Sone.
- *
- * @return The insert URI of the Sone
- */
- public FreenetURI getInsertUri() {
- return (FreenetURI) soneProperties.get("insertUri");
- }
-
//
// ACTIONS
//
Identity getIdentity();
/**
- * Sets the identity of this Sone. The {@link Identity#getId() ID} of the
- * identity has to match this Sone’s {@link #getId()}.
- *
- * @param identity
- * The identity of this Sone
- * @return This Sone (for method chaining)
- * @throws IllegalArgumentException
- * if the ID of the identity does not match this Sone’s ID
- */
- Sone setIdentity(Identity identity) throws IllegalArgumentException;
-
- /**
* Returns the name of this Sone.
*
* @return The name of this Sone
FreenetURI getInsertUri();
/**
- * Sets the insert URI of this Sone.
- *
- * @param insertUri
- * The insert URI of this Sone
- * @return This Sone (for method chaining)
- */
- Sone setInsertUri(FreenetURI insertUri);
-
- /**
* Returns the latest edition of this Sone.
*
* @return The latest edition of this Sone
package net.pterodactylus.sone.data;
import static com.google.common.base.Preconditions.checkNotNull;
+import static java.lang.String.format;
+import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import net.pterodactylus.sone.data.SoneOptions.DefaultSoneOptions;
import net.pterodactylus.sone.freenet.wot.Identity;
+import net.pterodactylus.sone.freenet.wot.OwnIdentity;
import net.pterodactylus.util.logging.Logging;
import freenet.keys.FreenetURI;
}
/**
- * Sets the identity of this Sone. The {@link Identity#getId() ID} of the
- * identity has to match this Sone’s {@link #getId()}.
- *
- * @param identity
- * The identity of this Sone
- * @return This Sone (for method chaining)
- * @throws IllegalArgumentException
- * if the ID of the identity does not match this Sone’s ID
- */
- public SoneImpl setIdentity(Identity identity) throws IllegalArgumentException {
- if (!identity.getId().equals(id)) {
- throw new IllegalArgumentException("Identity’s ID does not match Sone’s ID!");
- }
- this.identity = identity;
- return this;
- }
-
- /**
* Returns the name of this Sone.
*
* @return The name of this Sone
* @return The insert URI of this Sone
*/
public FreenetURI getInsertUri() {
- return (insertUri != null) ? insertUri.setSuggestedEdition(latestEdition) : null;
- }
-
- /**
- * Sets the insert URI of this Sone.
- *
- * @param insertUri
- * The insert URI of this Sone
- * @return This Sone (for method chaining)
- */
- public Sone setInsertUri(FreenetURI insertUri) {
- if (this.insertUri == null) {
- this.insertUri = insertUri.setKeyType("USK").setDocName("Sone").setMetaString(new String[0]);
- return this;
+ if (!isLocal()) {
+ return null;
}
- if (!this.insertUri.equalsKeypair(insertUri)) {
- logger.log(Level.WARNING, String.format("Request URI %s tried to overwrite %s!", insertUri, this.insertUri));
- return this;
+ try {
+ return new FreenetURI(((OwnIdentity) getIdentity()).getInsertUri()).setDocName("Sone").setMetaString(new String[0]);
+ } catch (MalformedURLException e) {
+ throw new IllegalStateException(format("Own identity %s's insert URI is incorrect.", getIdentity()), e);
}
- return this;
}
/**
}
@Test
- public void soneInsertUriIsCopiedToNewSone() throws SoneException {
- InputStream inputStream = getClass().getResourceAsStream("sone-parser-no-payload.xml");
- FreenetURI insertUri = mock(FreenetURI.class);
- when(insertUri.setKeyType(anyString())).thenReturn(insertUri);
- when(insertUri.setDocName(anyString())).thenReturn(insertUri);
- when(insertUri.setMetaString(any(String[].class))).thenReturn(insertUri);
- when(insertUri.setSuggestedEdition(anyLong())).thenReturn(insertUri);
- when(sone.getInsertUri()).thenReturn(insertUri);
- assertThat(soneDownloader.parseSone(sone, inputStream).getInsertUri(), is(insertUri));
- }
-
- @Test
public void parsingASoneSucceedsWithProfile() throws SoneException, MalformedURLException {
InputStream inputStream = getClass().getResourceAsStream("sone-parser-with-profile.xml");
final Profile profile = soneDownloader.parseSone(sone, inputStream).getProfile();
InsertInformation insertInformation = soneInserter.new InsertInformation(sone);
HashMap<String, Object> manifestEntries = insertInformation.generateManifestEntries();
assertThat(manifestEntries.keySet(), containsInAnyOrder("index.html", "sone.xml"));
- assertThat(insertInformation.getInsertUri(), is(insertUri));
assertThat(insertInformation.getFingerprint(), is(fingerprint));
}