162 lines
4.8 KiB
Java
Raw Normal View History

/*
* Copyright [2011] [wisemapping]
*
2011-01-23 21:03:12 -03:00
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
* It is basically the Apache License, Version 2.0 (the "License") plus the
* "powered by wisemapping" text requirement on every single page;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the license at
*
* http://www.wisemapping.org/license
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
2009-06-07 18:59:43 +00:00
package com.wisemapping.view;
import com.wisemapping.exceptions.WiseMappingException;
import com.wisemapping.model.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
2009-06-07 18:59:43 +00:00
2012-06-17 02:51:01 -03:00
import java.io.IOException;
2009-06-07 18:59:43 +00:00
import java.text.DateFormat;
import java.util.*;
public class MindMapBean {
private MindMap mindmap;
private List<CollaboratorBean> viewers;
private List<CollaboratorBean> collaborators;
private Collaborator collaborator;
2009-06-07 18:59:43 +00:00
public MindMapBean(@NotNull final MindMap mindmap, @Nullable final Collaborator collaborator) {
this.mindmap = mindmap;
this.collaborator = collaborator;
this.collaborators = filterCollaboratorBy(mindmap.getCollaborations(), CollaborationRole.EDITOR);
2012-06-17 02:51:01 -03:00
this.viewers = filterCollaboratorBy(mindmap.getCollaborations(), CollaborationRole.VIEWER);
2009-06-07 18:59:43 +00:00
}
public boolean getPublic() {
return mindmap.isPublic();
2009-06-07 18:59:43 +00:00
}
public String getTitle() {
return mindmap.getTitle();
2009-06-07 18:59:43 +00:00
}
public String getDescription() {
return mindmap.getDescription();
2009-06-07 18:59:43 +00:00
}
public int getId() {
return mindmap.getId();
2009-06-07 18:59:43 +00:00
}
2012-06-06 00:48:46 -03:00
public boolean isStarred() {
return mindmap.isStarred(collaborator);
2012-06-06 00:48:46 -03:00
}
public List<CollaboratorBean> getViewers() {
2009-06-07 18:59:43 +00:00
return viewers;
}
public List<CollaboratorBean> getCollaborators() {
return collaborators;
2009-06-07 18:59:43 +00:00
}
public String getLastEditor() {
return mindmap.getLastModifierUser();
2009-06-07 18:59:43 +00:00
}
2012-05-20 02:25:54 -03:00
public String getLastEditTime() {
return DateFormat.getInstance().format(mindmap.getLastModificationTime().getTime());
2009-06-07 18:59:43 +00:00
}
public String getCreationTime() {
return DateFormat.getInstance().format(mindmap.getCreationTime().getTime());
2009-06-07 18:59:43 +00:00
}
public String getTags() {
return mindmap.getTags();
2009-06-07 18:59:43 +00:00
}
2012-06-17 02:51:01 -03:00
private List<CollaboratorBean> filterCollaboratorBy(Set<Collaboration> source, CollaborationRole role) {
List<CollaboratorBean> col = new ArrayList<CollaboratorBean>();
2009-06-07 18:59:43 +00:00
if (source != null) {
2012-06-09 15:49:19 -03:00
for (Collaboration mu : source) {
2009-06-07 18:59:43 +00:00
if (mu.getRole() == role) {
col.add(new CollaboratorBean(mu.getCollaborator(), mu.getRole()));
2009-06-07 18:59:43 +00:00
}
}
}
return col;
}
2012-06-17 02:51:01 -03:00
public int getCountCollaborators() {
return collaborators != null ? collaborators.size() : 0;
2009-06-07 18:59:43 +00:00
}
public int getCountViewers() {
return viewers != null ? viewers.size() : 0;
}
public int getCountShared() {
2012-06-17 02:51:01 -03:00
return getCountCollaborators() + getCountViewers();
2009-06-07 18:59:43 +00:00
}
public boolean isShared() {
return getCountShared() > 0;
}
public void setTitle(String t) {
mindmap.setTitle(t);
2009-06-07 18:59:43 +00:00
}
public void setDescription(String d) {
mindmap.setDescription(d);
2009-06-07 18:59:43 +00:00
}
2012-06-17 02:51:01 -03:00
public String getXmlAsJsLiteral() throws IOException {
return this.mindmap.getXmlAsJsLiteral();
2012-06-17 02:51:01 -03:00
}
public String getProperties() throws WiseMappingException {
String result;
if (collaborator != null) {
final CollaborationProperties properties = this.mindmap.findCollaborationProperties(collaborator);
result = properties.getMindmapProperties();
} else {
// It must be public view ...
result = CollaborationProperties.DEFAULT_JSON_PROPERTIES;
}
return result;
2012-06-17 02:51:01 -03:00
}
2012-06-12 11:23:47 -03:00
public User getCreator() {
return mindmap.getCreator();
2009-06-07 18:59:43 +00:00
}
2012-06-17 02:51:01 -03:00
public boolean isOwner() {
return mindmap.hasPermissions(collaborator, CollaborationRole.OWNER);
2012-06-17 02:51:01 -03:00
}
public boolean isEditor() {
return mindmap.hasPermissions(collaborator, CollaborationRole.EDITOR);
}
2012-06-17 22:48:33 -03:00
public String getRole() {
final Collaboration collaboration = this.mindmap.findCollaboration(collaborator);
return collaboration.getRole().getLabel();
}
public MindMap getDelegated() {
return mindmap;
}
2009-06-07 18:59:43 +00:00
}