Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PlantUmlJob extension with system and allocation. #55

Merged
merged 3 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.emf.common.util.URI;
import org.palladiosimulator.pcm.allocation.Allocation;
import org.palladiosimulator.pcm.repository.Repository;
import org.palladiosimulator.pcm.system.System;
import org.palladiosimulator.retriever.extraction.blackboard.RetrieverBlackboard;
import org.palladiosimulator.retriever.extraction.engine.RetrieverConfiguration;
import org.palladiosimulator.view.plantuml.generator.PcmAllocationDiagramGenerator;
import org.palladiosimulator.view.plantuml.generator.PcmComponentDiagramGenerator;
import org.palladiosimulator.view.plantuml.generator.PcmSystemDiagramGenerator;

import de.uka.ipd.sdq.workflow.jobs.AbstractBlackboardInteractingJob;
import de.uka.ipd.sdq.workflow.jobs.CleanupFailedException;
Expand All @@ -25,59 +29,90 @@

public class PlantUmlJob extends AbstractBlackboardInteractingJob<RetrieverBlackboard> {

private static final Logger LOG = Logger.getLogger(PlantUmlJob.class);
private static final String ALLOCATION_DIAGRAM_NAME = "allocationDiagram.puml";
private static final String COMPONENT_DIAGRAM_NAME = "componentDiagram.puml";
private static final String END_UML = "\n@enduml\n";
private static final String JOB_NAME = "Retriever PlantUML Generation";
private static final Logger LOGGER = Logger.getLogger(PlantUmlJob.class);
private static final String START_UML = "@startuml\n";
private static final String SYSTEM_DIAGRAM_NAME = "systemDiagram.puml";

private static final String NAME = "Retriever PlantUML Generation";
private final String allocationKey;
private final URI outputFolder;
private final String repositoryKey;
private final String systemKey;

private final RetrieverConfiguration configuration;
public PlantUmlJob(final RetrieverBlackboard blackboard, final URI outputFolder, final String repositoryKey,
final String systemKey, final String allocationKey) {
super.setBlackboard(Objects.requireNonNull(blackboard));
this.repositoryKey = Objects.requireNonNull(repositoryKey);
this.systemKey = Objects.requireNonNull(systemKey);
this.allocationKey = Objects.requireNonNull(allocationKey);
this.outputFolder = Objects.requireNonNull(outputFolder);

public PlantUmlJob(final RetrieverConfiguration configuration, final RetrieverBlackboard blackboard) {
super.setBlackboard(blackboard);
this.configuration = Objects.requireNonNull(configuration);
}

@Override
public void cleanup(final IProgressMonitor arg0) throws CleanupFailedException {
// No cleanup required.
}

@Override
public void execute(final IProgressMonitor arg0) throws JobFailedException, UserCanceledException {
final PcmComponentDiagramGenerator generator = new PcmComponentDiagramGenerator(
(Repository) this.getBlackboard()
.getPartition(RetrieverBlackboard.KEY_REPOSITORY));
final String plantUmlSource = "@startuml\n" + generator.getDiagramText() + "\n@enduml\n";
final Repository repository = (Repository) this.getBlackboard()
.getPartition(this.repositoryKey);
if ((repository != null) && !repository.eContents()
.isEmpty()) {
this.writeFile(arg0, START_UML + new PcmComponentDiagramGenerator(repository).getDiagramText() + END_UML,
COMPONENT_DIAGRAM_NAME);
}

final System system = (System) this.getBlackboard()
.getPartition(this.systemKey);
if ((system != null) && !system.eContents()
.isEmpty()) {
this.writeFile(arg0, START_UML + new PcmSystemDiagramGenerator(system).getDiagramText() + END_UML,
SYSTEM_DIAGRAM_NAME);
}

final Allocation allocation = (Allocation) this.getBlackboard()
.getPartition(this.allocationKey);
if ((allocation != null) && !allocation.eContents()
.isEmpty()) {
this.writeFile(arg0, START_UML + new PcmAllocationDiagramGenerator(allocation).getDiagramText() + END_UML,
ALLOCATION_DIAGRAM_NAME);
}
}

@Override
public String getName() {
return JOB_NAME;
}

if (this.configuration.getOutputFolder()
.isPlatformResource()) {
private void writeFile(final IProgressMonitor monitor, final String plantUmlSource, final String fileName) {
if (this.outputFolder.isPlatformResource()) {
final IWorkspaceRoot root = ResourcesPlugin.getWorkspace()
.getRoot();
final IFile file = root.getFile(new Path(this.configuration.getOutputFolder()
.appendSegment("componentDiagram.puml")
final IFile file = root.getFile(new Path(this.outputFolder.appendSegment(fileName)
.toPlatformString(true)));
try {
if (!file.exists()) {
file.create(new ByteArrayInputStream(new byte[0]), IResource.FORCE, null);
file.create(new ByteArrayInputStream(new byte[0]), IResource.FORCE, monitor);
}
file.setContents(new ByteArrayInputStream(plantUmlSource.getBytes()), IResource.FORCE, null);
file.setContents(new ByteArrayInputStream(plantUmlSource.getBytes()), IResource.FORCE, monitor);
} catch (final CoreException e) {
LOG.error(e);
LOGGER.error(e);
}

} else {
final String path = this.configuration.getOutputFolder()
.appendSegment("componentDiagram.puml")
final String path = this.outputFolder.appendSegment(fileName)
.devicePath();
try (FileWriter writer = new FileWriter(path)) {
writer.append(plantUmlSource);
} catch (final IOException e) {
LOG.error(e);
LOGGER.error(e);
}
}
}

@Override
public String getName() {
return NAME;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ public RetrieverJob(final RetrieverConfiguration configuration) {
RetrieverBlackboardKeys.RULE_ENGINE_MOCORE_OUTPUT_ALLOCATION,
RetrieverBlackboardKeys.RULE_ENGINE_MOCORE_OUTPUT_RESOURCE_ENVIRONMENT));

super.add(new PlantUmlJob(configuration, this.getBlackboard()));
super.add(new PlantUmlJob(this.getBlackboard(), configuration.getOutputFolder(),
RetrieverBlackboardKeys.RULE_ENGINE_MOCORE_OUTPUT_REPOSITORY,
RetrieverBlackboardKeys.RULE_ENGINE_MOCORE_OUTPUT_SYSTEM,
RetrieverBlackboardKeys.RULE_ENGINE_MOCORE_OUTPUT_ALLOCATION));
}

private List<ParallelJob> createRuleJobs(final RetrieverConfiguration configuration) {
Expand Down
Loading