package org.oasis.datacore.sample.citizenkin;

import org.oasis.datacore.core.meta.model.*;
import org.oasis.datacore.sample.DatacoreSampleBase;
import org.springframework.stereotype.Component;

/**
 * Electoral roll registration request. To be valid, the resource MUST have BOTH an envelope and a procedure
 *
 * NOTE: this models the specifically French procedure. This has very
 * little applicability to other countries; therefore for clarity the
 * field names are in the original French.
 *
 * User: schambon
 * Date: 12/24/13
 */
@Component
public class CitizenKinElectionModelInitializer extends DatacoreSampleBase {


    public static final String CITIZENKIN_PROCEDURE_ENVELOPE = "citizenkin.procedure.envelope";
    public static final String CITIZENKIN_PROCEDURE_ELECTORAL_ROLL_REGISTRATION = "citizenkin.procedure.electoral_roll_registration";

    public static final String STRING_TYPE = DCFieldTypeEnum.STRING.getType();
    public static final String DATE_TYPE = DCFieldTypeEnum.DATE.getType();
    public static final String LONG_TYPE = DCFieldTypeEnum.LONG.getType();


    @Override
    public void doInit() {

        DCModel envelope = new DCModel(CITIZENKIN_PROCEDURE_ENVELOPE);
        envelope.addField(new DCField("definition_name", STRING_TYPE, true, 10));
        envelope.addField(new DCField("initiator", STRING_TYPE, true, 100));
        envelope.addField(new DCField("recipient", STRING_TYPE, false, 10));
        envelope.addField(new DCField("state", STRING_TYPE, true, 10));
        envelope.addField(new DCField("start_date", DATE_TYPE, true, 0));
        envelope.addField(new DCField("modify_date", DATE_TYPE, false, 0));
        envelope.addField(new DCField("comments", STRING_TYPE, false, 0));

        modelAdminService.addModel(envelope);


        DCModel model = new DCModel(CITIZENKIN_PROCEDURE_ELECTORAL_ROLL_REGISTRATION);

        model.addField(new DCResourceField("envelope", CITIZENKIN_PROCEDURE_ENVELOPE, true, 10));

        model.addField(new DCField("nom_de_famille", STRING_TYPE, false, 0));
        model.addField(new DCField("nom_d_usage", STRING_TYPE, false, 0));
        model.addField(new DCField("prenom", STRING_TYPE, false, 0));
        model.addField(new DCField("sexe", STRING_TYPE, true, 0));
        model.addField(new DCField("date_de_naissance", DATE_TYPE, false, 0));
        model.addField(new DCField("commune_de_naissance", STRING_TYPE, false, 0));
        model.addField(new DCField("code_departement_de_naissance", STRING_TYPE, false, 0));
        model.addField(new DCField("libelle_territoire_de_naissance_outremer", STRING_TYPE, false, 0));
        model.addField(new DCField("pays_de_naissance", STRING_TYPE, false, 0));

        /* One of:
        "premiere_demande"
        "demenagement_meme_commune"
        "changement_commune"
         */
        model.addField(new DCField("type_de_demande", STRING_TYPE, true, 0));

        model.addField(new DCField("commune_origine", STRING_TYPE, false, 0));
        model.addField(new DCField("code_departement_origine", STRING_TYPE, false, 0));
        model.addField(new DCField("libelle_territoire_outremer_origine", STRING_TYPE, false, 0));

        model.addField(new DCField("ambassade_poste_consulaire_origine", STRING_TYPE, false, 0));
        model.addField(new DCField("pays_origine", STRING_TYPE, false, 0));

        model.addField(new DCField("adresse1", STRING_TYPE, false, 0));
        model.addField(new DCField("adresse2", STRING_TYPE, false, 0));
        model.addField(new DCField("code_postal", STRING_TYPE, false, 0));
        model.addField(new DCField("commune", STRING_TYPE, false, 0));
        model.addField(new DCField("telephone", STRING_TYPE, false, 0));
        model.addField(new DCField("courriel", STRING_TYPE, false, 0));

        /*
         * in January 2014: points to a CK-local URL
         * Later: points to a Digital Safe resource (somehow)
         */
        model.addField(new DCField("justificatif_identite", STRING_TYPE, false, 0));
        model.addField(new DCListField("justificatifs_domicile", new DCField("justificatif_domicile", STRING_TYPE, false, 0)));


        modelAdminService.addModel(model);
    }
}

@@ -623,105 +623,8 @@
  %7B%0A%0A
-%0A    public static final String CITIZENKIN_PROCEDURE_ENVELOPE = %22citizenkin.procedure.envelope%22;%0A
     
@@ -912,778 +912,49 @@
 ();%0A
-    public static final String LONG_TYPE = DCFieldTypeEnum.LONG.getType();%0A%0A%0A    @Override%0A    public void doInit() %7B%0A%0A        DCModel envelope = new DCModel(CITIZENKIN_PROCEDURE_ENVELOPE);%0A        envelope.addField(new DCField(%22definition_name%22, STRING_TYPE, true, 10));%0A        envelope.addField(new DCField(%22initiator%22, STRING_TYPE, true, 100));%0A        envelope.addField(new DCField(%22recipient%22, STRING_TYPE, false, 10));%0A        envelope.addField(new DCField(%22state%22, STRING_TYPE, true, 10));%0A        envelope.addField(new DCField(%22start_date%22, DATE_TYPE, true, 0));%0A        envelope.addField(new DCField(%22modify_date%22, DATE_TYPE, false, 0));%0A        envelope.addField(new DCField(%22comments%22, STRING_TYPE, false, 0));%0A%0A        modelAdminService.addModel(envelope);%0A
+%0A    @Override%0A    public void doInit() %7B
 %0A%0A  
@@ -1043,107 +1043,8 @@
 );%0A%0A
-        model.addField(new DCResourceField(%22envelope%22, CITIZENKIN_PROCEDURE_ENVELOPE, true, 10));%0A%0A
     
@@ -1097,36 +1097,35 @@
 %22, STRING_TYPE, 
-fals
+tru
 e, 0));%0A        
@@ -1241,36 +1241,35 @@
 %22, STRING_TYPE, 
-fals
+tru
 e, 0));%0A        
@@ -1390,28 +1390,27 @@
  DATE_TYPE, 
-fals
+tru
 e, 0));%0A    
@@ -1469,36 +1469,35 @@
 %22, STRING_TYPE, 
-fals
+tru
 e, 0));%0A        
@@ -1561,36 +1561,35 @@
 %22, STRING_TYPE, 
-fals
+tru
 e, 0));%0A        
@@ -2462,36 +2462,35 @@
 %22, STRING_TYPE, 
-fals
+tru
 e, 0));%0A        
@@ -2608,36 +2608,35 @@
 %22, STRING_TYPE, 
-fals
+tru
 e, 0));%0A        
@@ -2678,36 +2678,35 @@
 %22, STRING_TYPE, 
-fals
+tru
 e, 0));%0A        
@@ -2872,16 +2872,8 @@
  in 
-January 
 2014
@@ -2903,70 +2903,8 @@
 URL%0A
-         * Later: points to a Digital Safe resource (somehow)%0A
     
@@ -2976,36 +2976,35 @@
 %22, STRING_TYPE, 
-fals
+tru
 e, 0));%0A        
@@ -3106,28 +3106,27 @@
 TRING_TYPE, 
-fals
+tru
 e, 0)));%0A%0A%0A 

Update Citizen Kin electoral roll registration model (see pole-numerique/oasis-citizenkin#59)