@Override
  public void upgrade() {
    LOG.info("Updating metadata from version 6 to 7");
    List<String> sqls =
        Arrays.asList(
            "ALTER TABLE attributes ADD COLUMN visibleExpression TEXT",
            "ALTER TABLE attributes ADD COLUMN validationExpression TEXT");

    sqls.forEach(
        sql -> {
          try {
            LOG.info(sql);
            jdbcTemplate.execute(sql);
          } catch (DataAccessException e) {
            LOG.error(e.getMessage());
          }
        });
    LOG.info("Create bare mysql repository collection for the metadata...");

    DataServiceImpl dataService = new DataServiceImpl();

    // Get the undecorated repos
    MysqlRepositoryCollection undecoratedMySQL =
        new MysqlRepositoryCollection() {
          @Override
          protected MysqlRepository createMysqlRepository() {
            return new MysqlRepository(
                dataService, dataSource, new AsyncJdbcTemplate(new JdbcTemplate(dataSource)));
          }

          @Override
          public boolean hasRepository(String name) {
            throw new UnsupportedOperationException();
          }
        };
    MetaDataService metaData = new MetaDataServiceImpl(dataService);
    RunAsSystemProxy.runAsSystem(() -> metaData.setDefaultBackend(undecoratedMySQL));

    searchService.delete(AttributeMetaDataMetaData.ENTITY_NAME);
    searchService.createMappings(AttributeMetaDataMetaData.INSTANCE);

    searchService.rebuildIndex(
        undecoratedMySQL.getRepository(AttributeMetaDataMetaData.ENTITY_NAME),
        AttributeMetaDataMetaData.INSTANCE);
  }
Пример #2
0
 public void bootstrap() {
   if (!searchService.hasMapping(AttributeMetadata.ATTRIBUTE_META_DATA)) {
     LOG.debug(
         "No index for Attribute found, asuming missing index, schedule (re)index for all entities");
     metaDataService
         .getRepositories()
         .forEach(repo -> indexActionRegisterService.register(repo.getName(), null));
     LOG.debug("Done scheduling (re)index jobs for all entities");
   } else {
     LOG.debug("Index for Attribute found, index is present, no (re)index needed");
     List<IndexJobExecution> failedIndexJobs =
         dataService
             .findAll(
                 IndexJobExecutionMeta.INDEX_JOB_EXECUTION,
                 new QueryImpl<IndexJobExecution>().eq(JobExecutionMetaData.STATUS, FAILED),
                 IndexJobExecution.class)
             .collect(Collectors.toList());
     failedIndexJobs.forEach(job -> registerNewIndexActionForDirtyJobs(job));
   }
 }