mercredi 28 juillet 2021

*** annotation LOMBOK *** replacing getters and setters methods

 *** annotation LOMBOK ***

in IntelliJ : install the plugin lombok
in project pom.xml : add the dependency
in Entity add those annotations
@Entity
@Data @NoArgsConstructor @AllArgsConstructor @ToString

and we have not need to add Setters, Getters, and Constructors methods

mardi 27 juillet 2021

@ManyToOne and @OneToOne relations with @EmbeddedId

******************************

*** @ManyToOne and @OneToOne relations with @EmbeddedId

******************************


@Entity

public class Bons implements Serializable {


@EmbeddedId

private BonsKey id;

...

}

@Embeddable

public class BonsKey implements Serializable {


@ManyToOne

@JoinColumn(name = "CODE_PRESTATAIRE")

private Prestataires prestataire;

@ManyToOne

@JoinColumn(name = "NUM_SERVICE")

private ServicesDossiers serviceDossier;

...

}

@Entity

public class Communications implements Serializable{


@Id @GeneratedValue

@Column(name="CODE_COMMUNICATION")

private Long codeCommunication;



@ManyToOne

@JoinColumns({

@JoinColumn(name="BON_CODE_PRESTATAIRE", nullable = true),

@JoinColumn(name="BON_NUM_SERVICE",nullable = true)

})

private Bons bonId;

} 

lundi 26 juillet 2021

GIT install Config

1- Download GIT Installer from https://git-scm.com/downloads

2- Configure username and Email

$ git config --global user.name "Mohamed AMINE OSMAN"

$ git config --global user.email "medamine.osman@apus-consulting.tn"

3- Create the first Git Repository

$ git init first_project

$ cd first_project

create file1.txt

$ git add file1.txt

$ git commit -m "this is my first commit"

4- Edit your setting

$ git config --list --show-origin

vendredi 16 juillet 2021

Spring Boot Get Client IP Adress

private final String LOCALHOST_IPV4 = "127.0.0.1";

private final String LOCALHOST_IPV6 = "0:0:0:0:0:0:0:1";


public String getClientIp(HttpServletRequest request) {

String ipAddress = request.getHeader("X-Forwarded-For");

if(StringUtils.isEmpty(ipAddress) || "unknown".equalsIgnoreCase(ipAddress)) {

ipAddress = request.getHeader("Proxy-Client-IP");

}


if(StringUtils.isEmpty(ipAddress) || "unknown".equalsIgnoreCase(ipAddress)) {

ipAddress = request.getHeader("WL-Proxy-Client-IP");

}


if(StringUtils.isEmpty(ipAddress) || "unknown".equalsIgnoreCase(ipAddress)) {

ipAddress = request.getRemoteAddr();

if(LOCALHOST_IPV4.equals(ipAddress) || LOCALHOST_IPV6.equals(ipAddress)) {

try {

InetAddress inetAddress = InetAddress.getLocalHost();

ipAddress = inetAddress.getHostAddress();

} catch (UnknownHostException e) {

e.printStackTrace();

}

}

}


if(!StringUtils.isEmpty(ipAddress)

&& ipAddress.length() > 15

&& ipAddress.indexOf(",") > 0) {

ipAddress = ipAddress.substring(0, ipAddress.indexOf(","));

}


return ipAddress;

}

@RequestMapping(value="/Index")

public String Index(HttpServletRequest request) {

System.out.println("mon adresse ip:"+getClientIp(request));

}


run console:

mon adresse ip:xxx.xxx.xxx.xxx


dimanche 11 juillet 2021

Date manipulation

 LocalDateTime localDateTime = LocalDateTime.now();

int year = localDateTime.getYear();

int month = localDateTime.getMonthValue();

int day = localDateTime.getDayOfMonth();

int hour = localDateTime.getHour();

int minute = localDateTime.getMinute();

int seconde = localDateTime.getSecond();


System.out.println("local date:" + year + "/" + month + "/" + day + ":" + hour + ":" + minute + ":" + seconde);

local date:2021/7/12:12:18:18

-------------------------------------------------------------------------------------

int year = service.getDateService().getYear()+1900;

int month = service.getDateService().getMonth()+1;

System.out.println("année service:"+year);

System.out.println("mois service:"+month);

System.out.println("mois service:"+String.valueOf(year)+String.format("%02d", month));

//année service:2021

//mois service:7

//mois service:202107

   

--> how to resolve a deprecated getYear() and getMonth():

//Initialize your Date however you like it.

Date date = service.getDateService();

Calendar calendar = new GregorianCalendar();

calendar.setTime(date);

int annee = calendar.get(Calendar.YEAR);

//Add one to month {0 - 11}

int mois = calendar.get(Calendar.MONTH) + 1;

int jours = calendar.get(Calendar.DAY_OF_MONTH);

System.out.println("année:"+annee);

System.out.println("mois:"+mois);

System.out.println("jours:"+jours);

//année:2021

//mois:7

//jours:10

vendredi 2 juillet 2021

Thymeleaf when the value is null

 th:value="${beneficiaireDossier.client} ? ${beneficiaireDossier.client.libelleClient} : ''"

<input class="form-control form-control-sm" type="text" readonly="readonly" th:value="${beneficiaireDossier.client} ? ${beneficiaireDossier.client.libelleClient} : ''"/>


jeudi 24 juin 2021

Recursive relationship in Spring Data and JPA

@Entity

