Commit 8228d6c3 authored by zikas96's avatar zikas96
Browse files

Merge branch 'feat/migration-new' into feat/migration-new-gestion-role

parents 3d914c7f cd520e6f
...@@ -7,4 +7,4 @@ cp -r src/main/config target/src/main/config ...@@ -7,4 +7,4 @@ cp -r src/main/config target/src/main/config
#retrieve version #retrieve version
version="$(grep -oP '(?<=>).*?(?=</version>)' pom.xml | grep -v 'version')" version="$(grep -oP '(?<=>).*?(?=</version>)' pom.xml | grep -v 'version')"
./target/iam-external-$(echo $version).jar -Xms128m -Xmx512m --spring.profiles.active=dev java -jar target/iam-external-$(echo $version).jar -Xms128m -Xmx512m --spring.profiles.active=dev
...@@ -303,7 +303,7 @@ ...@@ -303,7 +303,7 @@
<executable>true</executable> <executable>true</executable>
<attach>true</attach> <!-- Need to use the original jar for integration-tests --> <attach>true</attach> <!-- Need to use the original jar for integration-tests -->
<mainClass>fr.gouv.vitamui.iam.internal.server.ApiIamInternalServerApplication</mainClass> <mainClass>fr.gouv.vitamui.iam.internal.server.ApiIamInternalServerApplication</mainClass>
<jvmArguments>-Xmx512m -Dvitam.config.folder=src/main/config/dev-vitam</jvmArguments> <jvmArguments>-Xmx512m</jvmArguments>
<arguments> <arguments>
<argument>--spring.profiles.active=dev</argument> <argument>--spring.profiles.active=dev</argument>
</arguments> </arguments>
......
...@@ -7,4 +7,4 @@ cp -r src/main/config target/src/main/config ...@@ -7,4 +7,4 @@ cp -r src/main/config target/src/main/config
#retrieve version #retrieve version
version="$(grep -oP '(?<=>).*?(?=</version>)' pom.xml | grep -v 'version')" version="$(grep -oP '(?<=>).*?(?=</version>)' pom.xml | grep -v 'version')"
java -Dvitam.config.folder=src/main/resources/dev/vitam -jar target/iam-internal-$(echo $version).jar -Xms128m -Xmx512m --spring.profiles.active=dev java -Dvitam.config.folder=src/main/config/dev-vitam -jar target/iam-internal-$(echo $version).jar -Xms128m -Xmx512m --spring.profiles.active=dev
serverHost: 10.6.10.65
serverPort: 8444
secure: true
sslConfiguration :
keystore :
- keyPath: keystore_access-external.p12
keyPassword: azerty4
truststore :
- keyPath: truststore_access-external.jks
keyPassword: azerty10
hostnameVerification: true
serverHost: 10.6.10.65
serverPort: 8443
secure: true
sslConfiguration:
keystore :
- keyPath: keystore_access-external.p12
keyPassword: azerty4
truststore :
- keyPath: truststore_access-external.jks
keyPassword: azerty10
hostnameVerification: true
...@@ -26,14 +26,12 @@ ...@@ -26,14 +26,12 @@
package fr.gouv.vitamui.pastis.client; package fr.gouv.vitamui.pastis.client;
import fr.gouv.vitamui.commons.api.CommonConstants;
import fr.gouv.vitamui.commons.api.domain.PaginatedValuesDto; import fr.gouv.vitamui.commons.api.domain.PaginatedValuesDto;
import fr.gouv.vitamui.commons.api.logger.VitamUILogger; import fr.gouv.vitamui.commons.api.logger.VitamUILogger;
import fr.gouv.vitamui.commons.api.logger.VitamUILoggerFactory; import fr.gouv.vitamui.commons.api.logger.VitamUILoggerFactory;
import fr.gouv.vitamui.commons.rest.client.BasePaginatingAndSortingRestClient; import fr.gouv.vitamui.commons.rest.client.BasePaginatingAndSortingRestClient;
import fr.gouv.vitamui.commons.rest.client.ExternalHttpContext; import fr.gouv.vitamui.commons.rest.client.ExternalHttpContext;
import fr.gouv.vitamui.commons.vitam.api.dto.ResultsDto; import fr.gouv.vitamui.pastis.common.dto.profiles.Notice;
import fr.gouv.vitamui.pastis.common.dto.profiles.PastisProfile;
import fr.gouv.vitamui.pastis.common.rest.RestApi; import fr.gouv.vitamui.pastis.common.rest.RestApi;
import org.springframework.core.ParameterizedTypeReference; import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity; import org.springframework.http.HttpEntity;
...@@ -41,11 +39,10 @@ import org.springframework.http.HttpMethod; ...@@ -41,11 +39,10 @@ import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;
import java.util.List; import java.util.List;
public class PastisRestClient extends BasePaginatingAndSortingRestClient<PastisProfile, ExternalHttpContext> { public class PastisRestClient extends BasePaginatingAndSortingRestClient<Notice, ExternalHttpContext> {
private static final VitamUILogger LOGGER = private static final VitamUILogger LOGGER =
VitamUILoggerFactory.getInstance(PastisRestClient.class); VitamUILoggerFactory.getInstance(PastisRestClient.class);
...@@ -56,19 +53,19 @@ public class PastisRestClient extends BasePaginatingAndSortingRestClient<PastisP ...@@ -56,19 +53,19 @@ public class PastisRestClient extends BasePaginatingAndSortingRestClient<PastisP
} }
@Override @Override
protected Class<PastisProfile> getDtoClass() { protected Class<Notice> getDtoClass() {
return PastisProfile.class; return Notice.class;
} }
@Override @Override
protected ParameterizedTypeReference<List<PastisProfile>> getDtoListClass() { protected ParameterizedTypeReference<List<Notice>> getDtoListClass() {
return new ParameterizedTypeReference<List<PastisProfile>>() { return new ParameterizedTypeReference<List<Notice>>() {
}; };
} }
@Override @Override
protected ParameterizedTypeReference<PaginatedValuesDto<PastisProfile>> getDtoPaginatedClass() { protected ParameterizedTypeReference<PaginatedValuesDto<Notice>> getDtoPaginatedClass() {
return new ParameterizedTypeReference<PaginatedValuesDto<PastisProfile>>() { return new ParameterizedTypeReference<PaginatedValuesDto<Notice>>() {
}; };
} }
...@@ -77,11 +74,11 @@ public class PastisRestClient extends BasePaginatingAndSortingRestClient<PastisP ...@@ -77,11 +74,11 @@ public class PastisRestClient extends BasePaginatingAndSortingRestClient<PastisP
return RestApi.STANDALONE; return RestApi.STANDALONE;
} }
public ResponseEntity<List<PastisProfile>> getAllProfiles(ExternalHttpContext context) { public ResponseEntity<List<Notice>> getAllProfiles(ExternalHttpContext context) {
LOGGER.debug("get all pastis profile"); LOGGER.debug("get all pastis profile");
MultiValueMap<String, String> headers = buildSearchHeaders(context); MultiValueMap<String, String> headers = buildSearchHeaders(context);
final HttpEntity<PastisProfile> request = new HttpEntity<>(headers); final HttpEntity<Notice> request = new HttpEntity<>(headers);
final ResponseEntity<List<PastisProfile>> response = final ResponseEntity<List<Notice>> response =
restTemplate.exchange(getUrl() + RestApi.STANDALONE_GET_ALL_PROFILES, HttpMethod.GET, restTemplate.exchange(getUrl() + RestApi.STANDALONE_GET_ALL_PROFILES, HttpMethod.GET,
request, getDtoListClass()); request, getDtoListClass());
return response; return response;
......
...@@ -35,6 +35,7 @@ import fr.gouv.vitamui.commons.api.logger.VitamUILoggerFactory; ...@@ -35,6 +35,7 @@ import fr.gouv.vitamui.commons.api.logger.VitamUILoggerFactory;
import fr.gouv.vitamui.commons.rest.client.BasePaginatingAndSortingRestClient; import fr.gouv.vitamui.commons.rest.client.BasePaginatingAndSortingRestClient;
import fr.gouv.vitamui.commons.rest.client.ExternalHttpContext; import fr.gouv.vitamui.commons.rest.client.ExternalHttpContext;
import fr.gouv.vitamui.pastis.common.dto.ElementProperties; import fr.gouv.vitamui.pastis.common.dto.ElementProperties;
import fr.gouv.vitamui.pastis.common.dto.profiles.Notice;
import fr.gouv.vitamui.pastis.common.dto.profiles.PastisProfile; import fr.gouv.vitamui.pastis.common.dto.profiles.PastisProfile;
import fr.gouv.vitamui.pastis.common.dto.profiles.ProfileNotice; import fr.gouv.vitamui.pastis.common.dto.profiles.ProfileNotice;
import fr.gouv.vitamui.pastis.common.dto.profiles.ProfileResponse; import fr.gouv.vitamui.pastis.common.dto.profiles.ProfileResponse;
...@@ -89,12 +90,12 @@ public class PastisTransformationRestClient extends BasePaginatingAndSortingRest ...@@ -89,12 +90,12 @@ public class PastisTransformationRestClient extends BasePaginatingAndSortingRest
return RestApi.STANDALONE; return RestApi.STANDALONE;
} }
public ResponseEntity<ProfileResponse> loadProfile(String id, ExternalHttpContext context) { public ResponseEntity<ProfileResponse> loadProfile(Notice notice, ExternalHttpContext context) {
LOGGER.debug("Transform profile"); LOGGER.debug("Transform profile");
MultiValueMap<String, String> headers = buildSearchHeaders(context); MultiValueMap<String, String> headers = buildSearchHeaders(context);
final HttpEntity<PastisProfile> request = new HttpEntity<>(headers); final HttpEntity<Notice> request = new HttpEntity<>(notice, headers);
final ResponseEntity<ProfileResponse> response = final ResponseEntity<ProfileResponse> response =
restTemplate.exchange(getUrl() + RestApi.STANDALONE_TRANSFORM_PROFILE + "?id=" + id , HttpMethod.POST, restTemplate.exchange(getUrl() + RestApi.STANDALONE_TRANSFORM_PROFILE, HttpMethod.POST,
request, ProfileResponse.class); request, ProfileResponse.class);
return response; return response;
/* final UriComponentsBuilder uriBuilder = /* final UriComponentsBuilder uriBuilder =
......
package fr.gouv.vitamui.pastis.common.dto; package fr.gouv.vitamui.pastis.common.dto;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import fr.gouv.vitam.common.model.administration.ArchiveUnitProfileStatus; import fr.gouv.vitam.common.model.administration.ArchiveUnitProfileStatus;
import fr.gouv.vitam.common.model.administration.ProfileFormat;
import fr.gouv.vitamui.commons.api.domain.IdDto; import fr.gouv.vitamui.commons.api.domain.IdDto;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
...@@ -15,16 +17,28 @@ import java.util.List; ...@@ -15,16 +17,28 @@ import java.util.List;
@Getter @Getter
@Setter @Setter
public class ArchivalProfileUnitDto extends IdDto implements Serializable { public class ArchivalProfileUnitDto extends IdDto implements Serializable {
private Integer tenant; @JsonProperty("identifier")
private Integer version;
private String identifier; private String identifier;
@JsonProperty("name")
private String name; private String name;
@JsonProperty("description")
private String description; private String description;
private ArchiveUnitProfileStatus status; @JsonProperty("status")
private String creationdate; ArchiveUnitProfileStatus status;
private String lastupdate; @JsonProperty("creationDate")
private String activationdate; private String creationDate;
private String deactivationdate; @JsonProperty("lastUpdate")
private String lastUpdate;
@JsonProperty("activationDate")
private String activationDate;
@JsonProperty("deactivationDate")
private String deactivationDate;
@JsonProperty("controlSchema")
private String controlSchema; private String controlSchema;
private List<String> fields; @JsonProperty("tenant")
private String tenant;
@JsonProperty("version")
private String version;
@JsonProperty("fields")
private List< String> fields;
} }
...@@ -2,6 +2,8 @@ package fr.gouv.vitamui.pastis.common.dto; ...@@ -2,6 +2,8 @@ package fr.gouv.vitamui.pastis.common.dto;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import fr.gouv.vitam.common.model.administration.ArchiveUnitProfileStatus;
import fr.gouv.vitam.common.model.administration.ProfileFormat; import fr.gouv.vitam.common.model.administration.ProfileFormat;
import fr.gouv.vitam.common.model.administration.ProfileStatus; import fr.gouv.vitam.common.model.administration.ProfileStatus;
import fr.gouv.vitamui.commons.api.domain.IdDto; import fr.gouv.vitamui.commons.api.domain.IdDto;
...@@ -9,21 +11,35 @@ import lombok.Getter; ...@@ -9,21 +11,35 @@ import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.ToString; import lombok.ToString;
import java.util.List;
@ToString @ToString
@JsonInclude(JsonInclude.Include.NON_NULL) @JsonInclude(JsonInclude.Include.NON_NULL)
@Getter @Getter
@Setter @Setter
public class ProfileDto extends IdDto { public class ProfileDto extends IdDto {
private Integer tenant; @JsonProperty("identifier")
private Integer version;
private String identifier; private String identifier;
@JsonProperty("name")
private String name; private String name;
@JsonProperty("description")
private String description; private String description;
private ProfileStatus status; @JsonProperty("status")
private ProfileFormat format; ProfileStatus status;
@JsonProperty("creationDate")
private String creationDate;
@JsonProperty("lastUpdate")
private String lastUpdate;
@JsonProperty("activationDate")
private String activationDate;
@JsonProperty("deactivationDate")
private String deactivationDate;
@JsonProperty("tenant")
private String tenant;
@JsonProperty("version")
private String version;
@JsonProperty("path")
private String path; private String path;
private String creationdate; @JsonProperty("format")
private String lastupdate; private ProfileFormat format;
private String activationdate;
private String deactivationdate;
} }
package fr.gouv.vitamui.pastis.common.dto.profiles; package fr.gouv.vitamui.pastis.common.dto.profiles;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.module.afterburner.AfterburnerModule;
import fr.gouv.vitam.common.model.administration.ArchiveUnitProfileStatus; import fr.gouv.vitam.common.model.administration.ArchiveUnitProfileStatus;
import fr.gouv.vitam.common.model.administration.ProfileFormat; import fr.gouv.vitam.common.model.administration.ProfileFormat;
import fr.gouv.vitamui.commons.api.domain.IdDto; import fr.gouv.vitamui.commons.api.domain.IdDto;
import fr.gouv.vitamui.pastis.common.util.NoticeUtils;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import org.json.JSONTokener; import org.json.JSONTokener;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
...@@ -17,10 +24,14 @@ import java.io.InputStream; ...@@ -17,10 +24,14 @@ import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.Serializable; import java.io.Serializable;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
@Data@AllArgsConstructor@NoArgsConstructor @Data@AllArgsConstructor@NoArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Notice extends IdDto implements Serializable { public class Notice extends IdDto implements Serializable {
@JsonProperty("identifier") @JsonProperty("identifier")
String identifier; String identifier;
...@@ -41,9 +52,9 @@ public class Notice extends IdDto implements Serializable { ...@@ -41,9 +52,9 @@ public class Notice extends IdDto implements Serializable {
@JsonProperty("controlSchema") @JsonProperty("controlSchema")
String controlSchema; String controlSchema;
@JsonProperty("tenant") @JsonProperty("tenant")
String tenant; Integer tenant;
@JsonProperty("version") @JsonProperty("version")
String version; Integer version;
@JsonProperty("fields") @JsonProperty("fields")
List<String> fields; List<String> fields;
@JsonProperty("path") @JsonProperty("path")
...@@ -59,15 +70,22 @@ public class Notice extends IdDto implements Serializable { ...@@ -59,15 +70,22 @@ public class Notice extends IdDto implements Serializable {
this.status = ArchiveUnitProfileStatus.ACTIVE; this.status = ArchiveUnitProfileStatus.ACTIVE;
this.lastUpdate = new Timestamp(lastUpdate).toString(); this.lastUpdate = new Timestamp(lastUpdate).toString();
this.deactivationDate = new Timestamp(lastUpdate).toString(); this.deactivationDate = new Timestamp(lastUpdate).toString();
this.activationDate = new Timestamp(lastUpdate).toString();
this.creationDate = new Timestamp(lastUpdate).toString(); this.creationDate = new Timestamp(lastUpdate).toString();
this.path = fileName; this.tenant = 1;
this.format = getFileType(fileName).equals("PA") ? ProfileFormat.RNG : null; this.version = 1;
if(getFileType(fileName).equals("PUA")){ this.description = "Description";
this.name = getFileBaseName(fileName);
if(getFileType(fileName).equals(ProfileType.PUA)){
InputStream inputStream = getClass().getClassLoader().getResourceAsStream("rng/" + InputStream inputStream = getClass().getClassLoader().getResourceAsStream("rng/" +
fileName); fileName);
JSONTokener tokener = new JSONTokener(new InputStreamReader(inputStream)); JSONTokener tokener = new JSONTokener(new InputStreamReader(inputStream));
JSONObject profileJson = new JSONObject(tokener); JSONObject profileJson = new JSONObject(tokener);
this.controlSchema = profileJson.getString("ControlSchema"); this.controlSchema = profileJson.getString("controlSchema");
this.fields = NoticeUtils.convert((JSONArray) profileJson.get("fields"));
}else{
this.path = fileName;
this.format = ProfileFormat.RNG;
} }
} }
...@@ -76,9 +94,22 @@ public class Notice extends IdDto implements Serializable { ...@@ -76,9 +94,22 @@ public class Notice extends IdDto implements Serializable {
return tokens[0]; return tokens[0];
} }
public String getFileType(String fileName){ public ProfileType getFileType(String fileName){
String[] tokens = fileName.split("\\.(?=[^\\.]+$)"); String[] tokens = fileName.split("\\.(?=[^\\.]+$)");
return tokens[1].equals("rng") ? "PA" : "PUA"; return tokens[1].equals("rng") ? ProfileType.PA : ProfileType.PUA;
} }
public String serialiseString() throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new AfterburnerModule());
String json = mapper.writeValueAsString(this);
return json;
}
/* public void deserialize(JSONObject jsonObject) {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.readValue(jsonObject, Notice.class);
}*/
} }
...@@ -38,5 +38,5 @@ public class ProfileResponse extends IdDto { ...@@ -38,5 +38,5 @@ public class ProfileResponse extends IdDto {
String name; String name;
ElementProperties profile; ElementProperties profile;
Notice notice; Notice notice;
String type; ProfileType type;
} }
package fr.gouv.vitamui.pastis.common.dto.profiles;
public enum ProfileType {
PA,
PUA;
private ProfileType() {
}
}
package fr.gouv.vitamui.pastis.common.util;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.module.afterburner.AfterburnerModule;
import fr.gouv.vitamui.pastis.common.dto.profiles.Notice;
import fr.gouv.vitamui.pastis.common.dto.profiles.ProfileType;
import org.json.JSONArray;
import org.json.JSONException;
import java.util.ArrayList;
public class NoticeUtils {
private NoticeUtils() {
}
public static ArrayList<String> convert(JSONArray jArr)
{
ArrayList<String> list = new ArrayList<String>();
try {
for (int i=0, l=jArr.length(); i<l; i++){
list.add(jArr.getString(i));
}
} catch (JSONException e) {}
return list;
}
public static ProfileType getFileType(Notice notice){
return notice.getPath() != null && notice.getControlSchema()==null ? ProfileType.PA : ProfileType.PUA;
}
public static String serialiseString(Object o) throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new AfterburnerModule());
String json = mapper.writeValueAsString(o);
return json;
}
}
...@@ -90,18 +90,18 @@ class PastisController { ...@@ -90,18 +90,18 @@ class PastisController {
} }
@RequestMapping (value = "/getfile", method = RequestMethod.GET) @RequestMapping (value = "/getfile", method = RequestMethod.GET)
ResponseEntity<String> getFile() { ResponseEntity<String> getFile(@RequestParam(name = "name") String filename) {
if (profileService.getFile() != null) { if (profileService.getFile(filename) != null) {
return ResponseEntity.ok(profileService.getFile()); return ResponseEntity.ok(profileService.getFile(filename));
} else { } else {
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
} }
} }
@RequestMapping (value = RestApi.STANDALONE_TRANSFORM_PROFILE, method = RequestMethod.POST) @RequestMapping (value = RestApi.STANDALONE_TRANSFORM_PROFILE, method = RequestMethod.POST)
ResponseEntity<ProfileResponse> loadProfile(@RequestParam(name = "id") String id) throws JsonProcessingException { ResponseEntity<ProfileResponse> loadProfile(@RequestBody final Notice notice) throws JsonProcessingException {
if (profileService.loadProfile(id) != null) { if (profileService.loadProfile(notice) != null) {
return ResponseEntity.ok(profileService.loadProfile(id)); return ResponseEntity.ok(profileService.loadProfile(notice));
} else { } else {
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
} }
......