Super clean and upgrade to the new archi-data(back) and upgrade fron with new common system
This commit is contained in:
parent
3ad9b8b579
commit
c6472630ca
86
back/pom.xml
86
back/pom.xml
@ -15,6 +15,20 @@
|
||||
|
||||
<maven.dependency.version>3.1.1</maven.dependency.version>
|
||||
</properties>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>gitea</id>
|
||||
<url>https://gitea.atria-soft.org/api/packages/kangaroo-and-rabbit/maven</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>kangaroo-and-rabbit</groupId>
|
||||
<artifactId>archidata</artifactId>
|
||||
<version>0.1.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
@ -28,78 +42,6 @@
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<!-- https://mvnrepository.com/artifact/org.glassfish.jersey.media/jersey-media-multipart -->
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.media</groupId>
|
||||
<artifactId>jersey-media-multipart</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.inject</groupId>
|
||||
<artifactId>jersey-hk2</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.containers</groupId>
|
||||
<artifactId>jersey-container-grizzly2-http</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.xml.bind</groupId>
|
||||
<artifactId>jaxb-api</artifactId>
|
||||
<version>${jaxb.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.ws.rs</groupId>
|
||||
<artifactId>javax.ws.rs-api</artifactId>
|
||||
<version>2.1.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.xml.bind</groupId>
|
||||
<artifactId>jaxb-impl</artifactId>
|
||||
<version>${jaxb.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.istack</groupId>
|
||||
<artifactId>istack-commons-runtime</artifactId>
|
||||
<version>${istack.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
|
||||
<artifactId>jersey-test-framework-provider-grizzly2</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>8.0.30</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.media</groupId>
|
||||
<artifactId>jersey-media-json-jackson</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.8.10</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<version>3.0.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
<version>RELEASE</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.nimbusds</groupId>
|
||||
<artifactId>nimbus-jose-jwt</artifactId>
|
||||
<version>9.22</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<sourceDirectory>src</sourceDirectory>
|
||||
<testSourceDirectory>test/src</testSourceDirectory>
|
||||
|
@ -1,138 +0,0 @@
|
||||
package org.kar.karideo;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.kar.karideo.db.DBEntry;
|
||||
import org.kar.karideo.model.User;
|
||||
import org.kar.karideo.model.UserSmall;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class UserDB {
|
||||
|
||||
public UserDB() {
|
||||
}
|
||||
|
||||
public static User getUsers(long userId) {
|
||||
DBEntry entry = new DBEntry(WebLauncher.dbConfig);
|
||||
String query = "SELECT * FROM user WHERE id = ?";
|
||||
try {
|
||||
PreparedStatement ps = entry.connection.prepareStatement(query);
|
||||
ps.setLong(1, userId);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
if (rs.next()) {
|
||||
User out = new User(rs);
|
||||
entry.disconnect();
|
||||
return out;
|
||||
}
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
entry.disconnect();
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static User getUserOrCreate(long userId, String userLogin) {
|
||||
User user = getUsers(userId);
|
||||
if (user != null) {
|
||||
/*
|
||||
boolean blocked = false;
|
||||
boolean removed = false;
|
||||
if (user.email != userOAuth.email || user.login != userOAuth.login || user.blocked != blocked || user.removed != removed) {
|
||||
updateUsersInfoFromOAuth(userOAuth.id, userOAuth.email, userOAuth.login, blocked, removed);
|
||||
} else {
|
||||
updateUsersConnectionTime(userOAuth.id);
|
||||
}
|
||||
return getUsers(userOAuth.id);
|
||||
*/
|
||||
return user;
|
||||
}
|
||||
createUsersInfoFromOAuth(userId, userLogin);
|
||||
return getUsers(userId);
|
||||
}
|
||||
/*
|
||||
private static void updateUsersConnectionTime(long userId) {
|
||||
DBEntry entry = new DBEntry(WebLauncher.dbConfig);
|
||||
String query = "UPDATE `user` SET `lastConnection`=now(3) WHERE `id` = ?";
|
||||
try {
|
||||
PreparedStatement ps = entry.connection.prepareStatement(query);
|
||||
ps.setLong(1, userId);
|
||||
ps.executeUpdate();
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
entry.disconnect();
|
||||
}
|
||||
|
||||
private static void updateUsersInfoFromOAuth(long userId, String email, String login, boolean blocked, boolean removed) {
|
||||
DBEntry entry = new DBEntry(WebLauncher.dbConfig);
|
||||
String query = "UPDATE `user` SET `login`=?, `email`=?, `lastConnection`=now(3), `blocked`=?, `removed`=? WHERE id = ?";
|
||||
try {
|
||||
PreparedStatement ps = entry.connection.prepareStatement(query);
|
||||
ps.setString(1, login);
|
||||
ps.setString(2, email);
|
||||
ps.setString(3, blocked ? "TRUE" : "FALSE");
|
||||
ps.setString(4, removed ? "TRUE" : "FALSE");
|
||||
ps.setLong(5, userId);
|
||||
ps.executeUpdate();
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
entry.disconnect();
|
||||
}
|
||||
*/
|
||||
|
||||
private static void createUsersInfoFromOAuth(long userId, String login) {
|
||||
DBEntry entry = new DBEntry(WebLauncher.dbConfig);
|
||||
String query = "INSERT INTO `user` (`id`, `login`, `lastConnection`, `admin`, `blocked`, `removed`) VALUE (?,?,now(3),'FALSE','FALSE','FALSE')";
|
||||
try {
|
||||
PreparedStatement ps = entry.connection.prepareStatement(query);
|
||||
ps.setLong(1, userId);
|
||||
ps.setString(2, login);
|
||||
ps.executeUpdate();
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
entry.disconnect();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -6,57 +6,51 @@ import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
|
||||
import org.glassfish.jersey.media.multipart.MultiPartFeature;
|
||||
import org.glassfish.jersey.server.ResourceConfig;
|
||||
import org.kar.karideo.api.*;
|
||||
import org.kar.karideo.db.DBConfig;
|
||||
import org.kar.karideo.filter.AuthenticationFilter;
|
||||
import org.kar.karideo.filter.CORSFilter;
|
||||
import org.kar.karideo.filter.OptionFilter;
|
||||
import org.kar.karideo.util.ConfigVariable;
|
||||
import org.kar.karideo.util.JWTWrapper;
|
||||
import org.kar.karideo.model.Data;
|
||||
import org.kar.karideo.model.Media;
|
||||
import org.kar.karideo.model.Season;
|
||||
import org.kar.karideo.model.Series;
|
||||
import org.kar.karideo.model.Type;
|
||||
import org.kar.archidata.GlobalConfiguration;
|
||||
import org.kar.archidata.SqlWrapper;
|
||||
import org.kar.archidata.UpdateJwtPublicKey;
|
||||
import org.kar.archidata.db.DBConfig;
|
||||
import org.kar.archidata.filter.AuthenticationFilter;
|
||||
import org.kar.archidata.filter.CORSFilter;
|
||||
import org.kar.archidata.filter.OptionFilter;
|
||||
import org.kar.archidata.model.User;
|
||||
import org.kar.archidata.util.ConfigBaseVariable;
|
||||
import org.kar.archidata.util.JWTWrapper;
|
||||
import org.glassfish.jersey.jackson.JacksonFeature;
|
||||
|
||||
import javax.ws.rs.core.UriBuilder;
|
||||
import java.net.URI;
|
||||
|
||||
class UpdateJwtPublicKey extends Thread {
|
||||
boolean kill = false;
|
||||
public void run() {
|
||||
try {
|
||||
Thread.sleep(1000*20, 0);
|
||||
} catch (InterruptedException e2) {
|
||||
// TODO Auto-generated catch block
|
||||
e2.printStackTrace();
|
||||
}
|
||||
while (this.kill == false) {
|
||||
// need to uppgrade when server call us...
|
||||
try {
|
||||
JWTWrapper.initLocalTokenRemote(ConfigVariable.getSSOAddress(), "karideo");
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
System.out.println("Can not retreive the basic tocken");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Thread.sleep(1000*60*5, 0);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
public void kill() {
|
||||
this.kill = true;
|
||||
}
|
||||
}
|
||||
|
||||
public class WebLauncher {
|
||||
public static DBConfig dbConfig;
|
||||
private WebLauncher() {
|
||||
}
|
||||
|
||||
private static URI getBaseURI() {
|
||||
return UriBuilder.fromUri(ConfigVariable.getlocalAddress()).build();
|
||||
return UriBuilder.fromUri(ConfigBaseVariable.getlocalAddress()).build();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
ConfigBaseVariable.bdDatabase = "karideo";
|
||||
|
||||
try {
|
||||
String out = "";
|
||||
out += SqlWrapper.createTable(Data.class);
|
||||
out += SqlWrapper.createTable(Media.class);
|
||||
out += SqlWrapper.createTable(Type.class);
|
||||
out += SqlWrapper.createTable(Series.class);
|
||||
out += SqlWrapper.createTable(Season.class);
|
||||
out += SqlWrapper.createTable(User.class);
|
||||
System.out.println(out);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
// Configure resources
|
||||
@ -64,16 +58,12 @@ public class WebLauncher {
|
||||
ResourceConfig rc = new ResourceConfig();
|
||||
|
||||
// add multi-part models ..
|
||||
//rc.register(new MultiPartFeature());
|
||||
//rc.register(new InjectionBinder());
|
||||
rc.register(new MultiPartFeature());
|
||||
//rc.register(new MyFileUploader());
|
||||
// global authentication system
|
||||
rc.register(new OptionFilter());
|
||||
// remove cors ==> all time called by an other system...
|
||||
rc.register(new CORSFilter());
|
||||
// global authentication system
|
||||
//rc.register(new AuthenticationFilter());
|
||||
rc.registerClasses(AuthenticationFilter.class);
|
||||
// add default resource:
|
||||
rc.registerClasses(UserResource.class);
|
||||
@ -81,10 +71,11 @@ public class WebLauncher {
|
||||
rc.registerClasses(DataResource.class);
|
||||
rc.registerClasses(SeasonResource.class);
|
||||
rc.registerClasses(TypeResource.class);
|
||||
rc.registerClasses(UniverseResource.class);
|
||||
rc.registerClasses(VideoResource.class);
|
||||
|
||||
rc.registerClasses(HealthCheck.class);
|
||||
rc.registerClasses(Front.class);
|
||||
|
||||
// add jackson to be discover when we are ins standalone server
|
||||
rc.register(JacksonFeature.class);
|
||||
// enable this to show low level request
|
||||
@ -96,12 +87,7 @@ public class WebLauncher {
|
||||
//System.out.println(" getDBLogin: '" + ConfigVariable.getDBLogin() + "'");
|
||||
//System.out.println(" getDBPassword: '" + ConfigVariable.getDBPassword() + "'");
|
||||
//System.out.println(" getDBName: '" + ConfigVariable.getDBName() + "'");
|
||||
dbConfig = new DBConfig(ConfigVariable.getDBHost(),
|
||||
Integer.parseInt(ConfigVariable.getDBPort()),
|
||||
ConfigVariable.getDBLogin(),
|
||||
ConfigVariable.getDBPassword(),
|
||||
ConfigVariable.getDBName());
|
||||
System.out.println(" ==> " + dbConfig);
|
||||
System.out.println(" ==> " + GlobalConfiguration.dbConfig);
|
||||
System.out.println("OAuth service " + getBaseURI());
|
||||
HttpServer server = GrizzlyHttpServerFactory.createHttpServer(getBaseURI(), rc);
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
|
||||
|
16
back/src/org/kar/karideo/WebLauncherLocal.java
Executable file
16
back/src/org/kar/karideo/WebLauncherLocal.java
Executable file
@ -0,0 +1,16 @@
|
||||
|
||||
package org.kar.karideo;
|
||||
|
||||
import org.kar.archidata.util.ConfigBaseVariable;
|
||||
|
||||
public class WebLauncherLocal {
|
||||
private WebLauncherLocal() {}
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
if (true) {
|
||||
// for local test:
|
||||
ConfigBaseVariable.apiAdress = "http://0.0.0.0:18080/karideo/api/";
|
||||
}
|
||||
WebLauncher.main(args);
|
||||
}
|
||||
}
|
@ -2,16 +2,13 @@ package org.kar.karideo.api;
|
||||
|
||||
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
|
||||
import org.glassfish.jersey.media.multipart.FormDataParam;
|
||||
import org.kar.karideo.WebLauncher;
|
||||
import org.kar.karideo.annotation.PermitTokenInURI;
|
||||
import org.kar.karideo.db.DBEntry;
|
||||
import org.kar.karideo.filter.GenericContext;
|
||||
import org.kar.archidata.filter.GenericContext;
|
||||
import org.kar.karideo.model.Data;
|
||||
import org.kar.karideo.model.DataSmall;
|
||||
import org.kar.karideo.util.ConfigVariable;
|
||||
import org.kar.archidata.SqlWrapper;
|
||||
import org.kar.archidata.annotation.security.RolesAllowed;
|
||||
import org.kar.archidata.util.ConfigBaseVariable;
|
||||
|
||||
import org.kar.archidata.annotation.security.PermitAll;
|
||||
import javax.annotation.security.RolesAllowed;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.CacheControl;
|
||||
@ -29,12 +26,7 @@ import java.nio.file.Paths;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
||||
// https://stackoverflow.com/questions/35367113/jersey-webservice-scalable-approach-to-download-file-and-reply-to-client
|
||||
@ -62,9 +54,9 @@ public class DataResource {
|
||||
}
|
||||
|
||||
public static String getTmpFileInData(long tmpFolderId) {
|
||||
String filePath = ConfigVariable.getTmpDataFolder() + File.separator + tmpFolderId;
|
||||
String filePath = ConfigBaseVariable.getTmpDataFolder() + File.separator + tmpFolderId;
|
||||
try {
|
||||
createFolder(ConfigVariable.getTmpDataFolder() + File.separator);
|
||||
createFolder(ConfigBaseVariable.getTmpDataFolder() + File.separator);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -72,9 +64,9 @@ public class DataResource {
|
||||
}
|
||||
|
||||
public static String getFileData(long tmpFolderId) {
|
||||
String filePath = ConfigVariable.getMediaDataFolder() + File.separator + tmpFolderId + File.separator + "data";
|
||||
String filePath = ConfigBaseVariable.getMediaDataFolder() + File.separator + tmpFolderId + File.separator + "data";
|
||||
try {
|
||||
createFolder(ConfigVariable.getMediaDataFolder() + File.separator + tmpFolderId + File.separator);
|
||||
createFolder(ConfigBaseVariable.getMediaDataFolder() + File.separator + tmpFolderId + File.separator);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -83,46 +75,29 @@ public class DataResource {
|
||||
|
||||
public static Data getWithSha512(String sha512) {
|
||||
System.out.println("find sha512 = " + sha512);
|
||||
DBEntry entry = new DBEntry(WebLauncher.dbConfig);
|
||||
String query = "SELECT `id`, `deleted`, `sha512`, `mime_type`, `size` FROM `data` WHERE `sha512` = ?";
|
||||
try {
|
||||
PreparedStatement ps = entry.connection.prepareStatement(query);
|
||||
ps.setString(1, sha512);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
if (rs.next()) {
|
||||
Data out = new Data(rs);
|
||||
entry.disconnect();
|
||||
return out;
|
||||
return SqlWrapper.getWhere(Data.class, "sha512", "=", sha512);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
entry.disconnect();
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
public static Data getWithId(long id) {
|
||||
DBEntry entry = new DBEntry(WebLauncher.dbConfig);
|
||||
String query = "SELECT `id`, `deleted`, `sha512`, `mime_type`, `size` FROM `data` WHERE `deleted` = false AND `id` = ?";
|
||||
System.out.println("find id = " + id);
|
||||
try {
|
||||
PreparedStatement ps = entry.connection.prepareStatement(query);
|
||||
ps.setLong(1, id);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
if (rs.next()) {
|
||||
Data out = new Data(rs);
|
||||
entry.disconnect();
|
||||
return out;
|
||||
return SqlWrapper.get(Data.class, id);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
entry.disconnect();
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Data createNewData(long tmpUID, String originalFileName, String sha512) throws IOException, SQLException {
|
||||
public static Data createNewData(long tmpUID, String originalFileName, String sha512) throws IOException {
|
||||
// determine mime type:
|
||||
Data injectedData = new Data();
|
||||
String mimeType = "";
|
||||
String extension = originalFileName.substring(originalFileName.lastIndexOf('.') + 1);
|
||||
switch (extension.toLowerCase()) {
|
||||
@ -148,66 +123,24 @@ public class DataResource {
|
||||
default:
|
||||
throw new IOException("Can not find the mime type of data input: '" + extension + "'");
|
||||
}
|
||||
injectedData.mimeType = mimeType;
|
||||
injectedData.sha512 = sha512;
|
||||
String tmpPath = getTmpFileInData(tmpUID);
|
||||
long fileSize = Files.size(Paths.get(tmpPath));
|
||||
DBEntry entry = new DBEntry(WebLauncher.dbConfig);
|
||||
long uniqueSQLID = -1;
|
||||
try {
|
||||
// prepare the request:
|
||||
String query = "INSERT INTO `data` (`sha512`, `mime_type`, `size`, `original_name`) VALUES (?, ?, ?, ?)";
|
||||
PreparedStatement ps = entry.connection.prepareStatement(query,
|
||||
Statement.RETURN_GENERATED_KEYS);
|
||||
int iii = 1;
|
||||
ps.setString(iii++, sha512);
|
||||
ps.setString(iii++, mimeType);
|
||||
ps.setLong(iii++, fileSize);
|
||||
ps.setString(iii++, originalFileName);
|
||||
// execute the request
|
||||
int affectedRows = ps.executeUpdate();
|
||||
if (affectedRows == 0) {
|
||||
throw new SQLException("Creating data failed, no rows affected.");
|
||||
}
|
||||
// retreive uid inserted
|
||||
try (ResultSet generatedKeys = ps.getGeneratedKeys()) {
|
||||
if (generatedKeys.next()) {
|
||||
uniqueSQLID = generatedKeys.getLong(1);
|
||||
} else {
|
||||
throw new SQLException("Creating user failed, no ID obtained (1).");
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
System.out.println("Can not get the UID key inserted ... ");
|
||||
ex.printStackTrace();
|
||||
throw new SQLException("Creating user failed, no ID obtained (2).");
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
entry.disconnect();
|
||||
System.out.println("Add Data raw done. uid data=" + uniqueSQLID);
|
||||
Data out = getWithId(uniqueSQLID);
|
||||
injectedData.size = Files.size(Paths.get(tmpPath));
|
||||
|
||||
String mediaPath = getFileData(out.id);
|
||||
try {
|
||||
injectedData = SqlWrapper.insert(injectedData);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
String mediaPath = getFileData(injectedData.id);
|
||||
System.out.println("src = " + tmpPath);
|
||||
System.out.println("dst = " + mediaPath);
|
||||
Files.move(Paths.get(tmpPath), Paths.get(mediaPath), StandardCopyOption.ATOMIC_MOVE);
|
||||
|
||||
System.out.println("Move done");
|
||||
// all is done the file is corectly installed...
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
public static void undelete(Long id) {
|
||||
DBEntry entry = new DBEntry(WebLauncher.dbConfig);
|
||||
String query = "UPDATE `data` SET `deleted` = false WHERE `id` = ?";
|
||||
try {
|
||||
PreparedStatement ps = entry.connection.prepareStatement(query);
|
||||
ps.setLong(1, id);
|
||||
ps.execute();
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
entry.disconnect();
|
||||
return injectedData;
|
||||
}
|
||||
|
||||
static String saveTemporaryFile(InputStream uploadedInputStream, long idData) {
|
||||
@ -261,18 +194,6 @@ public class DataResource {
|
||||
return out;
|
||||
}
|
||||
|
||||
// curl http://localhost:9993/api/users/3
|
||||
//@Secured
|
||||
/*
|
||||
@GET
|
||||
@Path("{id}")
|
||||
//@RolesAllowed("GUEST")
|
||||
@Produces(MediaType.APPLICATION_OCTET_STREAM)
|
||||
public Response retriveData(@HeaderParam("Range") String range, @PathParam("id") Long id) throws Exception {
|
||||
return retriveDataFull(range, id, "no-name");
|
||||
}
|
||||
*/
|
||||
|
||||
public static String bytesToHex(byte[] bytes) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (byte b : bytes) {
|
||||
@ -282,47 +203,13 @@ public class DataResource {
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
@POST
|
||||
@Path("/upload")
|
||||
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
||||
public Response uploadFile(FormDataMultiPart form) {
|
||||
|
||||
FormDataBodyPart filePart = form.getField("file");
|
||||
|
||||
ContentDisposition headerOfFilePart = filePart.getContentDisposition();
|
||||
|
||||
InputStream fileInputStream = filePart.getValueAs(InputStream.class);
|
||||
|
||||
String filePath = ConfigVariable.getTmpDataFolder() + File.separator + tmpFolderId++;
|
||||
//headerOfFilePart.getFileName();
|
||||
|
||||
// save the file to the server
|
||||
saveFile(fileInputStream, filePath);
|
||||
|
||||
String output = "File saved to server location using FormDataMultiPart : " + filePath;
|
||||
|
||||
return Response.status(200).entity(output).build();
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
public DataSmall getSmall(Long id) {
|
||||
DBEntry entry = new DBEntry(WebLauncher.dbConfig);
|
||||
String query = "SELECT `id`, `sha512`, `mime_type`, `size` FROM `data` WHERE `deleted` = false AND `id` = ?";
|
||||
public Data getSmall(Long id) {
|
||||
try {
|
||||
PreparedStatement ps = entry.connection.prepareStatement(query);
|
||||
ps.setLong(1, id);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
if (rs.next()) {
|
||||
DataSmall out = new DataSmall(rs);
|
||||
entry.disconnect();
|
||||
return out;
|
||||
return SqlWrapper.get(Data.class, id);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
entry.disconnect();
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -337,9 +224,9 @@ public class DataResource {
|
||||
System.out.println("===================================================");
|
||||
//public NodeSmall uploadFile(final FormDataMultiPart form) {
|
||||
System.out.println("Upload file: ");
|
||||
String filePath = ConfigVariable.getTmpDataFolder() + File.separator + tmpFolderId++;
|
||||
String filePath = ConfigBaseVariable.getTmpDataFolder() + File.separator + tmpFolderId++;
|
||||
try {
|
||||
createFolder(ConfigVariable.getTmpDataFolder() + File.separator);
|
||||
createFolder(ConfigBaseVariable.getTmpDataFolder() + File.separator);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -358,14 +245,14 @@ public class DataResource {
|
||||
//System.out.println("===================================================");
|
||||
System.out.println("== DATA retriveDataId ? id=" + id + " user=" + (gc==null?"null":gc.user));
|
||||
//System.out.println("===================================================");
|
||||
DataSmall value = getSmall(id);
|
||||
Data value = getSmall(id);
|
||||
if (value == null) {
|
||||
Response.status(404).
|
||||
entity("media NOT FOUND: " + id).
|
||||
type("text/plain").
|
||||
build();
|
||||
}
|
||||
return buildStream(ConfigVariable.getMediaDataFolder() + File.separator + id + File.separator + "data", range, value.mimeType);
|
||||
return buildStream(ConfigBaseVariable.getMediaDataFolder() + File.separator + id + File.separator + "data", range, value.mimeType);
|
||||
}
|
||||
|
||||
@GET
|
||||
@ -379,14 +266,14 @@ public class DataResource {
|
||||
//System.out.println("===================================================");
|
||||
//System.out.println("== DATA retriveDataThumbnailId ? " + (gc==null?"null":gc.user));
|
||||
//System.out.println("===================================================");
|
||||
DataSmall value = getSmall(id);
|
||||
Data value = getSmall(id);
|
||||
if (value == null) {
|
||||
return Response.status(404).
|
||||
entity("media NOT FOUND: " + id).
|
||||
type("text/plain").
|
||||
build();
|
||||
}
|
||||
String filePathName = ConfigVariable.getMediaDataFolder() + File.separator + id + File.separator + "data";
|
||||
String filePathName = ConfigBaseVariable.getMediaDataFolder() + File.separator + id + File.separator + "data";
|
||||
if ( value.mimeType.contentEquals("image/jpeg")
|
||||
|| value.mimeType.contentEquals("image/png")
|
||||
// || value.mimeType.contentEquals("image/webp")
|
||||
@ -448,14 +335,14 @@ public class DataResource {
|
||||
//System.out.println("===================================================");
|
||||
System.out.println("== DATA retriveDataFull ? id=" + id + " user=" + (gc==null?"null":gc.user));
|
||||
//System.out.println("===================================================");
|
||||
DataSmall value = getSmall(id);
|
||||
Data value = getSmall(id);
|
||||
if (value == null) {
|
||||
Response.status(404).
|
||||
entity("media NOT FOUND: " + id).
|
||||
type("text/plain").
|
||||
build();
|
||||
}
|
||||
return buildStream(ConfigVariable.getMediaDataFolder() + File.separator + id + File.separator + "data", range, value.mimeType);
|
||||
return buildStream(ConfigBaseVariable.getMediaDataFolder() + File.separator + id + File.separator + "data", range, value.mimeType);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -532,4 +419,8 @@ public class DataResource {
|
||||
return out.build();
|
||||
}
|
||||
|
||||
public static void undelete(Long id) throws Exception {
|
||||
SqlWrapper.unsetDelete(Data.class, id);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,111 +1,16 @@
|
||||
package org.kar.karideo.api;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import org.kar.archidata.annotation.security.PermitAll;
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.CacheControl;
|
||||
import javax.ws.rs.core.PathSegment;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.ResponseBuilder;
|
||||
import org.kar.archidata.api.FrontGeneric;
|
||||
|
||||
import javax.ws.rs.Path;
|
||||
|
||||
import org.kar.karideo.util.ConfigVariable;
|
||||
|
||||
@Path("/karideo")
|
||||
public class Front {
|
||||
private String getExtension(String filename) {
|
||||
if (filename.contains(".")) {
|
||||
return filename.substring(filename.lastIndexOf(".") + 1);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
private Response retrive(String fileName) throws Exception {
|
||||
String filePathName = ConfigVariable.getFrontFolder() + File.separator + fileName;
|
||||
String extention = getExtension(filePathName);
|
||||
String mineType = null;
|
||||
System.out.println("try retrive : '" + filePathName + "' '" + extention + "'");
|
||||
CacheControl cc = new CacheControl();
|
||||
cc.setMaxAge(3600);
|
||||
cc.setNoCache(false);
|
||||
if (extention.length() !=0 && extention.length() <= 5) {
|
||||
if (extention.equalsIgnoreCase("jpg") || extention.equalsIgnoreCase("jpeg")) {
|
||||
mineType = "image/jpeg";
|
||||
} else if (extention.equalsIgnoreCase("gif")) {
|
||||
mineType = "image/gif";
|
||||
} else if (extention.equalsIgnoreCase("png")) {
|
||||
mineType = "image/png";
|
||||
} else if (extention.equalsIgnoreCase("svg")) {
|
||||
mineType = "image/svg+xml";
|
||||
} else if (extention.equalsIgnoreCase("webp")) {
|
||||
mineType = "image/webp";
|
||||
} else if (extention.equalsIgnoreCase("js")) {
|
||||
cc.setMaxAge(1);
|
||||
cc.setNoCache(true);
|
||||
mineType = "application/javascript";
|
||||
} else if (extention.equalsIgnoreCase("json")) {
|
||||
mineType = "application/json";
|
||||
cc.setMaxAge(1);
|
||||
cc.setNoCache(true);
|
||||
} else if (extention.equalsIgnoreCase("ico")) {
|
||||
mineType = "image/x-icon";
|
||||
} else if (extention.equalsIgnoreCase("html")) {
|
||||
mineType = "text/html";
|
||||
cc.setMaxAge(1);
|
||||
cc.setNoCache(true);
|
||||
} else if (extention.equalsIgnoreCase("css")) {
|
||||
mineType = "text/css";
|
||||
cc.setMaxAge(1);
|
||||
cc.setNoCache(true);
|
||||
} else {
|
||||
return Response.status(403).
|
||||
entity("Not supported model: '" + fileName + "'").
|
||||
type("text/plain").
|
||||
build();
|
||||
}
|
||||
} else {
|
||||
mineType = "text/html";
|
||||
filePathName = ConfigVariable.getFrontFolder() + File.separator + "index.html";
|
||||
}
|
||||
System.out.println(" ==> '" + filePathName + "'");
|
||||
// reads input image
|
||||
File download = new File(filePathName);
|
||||
if (!download.exists()) {
|
||||
return Response.status(404).
|
||||
entity("Not Found: '" + fileName + "' extension='" + extention + "'").
|
||||
type("text/plain").
|
||||
build();
|
||||
}
|
||||
ResponseBuilder response = Response.ok((Object)download);
|
||||
// use this if I want to download the file:
|
||||
//response.header("Content-Disposition", "attachment; filename=" + fileName);
|
||||
response.cacheControl(cc);
|
||||
response.type(mineType);
|
||||
public class Front extends FrontGeneric {
|
||||
public Front() {
|
||||
this.baseFrontFolder = ConfigVariable.getFrontFolder();
|
||||
|
||||
return response.build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@PermitAll()
|
||||
//@Produces(MediaType.APPLICATION_OCTET_STREAM)
|
||||
//@CacheMaxAge(time = 1, unit = TimeUnit.DAYS)
|
||||
public Response retrive0() throws Exception {
|
||||
return retrive("index.html");
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("{any: .*}")
|
||||
@PermitAll()
|
||||
//@Produces(MediaType.APPLICATION_OCTET_STREAM)
|
||||
//@CacheMaxAge(time = 10, unit = TimeUnit.DAYS)
|
||||
public Response retrive1(@PathParam("any") List<PathSegment> segments) throws Exception {
|
||||
String filename = "";
|
||||
for (PathSegment elem: segments) {
|
||||
if (!filename.isEmpty()) {
|
||||
filename += File.separator;
|
||||
}
|
||||
filename += elem.getPath();
|
||||
}
|
||||
return retrive(filename);
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
import org.kar.karideo.util.JWTWrapper;
|
||||
import org.kar.archidata.util.JWTWrapper;
|
||||
|
||||
@Path("/health_check")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
|
@ -22,21 +22,6 @@ public class MediaStreamer implements StreamingOutput {
|
||||
this.raf = raf;
|
||||
}
|
||||
|
||||
/*
|
||||
public void write(OutputStream out) {
|
||||
try (FileInputStream in = new FileInputStream(file)) {
|
||||
byte[] buf = new byte[1024*1024];
|
||||
int len;
|
||||
while ((len = in.read(buf)) != -1) {
|
||||
out.write(buf, 0, len);
|
||||
out.flush();
|
||||
//System.out.println("---- wrote " + len + " bytes file ----");
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
throw new InternalServerErrorException(ex);
|
||||
}
|
||||
}
|
||||
*/
|
||||
@Override
|
||||
public void write(OutputStream outputStream) {
|
||||
try {
|
||||
|
@ -1,482 +0,0 @@
|
||||
package org.kar.karideo.api;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
|
||||
import org.kar.karideo.WebLauncher;
|
||||
import org.kar.karideo.db.DBEntry;
|
||||
import org.kar.karideo.model.Data;
|
||||
import org.kar.karideo.model.NodeSmall;
|
||||
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class NodeInterface {
|
||||
/* test en SQL qui fait joli...
|
||||
SELECT node.id,
|
||||
node.name,
|
||||
node.description,
|
||||
node.parent_id,
|
||||
GROUP_CONCAT(cover_link_node.data_id SEPARATOR '-') as covers
|
||||
FROM node, cover_link_node
|
||||
WHERE node.deleted = false AND cover_link_node.deleted = false AND node.type = "TYPE" AND cover_link_node.node_id = node.id
|
||||
GROUP BY node.id
|
||||
ORDER BY node.name
|
||||
|
||||
// bon c'est bien mais c'est mieux en faisant un left join avec préfiltrage ...
|
||||
|
||||
|
||||
SELECT node.id,
|
||||
node.name,
|
||||
node.description,
|
||||
node.parent_id,
|
||||
cover_link_node.data_id
|
||||
FROM node
|
||||
LEFT JOIN cover_link_node
|
||||
ON node.id = cover_link_node.node_id
|
||||
AND cover_link_node.deleted = false
|
||||
WHERE node.deleted = false
|
||||
AND node.type = "TYPE"
|
||||
ORDER BY node.name
|
||||
|
||||
// marche pas:
|
||||
SELECT node.id,
|
||||
node.name,
|
||||
node.description,
|
||||
node.parent_id,
|
||||
`extract.covers`
|
||||
FROM node
|
||||
LEFT JOIN (SELECT tmp.node_id,
|
||||
GROUP_CONCAT(`tmp.data_id` SEPARATOR '-') as `covers`
|
||||
FROM cover_link_node tmp
|
||||
WHERE tmp.deleted = false
|
||||
GROUP BY tmp.node_id) extract
|
||||
ON node.id = extract.node_id
|
||||
WHERE node.deleted = false
|
||||
AND node.type = "TYPE"
|
||||
ORDER BY node.name
|
||||
|
||||
// et enfin une version qui fonctionne ...
|
||||
SELECT node.id,
|
||||
node.name,
|
||||
node.description,
|
||||
node.parent_id,
|
||||
(SELECT GROUP_CONCAT(tmp.data_id)
|
||||
FROM cover_link_node tmp
|
||||
WHERE tmp.deleted = false
|
||||
AND node.id = tmp.node_id
|
||||
GROUP BY tmp.node_id) AS covers
|
||||
FROM node
|
||||
WHERE node.deleted = false
|
||||
AND node.type = "TYPE"
|
||||
ORDER BY node.name
|
||||
|
||||
*/
|
||||
public static List<NodeSmall> get(String typeInNode) {
|
||||
System.out.println(typeInNode + " get");
|
||||
DBEntry entry = new DBEntry(WebLauncher.dbConfig);
|
||||
List<NodeSmall> out = new ArrayList<>();
|
||||
String query = "SELECT node.id," +
|
||||
" node.name," +
|
||||
" node.description," +
|
||||
" node.parent_id," +
|
||||
" (SELECT GROUP_CONCAT(tmp.data_id SEPARATOR '-')" +
|
||||
" FROM cover_link_node tmp" +
|
||||
" WHERE tmp.deleted = false" +
|
||||
" AND node.id = tmp.node_id" +
|
||||
" GROUP BY tmp.node_id) AS covers" +
|
||||
" FROM node" +
|
||||
" WHERE node.deleted = false " +
|
||||
" AND node.type = ?" +
|
||||
" ORDER BY node.name";
|
||||
try {
|
||||
PreparedStatement ps = entry.connection.prepareStatement(query);
|
||||
int iii = 1;
|
||||
ps.setString(iii++, typeInNode);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
while (rs.next()) {
|
||||
out.add(new NodeSmall(rs));
|
||||
}
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
entry.disconnect();
|
||||
entry = null;
|
||||
System.out.println("retrieve " + out.size() + " " + typeInNode);
|
||||
return out;
|
||||
}
|
||||
|
||||
public static NodeSmall getWithId(String typeInNode, long id) {
|
||||
DBEntry entry = new DBEntry(WebLauncher.dbConfig);
|
||||
String query = "SELECT node.id," +
|
||||
" node.name," +
|
||||
" node.description," +
|
||||
" node.parent_id," +
|
||||
" (SELECT GROUP_CONCAT(tmp.data_id SEPARATOR '-')" +
|
||||
" FROM cover_link_node tmp" +
|
||||
" WHERE tmp.deleted = false" +
|
||||
" AND node.id = tmp.node_id" +
|
||||
" GROUP BY tmp.node_id) AS covers" +
|
||||
" FROM node" +
|
||||
" WHERE node.deleted = false " +
|
||||
" AND node.type = ?" +
|
||||
" AND node.id = ?" +
|
||||
" ORDER BY node.name";
|
||||
try {
|
||||
PreparedStatement ps = entry.connection.prepareStatement(query);
|
||||
int iii = 1;
|
||||
ps.setString(iii++, typeInNode);
|
||||
ps.setLong(iii++, id);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
if (rs.next()) {
|
||||
NodeSmall out = new NodeSmall(rs);
|
||||
entry.disconnect();
|
||||
entry = null;
|
||||
return out;
|
||||
}
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
entry.disconnect();
|
||||
entry = null;
|
||||
return null;
|
||||
}
|
||||
|
||||
public static List<NodeSmall> getWithName(String typeInNode, String name) {
|
||||
DBEntry entry = new DBEntry(WebLauncher.dbConfig);
|
||||
List<NodeSmall> out = new ArrayList<>();
|
||||
String query = "SELECT node.id," +
|
||||
" node.name," +
|
||||
" node.description," +
|
||||
" node.parent_id," +
|
||||
" (SELECT GROUP_CONCAT(tmp.data_id SEPARATOR '-')" +
|
||||
" FROM cover_link_node tmp" +
|
||||
" WHERE tmp.deleted = false" +
|
||||
" AND node.id = tmp.node_id" +
|
||||
" GROUP BY tmp.node_id) AS covers" +
|
||||
" FROM node" +
|
||||
" WHERE node.deleted = false " +
|
||||
" AND node.type = ?" +
|
||||
" AND node.name = ?" +
|
||||
" ORDER BY node.name";
|
||||
try {
|
||||
PreparedStatement ps = entry.connection.prepareStatement(query);
|
||||
int iii = 1;
|
||||
ps.setString(iii++, typeInNode);
|
||||
ps.setString(iii++, name);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
while (rs.next()) {
|
||||
out.add(new NodeSmall(rs));
|
||||
}
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
entry.disconnect();
|
||||
entry = null;
|
||||
return out;
|
||||
}
|
||||
|
||||
public static NodeSmall getWithNameAndParent(String typeInNode, String name, long parentId) {
|
||||
DBEntry entry = new DBEntry(WebLauncher.dbConfig);
|
||||
String query = "SELECT node.id," +
|
||||
" node.name," +
|
||||
" node.description," +
|
||||
" node.parent_id," +
|
||||
" (SELECT GROUP_CONCAT(tmp.data_id SEPARATOR '-')" +
|
||||
" FROM cover_link_node tmp" +
|
||||
" WHERE tmp.deleted = false" +
|
||||
" AND node.id = tmp.node_id" +
|
||||
" GROUP BY tmp.node_id) AS covers" +
|
||||
" FROM node" +
|
||||
" WHERE node.deleted = false " +
|
||||
" AND node.type = ?" +
|
||||
" AND node.name = ?" +
|
||||
" AND node.parent_id = ?" +
|
||||
" ORDER BY node.name";
|
||||
try {
|
||||
PreparedStatement ps = entry.connection.prepareStatement(query);
|
||||
int iii = 1;
|
||||
ps.setString(iii++, typeInNode);
|
||||
ps.setString(iii++, name);
|
||||
ps.setLong(iii++, parentId);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
if (rs.next()) {
|
||||
NodeSmall out = new NodeSmall(rs);
|
||||
entry.disconnect();
|
||||
entry = null;
|
||||
return out;
|
||||
}
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
entry.disconnect();
|
||||
entry = null;
|
||||
return null;
|
||||
}
|
||||
|
||||
public static NodeSmall createNode(String typeInNode, String name, String descrition, Long parentId) {
|
||||
DBEntry entry = new DBEntry(WebLauncher.dbConfig);
|
||||
long uniqueSQLID = -1;
|
||||
// real add in the BDD:
|
||||
try {
|
||||
// prepare the request:
|
||||
String query = "INSERT INTO node (`type`, `name`, `description`, `parent_id`) VALUES (?, ?, ?, ?)";
|
||||
PreparedStatement ps = entry.connection.prepareStatement(query,
|
||||
Statement.RETURN_GENERATED_KEYS);
|
||||
int iii = 1;
|
||||
ps.setString(iii++, typeInNode);
|
||||
ps.setString(iii++, name);
|
||||
if (descrition == null) {
|
||||
ps.setNull(iii++, Types.VARCHAR);
|
||||
} else {
|
||||
ps.setString(iii++, descrition);
|
||||
}
|
||||
if (parentId == null) {
|
||||
ps.setNull(iii++, Types.BIGINT);
|
||||
} else {
|
||||
ps.setLong(iii++, parentId);
|
||||
}
|
||||
// execute the request
|
||||
int affectedRows = ps.executeUpdate();
|
||||
if (affectedRows == 0) {
|
||||
throw new SQLException("Creating node failed, no rows affected.");
|
||||
}
|
||||
// retreive uid inserted
|
||||
try (ResultSet generatedKeys = ps.getGeneratedKeys()) {
|
||||
if (generatedKeys.next()) {
|
||||
uniqueSQLID = generatedKeys.getLong(1);
|
||||
} else {
|
||||
throw new SQLException("Creating node failed, no ID obtained (1).");
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
System.out.println("Can not get the UID key inserted ... ");
|
||||
ex.printStackTrace();
|
||||
throw new SQLException("Creating node failed, no ID obtained (2).");
|
||||
}
|
||||
//ps.execute();
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return getWithId(typeInNode, uniqueSQLID);
|
||||
|
||||
}
|
||||
|
||||
public static NodeSmall getOrCreate(String typeInNode, String name, Long parentId) {
|
||||
if (name == null || name.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
NodeSmall node = getWithNameAndParent(typeInNode, name, parentId);
|
||||
if (node != null) {
|
||||
return node;
|
||||
}
|
||||
return createNode(typeInNode, name, null, parentId);
|
||||
}
|
||||
|
||||
static private String multipartCorrection(String data) {
|
||||
if (data == null) {
|
||||
return null;
|
||||
}
|
||||
if (data.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
if (data.contentEquals("null")) {
|
||||
return null;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
static public Response uploadCover(String typeInNode,
|
||||
Long nodeId,
|
||||
String file_name,
|
||||
InputStream fileInputStream,
|
||||
FormDataContentDisposition fileMetaData
|
||||
) {
|
||||
try {
|
||||
// correct input string stream :
|
||||
file_name = multipartCorrection(file_name);
|
||||
|
||||
//public NodeSmall uploadFile(final FormDataMultiPart form) {
|
||||
System.out.println("Upload media file: " + fileMetaData);
|
||||
System.out.println(" - id: " + nodeId);
|
||||
System.out.println(" - file_name: " + file_name);
|
||||
System.out.println(" - fileInputStream: " + fileInputStream);
|
||||
System.out.println(" - fileMetaData: " + fileMetaData);
|
||||
System.out.flush();
|
||||
NodeSmall media = getWithId(typeInNode, nodeId);
|
||||
if (media == null) {
|
||||
return Response.notModified("Media Id does not exist or removed...").build();
|
||||
}
|
||||
|
||||
long tmpUID = DataResource.getTmpDataId();
|
||||
String sha512 = DataResource.saveTemporaryFile(fileInputStream, tmpUID);
|
||||
Data data = DataResource.getWithSha512(sha512);
|
||||
if (data == null) {
|
||||
System.out.println("Need to add the data in the BDD ... ");
|
||||
System.out.flush();
|
||||
try {
|
||||
data = DataResource.createNewData(tmpUID, file_name, sha512);
|
||||
} catch (IOException ex) {
|
||||
DataResource.removeTemporaryFile(tmpUID);
|
||||
ex.printStackTrace();
|
||||
return Response.notModified("can not create input media").build();
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
DataResource.removeTemporaryFile(tmpUID);
|
||||
return Response.notModified("Error in SQL insertion ...").build();
|
||||
}
|
||||
} else if (data.deleted == true) {
|
||||
System.out.println("Data already exist but deleted");
|
||||
System.out.flush();
|
||||
DataResource.undelete(data.id);
|
||||
data.deleted = false;
|
||||
} else {
|
||||
System.out.println("Data already exist ... all good");
|
||||
System.out.flush();
|
||||
}
|
||||
// Fist step: retrieve all the Id of each parents:...
|
||||
System.out.println("Find typeNode");
|
||||
|
||||
DBEntry entry = new DBEntry(WebLauncher.dbConfig);
|
||||
long uniqueSQLID = -1;
|
||||
// real add in the BDD:
|
||||
try {
|
||||
// prepare the request:
|
||||
String query = "INSERT INTO cover_link_node (create_date, modify_date, node_id, data_id)" +
|
||||
" VALUES (now(3), now(3), ?, ?)";
|
||||
PreparedStatement ps = entry.connection.prepareStatement(query,
|
||||
Statement.RETURN_GENERATED_KEYS);
|
||||
int iii = 1;
|
||||
ps.setLong(iii++, media.id);
|
||||
ps.setLong(iii++, data.id);
|
||||
// execute the request
|
||||
int affectedRows = ps.executeUpdate();
|
||||
if (affectedRows == 0) {
|
||||
throw new SQLException("Creating data failed, no rows affected.");
|
||||
}
|
||||
// retreive uid inserted
|
||||
try (ResultSet generatedKeys = ps.getGeneratedKeys()) {
|
||||
if (generatedKeys.next()) {
|
||||
uniqueSQLID = generatedKeys.getLong(1);
|
||||
} else {
|
||||
throw new SQLException("Creating user failed, no ID obtained (1).");
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
System.out.println("Can not get the UID key inserted ... ");
|
||||
ex.printStackTrace();
|
||||
throw new SQLException("Creating user failed, no ID obtained (2).");
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
entry.disconnect();
|
||||
return Response.serverError().build();
|
||||
}
|
||||
// if we do not une the file .. remove it ... otherwise this is meamory leak...
|
||||
DataResource.removeTemporaryFile(tmpUID);
|
||||
System.out.println("uploaded .... compleate: " + uniqueSQLID);
|
||||
return Response.ok(getWithId(typeInNode, nodeId)).build();
|
||||
} catch (Exception ex) {
|
||||
System.out.println("Cat ann unexpected error ... ");
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return Response.serverError().build();
|
||||
}
|
||||
static public Response removeCover(String typeInNode, Long nodeId, Long coverId) {
|
||||
DBEntry entry = new DBEntry(WebLauncher.dbConfig);
|
||||
String query = "UPDATE `cover_link_node` SET `modify_date`=now(3), `deleted`=true WHERE `node_id` = ? AND `data_id` = ?";
|
||||
try {
|
||||
PreparedStatement ps = entry.connection.prepareStatement(query);
|
||||
int iii = 1;
|
||||
ps.setLong(iii++, nodeId);
|
||||
ps.setLong(iii++, coverId);
|
||||
ps.executeUpdate();
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
entry.disconnect();
|
||||
return Response.serverError().build();
|
||||
}
|
||||
entry.disconnect();
|
||||
return Response.ok(getWithId(typeInNode, nodeId)).build();
|
||||
}
|
||||
|
||||
static public Response put(String typeInNode, Long id, String jsonRequest) {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
try {
|
||||
JsonNode root = mapper.readTree(jsonRequest);
|
||||
String query = "UPDATE `node` SET `modify_date`=now(3)";
|
||||
if (!root.path("name").isMissingNode()) {
|
||||
query += ", `name` = ? ";
|
||||
}
|
||||
if (!root.path("description").isMissingNode()) {
|
||||
query += ", `description` = ? ";
|
||||
}
|
||||
if (!root.path("parentId").isMissingNode()) {
|
||||
query += ", `parent_id` = ? ";
|
||||
}
|
||||
query += " WHERE `id` = ?";
|
||||
DBEntry entry = new DBEntry(WebLauncher.dbConfig);
|
||||
try {
|
||||
PreparedStatement ps = entry.connection.prepareStatement(query);
|
||||
int iii = 1;
|
||||
if (!root.path("name").isMissingNode()) {
|
||||
if (root.path("name").isNull()) {
|
||||
ps.setString(iii++, "???");
|
||||
} else {
|
||||
ps.setString(iii++, root.path("name").asText());
|
||||
}
|
||||
}
|
||||
if (!root.path("description").isMissingNode()) {
|
||||
if (root.path("description").isNull()) {
|
||||
ps.setNull(iii++, Types.VARCHAR);
|
||||
} else {
|
||||
ps.setString(iii++, root.path("description").asText());
|
||||
}
|
||||
}
|
||||
if (!root.path("parentId").isMissingNode()) {
|
||||
if (root.path("parentId").isNull()) {
|
||||
ps.setNull(iii++, Types.BIGINT);
|
||||
} else {
|
||||
ps.setLong(iii++, root.path("parentId").asLong());
|
||||
}
|
||||
}
|
||||
ps.setLong(iii++, id);
|
||||
System.out.println(" request : " + ps.toString());
|
||||
ps.executeUpdate();
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
entry.disconnect();
|
||||
entry = null;
|
||||
return Response.notModified("SQL error").build();
|
||||
}
|
||||
entry.disconnect();
|
||||
entry = null;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return Response.notModified("input json error error").build();
|
||||
}
|
||||
return Response.ok(getWithId(typeInNode, id)).build();
|
||||
}
|
||||
|
||||
|
||||
static public Response delete(String typeInNode, Long nodeId) {
|
||||
DBEntry entry = new DBEntry(WebLauncher.dbConfig);
|
||||
String query = "UPDATE `node` SET `modify_date`=now(3), `deleted`=true WHERE `id` = ? AND `type` = ?";
|
||||
try {
|
||||
PreparedStatement ps = entry.connection.prepareStatement(query);
|
||||
int iii = 1;
|
||||
ps.setLong(iii++, nodeId);
|
||||
ps.setString(iii++, typeInNode);
|
||||
ps.executeUpdate();
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
entry.disconnect();
|
||||
return Response.serverError().build();
|
||||
}
|
||||
entry.disconnect();
|
||||
return Response.ok().build();
|
||||
}
|
||||
|
||||
}
|
@ -2,10 +2,11 @@ package org.kar.karideo.api;
|
||||
|
||||
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
|
||||
import org.glassfish.jersey.media.multipart.FormDataParam;
|
||||
import org.kar.karideo.model.NodeSmall;
|
||||
import org.kar.karideo.model.Season;
|
||||
import org.kar.archidata.SqlWrapper;
|
||||
import org.kar.archidata.annotation.security.RolesAllowed;
|
||||
import org.kar.archidata.util.DataTools;
|
||||
|
||||
import org.kar.archidata.annotation.security.PermitAll;
|
||||
import javax.annotation.security.RolesAllowed;
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
@ -15,42 +16,54 @@ import java.util.List;
|
||||
@Path("/season")
|
||||
@Produces({MediaType.APPLICATION_JSON})
|
||||
public class SeasonResource {
|
||||
private static final String typeInNode = "SEASON";
|
||||
|
||||
@GET
|
||||
@Path("{id}")
|
||||
@RolesAllowed("USER")
|
||||
public static NodeSmall getWithId(@PathParam("id") Long id) {
|
||||
return NodeInterface.getWithId(typeInNode, id);
|
||||
}
|
||||
|
||||
public static List<NodeSmall> getWithName(String name) {
|
||||
return NodeInterface.getWithName(typeInNode, name);
|
||||
}
|
||||
|
||||
public static NodeSmall getOrCreate(int season, Long seriesId) {
|
||||
return NodeInterface.getOrCreate(typeInNode, Integer.toString(season), seriesId);
|
||||
public static Season getWithId(@PathParam("id") Long id) throws Exception {
|
||||
return SqlWrapper.get(Season.class, id);
|
||||
}
|
||||
|
||||
@GET
|
||||
@RolesAllowed("USER")
|
||||
public List<NodeSmall> get() {
|
||||
return NodeInterface.get(typeInNode);
|
||||
public List<Season> get() throws Exception {
|
||||
return SqlWrapper.gets(Season.class, false);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("{id}")
|
||||
@RolesAllowed("USER")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public Season get(@PathParam("id") Long id) throws Exception {
|
||||
return SqlWrapper.get(Season.class, id);
|
||||
}
|
||||
|
||||
/* =============================================================================
|
||||
* ADMIN SECTION:
|
||||
* ============================================================================= */
|
||||
|
||||
@POST
|
||||
@RolesAllowed("ADMIN")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public Season put(String jsonRequest) throws Exception {
|
||||
return SqlWrapper.insertWithJson(Season.class, jsonRequest);
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("{id}")
|
||||
@RolesAllowed("ADMIN")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public Response put(@PathParam("id") Long id, String jsonRequest) {
|
||||
return NodeInterface.put(typeInNode, id, jsonRequest);
|
||||
public Season put(@PathParam("id") Long id, String jsonRequest) throws Exception {
|
||||
SqlWrapper.update(Season.class, id, jsonRequest);
|
||||
return SqlWrapper.get(Season.class, id);
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("{id}")
|
||||
@RolesAllowed("ADMIN")
|
||||
public Response delete(@PathParam("id") Long id) {
|
||||
return NodeInterface.delete(typeInNode, id);
|
||||
public Response delete(@PathParam("id") Long id) throws Exception {
|
||||
SqlWrapper.setDelete(Season.class, id);
|
||||
return Response.ok().build();
|
||||
}
|
||||
|
||||
@POST
|
||||
@ -62,12 +75,32 @@ public class SeasonResource {
|
||||
@FormDataParam("file") InputStream fileInputStream,
|
||||
@FormDataParam("file") FormDataContentDisposition fileMetaData
|
||||
) {
|
||||
return NodeInterface.uploadCover(typeInNode, id, fileName, fileInputStream, fileMetaData);
|
||||
return DataTools.uploadCover(Season.class, id, fileName, fileInputStream, fileMetaData);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("{id}/rm_cover/{cover_id}")
|
||||
@Path("{id}/rm_cover/{coverId}")
|
||||
@RolesAllowed("ADMIN")
|
||||
public Response removeCover(@PathParam("id") Long nodeId, @PathParam("cover_id") Long coverId) {
|
||||
return NodeInterface.removeCover(typeInNode, nodeId, coverId);
|
||||
public Response removeCover(@PathParam("id") Long id, @PathParam("coverId") Long coverId) throws Exception {
|
||||
SqlWrapper.removeLink(Season.class, id, "cover", coverId);
|
||||
return Response.ok(SqlWrapper.get(Season.class, id)).build();
|
||||
}
|
||||
|
||||
public static Season getOrCreate(String name, Long seriesId) {
|
||||
try {
|
||||
Season out = SqlWrapper.getWhere(Season.class, "name", "=", name, "parentId", "=", seriesId);
|
||||
if (out == null) {
|
||||
out = new Season();
|
||||
out.name = name;
|
||||
out.parentId = seriesId;
|
||||
out = SqlWrapper.insert(out);
|
||||
return out;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,10 +2,12 @@ package org.kar.karideo.api;
|
||||
|
||||
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
|
||||
import org.glassfish.jersey.media.multipart.FormDataParam;
|
||||
import org.kar.karideo.model.NodeSmall;
|
||||
import org.kar.karideo.model.Season;
|
||||
import org.kar.karideo.model.Series;
|
||||
import org.kar.archidata.SqlWrapper;
|
||||
import org.kar.archidata.annotation.security.RolesAllowed;
|
||||
import org.kar.archidata.util.DataTools;
|
||||
|
||||
import org.kar.archidata.annotation.security.PermitAll;
|
||||
import javax.annotation.security.RolesAllowed;
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
@ -15,43 +17,54 @@ import java.util.List;
|
||||
@Path("/series")
|
||||
@Produces({MediaType.APPLICATION_JSON})
|
||||
public class SeriesResource {
|
||||
private static final String typeInNode = "SERIES";
|
||||
|
||||
@GET
|
||||
@Path("{id}")
|
||||
@RolesAllowed("USER")
|
||||
public static NodeSmall getWithId(@PathParam("id") Long id) {
|
||||
return NodeInterface.getWithId(typeInNode, id);
|
||||
}
|
||||
|
||||
public static List<NodeSmall> getWithName(String name) {
|
||||
return NodeInterface.getWithName(typeInNode, name);
|
||||
}
|
||||
|
||||
public static NodeSmall getOrCreate(String series, Long typeId) {
|
||||
return NodeInterface.getOrCreate(typeInNode, series, typeId);
|
||||
|
||||
public static Series getWithId(@PathParam("id") Long id) throws Exception {
|
||||
return SqlWrapper.get(Series.class, id);
|
||||
}
|
||||
|
||||
@GET
|
||||
@RolesAllowed("USER")
|
||||
public List<NodeSmall> get() {
|
||||
return NodeInterface.get(typeInNode);
|
||||
public List<Series> get() throws Exception {
|
||||
return SqlWrapper.gets(Series.class, false);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("{id}")
|
||||
@RolesAllowed("USER")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public Series get(@PathParam("id") Long id) throws Exception {
|
||||
return SqlWrapper.get(Series.class, id);
|
||||
}
|
||||
|
||||
/* =============================================================================
|
||||
* ADMIN SECTION:
|
||||
* ============================================================================= */
|
||||
|
||||
@POST
|
||||
@RolesAllowed("ADMIN")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public Series put(String jsonRequest) throws Exception {
|
||||
return SqlWrapper.insertWithJson(Series.class, jsonRequest);
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("{id}")
|
||||
@RolesAllowed("ADMIN")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public Response put(@PathParam("id") Long id, String jsonRequest) {
|
||||
return NodeInterface.put(typeInNode, id, jsonRequest);
|
||||
public Series put(@PathParam("id") Long id, String jsonRequest) throws Exception {
|
||||
SqlWrapper.update(Series.class, id, jsonRequest);
|
||||
return SqlWrapper.get(Series.class, id);
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("{id}")
|
||||
@RolesAllowed("ADMIN")
|
||||
public Response delete(@PathParam("id") Long id) {
|
||||
return NodeInterface.delete(typeInNode, id);
|
||||
public Response delete(@PathParam("id") Long id) throws Exception {
|
||||
SqlWrapper.setDelete(Series.class, id);
|
||||
return Response.ok().build();
|
||||
}
|
||||
|
||||
@POST
|
||||
@ -63,14 +76,32 @@ public class SeriesResource {
|
||||
@FormDataParam("file") InputStream fileInputStream,
|
||||
@FormDataParam("file") FormDataContentDisposition fileMetaData
|
||||
) {
|
||||
return NodeInterface.uploadCover(typeInNode, id, fileName, fileInputStream, fileMetaData);
|
||||
return DataTools.uploadCover(Series.class, id, fileName, fileInputStream, fileMetaData);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("{id}/rm_cover/{coverId}")
|
||||
@RolesAllowed("ADMIN")
|
||||
public Response removeCover(@PathParam("id") Long nodeId, @PathParam("coverId") Long coverId) {
|
||||
return NodeInterface.removeCover(typeInNode, nodeId, coverId);
|
||||
public Response removeCover(@PathParam("id") Long id, @PathParam("coverId") Long coverId) throws Exception {
|
||||
SqlWrapper.removeLink(Series.class, id, "cover", coverId);
|
||||
return Response.ok(SqlWrapper.get(Series.class, id)).build();
|
||||
}
|
||||
|
||||
public static Series getOrCreate(String name, Long typeId) {
|
||||
try {
|
||||
Series out = SqlWrapper.getWhere(Series.class, "name", "=", name, "parentId", "=", typeId);
|
||||
if (out == null) {
|
||||
out = new Series();
|
||||
out.name = name;
|
||||
out.parentId = typeId;
|
||||
out = SqlWrapper.insert(out);
|
||||
return out;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,10 +2,11 @@ package org.kar.karideo.api;
|
||||
|
||||
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
|
||||
import org.glassfish.jersey.media.multipart.FormDataParam;
|
||||
import org.kar.karideo.model.NodeSmall;
|
||||
import org.kar.karideo.model.Type;
|
||||
import org.kar.archidata.SqlWrapper;
|
||||
import org.kar.archidata.annotation.security.RolesAllowed;
|
||||
import org.kar.archidata.util.DataTools;
|
||||
|
||||
import org.kar.archidata.annotation.security.PermitAll;
|
||||
import javax.annotation.security.RolesAllowed;
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
@ -15,38 +16,59 @@ import java.util.List;
|
||||
@Path("/type")
|
||||
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
|
||||
public class TypeResource {
|
||||
private static final String typeInNode = "TYPE";
|
||||
|
||||
|
||||
@GET
|
||||
@Path("{id}")
|
||||
@RolesAllowed("USER")
|
||||
public static NodeSmall getWithId(@PathParam("id") Long id) {
|
||||
return NodeInterface.getWithId(typeInNode, id);
|
||||
}
|
||||
|
||||
public static List<NodeSmall> getWithName(String name) {
|
||||
return NodeInterface.getWithName(typeInNode, name);
|
||||
public static Type getWithId(@PathParam("id") Long id) throws Exception {
|
||||
return SqlWrapper.get(Type.class, id);
|
||||
}
|
||||
|
||||
@GET
|
||||
@RolesAllowed("USER")
|
||||
public List<NodeSmall> get() {
|
||||
return NodeInterface.get(typeInNode);
|
||||
public List<Type> get() throws Exception {
|
||||
return SqlWrapper.gets(Type.class, false);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("{id}")
|
||||
@RolesAllowed("USER")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public Type get(@PathParam("id") Long id) throws Exception {
|
||||
return SqlWrapper.get(Type.class, id);
|
||||
}
|
||||
|
||||
public static Type getId(Long id) throws Exception {
|
||||
return SqlWrapper.get(Type.class, id);
|
||||
}
|
||||
|
||||
/* =============================================================================
|
||||
* ADMIN SECTION:
|
||||
* ============================================================================= */
|
||||
|
||||
@POST
|
||||
@RolesAllowed("ADMIN")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public Type put(String jsonRequest) throws Exception {
|
||||
return SqlWrapper.insertWithJson(Type.class, jsonRequest);
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("{id}")
|
||||
@RolesAllowed("ADMIN")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public Response put(@PathParam("id") Long id, String jsonRequest) {
|
||||
return NodeInterface.put(typeInNode, id, jsonRequest);
|
||||
public Type put(@PathParam("id") Long id, String jsonRequest) throws Exception {
|
||||
SqlWrapper.update(Type.class, id, jsonRequest);
|
||||
return SqlWrapper.get(Type.class, id);
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("{id}")
|
||||
@RolesAllowed("ADMIN")
|
||||
public Response delete(@PathParam("id") Long id) {
|
||||
return NodeInterface.delete(typeInNode, id);
|
||||
public Response delete(@PathParam("id") Long id) throws Exception {
|
||||
SqlWrapper.setDelete(Type.class, id);
|
||||
return Response.ok().build();
|
||||
}
|
||||
|
||||
@POST
|
||||
@ -54,16 +76,36 @@ public class TypeResource {
|
||||
@RolesAllowed("ADMIN")
|
||||
@Consumes({MediaType.MULTIPART_FORM_DATA})
|
||||
public Response uploadCover(@PathParam("id") Long id,
|
||||
@FormDataParam("file_name") String file_name,
|
||||
@FormDataParam("fileName") String fileName,
|
||||
@FormDataParam("file") InputStream fileInputStream,
|
||||
@FormDataParam("file") FormDataContentDisposition fileMetaData
|
||||
) {
|
||||
return NodeInterface.uploadCover(typeInNode, id, file_name, fileInputStream, fileMetaData);
|
||||
return DataTools.uploadCover(Type.class, id, fileName, fileInputStream, fileMetaData);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("{id}/rm_cover/{cover_id}")
|
||||
@Path("{id}/rm_cover/{coverId}")
|
||||
@RolesAllowed("ADMIN")
|
||||
public Response removeCover(@PathParam("id") Long nodeId, @PathParam("cover_id") Long coverId) {
|
||||
return NodeInterface.removeCover(typeInNode, nodeId, coverId);
|
||||
public Response removeCover(@PathParam("id") Long id, @PathParam("coverId") Long coverId) throws Exception {
|
||||
SqlWrapper.removeLink(Type.class, id, "cover", coverId);
|
||||
return Response.ok(SqlWrapper.get(Type.class, id)).build();
|
||||
}
|
||||
|
||||
public static Type getOrCreate(String name) {
|
||||
try {
|
||||
Type out = SqlWrapper.getWhere(Type.class, "name", "=", name);
|
||||
if (out == null) {
|
||||
out = new Type();
|
||||
out.name = name;
|
||||
out = SqlWrapper.insert(out);
|
||||
return out;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,73 +0,0 @@
|
||||
package org.kar.karideo.api;
|
||||
|
||||
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
|
||||
import org.glassfish.jersey.media.multipart.FormDataParam;
|
||||
import org.kar.karideo.model.NodeSmall;
|
||||
|
||||
import org.kar.archidata.annotation.security.PermitAll;
|
||||
import javax.annotation.security.RolesAllowed;
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
|
||||
@Path("/universe")
|
||||
@Produces({MediaType.APPLICATION_JSON})
|
||||
public class UniverseResource {
|
||||
private static final String typeInNode = "UNIVERSE";
|
||||
|
||||
@GET
|
||||
@Path("{id}")
|
||||
@RolesAllowed("USER")
|
||||
public static NodeSmall getWithId(@PathParam("id") Long id) {
|
||||
return NodeInterface.getWithId(typeInNode, id);
|
||||
}
|
||||
|
||||
public static List<NodeSmall> getWithName(String name) {
|
||||
return NodeInterface.getWithName(typeInNode, name);
|
||||
}
|
||||
|
||||
public static NodeSmall getOrCreate(String universe) {
|
||||
return NodeInterface.getOrCreate(typeInNode, universe, null);
|
||||
}
|
||||
|
||||
@GET
|
||||
@RolesAllowed("USER")
|
||||
public List<NodeSmall> get() {
|
||||
return NodeInterface.get(typeInNode);
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("{id}")
|
||||
@RolesAllowed("ADMIN")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public Response put(@PathParam("id") Long id, String jsonRequest) {
|
||||
return NodeInterface.put(typeInNode, id, jsonRequest);
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("{id}")
|
||||
@RolesAllowed("ADMIN")
|
||||
public Response delete(@PathParam("id") Long id) {
|
||||
return NodeInterface.delete(typeInNode, id);
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("{id}/add_cover")
|
||||
@RolesAllowed("ADMIN")
|
||||
@Consumes({MediaType.MULTIPART_FORM_DATA})
|
||||
public Response uploadCover(@PathParam("id") Long id,
|
||||
@FormDataParam("fileName") String fileName,
|
||||
@FormDataParam("file") InputStream fileInputStream,
|
||||
@FormDataParam("file") FormDataContentDisposition fileMetaData
|
||||
) {
|
||||
return NodeInterface.uploadCover(typeInNode, id, fileName, fileInputStream, fileMetaData);
|
||||
}
|
||||
@GET
|
||||
@Path("{id}/rm_cover/{cover_id}")
|
||||
@RolesAllowed("ADMIN")
|
||||
public Response removeCover(@PathParam("id") Long nodeId, @PathParam("cover_id") Long coverId) {
|
||||
return NodeInterface.removeCover(typeInNode, nodeId, coverId);
|
||||
}
|
||||
}
|
@ -1,30 +1,16 @@
|
||||
package org.kar.karideo.api;
|
||||
|
||||
import org.kar.karideo.UserDB;
|
||||
import org.kar.karideo.WebLauncher;
|
||||
import org.kar.karideo.db.DBEntry;
|
||||
import org.kar.karideo.filter.GenericContext;
|
||||
import org.kar.karideo.model.User;
|
||||
import org.kar.karideo.model.UserExtern;
|
||||
import org.kar.karideo.model.UserPerso;
|
||||
import org.kar.archidata.SqlWrapper;
|
||||
import org.kar.archidata.filter.GenericContext;
|
||||
import org.kar.archidata.model.User;
|
||||
import org.kar.karideo.model.UserKarideo;
|
||||
|
||||
import org.kar.archidata.annotation.security.PermitAll;
|
||||
import javax.annotation.security.RolesAllowed;
|
||||
import org.kar.archidata.annotation.security.RolesAllowed;
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.SecurityContext;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
@Path("/users")
|
||||
@ -34,197 +20,52 @@ public class UserResource {
|
||||
public UserResource() {
|
||||
}
|
||||
|
||||
private static String randomString(int count) {
|
||||
Random rand = new Random(System.nanoTime());
|
||||
String s = new String();
|
||||
int nbChar = count;
|
||||
for (int i = 0; i < nbChar; i++) {
|
||||
char c = (char) rand.nextInt();
|
||||
while ((c < 'a' || c > 'z') && (c < 'A' || c > 'Z') && (c < '0' || c > '9'))
|
||||
c = (char) rand.nextInt();
|
||||
s = s + c;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
// I do not understand why angular request option before, but this is needed..
|
||||
/*
|
||||
@OPTIONS
|
||||
public Response getOption(){
|
||||
return Response.ok()
|
||||
.header("Allow", "POST")
|
||||
.header("Allow", "GET")
|
||||
.header("Allow", "OPTIONS")
|
||||
.build();
|
||||
}
|
||||
*/
|
||||
// curl http://localhost:9993/api/users
|
||||
@GET
|
||||
@RolesAllowed("ADMIN")
|
||||
public List<UserExtern> getUsers() {
|
||||
public List<UserKarideo> getUsers() {
|
||||
System.out.println("getUsers");
|
||||
DBEntry entry = new DBEntry(WebLauncher.dbConfig);
|
||||
List<UserExtern> out = new ArrayList<>();
|
||||
String query = "SELECT * FROM user";
|
||||
try {
|
||||
Statement st = entry.connection.createStatement();
|
||||
ResultSet rs = st.executeQuery(query);
|
||||
while (rs.next()) {
|
||||
out.add(new UserExtern(new User(rs)));
|
||||
return SqlWrapper.gets(UserKarideo.class, false);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
entry.disconnect();
|
||||
entry = null;
|
||||
return out;
|
||||
return null;
|
||||
}
|
||||
|
||||
// I do not understand why angular request option before, but this is needed..
|
||||
/*
|
||||
@OPTIONS
|
||||
@Path("{id}")
|
||||
public Response getTokenOption(@PathParam("id") long userId){
|
||||
return Response.ok()
|
||||
.header("Allow", "POST")
|
||||
.header("Allow", "GET")
|
||||
.header("Allow", "OPTIONS")
|
||||
.build();
|
||||
}
|
||||
*/
|
||||
// curl http://localhost:9993/api/users/3
|
||||
@GET
|
||||
@Path("{id}")
|
||||
@RolesAllowed("ADMIN")
|
||||
public UserExtern getUsers(@Context SecurityContext sc, @PathParam("id") long userId) {
|
||||
public UserKarideo getUsers(@Context SecurityContext sc, @PathParam("id") long userId) {
|
||||
System.out.println("getUser " + userId);
|
||||
GenericContext gc = (GenericContext) sc.getUserPrincipal();
|
||||
System.out.println("===================================================");
|
||||
System.out.println("== USER ? " + gc.user);
|
||||
System.out.println("===================================================");
|
||||
return new UserExtern(UserDB.getUsers(userId));
|
||||
try {
|
||||
return SqlWrapper.get(UserKarideo.class, userId);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
@OPTIONS
|
||||
@Path("me")
|
||||
public Response getOptionMe(){
|
||||
return Response.ok()
|
||||
.header("Allow", "GET")
|
||||
.header("Allow", "OPTIONS")
|
||||
.build();
|
||||
}
|
||||
*/
|
||||
// curl http://localhost:9993/api/users/3
|
||||
@GET
|
||||
@Path("me")
|
||||
@RolesAllowed("USER")
|
||||
public UserPerso getMe(@Context SecurityContext sc) {
|
||||
public User getMe(@Context SecurityContext sc) {
|
||||
System.out.println("getMe()");
|
||||
GenericContext gc = (GenericContext) sc.getUserPrincipal();
|
||||
System.out.println("===================================================");
|
||||
System.out.println("== USER ? " + gc.user);
|
||||
System.out.println("===================================================");
|
||||
return new UserPerso(gc.user);
|
||||
return gc.user;
|
||||
}
|
||||
|
||||
// curl -d '{"id":3,"login":"HeeroYui","password":"bouloued","email":"yui.heero@gmail.com","emailValidate":0,"newEmail":null,"authorisationLevel":"ADMIN"}' -H "Content-Type: application/json" -X POST http://localhost:9993/api/users
|
||||
@POST
|
||||
@RolesAllowed("ADMIN")
|
||||
public Response createUser(User user) {
|
||||
System.out.println("getUser " + user);
|
||||
/*
|
||||
DBEntry entry = new DBEntry(WebLauncher.dbConfig);
|
||||
String query = "SELECT * FROM user WHERE id = ?";
|
||||
try {
|
||||
PreparedStatement ps = entry.connection.prepareStatement(query);
|
||||
ps.setLong(1, userId);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
if (rs.next()) {
|
||||
User out = new User(rs);
|
||||
entry.disconnect();
|
||||
return out;
|
||||
}
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
entry.disconnect();
|
||||
entry = null;
|
||||
return null;
|
||||
*/
|
||||
String result = "User saved ... : " + user;
|
||||
return Response.status(201).entity(result).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/check_login")
|
||||
@PermitAll
|
||||
public Response checkLogin(@QueryParam("login") String login) {
|
||||
System.out.println("checkLogin: " + login);
|
||||
|
||||
DBEntry entry = new DBEntry(WebLauncher.dbConfig);
|
||||
String query = "SELECT COUNT(*) FROM user WHERE login = ?";
|
||||
try {
|
||||
PreparedStatement ps = entry.connection.prepareStatement(query);
|
||||
ps.setString(1, login);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
if (rs.next()) {
|
||||
int count = rs.getInt(1);
|
||||
entry.disconnect();
|
||||
if (count >= 1) {
|
||||
return Response.ok().build();
|
||||
}
|
||||
return Response.status(404).build();
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
entry.disconnect();
|
||||
return Response.status(520).build();
|
||||
}
|
||||
|
||||
// TODO: for more security we need to hash the email when sended... or remove thios API !!!
|
||||
@GET
|
||||
@Path("/check_email")
|
||||
@PermitAll
|
||||
public Response checkEmail(@QueryParam("email") String email) {
|
||||
System.out.println("checkEmail: " + email);
|
||||
|
||||
DBEntry entry = new DBEntry(WebLauncher.dbConfig);
|
||||
String query = "SELECT COUNT(*) FROM user WHERE email = ?";
|
||||
try {
|
||||
PreparedStatement ps = entry.connection.prepareStatement(query);
|
||||
ps.setString(1, email);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
if (rs.next()) {
|
||||
int count = rs.getInt(1);
|
||||
entry.disconnect();
|
||||
if (count >= 1) {
|
||||
return Response.ok().build();
|
||||
}
|
||||
return Response.status(404).build();
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
entry.disconnect();
|
||||
return Response.status(520).build();
|
||||
}
|
||||
|
||||
public String getSHA512(String passwordToHash) {
|
||||
try {
|
||||
MessageDigest md = MessageDigest.getInstance("SHA-512");
|
||||
byte[] bytes = md.digest(passwordToHash.getBytes(StandardCharsets.UTF_8));
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < bytes.length; i++) {
|
||||
sb.append(Integer.toString((bytes[i] & 0xff) + 0x100, 16).substring(1));
|
||||
}
|
||||
return sb.toString();
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,252 +1,52 @@
|
||||
package org.kar.karideo.api;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
|
||||
import org.glassfish.jersey.media.multipart.FormDataParam;
|
||||
import org.kar.karideo.WebLauncher;
|
||||
import org.kar.karideo.db.DBEntry;
|
||||
import org.kar.archidata.db.DBEntry;
|
||||
import org.kar.archidata.util.DataTools;
|
||||
import org.kar.karideo.model.Data;
|
||||
import org.kar.karideo.model.MediaSmall;
|
||||
import org.kar.karideo.model.NodeSmall;
|
||||
|
||||
import org.kar.archidata.annotation.security.PermitAll;
|
||||
import javax.annotation.security.RolesAllowed;
|
||||
import org.kar.karideo.model.Media;
|
||||
import org.kar.karideo.model.Season;
|
||||
import org.kar.karideo.model.Series;
|
||||
import org.kar.karideo.model.Type;
|
||||
import org.kar.archidata.SqlWrapper;
|
||||
import org.kar.archidata.annotation.security.RolesAllowed;
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.ResponseBuilder;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Path("/video")
|
||||
@Produces({MediaType.APPLICATION_JSON})
|
||||
public class VideoResource {
|
||||
// UPDATE `node` SET `type` = "SEASON" WHERE `type` = "SAISON"
|
||||
// UPDATE `node` SET `type` = "UNIVERSE" WHERE `type` = "UNIVERS"
|
||||
// UPDATE `node` SET `type` = "SERIES" WHERE `type` = "SERIE"
|
||||
|
||||
@GET
|
||||
@RolesAllowed("USER")
|
||||
public List<MediaSmall> get() {
|
||||
System.out.println("VIDEO get");
|
||||
DBEntry entry = new DBEntry(WebLauncher.dbConfig);
|
||||
List<MediaSmall> out = new ArrayList<>();
|
||||
String query = "SELECT media.id," +
|
||||
" media.name," +
|
||||
" media.description," +
|
||||
" media.data_id," +
|
||||
" media.type_id," +
|
||||
" media.universe_id," +
|
||||
" media.series_id," +
|
||||
" media.season_id," +
|
||||
" media.episode," +
|
||||
" media.date," +
|
||||
" media.time," +
|
||||
" media.age_limit," +
|
||||
" (SELECT GROUP_CONCAT(tmp.data_id SEPARATOR '-')" +
|
||||
" FROM cover_link_media tmp" +
|
||||
" WHERE tmp.deleted = false" +
|
||||
" AND media.id = tmp.media_id" +
|
||||
" GROUP BY tmp.media_id) AS covers" +
|
||||
" FROM media" +
|
||||
" WHERE media.deleted = false " +
|
||||
" GROUP BY media.id" +
|
||||
" ORDER BY media.name";
|
||||
try {
|
||||
Statement st = entry.connection.createStatement();
|
||||
ResultSet rs = st.executeQuery(query);
|
||||
while (rs.next()) {
|
||||
out.add(new MediaSmall(rs));
|
||||
}
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
entry.disconnect();
|
||||
entry = null;
|
||||
System.out.println("retrieve " + out.size() + " VIDEO");
|
||||
return out;
|
||||
public List<Media> get() throws Exception {
|
||||
return SqlWrapper.gets(Media.class, false);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("{id}")
|
||||
@RolesAllowed("USER")
|
||||
public MediaSmall get(@PathParam("id") Long id) {
|
||||
System.out.println("VIDEO get " + id);
|
||||
DBEntry entry = new DBEntry(WebLauncher.dbConfig);
|
||||
String query = "SELECT media.id," +
|
||||
" media.name," +
|
||||
" media.description," +
|
||||
" media.data_id," +
|
||||
" media.type_id," +
|
||||
" media.universe_id," +
|
||||
" media.series_id," +
|
||||
" media.season_id," +
|
||||
" media.episode," +
|
||||
" media.date," +
|
||||
" media.time," +
|
||||
" media.age_limit," +
|
||||
" (SELECT GROUP_CONCAT(tmp.data_id SEPARATOR '-')" +
|
||||
" FROM cover_link_media tmp" +
|
||||
" WHERE tmp.deleted = false" +
|
||||
" AND media.id = tmp.media_id" +
|
||||
" GROUP BY tmp.media_id) AS covers" +
|
||||
" FROM media" +
|
||||
" WHERE media.deleted = false " +
|
||||
" AND media.id = ? " +
|
||||
" GROUP BY media.id" +
|
||||
" ORDER BY media.name";
|
||||
try {
|
||||
PreparedStatement ps = entry.connection.prepareStatement(query);
|
||||
int iii = 1;
|
||||
ps.setLong(iii++, id);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
if (rs.next()) {
|
||||
MediaSmall out = new MediaSmall(rs);
|
||||
entry.disconnect();
|
||||
entry = null;
|
||||
return out;
|
||||
}
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
entry.disconnect();
|
||||
entry = null;
|
||||
return null;
|
||||
public Media get(@PathParam("id") Long id) throws Exception {
|
||||
return SqlWrapper.get(Media.class, id);
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("{id}")
|
||||
@RolesAllowed("ADMIN")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public Response put(@PathParam("id") Long id, String jsonRequest) {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
try {
|
||||
JsonNode root = mapper.readTree(jsonRequest);
|
||||
String query = "UPDATE `media` SET `modify_date`=now(3)";
|
||||
if (!root.path("name").isMissingNode()) {
|
||||
query += ", `name` = ? ";
|
||||
public Media put(@PathParam("id") Long id, String jsonRequest) throws Exception {
|
||||
SqlWrapper.update(Media.class, id, jsonRequest);
|
||||
return SqlWrapper.get(Media.class, id);
|
||||
}
|
||||
if (!root.path("description").isMissingNode()) {
|
||||
query += ", `description` = ? ";
|
||||
}
|
||||
if (!root.path("episode").isMissingNode()) {
|
||||
query += ", `episode` = ? ";
|
||||
}
|
||||
if (!root.path("time").isMissingNode()) {
|
||||
query += ", `time` = ? ";
|
||||
}
|
||||
if (!root.path("typeId").isMissingNode()) {
|
||||
query += ", `type_id` = ? ";
|
||||
}
|
||||
if (!root.path("universeId").isMissingNode()) {
|
||||
query += ", `universe_id` = ? ";
|
||||
}
|
||||
if (!root.path("seriesId").isMissingNode()) {
|
||||
query += ", `series_id` = ? ";
|
||||
}
|
||||
if (!root.path("seasonId").isMissingNode()) {
|
||||
query += ", `season_id` = ? ";
|
||||
}
|
||||
query += " WHERE `id` = ?";
|
||||
DBEntry entry = new DBEntry(WebLauncher.dbConfig);
|
||||
try {
|
||||
PreparedStatement ps = entry.connection.prepareStatement(query);
|
||||
int iii = 1;
|
||||
if (!root.path("name").isMissingNode()) {
|
||||
if (root.path("name").isNull()) {
|
||||
ps.setString(iii++, "???");
|
||||
} else {
|
||||
ps.setString(iii++, root.path("name").asText());
|
||||
}
|
||||
}
|
||||
if (!root.path("description").isMissingNode()) {
|
||||
if (root.path("description").isNull()) {
|
||||
ps.setNull(iii++, Types.VARCHAR);
|
||||
} else {
|
||||
ps.setString(iii++, root.path("description").asText());
|
||||
}
|
||||
}
|
||||
if (!root.path("episode").isMissingNode()) {
|
||||
if (root.path("episode").isNull()) {
|
||||
ps.setNull(iii++, Types.INTEGER);
|
||||
} else {
|
||||
ps.setInt(iii++, root.path("episode").asInt());
|
||||
}
|
||||
}
|
||||
if (!root.path("time").isMissingNode()) {
|
||||
if (root.path("time").isNull()) {
|
||||
ps.setNull(iii++, Types.INTEGER);
|
||||
} else {
|
||||
ps.setInt(iii++, root.path("time").asInt());
|
||||
}
|
||||
}
|
||||
if (!root.path("typeId").isMissingNode()) {
|
||||
if (root.path("typeId").isNull()) {
|
||||
ps.setNull(iii++, Types.BIGINT);
|
||||
} else {
|
||||
ps.setLong(iii++, root.path("typeId").asLong());
|
||||
}
|
||||
}
|
||||
if (!root.path("universe_id").isMissingNode()) {
|
||||
if (root.path("universe_id").isNull()) {
|
||||
ps.setNull(iii++, Types.BIGINT);
|
||||
} else {
|
||||
ps.setLong(iii++, root.path("universeId").asLong());
|
||||
}
|
||||
}
|
||||
if (!root.path("seriesId").isMissingNode()) {
|
||||
if (root.path("seriesId").isNull()) {
|
||||
ps.setNull(iii++, Types.BIGINT);
|
||||
} else {
|
||||
ps.setLong(iii++, root.path("seriesId").asLong());
|
||||
}
|
||||
}
|
||||
if (!root.path("seasonId").isMissingNode()) {
|
||||
if (root.path("seasonId").isNull()) {
|
||||
ps.setNull(iii++, Types.BIGINT);
|
||||
} else {
|
||||
ps.setLong(iii++, root.path("seasonId").asLong());
|
||||
}
|
||||
}
|
||||
ps.setLong(iii++, id);
|
||||
System.out.println(" request : " + ps.toString());
|
||||
ps.executeUpdate();
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
entry.disconnect();
|
||||
entry = null;
|
||||
return Response.notModified("SQL error").build();
|
||||
}
|
||||
entry.disconnect();
|
||||
entry = null;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return Response.notModified("input json error error").build();
|
||||
}
|
||||
return Response.ok(get(id)).build();
|
||||
}
|
||||
/*
|
||||
public static void update_time(String table, Long id, Timestamp dateCreate, Timestamp dateModify) {
|
||||
DBEntry entry = new DBEntry(WebLauncher.dbConfig);
|
||||
String query = "UPDATE " + table + " SET create_date = ?, modify_date = ? WHERE id = ?";
|
||||
try {
|
||||
PreparedStatement ps = entry.connection.prepareStatement(query);
|
||||
ps.setTimestamp(1, dateCreate);
|
||||
ps.setTimestamp(2, dateModify);
|
||||
ps.setLong(3, id);
|
||||
ps.execute();
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
entry.disconnect();
|
||||
}
|
||||
*/
|
||||
|
||||
private String multipartCorrection(String data) {
|
||||
if (data == null) {
|
||||
return null;
|
||||
@ -260,8 +60,6 @@ public class VideoResource {
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@POST
|
||||
@Path("/upload/")
|
||||
@RolesAllowed("ADMIN")
|
||||
@ -318,10 +116,6 @@ public class VideoResource {
|
||||
DataResource.removeTemporaryFile(tmpUID);
|
||||
ex.printStackTrace();
|
||||
return Response.notModified("can not create input media").build();
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
DataResource.removeTemporaryFile(tmpUID);
|
||||
return Response.notModified("Error in SQL insertion ...").build();
|
||||
}
|
||||
} else if (data.deleted == true) {
|
||||
System.out.println("Data already exist but deleted");
|
||||
@ -335,29 +129,22 @@ public class VideoResource {
|
||||
// Fist step: retive all the Id of each parents:...
|
||||
System.out.println("Find typeNode");
|
||||
// check if id of type exist:
|
||||
NodeSmall typeNode = TypeResource.getWithId(Long.parseLong(typeId));
|
||||
Type typeNode = TypeResource.getId(Long.parseLong(typeId));
|
||||
if (typeNode == null) {
|
||||
DataResource.removeTemporaryFile(tmpUID);
|
||||
return Response.notModified("TypeId does not exist ...").build();
|
||||
}
|
||||
System.out.println(" ==> " + typeNode);
|
||||
System.out.println("Find universeNode");
|
||||
// get id of universe:
|
||||
NodeSmall universeNode = UniverseResource.getOrCreate(universe);
|
||||
|
||||
System.out.println(" ==> " + universeNode);
|
||||
System.out.println("Find seriesNode");
|
||||
// get uid of group:
|
||||
NodeSmall seriesNode = SeriesResource.getOrCreate(series, typeNode.id);
|
||||
Series seriesNode = SeriesResource.getOrCreate(series, typeNode.id);
|
||||
|
||||
System.out.println(" ==> " + seriesNode);
|
||||
System.out.println("Find seasonNode");
|
||||
// get uid of season:
|
||||
Integer seasonId = null;
|
||||
NodeSmall seasonNode = null;
|
||||
Season seasonNode = null;
|
||||
try {
|
||||
seasonId = Integer.parseInt(season);
|
||||
seasonNode = SeasonResource.getOrCreate(Integer.parseInt(season), seriesNode.id);
|
||||
seasonNode = SeasonResource.getOrCreate(season, seriesNode.id);
|
||||
} catch (java.lang.NumberFormatException ex) {
|
||||
// nothing to do ....
|
||||
}
|
||||
@ -366,72 +153,38 @@ public class VideoResource {
|
||||
System.out.println("add media");
|
||||
|
||||
|
||||
DBEntry entry = new DBEntry(WebLauncher.dbConfig);
|
||||
long uniqueSQLID = -1;
|
||||
// real add in the BDD:
|
||||
try {
|
||||
// prepare the request:
|
||||
String query = "INSERT INTO media (create_date, modify_date, name, data_id, type_id, universe_id, series_id, season_id, episode)" +
|
||||
" VALUES (now(3), now(3), ?, ?, ?, ?, ?, ?, ?)";
|
||||
PreparedStatement ps = entry.connection.prepareStatement(query,
|
||||
Statement.RETURN_GENERATED_KEYS);
|
||||
int iii = 1;
|
||||
ps.setString(iii++, title);
|
||||
ps.setLong(iii++, data.id);
|
||||
ps.setLong(iii++, typeNode.id);
|
||||
if (universeNode == null) {
|
||||
ps.setNull(iii++, Types.BIGINT);
|
||||
} else {
|
||||
ps.setLong(iii++, universeNode.id);
|
||||
}
|
||||
if (seriesNode == null) {
|
||||
ps.setNull(iii++, Types.BIGINT);
|
||||
} else {
|
||||
ps.setLong(iii++, seriesNode.id);
|
||||
}
|
||||
if (seasonNode == null) {
|
||||
ps.setNull(iii++, Types.BIGINT);
|
||||
} else {
|
||||
ps.setLong(iii++, seasonNode.id);
|
||||
}
|
||||
if (episode == null || episode.contentEquals("")) {
|
||||
ps.setNull(iii++, Types.INTEGER);
|
||||
} else {
|
||||
ps.setInt(iii++, Integer.parseInt(episode));
|
||||
}
|
||||
// execute the request
|
||||
int affectedRows = ps.executeUpdate();
|
||||
if (affectedRows == 0) {
|
||||
throw new SQLException("Creating data failed, no rows affected.");
|
||||
}
|
||||
// retreive uid inserted
|
||||
try (ResultSet generatedKeys = ps.getGeneratedKeys()) {
|
||||
if (generatedKeys.next()) {
|
||||
uniqueSQLID = generatedKeys.getLong(1);
|
||||
} else {
|
||||
throw new SQLException("Creating user failed, no ID obtained (1).");
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
System.out.println("Can not get the UID key inserted ... ");
|
||||
ex.printStackTrace();
|
||||
throw new SQLException("Creating user failed, no ID obtained (2).");
|
||||
Media media = new Media();
|
||||
media.name = title;
|
||||
media.dataId = data.id;
|
||||
media.typeId = typeNode.id;
|
||||
media.seriesId = seriesNode.id;
|
||||
media.seasonId = seasonNode.id;
|
||||
media.episode = null;
|
||||
if (episode != null || ! episode.contentEquals("")) {
|
||||
media.episode = Integer.parseInt(episode);
|
||||
}
|
||||
Media out = SqlWrapper.insert(media);
|
||||
DataResource.removeTemporaryFile(tmpUID);
|
||||
System.out.println("uploaded .... compleate: " + uniqueSQLID);
|
||||
Media creation = get(uniqueSQLID);
|
||||
return Response.ok(creation).build();
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
// if we do not une the file .. remove it ... otherwise this is meamory leak...
|
||||
DataResource.removeTemporaryFile(tmpUID);
|
||||
System.out.println("uploaded .... compleate: " + uniqueSQLID);
|
||||
MediaSmall creation = get(uniqueSQLID);
|
||||
return Response.ok(creation).build();
|
||||
} catch (Exception ex) {
|
||||
System.out.println("Catch an unexpected error ... " + ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
return Response.status(417).
|
||||
entity("Back-end error : " + ex.getMessage()).
|
||||
entity("Back-end error: " + ex.getMessage()).
|
||||
type("text/plain").
|
||||
build();
|
||||
}
|
||||
return Response.status(417).
|
||||
entity("Back-end error").
|
||||
type("text/plain").
|
||||
build();
|
||||
}
|
||||
@POST
|
||||
@Path("{id}/add_cover")
|
||||
@ -442,132 +195,21 @@ public class VideoResource {
|
||||
@FormDataParam("file") InputStream fileInputStream,
|
||||
@FormDataParam("file") FormDataContentDisposition fileMetaData
|
||||
) {
|
||||
try {
|
||||
// correct input string stream :
|
||||
fileName = multipartCorrection(fileName);
|
||||
|
||||
//public NodeSmall uploadFile(final FormDataMultiPart form) {
|
||||
System.out.println("Upload media file: " + fileMetaData);
|
||||
System.out.println(" - id: " + id);
|
||||
System.out.println(" - fileName: " + fileName);
|
||||
System.out.println(" - fileInputStream: " + fileInputStream);
|
||||
System.out.println(" - fileMetaData: " + fileMetaData);
|
||||
System.out.flush();
|
||||
MediaSmall media = get(id);
|
||||
if (media == null) {
|
||||
return Response.notModified("Media Id does not exist or removed...").build();
|
||||
}
|
||||
|
||||
long tmpUID = DataResource.getTmpDataId();
|
||||
String sha512 = DataResource.saveTemporaryFile(fileInputStream, tmpUID);
|
||||
Data data = DataResource.getWithSha512(sha512);
|
||||
if (data == null) {
|
||||
System.out.println("Need to add the data in the BDD ... ");
|
||||
System.out.flush();
|
||||
try {
|
||||
data = DataResource.createNewData(tmpUID, fileName, sha512);
|
||||
} catch (IOException ex) {
|
||||
DataResource.removeTemporaryFile(tmpUID);
|
||||
ex.printStackTrace();
|
||||
return Response.notModified("can not create input media").build();
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
DataResource.removeTemporaryFile(tmpUID);
|
||||
return Response.notModified("Error in SQL insertion ...").build();
|
||||
}
|
||||
} else if (data.deleted == true) {
|
||||
System.out.println("Data already exist but deleted");
|
||||
System.out.flush();
|
||||
DataResource.undelete(data.id);
|
||||
data.deleted = false;
|
||||
} else {
|
||||
System.out.println("Data already exist ... all good");
|
||||
System.out.flush();
|
||||
}
|
||||
// Fist step: retrieve all the Id of each parents:...
|
||||
System.out.println("Find typeNode");
|
||||
|
||||
DBEntry entry = new DBEntry(WebLauncher.dbConfig);
|
||||
long uniqueSQLID = -1;
|
||||
// real add in the BDD:
|
||||
try {
|
||||
// prepare the request:
|
||||
String query = "INSERT INTO cover_link_media (create_date, modify_date, media_id, data_id)" +
|
||||
" VALUES (now(3), now(3), ?, ?)";
|
||||
PreparedStatement ps = entry.connection.prepareStatement(query,
|
||||
Statement.RETURN_GENERATED_KEYS);
|
||||
int iii = 1;
|
||||
ps.setLong(iii++, media.id);
|
||||
ps.setLong(iii++, data.id);
|
||||
// execute the request
|
||||
int affectedRows = ps.executeUpdate();
|
||||
if (affectedRows == 0) {
|
||||
throw new SQLException("Creating data failed, no rows affected.");
|
||||
}
|
||||
// retreive uid inserted
|
||||
try (ResultSet generatedKeys = ps.getGeneratedKeys()) {
|
||||
if (generatedKeys.next()) {
|
||||
uniqueSQLID = generatedKeys.getLong(1);
|
||||
} else {
|
||||
throw new SQLException("Creating user failed, no ID obtained (1).");
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
System.out.println("Can not get the UID key inserted ... ");
|
||||
ex.printStackTrace();
|
||||
throw new SQLException("Creating user failed, no ID obtained (2).");
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
// if we do not une the file .. remove it ... otherwise this is meamory leak...
|
||||
DataResource.removeTemporaryFile(tmpUID);
|
||||
System.out.println("uploaded .... compleate: " + uniqueSQLID);
|
||||
MediaSmall creation = get(id);
|
||||
return Response.ok(creation).build();
|
||||
} catch (Exception ex) {
|
||||
System.out.println("Cat ann unexpected error ... ");
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return Response.serverError().build();
|
||||
return DataTools.uploadCover(Media.class, id, fileName, fileInputStream, fileMetaData);
|
||||
}
|
||||
@GET
|
||||
@Path("{id}/rm_cover/{cover_id}")
|
||||
@Path("{id}/rm_cover/{coverId}")
|
||||
@RolesAllowed("ADMIN")
|
||||
public Response removeCover(@PathParam("id") Long mediaId, @PathParam("cover_id") Long coverId) {
|
||||
DBEntry entry = new DBEntry(WebLauncher.dbConfig);
|
||||
String query = "UPDATE `cover_link_media` SET `modify_date`=now(3), `deleted`=true WHERE `media_id` = ? AND `data_id` = ?";
|
||||
try {
|
||||
PreparedStatement ps = entry.connection.prepareStatement(query);
|
||||
int iii = 1;
|
||||
ps.setLong(iii++, mediaId);
|
||||
ps.setLong(iii++, coverId);
|
||||
ps.executeUpdate();
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
entry.disconnect();
|
||||
return Response.serverError().build();
|
||||
}
|
||||
entry.disconnect();
|
||||
return Response.ok(get(mediaId)).build();
|
||||
public Response removeCover(@PathParam("id") Long id, @PathParam("coverId") Long coverId) throws Exception {
|
||||
SqlWrapper.removeLink(Media.class, id, "cover", coverId);
|
||||
return Response.ok(SqlWrapper.get(Media.class, id)).build();
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("{id}")
|
||||
@RolesAllowed("ADMIN")
|
||||
public Response delete(@PathParam("id") Long id) {
|
||||
DBEntry entry = new DBEntry(WebLauncher.dbConfig);
|
||||
String query = "UPDATE `media` SET `modify_date`=now(3), `deleted`=true WHERE `id` = ? and `deleted` = false ";
|
||||
try {
|
||||
PreparedStatement ps = entry.connection.prepareStatement(query);
|
||||
int iii = 1;
|
||||
ps.setLong(iii++, id);
|
||||
ps.executeUpdate();
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
entry.disconnect();
|
||||
return Response.serverError().build();
|
||||
}
|
||||
entry.disconnect();
|
||||
public Response delete(@PathParam("id") Long id) throws Exception {
|
||||
SqlWrapper.setDelete(Media.class, id);
|
||||
return Response.ok().build();
|
||||
}
|
||||
}
|
||||
|
@ -1,60 +0,0 @@
|
||||
package org.kar.karideo.db;
|
||||
|
||||
public class DBConfig {
|
||||
private final String hostname;
|
||||
private final int port;
|
||||
private final String login;
|
||||
private final String password;
|
||||
private final String dbName;
|
||||
|
||||
public DBConfig(String hostname, Integer port, String login, String password, String dbName) {
|
||||
if (hostname == null) {
|
||||
this.hostname = "localhost";
|
||||
} else {
|
||||
this.hostname = hostname;
|
||||
}
|
||||
if (port == null) {
|
||||
this.port = 3306;
|
||||
} else {
|
||||
this.port = port;
|
||||
}
|
||||
this.login = login;
|
||||
this.password = password;
|
||||
this.dbName = dbName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DBConfig{" +
|
||||
"hostname='" + hostname + '\'' +
|
||||
", port=" + port +
|
||||
", login='" + login + '\'' +
|
||||
", password='" + password + '\'' +
|
||||
", dbName='" + dbName + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
public String getHostname() {
|
||||
return hostname;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public String getLogin() {
|
||||
return login;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public String getDbName() {
|
||||
return dbName;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return "jdbc:mysql://" + this.hostname + ":" + this.port + "/" + this.dbName + "?allowPublicKeyRetrieval=true&useSSL=false&serverTimezone=UTC";
|
||||
}
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
package org.kar.karideo.db;
|
||||
|
||||
import org.kar.karideo.model.User;
|
||||
|
||||
import java.sql.*;
|
||||
|
||||
public class DBEntry {
|
||||
public DBConfig config;
|
||||
public Connection connection;
|
||||
|
||||
public DBEntry(DBConfig config) {
|
||||
this.config = config;
|
||||
connect();
|
||||
}
|
||||
|
||||
public void connect() {
|
||||
try {
|
||||
connection = DriverManager.getConnection(config.getUrl(), config.getLogin(), config.getPassword());
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void disconnect() {
|
||||
try {
|
||||
//connection.commit();
|
||||
connection.close();
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void test() throws SQLException {
|
||||
String query = "SELECT * FROM user";
|
||||
Statement st = connection.createStatement();
|
||||
ResultSet rs = st.executeQuery(query);
|
||||
System.out.println("List of user:");
|
||||
if (rs.next()) {
|
||||
User user = new User(rs);
|
||||
System.out.println(" - " + user);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,199 +0,0 @@
|
||||
package org.kar.karideo.filter;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import javax.annotation.security.DenyAll;
|
||||
import org.kar.archidata.annotation.security.PermitAll;
|
||||
import javax.annotation.security.RolesAllowed;
|
||||
|
||||
|
||||
import javax.annotation.Priority;
|
||||
import javax.ws.rs.Priorities;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.container.ContainerRequestContext;
|
||||
import javax.ws.rs.container.ContainerRequestFilter;
|
||||
import javax.ws.rs.container.ResourceInfo;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
import javax.ws.rs.core.MultivaluedMap;
|
||||
import javax.ws.rs.core.PathSegment;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.ext.Provider;
|
||||
|
||||
import org.kar.karideo.UserDB;
|
||||
|
||||
import org.kar.karideo.annotation.PermitTokenInURI;
|
||||
import org.kar.karideo.model.User;
|
||||
import org.kar.karideo.model.UserSmall;
|
||||
import org.kar.karideo.util.JWTWrapper;
|
||||
|
||||
import com.nimbusds.jwt.JWTClaimsSet;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
// https://stackoverflow.com/questions/26777083/best-practice-for-rest-token-based-authentication-with-jax-rs-and-jersey
|
||||
// https://stackoverflow.com/questions/26777083/best-practice-for-rest-token-based-authentication-with-jax-rs-and-jersey/45814178#45814178
|
||||
// https://stackoverflow.com/questions/32817210/how-to-access-jersey-resource-secured-by-rolesallowed
|
||||
|
||||
//@PreMatching
|
||||
@Provider
|
||||
@Priority(Priorities.AUTHENTICATION)
|
||||
public class AuthenticationFilter implements ContainerRequestFilter {
|
||||
@Context
|
||||
private ResourceInfo resourceInfo;
|
||||
|
||||
private static final String AUTHENTICATION_SCHEME = "Yota";
|
||||
|
||||
@Override
|
||||
public void filter(ContainerRequestContext requestContext) throws IOException {
|
||||
/*
|
||||
System.out.println("-----------------------------------------------------");
|
||||
System.out.println("---- Check if have authorization ----");
|
||||
System.out.println("-----------------------------------------------------");
|
||||
System.out.println(" for:" + requestContext.getUriInfo().getPath());
|
||||
*/
|
||||
Method method = resourceInfo.getResourceMethod();
|
||||
// Access denied for all
|
||||
if(method.isAnnotationPresent(DenyAll.class)) {
|
||||
System.out.println(" ==> deny all " + requestContext.getUriInfo().getPath());
|
||||
requestContext.abortWith(Response.status(Response.Status.FORBIDDEN).entity("Access blocked !!!").build());
|
||||
return;
|
||||
}
|
||||
|
||||
//Access allowed for all
|
||||
if( method.isAnnotationPresent(PermitAll.class)) {
|
||||
System.out.println(" ==> permit all " + requestContext.getUriInfo().getPath());
|
||||
// no control ...
|
||||
return;
|
||||
}
|
||||
// this is a security guard, all the API must define their access level:
|
||||
if(!method.isAnnotationPresent(RolesAllowed.class)) {
|
||||
System.out.println(" ==> missin @RolesAllowed " + requestContext.getUriInfo().getPath());
|
||||
requestContext.abortWith(Response.status(Response.Status.FORBIDDEN).entity("Access ILLEGAL !!!").build());
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
// Get the Authorization header from the request
|
||||
String authorizationHeader = requestContext.getHeaderString(HttpHeaders.AUTHORIZATION);
|
||||
//System.out.println("authorizationHeader: " + authorizationHeader);
|
||||
if(authorizationHeader == null && method.isAnnotationPresent(PermitTokenInURI.class)) {
|
||||
MultivaluedMap<String, String> quaryparam = requestContext.getUriInfo().getQueryParameters();
|
||||
for (Entry<String, List<String>> item: quaryparam.entrySet()) {
|
||||
if (item.getKey().equals(HttpHeaders.AUTHORIZATION)) {
|
||||
if (!item.getValue().isEmpty()) {
|
||||
authorizationHeader = item.getValue().get(0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
//System.out.println("authorizationHeader: " + authorizationHeader);
|
||||
|
||||
|
||||
/*
|
||||
System.out.println(" -------------------------------");
|
||||
// this get the parameters inside the pre-parsed element in the request ex: @Path("thumbnail/{id}") generate a map with "id"
|
||||
MultivaluedMap<String, String> pathparam = requestContext.getUriInfo().getPathParameters();
|
||||
for (Entry<String, List<String>> item: pathparam.entrySet()) {
|
||||
System.out.println(" param: " + item.getKey() + " ==>" + item.getValue());
|
||||
}
|
||||
System.out.println(" -------------------------------");
|
||||
// need to add "@QueryParam("p") String token, " in the model
|
||||
//MultivaluedMap<String, String> quaryparam = requestContext.getUriInfo().getQueryParameters();
|
||||
for (Entry<String, List<String>> item: quaryparam.entrySet()) {
|
||||
System.out.println(" query: " + item.getKey() + " ==>" + item.getValue());
|
||||
}
|
||||
System.out.println(" -------------------------------");
|
||||
List<PathSegment> segments = requestContext.getUriInfo().getPathSegments();
|
||||
for (final PathSegment item: segments) {
|
||||
System.out.println(" query: " + item.getPath() + " ==>" + item.getMatrixParameters());
|
||||
}
|
||||
System.out.println(" -------------------------------");
|
||||
MultivaluedMap<String, String> headers = requestContext.getHeaders();
|
||||
for (Entry<String, List<String>> item: headers.entrySet()) {
|
||||
System.out.println(" headers: " + item.getKey() + " ==>" + item.getValue());
|
||||
}
|
||||
System.out.println(" -------------------------------");
|
||||
*/
|
||||
// Validate the Authorization header data Model "Yota userId:token"
|
||||
if (!isTokenBasedAuthentication(authorizationHeader)) {
|
||||
System.out.println("REJECTED unauthorized: " + requestContext.getUriInfo().getPath());
|
||||
abortWithUnauthorized(requestContext);
|
||||
return;
|
||||
}
|
||||
// check JWT token (basic:)
|
||||
|
||||
// Extract the token from the Authorization header (Remove "Yota ")
|
||||
String token = authorizationHeader.substring(AUTHENTICATION_SCHEME.length()).trim();
|
||||
System.out.println("token: " + token);
|
||||
|
||||
|
||||
User user = null;
|
||||
try {
|
||||
user = validateToken(token);
|
||||
} catch (Exception e) {
|
||||
abortWithUnauthorized(requestContext);
|
||||
}
|
||||
if (user == null) {
|
||||
abortWithUnauthorized(requestContext);
|
||||
}
|
||||
// create the security context model:
|
||||
String scheme = requestContext.getUriInfo().getRequestUri().getScheme();
|
||||
MySecurityContext userContext = new MySecurityContext(user, scheme);
|
||||
// retrieve the allowed right:
|
||||
RolesAllowed rolesAnnotation = method.getAnnotation(RolesAllowed.class);
|
||||
List<String> roles = Arrays.asList(rolesAnnotation.value());
|
||||
// check if the user have the right:
|
||||
boolean haveRight = false;
|
||||
for (String role : roles) {
|
||||
if (userContext.isUserInRole(role)) {
|
||||
haveRight = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//Is user valid?
|
||||
if( ! haveRight) {
|
||||
System.out.println("REJECTED not enought right : " + requestContext.getUriInfo().getPath() + " require: " + roles);
|
||||
requestContext.abortWith(Response.status(Response.Status.UNAUTHORIZED).entity("Not enought RIGHT !!!").build());
|
||||
return;
|
||||
}
|
||||
requestContext.setSecurityContext(userContext);
|
||||
System.out.println("Get local user : " + user);
|
||||
}
|
||||
|
||||
private boolean isTokenBasedAuthentication(String authorizationHeader) {
|
||||
// Check if the Authorization header is valid
|
||||
// It must not be null and must be prefixed with "Bearer" plus a whitespace
|
||||
// The authentication scheme comparison must be case-insensitive
|
||||
return authorizationHeader != null && authorizationHeader.toLowerCase().startsWith(AUTHENTICATION_SCHEME.toLowerCase() + " ");
|
||||
}
|
||||
|
||||
private void abortWithUnauthorized(ContainerRequestContext requestContext) {
|
||||
|
||||
// Abort the filter chain with a 401 status code response
|
||||
// The WWW-Authenticate header is sent along with the response
|
||||
requestContext.abortWith(
|
||||
Response.status(Response.Status.UNAUTHORIZED)
|
||||
.header(HttpHeaders.WWW_AUTHENTICATE,
|
||||
AUTHENTICATION_SCHEME + " base64(HEADER).base64(CONTENT).base64(KEY)")
|
||||
.build());
|
||||
}
|
||||
|
||||
private User validateToken(String authorization) throws Exception {
|
||||
System.out.println(" validate token : " + authorization);
|
||||
JWTClaimsSet ret = JWTWrapper.validateToken(authorization, "KarAuth");
|
||||
// check the token is valid !!! (signed and coherent issuer...
|
||||
if (ret == null) {
|
||||
System.out.println("The token is not valid: '" + authorization + "'");
|
||||
return null;
|
||||
}
|
||||
// check userID
|
||||
String userUID = ret.getSubject();
|
||||
long id = Long.parseLong(userUID);
|
||||
System.out.println("request user: '" + userUID + "'");
|
||||
return UserDB.getUserOrCreate(id, (String)ret.getClaim("login") );
|
||||
}
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package org.kar.karideo.filter;
|
||||
|
||||
import javax.ws.rs.container.ContainerRequestContext;
|
||||
import javax.ws.rs.container.ContainerResponseContext;
|
||||
import javax.ws.rs.container.ContainerResponseFilter;
|
||||
import javax.ws.rs.ext.Provider;
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
@Provider
|
||||
public class CORSFilter implements ContainerResponseFilter {
|
||||
|
||||
@Override
|
||||
public void filter(ContainerRequestContext request,
|
||||
ContainerResponseContext response) throws IOException {
|
||||
//System.err.println("filter cors ..." + request.toString());
|
||||
|
||||
response.getHeaders().add("Access-Control-Allow-Origin", "*");
|
||||
response.getHeaders().add("Access-Control-Allow-Headers", "*");
|
||||
// "Origin, content-type, Content-type, Accept, authorization, mime-type, filename");
|
||||
response.getHeaders().add("Access-Control-Allow-Credentials", "true");
|
||||
response.getHeaders().add("Access-Control-Allow-Methods",
|
||||
"GET, POST, PUT, DELETE, OPTIONS, HEAD");
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package org.kar.karideo.filter;
|
||||
|
||||
import org.kar.karideo.model.User;
|
||||
|
||||
import java.security.Principal;
|
||||
|
||||
public class GenericContext implements Principal {
|
||||
|
||||
public User user;
|
||||
|
||||
public GenericContext(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (user == null) {
|
||||
return "???";
|
||||
}
|
||||
return user.login;
|
||||
}
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
package org.kar.karideo.filter;
|
||||
|
||||
|
||||
import org.kar.karideo.model.User;
|
||||
|
||||
import javax.ws.rs.core.SecurityContext;
|
||||
import java.security.Principal;
|
||||
|
||||
// https://simplapi.wordpress.com/2015/09/19/jersey-jax-rs-securitycontext-in-action/
|
||||
class MySecurityContext implements SecurityContext {
|
||||
|
||||
private final GenericContext contextPrincipale;
|
||||
private final String sheme;
|
||||
|
||||
public MySecurityContext(User user, String sheme) {
|
||||
this.contextPrincipale = new GenericContext(user);
|
||||
this.sheme = sheme;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Principal getUserPrincipal() {
|
||||
return contextPrincipale;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUserInRole(String role) {
|
||||
if (role.contentEquals("ADMIN")) {
|
||||
return contextPrincipale.user.admin == true;
|
||||
}
|
||||
if (role.contentEquals("USER")) {
|
||||
// if not an admin, this is a user...
|
||||
return true; //contextPrincipale.user.admin == false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSecure() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthenticationScheme() {
|
||||
return "Yota";
|
||||
}
|
||||
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
package org.kar.karideo.filter;
|
||||
|
||||
import javax.ws.rs.container.ContainerRequestContext;
|
||||
import javax.ws.rs.container.ContainerRequestFilter;
|
||||
import javax.ws.rs.container.PreMatching;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.ext.Provider;
|
||||
import java.io.IOException;
|
||||
|
||||
@Provider
|
||||
@PreMatching
|
||||
public class OptionFilter implements ContainerRequestFilter {
|
||||
@Override
|
||||
public void filter(ContainerRequestContext requestContext) throws IOException {
|
||||
if (requestContext.getMethod().contentEquals("OPTIONS")) {
|
||||
requestContext.abortWith(Response.status(Response.Status.NO_CONTENT).build());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,12 +0,0 @@
|
||||
package org.kar.karideo.model;
|
||||
/*
|
||||
CREATE TABLE `cover_link_media` (
|
||||
`id` bigint NOT NULL COMMENT 'table ID' AUTO_INCREMENT PRIMARY KEY,
|
||||
`deleted` BOOLEAN NOT NULL DEFAULT false,
|
||||
`media_id` bigint,
|
||||
`data_id` bigint
|
||||
) AUTO_INCREMENT=10;
|
||||
*/
|
||||
|
||||
public class CoverLinkMedia {
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
package org.kar.karideo.model;
|
||||
/*
|
||||
CREATE TABLE `cover_link_node` (
|
||||
`id` bigint NOT NULL COMMENT 'table ID' AUTO_INCREMENT PRIMARY KEY,
|
||||
`deleted` BOOLEAN NOT NULL DEFAULT false,
|
||||
`node_id` bigint,
|
||||
`data_id` bigint
|
||||
) AUTO_INCREMENT=10;
|
||||
*/
|
||||
|
||||
public class CoverLinkNode {
|
||||
|
||||
}
|
@ -3,30 +3,29 @@ package org.kar.karideo.model;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class Data {
|
||||
public Long id;
|
||||
public boolean deleted;
|
||||
import org.kar.archidata.annotation.SQLComment;
|
||||
import org.kar.archidata.annotation.SQLIfNotExists;
|
||||
import org.kar.archidata.annotation.SQLLimitSize;
|
||||
import org.kar.archidata.annotation.SQLNotNull;
|
||||
import org.kar.archidata.annotation.SQLTableName;
|
||||
import org.kar.archidata.model.GenericTable;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
|
||||
@SQLTableName ("data")
|
||||
@SQLIfNotExists
|
||||
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
|
||||
public class Data extends GenericTable {
|
||||
|
||||
@SQLNotNull
|
||||
@SQLLimitSize(128)
|
||||
@SQLComment("Sha512 of the data")
|
||||
public String sha512;
|
||||
@SQLNotNull
|
||||
@SQLLimitSize(128)
|
||||
@SQLComment("Mime -type of the media")
|
||||
public String mimeType;
|
||||
@SQLNotNull
|
||||
@SQLComment("Size in Byte of the data")
|
||||
public Long size;
|
||||
|
||||
public Data() {
|
||||
|
||||
}
|
||||
|
||||
public Data(ResultSet rs) {
|
||||
int iii = 1;
|
||||
try {
|
||||
this.id = rs.getLong(iii++);
|
||||
this.deleted = rs.getBoolean(iii++);
|
||||
this.sha512 = rs.getString(iii++);
|
||||
this.mimeType = rs.getString(iii++);
|
||||
this.size = rs.getLong(iii++);
|
||||
if (rs.wasNull()) {
|
||||
this.size = null;
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,39 +0,0 @@
|
||||
package org.kar.karideo.model;
|
||||
/*
|
||||
CREATE TABLE `data` (
|
||||
`id` bigint NOT NULL COMMENT 'table ID' AUTO_INCREMENT PRIMARY KEY,
|
||||
`deleted` BOOLEAN NOT NULL DEFAULT false,
|
||||
`create_date` datetime NOT NULL DEFAULT now() COMMENT 'Time the element has been created',
|
||||
`modify_date` datetime NOT NULL DEFAULT now() COMMENT 'Time the element has been update',
|
||||
`sha512` varchar(129) COLLATE 'utf8_general_ci' NOT NULL,
|
||||
`mime_type` varchar(128) COLLATE 'utf8_general_ci' NOT NULL,
|
||||
`size` bigint,
|
||||
`original_name` TEXT
|
||||
) AUTO_INCREMENT=64;
|
||||
*/
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class DataSmall {
|
||||
public Long id;
|
||||
public String sha512;
|
||||
public String mimeType;
|
||||
public Long size;
|
||||
|
||||
public DataSmall() {
|
||||
|
||||
}
|
||||
|
||||
public DataSmall(ResultSet rs) {
|
||||
int iii = 1;
|
||||
try {
|
||||
this.id = rs.getLong(iii++);
|
||||
this.sha512 = rs.getString(iii++);
|
||||
this.mimeType = rs.getString(iii++);
|
||||
this.size = rs.getLong(iii++);
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
package org.kar.karideo.model;
|
||||
|
||||
|
||||
public class Group {
|
||||
}
|
@ -1,24 +1,49 @@
|
||||
package org.kar.karideo.model;
|
||||
/*
|
||||
CREATE TABLE `media` (
|
||||
`id` bigint NOT NULL COMMENT 'table ID' AUTO_INCREMENT PRIMARY KEY,
|
||||
`deleted` BOOLEAN NOT NULL DEFAULT false,
|
||||
`create_date` datetime NOT NULL DEFAULT now() COMMENT 'Time the element has been created',
|
||||
`modify_date` datetime NOT NULL DEFAULT now() COMMENT 'Time the element has been update',
|
||||
`name` TEXT COLLATE 'utf8_general_ci' NOT NULL,
|
||||
`description` TEXT COLLATE 'utf8_general_ci',
|
||||
`parent_id` bigint,
|
||||
`data_id` bigint,
|
||||
`type_id` bigint,
|
||||
`universe_id` bigint,
|
||||
`series_id` bigint,
|
||||
`season_id` bigint,
|
||||
`episode` int,
|
||||
`date` int,
|
||||
`age_limit` enum("-", "5", "9", "12", "14", "16", "18") NOT NULL DEFAULT '-'
|
||||
) AUTO_INCREMENT=85;
|
||||
*/
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.kar.archidata.annotation.SQLComment;
|
||||
import org.kar.archidata.annotation.SQLForeignKey;
|
||||
import org.kar.archidata.annotation.SQLIfNotExists;
|
||||
import org.kar.archidata.annotation.SQLNotNull;
|
||||
import org.kar.archidata.annotation.SQLTableLinkGeneric;
|
||||
import org.kar.archidata.annotation.SQLTableName;
|
||||
import org.kar.archidata.model.GenericTable;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
|
||||
|
||||
public class Media {
|
||||
@SQLTableName ("media")
|
||||
@SQLIfNotExists
|
||||
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
|
||||
public class Media extends GenericTable {
|
||||
@SQLNotNull
|
||||
@SQLComment("Name of the media (this represent the title)")
|
||||
public String name;
|
||||
@SQLComment("Description of the media")
|
||||
public String description;
|
||||
@SQLNotNull
|
||||
@SQLComment("Foreign Key Id of the data")
|
||||
@SQLForeignKey("data")
|
||||
public Long dataId;
|
||||
@SQLComment("Type of the media")
|
||||
@SQLForeignKey("type")
|
||||
public Long typeId;
|
||||
@SQLComment("Series reference of the media")
|
||||
@SQLForeignKey("series")
|
||||
public Long seriesId;
|
||||
@SQLComment("Saison reference of the media")
|
||||
@SQLForeignKey("season")
|
||||
public Long seasonId;
|
||||
@SQLComment("Episide Id")
|
||||
public Integer episode;
|
||||
@SQLComment("")
|
||||
public Integer date;
|
||||
@SQLComment("Creation years of the media")
|
||||
public Integer time;
|
||||
@SQLComment("Limitation Age of the media")
|
||||
public Integer ageLimit;
|
||||
@SQLComment("List of Id of the sopecific covers")
|
||||
@SQLTableLinkGeneric
|
||||
public List<Long> covers = null;
|
||||
}
|
||||
|
@ -1,104 +0,0 @@
|
||||
package org.kar.karideo.model;
|
||||
/*
|
||||
CREATE TABLE `node` (
|
||||
`id` bigint NOT NULL COMMENT 'table ID' AUTO_INCREMENT PRIMARY KEY,
|
||||
`deleted` BOOLEAN NOT NULL DEFAULT false,
|
||||
`create_date` datetime NOT NULL DEFAULT now() COMMENT 'Time the element has been created',
|
||||
`modify_date` datetime NOT NULL DEFAULT now() COMMENT 'Time the element has been update',
|
||||
`type` enum("TYPE", "UNIVERSE", "SERIES", "SEASON") NOT NULL DEFAULT 'TYPE',
|
||||
`name` TEXT COLLATE 'utf8_general_ci' NOT NULL,
|
||||
`description` TEXT COLLATE 'utf8_general_ci',
|
||||
`parent_id` bigint
|
||||
) AUTO_INCREMENT=10;
|
||||
*/
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
|
||||
|
||||
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
|
||||
public class MediaSmall {
|
||||
public class MediaStreamProperty {
|
||||
public Long id;
|
||||
public Long timeSecond;
|
||||
public Long width;
|
||||
public Long height;
|
||||
public Map<String, Long> videos = new HashMap<>();
|
||||
public Map<String, Long> audios = new HashMap<>();
|
||||
public Map<String, Long> subtitles = new HashMap<>();
|
||||
}
|
||||
|
||||
public Long id;
|
||||
public String name;
|
||||
public String description;
|
||||
public Long dataId;
|
||||
public Long typeId;
|
||||
public Long universeId;
|
||||
public Long seriesId;
|
||||
public Long seasonId;
|
||||
public Integer episode;
|
||||
public Integer date;
|
||||
public Integer time;
|
||||
public String ageLimit;
|
||||
public List<Long> covers = null;
|
||||
public MediaStreamProperty media;
|
||||
|
||||
public MediaSmall(ResultSet rs) {
|
||||
int iii = 1;
|
||||
try {
|
||||
this.id = rs.getLong(iii++);
|
||||
this.name = rs.getString(iii++);
|
||||
this.description = rs.getString(iii++);
|
||||
this.dataId = rs.getLong(iii++);
|
||||
if (rs.wasNull()) {
|
||||
this.dataId = null;
|
||||
}
|
||||
this.typeId = rs.getLong(iii++);
|
||||
if (rs.wasNull()) {
|
||||
this.typeId = null;
|
||||
}
|
||||
this.universeId = rs.getLong(iii++);
|
||||
if (rs.wasNull()) {
|
||||
this.universeId = null;
|
||||
}
|
||||
this.seriesId = rs.getLong(iii++);
|
||||
if (rs.wasNull()) {
|
||||
this.seriesId = null;
|
||||
}
|
||||
this.seasonId = rs.getLong(iii++);
|
||||
if (rs.wasNull()) {
|
||||
this.seasonId = null;
|
||||
}
|
||||
this.episode = rs.getInt(iii++);
|
||||
if (rs.wasNull()) {
|
||||
this.episode = null;
|
||||
}
|
||||
this.date = rs.getInt(iii++);
|
||||
if (rs.wasNull()) {
|
||||
this.date = null;
|
||||
}
|
||||
this.time = rs.getInt(iii++);
|
||||
if (rs.wasNull()) {
|
||||
this.time = null;
|
||||
}
|
||||
this.ageLimit = rs.getString(iii++);
|
||||
String coversString = rs.getString(iii++);
|
||||
if (!rs.wasNull()) {
|
||||
covers = new ArrayList<>();
|
||||
String[] elements = coversString.split("-");
|
||||
for (String elem : elements) {
|
||||
Long tmp = Long.parseLong(elem);
|
||||
covers.add(tmp);
|
||||
}
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
package org.kar.karideo.model;
|
||||
/*
|
||||
CREATE TABLE `node` (
|
||||
`id` bigint NOT NULL COMMENT 'table ID' AUTO_INCREMENT PRIMARY KEY,
|
||||
`deleted` BOOLEAN NOT NULL DEFAULT false,
|
||||
`create_date` datetime NOT NULL DEFAULT now() COMMENT 'Time the element has been created',
|
||||
`modify_date` datetime NOT NULL DEFAULT now() COMMENT 'Time the element has been update',
|
||||
`type` enum("TYPE", "UNIVERS", "SERIE", "SAISON", "MEDIA") NOT NULL DEFAULT 'TYPE',
|
||||
`name` TEXT COLLATE 'utf8_general_ci' NOT NULL,
|
||||
`description` TEXT COLLATE 'utf8_general_ci',
|
||||
`parent_id` bigint
|
||||
) AUTO_INCREMENT=10;
|
||||
*/
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
|
||||
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
|
||||
public class NodeSmall {
|
||||
public Long id;
|
||||
public String name;
|
||||
public String description;
|
||||
public Long parentId;
|
||||
public List<Long> covers = null;
|
||||
|
||||
public NodeSmall(ResultSet rs) {
|
||||
int iii = 1;
|
||||
try {
|
||||
this.id = rs.getLong(iii++);
|
||||
this.name = rs.getString(iii++);
|
||||
this.description = rs.getString(iii++);
|
||||
this.parentId = rs.getLong(iii++);
|
||||
if (rs.wasNull()) {
|
||||
this.parentId = null;
|
||||
}
|
||||
String coversString = rs.getString(iii++);
|
||||
if (!rs.wasNull()) {
|
||||
this.covers = new ArrayList<>();
|
||||
String[] elements = coversString.split("-");
|
||||
for (String elem : elements) {
|
||||
Long tmp = Long.parseLong(elem);
|
||||
this.covers.add(tmp);
|
||||
}
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "NodeSmall{" +
|
||||
"id=" + id +
|
||||
", name='" + name + '\'' +
|
||||
", description='" + description + '\'' +
|
||||
", parentId=" + parentId +
|
||||
", covers=" + covers +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
package org.kar.karideo.model;
|
||||
|
||||
public class Saison {
|
||||
}
|
32
back/src/org/kar/karideo/model/Season.java
Normal file
32
back/src/org/kar/karideo/model/Season.java
Normal file
@ -0,0 +1,32 @@
|
||||
package org.kar.karideo.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.kar.archidata.annotation.SQLComment;
|
||||
import org.kar.archidata.annotation.SQLForeignKey;
|
||||
import org.kar.archidata.annotation.SQLIfNotExists;
|
||||
import org.kar.archidata.annotation.SQLNotNull;
|
||||
import org.kar.archidata.annotation.SQLTableLinkGeneric;
|
||||
import org.kar.archidata.annotation.SQLTableName;
|
||||
import org.kar.archidata.model.GenericTable;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
|
||||
|
||||
@SQLTableName ("season")
|
||||
@SQLIfNotExists
|
||||
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
|
||||
public class Season extends GenericTable {
|
||||
@SQLNotNull
|
||||
@SQLComment("Name of the media (this represent the title)")
|
||||
public String name;
|
||||
@SQLComment("Description of the media")
|
||||
public String description;
|
||||
@SQLNotNull
|
||||
@SQLComment("series parent ID")
|
||||
@SQLForeignKey("series")
|
||||
public Long parentId;
|
||||
@SQLComment("List of Id of the sopecific covers")
|
||||
@SQLTableLinkGeneric
|
||||
public List<Long> covers = null;
|
||||
}
|
32
back/src/org/kar/karideo/model/Series.java
Normal file
32
back/src/org/kar/karideo/model/Series.java
Normal file
@ -0,0 +1,32 @@
|
||||
package org.kar.karideo.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.kar.archidata.annotation.SQLComment;
|
||||
import org.kar.archidata.annotation.SQLForeignKey;
|
||||
import org.kar.archidata.annotation.SQLIfNotExists;
|
||||
import org.kar.archidata.annotation.SQLNotNull;
|
||||
import org.kar.archidata.annotation.SQLTableLinkGeneric;
|
||||
import org.kar.archidata.annotation.SQLTableName;
|
||||
import org.kar.archidata.model.GenericTable;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
|
||||
|
||||
@SQLTableName ("series")
|
||||
@SQLIfNotExists
|
||||
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
|
||||
public class Series extends GenericTable {
|
||||
@SQLNotNull
|
||||
@SQLComment("Name of the media (this represent the title)")
|
||||
public String name;
|
||||
@SQLComment("Description of the media")
|
||||
public String description;
|
||||
@SQLNotNull
|
||||
@SQLComment("series parent ID")
|
||||
@SQLForeignKey("type")
|
||||
public Long parentId;
|
||||
@SQLComment("List of Id of the sopecific covers")
|
||||
@SQLTableLinkGeneric
|
||||
public List<Long> covers = null;
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
package org.kar.karideo.model;
|
||||
|
||||
public enum State {
|
||||
// User has remove his account
|
||||
REMOVED,
|
||||
// User has been blocked his account
|
||||
BLOCKED,
|
||||
// generic user
|
||||
USER
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
package org.kar.karideo.model;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/*
|
||||
CREATE TABLE `token` (
|
||||
`id` bigint NOT NULL COMMENT 'Unique ID of the TOKEN' AUTO_INCREMENT PRIMARY KEY,
|
||||
`userId` bigint NOT NULL COMMENT 'Unique ID of the user',
|
||||
`token` varchar(128) COLLATE 'latin1_bin' NOT NULL COMMENT 'Token (can be not unique)',
|
||||
`createTime` datetime NOT NULL COMMENT 'Time the token has been created',
|
||||
`endValidityTime` datetime NOT NULL COMMENT 'Time of the token end validity'
|
||||
) AUTO_INCREMENT=10;
|
||||
|
||||
*/
|
||||
public class Token {
|
||||
public Long id;
|
||||
public Long userId;
|
||||
public String token;
|
||||
public String createTime;
|
||||
public String endValidityTime;
|
||||
|
||||
public Token() {
|
||||
}
|
||||
|
||||
public Token(long id, long userId, String token, String createTime, String endValidityTime) {
|
||||
this.id = id;
|
||||
this.userId = userId;
|
||||
this.token = token;
|
||||
this.createTime = createTime;
|
||||
this.endValidityTime = endValidityTime;
|
||||
}
|
||||
|
||||
public Token(ResultSet rs) {
|
||||
int iii = 1;
|
||||
try {
|
||||
this.id = rs.getLong(iii++);
|
||||
this.userId = rs.getLong(iii++);
|
||||
this.token = rs.getString(iii++);
|
||||
this.createTime = rs.getString(iii++);
|
||||
this.endValidityTime = rs.getString(iii++);
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Token{" +
|
||||
"id=" + id +
|
||||
", userId=" + userId +
|
||||
", token='" + token + '\'' +
|
||||
", createTime=" + createTime +
|
||||
", endValidityTime=" + endValidityTime +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -1,6 +1,28 @@
|
||||
package org.kar.karideo.model;
|
||||
|
||||
public class Type {
|
||||
import java.util.List;
|
||||
|
||||
import org.kar.archidata.annotation.SQLComment;
|
||||
import org.kar.archidata.annotation.SQLForeignKey;
|
||||
import org.kar.archidata.annotation.SQLIfNotExists;
|
||||
import org.kar.archidata.annotation.SQLNotNull;
|
||||
import org.kar.archidata.annotation.SQLTableLinkGeneric;
|
||||
import org.kar.archidata.annotation.SQLTableName;
|
||||
import org.kar.archidata.model.GenericTable;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
|
||||
|
||||
@SQLTableName ("type")
|
||||
@SQLIfNotExists
|
||||
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
|
||||
public class Type extends GenericTable {
|
||||
@SQLNotNull
|
||||
@SQLComment("Name of the media (this represent the title)")
|
||||
public String name;
|
||||
@SQLComment("Description of the media")
|
||||
public String description;
|
||||
@SQLComment("List of Id of the sopecific covers")
|
||||
@SQLTableLinkGeneric
|
||||
public List<Long> covers = null;
|
||||
}
|
||||
|
@ -1,4 +0,0 @@
|
||||
package org.kar.karideo.model;
|
||||
|
||||
public class Univers {
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
package org.kar.karideo.model;
|
||||
|
||||
/*
|
||||
CREATE TABLE `user` (
|
||||
`id` bigint NOT NULL COMMENT 'table ID' AUTO_INCREMENT PRIMARY KEY,
|
||||
`login` varchar(128) COLLATE 'utf8_general_ci' NOT NULL COMMENT 'login of the user',
|
||||
`email` varchar(512) COLLATE 'utf8_general_ci' NOT NULL COMMENT 'email of the user',
|
||||
`lastConnection` datetime NOT NULL COMMENT 'last connection time',
|
||||
`admin` enum("TRUE", "FALSE") NOT NULL DEFAULT 'FALSE',
|
||||
`blocked` enum("TRUE", "FALSE") NOT NULL DEFAULT 'FALSE',
|
||||
`removed` enum("TRUE", "FALSE") NOT NULL DEFAULT 'FALSE',
|
||||
`avatar` bigint DEFAULT NULL,
|
||||
) AUTO_INCREMENT=10;
|
||||
|
||||
*/
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
public class User {
|
||||
public Long id;
|
||||
public String login;
|
||||
public Timestamp lastConnection;
|
||||
public boolean admin;
|
||||
public boolean blocked;
|
||||
public boolean removed;
|
||||
|
||||
public User() {
|
||||
}
|
||||
|
||||
public User(Long id, String login, Timestamp lastConnection, String email, boolean admin, boolean blocked, boolean removed, Long avatar) {
|
||||
this.id = id;
|
||||
this.login = login;
|
||||
this.lastConnection = lastConnection;
|
||||
this.admin = admin;
|
||||
this.blocked = blocked;
|
||||
this.removed = removed;
|
||||
}
|
||||
|
||||
public User(ResultSet rs) {
|
||||
int iii = 1;
|
||||
try {
|
||||
this.id = rs.getLong(iii++);
|
||||
this.lastConnection = rs.getTimestamp(iii++);
|
||||
this.login = rs.getString(iii++);
|
||||
this.admin = "TRUE".equals(rs.getString(iii++));
|
||||
this.blocked = "TRUE".equals(rs.getString(iii++));
|
||||
this.removed = "TRUE".equals(rs.getString(iii++));
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "User{" +
|
||||
"id=" + id +
|
||||
", login='" + login + '\'' +
|
||||
", lastConnection='" + lastConnection + '\'' +
|
||||
", admin=" + admin +
|
||||
", blocked=" + blocked +
|
||||
", removed=" + removed +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
package org.kar.karideo.model;
|
||||
|
||||
/*
|
||||
CREATE TABLE `user` (
|
||||
`id` bigint NOT NULL COMMENT 'table ID' AUTO_INCREMENT PRIMARY KEY,
|
||||
`login` varchar(128) COLLATE 'utf8_general_ci' NOT NULL COMMENT 'login of the user',
|
||||
`email` varchar(512) COLLATE 'utf8_general_ci' NOT NULL COMMENT 'email of the user',
|
||||
`lastConnection` datetime NOT NULL COMMENT 'last connection time',
|
||||
`admin` enum("TRUE", "FALSE") NOT NULL DEFAULT 'FALSE',
|
||||
`blocked` enum("TRUE", "FALSE") NOT NULL DEFAULT 'FALSE',
|
||||
`removed` enum("TRUE", "FALSE") NOT NULL DEFAULT 'FALSE'
|
||||
) AUTO_INCREMENT=10;
|
||||
|
||||
*/
|
||||
|
||||
|
||||
public class UserExtern {
|
||||
public Long id;
|
||||
public String login;
|
||||
public boolean admin;
|
||||
|
||||
public UserExtern(User other) {
|
||||
this.id = other.id;
|
||||
this.login = other.login;
|
||||
this.admin = other.admin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "User{" +
|
||||
"id=" + id +
|
||||
", login='" + login + '\'' +
|
||||
", admin=" + admin +
|
||||
'}';
|
||||
}
|
||||
}
|
14
back/src/org/kar/karideo/model/UserKarideo.java
Normal file
14
back/src/org/kar/karideo/model/UserKarideo.java
Normal file
@ -0,0 +1,14 @@
|
||||
package org.kar.karideo.model;
|
||||
|
||||
import org.kar.archidata.annotation.SQLIfNotExists;
|
||||
import org.kar.archidata.annotation.SQLTableName;
|
||||
import org.kar.archidata.model.User;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
|
||||
@SQLTableName ("user")
|
||||
@SQLIfNotExists
|
||||
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
|
||||
public class UserKarideo extends User {
|
||||
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
package org.kar.karideo.model;
|
||||
|
||||
/*
|
||||
CREATE TABLE `user` (
|
||||
`id` bigint NOT NULL COMMENT 'table ID' AUTO_INCREMENT PRIMARY KEY,
|
||||
`login` varchar(128) COLLATE 'utf8_general_ci' NOT NULL COMMENT 'login of the user',
|
||||
`email` varchar(512) COLLATE 'utf8_general_ci' NOT NULL COMMENT 'email of the user',
|
||||
`lastConnection` datetime NOT NULL COMMENT 'last connection time',
|
||||
`admin` enum("TRUE", "FALSE") NOT NULL DEFAULT 'FALSE',
|
||||
`blocked` enum("TRUE", "FALSE") NOT NULL DEFAULT 'FALSE',
|
||||
`removed` enum("TRUE", "FALSE") NOT NULL DEFAULT 'FALSE'
|
||||
) AUTO_INCREMENT=10;
|
||||
|
||||
*/
|
||||
|
||||
|
||||
public class UserPerso {
|
||||
public Long id;
|
||||
public String login;
|
||||
public boolean admin;
|
||||
public boolean blocked;
|
||||
public boolean removed;
|
||||
|
||||
public UserPerso(User other) {
|
||||
this.id = other.id;
|
||||
this.login = other.login;
|
||||
this.admin = other.admin;
|
||||
this.blocked = other.blocked;
|
||||
this.removed = other.removed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "User{" +
|
||||
"id=" + id +
|
||||
", login='" + login + '\'' +
|
||||
", admin=" + admin +
|
||||
", blocked=" + blocked +
|
||||
", removed=" + removed +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
package org.kar.karideo.model;
|
||||
|
||||
/*
|
||||
CREATE TABLE `user` (
|
||||
`id` bigint NOT NULL COMMENT 'table ID' AUTO_INCREMENT PRIMARY KEY,
|
||||
`login` varchar(128) COLLATE 'utf8_general_ci' NOT NULL COMMENT 'login of the user',
|
||||
`password` varchar(128) COLLATE 'latin1_bin' NOT NULL COMMENT 'password of the user hashed (sha512)',
|
||||
`email` varchar(512) COLLATE 'utf8_general_ci' NOT NULL COMMENT 'email of the user',
|
||||
`emailValidate` bigint COMMENT 'date of the email validation',
|
||||
`newEmail` varchar(512) COLLATE 'utf8_general_ci' COMMENT 'email of the user if he want to change',
|
||||
`authorisationLevel` enum("REMOVED", "USER", "ADMIN") NOT NULL COMMENT 'user level of authorization'
|
||||
) AUTO_INCREMENT=10;
|
||||
|
||||
*/
|
||||
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class UserSmall {
|
||||
public long id;
|
||||
public String login;
|
||||
public String email;
|
||||
public State authorisationLevel;
|
||||
|
||||
public UserSmall() {
|
||||
}
|
||||
|
||||
public UserSmall(long id, String login, String email, State authorisationLevel) {
|
||||
this.id = id;
|
||||
this.login = login;
|
||||
this.email = email;
|
||||
this.authorisationLevel = authorisationLevel;
|
||||
}
|
||||
|
||||
public UserSmall(ResultSet rs) {
|
||||
int iii = 1;
|
||||
try {
|
||||
this.id = rs.getLong(iii++);
|
||||
this.login = rs.getString(iii++);
|
||||
this.email = rs.getString(iii++);
|
||||
this.authorisationLevel = State.valueOf(rs.getString(iii++));
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
/*
|
||||
public void serialize(ResultSet rs) {
|
||||
int iii = 1;
|
||||
try {
|
||||
this.id = rs.getLong(iii++);
|
||||
this.login = rs.getString(iii++);
|
||||
this.password = rs.getString(iii++);
|
||||
this.email = rs.getString(iii++);
|
||||
this.emailValidate = rs.getLong(iii++);
|
||||
this.newEmail = rs.getString(iii++);
|
||||
this.authorisationLevel = State.valueOf(rs.getString(iii++));
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "UserSmall{" +
|
||||
"id='" + id + '\'' +
|
||||
", login='" + login + '\'' +
|
||||
", email='" + email + '\'' +
|
||||
", authorisationLevel=" + authorisationLevel +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -3,86 +3,10 @@ package org.kar.karideo.util;
|
||||
public class ConfigVariable {
|
||||
public static final String BASE_NAME = "ORG_KARIDEO_";
|
||||
|
||||
public static String getTmpDataFolder() {
|
||||
String out = System.getenv(BASE_NAME + "DATA_TMP_FOLDER");
|
||||
if (out == null) {
|
||||
return "/application/data/tmp";
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
public static String getMediaDataFolder() {
|
||||
String out = System.getenv(BASE_NAME + "DATA_FOLDER");
|
||||
if (out == null) {
|
||||
return "/application/data/media";
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
public static String getFrontFolder() {
|
||||
String out = System.getenv(BASE_NAME + "FRONT_FOLDER");
|
||||
if (out == null) {
|
||||
return "/application/karideo";
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
public static String getDBHost() {
|
||||
String out = System.getenv(BASE_NAME + "DB_HOST");
|
||||
if (out == null) {
|
||||
return "localhost";
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
public static String getDBPort() {
|
||||
String out = System.getenv(BASE_NAME + "DB_PORT");
|
||||
if (out == null) {
|
||||
return "3306";
|
||||
//return "17036";
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
public static String getDBLogin() {
|
||||
String out = System.getenv(BASE_NAME + "DB_USER");
|
||||
if (out == null) {
|
||||
return "karideo";
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
public static String getDBPassword() {
|
||||
String out = System.getenv(BASE_NAME + "DB_PASSWORD");
|
||||
if (out == null) {
|
||||
return "karideo_password";
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
public static String getDBName() {
|
||||
String out = System.getenv(BASE_NAME + "DB_DATABASE");
|
||||
if (out == null) {
|
||||
return "karideo";
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
public static String getlocalAddress() {
|
||||
String out = System.getenv(BASE_NAME + "ADDRESS");
|
||||
if (out == null) {
|
||||
return "http://0.0.0.0:80/karideo/api/";
|
||||
//return "http://0.0.0.0:18080/karideo/api/";
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
public static String getSSOAddress() {
|
||||
String out = System.getenv("SSO_ADDRESS");
|
||||
if (out == null) {
|
||||
return "http://sso_host/karauth/api/";
|
||||
//return "http://192.168.1.156/karauth/api/";
|
||||
return "/application/front";
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
@ -1,5 +0,0 @@
|
||||
package org.kar.karideo.util;
|
||||
|
||||
public class CoverTools {
|
||||
|
||||
}
|
@ -1,175 +0,0 @@
|
||||
package org.kar.karideo.util;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.text.ParseException;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.nimbusds.jose.JOSEException;
|
||||
import com.nimbusds.jose.JOSEObjectType;
|
||||
import com.nimbusds.jose.JWSAlgorithm;
|
||||
import com.nimbusds.jose.JWSHeader;
|
||||
import com.nimbusds.jose.JWSSigner;
|
||||
import com.nimbusds.jose.JWSVerifier;
|
||||
import com.nimbusds.jose.crypto.RSASSASigner;
|
||||
import com.nimbusds.jose.crypto.RSASSAVerifier;
|
||||
import com.nimbusds.jose.jwk.RSAKey;
|
||||
import com.nimbusds.jose.jwk.gen.RSAKeyGenerator;
|
||||
import com.nimbusds.jwt.JWTClaimsSet;
|
||||
import com.nimbusds.jwt.SignedJWT;
|
||||
|
||||
public class JWTWrapper {
|
||||
private static RSAKey rsaJWK = null;;
|
||||
private static RSAKey rsaPublicJWK = null;
|
||||
|
||||
public static class PublicKey {
|
||||
public String key;
|
||||
|
||||
public PublicKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
public PublicKey() {
|
||||
}
|
||||
}
|
||||
public static void initLocalTokenRemote(String ssoUri, String application) throws IOException, ParseException {
|
||||
// check Token:
|
||||
URL obj = new URL(ssoUri + "public_key");
|
||||
System.out.println("Request token from:" + obj);
|
||||
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
|
||||
con.setRequestMethod("GET");
|
||||
con.setRequestProperty("User-Agent", application);
|
||||
con.setRequestProperty("Cache-Control", "no-cache");
|
||||
con.setRequestProperty("Content-Type", "application/json");
|
||||
con.setRequestProperty("Accept", "application/json");
|
||||
int responseCode = con.getResponseCode();
|
||||
|
||||
System.out.println("GET Response Code :: " + responseCode);
|
||||
if (responseCode == HttpURLConnection.HTTP_OK) { // success
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
|
||||
|
||||
String inputLine;
|
||||
StringBuffer response = new StringBuffer();
|
||||
while ((inputLine = in.readLine()) != null) {
|
||||
response.append(inputLine);
|
||||
}
|
||||
in.close();
|
||||
// print result
|
||||
//System.out.println(response.toString());
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
PublicKey values = mapper.readValue(response.toString(), PublicKey.class);
|
||||
rsaPublicJWK = RSAKey.parse(values.key);
|
||||
return;
|
||||
}
|
||||
System.out.println("GET JWT validator token not worked");
|
||||
}
|
||||
|
||||
public static void initLocalToken() throws Exception{
|
||||
// RSA signatures require a public and private RSA key pair, the public key
|
||||
// must be made known to the JWS recipient in order to verify the signatures
|
||||
try {
|
||||
String generatedStringForKey = UUID.randomUUID().toString();
|
||||
rsaJWK = new RSAKeyGenerator(2048).keyID(generatedStringForKey).generate();
|
||||
rsaPublicJWK = rsaJWK.toPublicJWK();
|
||||
//System.out.println("RSA key (all): " + rsaJWK.toJSONString());
|
||||
//System.out.println("RSA key (pub): " + rsaPublicJWK.toJSONString());
|
||||
} catch (JOSEException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
System.out.println("Can not generate teh public abnd private keys ...");
|
||||
rsaJWK = null;
|
||||
rsaPublicJWK = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void initValidateToken(String publicKey) {
|
||||
try {
|
||||
rsaPublicJWK = RSAKey.parse(publicKey);
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
System.out.println("Can not retrieve public Key !!!!!!!! RSAKey='" + publicKey + "'");
|
||||
}
|
||||
|
||||
}
|
||||
public static String getPublicKey() {
|
||||
if (rsaPublicJWK == null) {
|
||||
return null;
|
||||
}
|
||||
return rsaPublicJWK.toJSONString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a token with the provided elements
|
||||
* @param userID UniqueId of the USER (global unique ID)
|
||||
* @param userLogin Login of the user (never change)
|
||||
* @param isuer The one who provide the Token
|
||||
* @param timeOutInMunites Expiration of the token.
|
||||
* @return the encoded token
|
||||
*/
|
||||
public static String generateJWToken(long userID, String userLogin, String isuer, int timeOutInMunites) {
|
||||
if (rsaJWK == null) {
|
||||
System.out.println("JWT private key is not present !!!");
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
// Create RSA-signer with the private key
|
||||
JWSSigner signer = new RSASSASigner(rsaJWK);
|
||||
// Prepare JWT with claims set
|
||||
JWTClaimsSet claimsSet = new JWTClaimsSet.Builder()
|
||||
.subject(Long.toString(userID))
|
||||
.claim("login", userLogin)
|
||||
.issuer(isuer)
|
||||
.issueTime(new Date())
|
||||
.expirationTime(new Date(new Date().getTime() + 60 * timeOutInMunites * 1000 /* millisecond */))
|
||||
.build();
|
||||
|
||||
SignedJWT signedJWT = new SignedJWT(new JWSHeader.Builder(JWSAlgorithm.RS256).type(JOSEObjectType.JWT)/*.keyID(rsaJWK.getKeyID())*/.build(), claimsSet);
|
||||
|
||||
// Compute the RSA signature
|
||||
signedJWT.sign(signer);
|
||||
// serialize the output...
|
||||
return signedJWT.serialize();
|
||||
} catch (JOSEException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static JWTClaimsSet validateToken(String signedToken, String isuer) {
|
||||
if (rsaPublicJWK == null) {
|
||||
System.out.println("JWT public key is not present !!!");
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
// On the consumer side, parse the JWS and verify its RSA signature
|
||||
SignedJWT signedJWT = SignedJWT.parse(signedToken);
|
||||
|
||||
JWSVerifier verifier = new RSASSAVerifier(rsaPublicJWK);
|
||||
if (!signedJWT.verify(verifier)) {
|
||||
System.out.println("JWT token is NOT verified ");
|
||||
return null;
|
||||
}
|
||||
if (!new Date().before(signedJWT.getJWTClaimsSet().getExpirationTime())) {
|
||||
System.out.println("JWT token is expired now = " + new Date() + " with=" + signedJWT.getJWTClaimsSet().getExpirationTime() );
|
||||
return null;
|
||||
}
|
||||
if (!isuer.equals(signedJWT.getJWTClaimsSet().getIssuer())) {
|
||||
System.out.println("JWT issuer is wong: '" + isuer + "' != '" + signedJWT.getJWTClaimsSet().getIssuer() + "'" );
|
||||
return null;
|
||||
}
|
||||
// the element must be validated outside ...
|
||||
//System.out.println("JWT token is verified 'alice' =?= '" + signedJWT.getJWTClaimsSet().getSubject() + "'");
|
||||
//System.out.println("JWT token isuer 'https://c2id.com' =?= '" + signedJWT.getJWTClaimsSet().getIssuer() + "'");
|
||||
return signedJWT.getJWTClaimsSet();
|
||||
} catch (JOSEException ex) {
|
||||
ex.printStackTrace();
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
package org.kar.karideo.util;
|
||||
|
||||
|
||||
public class PublicKey {
|
||||
public String key;
|
||||
|
||||
public PublicKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
}
|
@ -35,6 +35,16 @@
|
||||
"replace" : "src/environments/environment.ts",
|
||||
"with" : "src/environments/environment.prod.ts"
|
||||
} ]
|
||||
},
|
||||
"develop" : {
|
||||
"optimization" : false,
|
||||
"outputHashing" : "none",
|
||||
"sourceMap" : true,
|
||||
"namedChunks" : true,
|
||||
"aot" : true,
|
||||
"extractLicenses" : true,
|
||||
"vendorChunk" : true,
|
||||
"buildOptimizer" : false
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -46,6 +56,9 @@
|
||||
"configurations" : {
|
||||
"production" : {
|
||||
"browserTarget" : "karideo:build:production"
|
||||
},
|
||||
"develop" : {
|
||||
"browserTarget" : "karideo:build:develop"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
17132
front/package-lock.json
generated
17132
front/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -5,7 +5,7 @@
|
||||
"scripts": {
|
||||
"all": "npm run build && npm run test",
|
||||
"ng": "ng",
|
||||
"start": "ng serve --watch --port 4202",
|
||||
"start": "ng serve --configuration=develop --watch --port 4202",
|
||||
"build": "ng build --prod",
|
||||
"test": "ng test",
|
||||
"lint": "ng lint",
|
||||
@ -13,51 +13,28 @@
|
||||
},
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@angular/animations": "^13.2.5",
|
||||
"@angular/cdk": "^13.2.5",
|
||||
"@angular/common": "^13.2.5",
|
||||
"@angular/compiler": "^13.2.5",
|
||||
"@angular/core": "^13.2.5",
|
||||
"@angular/forms": "^13.2.5",
|
||||
"@angular/material": "^13.2.5",
|
||||
"@angular/platform-browser": "^13.2.5",
|
||||
"@angular/platform-browser-dynamic": "^13.2.5",
|
||||
"@angular/router": "^13.2.5",
|
||||
"core-js": "^3.21.1",
|
||||
"jquery": "^3.6.0",
|
||||
"rxjs": "^7.5.4",
|
||||
"tslib": "^2.3.1",
|
||||
"videogular": "^2.2.1",
|
||||
"zone.js": "^0.11.5"
|
||||
"@angular/animations": "^14.2.10",
|
||||
"@angular/cdk": "^14.2.7",
|
||||
"@angular/common": "^14.2.10",
|
||||
"@angular/compiler": "^14.2.10",
|
||||
"@angular/core": "^14.2.10",
|
||||
"@angular/forms": "^14.2.10",
|
||||
"@angular/material": "^14.2.7",
|
||||
"@angular/platform-browser": "^14.2.10",
|
||||
"@angular/platform-browser-dynamic": "^14.2.10",
|
||||
"@angular/router": "^14.2.10",
|
||||
"rxjs": "^7.5.7",
|
||||
"zone.js": "^0.12.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@angular-devkit/build-angular": "^13.2.5",
|
||||
"@angular-eslint/builder": "13.1.0",
|
||||
"@angular-eslint/eslint-plugin": "13.1.0",
|
||||
"@angular-eslint/eslint-plugin-template": "13.1.0",
|
||||
"@angular-eslint/schematics": "13.1.0",
|
||||
"@angular-eslint/template-parser": "13.1.0",
|
||||
"@angular/cli": "^13.2.5",
|
||||
"@angular/compiler-cli": "^13.2.5",
|
||||
"@angular/language-service": "^13.2.5",
|
||||
"@types/jasmine": "^3.10.3",
|
||||
"@types/jasminewd2": "^2.0.10",
|
||||
"@types/node": "^17.0.21",
|
||||
"@typescript-eslint/eslint-plugin": "^5.17.0",
|
||||
"@typescript-eslint/parser": "^5.17.0",
|
||||
"codelyzer": "^6.0.2",
|
||||
"eslint": "^8.12.0",
|
||||
"eslint-config-google": "^0.14.0",
|
||||
"jasmine-core": "^4.0.1",
|
||||
"jasmine-spec-reporter": "^7.0.0",
|
||||
"karma": "^6.3.17",
|
||||
"karma-chrome-launcher": "^3.1.0",
|
||||
"karma-coverage-istanbul-reporter": "^3.0.3",
|
||||
"karma-jasmine": "^4.0.1",
|
||||
"karma-jasmine-html-reporter": "^1.7.0",
|
||||
"protractor": "^7.0.0",
|
||||
"ts-node": "^10.7.0",
|
||||
"tslint": "^5.20.1",
|
||||
"typescript": "~4.5.5"
|
||||
"@angular-devkit/build-angular": "^14.2.9",
|
||||
"@angular-eslint/builder": "14.2.0",
|
||||
"@angular-eslint/eslint-plugin": "14.2.0",
|
||||
"@angular-eslint/eslint-plugin-template": "14.2.0",
|
||||
"@angular-eslint/schematics": "14.2.0",
|
||||
"@angular-eslint/template-parser": "14.2.0",
|
||||
"@angular/cli": "^14.2.9",
|
||||
"@angular/compiler-cli": "^14.2.10",
|
||||
"@angular/language-service": "^14.2.10"
|
||||
}
|
||||
}
|
||||
|
@ -32,3 +32,11 @@ npx ng lint
|
||||
```
|
||||
|
||||
|
||||
build the local image:
|
||||
|
||||
docker build -t gitea.atria-soft.org/kangaroo-and-rabbit/karideo:latest .
|
||||
|
||||
docker login gitea.atria-soft.org
|
||||
|
||||
docker push gitea.atria-soft.org/kangaroo-and-rabbit/karideo:latest
|
||||
|
||||
|
@ -6,9 +6,10 @@
|
||||
|
||||
import { NgModule } from '@angular/core';
|
||||
import { Routes, RouterModule } from '@angular/router'; // CLI imports router
|
||||
import { SsoScene } from 'common/scene';
|
||||
import { ForbiddenScene, HomeOutScene, SsoScene } from 'common/scene';
|
||||
import { OnlyAdminGuard, OnlyUnregisteredGuardHome, OnlyUsersGuard, OnlyUsersGuardHome } from 'common/service';
|
||||
|
||||
import { HelpScene, HomeScene, SeasonEditScene, SeasonScene, SeriesEditScene, SeriesScene, SettingsScene, TypeScene, UniverseScene, VideoEditScene, VideoScene } from './scene';
|
||||
import { HelpScene, HomeScene, SeasonEditScene, SeasonScene, SeriesEditScene, SeriesScene, SettingsScene, TypeScene, VideoEditScene, VideoScene } from './scene';
|
||||
import { UploadScene } from './scene/upload/upload';
|
||||
// import { HelpComponent } from './help/help.component';
|
||||
|
||||
@ -17,31 +18,86 @@ import { UploadScene } from './scene/upload/upload';
|
||||
|
||||
const routes: Routes = [
|
||||
{ path: '', redirectTo: '/home', pathMatch: 'full' },
|
||||
{ path: 'home', component: HomeScene },
|
||||
{ path: 'upload', component: UploadScene },
|
||||
{ path: 'type/:universeId/:typeId/:seriesId/:seasonId/:videoId', component: TypeScene },
|
||||
|
||||
{ path: 'universe/:universeId/:typeId/:seriesId/:seasonId/:videoId', component: UniverseScene },
|
||||
|
||||
{ path: 'series/:universeId/:typeId/:seriesId/:seasonId/:videoId', component: SeriesScene },
|
||||
{ path: 'series-edit/:universeId/:typeId/:seriesId/:seasonId/:videoId', component: SeriesEditScene },
|
||||
|
||||
{ path: 'season/:universeId/:typeId/:seriesId/:seasonId/:videoId', component: SeasonScene },
|
||||
{ path: 'season-edit/:universeId/:typeId/:seriesId/:seasonId/:videoId', component: SeasonEditScene },
|
||||
|
||||
{ path: 'video/:universeId/:typeId/:seriesId/:seasonId/:videoId', component: VideoScene },
|
||||
{ path: 'video-edit/:universeId/:typeId/:seriesId/:seasonId/:videoId', component: VideoEditScene },
|
||||
{ path: 'forbidden', component: ForbiddenScene },
|
||||
|
||||
{
|
||||
path: 'home',
|
||||
component: HomeScene,
|
||||
canActivate: [OnlyUsersGuardHome], // this route to unregistered path when not logged ==> permit to simplify display
|
||||
},
|
||||
{
|
||||
path: 'unregistered',
|
||||
component: HomeOutScene,
|
||||
canActivate: [OnlyUnregisteredGuardHome], // jump to the home when registered
|
||||
},
|
||||
// ------------------------------------
|
||||
// -- SSO Generic interface
|
||||
// ------------------------------------
|
||||
{ path: 'sso/:data/:keepConnected/:token', component: SsoScene },
|
||||
{ path: 'sso', component: SsoScene },
|
||||
|
||||
// ------------------------------------
|
||||
// -- Generic pages
|
||||
// ------------------------------------
|
||||
{ path: 'help/:page', component: HelpScene },
|
||||
{ path: 'help', component: HelpScene },
|
||||
{ path: 'settings', component: SettingsScene },
|
||||
|
||||
// ------------------------------------
|
||||
// -- upload new data:
|
||||
// ------------------------------------
|
||||
{
|
||||
path: 'upload',
|
||||
component: UploadScene,
|
||||
canActivate: [OnlyAdminGuard],
|
||||
},
|
||||
{
|
||||
path: 'type/:typeId/:seriesId/:seasonId/:videoId',
|
||||
component: TypeScene,
|
||||
canActivate: [OnlyUsersGuard],
|
||||
},
|
||||
|
||||
{
|
||||
path: 'series/:typeId/:seriesId/:seasonId/:videoId',
|
||||
component: SeriesScene,
|
||||
canActivate: [OnlyUsersGuard],
|
||||
},
|
||||
{
|
||||
path: 'series-edit/:typeId/:seriesId/:seasonId/:videoId',
|
||||
component: SeriesEditScene,
|
||||
canActivate: [OnlyAdminGuard],
|
||||
},
|
||||
|
||||
{
|
||||
path: 'season/:typeId/:seriesId/:seasonId/:videoId',
|
||||
component: SeasonScene,
|
||||
canActivate: [OnlyUsersGuard],
|
||||
},
|
||||
{
|
||||
path: 'season-edit/:typeId/:seriesId/:seasonId/:videoId',
|
||||
component: SeasonEditScene,
|
||||
canActivate: [OnlyAdminGuard],
|
||||
},
|
||||
|
||||
{
|
||||
path: 'video/:typeId/:seriesId/:seasonId/:videoId',
|
||||
component: VideoScene,
|
||||
canActivate: [OnlyUsersGuard],
|
||||
},
|
||||
{
|
||||
path: 'video-edit/:typeId/:seriesId/:seasonId/:videoId',
|
||||
component: VideoEditScene,
|
||||
canActivate: [OnlyAdminGuard],
|
||||
},
|
||||
{
|
||||
path: 'settings',
|
||||
component: SettingsScene,
|
||||
canActivate: [OnlyUsersGuard],
|
||||
},
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
imports: [ RouterModule.forRoot(routes, { relativeLinkResolution: 'legacy' }) ],
|
||||
imports: [ RouterModule.forRoot(routes) ],
|
||||
exports: [ RouterModule ]
|
||||
})
|
||||
export class AppRoutingModule { }
|
||||
|
@ -1,15 +1,14 @@
|
||||
|
||||
<!-- exercice section -->
|
||||
<app-top-menu></app-top-menu>
|
||||
<!--
|
||||
<div class="main-content" ng-include="currentDisplay" ng-if="currentDisplay != ''"></div>
|
||||
<div class="main-modal" ng-include="currentModal" ng-if="currentModal != ''" ></div> <!-- (click)="onOutModal()" -->
|
||||
-->
|
||||
<div class="main-content">
|
||||
<router-outlet *ngIf="autoConnectedDone"></router-outlet>
|
||||
<div class="generic-page" *ngIf="!isConnected">
|
||||
<!-- Generig global menu -->
|
||||
<app-top-menu [menu]="currentMenu" (callback)="eventOnMenu($event)"></app-top-menu>
|
||||
<!-- all interfaced pages -->
|
||||
<div class="main-content" *ngIf="autoConnectedDone">
|
||||
<router-outlet ></router-outlet>
|
||||
</div>
|
||||
<div class="main-content" *ngIf="!autoConnectedDone">
|
||||
<div class="generic-page">
|
||||
<div class="fill-all colomn_mutiple">
|
||||
<b style="color:red;">You Must be connected to access @Karideo...</b>
|
||||
<b style="color:red;">Auto-connection in progress</b>
|
||||
<div class="clear"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -6,7 +6,21 @@
|
||||
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
import { UserService, SessionService } from 'common/service';
|
||||
import { EventOnMenu } from 'common/component/top-menu/top-menu';
|
||||
import { MenuItem, MenuPosition } from 'common/model';
|
||||
import { UserService, SessionService, SSOService } from 'common/service';
|
||||
import { isNullOrUndefined } from 'common/utils';
|
||||
import { ArianeService } from './service';
|
||||
|
||||
enum MenuEventType {
|
||||
SSO_LOGIN = "SSO_CALL_LOGIN",
|
||||
SSO_LOGOUT = "SSO_CALL_LOGOUT",
|
||||
SSO_SIGNUP = "SSO_CALL_SIGNUP",
|
||||
TYPE = "TYPE",
|
||||
SERIES = "SERIES",
|
||||
SEASON = "SEASON",
|
||||
VIDEO = "VIDEO",
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-root',
|
||||
@ -19,27 +33,47 @@ export class AppComponent implements OnInit {
|
||||
title: string = 'Karideo';
|
||||
autoConnectedDone: boolean = false;
|
||||
isConnected: boolean = false;
|
||||
signUpEnable: boolean = true;
|
||||
currentMenu: MenuItem[] = [];
|
||||
location: string = "home";
|
||||
|
||||
constructor(
|
||||
private router: Router,
|
||||
private userService: UserService,
|
||||
private sessionService: SessionService) {
|
||||
private sessionService: SessionService,
|
||||
private ssoService: SSOService,
|
||||
private arianeService: ArianeService) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.location = location.pathname;
|
||||
this.autoConnectedDone = false;
|
||||
this.isConnected = false;
|
||||
this.updateMainMenu();
|
||||
let self = this;
|
||||
this.sessionService.change.subscribe((isConnected) => {
|
||||
console.log(`receive event from session ...${ isConnected}`);
|
||||
self.isConnected = isConnected;
|
||||
self.autoConnectedDone = true;
|
||||
self.updateMainMenu();
|
||||
});
|
||||
this.ssoService.checkSignUpEnable()
|
||||
.then((value: boolean) => {
|
||||
console.log(`Get value signUp = ${value}`);
|
||||
self.signUpEnable = value;
|
||||
self.updateMainMenu();
|
||||
self.router.navigateByUrl(self.location);
|
||||
console.log(`update global URL = ${self.location}`);
|
||||
}).catch((error: any) => {
|
||||
console.log(`Can not call the sso to check the sign-up_interface: ${error}`);
|
||||
});
|
||||
|
||||
this.userService.checkAutoConnect().then(() => {
|
||||
console.log(` ==>>>>> Autoconnect THEN !!!`);
|
||||
self.autoConnectedDone = true;
|
||||
//window.location.href = self.location;
|
||||
}).catch(() => {
|
||||
console.log(` ==>>>>> Autoconnect CATCH !!!`);
|
||||
self.autoConnectedDone = true;
|
||||
@ -47,6 +81,176 @@ export class AppComponent implements OnInit {
|
||||
console.log(` ==>>>>> Autoconnect FINALLY !!!`);
|
||||
self.autoConnectedDone = true;
|
||||
});
|
||||
this.arianeService.segmentChange.subscribe((_segmentName: string) => {
|
||||
self.updateMainMenu();
|
||||
});
|
||||
this.arianeService.typeChange.subscribe((_typeId: number) => {
|
||||
self.updateMainMenu();
|
||||
});
|
||||
this.arianeService.seriesChange.subscribe((_seriesId: number) => {
|
||||
self.updateMainMenu();
|
||||
});
|
||||
this.arianeService.seasonChange.subscribe((_seasonId: number) => {
|
||||
self.updateMainMenu();
|
||||
});
|
||||
this.arianeService.videoChange.subscribe((_videoId: number) => {
|
||||
self.updateMainMenu();
|
||||
});
|
||||
}
|
||||
|
||||
eventOnMenu(data: EventOnMenu): void {
|
||||
//console.log(`plopppppppppp ${JSON.stringify(this.route.snapshot.url)}`);
|
||||
//console.log(`Get event on menu: ${JSON.stringify(data, null, 4)}`);
|
||||
switch(data.menu.otherData) {
|
||||
case MenuEventType.SSO_LOGIN:
|
||||
this.ssoService.requestSignIn();
|
||||
break;
|
||||
case MenuEventType.SSO_LOGOUT:
|
||||
this.ssoService.requestSignOut();
|
||||
break;
|
||||
case MenuEventType.SSO_SIGNUP:
|
||||
this.ssoService.requestSignUp();
|
||||
break;
|
||||
case MenuEventType.TYPE:
|
||||
this.arianeService.navigateType(this.arianeService.getTypeId(), data.newWindows, data.ctrl);
|
||||
break;
|
||||
case MenuEventType.SERIES:
|
||||
this.arianeService.navigateSeries(this.arianeService.getSeriesId(), data.newWindows, data.ctrl);
|
||||
break;
|
||||
case MenuEventType.SEASON:
|
||||
this.arianeService.navigateSeason(this.arianeService.getSeasonId(), data.newWindows, data.ctrl);
|
||||
break;
|
||||
case MenuEventType.VIDEO:
|
||||
this.arianeService.navigateVideo(this.arianeService.getVideoId(), data.newWindows, data.ctrl);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
updateMainMenu(): void {
|
||||
console.log("update main menu :");
|
||||
if (this.isConnected) {
|
||||
this.currentMenu = [
|
||||
{
|
||||
position: MenuPosition.LEFT,
|
||||
hover: `You are logged as: ${this.sessionService.getLogin()}`,
|
||||
icon: "menu",
|
||||
title: "Menu",
|
||||
subMenu: [
|
||||
{
|
||||
position: MenuPosition.LEFT,
|
||||
hover: "Go to Home page",
|
||||
icon: "home",
|
||||
title: "Home",
|
||||
navigateTo: "home",
|
||||
}, {
|
||||
position: MenuPosition.LEFT,
|
||||
icon: "group_work",
|
||||
title: this.arianeService.getTypeName(),
|
||||
otherData: MenuEventType.TYPE,
|
||||
callback: true,
|
||||
enable: !isNullOrUndefined(this.arianeService.getTypeId()),
|
||||
}, {
|
||||
position: MenuPosition.LEFT,
|
||||
icon: "tag",
|
||||
title: this.arianeService.getSeriesName(),
|
||||
otherData: MenuEventType.SERIES,
|
||||
callback: true,
|
||||
enable: !isNullOrUndefined(this.arianeService.getSeriesId()),
|
||||
}, {
|
||||
position: MenuPosition.LEFT,
|
||||
icon: "album",
|
||||
title: `Season ${this.arianeService.getSeasonName()}`,
|
||||
otherData: MenuEventType.SEASON,
|
||||
callback: true,
|
||||
enable: !isNullOrUndefined(this.arianeService.getSeasonId()),
|
||||
}, {
|
||||
position: MenuPosition.LEFT,
|
||||
icon: "movie",
|
||||
title: this.arianeService.getVideoName(),
|
||||
otherData: MenuEventType.VIDEO,
|
||||
callback: true,
|
||||
enable: !isNullOrUndefined(this.arianeService.getVideoId()),
|
||||
},
|
||||
],
|
||||
}, {
|
||||
position: MenuPosition.RIGHT,
|
||||
image: "assets/images/avatar_generic.svg",
|
||||
title: "",
|
||||
subMenu: [
|
||||
{
|
||||
position: MenuPosition.LEFT,
|
||||
hover: `You are logged as: <b>${this.sessionService.getLogin()}</b>`,
|
||||
title: `Sign in as ${this.sessionService.getLogin()}`,
|
||||
}, {
|
||||
position: MenuPosition.LEFT,
|
||||
icon: "add_circle",
|
||||
title: "Add media",
|
||||
navigateTo: "upload",
|
||||
enable: this.sessionService.userAdmin === true,
|
||||
}, {
|
||||
position: MenuPosition.LEFT,
|
||||
icon: "settings",
|
||||
title: "Settings",
|
||||
navigateTo: "settings",
|
||||
}, {
|
||||
position: MenuPosition.LEFT,
|
||||
icon: "help",
|
||||
title: "Help",
|
||||
navigateTo: "help",
|
||||
}, {
|
||||
position: MenuPosition.LEFT,
|
||||
hover: "Exit connection",
|
||||
icon: "exit_to_app",
|
||||
title: "Sign out",
|
||||
callback: true,
|
||||
otherData: MenuEventType.SSO_LOGOUT,
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
} else {
|
||||
this.currentMenu = [
|
||||
{
|
||||
position: MenuPosition.LEFT,
|
||||
hover: "Go to Home page",
|
||||
icon: "home",
|
||||
title: "Home",
|
||||
navigateTo: "home",
|
||||
}, {
|
||||
position: MenuPosition.RIGHT,
|
||||
hover: "Create a new account",
|
||||
icon: "add_circle_outline",
|
||||
title: "Sign-up",
|
||||
callback: true,
|
||||
model: this.signUpEnable?undefined:"disable",
|
||||
otherData: MenuEventType.SSO_SIGNUP,
|
||||
}, {
|
||||
position: MenuPosition.RIGHT,
|
||||
hover: "Login page",
|
||||
icon: "account_circle",
|
||||
title: "Sign-in",
|
||||
callback: true,
|
||||
otherData: MenuEventType.SSO_LOGIN,
|
||||
},
|
||||
];
|
||||
}
|
||||
console.log(" ==> DONE");
|
||||
|
||||
}
|
||||
getSegmentDisplayable(): string {
|
||||
let segment = this.arianeService.getCurrrentSegment();
|
||||
if (segment === "type") {
|
||||
return "Type";
|
||||
}
|
||||
if (segment === "season") {
|
||||
return "Season";
|
||||
}
|
||||
if (segment === "series") {
|
||||
return "Series";
|
||||
}
|
||||
if (segment === "video") {
|
||||
return "Video";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,27 +11,26 @@ import { HttpClientModule } from '@angular/common/http';
|
||||
import { FormsModule, ReactiveFormsModule } from '@angular/forms'; // this is needed for dynamic selection of the select
|
||||
import { AppRoutingModule } from './app-routing.module';
|
||||
|
||||
import { UploadFileComponent } from '../common/component/upload-file/upload-file';
|
||||
import { TopMenuComponent } from './component/top-menu/top-menu';
|
||||
import { UploadFileComponent } from 'common/component/upload-file/upload-file';
|
||||
import { ElementDataImageComponent } from './component/data-image/data-image';
|
||||
import { ElementTypeComponent } from './component/element-type/element-type';
|
||||
import { ElementSeriesComponent } from './component/element-series/element-series';
|
||||
import { ElementSeasonComponent } from './component/element-season/element-season';
|
||||
import { ElementVideoComponent } from './component/element-video/element-video';
|
||||
import { PopInComponent } from '../common/component/popin/popin';
|
||||
import { PopInComponent } from 'common/component/popin/popin';
|
||||
|
||||
import { PopInCreateType } from './popin/create-type/create-type';
|
||||
import { PopInUploadProgress } from '../common/popin/upload-progress/upload-progress';
|
||||
import { PopInDeleteConfirm } from '../common/popin/delete-confirm/delete-confirm';
|
||||
import { PopInUploadProgress } from 'common/popin/upload-progress/upload-progress';
|
||||
import { PopInDeleteConfirm } from 'common/popin/delete-confirm/delete-confirm';
|
||||
|
||||
import { AppComponent } from './app.component';
|
||||
import { ErrorComponent } from '../common/error/error';
|
||||
import { HomeScene, HelpScene, TypeScene, UniverseScene, SeriesScene, SeasonScene, VideoScene, SettingsScene,
|
||||
import { HomeScene, HelpScene, TypeScene, SeriesScene, SeasonScene, VideoScene, SettingsScene,
|
||||
VideoEditScene, SeasonEditScene, SeriesEditScene } from './scene';
|
||||
import { TypeService, DataService, UniverseService, SeriesService, SeasonService, VideoService, ArianeService } from './service';
|
||||
import { BddService, CookiesService, HttpWrapperService, PopInService, SessionService, SSOService, StorageService, UserService } from 'common/service';
|
||||
import { ErrorViewerScene, SsoScene } from 'common/scene';
|
||||
import { TypeService, DataService, SeriesService, SeasonService, VideoService, ArianeService } from './service';
|
||||
import { BddService, CookiesService, HttpWrapperService, OnlyAdminGuard, OnlyUnregisteredGuardHome, OnlyUsersGuard, OnlyUsersGuardHome, PopInService, SessionService, SSOService, StorageService, UserService } from 'common/service';
|
||||
import { ErrorViewerScene, ForbiddenScene, HomeOutScene, NotFound404Scene, SsoScene } from 'common/scene';
|
||||
import { UploadScene } from './scene/upload/upload';
|
||||
import { ErrorComponent, TopMenuComponent } from 'common/component';
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
@ -55,7 +54,6 @@ import { UploadScene } from './scene/upload/upload';
|
||||
HelpScene,
|
||||
SsoScene,
|
||||
TypeScene,
|
||||
UniverseScene,
|
||||
SeriesScene,
|
||||
SeasonScene,
|
||||
VideoScene,
|
||||
@ -64,6 +62,9 @@ import { UploadScene } from './scene/upload/upload';
|
||||
SeasonEditScene,
|
||||
SeriesEditScene,
|
||||
UploadScene,
|
||||
ForbiddenScene,
|
||||
HomeOutScene,
|
||||
NotFound404Scene,
|
||||
],
|
||||
imports: [
|
||||
BrowserModule,
|
||||
@ -84,11 +85,14 @@ import { UploadScene } from './scene/upload/upload';
|
||||
BddService,
|
||||
TypeService,
|
||||
DataService,
|
||||
UniverseService,
|
||||
SeriesService,
|
||||
SeasonService,
|
||||
VideoService,
|
||||
ArianeService
|
||||
ArianeService,
|
||||
OnlyUsersGuard,
|
||||
OnlyAdminGuard,
|
||||
OnlyUsersGuardHome,
|
||||
OnlyUnregisteredGuardHome,
|
||||
],
|
||||
exports: [
|
||||
AppComponent,
|
||||
|
@ -1,211 +0,0 @@
|
||||
<div class="top">
|
||||
<div id="main-menu" class="main-menu color-menu-background">
|
||||
<button class="item"
|
||||
(click)="onHome($event)"
|
||||
(auxclick)="($event)">
|
||||
<div class="xdesktop">
|
||||
<i class="material-icons">home</i> Home
|
||||
</div>
|
||||
<div class="xmobile">
|
||||
<i class="material-icons">home</i>
|
||||
</div>
|
||||
</button>
|
||||
<div class="ariane">
|
||||
<button class="item"
|
||||
*ngIf="arianeTypeId !== null"
|
||||
title="Uype"
|
||||
(click)="onArianeType($event)"
|
||||
(auxclick)="onArianeType($event)">
|
||||
<div class="xdesktop">
|
||||
{{arianeTypeName}}
|
||||
</div>
|
||||
<div class="xmobile">
|
||||
T
|
||||
</div>
|
||||
</button>
|
||||
<div class="item_ariane_separator" *ngIf="arianeUniverseId !== null && arianeTypeId !== null" >/</div>
|
||||
<button class="item"
|
||||
*ngIf="arianeUniverseId !== null"
|
||||
title="Universe"
|
||||
(click)="onArianeUniverse($event)"
|
||||
(auxclick)="onArianeUniverse($event)">
|
||||
<div class="xdesktop">
|
||||
{{arianeUniverseName}}
|
||||
</div>
|
||||
<div class="xmobile">
|
||||
U
|
||||
</div>
|
||||
</button>
|
||||
<div class="item_ariane_separator" *ngIf="arianeSeriesId !== null && (arianeUniverseId !== null || arianeTypeId !== null)" >/</div>
|
||||
<button class="item"
|
||||
*ngIf="arianeSeriesId !== null"
|
||||
title="Series"
|
||||
(click)="onArianeSeries($event)"
|
||||
(auxclick)="onArianeSeries($event)">
|
||||
<div class="xdesktop">
|
||||
{{arianeSeriesName}}
|
||||
</div>
|
||||
<div class="xmobile">
|
||||
G
|
||||
</div>
|
||||
</button>
|
||||
<div class="item_ariane_separator" *ngIf="arianeSeasonId !== null && (arianeSeriesId !== null || arianeUniverseId !== null || arianeTypeId !== null)" >/</div>
|
||||
<button class="item"
|
||||
*ngIf="arianeSeasonId !== null"
|
||||
title="Season"
|
||||
(click)="onArianeSeason($event)"
|
||||
(auxclick)="onArianeSeason($event)">
|
||||
<div class="xdesktop">
|
||||
{{arianeSeasonName}}
|
||||
</div>
|
||||
<div class="xmobile">
|
||||
S
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
<button class="item"
|
||||
*ngIf="!login"
|
||||
style="float:right;"
|
||||
(click)="onSignUp($event)"
|
||||
(auxclick)="onSignUp($event)">
|
||||
<div class="xdesktop">
|
||||
<i class="material-icons">add_circle_outline</i> Sign-up
|
||||
</div>
|
||||
<div class="xmobile">
|
||||
<i class="material-icons">add_circle_outline</i>
|
||||
</div>
|
||||
</button>
|
||||
<button class="item"
|
||||
*ngIf="!login"
|
||||
style="float:right;"
|
||||
(click)="onSignIn($event)"
|
||||
(auxclick)="onSignIn($event)">
|
||||
<div class="xdesktop">
|
||||
<i class="material-icons">account_circle</i> Sign-in
|
||||
</div>
|
||||
<div class="xmobile">
|
||||
<i class="material-icons">account_circle</i>
|
||||
</div>
|
||||
</button>
|
||||
<button class="item"
|
||||
*ngIf="login"
|
||||
style="float:right; height:56px;"
|
||||
(click)="onAvatar()">
|
||||
<img class="avatar" src="{{avatar}}"/>
|
||||
</button>
|
||||
<button class="item"
|
||||
*ngIf="editShow === true"
|
||||
style="float:right; height:56px;"
|
||||
(click)="onEdit()">
|
||||
<div class="xdesktop">
|
||||
<i class="material-icons">edit</i> Edit
|
||||
</div>
|
||||
<div class="xmobile">
|
||||
<i class="material-icons">edit</i>
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
<div class="fill-all" *ngIf="login !== null && displayUserMenu === true" (click)="onOutUserProperty()">
|
||||
<!-- (click)="onOutUserProperty()" -->
|
||||
<div class="sub-menu user-menu color-menu-background">
|
||||
<button class="item" disabled="disabled">
|
||||
Sign in as <b>{{login}}</b>
|
||||
</button>
|
||||
<button class="item"
|
||||
(click)="onHelp($event)"
|
||||
(auxclick)="onHelp($event)">
|
||||
<i class="material-icons">help_outline</i> Help
|
||||
</button>
|
||||
<button class="item"
|
||||
(click)="onSetting($event)"
|
||||
(auxclick)="onSetting($event)">
|
||||
<i class="material-icons">settings</i> Settings
|
||||
</button>
|
||||
<button class="item"
|
||||
(click)="onLogout($event)"
|
||||
(auxclick)="onLogout($event)">
|
||||
<i class="material-icons">exit_to_app</i> Sign out
|
||||
</button>
|
||||
<button class="item"
|
||||
(click)="onAddMedia($event)"
|
||||
(auxclick)="onAddMedia($event)">
|
||||
<i class="material-icons">add_circle</i> Add media
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="fill-all" *ngIf="displayEditMenu == true" (click)="onOutUserProperty()">
|
||||
<!-- (click)="onOutUserProperty()" -->
|
||||
<div class="xdesktop">
|
||||
<div class="sub-menu edit-menu color-menu-background">
|
||||
<!--
|
||||
<button class="item"
|
||||
*ngIf="arianeTypeId !== null"
|
||||
(click)="onSubEditType($event)"
|
||||
(auxclick)="onSubEditType($event)">
|
||||
<b>Edit Type</b>
|
||||
</button>
|
||||
<button class="item"
|
||||
*ngIf="arianeUniverseId !== null"
|
||||
(click)="onSubEditUniverse($event)"
|
||||
(auxclick)="onSubEditUniverse($event)">
|
||||
<b>Edit Universe</b>
|
||||
</button>
|
||||
-->
|
||||
<button class="item"
|
||||
*ngIf="arianeSeriesId !== null"
|
||||
(click)="onSubEditSeries($event)"
|
||||
(auxclick)="onSubEditSeries($event)">
|
||||
<b>Edit Series</b>
|
||||
</button>
|
||||
<button class="item"
|
||||
*ngIf="arianeSeasonId !== null"
|
||||
(click)="onSubEditSeason($event)"
|
||||
(auxclick)="onSubEditSeason($event)">
|
||||
<b>Edit Season</b>
|
||||
</button>
|
||||
<button class="item"
|
||||
*ngIf="arianeVideoId !== null"
|
||||
(click)="onSubEditVideo($event)"
|
||||
(auxclick)="onSubEditVideo($event)">
|
||||
<b>Edit Video</b>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="xmobile">
|
||||
<div class="sub-menu edit-menu-mob color-menu-background">
|
||||
<!--
|
||||
<button class="item"
|
||||
*ngIf="arianeTypeId !== null"
|
||||
(click)="onSubEditType($event)"
|
||||
(auxclick)="onSubEditType($event)">
|
||||
<b>Edit Type</b>
|
||||
</button>
|
||||
<button class="item"
|
||||
*ngIf="arianeUniverseId !== null"
|
||||
(click)="onSubEditUniverse($event)"
|
||||
(auxclick)="onSubEditUniverse($event)">
|
||||
<b>Edit Universe</b>
|
||||
</button>
|
||||
-->
|
||||
<button class="item"
|
||||
*ngIf="arianeSeriesId !== null"
|
||||
(click)="onSubEditSeries($event)"
|
||||
(auxclick)="onSubEditSeries($event)">
|
||||
<b>Edit Series</b>
|
||||
</button>
|
||||
<button class="item"
|
||||
*ngIf="arianeSeasonId !== null"
|
||||
(click)="onSubEditSeason($event)"
|
||||
(auxclick)="onSubEditSeason($event)">
|
||||
<b>Edit Season</b>
|
||||
</button>
|
||||
<button class="item"
|
||||
*ngIf="arianeVideoId !== null"
|
||||
(click)="onSubEditVideo($event)"
|
||||
(auxclick)="onSubEditVideo($event)">
|
||||
<b>Edit Video</b>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
@ -1,215 +0,0 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2018, Edouard DUPIN, all right reserved
|
||||
* @license PROPRIETARY (see license file)
|
||||
*/
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
import { UserService, SessionService, SSOService } from 'common/service';
|
||||
import { ArianeService } from 'app/service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-top-menu',
|
||||
templateUrl: './top-menu.html',
|
||||
styleUrls: [ './top-menu.less' ]
|
||||
})
|
||||
export class TopMenuComponent implements OnInit {
|
||||
public login: string;// Session.getLogin();
|
||||
public avatar: string;// Session.getAvatar();
|
||||
public displayUserMenu: boolean = false;
|
||||
public displayEditMenu: boolean = false;
|
||||
|
||||
public arianeTypeId: number = null;
|
||||
public arianeTypeName: string = null;
|
||||
|
||||
public arianeUniverseId: number = null;
|
||||
public arianeUniverseName: string = null;
|
||||
|
||||
public arianeSeriesId: number = null;
|
||||
public arianeSeriesName: string = null;
|
||||
|
||||
public arianeSeasonId: number = null;
|
||||
public arianeSeasonName: string = null;
|
||||
|
||||
public arianeVideoId: number = null;
|
||||
public arianeVideoName: string = null;
|
||||
|
||||
public editShow: boolean = false;
|
||||
|
||||
constructor(private router: Router,
|
||||
private sessionService: SessionService,
|
||||
private arianeService: ArianeService,
|
||||
private userService: UserService,
|
||||
private ssoService: SSOService) {
|
||||
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
let self = this;
|
||||
this.sessionService.change.subscribe((isConnected) => {
|
||||
console.log(`TOP-MENU: receive event from session ...${isConnected}`);
|
||||
if(isConnected === false) {
|
||||
self.login = undefined;
|
||||
self.avatar = undefined;
|
||||
self.displayUserMenu = false;
|
||||
} else {
|
||||
self.updateIsJusteLogged();
|
||||
}
|
||||
});
|
||||
if (this.sessionService.islogged()) {
|
||||
this.updateIsJusteLogged();
|
||||
}
|
||||
this.arianeService.typeChange.subscribe((typeId: number) => {
|
||||
this.arianeTypeId = typeId;
|
||||
this.arianeTypeName = this.arianeService.getTypeName();
|
||||
this.updateEditShow();
|
||||
});
|
||||
this.arianeService.universeChange.subscribe((universId) => {
|
||||
this.arianeUniverseId = universId;
|
||||
this.arianeUniverseName = this.arianeService.getUniverseName();
|
||||
this.updateEditShow();
|
||||
});
|
||||
this.arianeService.seriesChange.subscribe((seriesId) => {
|
||||
this.arianeSeriesId = seriesId;
|
||||
this.arianeSeriesName = this.arianeService.getSeriesName();
|
||||
this.updateEditShow();
|
||||
});
|
||||
this.arianeService.seasonChange.subscribe((seasonId) => {
|
||||
this.arianeSeasonId = seasonId;
|
||||
this.arianeSeasonName = this.arianeService.getSeasonName();
|
||||
this.updateEditShow();
|
||||
});
|
||||
this.arianeService.videoChange.subscribe((videoId) => {
|
||||
this.arianeVideoId = videoId;
|
||||
this.arianeVideoName = this.arianeService.getVideoName();
|
||||
this.updateEditShow();
|
||||
});
|
||||
}
|
||||
|
||||
private updateIsJusteLogged(): void {
|
||||
this.login = this.sessionService.getLogin();
|
||||
this.avatar = this.sessionService.getAvatar();
|
||||
this.displayUserMenu = false;
|
||||
console.log(` login:${this.sessionService.getLogin()}`);
|
||||
console.log(` avatar:${this.avatar}`);
|
||||
|
||||
}
|
||||
|
||||
onAvatar(): void {
|
||||
console.log(`onAvatar() ${ this.displayUserMenu}`);
|
||||
this.displayUserMenu = !this.displayUserMenu;
|
||||
this.displayEditMenu = false;
|
||||
}
|
||||
|
||||
|
||||
onHome(event: any): void {
|
||||
console.log('onHome()');
|
||||
this.router.navigate([ 'home' ]);
|
||||
}
|
||||
|
||||
onSignIn(event: any): void {
|
||||
console.log('onSignIn()');
|
||||
this.ssoService.requestSignIn();
|
||||
}
|
||||
|
||||
onSignUp(event: any): void {
|
||||
console.log('onSignIn()');
|
||||
this.ssoService.requestSignUp();
|
||||
this.displayUserMenu = false;
|
||||
}
|
||||
|
||||
onLogout(event: any): void {
|
||||
console.log('onLogout()');
|
||||
this.ssoService.requestSignOut();
|
||||
this.userService.logOut();
|
||||
this.router.navigate(['home']);
|
||||
this.displayUserMenu = false;
|
||||
}
|
||||
|
||||
|
||||
onSetting(event: any): void {
|
||||
console.log('onSetting()');
|
||||
this.router.navigate([ 'settings' ]);
|
||||
this.displayUserMenu = false;
|
||||
}
|
||||
|
||||
onHelp(event: any): void {
|
||||
console.log('onHelp()');
|
||||
this.router.navigate([ 'help' ]);
|
||||
this.displayUserMenu = false;
|
||||
}
|
||||
|
||||
onOutUserProperty(): void {
|
||||
console.log('onOutUserProperty ==> event...');
|
||||
this.displayUserMenu = false;
|
||||
this.displayEditMenu = false;
|
||||
}
|
||||
|
||||
onArianeType(event: any): void {
|
||||
console.log(`onArianeType(${ this.arianeTypeId })`);
|
||||
this.arianeService.navigateType(this.arianeTypeId, event.which === 2);
|
||||
}
|
||||
|
||||
onArianeUniverse(event: any): void {
|
||||
console.log(`onArianeUniverse(${ this.arianeUniverseId })`);
|
||||
this.arianeService.navigateUniverse(this.arianeUniverseId, event.which === 2);
|
||||
}
|
||||
|
||||
onArianeSeries(event: any): void {
|
||||
console.log(`onArianeSeries(${ this.arianeSeriesId })`);
|
||||
this.arianeService.navigateSeries(this.arianeSeriesId, event.which === 2);
|
||||
}
|
||||
|
||||
onArianeSeason(event: any): void {
|
||||
console.log(`onArianeSeason(${ this.arianeSeasonId })`);
|
||||
this.arianeService.navigateSeason(this.arianeSeasonId, event.which === 2);
|
||||
}
|
||||
|
||||
updateEditShow():void {
|
||||
this.editShow = /* this.arianeTypeId !== null
|
||||
|| this.arianeUniverseId !== null
|
||||
||*/ this.arianeSeriesId !== null ||
|
||||
this.arianeSeasonId !== null ||
|
||||
this.arianeVideoId !== null;
|
||||
}
|
||||
onEdit(): void {
|
||||
console.log('onEdit()');
|
||||
this.displayEditMenu = !this.displayEditMenu;
|
||||
this.displayUserMenu = false;
|
||||
}
|
||||
onSubEditVideo(event: any): void {
|
||||
console.log('onSubEdit()');
|
||||
this.displayEditMenu = false;
|
||||
this.displayUserMenu = false;
|
||||
this.arianeService.navigateVideoEdit(this.arianeVideoId, event.which === 2);
|
||||
}
|
||||
onSubEditSeason(event: any): void {
|
||||
console.log('onSubEdit()');
|
||||
this.displayEditMenu = false;
|
||||
this.displayUserMenu = false;
|
||||
this.arianeService.navigateSeasonEdit(this.arianeSeasonId, event.which === 2);
|
||||
}
|
||||
onSubEditSeries(event: any): void {
|
||||
console.log('onSubEdit()');
|
||||
this.displayEditMenu = false;
|
||||
this.displayUserMenu = false;
|
||||
this.arianeService.navigateSeriesEdit(this.arianeSeriesId, event.which === 2);
|
||||
}
|
||||
onSubEditUniverse(event: any): void {
|
||||
console.log('onSubEdit()');
|
||||
this.displayEditMenu = false;
|
||||
this.displayUserMenu = false;
|
||||
this.arianeService.navigateUniverseEdit(this.arianeUniverseId, event.which === 2);
|
||||
}
|
||||
onSubEditType(event: any): void {
|
||||
console.log('onSubEditType()');
|
||||
this.displayEditMenu = false;
|
||||
this.displayUserMenu = false;
|
||||
this.arianeService.navigateTypeEdit(this.arianeTypeId, event.which === 2);
|
||||
}
|
||||
onAddMedia(event: any): void {
|
||||
console.log('onAddMedia()');
|
||||
this.router.navigate([ 'upload' ]);
|
||||
this.displayUserMenu = false;
|
||||
}
|
||||
}
|
@ -5,13 +5,12 @@ import { isNodeData, NodeData } from "common/model/node";
|
||||
export interface Media extends NodeData {
|
||||
dataId?: number;
|
||||
typeId?: number;
|
||||
universeId?: number;
|
||||
seriesId?: number;
|
||||
seasonId?: number;
|
||||
episode?: number;
|
||||
date?: number;
|
||||
time?: number;
|
||||
ageLimit?: string;
|
||||
ageLimit?: number;
|
||||
};
|
||||
|
||||
|
||||
@ -26,9 +25,6 @@ export function isMedia(data: any): data is Media {
|
||||
if (!isOptionalOf(data.typeId, isNumberFinite)) {
|
||||
return false;
|
||||
}
|
||||
if (!isOptionalOf(data.universeId, isNumberFinite)) {
|
||||
return false;
|
||||
}
|
||||
if (!isOptionalOf(data.seriesId, isNumberFinite)) {
|
||||
return false;
|
||||
}
|
||||
@ -44,7 +40,7 @@ export function isMedia(data: any): data is Media {
|
||||
if (!isOptionalOf(data.time, isNumberFinite)) {
|
||||
return false;
|
||||
}
|
||||
if (!isOptionalOf(data.ageLimit, isString)) {
|
||||
if (!isOptionalOf(data.ageLimit, isNumberFinite)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -6,7 +6,6 @@
|
||||
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { ArianeService } from 'app/service/ariane';
|
||||
|
||||
@Component({
|
||||
selector: 'app-help',
|
||||
@ -16,11 +15,9 @@ import { ArianeService } from 'app/service/ariane';
|
||||
export class HelpScene implements OnInit {
|
||||
page = '';
|
||||
|
||||
constructor(private route: ActivatedRoute,
|
||||
private arianeService: ArianeService) { }
|
||||
constructor(private route: ActivatedRoute) { }
|
||||
|
||||
ngOnInit() {
|
||||
this.arianeService.updateManual(this.route.snapshot.paramMap);
|
||||
const page = this.route.snapshot.paramMap.get('page');
|
||||
if (page == null) {
|
||||
this.page = undefined;
|
||||
|
@ -5,7 +5,6 @@
|
||||
*/
|
||||
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
|
||||
import { TypeService } from 'app/service/type';
|
||||
import { ArianeService } from 'app/service/ariane';
|
||||
@ -18,14 +17,12 @@ import { ArianeService } from 'app/service/ariane';
|
||||
export class HomeScene implements OnInit {
|
||||
dataList = [];
|
||||
error = '';
|
||||
constructor(private route: ActivatedRoute,
|
||||
private typeService: TypeService,
|
||||
constructor(private typeService: TypeService,
|
||||
private arianeService: ArianeService) {
|
||||
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.arianeService.updateManual(this.route.snapshot.paramMap);
|
||||
let self = this;
|
||||
this.typeService.getData()
|
||||
.then((response) => {
|
||||
|
@ -6,7 +6,6 @@ import { SeriesEditScene } from "./series-edit/series-edit";
|
||||
import { SeriesScene } from "./series/series";
|
||||
import { SettingsScene } from "./settings/settings";
|
||||
import { TypeScene } from "./type/type";
|
||||
import { UniverseScene } from "./universe/universe";
|
||||
import { VideoEditScene } from "./video-edit/video-edit";
|
||||
import { VideoScene } from "./video/video";
|
||||
|
||||
@ -20,7 +19,6 @@ export {
|
||||
SeriesScene,
|
||||
SeriesEditScene,
|
||||
TypeScene,
|
||||
UniverseScene,
|
||||
VideoScene,
|
||||
VideoEditScene,
|
||||
};
|
||||
|
@ -5,7 +5,6 @@
|
||||
*/
|
||||
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
|
||||
import { SeasonService , ArianeService, DataService} from 'app/service';
|
||||
import { NodeData } from 'common/model';
|
||||
@ -68,7 +67,6 @@ export class SeasonEditScene implements OnInit {
|
||||
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private seasonService: SeasonService,
|
||||
private arianeService: ArianeService,
|
||||
private popInService: PopInService,
|
||||
@ -77,7 +75,6 @@ export class SeasonEditScene implements OnInit {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.arianeService.updateManual(this.route.snapshot.paramMap);
|
||||
this.idSeason = this.arianeService.getSeasonId();
|
||||
let self = this;
|
||||
this.seasonService.get(this.idSeason)
|
||||
|
@ -5,7 +5,6 @@
|
||||
*/
|
||||
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
|
||||
import { SeasonService, DataService, SeriesService, ArianeService } from 'app/service';
|
||||
|
||||
@ -25,7 +24,6 @@ export class SeasonScene implements OnInit {
|
||||
videosError = '';
|
||||
videos = [];
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private seasonService: SeasonService,
|
||||
private seriesService: SeriesService,
|
||||
private arianeService: ArianeService,
|
||||
@ -34,8 +32,6 @@ export class SeasonScene implements OnInit {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
console.log('ngOnInit(SeasonComponent)');
|
||||
this.arianeService.updateManual(this.route.snapshot.paramMap);
|
||||
this.idSeason = this.arianeService.getSeasonId();
|
||||
|
||||
let self = this;
|
||||
|
@ -5,7 +5,6 @@
|
||||
*/
|
||||
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
|
||||
import { SeriesService, DataService, TypeService, ArianeService } from 'app/service';
|
||||
import { UploadProgress } from 'common/popin/upload-progress/upload-progress';
|
||||
@ -74,8 +73,7 @@ export class SeriesEditScene implements OnInit {
|
||||
}
|
||||
|
||||
|
||||
constructor(private route: ActivatedRoute,
|
||||
private dataService: DataService,
|
||||
constructor(private dataService: DataService,
|
||||
private typeService: TypeService,
|
||||
private seriesService: SeriesService,
|
||||
private arianeService: ArianeService,
|
||||
@ -84,7 +82,6 @@ export class SeriesEditScene implements OnInit {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.arianeService.updateManual(this.route.snapshot.paramMap);
|
||||
this.idSeries = this.arianeService.getSeriesId();
|
||||
let self = this;
|
||||
this.listType = [ { value: null, label: '---' } ];
|
||||
|
@ -5,7 +5,6 @@
|
||||
*/
|
||||
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
|
||||
import { SeriesService, DataService, ArianeService } from 'app/service';
|
||||
import { NodeData } from 'common/model';
|
||||
@ -27,7 +26,6 @@ export class SeriesScene implements OnInit {
|
||||
videosError: string = '';
|
||||
videos: Array<any> = [];
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private seriesService: SeriesService,
|
||||
private arianeService: ArianeService,
|
||||
private dataService: DataService) {
|
||||
@ -35,7 +33,6 @@ export class SeriesScene implements OnInit {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.arianeService.updateManual(this.route.snapshot.paramMap);
|
||||
// this.idUniverse = parseInt(this.route.snapshot.paramMap.get('universId'));
|
||||
// this.idType = parseInt(this.route.snapshot.paramMap.get('typeId'));
|
||||
this.idSeries = this.arianeService.getSeriesId();
|
||||
|
@ -6,7 +6,6 @@
|
||||
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { ArianeService, DataService } from 'app/service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-settings',
|
||||
@ -17,13 +16,11 @@ export class SettingsScene implements OnInit {
|
||||
page = '';
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private arianeService: ArianeService) {
|
||||
private route: ActivatedRoute) {
|
||||
// nothing to do.
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.arianeService.updateManual(this.route.snapshot.paramMap);
|
||||
const page = this.route.snapshot.paramMap.get('page');
|
||||
if (page == null) {
|
||||
this.page = undefined;
|
||||
|
@ -26,7 +26,6 @@ export class TypeScene implements OnInit {
|
||||
videosError = '';
|
||||
videos = [];
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private typeService: TypeService,
|
||||
private arianeService: ArianeService,
|
||||
private dateService: DataService) {
|
||||
@ -42,7 +41,6 @@ export class TypeScene implements OnInit {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.arianeService.updateManual(this.route.snapshot.paramMap);
|
||||
this.typeId = this.arianeService.getTypeId();
|
||||
let self = this;
|
||||
console.log(`get type global id: ${ this.typeId}`);
|
||||
|
@ -1,8 +0,0 @@
|
||||
<div class="generic-page">
|
||||
<div class="fill-all colomn_mutiple">
|
||||
<div *ngFor="let data of videos" class="item item-video" (click)="onSelectVideo($event, data)" (auxclick)="onSelectVideo($event, data)">
|
||||
<app-element-video [element]="data"></app-element-video>
|
||||
</div>
|
||||
<div class="clear"></div>
|
||||
</div>
|
||||
</div>
|
@ -1,62 +0,0 @@
|
||||
.fill-all{
|
||||
width:100%;
|
||||
height:100%;
|
||||
margin:0;
|
||||
padding:0;
|
||||
border:0;
|
||||
background-color:#0F0;
|
||||
}
|
||||
|
||||
.item {
|
||||
font-size: 20px;
|
||||
height: 21%;
|
||||
width: 23%;
|
||||
margin: 1%;
|
||||
padding: 0;
|
||||
overflow: hidden;
|
||||
//box-shadow: 0 1px 1.5px 0 rgba(0,0,0,.12),0 1px 1px 0 rgba(0,0,0,.24);
|
||||
box-shadow: 0px 2px 4px 0 rgba(0, 0, 0, 0.6);
|
||||
line-height: normal;
|
||||
border: none;
|
||||
font-family: "Roboto","Helvetica","Arial",sans-serif;
|
||||
font-weight: 500;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0;
|
||||
will-change: box-shadow;
|
||||
outline: none;
|
||||
cursor: pointer;
|
||||
text-decoration: none;
|
||||
text-align: center;
|
||||
vertical-align: middle;
|
||||
transition-duration: 0.4s;
|
||||
float:left;
|
||||
display:block;
|
||||
|
||||
h1 {
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
background-color: #F00;
|
||||
}
|
||||
|
||||
.material-icons {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.material-icons {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: ~"translate(-12px,-12px)";
|
||||
line-height: 24px;
|
||||
width: 24px;
|
||||
}
|
||||
}
|
||||
|
||||
.item-video {
|
||||
&:hover {
|
||||
background-color: #0F0;
|
||||
}
|
||||
}
|
||||
|
@ -1,59 +0,0 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2018, Edouard DUPIN, all right reserved
|
||||
* @license PROPRIETARY (see license file)
|
||||
*/
|
||||
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { Router, ActivatedRoute } from '@angular/router';
|
||||
|
||||
import { ArianeService } from 'app/service/ariane';
|
||||
import { environment } from 'environments/environment';
|
||||
|
||||
@Component({
|
||||
selector: 'app-universe',
|
||||
templateUrl: './universe.html',
|
||||
styleUrls: [ './universe.less' ]
|
||||
})
|
||||
|
||||
export class UniverseScene implements OnInit {
|
||||
universeId = -1;
|
||||
videosError = '';
|
||||
videos = [];
|
||||
constructor(private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private arianeService: ArianeService) {
|
||||
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.arianeService.updateManual(this.route.snapshot.paramMap);
|
||||
this.universeId = this.arianeService.getUniverseId();
|
||||
console.log(`get parameter id: ${ this.universeId}`);
|
||||
|
||||
/*
|
||||
let self = this;
|
||||
this.universeService.getVideo(this.universId)
|
||||
.then(function(response) {
|
||||
self.videosError = "";
|
||||
self.videos = response
|
||||
}).catch(function(response) {
|
||||
self.videosError = "Can not get the List of video without season";
|
||||
self.videos = []
|
||||
});
|
||||
*/
|
||||
}
|
||||
|
||||
onSelectVideo(event: any, idSelected: number):void {
|
||||
if(event.which === 2) {
|
||||
if(environment.frontBaseUrl === undefined || environment.frontBaseUrl === null || environment.frontBaseUrl === '') {
|
||||
window.open(`/video/${ idSelected}`);
|
||||
} else {
|
||||
window.open(`/${ environment.frontBaseUrl }/video/${ idSelected}`);
|
||||
}
|
||||
} else {
|
||||
this.router.navigate([ `video/${ idSelected}` ]);
|
||||
this.arianeService.setVideo(idSelected);
|
||||
}
|
||||
}
|
||||
}
|
@ -56,16 +56,6 @@
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="left-colomn">Universe:</td>
|
||||
<td class="right-colomn">
|
||||
<input type="text"
|
||||
placeholder="Universe of the Media"
|
||||
[value]="globalUniverse"
|
||||
(input)="onUniverse($event.target.value)"
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="left-colomn">Series:</td>
|
||||
<td class="right-colomn">
|
||||
|
@ -44,9 +44,6 @@
|
||||
border: 0px;
|
||||
}
|
||||
}
|
||||
.tool-colomn {
|
||||
|
||||
}
|
||||
}
|
||||
.error {
|
||||
border-color: rgba(200,0,0,1.0);
|
||||
|
@ -7,7 +7,7 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
|
||||
import { TypeService, UniverseService, SeriesService, VideoService, ArianeService, SeasonService } from 'app/service';
|
||||
import { TypeService, SeriesService, VideoService, ArianeService, SeasonService } from 'app/service';
|
||||
import { UploadProgress } from 'common/popin/upload-progress/upload-progress';
|
||||
import { PopInService } from 'common/service';
|
||||
|
||||
@ -24,7 +24,6 @@ export class FileParsedElement {
|
||||
public episodeDetected: boolean = false;
|
||||
constructor(
|
||||
public file: File,
|
||||
public universe: string,
|
||||
public series: string,
|
||||
public season: number,
|
||||
public episode: number,
|
||||
@ -65,9 +64,6 @@ export class UploadScene implements OnInit {
|
||||
listType: ElementList[] = [
|
||||
{ value: null, label: '---' },
|
||||
];
|
||||
listUniverse: ElementList[] = [
|
||||
{ value: null, label: '---' },
|
||||
];
|
||||
listSeries: ElementList[] = [
|
||||
{ value: null, label: '---' },
|
||||
];
|
||||
@ -95,16 +91,12 @@ export class UploadScene implements OnInit {
|
||||
listSeason: ElementList[] = [
|
||||
{ value: null, label: '---' },
|
||||
];
|
||||
globalUniverse: string = '';
|
||||
globalSeries: string = '';
|
||||
globalSeason: number = null;
|
||||
constructor(private route: ActivatedRoute,
|
||||
private typeService: TypeService,
|
||||
private universeService: UniverseService,
|
||||
constructor(private typeService: TypeService,
|
||||
private seriesService: SeriesService,
|
||||
private seasonService: SeasonService,
|
||||
private videoService: VideoService,
|
||||
private arianeService: ArianeService,
|
||||
private popInService: PopInService) {
|
||||
// nothing to do.
|
||||
}
|
||||
@ -127,20 +119,10 @@ export class UploadScene implements OnInit {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.arianeService.updateManual(this.route.snapshot.paramMap);
|
||||
let self = this;
|
||||
this.listType = [ { value: null, label: '---' } ];
|
||||
this.listUniverse = [ { value: null, label: '---' } ];
|
||||
this.listSeries = [ { value: null, label: '---' } ];
|
||||
this.listSeason = [ { value: null, label: '---' } ];
|
||||
this.universeService.getData()
|
||||
.then((response2) => {
|
||||
for(let iii = 0; iii < response2.length; iii++) {
|
||||
self.listUniverse.push({ value: response2[iii].id, label: response2[iii].name });
|
||||
}
|
||||
}).catch((response2) => {
|
||||
console.log(`get response22 : ${ JSON.stringify(response2, null, 2)}`);
|
||||
});
|
||||
this.typeService.getData()
|
||||
.then((response2) => {
|
||||
for(let iii = 0; iii < response2.length; iii++) {
|
||||
@ -216,11 +198,6 @@ export class UploadScene implements OnInit {
|
||||
this.updateNeedSend();
|
||||
}
|
||||
|
||||
onUniverse(value: any): void {
|
||||
this.globalUniverse = value;
|
||||
this.updateNeedSend();
|
||||
}
|
||||
|
||||
onEpisode(data: FileParsedElement, value: any): void {
|
||||
data.episode = value;
|
||||
// console.log("change episode ID: " + value + " ==> " + this.parseEpisode.toString());
|
||||
@ -253,7 +230,6 @@ export class UploadScene implements OnInit {
|
||||
|
||||
|
||||
clearData() {
|
||||
this.globalUniverse = '';
|
||||
this.globalSeries = '';
|
||||
this.globalSeason = null;
|
||||
this.parsedElement = [];
|
||||
@ -269,7 +245,6 @@ export class UploadScene implements OnInit {
|
||||
|
||||
addFileWithMetaData(file: File) {
|
||||
// parsedElement: FileParsedElement[] = [];
|
||||
let universe: string = null;
|
||||
let series: string = null;
|
||||
let season: number | null = null;
|
||||
let episode: number | null = null;
|
||||
@ -311,13 +286,7 @@ export class UploadScene implements OnInit {
|
||||
}
|
||||
}
|
||||
if(find === false) {
|
||||
if(season === null && episode === null) {
|
||||
if(universe === '') {
|
||||
universe = element;
|
||||
} else {
|
||||
universe = `${universe }-${ element}`;
|
||||
}
|
||||
} else if(title === '') {
|
||||
if(title === '') {
|
||||
title = element;
|
||||
} else {
|
||||
title = `${title }-${ element}`;
|
||||
@ -335,7 +304,7 @@ export class UploadScene implements OnInit {
|
||||
}
|
||||
// remove extention
|
||||
title = title.replace(new RegExp('\\.(mkv|MKV|Mkv|webm|WEBM|Webm|mp4)'), '');
|
||||
let tmp = new FileParsedElement(file, universe, series, season, episode, title);
|
||||
let tmp = new FileParsedElement(file, series, season, episode, title);
|
||||
console.log(`==>${ JSON.stringify(tmp)}`);
|
||||
// add it in the list.
|
||||
this.parsedElement.push(tmp);
|
||||
@ -355,17 +324,6 @@ export class UploadScene implements OnInit {
|
||||
this.updateNeedSend();
|
||||
return;
|
||||
}
|
||||
// we verify fith the first value to remove all unknown ...
|
||||
// clean different univers:
|
||||
for(let iii = 1; iii < this.parsedElement.length; iii++) {
|
||||
console.log(`check universe [${ iii + 1 }/${ this.parsedElement.length }] '${ this.parsedElement[0].universe } !== ${ this.parsedElement[iii].universe }'`);
|
||||
if(this.parsedElement[0].universe !== this.parsedElement[iii].universe) {
|
||||
this.parsedFailedElement.push(new FileFailParsedElement(this.parsedElement[iii].file, 'Remove from list due to wrong universe value'));
|
||||
console.log(`Remove from list (!= universe) : [${ iii + 1 }/${ this.parsedElement.length }] '${ this.parsedElement[iii].file.name }'`);
|
||||
this.parsedElement.splice(iii, 1);
|
||||
iii--;
|
||||
}
|
||||
}
|
||||
// clean different series:
|
||||
for(let iii = 1; iii < this.parsedElement.length; iii++) {
|
||||
console.log(`check series [${ iii + 1 }/${ this.parsedElement.length }] '${ this.parsedElement[0].series } !== ${ this.parsedElement[iii].series }'`);
|
||||
@ -387,7 +345,6 @@ export class UploadScene implements OnInit {
|
||||
}
|
||||
}
|
||||
console.log(`check : ${JSON.stringify(this.parsedElement[0])}`)
|
||||
this.globalUniverse = this.parsedElement[0].universe ?? '';
|
||||
this.globalSeries = this.parsedElement[0].series ?? '';
|
||||
this.globalSeason = this.parsedElement[0].season ?? null;
|
||||
|
||||
@ -442,10 +399,6 @@ export class UploadScene implements OnInit {
|
||||
let self = this;
|
||||
|
||||
self.upload.labelMediaTitle = '';
|
||||
// add universe
|
||||
if(self.globalUniverse !== null) {
|
||||
self.upload.labelMediaTitle = self.upload.labelMediaTitle + self.globalUniverse;
|
||||
}
|
||||
// add series
|
||||
if(self.globalSeries !== null) {
|
||||
if(self.upload.labelMediaTitle.length !== 0) {
|
||||
@ -474,7 +427,6 @@ export class UploadScene implements OnInit {
|
||||
self.upload.labelMediaTitle = `[${ id + 1 }/${ total }]${ self.upload.labelMediaTitle }${eleemnent.title}`;
|
||||
|
||||
self.videoService.uploadFile(eleemnent.file,
|
||||
self.globalUniverse,
|
||||
self.globalSeries,
|
||||
self.seriesId,
|
||||
self.globalSeason,
|
||||
@ -609,10 +561,6 @@ export class UploadScene implements OnInit {
|
||||
console.log(`GET event: ${ event}`);
|
||||
this.popInService.close('popin-new-type');
|
||||
}
|
||||
eventPopUpUniverse(event: string): void {
|
||||
console.log(`GET event: ${ event}`);
|
||||
this.popInService.close('popin-new-universe');
|
||||
}
|
||||
|
||||
newSeason(): void {
|
||||
console.log('Request new Season...');
|
||||
@ -626,8 +574,4 @@ export class UploadScene implements OnInit {
|
||||
console.log('Request new Type...');
|
||||
this.popInService.open('popin-create-type');
|
||||
}
|
||||
newUniverse() {
|
||||
console.log('Request new Universe...');
|
||||
this.popInService.open('popin-new-universe');
|
||||
}
|
||||
}
|
||||
|
@ -78,22 +78,6 @@
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="request_raw">
|
||||
<div class="label">
|
||||
Universe:
|
||||
</div>
|
||||
<div class="input">
|
||||
<select [ngModel]="data.universeId"
|
||||
(ngModelChange)="onChangeUniverse($event)">
|
||||
<option *ngFor="let element of listUniverse" [ngValue]="element.value">{{element.label}}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="input_add">
|
||||
<button class="button color-button-normal color-shadow-black" (click)="newUniverse()" type="submit">
|
||||
<i class="material-icons">add_circle_outline</i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="request_raw">
|
||||
<div class="label">
|
||||
Series:
|
||||
@ -244,16 +228,3 @@
|
||||
</p>
|
||||
</app-popin>
|
||||
|
||||
|
||||
<app-popin id="popin-new-universe"
|
||||
popSize="big"
|
||||
popTitle="Create a new universe"
|
||||
closeTopRight="true"
|
||||
closeTitle="Cancel"
|
||||
validateTitle="Create"
|
||||
(callback)="eventPopUpUniverse($event[0])">
|
||||
<p>
|
||||
Name: <!-- <input type="text" [(ngModel)]="bodyText" /> -->
|
||||
</p>
|
||||
</app-popin>
|
||||
|
||||
|
@ -8,7 +8,7 @@ import { Component, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
|
||||
|
||||
import { DataService, TypeService, UniverseService, SeriesService, VideoService, ArianeService } from 'app/service';
|
||||
import { DataService, TypeService, SeriesService, VideoService, ArianeService } from 'app/service';
|
||||
import { UploadProgress } from 'common/popin/upload-progress/upload-progress';
|
||||
import { NodeData } from 'common/model';
|
||||
import { PopInService } from 'common/service';
|
||||
@ -24,7 +24,6 @@ class DataToSend {
|
||||
name:string = '';
|
||||
description:string = '';
|
||||
episode?:number;
|
||||
universeId:number = null;
|
||||
seriesId:number = null;
|
||||
seasonId:number = null;
|
||||
dataId:number = -1;
|
||||
@ -37,7 +36,6 @@ class DataToSend {
|
||||
tmp.name = this.name;
|
||||
tmp.description = this.description;
|
||||
tmp.episode = this.episode;
|
||||
tmp.universeId = this.universeId;
|
||||
tmp.seriesId = this.seriesId;
|
||||
tmp.seasonId = this.seasonId;
|
||||
tmp.dataId = this.dataId;
|
||||
@ -113,7 +111,6 @@ export class VideoEditScene implements OnInit {
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private typeService: TypeService,
|
||||
private universeService: UniverseService,
|
||||
private seriesService: SeriesService,
|
||||
private videoService: VideoService,
|
||||
private arianeService: ArianeService,
|
||||
@ -139,9 +136,6 @@ export class VideoEditScene implements OnInit {
|
||||
if(this.data.typeId !== this.dataOri.typeId) {
|
||||
this.needSend = true;
|
||||
}
|
||||
if(this.data.universeId !== this.dataOri.universeId) {
|
||||
this.needSend = true;
|
||||
}
|
||||
if(this.data.seriesId !== this.dataOri.seriesId) {
|
||||
this.needSend = true;
|
||||
}
|
||||
@ -167,21 +161,12 @@ export class VideoEditScene implements OnInit {
|
||||
}
|
||||
}
|
||||
ngOnInit() {
|
||||
this.arianeService.updateManual(this.route.snapshot.paramMap);
|
||||
this.idVideo = this.arianeService.getVideoId();
|
||||
let self = this;
|
||||
this.listType = [ { value: null, label: '---' } ];
|
||||
this.listUniverse = [ { value: null, label: '---' } ];
|
||||
this.listSeries = [ { value: null, label: '---' } ];
|
||||
this.listSeason = [ { value: null, label: '---' } ];
|
||||
this.universeService.getData()
|
||||
.then((response2) => {
|
||||
for(let iii = 0; iii < response2.length; iii++) {
|
||||
self.listUniverse.push({ value: response2[iii].id, label: response2[iii].name });
|
||||
}
|
||||
}).catch((response2) => {
|
||||
console.log(`get response22 : ${ JSON.stringify(response2, null, 2)}`);
|
||||
});
|
||||
this.typeService.getData()
|
||||
.then((response2) => {
|
||||
for(let iii = 0; iii < response2.length; iii++) {
|
||||
@ -206,10 +191,6 @@ export class VideoEditScene implements OnInit {
|
||||
self.data.name = response.name;
|
||||
self.data.description = response.description;
|
||||
self.data.episode = response.episode;
|
||||
self.data.universeId = response.universeId;
|
||||
if(self.data.universeId === undefined) {
|
||||
self.data.universeId = null;
|
||||
}
|
||||
self.data.dataId = response.dataId;
|
||||
self.data.time = response.time;
|
||||
self.data.generatedName = "????????? TODO ????????? "; // response.generatedName;
|
||||
@ -259,11 +240,6 @@ export class VideoEditScene implements OnInit {
|
||||
}
|
||||
}
|
||||
|
||||
onChangeUniverse(value:any):void {
|
||||
this.data.universeId = value;
|
||||
this.updateNeedSend();
|
||||
}
|
||||
|
||||
onChangeSeries(value:any):void {
|
||||
this.data.seriesId = value;
|
||||
if(this.data.seriesId === undefined) {
|
||||
@ -349,13 +325,6 @@ export class VideoEditScene implements OnInit {
|
||||
data.typeId = this.data.typeId;
|
||||
}
|
||||
}
|
||||
if(this.data.universeId !== this.dataOri.universeId) {
|
||||
if(this.data.universeId === undefined) {
|
||||
data.universeId = null;
|
||||
} else {
|
||||
data.universeId = this.data.universeId;
|
||||
}
|
||||
}
|
||||
if(this.data.seriesId !== this.dataOri.seriesId) {
|
||||
if(this.data.seriesId === undefined) {
|
||||
data.seriesId = null;
|
||||
@ -486,10 +455,6 @@ export class VideoEditScene implements OnInit {
|
||||
console.log(`GET event: ${ event}`);
|
||||
this.popInService.close('popin-new-type');
|
||||
}
|
||||
eventPopUpUniverse(event: string): void {
|
||||
console.log(`GET event: ${ event}`);
|
||||
this.popInService.close('popin-new-universe');
|
||||
}
|
||||
|
||||
newSeason(): void {
|
||||
console.log('Request new Season...');
|
||||
@ -503,10 +468,6 @@ export class VideoEditScene implements OnInit {
|
||||
console.log('Request new Type...');
|
||||
this.popInService.open('popin-create-type');
|
||||
}
|
||||
newUniverse() {
|
||||
console.log('Request new Universe...');
|
||||
this.popInService.open('popin-new-universe');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -73,8 +73,7 @@ export class VideoScene implements OnInit {
|
||||
displayNeedHide:boolean = false;
|
||||
timeLeft: number = 10;
|
||||
interval = null;
|
||||
constructor(private route: ActivatedRoute,
|
||||
private videoService: VideoService,
|
||||
constructor(private videoService: VideoService,
|
||||
private seriesService: SeriesService,
|
||||
private seasonService: SeasonService,
|
||||
private httpService: HttpWrapperService,
|
||||
@ -182,7 +181,6 @@ export class VideoScene implements OnInit {
|
||||
ngOnInit() {
|
||||
let self = this;
|
||||
this.startHideTimer();
|
||||
this.arianeService.updateManual(this.route.snapshot.paramMap);
|
||||
this.idVideo = this.arianeService.getVideoId();
|
||||
this.arianeService.videoChange.subscribe((videoId) => {
|
||||
console.log(`Detect videoId change...${ videoId}`);
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { NodeData } from "common/model";
|
||||
import { isNodeData, NodeData } from "common/model";
|
||||
import { HttpWrapperService, BddService } from "common/service";
|
||||
import { DataInterface, isNullOrUndefined } from "common/utils";
|
||||
import { DataInterface, isArrayOf, isNullOrUndefined, TypeCheck } from "common/utils";
|
||||
|
||||
export class GenericInterfaceModelDB {
|
||||
constructor(
|
||||
@ -10,6 +10,65 @@ export class GenericInterfaceModelDB {
|
||||
// nothing to do ...
|
||||
}
|
||||
|
||||
gets(): Promise<NodeData[]> {
|
||||
let self = this;
|
||||
return new Promise((resolve, reject) => {
|
||||
self.bdd.get(self.serviceName)
|
||||
.then((response: DataInterface) => {
|
||||
let data = response.gets();
|
||||
if(isNullOrUndefined(data)) {
|
||||
reject('Data does not exist in the local BDD');
|
||||
return;
|
||||
}
|
||||
resolve(data);
|
||||
return;
|
||||
}).catch((response) => {
|
||||
reject(response);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
getLike(nameArtist:string):any {
|
||||
let self = this;
|
||||
return new Promise((resolve, reject) => {
|
||||
self.bdd.get(self.serviceName)
|
||||
.then((response:DataInterface) => {
|
||||
let data = response.getNameLike(nameArtist);
|
||||
if(data === null || data === undefined || data.length === 0) {
|
||||
reject('Data does not exist in the local BDD');
|
||||
return;
|
||||
}
|
||||
resolve(data);
|
||||
return;
|
||||
}).catch((response) => {
|
||||
reject(response);
|
||||
});
|
||||
});
|
||||
}
|
||||
getOrder(): Promise<NodeData[]> {
|
||||
let self = this;
|
||||
return new Promise((resolve, reject) => {
|
||||
self.bdd.get(self.serviceName)
|
||||
.then((response: DataInterface) => {
|
||||
let data = response.getsWhere([
|
||||
{
|
||||
check: TypeCheck.NOT_EQUAL,
|
||||
key: 'id',
|
||||
value: [undefined, null],
|
||||
},
|
||||
],
|
||||
[ 'name', 'id' ]);
|
||||
//data = response.gets();
|
||||
if (isArrayOf(data, isNodeData)) {
|
||||
resolve(data);
|
||||
}
|
||||
reject("The model is wrong ...");
|
||||
}).catch((response) => {
|
||||
console.log(`[E] ${ self.constructor.name }: can not retrive BDD values`);
|
||||
reject(response);
|
||||
});
|
||||
});
|
||||
}
|
||||
get(id:number): Promise<NodeData> {
|
||||
let self = this;
|
||||
return new Promise((resolve, reject) => {
|
||||
@ -27,6 +86,26 @@ export class GenericInterfaceModelDB {
|
||||
});
|
||||
});
|
||||
}
|
||||
getAll(ids: number[]): Promise<NodeData[]> {
|
||||
let self = this;
|
||||
return new Promise((resolve, reject) => {
|
||||
self.bdd.get(self.serviceName)
|
||||
.then((response: DataInterface) => {
|
||||
let data = response.getsWhere([
|
||||
{
|
||||
check: TypeCheck.EQUAL,
|
||||
key: 'id',
|
||||
value: ids,
|
||||
},
|
||||
],
|
||||
[ 'name', 'id' ]);
|
||||
resolve(data);
|
||||
return;
|
||||
}).catch((response) => {
|
||||
reject(response);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
getData(): Promise<NodeData[]> {
|
||||
let self = this;
|
||||
@ -42,6 +121,11 @@ export class GenericInterfaceModelDB {
|
||||
});
|
||||
}
|
||||
|
||||
insert(data: any): any {
|
||||
let ret = this.http.postSpecific([this.serviceName], data);
|
||||
return this.bdd.addAfterPost(this.serviceName, ret);
|
||||
|
||||
}
|
||||
put(id:number, data:any):any {
|
||||
let ret = this.http.putSpecific([this.serviceName, id], data);
|
||||
return this.bdd.setAfterPut(this.serviceName, id, ret);
|
||||
|
@ -6,53 +6,71 @@
|
||||
|
||||
import { Injectable, Output, EventEmitter } from '@angular/core';
|
||||
|
||||
import { Router } from '@angular/router';
|
||||
import { NavigationEnd, NavigationError, NavigationStart, Router } from '@angular/router';
|
||||
|
||||
import { TypeService } from './type';
|
||||
import { UniverseService } from './universe';
|
||||
import { SeriesService } from './series';
|
||||
import { SeasonService } from './season';
|
||||
import { VideoService } from './video';
|
||||
import { environment } from 'environments/environment';
|
||||
import { NodeData } from 'common/model';
|
||||
import { isNullOrUndefined, isStringNullOrUndefined, isUndefined } from 'common/utils';
|
||||
|
||||
export class InputOrders {
|
||||
public typeId: number = null;
|
||||
public universeId: number = null;
|
||||
public seriesId: number = null;
|
||||
public seasonId: number = null;
|
||||
public videoId: number = null;
|
||||
public typeId: number = undefined;
|
||||
public seriesId: number = undefined;
|
||||
public seasonId: number = undefined;
|
||||
public videoId: number = undefined;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class ArianeService {
|
||||
public typeId: number = null;
|
||||
public typeName: string = null;
|
||||
public typeId: number = undefined;
|
||||
public typeName: string = undefined;
|
||||
@Output() typeChange: EventEmitter<number> = new EventEmitter();
|
||||
|
||||
public universeId: number = null;
|
||||
public universeName: string = null;
|
||||
@Output() universeChange: EventEmitter<number> = new EventEmitter();
|
||||
|
||||
public seriesId: number = null;
|
||||
public seriesName: string = null;
|
||||
public seriesId: number = undefined;
|
||||
public seriesName: string = undefined;
|
||||
@Output() seriesChange: EventEmitter<number> = new EventEmitter();
|
||||
|
||||
public seasonId: number = null;
|
||||
public seasonName: string = null;
|
||||
public seasonId: number = undefined;
|
||||
public seasonName: string = undefined;
|
||||
@Output() seasonChange: EventEmitter<number> = new EventEmitter();
|
||||
|
||||
public videoId: number = null;
|
||||
public videoName: string = null;
|
||||
public videoId: number = undefined;
|
||||
public videoName: string = undefined;
|
||||
@Output() videoChange: EventEmitter<number> = new EventEmitter();
|
||||
|
||||
public segment: string = "";
|
||||
@Output() segmentChange: EventEmitter<string> = new EventEmitter();
|
||||
|
||||
constructor(private router: Router,
|
||||
private typeService: TypeService,
|
||||
private universeService: UniverseService,
|
||||
private seriesService: SeriesService,
|
||||
private seasonService: SeasonService,
|
||||
private videoService: VideoService) {
|
||||
//console.log('Start ArianeService');
|
||||
let self = this;
|
||||
this.router.events.subscribe((event: any) => {
|
||||
if (event instanceof NavigationStart) {
|
||||
// Show progress spinner or progress bar
|
||||
//console.log('>>>>>>>>>>>>>> Route change detected');
|
||||
}
|
||||
|
||||
if (event instanceof NavigationEnd) {
|
||||
// Hide progress spinner or progress bar
|
||||
//this.currentRoute = event.url;
|
||||
//console.log(`>>>>>>>>>>>> ${event}`);
|
||||
self.updateProperties();
|
||||
}
|
||||
|
||||
if (event instanceof NavigationError) {
|
||||
// Hide progress spinner or progress bar
|
||||
|
||||
// Present error to user
|
||||
//console.log(`<<<<<<<<<<<<< ${event.error}`);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
updateParams(params) {
|
||||
console.log(`sparams ${ params}`);
|
||||
@ -60,72 +78,71 @@ export class ArianeService {
|
||||
if(params.typeId) {
|
||||
this.setType(params.typeId);
|
||||
} else {
|
||||
this.setType(null);
|
||||
this.setType(undefined);
|
||||
}
|
||||
}
|
||||
getCurrrentSegment(): string|undefined {
|
||||
return this.segment;
|
||||
}
|
||||
|
||||
updateManual(params) {
|
||||
let typeId = params.get('typeId');
|
||||
if(typeId === null || typeId === undefined || typeId === 'null' || typeId === 'NULL' || typeId === '') {
|
||||
typeId = null;
|
||||
} else {
|
||||
typeId = parseInt(typeId, 10);
|
||||
getIsParam(params: any, name: string): undefined|number {
|
||||
let valueStr = params.get(name);
|
||||
if(isNullOrUndefined(valueStr) || isStringNullOrUndefined(valueStr)) {
|
||||
return undefined;
|
||||
}
|
||||
console.log(`typeId = ${ typeId } ${ params.get('typeId')}`);
|
||||
return parseInt(valueStr, 10);
|
||||
|
||||
let universeId = params.get('universeId');
|
||||
if(universeId === null || universeId === undefined || universeId === 'null' || universeId === 'NULL' || universeId === '') {
|
||||
universeId = null;
|
||||
} else {
|
||||
universeId = parseInt(universeId, 10);
|
||||
}
|
||||
console.log(`universeId = ${ universeId } ${ params.get('universId')}`);
|
||||
|
||||
let seriesId = params.get('seriesId');
|
||||
if(seriesId === null || seriesId === undefined || seriesId === 'null' || seriesId === 'NULL' || seriesId === '') {
|
||||
seriesId = null;
|
||||
} else {
|
||||
seriesId = parseInt(seriesId, 10);
|
||||
updateProperties() {
|
||||
let elem = this.router.routerState.root;
|
||||
while (!isNullOrUndefined(elem.firstChild)) {
|
||||
elem = elem.firstChild;
|
||||
}
|
||||
console.log(`seriesId = ${ seriesId } ${ params.get('seriesId')}`);
|
||||
//console.log(`!!!!!!!!!!!!!!!!!!!!!!!!!! ${JSON.stringify(elem.snapshot.paramMap)}`);
|
||||
let params = elem.snapshot.paramMap;
|
||||
let segment: string[] = location.pathname.split("/");
|
||||
while (segment.length > 1 && (segment[0] === "" || segment[0] === environment.applName)) {
|
||||
segment = segment.slice(1);
|
||||
}
|
||||
if (segment.length > 0) {
|
||||
if (this.segment !== segment[0]) {
|
||||
this.segment = segment[0];
|
||||
this.segmentChange.emit(this.segment)
|
||||
}
|
||||
} else {
|
||||
if (this.segment !== "") {
|
||||
this.segment = "";
|
||||
this.segmentChange.emit(this.segment)
|
||||
}
|
||||
}
|
||||
console.log(`segment: ${JSON.stringify(this.segment)}`);
|
||||
console.log(`params: ${JSON.stringify(params)}`);
|
||||
|
||||
let seasonId = params.get('seasonId');
|
||||
if(seasonId === null || seasonId === undefined || seasonId === 'null' || seasonId === 'NULL' || seasonId === '') {
|
||||
seasonId = null;
|
||||
} else {
|
||||
seasonId = parseInt(seasonId, 10);
|
||||
}
|
||||
console.log(`seasonId = ${ seasonId } ${ params.get('seasonId')}`);
|
||||
|
||||
let videoId = params.get('videoId');
|
||||
if(videoId === null || videoId === undefined || videoId === 'null' || videoId === 'NULL' || videoId === '') {
|
||||
videoId = null;
|
||||
} else {
|
||||
videoId = parseInt(videoId, 10);
|
||||
}
|
||||
console.log(`videoId = ${ videoId } ${ params.get('videoId')}`);
|
||||
|
||||
let typeId = this.getIsParam(params, 'typeId');
|
||||
let seriesId = this.getIsParam(params, 'seriesId');
|
||||
let seasonId = this.getIsParam(params, 'seasonId');
|
||||
let videoId = this.getIsParam(params, 'videoId');
|
||||
|
||||
this.setType(typeId);
|
||||
this.setUniverse(universeId);
|
||||
this.setSeries(seriesId);
|
||||
this.setSeason(seasonId);
|
||||
this.setVideo(videoId);
|
||||
}
|
||||
reset():void {
|
||||
this.typeId = null;
|
||||
this.typeName = null;
|
||||
this.typeId = undefined;
|
||||
this.typeName = undefined;
|
||||
this.typeChange.emit(this.typeId);
|
||||
this.universeId = null;
|
||||
this.universeName = null;
|
||||
this.universeChange.emit(this.universeId);
|
||||
this.seriesId = null;
|
||||
this.seriesName = null;
|
||||
this.seriesId = undefined;
|
||||
this.seriesName = undefined;
|
||||
this.seriesChange.emit(this.seriesId);
|
||||
this.seasonId = null;
|
||||
this.seasonName = null;
|
||||
this.seasonId = undefined;
|
||||
this.seasonName = undefined;
|
||||
this.seasonChange.emit(this.seasonId);
|
||||
this.videoId = null;
|
||||
this.videoName = null;
|
||||
this.videoId = undefined;
|
||||
this.videoName = undefined;
|
||||
this.videoChange.emit(this.videoId);
|
||||
}
|
||||
|
||||
@ -136,10 +153,6 @@ export class ArianeService {
|
||||
if (out.typeId === 0){
|
||||
out.typeId = undefined;
|
||||
}
|
||||
out.universeId = parseInt(this.route.snapshot.paramMap.get('universId'));
|
||||
if (out.universeId === 0){
|
||||
out.universeId = undefined;
|
||||
}
|
||||
out.seriesId = parseInt(this.route.snapshot.paramMap.get('seriesId'));
|
||||
if (out.seriesId === 0){
|
||||
out.seriesId = undefined;
|
||||
@ -166,12 +179,9 @@ export class ArianeService {
|
||||
if(this.typeId === id) {
|
||||
return;
|
||||
}
|
||||
if(id === undefined) {
|
||||
return;
|
||||
}
|
||||
this.typeId = id;
|
||||
this.typeName = '??--??';
|
||||
if(this.typeId === null) {
|
||||
if(isUndefined(this.typeId)) {
|
||||
this.typeChange.emit(this.typeId);
|
||||
return;
|
||||
}
|
||||
@ -184,52 +194,20 @@ export class ArianeService {
|
||||
self.typeChange.emit(self.typeId);
|
||||
});
|
||||
}
|
||||
getTypeId():number {
|
||||
getTypeId():number|undefined {
|
||||
return this.typeId;
|
||||
}
|
||||
getTypeName():string {
|
||||
getTypeName():string|undefined {
|
||||
return this.typeName;
|
||||
}
|
||||
|
||||
setUniverse(id:number) {
|
||||
if(this.universeId === id) {
|
||||
return;
|
||||
}
|
||||
if(id === undefined) {
|
||||
return;
|
||||
}
|
||||
this.universeId = id;
|
||||
this.universeName = '??--??';
|
||||
if(this.universeId === null) {
|
||||
this.universeChange.emit(this.universeId);
|
||||
return;
|
||||
}
|
||||
let self = this;
|
||||
this.universeService.get(id)
|
||||
.then((response: NodeData) => {
|
||||
self.universeName = response.name;
|
||||
self.universeChange.emit(self.universeId);
|
||||
}).catch((response) => {
|
||||
self.universeChange.emit(self.universeId);
|
||||
});
|
||||
}
|
||||
getUniverseId():number {
|
||||
return this.universeId;
|
||||
}
|
||||
getUniverseName():string {
|
||||
return this.universeName;
|
||||
}
|
||||
|
||||
setSeries(id:number):void {
|
||||
setSeries(id:number|undefined):void {
|
||||
if(this.seriesId === id) {
|
||||
return;
|
||||
}
|
||||
if(id === undefined) {
|
||||
return;
|
||||
}
|
||||
this.seriesId = id;
|
||||
this.seriesName = '??--??';
|
||||
if(this.seriesId === null) {
|
||||
if(isUndefined(this.seriesId)) {
|
||||
this.seriesChange.emit(this.seriesId);
|
||||
return;
|
||||
}
|
||||
@ -249,16 +227,13 @@ export class ArianeService {
|
||||
return this.seriesName;
|
||||
}
|
||||
|
||||
setSeason(id:number):void {
|
||||
setSeason(id:number|undefined):void {
|
||||
if(this.seasonId === id) {
|
||||
return;
|
||||
}
|
||||
if(id === undefined) {
|
||||
return;
|
||||
}
|
||||
this.seasonId = id;
|
||||
this.seasonName = '??--??';
|
||||
if(this.seasonId === null) {
|
||||
if(isUndefined(this.seasonId)) {
|
||||
this.seasonChange.emit(this.seasonId);
|
||||
return;
|
||||
}
|
||||
@ -279,16 +254,13 @@ export class ArianeService {
|
||||
return this.seasonName;
|
||||
}
|
||||
|
||||
setVideo(id:number):void {
|
||||
setVideo(id:number|undefined):void {
|
||||
if(this.videoId === id) {
|
||||
return;
|
||||
}
|
||||
if(id === undefined) {
|
||||
return;
|
||||
}
|
||||
this.videoId = id;
|
||||
this.videoName = '??--??';
|
||||
if(this.videoId === null) {
|
||||
if(isUndefined(this.videoId)) {
|
||||
this.videoChange.emit(this.videoId);
|
||||
return;
|
||||
}
|
||||
@ -313,7 +285,6 @@ export class ArianeService {
|
||||
/**
|
||||
* Generic navigation on the browser.
|
||||
* @param destination - new destination url
|
||||
* @param universeId - univers ID
|
||||
* @param typeId - type IF
|
||||
* @param seriesId - series real ID
|
||||
* @param seasonId - season ID
|
||||
@ -323,16 +294,15 @@ export class ArianeService {
|
||||
*/
|
||||
genericNavigate(
|
||||
destination:string,
|
||||
universeId:number,
|
||||
typeId:number,
|
||||
seriesId:number,
|
||||
seasonId:number,
|
||||
videoId:number,
|
||||
newWindows:boolean = false,
|
||||
replaceCurrentPage: boolean = false): void {
|
||||
let addressOffset = `${destination }/${ universeId }/${ typeId }/${ seriesId }/${ seasonId }/${ videoId}`;
|
||||
let addressOffset = `${ destination }/${ typeId }/${ seriesId }/${ seasonId }/${ videoId }`;
|
||||
if(newWindows === true) {
|
||||
if(environment.frontBaseUrl === undefined || environment.frontBaseUrl === null || environment.frontBaseUrl === '') {
|
||||
if(!isNullOrUndefined(environment.frontBaseUrl) || environment.frontBaseUrl === '') {
|
||||
window.open(`/${ addressOffset}`);
|
||||
} else {
|
||||
window.open(`/${ environment.frontBaseUrl }/${ addressOffset}`);
|
||||
@ -342,50 +312,44 @@ export class ArianeService {
|
||||
}
|
||||
}
|
||||
|
||||
navigateUniverse(id:number, newWindows:boolean):void {
|
||||
this.genericNavigate('universe', id, this.typeId, null, null, null, newWindows);
|
||||
}
|
||||
navigateUniverseEdit(id:number, newWindows:boolean):void {
|
||||
this.genericNavigate('universe-edit', id, this.typeId, null, null, null, newWindows);
|
||||
}
|
||||
navigateType(id:number, newWindows:boolean, ctrl:boolean = false):void {
|
||||
if(ctrl === true) {
|
||||
this.navigateTypeEdit(id, newWindows);
|
||||
return;
|
||||
}
|
||||
this.genericNavigate('type', this.universeId, id, null, null, null, newWindows);
|
||||
this.genericNavigate('type', id, null, null, null, newWindows);
|
||||
}
|
||||
navigateTypeEdit(id:number, newWindows:boolean):void {
|
||||
this.genericNavigate('type-edit', this.universeId, id, null, null, null, newWindows);
|
||||
this.genericNavigate('type-edit', id, null, null, null, newWindows);
|
||||
}
|
||||
navigateSeries(id:number, newWindows:boolean, ctrl:boolean = false):void {
|
||||
if(ctrl === true) {
|
||||
this.navigateSeriesEdit(id, newWindows);
|
||||
return;
|
||||
}
|
||||
this.genericNavigate('series', this.universeId, this.typeId, id, null, null, newWindows);
|
||||
this.genericNavigate('series', this.typeId, id, null, null, newWindows);
|
||||
}
|
||||
navigateSeriesEdit(id:number, newWindows:boolean):void {
|
||||
this.genericNavigate('series-edit', this.universeId, this.typeId, id, null, null, newWindows);
|
||||
this.genericNavigate('series-edit', this.typeId, id, null, null, newWindows);
|
||||
}
|
||||
navigateSeason(id:number, newWindows:boolean, ctrl:boolean = false, replaceCurrentPage: boolean = false):void {
|
||||
if(ctrl === true) {
|
||||
this.navigateSeasonEdit(id, newWindows);
|
||||
return;
|
||||
}
|
||||
this.genericNavigate('season', this.universeId, this.typeId, this.seriesId, id, null, newWindows, replaceCurrentPage);
|
||||
this.genericNavigate('season', this.typeId, this.seriesId, id, null, newWindows, replaceCurrentPage);
|
||||
}
|
||||
navigateSeasonEdit(id:number, newWindows:boolean):void {
|
||||
this.genericNavigate('season-edit', this.universeId, this.typeId, this.seriesId, id, null, newWindows);
|
||||
this.genericNavigate('season-edit', this.typeId, this.seriesId, id, null, newWindows);
|
||||
}
|
||||
navigateVideo(id:number, newWindows:boolean, ctrl:boolean = false):void {
|
||||
if(ctrl === true) {
|
||||
this.navigateVideoEdit(id, newWindows);
|
||||
return;
|
||||
}
|
||||
this.genericNavigate('video', this.universeId, this.typeId, this.seriesId, this.seasonId, id, newWindows);
|
||||
this.genericNavigate('video', this.typeId, this.seriesId, this.seasonId, id, newWindows);
|
||||
}
|
||||
navigateVideoEdit(id:number, newWindows:boolean):void {
|
||||
this.genericNavigate('video-edit', this.universeId, this.typeId, this.seriesId, this.seasonId, id, newWindows);
|
||||
this.genericNavigate('video-edit', this.typeId, this.seriesId, this.seasonId, id, newWindows);
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ import { DataService } from "./data";
|
||||
import { SeasonService } from "./season";
|
||||
import { SeriesService } from "./series";
|
||||
import { TypeService } from "./type";
|
||||
import { UniverseService } from "./universe";
|
||||
import { VideoService } from "./video";
|
||||
|
||||
|
||||
@ -14,7 +13,6 @@ export {
|
||||
SeasonService,
|
||||
SeriesService,
|
||||
TypeService,
|
||||
UniverseService,
|
||||
VideoService,
|
||||
};
|
||||
|
||||
|
@ -1,29 +0,0 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2018, Edouard DUPIN, all right reserved
|
||||
* @license PROPRIETARY (see license file)
|
||||
*/
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
import { HttpWrapperService, BddService } from 'common/service';
|
||||
import { GenericInterfaceModelDB } from './GenericInterfaceModelDB';
|
||||
|
||||
@Injectable()
|
||||
export class UniverseService extends GenericInterfaceModelDB {
|
||||
|
||||
constructor(http: HttpWrapperService,
|
||||
bdd: BddService) {
|
||||
super('universe', http, bdd);
|
||||
}
|
||||
|
||||
getSubSeries(id:number, select:Array<string> = []):any {
|
||||
// this.checkLocalBdd();
|
||||
}
|
||||
|
||||
getSubVideo(id:number, select:Array<string> = []):any {
|
||||
// this.checkLocalBdd();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -50,7 +50,6 @@ export class VideoService extends GenericInterfaceModelDB {
|
||||
}
|
||||
|
||||
uploadFile(file:File,
|
||||
universe?:string,
|
||||
series?:string,
|
||||
seriesId?:number,
|
||||
season?:number,
|
||||
@ -62,7 +61,6 @@ export class VideoService extends GenericInterfaceModelDB {
|
||||
formData.append('fileName', file.name);
|
||||
// set the file at hte begining it will permit to abort the transmission
|
||||
formData.append('file', file?? null);
|
||||
formData.append('universe', universe?? null);
|
||||
if(seriesId !== null) {
|
||||
formData.append('seriesId', seriesId.toString());
|
||||
} else {
|
||||
|
14
front/src/common/component/index.ts
Normal file
14
front/src/common/component/index.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import { ErrorComponent } from "./error/error";
|
||||
import { PopInComponent } from "./popin/popin";
|
||||
import { TopMenuComponent } from "./top-menu/top-menu";
|
||||
import { UploadFileComponent } from "./upload-file/upload-file";
|
||||
|
||||
|
||||
export {
|
||||
PopInComponent,
|
||||
TopMenuComponent,
|
||||
UploadFileComponent,
|
||||
ErrorComponent,
|
||||
};
|
||||
|
||||
|
@ -49,8 +49,9 @@ export class PopInComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
// open popIn
|
||||
open(): void {
|
||||
//console.log(`open pop-in: ${this.id}`);
|
||||
this.displayPopIn = true;
|
||||
// this.element.show();
|
||||
//this.element.show();
|
||||
}
|
||||
// close popin
|
||||
close(): void {
|
||||
|
88
front/src/common/component/top-menu/top-menu.html
Normal file
88
front/src/common/component/top-menu/top-menu.html
Normal file
@ -0,0 +1,88 @@
|
||||
<div class="top">
|
||||
<div id="main-menu" class="main-menu color-menu-background">
|
||||
<div *ngFor="let data of menu">
|
||||
<div class="inert_element"
|
||||
*ngIf="isNotButton(data)"
|
||||
[ngStyle]="{'float': data.position}"
|
||||
[ngClass]="getClassModel(data.model)">
|
||||
<div class="xdesktop" *ngIf="data.icon">
|
||||
<i class="material-icons">{{data.icon}}</i> {{data.title}}
|
||||
</div>
|
||||
<div class="xmobile" *ngIf="data.icon">
|
||||
<i class="material-icons">{{data.icon}}</i>
|
||||
</div>
|
||||
<div class="xdesktop" *ngIf="!data.icon">
|
||||
{{data.title}}
|
||||
</div>
|
||||
</div>
|
||||
<button class="item"
|
||||
*ngIf="!isNotButton(data)"
|
||||
(click)="onGeneric(data, $event)"
|
||||
(auxclick)="onGeneric(data, $event)"
|
||||
[ngStyle]="{'float': data.position}"
|
||||
[ngClass]="getClassModel(data.model)"
|
||||
[disable]="false">
|
||||
<div class="avatar" *ngIf="data.image">
|
||||
<img class="avatar" src="{{data.image}}"/> {{data.title}}
|
||||
</div>
|
||||
<div class="xdesktop" *ngIf="data.icon && !data.image">
|
||||
<i class="material-icons">{{data.icon}}</i> {{data.title}}
|
||||
</div>
|
||||
<div class="xmobile" *ngIf="data.icon && !data.image">
|
||||
<i class="material-icons">{{data.icon}}</i>
|
||||
</div>
|
||||
<div class="xdesktop" *ngIf="!data.icon && !data.image">
|
||||
{{data.title}}
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="fill-all" *ngIf="subMenu" (click)="onOutUserProperty()">
|
||||
<div class="sub-menu color-menu-background"
|
||||
[ngClass]="getClassMenuPosition()">
|
||||
<div *ngFor="let data of subMenu">
|
||||
<div class="inert_element unselectable"
|
||||
*ngIf="isNotButton(data)"
|
||||
[ngStyle]="{'float': data.position}"
|
||||
[ngClass]="getClassModel(data.model)" >
|
||||
<div class="xdesktop"
|
||||
*ngIf="data.icon"
|
||||
[ngStyle]="{'float': data.position}">
|
||||
<i class="material-icons">{{data.icon}}</i> {{data.title}}
|
||||
</div>
|
||||
<div class="xmobile"
|
||||
*ngIf="data.icon"
|
||||
[ngStyle]="{'float': data.position}">
|
||||
<i class="material-icons">{{data.icon}}</i>
|
||||
</div>
|
||||
<div *ngIf="!data.icon"
|
||||
[ngStyle]="{'float': data.position}">
|
||||
{{data.title}}
|
||||
</div>
|
||||
</div>
|
||||
<button class="item"
|
||||
*ngIf="isEnable(data) && !isNotButton(data)"
|
||||
(click)="onGeneric(data, $event)"
|
||||
(auxclick)="onGeneric(data, $event)"
|
||||
[ngStyle]="{'float': data.position}"
|
||||
[ngClass]="getClassModel(data.model)"
|
||||
[disable]="false">
|
||||
<div class="xdesktop"
|
||||
*ngIf="data.icon"
|
||||
[ngStyle]="{'float': data.position}">
|
||||
<i class="material-icons">{{data.icon}}</i> {{data.title}}
|
||||
</div>
|
||||
<div class="xmobile"
|
||||
*ngIf="data.icon"
|
||||
[ngStyle]="{'float': data.position}">
|
||||
<i class="material-icons">{{data.icon}}</i>
|
||||
</div>
|
||||
<div *ngIf="!data.icon"
|
||||
[ngStyle]="{'float': data.position}">
|
||||
{{data.title}}
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
@ -1,4 +1,27 @@
|
||||
|
||||
|
||||
.element-pos-left {
|
||||
z-index: 5;
|
||||
float: left;
|
||||
}
|
||||
.element-pos-right {
|
||||
z-index: 5;
|
||||
float: right;
|
||||
}
|
||||
.element-pos-center {
|
||||
z-index: 5;
|
||||
float: none;
|
||||
}
|
||||
|
||||
.model_happy {
|
||||
color:yellow;
|
||||
}
|
||||
.model_disable {
|
||||
color:rgb(100, 100, 100);
|
||||
}
|
||||
.model_error {
|
||||
color:darkred;
|
||||
}
|
||||
.top {
|
||||
.sub-menu {
|
||||
|
||||
@ -59,18 +82,14 @@
|
||||
}
|
||||
|
||||
}
|
||||
.user-menu {
|
||||
.menu-left {
|
||||
top:75px;
|
||||
left:15px;
|
||||
}
|
||||
.menu-right {
|
||||
top:75px;
|
||||
right:15px;
|
||||
}
|
||||
.edit-menu {
|
||||
top:75px;
|
||||
right:200px;
|
||||
}
|
||||
.edit-menu-mob {
|
||||
top:75px;
|
||||
right:25px;
|
||||
}
|
||||
|
||||
.fill-all {
|
||||
position: absolute;
|
||||
@ -125,6 +144,19 @@
|
||||
visibility: "visible";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
.inert_element {
|
||||
display:block;
|
||||
float: left;
|
||||
line-height: 56px;
|
||||
z-index: 4;
|
||||
margin: 0 3px 0 3px;
|
||||
border: 0;
|
||||
//text-transform: uppercase;
|
||||
font-weight: bold;
|
||||
font-size: 17px;
|
||||
}
|
||||
|
||||
.ariane {
|
||||
@ -138,17 +170,6 @@
|
||||
text-transform: uppercase;
|
||||
font-weight: bold;
|
||||
font-size: 15px;
|
||||
.item_ariane_separator {
|
||||
display:block;
|
||||
float: left;
|
||||
line-height: 56px;
|
||||
z-index: 4;
|
||||
margin: 0 3px 0 3px;
|
||||
border: 0;
|
||||
text-transform: uppercase;
|
||||
font-weight: bold;
|
||||
font-size: 30px;
|
||||
}
|
||||
}
|
||||
|
||||
.material-icons {
|
109
front/src/common/component/top-menu/top-menu.ts
Normal file
109
front/src/common/component/top-menu/top-menu.ts
Normal file
@ -0,0 +1,109 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2018, Edouard DUPIN, all right reserved
|
||||
* @license PROPRIETARY (see license file)
|
||||
*/
|
||||
import { Component, OnInit, Input, EventEmitter, Output } from '@angular/core';
|
||||
|
||||
import { Router } from '@angular/router';
|
||||
import { isNullOrUndefined } from 'common/utils';
|
||||
import { MenuItem } from 'common/model/menu-item';
|
||||
|
||||
|
||||
|
||||
export interface EventOnMenu {
|
||||
menu: MenuItem;
|
||||
newWindows: boolean;
|
||||
ctrl: boolean;
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-top-menu',
|
||||
templateUrl: './top-menu.html',
|
||||
styleUrls: [ './top-menu.less' ]
|
||||
})
|
||||
export class TopMenuComponent implements OnInit {
|
||||
@Input() menu: MenuItem[];
|
||||
subMenu: MenuItem[] = undefined;
|
||||
subMenuPosition: String = undefined;
|
||||
@Output() callback: EventEmitter<EventOnMenu> = new EventEmitter();
|
||||
|
||||
constructor(private router: Router) {
|
||||
|
||||
}
|
||||
|
||||
isNotButton(data: MenuItem) {
|
||||
return isNullOrUndefined(data.navigateTo)
|
||||
&& (isNullOrUndefined(data.callback) || data.callback === false)
|
||||
&& isNullOrUndefined(data.subMenu);
|
||||
}
|
||||
isEnable(data: MenuItem) {
|
||||
if (!isNullOrUndefined(data) && !isNullOrUndefined(data.enable) && data.enable === false) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
getPosition(data: string) : string {
|
||||
return `float: ${data}`;
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
|
||||
}
|
||||
onOutUserProperty(): void {
|
||||
//console.log('onOutUserProperty ==> event...');
|
||||
this.subMenu = undefined;
|
||||
}
|
||||
getClassMenuPosition(): string {
|
||||
if (isNullOrUndefined(this.subMenuPosition)) {
|
||||
return "menu-left";
|
||||
}
|
||||
return 'menu-' + this.subMenuPosition;
|
||||
}
|
||||
getClassModel(data?:string): string {
|
||||
if (isNullOrUndefined(data)) {
|
||||
return "";
|
||||
}
|
||||
return 'model_' + data;
|
||||
}
|
||||
|
||||
onGeneric(data: MenuItem, event: any): void {
|
||||
//console.log(`onGeneric()`);
|
||||
// check if we need to navigate
|
||||
if (!isNullOrUndefined(data.navigateTo)) {
|
||||
// remove in every case the subMenu:
|
||||
this.subMenu = undefined
|
||||
this.subMenuPosition = undefined;
|
||||
this.router.navigate([ data.navigateTo ]);
|
||||
return;
|
||||
}
|
||||
if (!isNullOrUndefined(data.callback) && data.callback === true) {
|
||||
//console.log(`Emit message on ${JSON.stringify(data)}`);
|
||||
this.callback.emit({
|
||||
menu: data,
|
||||
newWindows: event.which === 2,
|
||||
ctrl: event.ctrlKey,
|
||||
});
|
||||
return;
|
||||
}
|
||||
// check if we need to display a submenu
|
||||
if (isNullOrUndefined(data.subMenu)) {
|
||||
//just a toggle mode:
|
||||
data.subMenu = undefined;
|
||||
this.subMenuPosition = undefined;
|
||||
return;
|
||||
}
|
||||
if (this.subMenu === data.subMenu) {
|
||||
//just a toggle mode:
|
||||
this.subMenu = undefined;
|
||||
this.subMenuPosition = undefined;
|
||||
return;
|
||||
}
|
||||
//console.log(`Set Menu: ${JSON.stringify(data.subMenu)}`);
|
||||
// set the requested menu
|
||||
this.subMenu = data.subMenu;
|
||||
this.subMenuPosition = data.position;
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,8 @@
|
||||
import { isMenuItem, isMenuPosition, MenuItem, MenuPosition } from "./menu-item";
|
||||
import { NodeData, isNodeData } from "./node";
|
||||
|
||||
|
||||
export {
|
||||
NodeData, isNodeData,
|
||||
MenuPosition, isMenuPosition, MenuItem, isMenuItem,
|
||||
}
|
71
front/src/common/model/menu-item.ts
Normal file
71
front/src/common/model/menu-item.ts
Normal file
@ -0,0 +1,71 @@
|
||||
import { isObject, isOptionalOf, isString, isNullOrUndefined, isOptionalArrayOf } from "common/utils";
|
||||
|
||||
export enum MenuPosition {
|
||||
LEFT = "left",
|
||||
RIGHT = "right",
|
||||
CENTER = "none",
|
||||
}
|
||||
|
||||
export function isMenuPosition(data: any): data is MenuPosition {
|
||||
return data === "left"
|
||||
|| data === "right"
|
||||
|| data === "none";
|
||||
|
||||
}
|
||||
|
||||
export interface MenuItem {
|
||||
// Position of the menue element
|
||||
position: MenuPosition;
|
||||
// Hover help
|
||||
hover?: string;
|
||||
// Icon of the menue (need to be a meterial-icon name
|
||||
icon?: string;
|
||||
// If we want to display an image instead of an icon
|
||||
image?: string;
|
||||
// Displayed Title
|
||||
title: string;
|
||||
// Jump Link (If undefined: it is considered as text and not a button)
|
||||
model?: string;
|
||||
// Jump Link (If undefined: it is considered as text and not a button)
|
||||
navigateTo?: string;
|
||||
// if it request a callbak with the curent element: (not compatible with the previous)
|
||||
callback?: boolean;
|
||||
// Other data that want to be set by the user
|
||||
otherData?: any;
|
||||
// Enable or not the elemnt
|
||||
enable?: boolean;
|
||||
// Menu model For a subList of elements
|
||||
subMenu?: MenuItem[];
|
||||
};
|
||||
|
||||
|
||||
export function isMenuItem(data: any): data is MenuItem {
|
||||
if (isNullOrUndefined(data)) {
|
||||
return false;
|
||||
}
|
||||
if (!isObject(data)) {
|
||||
return false;
|
||||
}
|
||||
if (!isMenuPosition(data.position)) {
|
||||
return false;
|
||||
}
|
||||
if (!isOptionalOf(data.hover, isString)) {
|
||||
return false;
|
||||
}
|
||||
if (!isOptionalOf(data.icon, isString)) {
|
||||
return false;
|
||||
}
|
||||
if (!isOptionalOf(data.image, isString)) {
|
||||
return false;
|
||||
}
|
||||
if (!isString(data.title)) {
|
||||
return false;
|
||||
}
|
||||
if (!isOptionalOf(data.navigateTo, isString)) {
|
||||
return false;
|
||||
}
|
||||
if (!isOptionalArrayOf(data.subMenu, isMenuItem)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
8
front/src/common/popin/index.ts
Normal file
8
front/src/common/popin/index.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { PopInDeleteConfirm } from "./delete-confirm/delete-confirm";
|
||||
import { PopInUploadProgress } from "./upload-progress/upload-progress";
|
||||
|
||||
|
||||
export {
|
||||
PopInDeleteConfirm,
|
||||
PopInUploadProgress,
|
||||
}
|
@ -86,6 +86,7 @@ export class PopInUploadProgress implements OnInit {
|
||||
}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges) {
|
||||
//console.log(`Upload progress event : ${JSON.stringify(changes)}`);
|
||||
this.progress = Math.trunc(this.mediaUploaded * 100 / this.mediaSize);
|
||||
this.uploadDisplay = this.convertInHuman(this.mediaUploaded);
|
||||
this.sizeDisplay = this.convertInHuman(this.mediaSize);
|
||||
|
6
front/src/common/scene/404/404.html
Normal file
6
front/src/common/scene/404/404.html
Normal file
@ -0,0 +1,6 @@
|
||||
<div class="full-mode">
|
||||
<div class="centered">
|
||||
<div class="error"><label class="unselectable"><i class="material-icons">report</i> 404 Not Found !</label></div>
|
||||
<div class="comment"><label class="unselectable">Unknwn this page.</label></div>
|
||||
</div>
|
||||
</div>
|
50
front/src/common/scene/404/404.less
Normal file
50
front/src/common/scene/404/404.less
Normal file
@ -0,0 +1,50 @@
|
||||
|
||||
.full-mode{
|
||||
width:100%;
|
||||
height:100%;
|
||||
top:0;
|
||||
left:0;
|
||||
margin:0;
|
||||
padding:0;
|
||||
border:0;
|
||||
float:left;
|
||||
display:block;
|
||||
}
|
||||
|
||||
.centered {
|
||||
position:relative;
|
||||
max-width:75%;
|
||||
padding: 16px 32px 16px 32px;
|
||||
|
||||
top: 50%;
|
||||
transform: ~"translate(0, -50%)";
|
||||
font-size: 30px;
|
||||
|
||||
font-weight: 600;
|
||||
text-align: center;
|
||||
line-height: 200%;
|
||||
}
|
||||
|
||||
.error {
|
||||
font-size: 55px;
|
||||
background-size: 45px;
|
||||
/*background-attachment: fixed;*/
|
||||
background-position: 0% 50%;
|
||||
padding: 0 0 0 58px;
|
||||
margin: 17px 0 17px 0;
|
||||
text-shadow:0px 0px 4px #000000;
|
||||
color: rgb(160, 44, 44);
|
||||
i {
|
||||
font-size: 55px;
|
||||
}
|
||||
}
|
||||
|
||||
.comment {
|
||||
background-size: 45px;
|
||||
/*background-attachment: fixed;*/
|
||||
background-position: 0% 50%;
|
||||
padding: 0 0 0 58px;
|
||||
margin: 17px 0 17px 0;
|
||||
text-shadow:0px 0px 4px #07213a;
|
||||
color: white;
|
||||
}
|
16
front/src/common/scene/404/404.ts
Normal file
16
front/src/common/scene/404/404.ts
Normal file
@ -0,0 +1,16 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2018, Edouard DUPIN, all right reserved
|
||||
* @license PROPRIETARY (see license file)
|
||||
*/
|
||||
|
||||
import { Component } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'app-404-not-found',
|
||||
templateUrl: './404.html',
|
||||
styleUrls: [ './404.less' ]
|
||||
})
|
||||
export class NotFound404Scene {
|
||||
constructor() { }
|
||||
}
|
@ -6,7 +6,6 @@
|
||||
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { ArianeService } from 'app/service/ariane';
|
||||
|
||||
@Component({
|
||||
selector: 'app-error-viewer',
|
||||
@ -14,11 +13,10 @@ import { ArianeService } from 'app/service/ariane';
|
||||
styleUrls: [ './error-viewer.less' ]
|
||||
})
|
||||
export class ErrorViewerScene implements OnInit {
|
||||
constructor(private route: ActivatedRoute,
|
||||
private arianeService: ArianeService) { }
|
||||
constructor(private route: ActivatedRoute) { }
|
||||
|
||||
ngOnInit() {
|
||||
this.arianeService.updateManual(this.route.snapshot.paramMap);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
6
front/src/common/scene/forbidden/forbidden.html
Normal file
6
front/src/common/scene/forbidden/forbidden.html
Normal file
@ -0,0 +1,6 @@
|
||||
<div class="full-mode">
|
||||
<div class="centered">
|
||||
<div class="error"><label class="unselectable"><i class="material-icons">gpp_bad</i> 403 Forbidden</label></div>
|
||||
<div class="comment"><label class="unselectable">You don't have permission to access this resource.</label></div>
|
||||
</div>
|
||||
</div>
|
51
front/src/common/scene/forbidden/forbidden.less
Normal file
51
front/src/common/scene/forbidden/forbidden.less
Normal file
@ -0,0 +1,51 @@
|
||||
|
||||
.full-mode{
|
||||
width:100%;
|
||||
height:100%;
|
||||
top:0;
|
||||
left:0;
|
||||
margin:0;
|
||||
padding:0;
|
||||
border:0;
|
||||
float:left;
|
||||
display:block;
|
||||
}
|
||||
|
||||
.centered {
|
||||
position:relative;
|
||||
max-width:500px;
|
||||
padding: 16px 32px 16px 32px;
|
||||
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: ~"translate(-50%, -50%)";
|
||||
font-size: 30px;
|
||||
|
||||
font-weight: 600;
|
||||
text-align: left;
|
||||
line-height: 200%;
|
||||
}
|
||||
|
||||
.error {
|
||||
font-size: 55px;
|
||||
background-size: 45px;
|
||||
/*background-attachment: fixed;*/
|
||||
background-position: 0% 50%;
|
||||
padding: 0 0 0 58px;
|
||||
margin: 17px 0 17px 0;
|
||||
text-shadow:0px 0px 4px #000000;
|
||||
color: rgb(160, 44, 44);
|
||||
i {
|
||||
font-size: 55px;
|
||||
}
|
||||
}
|
||||
|
||||
.comment {
|
||||
background-size: 45px;
|
||||
/*background-attachment: fixed;*/
|
||||
background-position: 0% 50%;
|
||||
padding: 0 0 0 58px;
|
||||
margin: 17px 0 17px 0;
|
||||
text-shadow:0px 0px 4px #07213a;
|
||||
color: white;
|
||||
}
|
16
front/src/common/scene/forbidden/forbidden.ts
Normal file
16
front/src/common/scene/forbidden/forbidden.ts
Normal file
@ -0,0 +1,16 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2018, Edouard DUPIN, all right reserved
|
||||
* @license PROPRIETARY (see license file)
|
||||
*/
|
||||
|
||||
import { Component } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'app-forbidden',
|
||||
templateUrl: './forbidden.html',
|
||||
styleUrls: [ './forbidden.less' ]
|
||||
})
|
||||
export class ForbiddenScene {
|
||||
constructor() { }
|
||||
}
|
6
front/src/common/scene/home-out/home-out.html
Normal file
6
front/src/common/scene/home-out/home-out.html
Normal file
@ -0,0 +1,6 @@
|
||||
<div class="full-mode">
|
||||
<div class="centered">
|
||||
<div class="error"><label class="unselectable"><i class="material-icons">login</i> Not registered!</label></div>
|
||||
<div class="comment"><label class="unselectable">you must login to access to this website.</label></div>
|
||||
</div>
|
||||
</div>
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user