Search in sources :

Example 1 with ModelRepository

use of org.eclipse.vorto.repository.core.impl.ModelRepository in project vorto by eclipse.

the class VortolangUpgradeTask method doUpgrade.

@Override
public void doUpgrade() throws UpgradeProblem {
    setAdminUserContext();
    List<ModelInfo> searchResult = modelSearchService.search("*");
    final String newline = System.getProperty("line.separator");
    for (ModelInfo modelInfo : searchResult) {
        ModelRepository modelRepository = (ModelRepository) repositoryFactory.getRepositoryByModel(modelInfo.getId());
        Optional<FileContent> content = modelRepository.getFileContent(modelInfo.getId(), Optional.of(modelInfo.getFileName()));
        if (content.isPresent()) {
            String currentModelContent = "";
            try {
                currentModelContent = new String(content.get().getContent(), "utf-8");
            } catch (UnsupportedEncodingException e1) {
                logger.warn("Could not set vortolang field for model " + modelInfo.getId().getPrettyFormat() + ".Skipping...", e1);
            }
            if (currentModelContent.contains("vortolang 1.0")) {
                continue;
            }
            StringBuilder contentBuilder = new StringBuilder();
            contentBuilder.append("vortolang 1.0");
            contentBuilder.append(newline);
            contentBuilder.append(newline);
            try {
                contentBuilder.append(currentModelContent);
                logger.info("Upgrading " + modelInfo.toString() + " for vortolang attribute....");
                modelRepository.save(modelInfo.getId(), contentBuilder.toString().getBytes(), modelInfo.getFileName(), UserContext.user(modelInfo.getAuthor(), modelRepository.getWorkspaceId()), false);
                logger.info("Upgrade of " + modelInfo.toString() + " successful.");
            } catch (Throwable e) {
                logger.warn("Could not set vortolang field for model " + modelInfo.getId().getPrettyFormat() + ".Skipping...", e);
            }
        }
    }
}
Also used : FileContent(org.eclipse.vorto.repository.core.FileContent) ModelRepository(org.eclipse.vorto.repository.core.impl.ModelRepository) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 2 with ModelRepository

use of org.eclipse.vorto.repository.core.impl.ModelRepository in project vorto by eclipse.

the class TargetPlatformUpgradeTask method doUpgrade.

@Override
public void doUpgrade() throws UpgradeProblem {
    setAdminUserContext();
    List<ModelInfo> searchResult = modelSearchService.search("type:Mapping");
    for (ModelInfo modelInfo : searchResult) {
        logger.info("Upgrading " + modelInfo.toString() + " for target platform key attribute....");
        ModelRepository modelRepository = (ModelRepository) repositoryFactory.getRepositoryByModel(modelInfo.getId());
        ModelResource mappingModel = modelRepository.getEMFResource(modelInfo.getId());
        modelRepository.save(mappingModel, UserContext.user(modelInfo.getAuthor(), modelRepository.getWorkspaceId()));
    }
}
Also used : ModelRepository(org.eclipse.vorto.repository.core.impl.ModelRepository) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) ModelResource(org.eclipse.vorto.repository.core.ModelResource)

Aggregations

ModelInfo (org.eclipse.vorto.repository.core.ModelInfo)2 ModelRepository (org.eclipse.vorto.repository.core.impl.ModelRepository)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 FileContent (org.eclipse.vorto.repository.core.FileContent)1 ModelResource (org.eclipse.vorto.repository.core.ModelResource)1