Skip to content
Snippets Groups Projects
Commit 37f438ba authored by Félix  Sidokhine's avatar Félix Sidokhine Committed by Adrien Béraud
Browse files

fixes for bugs and build scripts

Change-Id: I0ae8cb75a3428d098299f95b250c7cedccb9e653
parent ecd08265
No related branches found
No related tags found
No related merge requests found
BUILD_DIRECTORY=build/
WEBAPP=../jams-server/src/main/resources/webapp/
JAMS_CLIENT=jams-client/
JAMS=jams
sudo npm run build
rm -rf $WEBAPP*
cp -r $BUILD_DIRECTORY* $WEBAPP
sed -i 's/material-dashboard-react\///g' $WEBAPP"index.html"
#cd ../$JAMS
#rm -rf jams
#rm derby.log
#rm oauth.key
#rm oauth.pub
#rm config.json
cd ..
#mvn clean package -DskipTests
mvn package
cd $JAMS
java -jar jams-launcher.jar 8080 server.pem server.key
#!/bin/bash
#Build the UI from the react js folder.
cd ../jams-react-client || exit
npm run build
#Now the UI is built we can exit and copy resource
mkdir -p ../jams-server/src/main/resources/webapp
sed -i 's/material-dashboard-react\///g' build/index.html
rm -rf ../jams-server/src/main/resources/webapp/*
mv build/* ../jams-server/src/main/resources/webapp
rm -rf build
...@@ -217,6 +217,24 @@ ...@@ -217,6 +217,24 @@
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<version>${maven.exec.version}</version>
<executions>
<execution>
<id>Build UI</id>
<phase>prepare-package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>bash</executable>
<commandlineArgs>build-ui.sh</commandlineArgs>
</configuration>
</execution>
</executions>
</plugin>
</plugins> </plugins>
</build> </build>
......
...@@ -57,7 +57,7 @@ public class TomcatLauncher { ...@@ -57,7 +57,7 @@ public class TomcatLauncher {
//Swap connectors fix. //Swap connectors fix.
public void swapConnectors(){ public void swapConnectors(){
if(getTomcat().getConnector().findSslHostConfigs() == null || getTomcat().getConnector().findSslHostConfigs().length < 1){ if(getTomcat().getConnector().findSslHostConfigs() != null && getTomcat().getConnector().findSslHostConfigs().length > 0){
getTomcat().getConnector().findSslHostConfigs()[0].setTruststoreFile(System.getProperty("user.dir") + File.separator + "keystore.jks"); getTomcat().getConnector().findSslHostConfigs()[0].setTruststoreFile(System.getProperty("user.dir") + File.separator + "keystore.jks");
getTomcat().getConnector().findSslHostConfigs()[0].setTruststorePassword("changeit"); getTomcat().getConnector().findSslHostConfigs()[0].setTruststorePassword("changeit");
getTomcat().getConnector().findSslHostConfigs()[0].setCertificateVerification("optional"); getTomcat().getConnector().findSslHostConfigs()[0].setCertificateVerification("optional");
......
/*
* 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.admin.contacts;
import com.jsoniter.JsonIterator;
import com.jsoniter.output.JsonStream;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import net.jami.jams.common.annotations.ScopedServletMethod;
import net.jami.jams.common.dao.StatementElement;
import net.jami.jams.common.dao.StatementList;
import net.jami.jams.common.objects.contacts.Contact;
import net.jami.jams.common.objects.user.AccessLevel;
import net.jami.jams.common.serialization.tomcat.TomcatCustomErrorHandler;
import net.jami.jams.common.utils.ContactMerger;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static net.jami.jams.server.Server.dataStore;
@WebServlet("/api/admin/contacts")
public class ContactServlet extends HttpServlet {
/**
* @apiVersion 1.0.0
* @api {get} /api/auth/contacts View contacts
* @apiName getContact
* @apiGroup Contacts
*
* @apiSuccess (200) {body} Contact[] List of contacts for the user
* @apiSuccessExample {json} Success-Response:
* [{
* "uri": "jami://7e3ab29383",
* "added": 18272662662
* },
* {
* "uri": "jami://7e3ab29383",
* "removed": 12387873
* },
* ]
*/
@Override
@ScopedServletMethod(securityGroups = {AccessLevel.ADMIN})
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
StatementList statementList = new StatementList();
statementList.addStatement(new StatementElement("owner","=",req.getParameter("username").toString(),""));
List<Contact> contactList = dataStore.getContactDao().getObjects(statementList);
resp.getOutputStream().write(JsonStream.serialize(contactList).getBytes());
}
/**
* @apiVersion 1.0.0
* @api {put} /api/auth/contacts Add a contact
* @apiName putContact
* @apiGroup Contacts
*
* @apiParam {body} Contact JSON representation of the contact object
* @apiParamExample {json} Request-Example:
* {
* "uri": "jami://7e3ab29383"
* }
*
* @apiSuccess (200) {null} null successfully added contact
* @apiError (500) {null} null contact could not be successfully added
*/
@Override
@ScopedServletMethod(securityGroups = {AccessLevel.ADMIN})
protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
Contact contact = JsonIterator.deserialize(req.getInputStream().readAllBytes(),Contact.class);
//TODO: Replace with mergetool.
contact.setTimestamp(System.currentTimeMillis());
contact.setStatus('A');
contact.setOwner(req.getAttribute("username").toString());
StatementList statementList = new StatementList();
statementList.addStatement(new StatementElement("owner","=",req.getParameter("username").toString(),""));
List<Contact> localList = dataStore.getContactDao().getObjects(statementList);
List<Contact> remoteList = new ArrayList<>();
remoteList.add(contact);
List<Contact> result = ContactMerger.mergeContacts(localList,remoteList);
if(dataStore.getContactDao().storeContactList(result)) resp.setStatus(200);
else TomcatCustomErrorHandler.sendCustomError(resp,500,"could not store a contact due to server-side error");
}
/**
* @apiVersion 1.0.0
* @api {delete} /api/auth/contacts Delete a contact
* @apiName deleteContact
* @apiGroup Contacts
*
* @apiParam {query} uri uri of the contact to delete
*
* @apiSuccess (200) {null} null successfully deleted contact
* @apiError (500) {null} null contact could not be successfully deleted
*/
@Override
@ScopedServletMethod(securityGroups = {AccessLevel.ADMIN})
protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
StatementList statementList = new StatementList();
statementList.addStatement(new StatementElement("owner","=",req.getParameter("username").toString(),"AND"));
statementList.addStatement(new StatementElement("uri","=",req.getParameter("uri"),""));
List<Contact> remoteList = dataStore.getContactDao().getObjects(statementList);
remoteList.get(0).setStatus('D');
remoteList.get(0).setTimestamp(System.currentTimeMillis());
statementList = new StatementList();
statementList.addStatement(new StatementElement("owner","=",req.getParameter("username").toString(),"AND"));
List<Contact> localList = dataStore.getContactDao().getObjects(statementList);
List<Contact> result = ContactMerger.mergeContacts(localList,remoteList);
if(dataStore.getContactDao().storeContactList(result)) resp.setStatus(200);
else TomcatCustomErrorHandler.sendCustomError(resp,500,"could not delete a contact due to server-side error");
}
/**
* @apiVersion 1.0.0
* @api {post} /api/auth/contacts Add a contact
* @apiName putContact
* @apiGroup Contacts
*
* @apiParam {body} Contact JSON representation of the contact object
* @apiParamExample {json} Request-Example:
*[
* {"uri":"tcp://def@local","added":1594742298377},
* {"uri":"tcp://abc@19293.com","removed":1594742298377}
* ]
*
* @apiSuccess (200) {json} Contact[] successfully added contact
* @apiError (500) {null} null contact could not be successfully added
*/
@Override
@ScopedServletMethod(securityGroups = {AccessLevel.ADMIN})
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
StatementList statementList = new StatementList();
statementList.addStatement(new StatementElement("owner","=",req.getParameter("username").toString(),""));
List<Contact> localList = dataStore.getContactDao().getObjects(statementList);
List<Contact> remoteList = Arrays.asList(JsonIterator.deserialize(req.getInputStream().readAllBytes(),Contact[].class));
remoteList.forEach(contact -> contact.setOwner(req.getParameter("username").toString()));
List<Contact> result = ContactMerger.mergeContacts(localList,remoteList);
if(!dataStore.getContactDao().storeContactList(result)) TomcatCustomErrorHandler.sendCustomError(resp,500,"Could not store contacts!");
else resp.getOutputStream().write(JsonStream.serialize(result).getBytes());
}
}
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