2016-06-20 13:57:57 +02:00
|
|
|
class DossierService
|
|
|
|
|
|
|
|
def initialize dossier, siret, france_connect_information
|
|
|
|
@dossier = dossier
|
|
|
|
@siret = siret
|
|
|
|
@france_connect_information = france_connect_information
|
|
|
|
end
|
|
|
|
|
|
|
|
def dossier_informations!
|
2016-10-30 22:59:57 +01:00
|
|
|
@entreprise_adapter = SIADE::EntrepriseAdapter.new(DossierService.siren @siret).to_params
|
2016-06-20 13:57:57 +02:00
|
|
|
|
2016-10-30 22:59:57 +01:00
|
|
|
if @entreprise_adapter[:http_code] == 404
|
2016-08-02 14:45:09 +02:00
|
|
|
raise RestClient::ResourceNotFound
|
2016-10-30 22:59:57 +01:00
|
|
|
elsif @entreprise_adapter[:http_code] == 503 ||
|
|
|
|
@entreprise_adapter[:http_code] == 500 ||
|
|
|
|
@entreprise_adapter[:http_code] == 400
|
|
|
|
raise RestClient::ServiceUnavailable
|
2016-08-02 14:45:09 +02:00
|
|
|
end
|
|
|
|
|
2016-06-22 11:29:59 +02:00
|
|
|
@etablissement_adapter = SIADE::EtablissementAdapter.new(@siret)
|
2016-06-20 13:57:57 +02:00
|
|
|
|
2016-09-16 17:08:50 +02:00
|
|
|
if @etablissement_adapter.to_params.nil?
|
|
|
|
raise RestClient::ResourceNotFound
|
|
|
|
end
|
|
|
|
|
|
|
|
@dossier.create_entreprise(@entreprise_adapter.to_params)
|
2016-06-22 11:29:59 +02:00
|
|
|
@dossier.create_etablissement(@etablissement_adapter.to_params)
|
2016-06-20 13:57:57 +02:00
|
|
|
|
2016-06-22 11:29:59 +02:00
|
|
|
@rna_adapter = SIADE::RNAAdapter.new(@siret)
|
|
|
|
@dossier.entreprise.create_rna_information(@rna_adapter.to_params)
|
2016-06-20 13:57:57 +02:00
|
|
|
|
2016-06-22 11:29:59 +02:00
|
|
|
@exercices_adapter = SIADE::ExercicesAdapter.new(@siret)
|
|
|
|
@dossier.etablissement.exercices.create(@exercices_adapter.to_params)
|
2016-06-20 13:57:57 +02:00
|
|
|
|
|
|
|
@dossier.update_attributes(mandataire_social: mandataire_social?(@entreprise_adapter.mandataires_sociaux))
|
|
|
|
@dossier.etablissement.update_attributes(entreprise: @dossier.entreprise)
|
|
|
|
|
|
|
|
@dossier
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.siren siret
|
|
|
|
siret[0..8]
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def mandataire_social? mandataires_list
|
|
|
|
unless @france_connect_information.nil?
|
|
|
|
|
|
|
|
mandataires_list.each do |mandataire|
|
|
|
|
return true if mandataire[:nom].upcase == @france_connect_information.family_name.upcase &&
|
|
|
|
mandataire[:prenom].upcase == @france_connect_information.given_name.upcase &&
|
|
|
|
mandataire[:date_naissance_timestamp] == @france_connect_information.birthdate.to_time.to_i
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|