-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
261 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...sitory-server/src/main/java/org/eclipse/vorto/repository/upgrade/AbstractUpgradeTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* Copyright (c) 2015-2018 Bosch Software Innovations GmbH and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* and Eclipse Distribution License v1.0 which accompany this distribution. | ||
* | ||
* The Eclipse Public License is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* The Eclipse Distribution License is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
* | ||
* Contributors: | ||
* Bosch Software Innovations GmbH - Please refer to git log | ||
*/ | ||
package org.eclipse.vorto.repository.upgrade; | ||
|
||
import org.eclipse.vorto.repository.api.ModelId; | ||
import org.eclipse.vorto.repository.core.IModelRepository; | ||
import org.eclipse.vorto.repository.core.impl.JcrModelRepository; | ||
import org.eclipse.vorto.repository.core.impl.ModelEMFResource; | ||
|
||
public abstract class AbstractUpgradeTask implements IUpgradeTask { | ||
|
||
private IModelRepository modelRepository; | ||
|
||
public AbstractUpgradeTask(IModelRepository repository) { | ||
this.modelRepository = repository; | ||
} | ||
|
||
protected IModelRepository getModelRepository() { | ||
return modelRepository; | ||
} | ||
|
||
protected ModelEMFResource getModel(ModelId modelId) { | ||
return ((JcrModelRepository)modelRepository).getEMFResource(modelId); | ||
} | ||
|
||
protected void saveModel(ModelEMFResource resource) { | ||
((JcrModelRepository)modelRepository).saveModel(resource); | ||
} | ||
|
||
|
||
} |
20 changes: 20 additions & 0 deletions
20
...repository-server/src/main/java/org/eclipse/vorto/repository/upgrade/IUpgradeService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* Copyright (c) 2015-2018 Bosch Software Innovations GmbH and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* and Eclipse Distribution License v1.0 which accompany this distribution. | ||
* | ||
* The Eclipse Public License is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* The Eclipse Distribution License is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
* | ||
* Contributors: | ||
* Bosch Software Innovations GmbH - Please refer to git log | ||
*/ | ||
package org.eclipse.vorto.repository.upgrade; | ||
|
||
public interface IUpgradeService { | ||
|
||
void installUpgrades(); | ||
} |
45 changes: 45 additions & 0 deletions
45
...po/repository-server/src/main/java/org/eclipse/vorto/repository/upgrade/IUpgradeTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* Copyright (c) 2015-2018 Bosch Software Innovations GmbH and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* and Eclipse Distribution License v1.0 which accompany this distribution. | ||
* | ||
* The Eclipse Public License is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* The Eclipse Distribution License is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
* | ||
* Contributors: | ||
* Bosch Software Innovations GmbH - Please refer to git log | ||
*/ | ||
package org.eclipse.vorto.repository.upgrade; | ||
|
||
/** | ||
* An UpgradeTask is executed when the repository is started up. | ||
* | ||
*/ | ||
public interface IUpgradeTask { | ||
|
||
/** | ||
* Performs the actual upgrade task | ||
* @throws UpgradeProblem | ||
*/ | ||
void doUpgrade() throws UpgradeProblem; | ||
|
||
/** | ||
* @return a short description of the task being performed | ||
*/ | ||
String getShortDescription(); | ||
|
||
public class UpgradeProblem extends RuntimeException { | ||
|
||
/** | ||
* | ||
*/ | ||
private static final long serialVersionUID = 1L; | ||
|
||
public UpgradeProblem(String msg, Throwable t) { | ||
super(msg, t); | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...server/src/main/java/org/eclipse/vorto/repository/upgrade/impl/DefaultUpgradeService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* Copyright (c) 2015-2018 Bosch Software Innovations GmbH and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* and Eclipse Distribution License v1.0 which accompany this distribution. | ||
* | ||
* The Eclipse Public License is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* The Eclipse Distribution License is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
* | ||
* Contributors: | ||
* Bosch Software Innovations GmbH - Please refer to git log | ||
*/ | ||
package org.eclipse.vorto.repository.upgrade.impl; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.eclipse.vorto.repository.upgrade.IUpgradeService; | ||
import org.eclipse.vorto.repository.upgrade.IUpgradeTask; | ||
import org.eclipse.vorto.repository.upgrade.IUpgradeTask.UpgradeProblem; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class DefaultUpgradeService implements IUpgradeService { | ||
|
||
private List<IUpgradeTask> tasks; | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(DefaultUpgradeService.class); | ||
|
||
@Override | ||
public void installUpgrades() { | ||
logger.info("Performing upgrade to the Vorto Repository and its content..."); | ||
for (IUpgradeTask task : tasks) { | ||
logger.info("Executing task - "+task.getShortDescription()); | ||
try { | ||
task.doUpgrade(); | ||
} catch (UpgradeProblem problem ) { | ||
logger.error("Problem executing upgrade task",problem); | ||
} | ||
} | ||
} | ||
|
||
public void addTasks(IUpgradeTask...tasks) { | ||
this.tasks = Arrays.asList(tasks); | ||
} | ||
|
||
} |
70 changes: 70 additions & 0 deletions
70
...repository-server/src/test/java/org/eclipse/vorto/repository/upgrade/UpgradeTaskTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/** | ||
* Copyright (c) 2015-2018 Bosch Software Innovations GmbH and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* and Eclipse Distribution License v1.0 which accompany this distribution. | ||
* | ||
* The Eclipse Public License is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* The Eclipse Distribution License is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
* | ||
* Contributors: | ||
* Bosch Software Innovations GmbH - Please refer to git log | ||
*/ | ||
package org.eclipse.vorto.repository.upgrade; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNull; | ||
|
||
import org.eclipse.vorto.repository.AbstractIntegrationTest; | ||
import org.eclipse.vorto.repository.api.ModelInfo; | ||
import org.eclipse.vorto.repository.core.IModelRepository; | ||
import org.eclipse.vorto.repository.core.impl.ModelEMFResource; | ||
import org.eclipse.vorto.repository.upgrade.impl.DefaultUpgradeService; | ||
import org.junit.Test; | ||
|
||
public class UpgradeTaskTest extends AbstractIntegrationTest { | ||
|
||
@Test | ||
public void testUpgradeFileContent() { | ||
checkinModel("Color.type", "alex"); | ||
ModelEMFResource resource = (ModelEMFResource)modelRepository.getEMFResource(modelRepository.search("*").get(0).getId()); | ||
assertNull(resource.getModel().getCategory()); | ||
DefaultUpgradeService service = new DefaultUpgradeService(); | ||
service.addTasks(new AddCategoryUpgradeTask(this.modelRepository)); | ||
|
||
service.installUpgrades(); | ||
|
||
resource = (ModelEMFResource)modelRepository.getEMFResource(modelRepository.search("*").get(0).getId()); | ||
assertEquals("iot",resource.getModel().getCategory()); | ||
|
||
} | ||
|
||
|
||
private class AddCategoryUpgradeTask extends AbstractUpgradeTask { | ||
|
||
public AddCategoryUpgradeTask(IModelRepository repo) { | ||
super(repo); | ||
} | ||
|
||
@Override | ||
public void doUpgrade() throws UpgradeProblem { | ||
for (ModelInfo model : modelRepository.search("*")) { | ||
ModelEMFResource resource = getModel(model.getId()); | ||
if (resource.getModel().getCategory() == null) { | ||
resource.getModel().setCategory("iot"); | ||
modelRepository.saveModel(resource); | ||
} | ||
|
||
} | ||
} | ||
|
||
@Override | ||
public String getShortDescription() { | ||
return "Adding category 'iot' to models without category."; | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters