diff --git a/pom.xml b/pom.xml index e2ed15f..7e2d274 100644 --- a/pom.xml +++ b/pom.xml @@ -70,6 +70,19 @@ org.springframework.ldap spring-ldap-core + + com.querydsl + querydsl-apt + provided + + + com.querydsl + querydsl-core + + + com.querydsl + querydsl-jpa + @@ -127,6 +140,26 @@ + + com.mysema.maven + apt-maven-plugin + 1.1.3 + + + + process + + generate-sources + + target/generated-sources/java + com.querydsl.apt.jpa.JPAAnnotationProcessor + + com.querydsl.core.annotations.Generated + + + + + diff --git a/src/main/java/fr/recia/mce/api/escomceapi/db/beans/Personne.java b/src/main/java/fr/recia/mce/api/escomceapi/db/beans/Personne.java new file mode 100644 index 0000000..bbaa772 --- /dev/null +++ b/src/main/java/fr/recia/mce/api/escomceapi/db/beans/Personne.java @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2023 GIP-RECIA, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package fr.recia.mce.api.escomceapi.db.beans; + +import java.util.Date; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class Personne { + + private String displayName; + private String identifiant; + private Date dateValidCharte; + private String uid; + private String mailFixe; + private String mail; + private boolean mailForward; + // private LdapPassword ldapPassword; + private boolean charteValide; + // private EnumEtat etat; + // private Structure structure; + private String domaineDeConnexion; + // private EnumPublic enumPublic; + // private InternetAddress internetAddress; + private String codeConfirmation; + // private EnumTypeConfirmation typeCode; + + private boolean isCfa; + + private boolean mailFixeConfirm; + private boolean mailPersoConfirm; + private String mailConfirme; + private boolean mailFixeConfiance; + + private String nom; + private String prenom; + private String aliasLogin; + private Date naissance; + + private String avatarUrl; + + // private List reponseSecreteList; + + public String typeOfParent() { + return null; + } + + public String lienParente() { + return null; + } +} diff --git a/src/main/java/fr/recia/mce/api/escomceapi/db/beans/Structure.java b/src/main/java/fr/recia/mce/api/escomceapi/db/beans/Structure.java new file mode 100644 index 0000000..f3ac344 --- /dev/null +++ b/src/main/java/fr/recia/mce/api/escomceapi/db/beans/Structure.java @@ -0,0 +1,171 @@ +/* + * Copyright (C) 2023 GIP-RECIA, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package fr.recia.mce.api.escomceapi.db.beans; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@NoArgsConstructor +@AllArgsConstructor +@Data +public class Structure implements Comparable { + + private boolean open4Ent; + private String nom; + + private String displayName; + + private String uai; + private String skin; + private String ville; + private String siren; + private String[] domaines; + private String type; + private String source; + + public boolean isOpen4Ent() { + return open4Ent; + } + + public String getNom() { + return nom; + } + + public void setNom(final String nom) { + if (nom != null) { + this.nom = nom.intern(); + } + } + + public String getDisplayName() { + return displayName; + } + + public void setDisplayName(final String displayName) { + if (displayName != null) { + this.displayName = displayName.intern(); + } + } + + public String getUai() { + return uai; + } + + public void setUai(final String uai) { + if (uai != null) { + this.uai = uai.intern(); + } + } + + public String getSkin() { + return skin; + } + + public void setSkin(final String skin) { + if (skin != null) { + this.skin = skin.intern(); + } + } + + public String getVille() { + return ville; + } + + public void setVille(final String ville) { + this.ville = ville; + } + + public String getSiren() { + return siren; + } + + public void setSiren(final String siren) { + if (siren != null) { + this.siren = siren.intern(); + } + } + + public String[] getDomaines() { + return domaines; + } + + public void setDomaines(final String[] domaines) { + if (domaines != null) { + this.domaines = new String[domaines.length]; + for (int i = 0; i < domaines.length; i++) { + this.domaines[i] = domaines[i].intern(); + } + } + } + + public String getType() { + return type; + } + + public void setType(final String type) { + if (type != null) { + this.type = type.intern(); + } + } + + @Override + public int compareTo(final Structure arg0) { + if (arg0 == this) { + return 0; + } + return getSiren().compareTo(arg0.getSiren()); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((siren == null) ? 0 : siren.hashCode()); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + Structure other = (Structure) obj; + if (siren == null) { + if (other.siren != null) { + return false; + } + } else if (!siren.equals(other.siren)) { + return false; + } + return true; + } + + public String getSource() { + return source; + } + + public void setSource(final String source) { + this.source = source; + } + +} diff --git a/src/main/java/fr/recia/mce/api/escomceapi/db/dto/PersonneDTO.java b/src/main/java/fr/recia/mce/api/escomceapi/db/dto/PersonneDTO.java new file mode 100644 index 0000000..17521ed --- /dev/null +++ b/src/main/java/fr/recia/mce/api/escomceapi/db/dto/PersonneDTO.java @@ -0,0 +1,294 @@ +/* + * Copyright (C) 2023 GIP-RECIA, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package fr.recia.mce.api.escomceapi.db.dto; + +import java.util.Date; + +import org.apache.commons.lang3.StringUtils; + +import fr.recia.mce.api.escomceapi.db.beans.Personne; +import fr.recia.mce.api.escomceapi.db.entities.APersonne; +import fr.recia.mce.api.escomceapi.db.entities.AStructure; +import fr.recia.mce.api.escomceapi.db.entities.CerbereEnfant; +import fr.recia.mce.api.escomceapi.db.entities.Login; +import lombok.Getter; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@Getter +public class PersonneDTO extends Personne { + + private APersonne aPersonneBase; + + private CerbereEnfant cerbereEnfant; + + private Login loginBase; + + private StructureDTO structureDto; + + private String mailFromLdap; + + public PersonneDTO(final APersonne aPersonne) { + this(aPersonne, aPersonne.getAStructure()); + } + + public PersonneDTO(final APersonne aPersonne, final AStructure aStructure) { + super(); + aPersonneBase = aPersonne; + structureDto = new StructureDTO(aStructure); + } + + public PersonneDTO(final APersonne aPersonne, final AStructure aStructure, final Login login) { + super(); + aPersonneBase = aPersonne; + structureDto = new StructureDTO(aStructure); + this.loginBase = login; + } + + public PersonneDTO(final APersonne aPersonne, final Login login) { + this(aPersonne); + loginBase = login; + } + + public PersonneDTO(final Login login) { + this(login.getAPersonneByAPersonneLogin()); + } + + public PersonneDTO(final APersonne aPersonne, final CerbereEnfant enfant, final AStructure aStructure, + final Login login) { + super(); + aPersonneBase = aPersonne; + structureDto = new StructureDTO(aStructure); + cerbereEnfant = enfant; + loginBase = login; + } + + @Override + public String getIdentifiant() { + if (loginBase != null) { + return loginBase.getNom(); + } + return getUid(); + } + + @Override + public String getNom() { + return aPersonneBase.getSn(); + } + + @Override + public String getPrenom() { + return aPersonneBase.getGivenName(); + } + + @Override + public String getUid() { + return aPersonneBase.getUid(); + } + + @Override + public Date getNaissance() { + return aPersonneBase.getDateNaissance(); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + + ((getUid() == null) ? 0 : getUid().hashCode()); + return result; + } + + @Override + public String getDisplayName() { + return aPersonneBase.getDisplayName(); + } + + @Override + public Date getDateValidCharte() { + return aPersonneBase.getValidationCharte(); + } + + @Override + public String getMailFixe() { + String mail = aPersonneBase.getEmail(); + if (mail == null) { + // add a condition only if its a student, isEleve() + log.info("mailfixe is null, then retrieve it from ldap"); + mail = getMailFromLdap(); + } + + return mail; + } + + @Override + public String getMail() { + return aPersonneBase.getEmailPersonnel(); + } + + @Override + public boolean isMailForward() { + return aPersonneBase.isDoForward(); + } + + /** + * Change le flag doForward en base + * + * @param doForward + */ + protected void setForward(final boolean doForward) { + aPersonneBase.setDoForward(doForward); + setDateModification(); + } + + /** + * Récupère le mot de passe en base + * + * @return le mot de passe codé ou non + */ + protected String getDbPassword() { + return aPersonneBase.getPassword(); + } + + /** + * fixe le mot de passe en base. + * + * @param password + */ + protected void setDbPassword(final String password) { + aPersonneBase.setPassword(password); + setDateModification(); + } + + /** + * Fixe l'état de la personne. + * + * @param etat + */ + protected void setEtat(final String etat) { + aPersonneBase.setEtat(etat); + setDateModification(); + } + + /** + * met a jour l'url de la photo dans sarapis mais pas dans ldap + * pour la mise a jour dans les 2 utiliser DaoServicePersonne.setPhotoUrl + * + * @param url + */ + @Override + public void setAvatarUrl(String url) { + aPersonneBase.setPhoto(url); + setDateModification(); + super.setAvatarUrl(url); + } + + @Override + public String getAvatarUrl() { + String url = super.getAvatarUrl(); + if (url == null && aPersonneBase != null) { + url = aPersonneBase.getPhoto(); + super.setAvatarUrl(url); + } + return url; + } + + /** + * Modifie la date de modification. + * + * @param dateModification + */ + public void setDateModification(final Date dateModification) { + aPersonneBase.setDateModification(dateModification); + } + + /** + * Fixe la date de modification au jour courant. + */ + public void setDateModification() { + setDateModification(new Date()); + } + + @Override + public boolean isCharteValide() { + Date d = aPersonneBase.getValidationCharte(); + return d != null; + } + + /** + * Fixe la date de signature de la charte. + * + * @param datedesignature + */ + public void setDateValideCharte(final Date datedesignature) { + aPersonneBase.setValidationCharte(datedesignature); + setDateModification(); + } + + /** + * + * @return apersonne + */ + APersonne getApersonne() { + return aPersonneBase; + } + + /** + * + * @return login + */ + Login getLogin() { + return loginBase; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (!super.equals(obj)) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + PersonneDTO other = (PersonneDTO) obj; + return StringUtils.equals(getUid(), other.getUid()); + } + + @Override + public String typeOfParent() { + if (cerbereEnfant == null) { + return null; + } + String rel = cerbereEnfant.getTypeRelation(); + if (rel == null) { + return null; + } + return rel.intern(); + } + + @Override + public String lienParente() { + if (cerbereEnfant == null) { + return null; + } + String lien = cerbereEnfant.getLienParente(); + return lien == null ? null : lien.intern(); + } + +} diff --git a/src/main/java/fr/recia/mce/api/escomceapi/db/dto/StructureDTO.java b/src/main/java/fr/recia/mce/api/escomceapi/db/dto/StructureDTO.java new file mode 100644 index 0000000..a9e3195 --- /dev/null +++ b/src/main/java/fr/recia/mce/api/escomceapi/db/dto/StructureDTO.java @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2023 GIP-RECIA, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package fr.recia.mce.api.escomceapi.db.dto; + +import java.util.regex.Pattern; + +import org.apache.commons.lang3.StringUtils; + +import fr.recia.mce.api.escomceapi.db.beans.Structure; +import fr.recia.mce.api.escomceapi.db.entities.AStructure; + +public class StructureDTO extends Structure { + + static private final Pattern P = Pattern.compile("(\\w+)-.+"); + + public enum DomSource { + AC, + CFA, + GIP, + LA, + REGION, + EF2S; + } + + private final AStructure aStructure; + + private DomSource domSource; + + public StructureDTO(final AStructure aStructure) { + super(); + this.aStructure = aStructure; + } + + @Override + public boolean isOpen4Ent() { + return false; + } + + @Override + public String getNom() { + String nom = aStructure.getNom(); + if (nom != null) { + nom = nom.replace('$', ' '); + return nom.intern(); + } + return nom; + } + + @Override + public String getDisplayName() { + String dn = super.getDisplayName(); + if (StringUtils.isBlank(dn)) { + return getNom(); + } + return dn.intern(); + } + + @Override + public String getSiren() { + String s = super.getSiren(); + if (s == null) { + s = aStructure.getSiren(); + super.setSiren(s); + } + return s; + } + + @Override + public String getSource() { + String src = super.getSource(); + if (src == null) { + src = aStructure.getSource(); + super.setSource(src); + } + return src; + } +} diff --git a/src/main/java/fr/recia/mce/api/escomceapi/db/repositories/APersonneRepository.java b/src/main/java/fr/recia/mce/api/escomceapi/db/repositories/APersonneRepository.java new file mode 100644 index 0000000..3fa30db --- /dev/null +++ b/src/main/java/fr/recia/mce/api/escomceapi/db/repositories/APersonneRepository.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2023 GIP-RECIA, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package fr.recia.mce.api.escomceapi.db.repositories; + +import org.springframework.data.jpa.repository.Query; +import org.springframework.stereotype.Repository; + +import fr.recia.mce.api.escomceapi.db.dto.PersonneDTO; +import fr.recia.mce.api.escomceapi.db.entities.APersonne; + +@Repository +public interface APersonneRepository extends AbstractRepository { + + @Query("SELECT new fr.recia.mce.api.escomceapi.db.dto.PersonneDTO(a, s, l) " + + "FROM APersonne a " + + "JOIN Login l ON a.id = l.aPersonneByAPersonneLogin " + + "JOIN AStructure s ON s.id = a.aStructure " + + "WHERE a.uid = :uid") + PersonneDTO getPersonneByUid(final String uid); + +} diff --git a/src/main/java/fr/recia/mce/api/escomceapi/db/repositories/AbstractRepository.java b/src/main/java/fr/recia/mce/api/escomceapi/db/repositories/AbstractRepository.java new file mode 100644 index 0000000..62b8763 --- /dev/null +++ b/src/main/java/fr/recia/mce/api/escomceapi/db/repositories/AbstractRepository.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2023 GIP-RECIA, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package fr.recia.mce.api.escomceapi.db.repositories; + +import java.io.Serializable; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.data.querydsl.QuerydslPredicateExecutor; +import org.springframework.data.repository.NoRepositoryBean; + +@SuppressWarnings("java:S119") +@NoRepositoryBean +public interface AbstractRepository + extends JpaRepository, QuerydslPredicateExecutor, JpaSpecificationExecutor { +} diff --git a/src/main/java/fr/recia/mce/api/escomceapi/services/PersonneService.java b/src/main/java/fr/recia/mce/api/escomceapi/services/PersonneService.java new file mode 100644 index 0000000..310f45e --- /dev/null +++ b/src/main/java/fr/recia/mce/api/escomceapi/services/PersonneService.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2023 GIP-RECIA, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package fr.recia.mce.api.escomceapi.services; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import fr.recia.mce.api.escomceapi.db.dto.PersonneDTO; +import fr.recia.mce.api.escomceapi.db.repositories.APersonneRepository; +import lombok.extern.slf4j.Slf4j; + +@Service +@Slf4j +public class PersonneService { + + @Autowired + private APersonneRepository aPersonneRepository; + + public PersonneDTO getPersonneByUid(String uid) { + log.info("uid: {}", uid); + PersonneDTO personne = aPersonneRepository.getPersonneByUid(uid); + + log.info("getPersonne : {}", personne); + return personne; + } + +} diff --git a/src/main/java/fr/recia/mce/api/escomceapi/web/rest/PersonneRestController.java b/src/main/java/fr/recia/mce/api/escomceapi/web/rest/PersonneRestController.java new file mode 100644 index 0000000..8dac1de --- /dev/null +++ b/src/main/java/fr/recia/mce/api/escomceapi/web/rest/PersonneRestController.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2023 GIP-RECIA, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package fr.recia.mce.api.escomceapi.web.rest; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import fr.recia.mce.api.escomceapi.db.dto.PersonneDTO; +import fr.recia.mce.api.escomceapi.services.PersonneService; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@RestController +@RequestMapping("/api/personne") +public class PersonneRestController { + + @Autowired + private PersonneService personneService; + + @GetMapping("/") + public ResponseEntity getPersonneByUid() { + PersonneDTO personne = personneService.getPersonneByUid("uid"); + log.info("personne: {}", personne); + if (personne == null) + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + + return new ResponseEntity<>(personne, HttpStatus.OK); + } + +}