Search in sources :

Example 1 with IEditorCommitableProcessor

use of org.alien4cloud.tosca.editor.processors.IEditorCommitableProcessor in project alien4cloud by alien4cloud.

the class EditorService method doSave.

private void doSave() throws IOException {
    EditionContext context = EditionContextManager.get();
    if (context.getLastOperationIndex() <= context.getLastSavedOperationIndex()) {
        // nothing to save..
        return;
    }
    StringBuilder commitMessage = new StringBuilder();
    // copy and cleanup all temporary files from the executed operations.
    for (int i = context.getLastSavedOperationIndex() + 1; i <= context.getLastOperationIndex(); i++) {
        AbstractEditorOperation operation = context.getOperations().get(i);
        IEditorOperationProcessor<?> processor = (IEditorOperationProcessor) processorMap.get(operation.getClass());
        if (processor instanceof IEditorCommitableProcessor) {
            ((IEditorCommitableProcessor) processor).beforeCommit(operation);
        }
        commitMessage.append(operation.getAuthor()).append(": ").append(operation.commitMessage()).append("\n");
    }
    saveYamlAndZipFile();
    Topology topology = EditionContextManager.getTopology();
    // Save the topology in elastic search
    topologyServiceCore.save(topology);
    // Topology has changed means that dependencies might have changed, must update the dependencies
    csarService.setDependencies(EditionContextManager.getCsar(), topology.getDependencies());
    // update substitution type if needed
    topologySubstitutionServive.updateSubstitutionType(topology, EditionContextManager.getCsar());
    // Local git commit
    repositoryService.commit(EditionContextManager.get().getCsar(), commitMessage.toString());
    // TODO add support for undo even after save, this require ability to rollback files to git state, we need file rollback support for that..
    context.setOperations(Lists.newArrayList(context.getOperations().subList(context.getLastOperationIndex() + 1, context.getOperations().size())));
    context.setLastOperationIndex(-1);
}
Also used : AbstractEditorOperation(org.alien4cloud.tosca.editor.operations.AbstractEditorOperation) IEditorCommitableProcessor(org.alien4cloud.tosca.editor.processors.IEditorCommitableProcessor) Topology(org.alien4cloud.tosca.model.templates.Topology) IEditorOperationProcessor(org.alien4cloud.tosca.editor.processors.IEditorOperationProcessor)

Aggregations

AbstractEditorOperation (org.alien4cloud.tosca.editor.operations.AbstractEditorOperation)1 IEditorCommitableProcessor (org.alien4cloud.tosca.editor.processors.IEditorCommitableProcessor)1 IEditorOperationProcessor (org.alien4cloud.tosca.editor.processors.IEditorOperationProcessor)1 Topology (org.alien4cloud.tosca.model.templates.Topology)1