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);
}
}
}
}
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()));
}
}
Aggregations