public class Rubriques implements Serializable {


@Id @GeneratedValue(strategy = GenerationType.IDENTITY)

@Column(name="CODE_RUBRIQUE")

private int codeRubrique;

@Column(name="LIBELLE_RUBRIQUE", length = 120)

private String libelleRubrique;


@OneToMany(mappedBy="rubriqueParent")

  private Set<Rubriques> sousRubrique;


  @ManyToOne

  @JoinColumn(name="RUBRIQUE_PARENT")

  private Rubriques rubriqueParent;

   

  @ManyToOne

  @JoinColumn(name="CODE_TYPE_RUBRIQUE")

  private TypesRubrique typeRubrique;

dimanche 30 mai 2021

DateTime-local in thymeleaf and Spring boot

Entity : 

@DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm")

@Column(name="DATE_DEBUT_SERVICE")

private Date dateDebutService;


@DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm")

@Column(name="DATE_FIN_SERVICE")

private Date dateFinService;


HTML Form :
<small class="form-text text-muted">Date Début</small>
<input type="datetime-local" name="dateDebutService" id="dateDebutService" th:field="*{dateDebutService}" class="form-control form-control-sm"/>

jeudi 27 mai 2021

Javascript function return multi values

function calculer_montant_service(txTva){

var ht = 100;

var tva = 0;

var ttc = 0;

ttc = ht * ((100 + txTva)/100);

tva = ttc - ht;

return{

ht : ht,

tva: tva,

ttc: ttc

};

}


var result = calculer_montant_service(19);

alert(result.ht);

alert(result.tva);

alert(result.ttc);


vendredi 21 mai 2021

Thymeleaf : Datalist autocomplete

 <div class="col-8 mb-1">

    <small class="form-text text-muted">Localité sinistre</small>

    <input class="form-control form-control-sm" list="listeLocalites" type="text" id="localite" th:field="*{localiteLieuSinistreDossier}"  placeholder="Localité lieu sinistre..."/>

    <datalist id="listeLocalites" name="localiteLieuSinistreDossier">

        <option th:if="${dossier.localiteLieuSinistreDossier}" th:each="ls:${listeLocalites}" th:value="${ls.codeLocalite}" th:label="${ls.codePostal.codePostal + ' ' + ls.libelleLocalite + ' ' + ls.delegation.libelleDelegation + ' ' + ls.delegation.gouvernorat.libelleGouvernorat}" th:selected="${dossier.localiteLieuSinistreDossier.codeLocalite==ls.codeLocalite}"></option>

        <option th:under="${dossier.localiteLieuSinistreDossier}" th:each="ls:${listeLocalites}" th:value="${ls.codeLocalite}" th:label="${ls.codePostal.codePostal + ' ' + ls.libelleLocalite + ' ' + ls.delegation.libelleDelegation + ' ' + ls.delegation.gouvernorat.libelleGouvernorat}"></option>

    </datalist>

</div>


Thymeleaf : Select dépendante

 <div class="col-2">

<small class="form-text text-muted">Gouvernorat</small>

<select name="gouvernorats" id="gouvernorats" class="form-control form-control-sm" title="Choisir gouvernorat...">

<option value=""></option>

<option th:if="${dossier.localiteLieuSinistreDossier}" th:each="gs:${listeGouvernorats}" th:value="${gs.codeGouvernorat}" th:text="${gs.libelleGouvernorat}" th:selected="${dossier.localiteLieuSinistreDossier.delegation.gouvernorat.codeGouvernorat==gs.codeGouvernorat}">Wireframe</option>

<option th:unless="${dossier.localiteLieuSinistreDossier}" th:each="gs:${listeGouvernorats}" th:value="${gs.codeGouvernorat}" th:text="${gs.libelleGouvernorat}">Wireframe</option>

</select>

</div>

<div class="col-2">

<small class="form-text text-muted">Délégation</small>

<select name="delegations" id="delegations" class="form-control form-control-sm" title="Choisir délégation...">

<option value=""></option>

<option th:if="${dossier.localiteLieuSinistreDossier}" th:each="des:${listeDelegations}" th:id="${des.gouvernorat.codeGouvernorat}" th:value="${des.codeDelegation}" th:text="${des.libelleDelegation}" th:selected="${dossier.localiteLieuSinistreDossier.delegation.codeDelegation==des.codeDelegation}">Wireframe</option>

<option th:unless="${dossier.localiteLieuSinistreDossier}" th:each="des:${listeDelegations}" th:id="${des.gouvernorat.codeGouvernorat}" th:value="${des.codeDelegation}" th:text="${des.libelleDelegation}">Wireframe</option>

</select>

</div>

<script type="text/javascript">
$('#gouvernorats').change(function() {
    $('#delegations option').hide();

    $('#delegations option[id="' + $(this).val() + '"]').show();
    // add this code to select 1'st of localite automaticaly 
    // when gouvernorat changed
    if ($('#delegations option[id="' + $(this).val() + '"]').length) {
        $('#delegations option[id="' + $(this).val() + '"]').first().prop('selected', true);
        $('#delegations').prop('disabled', false);
    }
    // in case if there's no corresponding localite: 
    // reset select element
    else {
        //alert("B");
        $('#delegations').val('pas de délégations');
        
        $('#delegations').prop('disabled', false);
    };
});
</script>

lundi 26 avril 2021

Professionnel

depuis Septembre 2019, Gérant de APUS CONSULTING société de service informatique, développement de logiciel avec mon ami et frère Walid KOUBAA.

Nous développons des applications WEB en utilisant les techniques suivantes:
Spring Boot
Bootstrap
Thymeleaf