Skip to content

Commit

Permalink
1273 Integration with Google Calendar
Browse files Browse the repository at this point in the history
  • Loading branch information
car031 committed Aug 6, 2024
1 parent d31ecdd commit 4417395
Show file tree
Hide file tree
Showing 37 changed files with 433 additions and 210 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected void runTask() throws TaskException {
if (max != null && max.intValue() < 1)
max = null;

log.info("Found a total of {} documents to be processed", size);
log.info("Found a total of {} documents to process", size);

List<Long> ids = documentDao.findIdsByWhere(PersistentObjectDAO.ENTITY + ".docRef is null and "
+ PersistentObjectDAO.ENTITY + ".digest is null and deleted = 0", null, max);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public class Generic extends ExtensibleObject implements Comparable<Generic> {

private String string8;

private String text1;

private Long integer1;

private Long integer2;
Expand Down Expand Up @@ -243,4 +245,12 @@ public String getString8() {
public void setString8(String string8) {
this.string8 = string8;
}

public String getText1() {
return text1;
}

public void setText1(String text1) {
this.text1 = text1;
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
package com.logicaldoc.core.searchengine.saved;

import java.beans.XMLDecoder;
import java.beans.XMLEncoder;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.Serializable;
import java.util.Date;

Expand All @@ -15,7 +9,7 @@
import com.logicaldoc.core.searchengine.SearchOptions;
import com.logicaldoc.core.security.TenantDAO;
import com.logicaldoc.util.Context;
import com.logicaldoc.util.io.FileUtil;
import com.logicaldoc.util.io.IOUtil;

/**
* A search saved in the database
Expand Down Expand Up @@ -59,29 +53,14 @@ public void saveOptions(SearchOptions opt) throws IOException, PersistenceExcept
String tenantName = tenantDao.getTenantName(getTenantId());
String charset = Context.get().getProperties().getProperty(tenantName + ".charset", "UTF-8");

File tmpFile = FileUtil.createTempFile("ser", ".txt");
try (OutputStream out = new FileOutputStream(tmpFile);
XMLEncoder encoder = new XMLEncoder(out, charset, false, 0)) {
encoder.writeObject(opt);
} catch (IOException ioe) {
FileUtil.delete(tmpFile);
throw ioe;
}

try {
setOptions(FileUtil.readFile(tmpFile).trim());
} finally {
FileUtil.delete(tmpFile);
}
setOptions(IOUtil.serialize(opt, charset));
}

public SearchOptions readOptions() {
try (XMLDecoder decoder = new XMLDecoder(new ByteArrayInputStream(getOptions().getBytes()))) {
SearchOptions searchOptions = (SearchOptions) decoder.readObject();
searchOptions.setName(getName());
searchOptions.setDescription(getDescription());
return searchOptions;
}
SearchOptions searchOptions = (SearchOptions) IOUtil.deserialize(getOptions());
searchOptions.setName(getName());
searchOptions.setDescription(getDescription());
return searchOptions;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,11 @@ public static void generateDefaultAvatar(User user) {
File tmpAvatarImage = null;
try {
tmpAvatarImage = FileUtil.createTempFile(AVATAR, ".png");

TenantDAO tenantDao = (TenantDAO) Context.get().getBean(TenantDAO.class);
String tenantName = tenantDao.getTenantName(user.getTenantId());
int size = Context.get().getProperties().getInt(tenantName + ".gui.avatar.size", 128);

BufferedImage avatar = UserUtil.generateDefaultAvatarImage(user, size);
ImageIO.write(avatar, "png", tmpAvatarImage);
user.setAvatar(ImageUtil.encodeImage(tmpAvatarImage));
Expand All @@ -182,37 +182,11 @@ public static void generateDefaultAvatar(User user) {
}

private static BufferedImage generateDefaultAvatarImage(User user, int size) throws IOException {
Gravatar gravatar = new Gravatar();
gravatar.setRating(GravatarRating.GENERAL_AUDIENCES);
gravatar.setDefaultImage(GravatarDefaultImage.GRAVATAR_ICON);
gravatar.setSize(size);

/*
* Check Gravatar with main email
*/
BufferedImage avatarImage = null;
byte[] bytes;
try {
bytes = gravatar.download(user.getEmail());
if (bytes != null && bytes.length > 0)
avatarImage = ImageIO.read(new ByteArrayInputStream(bytes));
} catch (Exception t) {
log.warn("Cannot download gravatar for email {}", user.getEmail(), t);
}

/*
* Check Gravatar with secondary email
*/
if (avatarImage == null && StringUtils.isNotEmpty(user.getEmail2())) {
try {
bytes = gravatar.download(user.getEmail2());
if (bytes != null && bytes.length > 0)
avatarImage = ImageIO.read(new ByteArrayInputStream(bytes));
} catch (Exception t) {
log.warn("Cannot download gravatar for email {}", user.getEmail2(), t);
}
}

BufferedImage avatarImage = getImageFromGravatar(user, size);

/*
* Now generate one from scratch
*/
Expand All @@ -230,6 +204,39 @@ private static BufferedImage generateDefaultAvatarImage(User user, int size) thr
return avatarImage;
}

protected static BufferedImage getImageFromGravatar(User user, int size) {
BufferedImage avatarImage = null;
if (Context.get().getProperties().getBoolean("gravatar.enabled", false)) {
Gravatar gravatar = new Gravatar();
gravatar.setRating(GravatarRating.GENERAL_AUDIENCES);
gravatar.setDefaultImage(GravatarDefaultImage.GRAVATAR_ICON);
gravatar.setSize(size);

byte[] bytes;
try {
bytes = gravatar.download(user.getEmail());
if (bytes != null && bytes.length > 0)
avatarImage = ImageIO.read(new ByteArrayInputStream(bytes));
} catch (Exception t) {
log.warn("Cannot download gravatar for email {}", user.getEmail(), t);
}

/*
* Check Gravatar with secondary email
*/
if (avatarImage == null && StringUtils.isNotEmpty(user.getEmail2())) {
try {
bytes = gravatar.download(user.getEmail2());
if (bytes != null && bytes.length > 0)
avatarImage = ImageIO.read(new ByteArrayInputStream(bytes));
} catch (Exception t) {
log.warn("Cannot download gravatar for email {}", user.getEmail2(), t);
}
}
}
return avatarImage;
}

/**
* If the image is bigger, then gets the central square
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<property name="string6" type="string" column="ld_string6" />
<property name="string7" type="string" column="ld_string7" />
<property name="string8" type="string" column="ld_string8" />
<property name="text1" type="string" column="ld_text1" />
<property name="integer1" type="long" column="ld_integer1" />
<property name="integer2" type="long" column="ld_integer2" />
<property name="integer3" type="long" column="ld_integer3" />
Expand Down
5 changes: 4 additions & 1 deletion logicaldoc-core/src/main/resources/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,10 @@
</extension>
<extension plugin-id="logicaldoc-core" point-id="Aspect" id="aspWriteCheck">
<parameter id="code" value="writeCheck" />
</extension>
</extension>
<extension plugin-id="logicaldoc-core" point-id="Aspect" id="aspSendingMessages">
<parameter id="code" value="sendingMessages" />
</extension>

<extension plugin-id="logicaldoc-core" point-id="FormatConverter" id="imageConv">
<parameter id="in" value="png,gif,jpg,jpeg,jfif,tif,tiff,bmp,psd,webp,heic"/>
Expand Down
2 changes: 1 addition & 1 deletion logicaldoc-core/src/main/resources/sql/logicaldoc-core.sql
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ create table ld_generic (ld_id bigint not null, ld_lastmodified timestamp not nu
ld_string2 varchar(4000), ld_string3 varchar(4000), ld_string4 varchar(4000),
ld_string5 varchar(1000), ld_string6 varchar(1000), ld_string7 varchar(1000), ld_string8 varchar(1000),
ld_integer1 bigint null, ld_integer2 bigint null, ld_integer3 bigint null,
ld_double1 float, ld_double2 float,
ld_double1 float, ld_double2 float, ld_text1 varchar(100000),
ld_date1 timestamp null, ld_date2 timestamp null, primary key (ld_id));
create table ld_generic_ext (ld_genid bigint not null, ld_mandatory int not null, ld_type int not null,
ld_editor bigint not null, ld_position int not null, ld_stringvalue varchar(4000), ld_stringvalues varchar(4000),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ create table ld_generic (ld_id bigint not null, ld_lastmodified datetime not nul
ld_string2 varchar(4000), ld_string3 varchar(4000), ld_string4 varchar(4000),
ld_string5 varchar(1000), ld_string6 varchar(1000), ld_string7 varchar(1000), ld_string8 varchar(1000),
ld_integer1 bigint null, ld_integer2 bigint null, ld_integer3 bigint null,
ld_double1 double, ld_double2 double,
ld_double1 double, ld_double2 double, ld_text1 mediumtext,
ld_date1 datetime null, ld_date2 datetime null, primary key (ld_id)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE utf8_bin;
create table ld_generic_ext (ld_genid bigint not null, ld_mandatory int not null, ld_type int not null,
ld_editor bigint not null, ld_position int not null, ld_stringvalue varchar(4000), ld_stringvalues varchar(4000),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ create table ld_generic (ld_id bigint not null, ld_lastmodified datetime not nul
ld_string2 nvarchar(4000), ld_string3 nvarchar(4000), ld_string4 nvarchar(4000),
ld_string5 varchar(1000), ld_string6 varchar(1000), ld_string7 varchar(1000), ld_string8 varchar(1000),
ld_integer1 bigint null, ld_integer2 bigint null, ld_integer3 bigint null,
ld_double1 float, ld_double2 float,
ld_double1 float, ld_double2 float, ld_text1 nvarchar(max),
ld_date1 datetime null, ld_date2 datetime null, primary key (ld_id));
create table ld_generic_ext (ld_genid bigint not null, ld_mandatory int not null, ld_type int not null,
ld_editor bigint not null, ld_position int not null, ld_stringvalue nvarchar(4000), ld_stringvalues nvarchar(4000),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ create table ld_generic (ld_id bigint not null, ld_lastmodified datetime not nul
ld_string2 varchar(4000), ld_string3 varchar(4000), ld_string4 varchar(4000),
ld_string5 varchar(1000), ld_string6 varchar(1000), ld_string7 varchar(1000), ld_string8 varchar(1000),
ld_integer1 bigint null, ld_integer2 bigint null, ld_integer3 bigint null,
ld_double1 double, ld_double2 double,
ld_double1 double, ld_double2 double, ld_text1 mediumtext,
ld_date1 datetime null, ld_date2 datetime null, primary key (ld_id)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE utf8_bin;
create table ld_generic_ext (ld_genid bigint not null, ld_mandatory int not null, ld_type int not null,
ld_editor bigint not null, ld_position int not null, ld_stringvalue varchar(4000), ld_stringvalues varchar(4000),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ create table ld_generic (ld_id number(19,0) not null, ld_lastmodified timestamp
ld_string2 varchar(4000), ld_string3 varchar(4000), ld_string4 varchar(4000),
ld_string5 varchar(1000), ld_string6 varchar(1000), ld_string7 varchar(1000), ld_string8 varchar(1000),
ld_integer1 number(19,0) null, ld_integer2 number(19,0) null, ld_integer3 number(19,0) null,
ld_double1 float, ld_double2 float,
ld_double1 float, ld_double2 float, ld_text1 clob,
ld_date1 timestamp null, ld_date2 timestamp null, primary key (ld_id));
create table ld_generic_ext (ld_genid number(19,0) not null, ld_mandatory int not null, ld_type int not null,
ld_editor number(19,0) not null, ld_position int not null, ld_stringvalue varchar(4000), ld_stringvalues varchar(4000),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,18 @@ protected void service(HttpServletRequest request, HttpServletResponse response)
private void printEntries(Dropbox dbox, boolean folders, String parent, PrintWriter writer) throws DbxException {
Metadata ent = dbox.get(parent);
if ((ent == null && "/".equals(parent)) || ent instanceof FolderMetadata) {
printEntries(dbox, folders, parent, writer);
}

List<Metadata> entries = dbox.list(parent);
for (Metadata entry : entries) {
if (folders && entry instanceof FileMetadata)
continue;
writer.print("<entry>");
writer.print("<path><![CDATA[" + entry.getPathDisplay() + "]]></path>");
writer.print("<parent><![CDATA[" + parent + "]]></parent>");
writer.print("<name><![CDATA[" + entry.getName() + "]]></name>");
writer.print("<type>" + ((entry instanceof FileMetadata) ? "file" : "folder") + "</type>");
printIcon(writer, entry);
writer.print("</entry>");
List<Metadata> entries = dbox.list(parent);
for (Metadata entry : entries) {
if (folders && entry instanceof FileMetadata)
continue;
writer.print("<entry>");
writer.print("<path><![CDATA[" + entry.getPathDisplay() + "]]></path>");
writer.print("<parent><![CDATA[" + parent + "]]></parent>");
writer.print("<name><![CDATA[" + entry.getName() + "]]></name>");
writer.print("<type>" + ((entry instanceof FileMetadata) ? "file" : "folder") + "</type>");
printIcon(writer, entry);
writer.print("</entry>");
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public class Feature {

public static final int FOLDER_TEMPLATE = 42;

public static final int GDRIVE = 43;
public static final int GOOGLE_DRIVE = 43;

public static final int SMB_STORE = 44;

Expand Down Expand Up @@ -218,6 +218,8 @@ public class Feature {
public static final int TECHNICAL_SUPPORT = 103;

public static final int CHATGPT = 104;

public static final int GOOGLE_CALENDAR = 105;

private static Set<String> features = new HashSet<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,13 @@ public class Menu {
public static final long CHATGPT = -2130;

public static final long PROFILE_SECURITY = 41;

public static final long APIKEYS = 42;

public static final long PROFILE_TWO_FACTORS_AUTHENTICATION = 43;

public static final long GOOGLE_CALENDAR = -2081;

private static Set<Long> menus = new HashSet<>();

private Menu() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.logicaldoc.gui.common.client;

/**
* Exception used to inform the GUI about unhauthorized errors when using OAuth
* external tools
*
* @author Marco Meschieri - LogicalDOC
* @since 8.8.1
*/
public class OAuthException extends ServerException {

private static final long serialVersionUID = 1L;

public OAuthException() {
super();
}

public OAuthException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ public class GUICalendarEvent implements Serializable {

private Long parentId = null;

private String externalId = "";

private String externalUrl = "";

private String title = "";

private String type = "";
Expand Down Expand Up @@ -292,4 +296,20 @@ public String getAutomation() {
public void setAutomation(String automation) {
this.automation = automation;
}

public String getExternalId() {
return externalId;
}

public void setExternalId(String externalId) {
this.externalId = externalId;
}

public String getExternalUrl() {
return externalUrl;
}

public void setExternalUrl(String externalUrl) {
this.externalUrl = externalUrl;
}
}
Loading

0 comments on commit 4417395

Please sign in to comment.