Skip to content
This repository has been archived by the owner on Jan 15, 2022. It is now read-only.

Commit

Permalink
Implement new Calendar REST API
Browse files Browse the repository at this point in the history
  • Loading branch information
Tran The Trong committed Apr 22, 2015
1 parent a34a79b commit 64db672
Show file tree
Hide file tree
Showing 63 changed files with 9,494 additions and 1,255 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@
*/

public class Attachment {
private static final Log log = ExoLogger.getExoLogger(Attachment.class);

private static final Log log = ExoLogger.getExoLogger(Attachment.class);

private String id;

private String name;
Expand Down Expand Up @@ -95,17 +96,21 @@ public void setName(String name_) {
this.name = name_;
}

public String getDataPath() throws Exception {
Node attachmentData;
public String getDataPath() {
try {
attachmentData = (Node) getSesison().getItem(getId());
} catch (ItemNotFoundException e) {
if(getSesison() != null) {
Node attachmentData = (Node) getSesison().getItem(getId());
if(attachmentData != null) {
return attachmentData.getPath();
}
}
} catch (Exception e) {
if (log.isDebugEnabled()) {
log.debug("The attachment note is not exist", e);
}
return null;

}
return attachmentData.getPath();
return null;
}

private Session getSesison() throws Exception {
Expand Down Expand Up @@ -153,14 +158,14 @@ public String getWorkspace() {

/**
* keep id to make sure temp file will be removed after use uploaded file
*/
*/
public void setResourceId(String resourceId) {
this.resourceId = resourceId;
}

/**
* get id to call download service remove temp file
*/
*/
public String getResourceId() {
return resourceId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,44 @@
*/
public class Calendar {

public enum Type {

PERSONAL(0),

SHARED(1),

GROUP(2),

UNDEFINED(-1);

private final int type;

Type(int type) {
this.type = type;
}

public int type() {
return type;
}

public Type getType(int type) {
for (Type t : Type.values()) {
if (t.type() == type) {
return t;
}
}

return UNDEFINED;
}
}

public static final int TYPE_PRIVATE = 0;

public static final int TYPE_SHARED = 1;

public static final int TYPE_PUBLIC = 2;

public static final int TYPE_ALL = -1;

public static final String N_ASPARAGUS = "asparagus";

Expand Down Expand Up @@ -91,8 +124,6 @@ public class Calendar {

private String name;

private String calendarPath;

private String calendarColor = N_POWDER_BLUE;

private String description;
Expand All @@ -107,20 +138,21 @@ public class Calendar {

private String[] editPermission;

private boolean isDataInit = false;

private boolean isPublic = false;

@Deprecated
private String categoryId;

private String[] groups;

private String publicUrl;

private String privateUrl;

public static final String CALENDAR_PREF = "calendar".intern();
private String _calendarPath;

private boolean _isDataInit = false;

private boolean _isPublic = false;

private int _calType;

public static final String CALENDAR_PREF = "calendar";

public Calendar() {
id = CALENDAR_PREF + IdGenerator.generate();
Expand All @@ -145,11 +177,11 @@ public void setName(String name) {
}

public String getCalendarPath() {
return calendarPath;
return _calendarPath;
}

public void setCalendarPath(String path) {
this.calendarPath = path;
this._calendarPath = path;
}

public String getDescription() {
Expand Down Expand Up @@ -184,22 +216,12 @@ public void setGroups(String[] groups) {
this.groups = groups;
}

@Deprecated
public String getCategoryId() {
return categoryId;
}

@Deprecated
public void setCategoryId(String categoryId) {
this.categoryId = categoryId;
}

public boolean isPublic() {
return isPublic;
return _isPublic;
}

public void setPublic(boolean isPublic) {
this.isPublic = isPublic;
this._isPublic = isPublic;
}

public void setTimeZone(String timeZone) {
Expand Down Expand Up @@ -227,11 +249,11 @@ public String getCalendarColor() {
}

public void setDataInit(boolean isDataInit) {
this.isDataInit = isDataInit;
this._isDataInit = isDataInit;
}

public boolean isDataInit() {
return isDataInit;
return _isDataInit;
}

public void setCalendarOwner(String calendarOwner) {
Expand Down Expand Up @@ -285,4 +307,12 @@ public int hashCode()
{
return id.hashCode();
}

public int getCalType() {
return _calType;
}

public void setCalType(int calType) {
this._calType = calType;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (C) 2003-2014 eXo Platform SAS.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.exoplatform.calendar.service;

import java.util.ArrayList;
import java.util.Collection;

public class CalendarCollection<T> extends ArrayList<T> {
private static final long serialVersionUID = -2525910004085477043L;
private long fullSize;
private long size;

public long getFullSize() {
return fullSize;
}

public void setFullSize(long fullSize) {
this.fullSize = fullSize;
}

public CalendarCollection(Collection<T> list, long fullSize){
addAll(list);
this.size = list.size();
this.fullSize = fullSize;
}

public long getSize() {
return size;
}

public void setSize(long size) {
this.size = size;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
Expand All @@ -33,7 +37,6 @@
* Jul 11, 2007
*/
public class CalendarEvent {

final public static String TYPE_EVENT = "Event".intern();

final public static String TYPE_TASK = "Task".intern();
Expand Down Expand Up @@ -750,4 +753,77 @@ public String getActivityId() {
public void setActivityId(String activityId) {
this.activityId = activityId;
}

public void addParticipant(String parName, String status) {
List<String> pars = new LinkedList<String>();
if (this.getParticipant() != null) {
pars.addAll(Arrays.asList(this.getParticipant()));
}

if (!pars.contains(parName)) {
pars.add(parName);
setParticipant(pars.toArray(new String[pars.size()]));

Map<String, String> statusMap = getStatusMap();
if (statusMap.isEmpty()) {
statusMap = new HashMap<String, String>();
}
statusMap.put(parName, status);
setStatusMap(statusMap);
}
}

public void removeParticipant(String parName) {
if (this.getParticipant() == null) {
return;
}

List<String> parList = new LinkedList<String>(Arrays.asList(this.getParticipant()));
parList.remove(parName);
this.setParticipant(parList.toArray(new String[parList.size()]));

Map<String, String> statusMap = getStatusMap();
statusMap.remove(parName);
this.setStatusMap(statusMap);
}

public Invitation[] getInvitations() {
if (this.getParticipant() == null) {
return new Invitation[0];
}
Invitation[] invitations = new Invitation[this.getParticipant().length];

int i = 0;
Map<String, String> parStatus = getStatusMap();
for (String par : this.getParticipant()) {
invitations[i++] = new Invitation(this.getId(), par, parStatus.get(par));
}
return invitations;
}

public void setStatusMap(Map<String, String> statusMap) {
String[] status = new String[statusMap.values().size()];
int i = 0;
for (String name : statusMap.keySet()) {
status[i++] = String.format("%s:%s", name, statusMap.get(name));
}
this.setParticipantStatus(status);
}

public Map<String, String> getStatusMap() {
if (getParticipantStatus() == null) {
return Collections.emptyMap();
}
Map<String, String> status = new HashMap<String, String>();

for (String s : getParticipantStatus()) {
String[] tmp = s.split(":");
if (tmp.length == 2) {
status.put(tmp[0], tmp[1]);
} else {
status.put(tmp[0], "");
}
}
return status;
}
}
Loading

0 comments on commit 64db672

Please sign in to comment.