Fix toolbar title bug

Add properties peer user.
This commit is contained in:
Paulo Gustavo Veiga 2012-06-17 21:43:34 -03:00
parent c73934aadf
commit 521111fac2
20 changed files with 127 additions and 104 deletions

View File

@ -47,7 +47,7 @@ div#headerActions a {
}
div#headerMapTitle {
width: 200px;
min-width: 200px;
height:@header-info-height - 13;
text-align: left;
padding-top: 13px;
@ -65,6 +65,7 @@ div#headerMapTitle span {
-webkit-border-radius: 3px;
border-radius: 3px;
box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.2);
white-space:nowrap;
}
div#headerNotifier {

View File

@ -27,13 +27,13 @@ public interface MindmapManager {
Collaborator getCollaboratorBy(@NotNull String email);
Collaborator getCollaboratorBy(long id);
Collaborator findCollaborator(long id);
List<Collaboration> getMindmapUserByCollaborator(final long collaboratorId);
List<Collaboration> findCollaboration(final long collaboratorId);
List<Collaboration> getMindmapUserByRole(final CollaborationRole userRole);
List<Collaboration> findCollaboration(final CollaborationRole userRole);
Collaboration getMindmapUserBy(final int mindmapId, final User user);
Collaboration findCollaboration(final int mindmapId, final User user);
List<MindMap> getAllMindmaps();

View File

@ -109,25 +109,25 @@ public class MindmapManagerImpl
}
@Override
public Collaborator getCollaboratorBy(long id) {
public Collaborator findCollaborator(long id) {
return getHibernateTemplate().get(Collaborator.class, id);
}
@Override
public List<Collaboration> getMindmapUserByCollaborator(final long colaboratorId) {
return getHibernateTemplate().find("from com.wisemapping.model.Collaboration mindmapUser where colaborator_id=?", colaboratorId);
public List<Collaboration> findCollaboration(final long collaboratorId) {
return getHibernateTemplate().find("from com.wisemapping.model.Collaboration collaboration where colaborator_id=?", collaboratorId);
}
@Override
public List<Collaboration> getMindmapUserByRole(final CollaborationRole collaborationRole) {
return getHibernateTemplate().find("from com.wisemapping.model.Collaboration mindmapUser where roleId=?", collaborationRole.ordinal());
public List<Collaboration> findCollaboration(final CollaborationRole collaborationRole) {
return getHibernateTemplate().find("from com.wisemapping.model.Collaboration collaboration where roleId=?", collaborationRole.ordinal());
}
@Override
public Collaboration getMindmapUserBy(final int mindmapId, final User user) {
public Collaboration findCollaboration(final int mindmapId, final User user) {
final Collaboration result;
final List<Collaboration> mindMaps = getHibernateTemplate().find("from com.wisemapping.model.Collaboration mindmapUser where mindMap.id=? and colaborator_id=?", new Object[]{mindmapId, user.getId()});
final List<Collaboration> mindMaps = getHibernateTemplate().find("from com.wisemapping.model.Collaboration collaboration where mindMap.id=? and colaborator_id=?", new Object[]{mindmapId, user.getId()});
if (mindMaps != null && !mindMaps.isEmpty()) {
result = mindMaps.get(0);
} else {

View File

@ -82,8 +82,14 @@ public class Collaboration {
this.collaborator = collaborator;
}
@NotNull
public CollaborationProperties getCollaborationProperties() {
return collaborationProperties;
CollaborationProperties result = collaborationProperties;
if (result == null) {
collaborationProperties = new CollaborationProperties();
result = collaborationProperties;
}
return result;
}
public void setCollaborationProperties(@NotNull CollaborationProperties collaborationProperties) {

View File

@ -18,11 +18,15 @@
package com.wisemapping.model;
import org.jetbrains.annotations.NotNull;
public class CollaborationProperties {
private static final String DEFAULT_JSON_PROPERTIES = "{zoom:0.8}";
private int id;
private boolean starred;
private String mindmapProperties;
public CollaborationProperties(){
public CollaborationProperties() {
}
@ -41,4 +45,13 @@ public class CollaborationProperties {
public void setId(int id) {
this.id = id;
}
@NotNull
public String getMindmapProperties() {
return mindmapProperties == null ? DEFAULT_JSON_PROPERTIES : mindmapProperties;
}
public void setMindmapProperties(@NotNull String mindmapProperties) {
this.mindmapProperties = mindmapProperties;
}
}

View File

@ -92,21 +92,6 @@ public class MindMap {
this.xml = ZipUtils.zipToString(xml).getBytes(UTF_8);
}
public void setProperties(String properties) {
this.properties = properties;
}
public String getProperties() {
String ret;
if (properties == null) {
ret = "{zoom:0.85,saveOnLoad:true}";
} else {
ret = properties;
}
return ret;
}
public Set<Collaboration> getCollaborations() {
return collaborations;
}
@ -237,6 +222,12 @@ public class MindMap {
}
public void setStarred(@NotNull Collaborator collaborator, boolean value) throws WiseMappingException {
final CollaborationProperties collaborationProperties = getCollaborationProperties(collaborator);
collaborationProperties.setStarred(value);
}
@NotNull
public CollaborationProperties getCollaborationProperties(@NotNull Collaborator collaborator) throws WiseMappingException {
if (collaborator == null) {
throw new IllegalStateException("Collaborator can not be null");
}
@ -245,11 +236,7 @@ public class MindMap {
if (collaboration == null) {
throw new WiseMappingException("User is not collaborator");
}
if (collaboration.getCollaborationProperties() == null) {
collaboration.setCollaborationProperties(new CollaborationProperties());
}
collaboration.getCollaborationProperties().setStarred(value);
return collaboration.getCollaborationProperties();
}
public boolean isStarred(@NotNull Collaborator collaborator) {
@ -271,7 +258,6 @@ public class MindMap {
final MindMap result = new MindMap();
result.setDescription(this.getDescription());
result.setTitle(this.getTitle());
result.setProperties(this.getProperties());
result.setXml(this.getXml());
result.setTags(this.getTags());

View File

@ -174,7 +174,7 @@ public class MindmapController {
}
private MindMapBean findMindmapBean(long mapId) {
return new MindMapBean(findMindmap(mapId));
return new MindMapBean(findMindmap(mapId), Utils.getUser());
}
private boolean isWelcomeMap(MindMapBean map) {

View File

@ -21,6 +21,7 @@ package com.wisemapping.rest;
import com.wisemapping.rest.model.RestErrors;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
@ -29,6 +30,7 @@ import org.springframework.web.bind.annotation.ResponseStatus;
public class BaseController {
@Qualifier("messageSource")
@Autowired
private ResourceBundleMessageSource messageSource;
@ -36,6 +38,7 @@ public class BaseController {
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody
public RestErrors handleClientErrors(@NotNull IllegalArgumentException ex) {
ex.printStackTrace();
return new RestErrors(ex.getMessage());
}

View File

@ -89,7 +89,7 @@ public class MindmapController extends BaseController {
final User user = Utils.getUser();
final MindmapFilter filter = MindmapFilter.parse(q);
final List<Collaboration> collaborations = mindmapService.findCollaborationsBy(user);
final List<Collaboration> collaborations = mindmapService.findCollaborations(user);
final List<MindMap> mindmaps = new ArrayList<MindMap>();
for (Collaboration collaboration : collaborations) {
@ -125,7 +125,7 @@ public class MindmapController extends BaseController {
@ResponseStatus(value = HttpStatus.NO_CONTENT)
public void updateDocument(@RequestBody RestMindmap restMindmap, @PathVariable int id, @RequestParam(required = false) boolean minor) throws IOException, WiseMappingException {
final MindMap mindMap = mindmapService.findMindmapById(id);
final MindMap mindmap = mindmapService.findMindmapById(id);
final User user = Utils.getUser();
// Validate arguments ...
@ -133,17 +133,20 @@ public class MindmapController extends BaseController {
if (properties == null) {
throw new IllegalArgumentException("Map properties can not be null");
}
mindMap.setProperties(properties);
// Update collaboration properties ...
final CollaborationProperties collaborationProperties = mindmap.getCollaborationProperties(user);
collaborationProperties.setMindmapProperties(properties);
// Validate content ...
final String xml = restMindmap.getXml();
if (xml == null) {
throw new IllegalArgumentException("Map xml can not be null");
}
mindMap.setXmlStr(xml);
mindmap.setXmlStr(xml);
// Update map ...
saveMindmap(minor, mindMap, user);
saveMindmap(minor, mindmap, user);
}
/**
@ -153,41 +156,43 @@ public class MindmapController extends BaseController {
@ResponseStatus(value = HttpStatus.NO_CONTENT)
public void update(@RequestBody RestMindmap restMindmap, @PathVariable int id, @RequestParam(required = false) boolean minor) throws IOException, WiseMappingException {
final MindMap mindMap = mindmapService.findMindmapById(id);
final MindMap mindmap = mindmapService.findMindmapById(id);
final User user = Utils.getUser();
// Update document properties ...
final String properties = restMindmap.getProperties();
if (properties != null) {
mindMap.setProperties(properties);
}
final String xml = restMindmap.getXml();
if (xml != null) {
mindMap.setXmlStr(xml);
mindmap.setXmlStr(xml);
}
// Update title ...
final String title = restMindmap.getTitle();
if (title != null && !title.equals(mindMap.getTitle())) {
if (title != null && !title.equals(mindmap.getTitle())) {
if (mindmapService.getMindmapByTitle(title, user) != null) {
throw buildValidationException("title", "You already have a map with this title");
}
mindMap.setTitle(title);
mindmap.setTitle(title);
}
// Update description ...
final String description = restMindmap.getDescription();
if (description != null) {
mindMap.setDescription(description);
mindmap.setDescription(description);
}
final String tags = restMindmap.getTags();
if (tags != null) {
mindMap.setTags(tags);
mindmap.setTags(tags);
}
// Update document properties ...
final String properties = restMindmap.getProperties();
if (properties != null) {
final CollaborationProperties collaborationProperties = mindmap.getCollaborationProperties(user);
collaborationProperties.setMindmapProperties(properties);
}
// Update map ...
saveMindmap(minor, mindMap, user);
saveMindmap(minor, mindmap, user);
}

View File

@ -46,6 +46,7 @@ public class RestErrors {
}
public RestErrors(@NotNull String errorMsg) {
globalErrors = new ArrayList<String>();
globalErrors.add(errorMsg);
}
@ -68,9 +69,11 @@ public class RestErrors {
public Map<String, String> getFieldErrors() {
final Map<String, String> result = new HashMap<String, String>();
final List<FieldError> fieldErrors = errors.getFieldErrors();
for (FieldError fieldError : fieldErrors) {
result.put(fieldError.getField(), messageSource.getMessage(fieldError, Locale.ENGLISH));
if (errors != null) {
final List<FieldError> fieldErrors = errors.getFieldErrors();
for (FieldError fieldError : fieldErrors) {
result.put(fieldError.getField(), messageSource.getMessage(fieldError, Locale.ENGLISH));
}
}
return result;
}

View File

@ -2,9 +2,8 @@ package com.wisemapping.rest.model;
import com.wisemapping.exceptions.WiseMappingException;
import com.wisemapping.model.Collaborator;
import com.wisemapping.model.MindMap;
import com.wisemapping.model.User;
import com.wisemapping.model.*;
import com.wisemapping.security.Utils;
import org.codehaus.jackson.annotate.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -32,22 +31,28 @@ public class RestMindmap {
private MindMap mindmap;
@JsonIgnore
static private SimpleDateFormat sdf;
private String properties;
static {
sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
}
public RestMindmap() {
public RestMindmap() throws WiseMappingException {
this(new MindMap(), null);
}
public RestMindmap(@NotNull MindMap mindmap, @Nullable Collaborator collaborator) {
public RestMindmap(@NotNull MindMap mindmap, @Nullable Collaborator collaborator) throws WiseMappingException {
this.mindmap = mindmap;
this.collaborator = collaborator;
if (collaborator != null) {
final CollaborationProperties collaborationProperties = mindmap.getCollaborationProperties(collaborator);
this.properties = collaborationProperties.getMindmapProperties();
}
}
public String getCreationTime() {
final Calendar creationTime = mindmap.getCreationTime();
String result = null;
@ -139,8 +144,8 @@ public class RestMindmap {
}
public void setProperties(String properties) {
mindmap.setProperties(properties);
public void setProperties(@Nullable String properties) {
this.properties = properties;
}
public void setLastModificationTime(final String value) {
@ -150,7 +155,7 @@ public class RestMindmap {
}
public String getProperties() {
return mindmap.getProperties();
return properties;
}
public boolean getStarred() {

View File

@ -34,7 +34,7 @@ public interface MindmapService {
public MindMap getMindmapByTitle(String title, User user);
public List<Collaboration> findCollaborationsBy(@NotNull User user);
public List<Collaboration> findCollaborations(@NotNull User user);
public void updateMindmap(MindMap mindMap, boolean saveHistory) throws WiseMappingException;
@ -43,7 +43,7 @@ public interface MindmapService {
public void addCollaboration(@NotNull MindMap mindmap, @NotNull String email, @NotNull CollaborationRole role, @Nullable String message)
throws CollaborationException;
public void removeCollaboration(@NotNull MindMap mindmap, @NotNull Collaboration collaboration) throws CollaborationException;
public void removeCollaboration(@NotNull MindMap mindmap, @NotNull Collaboration collaboration) throws CollaborationException;
public void addTags(@NotNull MindMap mindmap, String tags);

View File

@ -78,8 +78,8 @@ public class MindmapServiceImpl
}
@Override
public List<Collaboration> findCollaborationsBy(@NotNull User user) {
return mindmapManager.getMindmapUserByCollaborator(user.getId());
public List<Collaboration> findCollaborations(@NotNull User user) {
return mindmapManager.findCollaboration(user.getId());
}
@Override

View File

@ -18,45 +18,46 @@
package com.wisemapping.view;
import com.wisemapping.model.Collaboration;
import com.wisemapping.model.CollaborationRole;
import com.wisemapping.model.MindMap;
import com.wisemapping.model.User;
import com.wisemapping.security.Utils;
import com.wisemapping.exceptions.WiseMappingException;
import com.wisemapping.model.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.text.DateFormat;
import java.util.*;
public class MindMapBean {
private MindMap mindMap;
private MindMap mindmap;
private List<CollaboratorBean> viewers;
private List<CollaboratorBean> collaborators;
private Collaborator collaborator;
public MindMapBean(final MindMap mindmap) {
this.mindMap = mindmap;
public MindMapBean(@NotNull final MindMap mindmap, @Nullable final Collaborator collaborator) {
this.mindmap = mindmap;
this.collaborator = collaborator;
this.collaborators = filterCollaboratorBy(mindmap.getCollaborations(), CollaborationRole.EDITOR);
this.viewers = filterCollaboratorBy(mindmap.getCollaborations(), CollaborationRole.VIEWER);
}
public boolean getPublic() {
return mindMap.isPublic();
return mindmap.isPublic();
}
public String getTitle() {
return mindMap.getTitle();
return mindmap.getTitle();
}
public String getDescription() {
return mindMap.getDescription();
return mindmap.getDescription();
}
public int getId() {
return mindMap.getId();
return mindmap.getId();
}
public boolean isStarred() {
return mindMap.isStarred(Utils.getUser());
return mindmap.isStarred(collaborator);
}
public List<CollaboratorBean> getViewers() {
@ -68,19 +69,19 @@ public class MindMapBean {
}
public String getLastEditor() {
return mindMap.getLastModifierUser();
return mindmap.getLastModifierUser();
}
public String getLastEditTime() {
return DateFormat.getInstance().format(mindMap.getLastModificationTime().getTime());
return DateFormat.getInstance().format(mindmap.getLastModificationTime().getTime());
}
public String getCreationTime() {
return DateFormat.getInstance().format(mindMap.getCreationTime().getTime());
return DateFormat.getInstance().format(mindmap.getCreationTime().getTime());
}
public String getTags() {
return mindMap.getTags();
return mindmap.getTags();
}
private List<CollaboratorBean> filterCollaboratorBy(Set<Collaboration> source, CollaborationRole role) {
@ -112,35 +113,36 @@ public class MindMapBean {
}
public void setTitle(String t) {
mindMap.setTitle(t);
mindmap.setTitle(t);
}
public void setDescription(String d) {
mindMap.setDescription(d);
mindmap.setDescription(d);
}
public String getXmlAsJsLiteral() throws IOException {
return this.mindMap.getXmlAsJsLiteral();
return this.mindmap.getXmlAsJsLiteral();
}
public String getProperties() {
return this.mindMap.getProperties();
public String getProperties() throws WiseMappingException {
final CollaborationProperties collaboration = this.mindmap.getCollaborationProperties(collaborator);
return collaboration.getMindmapProperties();
}
public User getCreator() {
return mindMap.getCreator();
return mindmap.getCreator();
}
public boolean isOwner() {
return mindMap.hasPermissions(Utils.getUser(), CollaborationRole.OWNER);
return mindmap.hasPermissions(collaborator, CollaborationRole.OWNER);
}
public boolean isEditor() {
return mindMap.hasPermissions(Utils.getUser(), CollaborationRole.EDITOR);
return mindmap.hasPermissions(collaborator, CollaborationRole.EDITOR);
}
public MindMap getDelegated(){
return mindMap;
public MindMap getDelegated() {
return mindmap;
}
}

View File

@ -9,6 +9,7 @@
<id name="id">
<generator class="increment"/>
</id>
<property name="mindmapProperties" column="mindmap_properties" unique="false" not-null="false"/>
<property name="starred" column="starred" unique="false" not-null="true"/>
</class>

View File

@ -17,8 +17,6 @@
<property name="lastModificationTime" column="edition_date"/>
<property name="creationTime" column="creation_date"/>
<property name="tags" column="tags"/>
<property name="properties" column="editor_properties"/>
<many-to-one name="creator" column="creator_id" unique="true" not-null="true"/>
<set name="collaborations"

View File

@ -1,6 +1,6 @@
log4j.rootLogger=WARN, stdout, R
log4j.logger.com.wisemapping=WARN,stdout,R
log4j.logger.org.springframework=DEBUG,stdout,R
log4j.logger.org.springframework=WARN,stdout,R
log4j.logger.org.codehaus.jackson=WARN,stdout,R
log4j.additivity.org.hibernate.SQL=false

View File

@ -70,7 +70,7 @@
<spring:message code="LOGOUT"/>
</a></span>
</div>
<a href="${pageContext.request.contextPath}/c/maps/">
<a href="c/maps/">
<div id="headerLogo"></div>
</a>

View File

@ -27,7 +27,6 @@ edition_date DATETIME,
creator_id INTEGER NOT NULL,
tags varchar(1014) ,
last_editor varchar(255) ,
editor_properties varchar(512)
--FOREIGN KEY(creator_id) REFERENCES USER(colaborator_id)
);
@ -40,13 +39,14 @@ creator_user varchar(255));
CREATE TABLE COLLABORATION_PROPERTIES
(id INTEGER NOT NULL IDENTITY,
starred BOOLEAN NOT NULL
starred BOOLEAN NOT NULL,
mindmap_properties varchar(512)
);
CREATE TABLE COLLABORATION
(id INTEGER NOT NULL IDENTITY,
colaborator_id INTEGER NOT NULL,
properties_id INTEGER,
properties_id INTEGER NOT NULL,
mindmap_id INTEGER NOT NULL,
role_id INTEGER NOT NULL,
FOREIGN KEY(colaborator_id) REFERENCES COLABORATOR(id),

View File

@ -28,7 +28,6 @@ edition_date datetime,
creator_id INTEGER not null,
tags varchar(1014) CHARACTER SET utf8 ,
last_editor varchar(255) CHARACTER SET utf8 ,
editor_properties varchar(512) CHARACTER SET utf8 ,
FOREIGN KEY(creator_id) REFERENCES USER(colaborator_id)
) CHARACTER SET utf8 ;
@ -43,7 +42,8 @@ creator_user varchar(255) CHARACTER SET utf8
CREATE TABLE COLLABORATION_PROPERTIES(
id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
starred BOOL NOT NULL default 0
starred BOOL NOT NULL default 0,
mindmap_properties varchar(512) CHARACTER SET utf8
) CHARACTER SET utf8;
CREATE TABLE COLLABORATION (