Project

General

Profile

« Previous | Next » 

Revision 4079cf73

Added by Andreas Kohlbecker over 6 years ago

ref #7137 using the RegistrationIdentifierMinter and using CDM_DATA_SOURCE_ID from the Spring enviroment

View differences:

src/main/java/eu/etaxonomy/cdm/addon/config/CdmVaadinConfiguration.java
25 25
import org.springframework.context.annotation.ComponentScan.Filter;
26 26
import org.springframework.context.annotation.Configuration;
27 27
import org.springframework.context.annotation.FilterType;
28
import org.springframework.context.annotation.Lazy;
29 28
import org.springframework.core.env.Environment;
30 29
import org.springframework.security.authentication.AuthenticationProvider;
31 30

  
......
38 37
import eu.etaxonomy.cdm.api.application.AbstractDataInserter;
39 38
import eu.etaxonomy.cdm.api.application.CdmRepository;
40 39
import eu.etaxonomy.cdm.api.application.DummyDataInserter;
40
import eu.etaxonomy.cdm.api.service.idminter.RegistrationIdentifierMinter;
41 41
import eu.etaxonomy.cdm.common.ConfigFileUtil;
42 42
import eu.etaxonomy.cdm.dataInserter.RegistrationRequiredDataInserter;
43 43
import eu.etaxonomy.cdm.opt.config.DataSourceConfigurer;
......
73 73
public class CdmVaadinConfiguration implements ApplicationContextAware  {
74 74

  
75 75

  
76
    public static final String CDM_DATA_SOURCE_ID = "cdm.dataSource.id";
76
    public static final String CDM_DATA_SOURCE_ID = DataSourceConfigurer.CDM_DATA_SOURCE_ID;
77 77

  
78 78
    public static final String CDM_VAADIN_UI_ACTIVATED = "cdm-vaadin.ui.activated";
79
    public static final String CDM_SERVICE_MINTER_REGSTRATION_MINID = "cdm.service.minter.registration.minLocalId";
80
    public static final String CDM_SERVICE_MINTER_REGSTRATION_MAXID = "cdm.service.minter.registration.maxLocalId";
81
    public static final String CDM_SERVICE_MINTER_REGSTRATION_IDFORMAT = "cdm.service.minter.registration.identifierFormatString";
79 82

  
80 83
    public static final Logger logger = Logger.getLogger(CdmVaadinConfiguration.class);
81 84

  
82 85
    @Autowired
83 86
    Environment env;
84 87

  
85
    @Autowired
86
    @Lazy
87
    //FIXME consider to set the instanceName (instanceID) in the spring environment to avoid a bean reference here
88
    // key CDM_DATA_SOURCE_ID is already declared here
89
    private DataSourceConfigurer dataSourceConfigurer;
90

  
91 88
    /*
92 89
     * NOTE: It is necessary to map the URLs starting with /VAADIN/* since none of the
93 90
     * @WebServlets is mapped to the root path. It is sufficient to configure one of the
......
162 159
        }
163 160
    }
164 161

  
162
    @Bean
163
    public RegistrationIdentifierMinter registrationIdentifierMinter() throws IOException {
164
        RegistrationIdentifierMinter minter = new RegistrationIdentifierMinter();
165
        ensureVaadinAppPropertiesLoaded();
166
        minter.setMinLocalId(appProps.getProperty(CDM_SERVICE_MINTER_REGSTRATION_MINID));
167
        minter.setMaxLocalId(appProps.getProperty(CDM_SERVICE_MINTER_REGSTRATION_MAXID));
168
        minter.setIdentifierFormatString(appProps.getProperty(CDM_SERVICE_MINTER_REGSTRATION_IDFORMAT));
169
        return minter;
170
    }
171

  
165 172
    @Bean
166 173
    @UIScope
167 174
    public DistributionStatusUI distributionStatusUI() {
......
180 187
        return null;
181 188
    }
182 189

  
183
    static final String PROPERTIES_NAME = "vaadin-apps";
190

  
191

  
192

  
193
    static final String PROPERTIES_FILE_NAME = "vaadin-apps";
184 194

  
185 195
    private Properties appProps = null;
186 196

  
......
208 218
    /**
209 219
     * Checks if the ui class supplied is activated by listing it in the properties by its {@link SpringUI#path()} value.
210 220
     *
221
     * TODO see https://dev.e-taxonomy.eu/redmine/issues/7139 (consider using spring profiles to enable vaadin UI contexts)
222
     *
211 223
     * @param type
212 224
     * @return
213 225
     */
......
217 229

  
218 230
        if(activeUIpaths == null){
219 231
            try {
220
                String currentDataSourceId = env.getProperty(CDM_DATA_SOURCE_ID);
232

  
221 233
                String activatedVaadinUIs = env.getProperty(CDM_VAADIN_UI_ACTIVATED);
222 234
                if(activatedVaadinUIs == null){
223 235
                    // not in environment? Read it from the config file!
224
                    if(appProps == null){
225
                        if(currentDataSourceId == null){
226
                            currentDataSourceId = dataSourceConfigurer.dataSourceProperties().getCurrentDataSourceId();
227
                        }
228
                        appProps = new ConfigFileUtil()
229
                                .setDefaultContent(APP_FILE_CONTENT)
230
                                .getProperties(currentDataSourceId, PROPERTIES_NAME);
231
                    }
236
                    ensureVaadinAppPropertiesLoaded();
232 237
                    if(appProps.get(CDM_VAADIN_UI_ACTIVATED) != null){
233 238
                        activatedVaadinUIs = appProps.get(CDM_VAADIN_UI_ACTIVATED).toString();
234 239
                    }
235 240
                }
241

  
236 242
                if(activatedVaadinUIs != null) {
237 243
                    String[] uiPaths = activatedVaadinUIs.split("\\s*,\\s*");
238 244
                    this.activeUIpaths = Arrays.asList(uiPaths);
......
249 255

  
250 256
    }
251 257

  
258
    /**
259
     * @param currentDataSourceId
260
     * @throws IOException
261
     */
262
    protected void ensureVaadinAppPropertiesLoaded() throws IOException {
263

  
264
        String currentDataSourceId = env.getProperty(CDM_DATA_SOURCE_ID);
265
        if(appProps == null){
266
            appProps = new ConfigFileUtil()
267
                    .setDefaultContent(APP_FILE_CONTENT)
268
                    .getProperties(currentDataSourceId, PROPERTIES_FILE_NAME);
269
        }
270
    }
271

  
252 272
    /**
253 273
     * {@inheritDoc}
254 274
     */
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationWorkingsetPresenter.java
26 26

  
27 27
import eu.etaxonomy.cdm.api.service.INameService;
28 28
import eu.etaxonomy.cdm.api.service.IRegistrationService;
29
import eu.etaxonomy.cdm.api.service.idminter.IdentifierMinter.Identifier;
30
import eu.etaxonomy.cdm.api.service.idminter.RegistrationIdentifierMinter;
29 31
import eu.etaxonomy.cdm.model.common.User;
30 32
import eu.etaxonomy.cdm.model.name.Rank;
31 33
import eu.etaxonomy.cdm.model.name.Registration;
......
73 75
    @Autowired
74 76
    private IRegistrationWorkingSetService workingSetService;
75 77

  
78
    @Autowired
79
    private RegistrationIdentifierMinter minter;
80

  
76 81
    /**
77 82
     * @return the workingSetService
78 83
     */
......
122 127
        // move into RegistrationWorkflowStateMachine
123 128
        TransactionStatus txStatus = getRepo().startTransaction();
124 129
        long identifier = System.currentTimeMillis();
130

  
131
        Identifier<String> identifiers = minter.mint();
132
        if(identifiers.getIdentifier() == null){
133
            throw new RuntimeException("RegistrationIdentifierMinter configuration incomplete.");
134
        }
125 135
        Registration reg = Registration.NewInstance(
126
                "http://phycobank.org/" + identifier,
127
                "" + identifier,
136
                identifiers.getIdentifier(),
137
                identifiers.getLocalId(),
128 138
                taxonNameId != null ? getRepo().getNameService().find(taxonNameId) : null,
129 139
                null);
130 140
        Authentication authentication = currentSecurityContext().getAuthentication();

Also available in: Unified diff