182 lines
5.0 KiB
Java
Raw Normal View History

2012-10-04 20:48:01 -03:00
/*
2022-03-17 18:47:34 -03:00
* Copyright [2022] [wisemapping]
2022-01-18 13:16:39 -08: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.
*/
2012-10-04 20:48:01 -03:00
2012-03-15 01:21:46 -03:00
package com.wisemapping.rest.model;
2020-11-06 21:35:54 -08:00
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.wisemapping.model.*;
2012-06-12 11:23:47 -03:00
import com.wisemapping.security.Utils;
2012-09-15 11:35:53 -03:00
import com.wisemapping.util.TimeUtils;
2012-03-15 01:21:46 -03:00
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.Calendar;
2022-01-18 13:16:39 -08:00
import java.util.List;
import java.util.Optional;
2014-01-29 02:56:09 -03:00
import java.util.Set;
2022-01-18 13:16:39 -08:00
import java.util.stream.Collectors;
2012-03-15 01:21:46 -03:00
@XmlRootElement(name = "mapinfo")
2012-03-15 01:21:46 -03:00
@XmlAccessorType(XmlAccessType.PROPERTY)
@JsonAutoDetect(
fieldVisibility = JsonAutoDetect.Visibility.NONE,
setterVisibility = JsonAutoDetect.Visibility.PUBLIC_ONLY,
isGetterVisibility = JsonAutoDetect.Visibility.NONE,
getterVisibility = JsonAutoDetect.Visibility.PUBLIC_ONLY
)
@JsonIgnoreProperties(ignoreUnknown = true)
public class RestMindmapInfo {
2022-01-18 13:16:39 -08:00
public static final String ROLE_NONE = "none";
2012-03-15 01:21:46 -03:00
@JsonIgnore
private final Mindmap mindmap;
2022-01-18 13:16:39 -08:00
@JsonIgnore
private Set<RestLabel> restLabels;
@JsonIgnore
private int mapId = -1;
private final Collaborator collaborator;
2012-03-15 01:21:46 -03:00
public RestMindmapInfo() {
this(new Mindmap(), null);
2012-03-15 01:21:46 -03:00
}
public RestMindmapInfo(@NotNull Mindmap mindmap, @Nullable Collaborator collaborator) {
2012-03-15 01:21:46 -03:00
this.mindmap = mindmap;
this.collaborator = collaborator;
2012-03-15 01:21:46 -03:00
}
2022-01-18 13:16:39 -08:00
public void setCreationTime(String value) {
2014-01-25 04:21:59 -03:00
// Ignore
}
public String getCreationTime() {
2014-01-25 03:13:51 -03:00
final Calendar creationTime = mindmap.getCreationTime();
return creationTime != null ? TimeUtils.toISO8601(creationTime.getTime()) : null;
2012-03-15 01:21:46 -03:00
}
public String getDescription() {
return mindmap.getDescription();
}
2014-01-25 03:13:51 -03:00
public void setDescription(String description) {
mindmap.setDescription(description);
}
2012-03-15 01:21:46 -03:00
public String getTitle() {
return mindmap.getTitle();
}
2014-01-25 03:13:51 -03:00
public void setTitle(String title) {
mindmap.setTitle(title);
}
2022-01-18 13:16:39 -08:00
public Set<RestLabel> getLabels() {
// Support test deserialization...
Set<RestLabel> result = this.restLabels;
if(result==null) {
final User me = Utils.getUser();
result = mindmap.getLabels().
stream()
.filter(l -> l.getCreator().equals(me))
.map(RestLabel::new)
.collect(Collectors.toSet());
}
return result;
}
public void setLabels(Set<RestLabel> restLabels) {
this.restLabels = restLabels;
}
2014-01-25 03:13:51 -03:00
2012-03-15 01:21:46 -03:00
public int getId() {
2022-01-18 13:16:39 -08:00
int result = this.mapId;
if(mapId==-1) {
result = mindmap.getId();
}
return result;
2012-03-15 01:21:46 -03:00
}
2014-01-25 03:13:51 -03:00
public void setId(int id) {
2022-01-18 13:16:39 -08:00
this.mapId = id;
2014-01-25 03:13:51 -03:00
}
2012-03-15 01:21:46 -03:00
public String getCreator() {
2014-01-25 03:13:51 -03:00
final User creator = mindmap.getCreator();
2022-01-18 13:16:39 -08:00
return creator != null ? creator.getFullName() : null;
2014-01-25 03:13:51 -03:00
}
public void setCreator(String email) {
2012-03-15 01:21:46 -03:00
}
2012-06-12 11:23:47 -03:00
public void setCreator() {
// Do nothing ...
2012-05-20 21:46:55 -03:00
}
2012-06-12 11:23:47 -03:00
public String getRole() {
2022-01-18 13:16:39 -08:00
final Optional<Collaboration> collaboration = mindmap.findCollaboration(Utils.getUser());
return collaboration.map(value -> value.getRole().getLabel()).orElse(ROLE_NONE);
2012-06-12 11:23:47 -03:00
}
2014-01-25 04:21:59 -03:00
public void setRole(String value) {
2012-06-12 11:23:47 -03:00
// Do nothing ...
2012-05-20 21:46:55 -03:00
}
2012-03-15 01:21:46 -03:00
public String getLastModifierUser() {
2012-07-15 00:57:44 -03:00
final User user = mindmap.getLastEditor();
return user != null ? user.getFullName() : "unknown";
2012-03-15 01:21:46 -03:00
}
2014-01-25 03:13:51 -03:00
public void setLastModifierUser(String value) {
}
public String getLastModificationTime() {
final Calendar calendar = mindmap.getLastModificationTime();
2022-01-18 13:16:39 -08:00
return calendar != null ? TimeUtils.toISO8601(calendar.getTime()) : null;
2012-03-15 01:21:46 -03:00
}
2014-01-25 03:13:51 -03:00
public void setLastModificationTime(String value) {
2012-03-15 01:21:46 -03:00
}
public boolean getPublic() {
2014-01-25 03:13:51 -03:00
return mindmap.isPublic();
}
public boolean getStarred() {
return mindmap.isStarred(collaborator);
}
2014-01-25 04:21:59 -03:00
public void setStarred(boolean value) {
2012-03-15 01:21:46 -03:00
}
2012-03-15 21:13:47 -03:00
@JsonIgnore
public Mindmap getDelegated() {
2012-03-15 21:13:47 -03:00
return this.mindmap;
}
2012-03-15 01:21:46 -03:00
}