Compare commits
	
		
			3 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| d35c83fcbf | |||
| 0fe769a203 | |||
| dbe1b469f6 | 
							
								
								
									
										2
									
								
								pom.xml
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								pom.xml
									
									
									
									
									
								
							| @@ -3,7 +3,7 @@ | ||||
| 	<modelVersion>4.0.0</modelVersion> | ||||
| 	<groupId>kangaroo-and-rabbit</groupId> | ||||
| 	<artifactId>archidata</artifactId> | ||||
| 	<version>0.7.0</version> | ||||
| 	<version>0.7.1</version> | ||||
| 	<properties> | ||||
| 		<maven.compiler.version>3.1</maven.compiler.version> | ||||
| 		<maven.compiler.source>21</maven.compiler.source> | ||||
|   | ||||
| @@ -6,7 +6,7 @@ import java.lang.annotation.RetentionPolicy; | ||||
| import java.lang.annotation.Target; | ||||
|  | ||||
| /** In case of the update parameter with String input to detect null element. */ | ||||
| @Target({ElementType.PARAMETER, ElementType.METHOD}) | ||||
| @Target({ ElementType.PARAMETER, ElementType.METHOD }) | ||||
| @Retention(RetentionPolicy.RUNTIME) | ||||
| public @interface AsyncType { | ||||
| 	Class<?> value(); | ||||
|   | ||||
| @@ -93,6 +93,7 @@ public class DataResource { | ||||
| 		} | ||||
| 		return filePath; | ||||
| 	} | ||||
|  | ||||
| 	public static String getFileData(final UUID uuid) { | ||||
| 		final String stringUUID = uuid.toString(); | ||||
| 		final String part1 = stringUUID.substring(0, 2); | ||||
| @@ -108,6 +109,7 @@ public class DataResource { | ||||
| 		filePath += part3; | ||||
| 		return filePath; | ||||
| 	} | ||||
|  | ||||
| 	public static String getFileMetaData(final UUID uuid) { | ||||
| 		return getFileData(uuid) + ".json"; | ||||
| 	} | ||||
|   | ||||
| @@ -835,7 +835,8 @@ public class DataAccess { | ||||
| 			UUID uuid = null; | ||||
| 			if (generateUUID) { | ||||
| 				firstField = false; | ||||
| 				uuid = UUID.randomUUID(); | ||||
| 				// uuid = UUID.randomUUID(); | ||||
| 				uuid = UuidUtils.nextUUID(); | ||||
| 				addElement(ps, uuid, iii); | ||||
| 				iii.inc(); | ||||
| 			} | ||||
| @@ -889,13 +890,8 @@ public class DataAccess { | ||||
| 					if (generatedKeys.next()) { | ||||
| 						if (primaryKeyField.getType() == UUID.class) { | ||||
| 							// uniqueSQLUUID = generatedKeys.getObject(1, UUID.class); | ||||
| 							/* | ||||
| 							final Object obj = generatedKeys.getObject(1); | ||||
| 							final BigInteger bigint = (BigInteger) generatedKeys.getObject(1); | ||||
| 							uniqueSQLUUID = UuidUtils.asUuid(bigint); | ||||
| 							final UUID generatedUUID = (UUID) generatedKeys.getObject(1); | ||||
| 							System.out.println("UUID généré: " + generatedUUID); | ||||
| 							 */ | ||||
| 							/* final Object obj = generatedKeys.getObject(1); final BigInteger bigint = (BigInteger) generatedKeys.getObject(1); uniqueSQLUUID = UuidUtils.asUuid(bigint); final UUID | ||||
| 							 * generatedUUID = (UUID) generatedKeys.getObject(1); System.out.println("UUID généré: " + generatedUUID); */ | ||||
| 							final Object obj = generatedKeys.getObject(1); | ||||
| 							final byte[] tmpid = generatedKeys.getBytes(1); | ||||
| 							uniqueSQLUUID = UuidUtils.asUuid(tmpid); | ||||
|   | ||||
| @@ -199,6 +199,7 @@ public class DataFactoryTsApi { | ||||
| 		} | ||||
| 		return ((AsyncType) annotation[0]).value(); | ||||
| 	} | ||||
|  | ||||
| 	public static Class<?> apiAnnotationGetAsyncType(final Method element) throws Exception { | ||||
| 		final Annotation[] annotation = element.getDeclaredAnnotationsByType(AsyncType.class); | ||||
| 		if (annotation.length == 0) { | ||||
| @@ -265,7 +266,7 @@ public class DataFactoryTsApi { | ||||
| 				returnTypeModel = method.getReturnType(); | ||||
| 			} | ||||
| 			boolean isUnmanagedReturnType = false; | ||||
| 			if (returnTypeModel == Response.class ) { | ||||
| 			if (returnTypeModel == Response.class) { | ||||
| 				isUnmanagedReturnType = true; | ||||
| 				returnTypeModel = Void.class; | ||||
| 			} | ||||
| @@ -551,16 +552,14 @@ public class DataFactoryTsApi { | ||||
| 		myWriter = new FileWriter(pathPackage + File.separator + "index.ts"); | ||||
| 		myWriter.write(index.toString()); | ||||
| 		myWriter.close(); | ||||
| 		final InputStream ioStream = DataFactoryTsApi.class | ||||
| 				.getClassLoader() | ||||
| 				.getResourceAsStream("rest-tools.ts"); | ||||
| 		final InputStream ioStream = DataFactoryTsApi.class.getClassLoader().getResourceAsStream("rest-tools.ts"); | ||||
| 		if (ioStream == null) { | ||||
| 			throw new IllegalArgumentException("rest-tools.ts is not found"); | ||||
| 		} | ||||
| 		final BufferedReader buffer = new BufferedReader(new InputStreamReader(ioStream)); | ||||
| 		myWriter = new FileWriter(pathPackage + File.separator + "rest-tools.ts"); | ||||
| 		String line; | ||||
| 		while( (line = buffer.readLine()) != null) { | ||||
| 		while ((line = buffer.readLine()) != null) { | ||||
| 			myWriter.write(line); | ||||
| 			myWriter.write("\n"); | ||||
| 		} | ||||
|   | ||||
| @@ -145,6 +145,7 @@ public class AddOnDataJson implements DataAccessAddOn { | ||||
| 			final boolean createIfNotExist, final boolean createDrop, final int fieldId) throws Exception { | ||||
| 		DataFactory.createTablesSpecificType(tableName, field, mainTableBuilder, preActionList, postActionList, createIfNotExist, createDrop, fieldId, JsonValue.class); | ||||
| 	} | ||||
|  | ||||
| 	public static void addLink(final Class<?> clazz, final Long id, final String column, final Long remoteKey) throws Exception { | ||||
| 		final String tableName = AnnotationTools.getTableName(clazz); | ||||
| 		final TableCoversLongLong data = DataAccess.get(TableCoversLongLong.class, id, new OverrideTableName(tableName)); | ||||
| @@ -174,6 +175,7 @@ public class AddOnDataJson implements DataAccessAddOn { | ||||
| 		data.covers.add(remoteKey); | ||||
| 		DataAccess.update(data, data.id, List.of("covers"), new OverrideTableName(tableName)); | ||||
| 	} | ||||
|  | ||||
| 	public static void addLink(final Class<?> clazz, final UUID id, final String column, final UUID remoteKey) throws Exception { | ||||
| 		final String tableName = AnnotationTools.getTableName(clazz); | ||||
| 		final TableCoversUUIDUUID data = DataAccess.get(TableCoversUUIDUUID.class, id, new OverrideTableName(tableName)); | ||||
| @@ -188,6 +190,7 @@ public class AddOnDataJson implements DataAccessAddOn { | ||||
| 		data.covers.add(remoteKey); | ||||
| 		DataAccess.update(data, data.id, List.of("covers"), new OverrideTableName(tableName)); | ||||
| 	} | ||||
|  | ||||
| 	public static void addLink(final Class<?> clazz, final UUID id, final String column, final Long remoteKey) throws Exception { | ||||
| 		final String tableName = AnnotationTools.getTableName(clazz); | ||||
| 		final TableCoversUUIDLong data = DataAccess.get(TableCoversUUIDLong.class, id, new OverrideTableName(tableName)); | ||||
| @@ -202,6 +205,7 @@ public class AddOnDataJson implements DataAccessAddOn { | ||||
| 		data.covers.add(remoteKey); | ||||
| 		DataAccess.update(data, data.id, List.of("covers"), new OverrideTableName(tableName)); | ||||
| 	} | ||||
|  | ||||
| 	public static void removeLink(final Class<?> clazz, final UUID id, final String column, final Long remoteKey) throws Exception { | ||||
| 		final String tableName = AnnotationTools.getTableName(clazz); | ||||
| 		final TableCoversUUIDLong data = DataAccess.get(TableCoversUUIDLong.class, id, new OverrideTableName(tableName)); | ||||
| @@ -218,6 +222,7 @@ public class AddOnDataJson implements DataAccessAddOn { | ||||
| 		data.covers = newList; | ||||
| 		DataAccess.update(data, data.id, List.of("covers"), new OverrideTableName(tableName)); | ||||
| 	} | ||||
|  | ||||
| 	public static void removeLink(final Class<?> clazz, final UUID id, final String column, final UUID remoteKey) throws Exception { | ||||
| 		final String tableName = AnnotationTools.getTableName(clazz); | ||||
| 		final TableCoversUUIDUUID data = DataAccess.get(TableCoversUUIDUUID.class, id, new OverrideTableName(tableName)); | ||||
| @@ -234,6 +239,7 @@ public class AddOnDataJson implements DataAccessAddOn { | ||||
| 		data.covers = newList; | ||||
| 		DataAccess.update(data, data.id, List.of("covers"), new OverrideTableName(tableName)); | ||||
| 	} | ||||
|  | ||||
| 	public static void removeLink(final Class<?> clazz, final Long id, final String column, final Long remoteKey) throws Exception { | ||||
| 		final String tableName = AnnotationTools.getTableName(clazz); | ||||
| 		final TableCoversLongLong data = DataAccess.get(TableCoversLongLong.class, id, new OverrideTableName(tableName)); | ||||
| @@ -250,6 +256,7 @@ public class AddOnDataJson implements DataAccessAddOn { | ||||
| 		data.covers = newList; | ||||
| 		DataAccess.update(data, data.id, List.of("covers"), new OverrideTableName(tableName)); | ||||
| 	} | ||||
|  | ||||
| 	public static void removeLink(final Class<?> clazz, final Long id, final String column, final UUID remoteKey) throws Exception { | ||||
| 		final String tableName = AnnotationTools.getTableName(clazz); | ||||
| 		final TableCoversLongUUID data = DataAccess.get(TableCoversLongUUID.class, id, new OverrideTableName(tableName)); | ||||
| @@ -266,22 +273,9 @@ public class AddOnDataJson implements DataAccessAddOn { | ||||
| 		data.covers = newList; | ||||
| 		DataAccess.update(data, data.id, List.of("covers"), new OverrideTableName(tableName)); | ||||
| 	} | ||||
| 	/* | ||||
| 	public static <TYPE> void addLink(final Class<TYPE> clazz, final Object localKey, final String column, final Object remoteKey) throws Exception { | ||||
| 		final String tableName = AnnotationTools.getTableName(clazz); | ||||
| 		final TYPE data = DataAccess.get(clazz, localKey); // TODO: add filter of the "column" | ||||
|  | ||||
| 		// find the field column: | ||||
|  | ||||
| 		// add the remoteKey in the list: | ||||
|  | ||||
|  | ||||
| 		// post new data in the DB | ||||
|  | ||||
| 		final String linkTableName = generateLinkTableName(this.tableName, this.column); | ||||
| 		final LinkTable insertElement = new LinkTable(this.localKey, this.remoteKey); | ||||
| 		DataAccess.insert(insertElement, new OverrideTableName(linkTableName)); | ||||
|  | ||||
| 	}*/ | ||||
| 	/* public static <TYPE> void addLink(final Class<TYPE> clazz, final Object localKey, final String column, final Object remoteKey) throws Exception { final String tableName = | ||||
| 	 * AnnotationTools.getTableName(clazz); final TYPE data = DataAccess.get(clazz, localKey); // TODO: add filter of the "column" // find the field column: // add the remoteKey in the list: // post | ||||
| 	 * new data in the DB final String linkTableName = generateLinkTableName(this.tableName, this.column); final LinkTable insertElement = new LinkTable(this.localKey, this.remoteKey); | ||||
| 	 * DataAccess.insert(insertElement, new OverrideTableName(linkTableName)); } */ | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -211,7 +211,8 @@ public class DataTools { | ||||
| 		return data; | ||||
| 	} | ||||
|  | ||||
| 	public static <CLASS_TYPE, ID_TYPE> Response uploadCover(final Class<CLASS_TYPE> clazz, final ID_TYPE id, String fileName, final InputStream fileInputStream, final FormDataContentDisposition fileMetaData) { | ||||
| 	public static <CLASS_TYPE, ID_TYPE> Response uploadCover(final Class<CLASS_TYPE> clazz, final ID_TYPE id, String fileName, final InputStream fileInputStream, | ||||
| 			final FormDataContentDisposition fileMetaData) { | ||||
| 		try { | ||||
| 			// correct input string stream : | ||||
| 			fileName = multipartCorrection(fileName); | ||||
|   | ||||
| @@ -2,6 +2,10 @@ package org.kar.archidata.tools; | ||||
|  | ||||
| import java.math.BigInteger; | ||||
| import java.nio.ByteBuffer; | ||||
| import java.time.Instant; | ||||
| import java.time.LocalDate; | ||||
| import java.time.ZoneOffset; | ||||
| import java.time.temporal.ChronoUnit; | ||||
| import java.util.UUID; | ||||
|  | ||||
| public class UuidUtils { | ||||
| @@ -25,4 +29,41 @@ public class UuidUtils { | ||||
| 		bb.putLong(uuid.getLeastSignificantBits()); | ||||
| 		return bb.array(); | ||||
| 	} | ||||
|  | ||||
| 	private static class Generator { | ||||
| 		private long base; | ||||
| 		private final long offset; | ||||
| 		private long previous; | ||||
|  | ||||
| 		public Generator() { | ||||
| 			this.offset = System.currentTimeMillis(); | ||||
| 			// The local method never generate new UUID in the past, then we use the creation function time to prevent 2038 error | ||||
| 			final Instant startingUUID = LocalDate.of(2024, 03, 19).atStartOfDay(ZoneOffset.UTC).toInstant(); | ||||
| 			this.base = startingUUID.until(Instant.now(), ChronoUnit.SECONDS); | ||||
| 			final String serveurBaseUUID = System.getenv("UUID_SERVER_ID"); | ||||
| 			if (serveurBaseUUID != null) { | ||||
| 				long serverId = Long.valueOf(serveurBaseUUID); | ||||
| 				serverId %= 0xFFFF; | ||||
| 				this.base += (serverId << (64 - 16)); | ||||
| 			} else { | ||||
| 				this.base += (1L << (64 - 16)); | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		public synchronized UUID next() { | ||||
| 			long tmp = System.currentTimeMillis(); | ||||
| 			if (this.previous >= tmp) { | ||||
| 				tmp = this.previous + 1; | ||||
| 			} | ||||
| 			this.previous = tmp; | ||||
| 			tmp -= this.offset; | ||||
| 			return new UUID(Long.reverseBytes(tmp), this.base); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	private static Generator generator = new Generator(); | ||||
|  | ||||
| 	public static UUID nextUUID() { | ||||
| 		return generator.next(); | ||||
| 	} | ||||
| } | ||||
|   | ||||
| @@ -1 +1 @@ | ||||
| 0.7.0 | ||||
| 0.7.1 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user