diff options
author | Morgan E. Cook | 2015-10-30 22:04:41 +0000 |
---|---|---|
committer | Angel Avila | 2015-12-03 18:24:27 +0000 |
commit | 950bb494da84cf73ea20fa0407a8c4e3c96eb862 (patch) | |
tree | 7072abcd9139688b4817a2cede2e10a0cbda8b24 | |
parent | 134f3b19d681e28dcae30f860e54aa47fa7fb069 (diff) | |
download | org.eclipse.osee-950bb494da84cf73ea20fa0407a8c4e3c96eb862.tar.gz org.eclipse.osee-950bb494da84cf73ea20fa0407a8c4e3c96eb862.tar.xz org.eclipse.osee-950bb494da84cf73ea20fa0407a8c4e3c96eb862.zip |
refactor: Add new rule to change proccess links
Signed-off-by: Morgan E. Cook <Morgan.e.cook@boeing.com>
6 files changed, 151 insertions, 1 deletions
diff --git a/plugins/org.eclipse.osee.define.report/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.define.report/META-INF/MANIFEST.MF index 08e7e6e4a4c..669f764e85f 100644 --- a/plugins/org.eclipse.osee.define.report/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.osee.define.report/META-INF/MANIFEST.MF @@ -19,6 +19,7 @@ Import-Package: com.google.common.base;version="15.0.0", org.eclipse.osee.framework.core.enums, org.eclipse.osee.framework.core.exception, org.eclipse.osee.framework.core.model, + org.eclipse.osee.framework.jdk.core.text, org.eclipse.osee.framework.jdk.core.text.change, org.eclipse.osee.framework.jdk.core.type, org.eclipse.osee.framework.jdk.core.util, diff --git a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/enums/CoreArtifactTypes.java b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/enums/CoreArtifactTypes.java index 3e97701735b..5647f4cc6fa 100644 --- a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/enums/CoreArtifactTypes.java +++ b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/enums/CoreArtifactTypes.java @@ -45,6 +45,8 @@ public final class CoreArtifactTypes { public static final IArtifactType InterfaceRequirement = TokenFactory.createArtifactType(0x0000000000000020L, "Interface Requirement"); public static final IArtifactType ImplementationDetails = TokenFactory.createArtifactType(0x000000000000001AL, "Implementation Details"); public static final IArtifactType ModelDiagram = TokenFactory.createArtifactType(0x0000000000000062L, "Model Diagram"); + public static final IArtifactType NativeArtifact = TokenFactory.createArtifactType(0x0000000000000014L, "Native Artifact"); + public static final IArtifactType WholeWord = TokenFactory.createArtifactType(0x0000000000000012L, "MS Word Whole Document"); public static final IArtifactType OseeApp = TokenFactory.createArtifactType(0x0000000000000059L, "OSEE App"); public static final IArtifactType OseeTypeDefinition = TokenFactory.createArtifactType(0x000000000000003CL, "Osee Type Definition"); public static final IArtifactType RendererTemplate = TokenFactory.createArtifactType(0x0000000000000009L, "Renderer Template"); diff --git a/plugins/org.eclipse.osee.orcs.rest/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.orcs.rest/META-INF/MANIFEST.MF index 6b64d034aa6..378828524b4 100644 --- a/plugins/org.eclipse.osee.orcs.rest/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.osee.orcs.rest/META-INF/MANIFEST.MF @@ -26,6 +26,8 @@ Import-Package: com.google.common.base;version="15.0.0", org.eclipse.osee.framework.core.model.cache, org.eclipse.osee.framework.core.model.change, org.eclipse.osee.framework.core.util, + org.eclipse.osee.framework.jdk.core.text, + org.eclipse.osee.framework.jdk.core.text.change, org.eclipse.osee.framework.jdk.core.type, org.eclipse.osee.framework.jdk.core.util, org.eclipse.osee.framework.jdk.core.util.io.xml, diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/admin/LinkUpdateResource.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/admin/LinkUpdateResource.java new file mode 100644 index 00000000000..78c17bbe99e --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/admin/LinkUpdateResource.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2015 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs.rest.admin; + +import java.io.File; +import java.io.IOException; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import org.eclipse.osee.framework.jdk.core.text.Rule; +import org.eclipse.osee.orcs.OrcsApi; + +/** + * @author Ryan D. Brooks + * @author Morgan E. Cook + */ +@Path("/") +public final class LinkUpdateResource { + private final OrcsApi orcsApi; + + public LinkUpdateResource(OrcsApi orcsApi) { + this.orcsApi = orcsApi; + } + + @Path("links") + @POST + @Produces(MediaType.TEXT_HTML) + public String fixLinks(@QueryParam("path") String path) throws IOException { + Rule rule = new UpdateLinksRule(orcsApi); + rule.setFileNamePattern(".*html"); + int modCount = rule.process(new File(path)); + return "Number of files modified: " + modCount; + } +} diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/admin/UpdateLinksRule.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/admin/UpdateLinksRule.java new file mode 100644 index 00000000000..f6df2d7b200 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/admin/UpdateLinksRule.java @@ -0,0 +1,98 @@ +/******************************************************************************* + * Copyright (c) 2015 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.orcs.rest.admin; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import org.eclipse.osee.framework.core.data.IAttributeType; +import org.eclipse.osee.framework.core.enums.CoreArtifactTypes; +import org.eclipse.osee.framework.core.enums.CoreAttributeTypes; +import org.eclipse.osee.framework.jdk.core.text.Rule; +import org.eclipse.osee.framework.jdk.core.text.change.ChangeSet; +import org.eclipse.osee.orcs.OrcsApi; +import org.eclipse.osee.orcs.data.ArtifactReadable; +import org.eclipse.osee.orcs.search.QueryBuilder; + +/** + * Replaces the old broken process links with the attribute and artifact IDs + * + * @author Ryan D. Brooks + * @author Morgan E. Cook + */ +public class UpdateLinksRule extends Rule { + + private final static Pattern generalPattern = Pattern.compile("<a href=\"http://osee[^\"]+"); + private final static Pattern precisePattern = Pattern.compile(".+?guid=([^&]+)(?:&|&)branchUuid=(\\d+)"); + private final static Pattern revPrecisePattern = Pattern.compile(".+?branch.uid=(\\d+)(?:&|&)guid=(.+)"); + private final OrcsApi orcsApi; + + public UpdateLinksRule(OrcsApi orcsApi) { + super("html"); + this.orcsApi = orcsApi; + } + + private String generateLink(String branchIdString, String artifactGuid) { + Long branchId = Long.valueOf(branchIdString); + artifactGuid = artifactGuid.replaceAll("%2[Bb]", "+"); + artifactGuid = artifactGuid.replaceAll("%3[Dd]", "="); + + QueryBuilder query = orcsApi.getQueryFactory().fromBranch(branchId).andGuid(artifactGuid); + ArtifactReadable artifact = query.getResults().getExactlyOne(); + Long artifactId = artifact.getUuid(); + + Long attributeId = getAttributeId(artifact); + + return String.format("<a href=\"http://osee.msc.az.boeing.com/orcs/branch/%s/artifact/%s/attribute/%s", branchId, + artifactId, attributeId); + } + + private Long getAttributeId(ArtifactReadable artifact) { + IAttributeType attributeType; + + if (artifact.isOfType(CoreArtifactTypes.WholeWord)) { + attributeType = CoreAttributeTypes.WholeWordContent; + + } else if (artifact.isOfType(CoreArtifactTypes.NativeArtifact)) { + attributeType = CoreAttributeTypes.NativeContent; + } else { + throw new RuntimeException("Unexpected Artifact type: " + artifact.getArtifactType()); + } + + return artifact.getSoleAttributeId(attributeType); + } + + private void applyTextSwap(ChangeSet set, Matcher matcher, String branchIdString, String artifactGuid) { + ruleWasApplicable = true; + String link = generateLink(branchIdString, artifactGuid); + set.replace(matcher.start(), matcher.end(), link); + } + + @Override + public ChangeSet computeChanges(CharSequence seq) { + ChangeSet changeSet = new ChangeSet(seq); + Matcher generalMatcher = generalPattern.matcher(seq); + + while (generalMatcher.find()) { + Matcher preciseMatcher = precisePattern.matcher(generalMatcher.group()); + Matcher revPreciseMatcher = revPrecisePattern.matcher(generalMatcher.group()); + + if (preciseMatcher.find()) { + applyTextSwap(changeSet, generalMatcher, preciseMatcher.group(2), preciseMatcher.group(1)); + } else if (revPreciseMatcher.find()) { + applyTextSwap(changeSet, generalMatcher, revPreciseMatcher.group(1), revPreciseMatcher.group(2)); + } else { + throw new RuntimeException("Unexpected Link Format: " + generalMatcher.group()); + } + } + + return changeSet; + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/OrcsApplication.java b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/OrcsApplication.java index b545e9a7367..0435e8b35c4 100644 --- a/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/OrcsApplication.java +++ b/plugins/org.eclipse.osee.orcs.rest/src/org/eclipse/osee/orcs/rest/internal/OrcsApplication.java @@ -18,6 +18,7 @@ import javax.ws.rs.core.Application; import org.eclipse.osee.activity.api.ActivityLog; import org.eclipse.osee.framework.resource.management.IResourceManager; import org.eclipse.osee.orcs.OrcsApi; +import org.eclipse.osee.orcs.rest.admin.LinkUpdateResource; import org.eclipse.osee.orcs.rest.internal.writer.OrcsWriterEndpointImpl; /** @@ -60,12 +61,14 @@ public class OrcsApplication extends Application { resources.add(new BranchEndpointImpl(orcsApi, resourceManager)); resources.add(new OrcsWriterEndpointImpl(orcsApi)); - resources.add(new TransactionEndpointImpl(orcsApi)); + resources.add(new TransactionEndpointImpl(orcsApi)); resources.add(new TypesEndpointImpl(orcsApi)); resources.add(new IndexerEndpointImpl(orcsApi)); resources.add(new ResourcesEndpointImpl(resourceManager)); resources.add(new DatastoreEndpointImpl(orcsApi, activityLog)); + + resources.add(new LinkUpdateResource(orcsApi)); } public void stop() { |