* @return The Sone rescuer for the given Sone
*/
public SoneRescuer getSoneRescuer(Sone sone) {
- Validation.begin().isNotNull("Sone", sone).check().is("Local Sone", isLocalSone(sone)).check();
+ Validation.begin().isNotNull("Sone", sone).check().is("Local Sone", sone.isLocal()).check();
synchronized (soneRescuers) {
SoneRescuer soneRescuer = soneRescuers.get(sone);
if (soneRescuer == null) {
* otherwise
*/
public boolean hasSone(String id) {
- return database.isLocalSone(id) || database.isRemoteSone(id);
- }
-
- /**
- * Returns whether the given Sone is a local Sone.
- *
- * @param sone
- * The Sone to check for its locality
- * @return {@code true} if the given Sone is local, {@code false} otherwise
- */
- public boolean isLocalSone(Sone sone) {
- return database.isLocalSone(sone);
- }
-
- /**
- * Returns whether the given ID is the ID of a local Sone.
- *
- * @param id
- * The Sone ID to check for its locality
- * @return {@code true} if the given ID is a local Sone, {@code false}
- * otherwise
- */
- public boolean isLocalSone(String id) {
- return database.isLocalSone(id);
+ return database.getSone(id, false) != null;
}
/**
}
/**
- * Returns whether the given Sone is a remote Sone.
- *
- * @param sone
- * The Sone to check
- * @return {@code true} if the given Sone is a remote Sone, {@code false}
- * otherwise
- */
- public boolean isRemoteSone(Sone sone) {
- return database.isRemoteSone(sone);
- }
-
- /**
- * Returns whether the Sone with the given ID is a remote Sone.
- *
- * @param id
- * The ID of the Sone to check
- * @return {@code true} if the Sone with the given ID is a remote Sone,
- * {@code false} otherwise
- */
- public boolean isRemoteSone(String id) {
- return database.isRemoteSone(id);
- }
-
- /**
* Returns whether the given Sone has been modified.
*
* @param sone
}
/**
+<<<<<<< HEAD
+=======
+ * Adds a local Sone from the given ID which has to be the ID of an own
+ * identity.
+ *
+ * @param id
+ * The ID of an own identity to add a Sone for
+ * @return The added (or already existing) Sone
+ */
+ public Sone addLocalSone(String id) {
+ if (database.getLocalSone(id, false) != null) {
+ logger.log(Level.FINE, "Tried to add known local Sone: %s", id);
+ return database.getLocalSone(id, false);
+ }
+ OwnIdentity ownIdentity = identityManager.getOwnIdentity(id);
+ if (ownIdentity == null) {
+ logger.log(Level.INFO, "Invalid Sone ID: %s", id);
+ return null;
+ }
+ return addLocalSone(ownIdentity);
+ }
+
+ /**
+>>>>>>> 4f36598... Store locality of a Sone in the Sone itself, remove related methods from Database.
* Adds a local Sone from the given own identity.
*
* @param ownIdentity
* @return The trust relationship
*/
public Trust getTrust(Sone origin, Sone target) {
- if (!isLocalSone(origin)) {
+ if (!origin.isLocal()) {
logger.log(Level.WARNING, String.format("Tried to get trust from remote Sone: %s", origin));
return null;
}
logger.log(Level.WARNING, String.format("Tried to delete Sone of non-own identity: %s", sone));
return;
}
- if (!database.isLocalSone(sone)) {
+ if (!sone.isLocal()) {
logger.log(Level.WARNING, String.format("Tried to delete non-local Sone: %s", sone));
return;
}
* The Sone to load and update
*/
public void loadSone(Sone sone) {
- if (!isLocalSone(sone)) {
+ if (!sone.isLocal()) {
logger.log(Level.FINE, String.format("Tried to load non-local Sone: %s", sone));
return;
}
* @return The created post
*/
public Post createPost(Sone sone, Sone recipient, long time, String text) {
- if (!isLocalSone(sone)) {
+ if (!sone.isLocal()) {
logger.log(Level.FINE, String.format("Tried to create post for non-local Sone: %s", sone));
return null;
}
* The post to delete
*/
public void deletePost(Post post) {
- if (!isLocalSone(post.getSone())) {
+ if (!post.getSone().isLocal()) {
logger.log(Level.WARNING, String.format("Tried to delete post of non-local Sone: %s", post.getSone()));
return;
}
* @return The created reply
*/
public PostReply createReply(Sone sone, Post post, long time, String text) {
- if (!isLocalSone(sone)) {
+ if (!sone.isLocal()) {
logger.log(Level.FINE, String.format("Tried to create reply for non-local Sone: %s", sone));
return null;
}
*/
public void deleteReply(PostReply reply) {
Sone sone = reply.getSone();
- if (!isLocalSone(sone)) {
+ if (!sone.isLocal()) {
logger.log(Level.FINE, String.format("Tried to delete non-local reply: %s", reply));
return;
}
* The album to remove
*/
public void deleteAlbum(Album album) {
- Validation.begin().isNotNull("Album", album).check().is("Local Sone", isLocalSone(album.getSone())).check();
+ Validation.begin().isNotNull("Album", album).check().is("Local Sone", album.getSone().isLocal()).check();
if (!album.isEmpty()) {
return;
}
* @return The newly created image
*/
public Image createImage(Sone sone, Album album, TemporaryImage temporaryImage) {
- Validation.begin().isNotNull("Sone", sone).isNotNull("Album", album).isNotNull("Temporary Image", temporaryImage).check().is("Local Sone", isLocalSone(sone)).check().isEqual("Owner and Album Owner", sone, album.getSone()).check();
+ Validation.begin().isNotNull("Sone", sone).isNotNull("Album", album).isNotNull("Temporary Image", temporaryImage).check().is("Local Sone", sone.isLocal()).check().isEqual("Owner and Album Owner", sone, album.getSone()).check();
Image image = new Image(temporaryImage.getId()).setSone(sone).setCreationTime(System.currentTimeMillis());
album.addImage(image);
synchronized (images) {
* The image to delete
*/
public void deleteImage(Image image) {
- Validation.begin().isNotNull("Image", image).check().is("Local Sone", isLocalSone(image.getSone())).check();
+ Validation.begin().isNotNull("Image", image).check().is("Local Sone", image.getSone().isLocal()).check();
deleteTemporaryImage(image.getId());
image.getAlbum().removeImage(image);
synchronized (images) {
* The Sone to save
*/
private synchronized void saveSone(Sone sone) {
- if (!isLocalSone(sone)) {
+ if (!sone.isLocal()) {
logger.log(Level.FINE, String.format("Tried to save non-local Sone: %s", sone));
return;
}
return null;
}
- Sone sone = new Sone(originalSone.getId()).setIdentity(originalSone.getIdentity());
+ Sone sone = new Sone(originalSone.getId(), originalSone.isLocal()).setIdentity(originalSone.getIdentity());
SimpleXML soneXml;
try {
}
};
- /** Filter that matches all {@link Core#isLocalSone(Sone) local Sones}. */
+ /** Filter that matches all {@link Core#getLocalSones() local Sones}. */
public static final Filter<Sone> LOCAL_SONE_FILTER = new Filter<Sone>() {
@Override
/** The ID of this Sone. */
private final String id;
+ /** Whether this is a local Sone. */
+ private final boolean local;
+
/** The identity of this Sone. */
private Identity identity;
*
* @param id
* The ID of the Sone
+ * @param local
+ * {@code true} if this Sone is local, {@code false} otherwise
*/
- public Sone(String id) {
+ public Sone(String id, boolean local) {
this.id = id;
+ this.local = local;
}
//
}
/**
+ * Returns whether this Sone is local.
+ *
+ * @return {@code true} if this Sone is local, {@code false} otherwise
+ */
+ public boolean isLocal() {
+ return local;
+ }
+
+ /**
* Returns the name of this Sone.
*
* @return The name of this Sone
public interface Database {
/**
- * Returns whether the given Sone is a local Sone.
- *
- * @param sone
- * The Sone to check
- * @return {@code true} if the given Sone is a local Sone, {@code false}
- * otherwise
- * @throws IllegalArgumentException
- * if {@code sone} is {@code null}
- * @throws DatabaseException
- * if a database error occurs
- */
- public boolean isLocalSone(Sone sone) throws DatabaseException;
-
- /**
- * Returns whether the given Sone ID belongs to a local Sone.
- *
- * @param id
- * The Sone ID to check
- * @return {@code true} if the given Sone ID belongs to a local Sone,
- * {@code false} otherwise
- * @throws IllegalArgumentException
- * if {@code id} is {@code null}
- * @throws DatabaseException
- * if a database error occurs
- */
- public boolean isLocalSone(String id) throws DatabaseException;
-
- /**
- * Returns whether the given Sone is a remote Sone.
- *
- * @param sone
- * The Sone to check
- * @return {@code true} if the given Sone is a remote Sone, {@code false}
- * otherwise
- * @throws IllegalArgumentException
- * if {@code sone} is {@code null}
- * @throws DatabaseException
- * if a database error occurs
- */
- public boolean isRemoteSone(Sone sone) throws DatabaseException;
-
- /**
- * Returns whether the given Sone ID belongs to a remote Sone.
- *
- * @param id
- * The Sone ID to check
- * @return {@code true} if the given Sone ID belongs to a remote Sone,
- * {@code false} otherwise
- * @throws IllegalArgumentException
- * if {@code id} is {@code null}
- * @throws DatabaseException
- * if a database error occurs
- */
- public boolean isRemoteSone(String id) throws DatabaseException;
-
- /**
* Returns the Sone with the given ID, creating a new Sone if a Sone with
* the given ID does not exist and {@code create} is {@code true}. When
* searching for a Sone with the given IDs, local Sones are preferred.
* {@inheritDoc}
*/
@Override
- public boolean isLocalSone(Sone sone) throws DatabaseException {
- Validation.begin().isNotNull("Sone", sone).check();
- return isLocalSone(sone.getId());
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean isLocalSone(String id) throws DatabaseException {
- Validation.begin().isNotNull("Sone ID", id).check();
- synchronized (localSones) {
- return localSones.containsKey(id);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean isRemoteSone(Sone sone) throws DatabaseException {
- Validation.begin().isNotNull("Sone", sone).check();
- return isRemoteSone(sone.getId());
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean isRemoteSone(String id) throws DatabaseException {
- Validation.begin().isNotNull("Sone ID", id).check();
- synchronized (remoteSones) {
- return remoteSones.containsKey(id);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
public Sone getSone(String id, boolean create) throws DatabaseException {
- if (isLocalSone(id)) {
+ if (getLocalSone(id, false) != null) {
return getLocalSone(id, create);
}
return getRemoteSone(id, create);
Validation.begin().isNotNull("Sone ID", id).check();
synchronized (localSones) {
if (!localSones.containsKey(id) && create) {
- localSones.put(id, new Sone(id));
+ localSones.put(id, new Sone(id, true));
}
return localSones.get(id);
}
Validation.begin().isNotNull("Sone ID", id).check();
synchronized (remoteSones) {
if (!remoteSones.containsKey(id) && create) {
- remoteSones.put(id, new Sone(id));
+ remoteSones.put(id, new Sone(id, false));
}
return remoteSones.get(id);
}
*/
@Override
public void saveSone(Sone sone) throws DatabaseException {
- if (isLocalSone(sone)) {
+ if (sone.isLocal()) {
synchronized (localSones) {
localSones.put(sone.getId(), sone);
}
*/
@Override
public void removeSone(Sone sone) throws DatabaseException {
- Map<String, Sone> sones = isLocalSone(sone) ? localSones : remoteSones;
+ Map<String, Sone> sones = sone.isLocal() ? localSones : remoteSones;
synchronized (sones) {
sones.remove(sone.getId());
}
*/
@Override
public void removeSone(String id) throws DatabaseException {
- Map<String, Sone> sones = isLocalSone(id) ? localSones : remoteSones;
+ Map<String, Sone> sones = ((getSone(id, false) != null) && getSone(id, false).isLocal()) ? localSones : remoteSones;
synchronized (sones) {
sones.remove(id);
}
@Override
public Response execute(SimpleFieldSet parameters, Bucket data, AccessType accessType) throws FcpException {
Post post = getPost(parameters, "Post");
- if (!getCore().isLocalSone(post.getSone())) {
+ if (!post.getSone().isLocal()) {
return new ErrorResponse(401, "Not allowed.");
}
return new Response("PostDeleted", new SimpleFieldSetBuilder().get());
@Override
public Response execute(SimpleFieldSet parameters, Bucket data, AccessType accessType) throws FcpException {
PostReply reply = getReply(parameters, "Reply");
- if (!getCore().isLocalSone(reply.getSone())) {
+ if (!reply.getSone().isLocal()) {
return new ErrorResponse(401, "Not allowed.");
}
return new Response("ReplyDeleted", new SimpleFieldSetBuilder().get());
return null;
}
Sone remoteSone = profile.getSone();
- if (core.isLocalSone(remoteSone)) {
+ if (remoteSone.isLocal()) {
/* always show your own avatars. */
return avatarId;
}
Sone sone = (Sone) object;
if (member.equals("niceName")) {
return getNiceName(sone);
- } else if (member.equals("local")) {
- return core.isLocalSone(sone);
} else if (member.equals("friend")) {
Sone currentSone = (Sone) templateContext.get("currentSone");
return (currentSone != null) && currentSone.hasFriend(sone.getId());
* don’t use create=true above, we don’t want the
* empty shell.
*/
- sone = new Sone(soneId);
+ sone = new Sone(soneId, false);
}
parts.add(new SonePart(sone));
line = line.substring(50);
if (album == null) {
throw new RedirectException("invalid.html");
}
- if (!webInterface.getCore().isLocalSone(album.getSone())) {
+ if (!album.getSone().isLocal()) {
throw new RedirectException("noPermission.html");
}
if (request.getHttpRequest().isPartSet("abortDelete")) {
if (image == null) {
throw new RedirectException("invalid.html");
}
- if (!webInterface.getCore().isLocalSone(image.getSone())) {
+ if (!image.getSone().isLocal()) {
throw new RedirectException("noPermission.html");
}
if (request.getMethod() == Method.POST) {
String postId = request.getHttpRequest().getPartAsStringFailsafe("post", 36);
String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256);
Post post = webInterface.getCore().getPost(postId);
- if (!webInterface.getCore().isLocalSone(post.getSone())) {
+ if (!post.getSone().isLocal()) {
throw new RedirectException("noPermission.html");
}
if (request.getHttpRequest().isPartSet("confirmDelete")) {
PostReply reply = webInterface.getCore().getReply(replyId);
String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256);
if (request.getMethod() == Method.POST) {
- if (!webInterface.getCore().isLocalSone(reply.getSone())) {
+ if (!reply.getSone().isLocal()) {
throw new RedirectException("noPermission.html");
}
if (request.getHttpRequest().isPartSet("confirmDelete")) {
if (album == null) {
throw new RedirectException("invalid.html");
}
- if (!webInterface.getCore().isLocalSone(album.getSone())) {
+ if (!album.getSone().isLocal()) {
throw new RedirectException("noPermission.html");
}
if ("true".equals(request.getHttpRequest().getPartAsStringFailsafe("moveLeft", 4))) {
if (image == null) {
throw new RedirectException("invalid.html");
}
- if (!webInterface.getCore().isLocalSone(image.getSone())) {
+ if (!image.getSone().isLocal()) {
throw new RedirectException("noPermission.html");
}
if ("true".equals(request.getHttpRequest().getPartAsStringFailsafe("moveLeft", 4))) {
}
/**
- * Returns all {@link Core#isLocalSone(Sone) local Sone}s that are
- * referenced by {@link SonePart}s in the given text (after parsing it using
+ * Returns all {@link Core#getLocalSones() local Sone}s that are referenced
+ * by {@link SonePart}s in the given text (after parsing it using
* {@link SoneTextParser}).
*
* @param text
*/
@Override
public void newPostFound(Post post) {
- boolean isLocal = getCore().isLocalSone(post.getSone());
- if (isLocal) {
+ if (post.getSone().isLocal()) {
localPostNotification.add(post);
} else {
newPostNotification.add(post);
}
if (!hasFirstStartNotification()) {
- notificationManager.addNotification(isLocal ? localPostNotification : newPostNotification);
- if (!getMentionedSones(post.getText()).isEmpty() && !isLocal) {
+ notificationManager.addNotification(post.getSone().isLocal() ? localPostNotification : newPostNotification);
+ if (!getMentionedSones(post.getText()).isEmpty() && !post.getSone().isLocal()) {
mentionNotification.add(post);
notificationManager.addNotification(mentionNotification);
}
*/
@Override
public void newReplyFound(PostReply reply) {
- boolean isLocal = getCore().isLocalSone(reply.getSone());
- if (isLocal) {
+ if (reply.getSone().isLocal()) {
localReplyNotification.add(reply);
} else {
newReplyNotification.add(reply);
}
if (!hasFirstStartNotification()) {
- notificationManager.addNotification(isLocal ? localReplyNotification : newReplyNotification);
- if (!getMentionedSones(reply.getText()).isEmpty() && !isLocal && (reply.getPost().getSone() != null) && (reply.getTime() <= System.currentTimeMillis())) {
+ notificationManager.addNotification(reply.getSone().isLocal() ? localReplyNotification : newReplyNotification);
+ if (!getMentionedSones(reply.getText()).isEmpty() && !reply.getSone().isLocal() && (reply.getPost().getSone() != null) && (reply.getTime() <= System.currentTimeMillis())) {
mentionNotification.add(reply.getPost());
notificationManager.addNotification(mentionNotification);
}
if ((post == null) || (post.getSone() == null)) {
return createErrorJsonObject("invalid-post-id");
}
- if (!webInterface.getCore().isLocalSone(post.getSone())) {
+ if (!post.getSone().isLocal()) {
return createErrorJsonObject("not-authorized");
}
webInterface.getCore().deletePost(post);
if (reply == null) {
return createErrorJsonObject("invalid-reply-id");
}
- if (!webInterface.getCore().isLocalSone(reply.getSone())) {
+ if (!reply.getSone().isLocal()) {
return createErrorJsonObject("not-authorized");
}
webInterface.getCore().deleteReply(reply);
if (album == null) {
return createErrorJsonObject("invalid-album-id");
}
- if (!webInterface.getCore().isLocalSone(album.getSone())) {
+ if (!album.getSone().isLocal()) {
return createErrorJsonObject("not-authorized");
}
if ("true".equals(request.getHttpRequest().getParam("moveLeft"))) {
if (image == null) {
return createErrorJsonObject("invalid-image-id");
}
- if (!webInterface.getCore().isLocalSone(image.getSone())) {
+ if (!image.getSone().isLocal()) {
return createErrorJsonObject("not-authorized");
}
if ("true".equals(request.getHttpRequest().getParam("moveLeft"))) {
*/
@Override
public Sone getSone(final String soneId, boolean create) {
- return new Sone(soneId) {
+ return new Sone(soneId, false) {
/**
* {@inheritDoc}