Skip to content
Snippets Groups Projects
Commit 1f248167 authored by Félix  Sidokhine's avatar Félix Sidokhine
Browse files

Merge branch 'feature/vcard-detail' into 'master'

Feature/vcard detail

See merge request fsidokhine/jams-refactoring!3
parents 31097581 c6e94ba4
No related branches found
No related tags found
No related merge requests found
......@@ -129,6 +129,12 @@ response = requests.get("http://localhost:8080/api/auth/user",headers=header)
print(response.status_code)
print(response.text)
print("Getting user profile as vcard")
response = requests.get("http://localhost:8080/api/auth/directory/entry?username=aberaud&format=vcard",headers=header)
print(response.status_code)
print(response.text)
response = requests.post("http://localhost:8080/api/update",headers=header)
print(response.status_code)
print(response.text)
\ No newline at end of file
print(response.text)
/*
* Copyright (C) 2020 by Savoir-faire Linux
* Authors: William Enright <william.enright@savoirfairelinux.com>
* Ndeye Anna Ndiaye <anna.ndiaye@savoirfairelinux.com>
* Johnny Flores <johnny.flores@savoirfairelinux.com>
* Mohammed Raza <mohammed.raza@savoirfairelinux.com>
* Felix Sidokhine <felix.sidokhine@savoirfairelinux.com>
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.jami.jams.ca.workers.crl;
import net.jami.jams.common.serialization.fs.FileStorage;
......
......@@ -27,6 +27,11 @@
<artifactId>xbean-classloader</artifactId>
<version>${xbean.version}</version>
</dependency>
<dependency>
<groupId>com.googlecode.ez-vcard</groupId>
<artifactId>ez-vcard</artifactId>
<version>${ez.vcard.version}</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -22,10 +22,24 @@
*/
package net.jami.jams.common.objects.user;
import com.jsoniter.annotation.JsonIgnore;
import ezvcard.Ezvcard;
import ezvcard.VCard;
import ezvcard.VCardVersion;
import ezvcard.parameter.EmailType;
import ezvcard.parameter.ImageType;
import ezvcard.parameter.TelephoneType;
import ezvcard.property.Organization;
import ezvcard.property.Photo;
import ezvcard.property.StructuredName;
import ezvcard.property.Telephone;
import lombok.Getter;
import lombok.Setter;
import org.bouncycastle.util.encoders.Base64;
import java.lang.reflect.Method;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
@Getter
......@@ -52,5 +66,30 @@ public class UserProfile {
private String email;
private String organization;
@JsonIgnore
//Ignore this if we pass through JSON iterator.
public String getAsVCard(){
VCard vCard = new VCard();
//We assume these always exist...
StructuredName structuredName = new StructuredName();
structuredName.setFamily(URLEncoder.encode(this.getLastName(), StandardCharsets.UTF_8));
structuredName.setGiven(URLEncoder.encode(this.getFirstName(), StandardCharsets.UTF_8));
vCard.setStructuredName(structuredName);
if(this.getPhoneNumber() != null) vCard.addTelephoneNumber(this.getPhoneNumber(), TelephoneType.WORK);
if(this.getMobileNumber() != null) vCard.addTelephoneNumber(this.getMobileNumber(),TelephoneType.CELL);
if(this.getFaxNumber() != null) vCard.addTelephoneNumber(this.getFaxNumber(), TelephoneType.FAX);
if(this.getEmail() != null) vCard.addEmail(this.getEmail(), EmailType.WORK);
if(this.getOrganization() != null) vCard.setOrganization(this.getOrganization());
/*I think this is how Base64 will work in this case*/
if(this.getProfilePicture() != null) {
Photo photo = new Photo(Base64.decode(this.getProfilePicture()), ImageType.JPEG);
vCard.addPhoto(photo);
}
return Ezvcard.write(vCard).version(VCardVersion.V3_0).go();
}
}
/*
* Copyright (C) 2020 by Savoir-faire Linux
* Authors: William Enright <william.enright@savoirfairelinux.com>
* Ndeye Anna Ndiaye <anna.ndiaye@savoirfairelinux.com>
* Johnny Flores <johnny.flores@savoirfairelinux.com>
* Mohammed Raza <mohammed.raza@savoirfairelinux.com>
* Felix Sidokhine <felix.sidokhine@savoirfairelinux.com>
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.jami.jams.common.serialization.fs;
import lombok.Getter;
......
......@@ -51,7 +51,10 @@ public class DirectoryEntryServlet extends HttpServlet {
UserProfile[] profiles = userAuthenticationModule.getAuthSources()
.get(new AuthModuleKey(req.getParameter("directory"), AuthenticationSourceType.fromString(req.getParameter("directoryType"))))
.getUserProfile(req.getParameter("username"), "LOGON_NAME");
resp.getOutputStream().write(JsonStream.serialize(profiles[0]).getBytes());
if(req.getParameter("format").equals("vcard")){
resp.getOutputStream().write(profiles[0].getAsVCard().getBytes());
}
else resp.getOutputStream().write(JsonStream.serialize(profiles[0]).getBytes());
return;
}
List<UserProfile> userProfiles = new ArrayList<>();
......@@ -59,7 +62,10 @@ public class DirectoryEntryServlet extends HttpServlet {
UserProfile[] profiles = v.getUserProfile(req.getParameter("username"), "LOGON_NAME");
if (profiles != null && profiles.length != 0) userProfiles.addAll(Arrays.asList(profiles));
});
resp.getOutputStream().write(JsonStream.serialize(userProfiles.get(0)).getBytes());
if(req.getParameter("format").equals("vcard")){
resp.getOutputStream().write(userProfiles.get(0).getAsVCard().getBytes());
}
else resp.getOutputStream().write(JsonStream.serialize(userProfiles.get(0)).getBytes());
}
@Override
......
/*
* Copyright (C) 2020 by Savoir-faire Linux
* Authors: William Enright <william.enright@savoirfairelinux.com>
* Ndeye Anna Ndiaye <anna.ndiaye@savoirfairelinux.com>
* Johnny Flores <johnny.flores@savoirfairelinux.com>
* Mohammed Raza <mohammed.raza@savoirfairelinux.com>
* Felix Sidokhine <felix.sidokhine@savoirfairelinux.com>
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.jami.jams.server.servlets.api.install;
import com.jsoniter.output.JsonStream;
......
......@@ -54,6 +54,7 @@
<maven.model.version>3.2.5</maven.model.version>
<apache.httpcore.version>4.4.12</apache.httpcore.version>
<apache.httpclient.version>4.5.10</apache.httpclient.version>
<ez.vcard.version>0.10.6</ez.vcard.version>
</properties>
<dependencies>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment