Project

General

Profile

Download (24.2 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2017 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.dataInserter;
10

    
11
import java.util.ArrayList;
12
import java.util.Arrays;
13
import java.util.EnumSet;
14
import java.util.HashMap;
15
import java.util.List;
16
import java.util.Map;
17
import java.util.Set;
18
import java.util.UUID;
19

    
20
import org.apache.logging.log4j.Level;
21
import org.apache.logging.log4j.LogManager;
22
import org.apache.logging.log4j.Logger;
23
import org.hibernate.Session;
24
import org.springframework.context.event.ContextRefreshedEvent;
25
import org.springframework.security.authentication.AuthenticationCredentialsNotFoundException;
26
import org.springframework.security.core.GrantedAuthority;
27
import org.springframework.transaction.TransactionStatus;
28
import org.springframework.transaction.annotation.Transactional;
29

    
30
import eu.etaxonomy.cdm.api.application.AbstractDataInserter;
31
import eu.etaxonomy.cdm.api.application.CdmRepository;
32
import eu.etaxonomy.cdm.api.service.pager.Pager;
33
import eu.etaxonomy.cdm.common.LogUtils;
34
import eu.etaxonomy.cdm.model.agent.Institution;
35
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
36
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
37
import eu.etaxonomy.cdm.model.name.Rank;
38
import eu.etaxonomy.cdm.model.name.TaxonName;
39
import eu.etaxonomy.cdm.model.permission.CRUD;
40
import eu.etaxonomy.cdm.model.permission.GrantedAuthorityImpl;
41
import eu.etaxonomy.cdm.model.permission.Group;
42
import eu.etaxonomy.cdm.model.permission.PermissionClass;
43
import eu.etaxonomy.cdm.model.taxon.Taxon;
44
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
45
import eu.etaxonomy.cdm.model.term.DefinedTerm;
46
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
47
import eu.etaxonomy.cdm.model.term.TermVocabulary;
48
import eu.etaxonomy.cdm.persistence.dao.common.IPreferenceDao;
49
import eu.etaxonomy.cdm.persistence.dao.hibernate.taxonGraph.AbstractHibernateTaxonGraphProcessor;
50
import eu.etaxonomy.cdm.persistence.dao.taxonGraph.TaxonGraphException;
51
import eu.etaxonomy.cdm.persistence.permission.CdmAuthority;
52
import eu.etaxonomy.cdm.persistence.permission.Role;
53
import eu.etaxonomy.cdm.vaadin.model.registration.KindOfUnitTerms;
54
import eu.etaxonomy.cdm.vaadin.permission.RolesAndPermissions;
55

    
56
///*
57
// * Can create missing registrations for names which have Extensions of the Type <code>IAPTRegdata.json</code>.
58
//* See https://dev.e-taxonomy.eu/redmine/issues/6621 for further details.
59
//* This feature can be activated by by supplying one of the following jvm command line arguments:
60
//* <ul>
61
//* <li><code>-DregistrationCreate=iapt</code>: create all iapt Registrations if missing</li>
62
//* <li><code>-DregistrationWipeout=iapt</code>: remove all iapt Registrations</li>
63
//* <li><code>-DregistrationWipeout=all</code>: remove all Registrations</li>
64
//* </ul>
65
//* The <code>-DregistrationWipeout</code> commands are executed before the <code>-DregistrationCreate</code> and will not change the name and type designations.
66
//*/
67
/**
68
 * This feature can be activated by by supplying one of the following jvm command line arguments:
69
 * <ul>
70
 *   <li><code>-DtaxonGraphCreate=true</code>: create taxon graph relations for all names below genus level</li>
71
 * </ul>
72
 *
73
 * @author a.kohlbecker
74
 * @since May 9, 2017
75
 */
76
public class RegistrationRequiredDataInserter extends AbstractDataInserter {
77

    
78
    private final static Logger logger = LogManager.getLogger();
79

    
80
//    protected static final String PARAM_NAME_CREATE = "registrationCreate";
81
//
82
//    protected static final String PARAM_NAME_WIPEOUT = "registrationWipeout";
83

    
84
    protected static final String TAXON_GRAPH_CREATE = "taxonGraphCreate";
85

    
86
    protected static final UUID GROUP_SUBMITTER_UUID = UUID.fromString("c468c6a7-b96c-4206-849d-5a825f806d3e");
87

    
88
    protected static final UUID GROUP_CURATOR_UUID = UUID.fromString("135210d3-3db7-4a81-ab36-240444637d45");
89

    
90
    private static final EnumSet<CRUD> CREATE_READ = EnumSet.of(CRUD.CREATE, CRUD.READ);
91
    private static final EnumSet<CRUD> CREATE_READ_UPDATE_DELETE = EnumSet.of(CRUD.CREATE, CRUD.READ, CRUD.UPDATE, CRUD.DELETE);
92

    
93

    
94
//    private ExtensionType extensionTypeIAPTRegData;
95

    
96
    private Map<String, Institution> instituteMap = new HashMap<>();
97

    
98
    public static boolean commandsExecuted = false;
99

    
100
    private CdmRepository repo;
101

    
102
    private boolean hasRun = false;
103

    
104
    public void setCdmRepository(CdmRepository repo){
105
      this.repo = repo;
106
    }
107

    
108
    @Override
109
    public void onApplicationEvent(ContextRefreshedEvent event) {
110
        if(hasRun){
111
            return;
112
        }
113
        runAsAuthentication(Role.ROLE_ADMIN);
114
        insertRequiredData();
115
        executeSuppliedCommands();
116
        restoreAuthentication();
117
        hasRun = true;
118
    }
119

    
120
    @Transactional
121
    private void insertRequiredData() {
122

    
123
        TransactionStatus txStatus = repo.startTransaction(false);
124

    
125
        Role roleCuration = RolesAndPermissions.ROLE_CURATION;
126
        if(repo.getGrantedAuthorityService().find(roleCuration.getUuid()) == null){
127
            repo.getGrantedAuthorityService().saveOrUpdate(roleCuration.asNewGrantedAuthority());
128
        }
129

    
130
        Group groupCurator = repo.getGroupService().load(GROUP_CURATOR_UUID, Arrays.asList("grantedAuthorities"));
131
        if(groupCurator == null){
132
            groupCurator = Group.NewInstance();
133
            groupCurator.setUuid(GROUP_CURATOR_UUID);
134
            groupCurator.setName("Curator");
135
        }
136
        assureGroupHas(groupCurator, new CdmAuthority(PermissionClass.REGISTRATION, CREATE_READ_UPDATE_DELETE).toString());
137
        repo.getGroupService().saveOrUpdate(groupCurator);
138

    
139
        Group groupSubmitter = repo.getGroupService().load(GROUP_SUBMITTER_UUID, Arrays.asList("grantedAuthorities"));
140
        if(groupSubmitter == null){
141
            groupSubmitter = Group.NewInstance();
142
            groupSubmitter.setUuid(GROUP_SUBMITTER_UUID);
143
            groupSubmitter.setName("Submitter");
144
        }
145
        assureGroupHas(groupSubmitter, new CdmAuthority(PermissionClass.TAXONNAME, CREATE_READ).toString());
146
        assureGroupHas(groupSubmitter, new CdmAuthority(PermissionClass.TEAMORPERSONBASE, CREATE_READ).toString());
147
        assureGroupHas(groupSubmitter, new CdmAuthority(PermissionClass.REGISTRATION, CREATE_READ).toString());
148
        assureGroupHas(groupSubmitter, new CdmAuthority(PermissionClass.REFERENCE, CREATE_READ).toString());
149
        assureGroupHas(groupSubmitter, new CdmAuthority(PermissionClass.SPECIMENOROBSERVATIONBASE, CREATE_READ).toString());
150
        assureGroupHas(groupSubmitter, new CdmAuthority(PermissionClass.COLLECTION, CREATE_READ).toString());
151
        repo.getGroupService().saveOrUpdate(groupSubmitter);
152

    
153
        TermVocabulary<DefinedTerm> kindOfUnitVocabulary = repo.getVocabularyService().find(KindOfUnitTerms.KIND_OF_UNIT_VOCABULARY().getUuid());
154
        if(kindOfUnitVocabulary == null){
155
            kindOfUnitVocabulary = repo.getVocabularyService().save(KindOfUnitTerms.KIND_OF_UNIT_VOCABULARY());
156
        }
157

    
158
        DefinedTermBase<?> kouSpecimen = repo.getTermService().find(KindOfUnitTerms.SPECIMEN().getUuid());
159
        DefinedTermBase<?> kouImage = repo.getTermService().find(KindOfUnitTerms.PUBLISHED_IMAGE().getUuid());
160
        DefinedTermBase<?> kouUnpublishedImage = repo.getTermService().find(KindOfUnitTerms.UNPUBLISHED_IMAGE().getUuid());
161
        DefinedTermBase<?> kouCulture = repo.getTermService().find(KindOfUnitTerms.CULTURE_METABOLIC_INACTIVE().getUuid());
162

    
163
        if(kouSpecimen == null){
164
            kouSpecimen = repo.getTermService().save(KindOfUnitTerms.SPECIMEN());
165
        }
166
        if(kouImage == null){
167
            kouImage = repo.getTermService().save(KindOfUnitTerms.PUBLISHED_IMAGE());
168
        }
169
        if(kouUnpublishedImage == null){
170
            kouUnpublishedImage = repo.getTermService().save(KindOfUnitTerms.UNPUBLISHED_IMAGE());
171
        }
172
        if(kouCulture == null){
173
            kouCulture = repo.getTermService().save(KindOfUnitTerms.CULTURE_METABOLIC_INACTIVE());
174
        }
175

    
176
        Set<DefinedTerm> termInVocab = kindOfUnitVocabulary.getTerms();
177
        List<DefinedTermBase> kouTerms = Arrays.asList(kouCulture, kouImage, kouSpecimen, kouUnpublishedImage);
178

    
179
        for(DefinedTermBase<?> t : kouTerms){
180
            if(!termInVocab.contains(t)){
181
                kindOfUnitVocabulary.addTerm((DefinedTerm)t);
182
            }
183
        }
184

    
185
        repo.commitTransaction(txStatus);
186

    
187
    }
188

    
189
    private void assureGroupHas(Group group, String authorityString){
190
        boolean authorityExists = false;
191

    
192
        for(GrantedAuthority ga : group.getGrantedAuthorities()){
193
            if((authorityExists = ga.getAuthority().equals(authorityString)) == true){
194
                break;
195
            }
196
        }
197
        if(!authorityExists){
198
            group.addGrantedAuthority(findGrantedAuthority(authorityString));
199
        }
200
    }
201

    
202
    private GrantedAuthorityImpl findGrantedAuthority(String authorityString){
203
        GrantedAuthorityImpl ga = null;
204
        try{
205
            ga = repo.getGrantedAuthorityService().findAuthorityString(authorityString);
206
        } catch (AuthenticationCredentialsNotFoundException e){
207
            e.printStackTrace();
208
        }
209
        if(ga == null){
210
            ga = GrantedAuthorityImpl.NewInstance(authorityString);
211
            repo.getGrantedAuthorityService().save(ga);
212
        }
213
        return ga;
214
    }
215

    
216
    private void executeSuppliedCommands() {
217

    
218
        if(commandsExecuted){
219
            // do not run twice
220
            // a second run could take place during initialization of the web context
221
            return;
222
        }
223
        commandsExecuted  = true;
224

    
225
        String taxonGraphCreate = System.getProperty(TAXON_GRAPH_CREATE);
226

    
227
        if(taxonGraphCreate != null){
228
            IPreferenceDao prefDao = (IPreferenceDao) repo.getBean("preferenceDao");
229

    
230
            AbstractHibernateTaxonGraphProcessor processor = new AbstractHibernateTaxonGraphProcessor(prefDao) {
231
                @Override
232
                public Session getSession() {
233
                    return repo.getSession();
234
                }
235
            };
236
            LogUtils.setLevel(logger, Level.DEBUG);
237
            int chunksize = 1000;
238
            int pageIndex = 0;
239
            TransactionStatus tx;
240
            Pager<Taxon> taxonPage;
241
            List<TaxonBase> taxa = new ArrayList<>();
242
            logger.debug("======= fixing sec refrences =========");
243
            while(true){
244
                tx = repo.startTransaction(false);
245
                taxonPage = repo.getTaxonService().page(Taxon.class, chunksize, pageIndex++, null, null);
246
                if(taxonPage.getRecords().size() == 0){
247
                    repo.commitTransaction(tx);
248
                    break;
249
                }
250
                for(Taxon taxon : taxonPage.getRecords()){
251
                    taxon.setSec(processor.secReference());
252
                    repo.getTaxonService().saveOrUpdate(taxon);
253
                }
254
                repo.commitTransaction(tx);
255
            }
256

    
257
            logger.debug("======= creating taxon graph =========");
258
            pageIndex = 0;
259
            Pager<TaxonName> page;
260
            while(true){
261
               tx = repo.startTransaction(false);
262
               page = repo.getNameService().page(null, chunksize, pageIndex++, null, null);
263
               if(page.getRecords().size() == 0){
264
                   repo.commitTransaction(tx);
265
                   break;
266
               }
267
               logger.debug(TAXON_GRAPH_CREATE + ": chunk " + pageIndex + "/" + Math.ceil(page.getCount() / chunksize));
268
               taxa = new ArrayList<>();
269

    
270
               for(TaxonName name : page.getRecords()){
271
                   if(name.getRank() != null && name.getRank().isLower(Rank.GENUS())){
272
                       NomenclaturalStatusType illegitimType = findILegitimateStatusType(name);
273
                       if(illegitimType == null){
274
                           Taxon taxon;
275
                           try {
276
                               logger.debug("Processing name: " + name.getTitleCache() + " [" + name.getRank().getLabel() + "]");
277
                               taxon = processor.assureSingleTaxon(name);
278
                               processor.updateEdges(taxon);
279
                               taxa.add(taxon);
280
                           } catch (TaxonGraphException e) {
281
                               logger.error(e.getMessage());
282
                           }
283
                       } else {
284
                           logger.debug("Skipping illegitimate name: " + name.getTitleCache() + " " + illegitimType.getLabel() + " [" + name.getRank().getLabel() + "]");
285
                       }
286
                   } else {
287
                       logger.debug("Skipping name: " + name.getTitleCache() + " [" + (name.getRank() != null ? name.getRank().getLabel() : "NULL") + "]");
288
                   }
289
               }
290
               repo.getTaxonService().saveOrUpdate(taxa);
291
               repo.commitTransaction(tx);
292
            }
293
        }
294

    
295
//        String wipeoutCmd = System.getProperty(PARAM_NAME_WIPEOUT);
296
//        String createCmd = System.getProperty(PARAM_NAME_CREATE);
297
//
298
//        // ============ DELETE
299
//        if(wipeoutCmd != null && wipeoutCmd.matches("iapt|all")){
300
//
301
//            boolean onlyIapt = wipeoutCmd.equals("iapt");
302
//            Set<UUID> deleteCandidates = new HashSet<UUID>();
303
//
304
//            TransactionStatus tx = repo.startTransaction(true);
305
//            List<Registration> allRegs = repo.getRegistrationService().list(null, null, null, null, null);
306
//            for(Registration reg : allRegs){
307
//                if(onlyIapt){
308
//                    try {
309
//                        @SuppressWarnings("unchecked")
310
//                        Set<String> extensions = reg.getName().getExtensions(getExtensionTypeIAPTRegData());
311
//                        if(reg.getUuid() != null){
312
//                            deleteCandidates.add(reg.getUuid());
313
//                        }
314
//                    } catch(NullPointerException e){
315
//                        // IGNORE
316
//                    }
317
//                } else {
318
//                    if(reg.getUuid() != null){
319
//                        deleteCandidates.add(reg.getUuid());
320
//                    }
321
//                }
322
//            }
323
//            repo.commitTransaction(tx);
324
//            if(!deleteCandidates.isEmpty()){
325
//                try {
326
//                    repo.getRegistrationService().delete(deleteCandidates);
327
//                } catch (Exception e) {
328
//                    // MySQLIntegrityConstraintViolationException happens here every second run !!!
329
//                    logger.error(e);
330
//                }
331
//            }
332
//        }
333
//
334
//        // ============ CREATE
335
//        int pageIndex = 0;
336
//        if(createCmd != null && createCmd.equals("iapt")){
337
//
338
//            DateTimeFormatter dateFormat1 = org.joda.time.format.DateTimeFormat.forPattern("dd.MM.yy").withPivotYear(1950);
339
//            DateTimeFormatter dateFormat2 = org.joda.time.format.DateTimeFormat.forPattern("yyyy-MM-dd").withPivotYear(1950);
340
//
341
//            TransactionStatus tx = repo.startTransaction(false);
342
//            while(true) {
343
//                Pager<TaxonName> pager = repo.getNameService().page(null, 1000, pageIndex, null, null);
344
//                if(pager.getRecords().isEmpty()){
345
//                    break;
346
//                }
347
//                List<Registration> newRegs = new ArrayList<>(pager.getRecords().size());
348
//                for(TaxonName name : pager.getRecords()){
349
//
350
//
351
//
352
//                    Set<String> extensionValues = name.getExtensions(getExtensionTypeIAPTRegData());
353
//
354
//                    // there is for sure only one
355
//                    if(extensionValues.isEmpty()){
356
//                        continue;
357
//                    }
358
//
359
//                    logger.debug("IAPT Registration for " + name.getTitleCache() + " ...");
360
//
361
//                    String iaptJson = extensionValues.iterator().next();
362
//                    try {
363
//
364
//                        IAPTRegData iaptData = new ObjectMapper().readValue(iaptJson, IAPTRegData.class);
365
//
366
//                        if(iaptData.getRegId() == null){
367
//                            continue;
368
//                        }
369
//
370
//                        DateTime regDate = null;
371
//                        if(iaptData.getDate() != null){
372
//                            DateTimeFormatter dateFormat;
373
//                            if(iaptData.getDate().matches("\\d{4}-\\d{2}-\\d{2}")){
374
//                                dateFormat = dateFormat2;
375
//                            } else {
376
//                                dateFormat = dateFormat1;
377
//                            }
378
//                            try {
379
//                                regDate = dateFormat.parseDateTime(iaptData.getDate());
380
//                                regDate.getYear();
381
//                            } catch (Exception e) {
382
//                                logger.error("Error parsing date : " + iaptData.getDate(), e);
383
//                                continue;
384
//                            }
385
//                        }
386
//
387
//                        Registration reg = Registration.NewInstance();
388
//                        reg.setStatus(RegistrationStatus.PUBLISHED);
389
//                        reg.setIdentifier("http://phycobank.org/" + iaptData.getRegId());
390
//                        reg.setSpecificIdentifier(iaptData.getRegId().toString());
391
//                        reg.setInstitution(getInstitution(iaptData.getOffice()));
392
//
393
//                        boolean isPhycobankID = Integer.valueOf(reg.getSpecificIdentifier()) >= 100000;
394
//
395
//                        Partial youngestDate = null;
396
//                        Reference youngestPub = null;
397
//
398
//                        // find youngest publication
399
//
400
//                        // NOTE:
401
//                        // data imported from IAPT does not have typedesignation citations and sometimes no nomref
402
//
403
//                        if(isPhycobankID){
404
//                            youngestPub = name.getNomenclaturalReference();
405
//                            youngestDate = partial(youngestPub.getDatePublished());
406
//
407
//                            if(name.getTypeDesignations() != null && !name.getTypeDesignations().isEmpty()){
408
//                                for(TypeDesignationBase<?> td : name.getTypeDesignations()){
409
//                                    if(td.getCitation() == null){
410
//                                        continue;
411
//                                    }
412
//                                    Partial pubdate = partial(td.getCitation().getDatePublished());
413
//                                    if(pubdate != null){
414
//
415
//                                        try {
416
//                                            if(youngestDate== null || earlierThanOther(youngestDate, pubdate)){
417
//                                                youngestDate = pubdate;
418
//                                                youngestPub = td.getCitation();
419
//                                            }
420
//                                        } catch (Exception e) {
421
//                                            logger.error("Error comparing " + youngestDate + " with" + pubdate , e);
422
//                                        }
423
//                                    }
424
//                                }
425
//                            }
426
//                        }
427
//
428
//                        if((isPhycobankID && youngestPub == name.getNomenclaturalReference()) || !isPhycobankID) {
429
//                            reg.setName(name);
430
//                        } else {
431
//                            logger.debug("skipping name published in older referece");
432
//                        }
433
//                        if(name.getTypeDesignations() != null && !name.getTypeDesignations().isEmpty()){
434
//                            // do not add the collection directly to avoid "Found shared references to a collection" problem
435
//                            Set<TypeDesignationBase> typeDesignations = new HashSet<>(name.getTypeDesignations().size());
436
//                            for(TypeDesignationBase<?> td : name.getTypeDesignations()){
437
//                                if(td.getCitation() == null && isPhycobankID){
438
//                                    logger.error("Missing TypeDesignation Citation in Phycobank data");
439
//                                    continue;
440
//                                }
441
//                                if((isPhycobankID && youngestPub == td.getCitation()) || !isPhycobankID){
442
//                                    typeDesignations.add(td);
443
//                                } else {
444
//                                    logger.debug("skipping typedesignation published in older reference");
445
//                                }
446
//                            }
447
//                            reg.setTypeDesignations(typeDesignations);
448
//                        }
449
//                        reg.setRegistrationDate(regDate);
450
//                        newRegs.add(reg);
451
//
452
//                    } catch (JsonParseException e) {
453
//                        logger.error("Error parsing IAPTRegData from extension", e);
454
//                    } catch (JsonMappingException e) {
455
//                        logger.error("Error mapping json from extension to IAPTRegData", e);
456
//                    } catch (IOException e) {
457
//                        logger.error(e);
458
//                    }
459
//
460
//                }
461
//                repo.getRegistrationService().save(newRegs);
462
//                tx.flush();
463
//                logger.debug("Registrations saved");
464
//                pageIndex++;
465
//            }
466
//            repo.commitTransaction(tx);
467
//        }
468

    
469
    }
470

    
471
    private NomenclaturalStatusType findILegitimateStatusType(TaxonName name){
472
        for(NomenclaturalStatus status : name.getStatus()){
473
            if(status.getType() != null && !status.getType().isLegitimate()){
474
                return status.getType();
475
            }
476
        }
477
        return null;
478
    }
479

    
480

    
481
//    /**
482
//     * @param youngestDate
483
//     * @param pubdate
484
//     * @return
485
//     */
486
//    private boolean earlierThanOther(Partial basePartial, Partial other) {
487
//
488
//        if(basePartial == null || basePartial.getValues().length == 0){
489
//            return false;
490
//        }
491
//        if(other == null || other.getValues().length == 0){
492
//            return true;
493
//        }
494
//        if(basePartial.size() == other.size()) {
495
//            return basePartial.compareTo(other) < 0;
496
//        }
497
//        basePartial = basePartial.without(DateTimeFieldType.dayOfMonth());
498
//        other = other.without(DateTimeFieldType.dayOfMonth());
499
//        if(basePartial.size() == other.size()) {
500
//            return basePartial.compareTo(other) < 0;
501
//        }
502
//        basePartial = basePartial.without(DateTimeFieldType.monthOfYear());
503
//        other = other.without(DateTimeFieldType.monthOfYear());
504
//        return basePartial.compareTo(other) < 0;
505
//
506
//    }
507

    
508

    
509
//    /**
510
//     * @param datePublished
511
//     * @return
512
//     */
513
//    private Partial partial(TimePeriod datePublished) {
514
//        if(datePublished != null){
515
//            if(datePublished.getEnd() != null){
516
//                return datePublished.getEnd();
517
//            } else {
518
//                return datePublished.getStart();
519
//            }
520
//        }
521
//        return null;
522
//    }
523

    
524

    
525
//    /**
526
//     * @param office
527
//     * @return
528
//     */
529
//    private Institution getInstitution(String office) {
530
//        Institution institution;
531
//        if(instituteMap.containsKey(office)){
532
//            institution = instituteMap.get(office);
533
//        } else {
534
//
535
//            Pager<Institution> pager = repo.getAgentService().findByTitleWithRestrictions(Institution.class, office, MatchMode.EXACT, null, null, null, null, null);
536
//   )         if(!pager.getRecords().isEmpty()){
537
//                institution =  pager.getRecords().get(0);
538
//            } else {
539
//                Institution institute = (Institution) repo.getAgentService().save(Institution.NewNamedInstance(office));
540
//                institution = institute;
541
//            }
542
//            instituteMap.put(office, institution);
543
//        }
544
//        return institution;
545
//    }
546

    
547

    
548
//    private ExtensionType getExtensionTypeIAPTRegData() {
549
//        if(extensionTypeIAPTRegData == null){
550
//            extensionTypeIAPTRegData = (ExtensionType) repo.getTermService().load(UUID.fromString("9be1bfe3-6ba0-4560-af15-86971ab96e09"));
551
//        }
552
//        return extensionTypeIAPTRegData;
553
//    }
554

    
555

    
556
}
(2-2/2)