Posts

Jackson Date Serialize and Deserialize with UTC+0 format and UTC+4

public class JacksonConfig { private static final String DATE_TIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss" ; public static class CustomLocalDateTimeDeserializer extends JsonDeserializer<LocalDateTime> { private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter. ofPattern ( DATE_TIME_FORMAT ) ; @Override public Class<LocalDateTime> handledType () { return LocalDateTime. class; } @Override public LocalDateTime deserialize (JsonParser parser , DeserializationContext ctxt) throws IOException { LocalDateTime dateTime = LocalDateTime. parse (parser.getText() , DATE_TIME_FORMATTER ) ; return dateTime.atZone(ZoneId. of ( "UTC" )) .withZoneSameInstant(ZoneId. systemDefault ()).toLocalDateTime() ; } } public static class CustomLocalDateTimeSerializer extends JsonSerializer<LocalDate...

AES encrypt-decrypt in Java

 public static String decrypt(byte[] data, byte[] key) throws NoSuchPaddingException, NoSuchAlgorithmException,             BadPaddingException, IllegalBlockSizeException, InvalidKeyException {         Cipher aes = Cipher.getInstance("AES/ECB/PKCS5Padding");         aes.init(Cipher.DECRYPT_MODE, new SecretKeySpec(key,     "AES"));         return new String(Base64.getDecoder().decode(Base64.getEncoder().encodeToString((aes.doFinal(data))))); } public static String encrypt(byte[] data, byte[] key) throws NoSuchPaddingException, NoSuchAlgorithmException,             BadPaddingException, IllegalBlockSizeException, InvalidKeyException {         Cipher aes = Cipher.getInstance("AES/ECB/PKCS5Padding");         aes.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(key,     "AES"));         return Ba...

Create smtp mail server

Firstly by a domain in namecheap , and create droplet(VM) in digitalocean https://namecheap.com , https://digitalocean.com Instructions: https://www.youtube.com/watch?v=Az8PHq-ZqhU https://inguide.in/build-postal-smtp-server-send-bulk-emails-ubuntu-18-04/ https://inguide.in/simplest-way-to-configure-postal-create-smtp-install-ssl/ Pls make attention for step by step instruction netstat -nlptu | egrep -i postal - print smtp port

Product.class dan List.class i almaq

 public static <T> Class<List<T>> getListClass(Class<T> cls) {         return (Class<List<T>>) (Class<?>) List.class; } bu metoda Product.class gonderib List<Product>.class aliriq istifade case i  final List<Product> entities =                 findProduct.executeFunction(getListClass(Product.class), sqlParameterSource); oracle bazadan data getirik ve bu list sheklidedir , ona gore de executeFunctionun ilk paramina list tipinde class gondermeliyik QEYD : adi halda List<Product>.class yazmaq olmur error verir

dto ichinde list dto map etmek

Entity classlar verilir:  public class Partner implements Serializable {          @OneToMany(mappedBy = "partner")     private List<Store> stores = new ArrayList<>(); } public class Store implements Serializable {          @ManyToOne     @JoinColumn(name = "partner_id", referencedColumnName = "id", nullable = false)     private Partner partner; } public class PartnerResponseDto {          private List<StoreResponseDto> stores;      } public interface PartnerMapper { List<PartnerResponseDto> toPartnerResponseDtoListI(List<Partner> partners); PartnerResponseDto toPartnerResponseDto(Partner partner); StoreResponseDto storeToStoreResponseDto(Store store); } Məntiq buduki qaytardığın dtonun içində olan dtolar ayrıca bildirilməlidi mapperdə 1 ci setrde servis list qaytarir deye list map olur , 2 ci setr ise dtonun ozudu , 3 cu setrde ise ma...

Jenkins enviroment installation on Azure

1) Install jenkins: https://docs.microsoft.com/en-us/azure/developer/jenkins/configure-on-linux-vm in vm creating part use this: az vm create \ --resource-group QuickstartJenkins-rg \ --name QuickstartJenkins-vm \ --image UbuntuLTS \ --size Standard B2s \ --admin-username "azureuser" \ --generate-ssh-keys \ --custom-data cloud-init-jenkins.txt in artice use other vm which is cost higher than B2s , but i am using B2s it works very well 2) Install docker: https://docs.docker.com/engine/install/ubuntu/ Then give permission to docker.sock for build image: Recommend way second one: sudo chmod 776 /var/run/docker.sock // for all sudo chown $USER /var/run/docker.sock // for current user 3) Install openjdk11 for build process, because our spring projects on jdk11 sudo apt install openjdk-11-jdk -y sudo update-alternatives --config java , then click enter for selecting * and configure openjdk11 in jenkins global tool configuration for further information about jenkins: https://www...

Java Date and Time examples

look at: https://stackabuse.com/how-to-get-current-date-and-time-in-java/  valuable source about java date classes : https://stackoverflow.com/questions/32437550/whats-the-difference-between-instant-and-localdatetime System.out.println(LocalDateTime.now()); 2021-03-19T13:27:06.043 System.out.println(Instant.now()); 2021-03-19T09:27:06.044Z System.out.println(LocalDateTime.now().atZone(ZoneId.systemDefault())); 2021-03-19T13:27:06.057+04:00[Asia/Baku] System.out.println(LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant()); 2021-03-19T09:27:06.058Z System.out.println(Date.from(LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant())); Fri Mar 19 13:27:06 AZT 2021 System.out.println(new Date()); Fri Mar 19 13:27:06 AZT 2021 System.out.println(LocalDate.now()); 2021-03-19 System.out.println(LocalTime.now()); 13:27:06.066 System.out.println(ZonedDateTime.now()); 2021-03-19T13:27:06.066+04:00[Asia/Baku] System.out.println(ZoneId.systemDefault()); Asia/Baku System.o...